# Tropical Operation Conversions: Multiple Operations

I apologize if my syntax is bad. I looked around, but didn't see anything on this in the stack exchange.

I would like to be able to transform a classical real-valued polynomial to a tropical polynomial. The rule set that we're using are: "a+b"=max(a,b), "a+b+c+..."=max(a,b,c,...) "ab"=a+b, "abc..."=a+b+c+...

I've defined those operations in the code below, but the problem I'm running into is that I can't convince Mathematica to take more than 2 expressions and separate it into separate terms as I would like. Here's my definitions:

 troptoclass[x_ + y_]:=max[x,y] troptoclass[x_ y_]:=x+y  troptoclass[x_^n_Integer]:=n*x

Here's what happens when I try the operations when it's more than 2 expressions:

or:

I think it boils down to having Mathematica be able to perform multiple operations in one statement, and also recognition. Is what I'm trying to do here possible in Mathematica? I'm a beginner with this program, any help is greatly appreciated.

• The simplest way is to do something like a + b c /. {Plus -> Max, Times -> Plus}; you would need to treat Power separately for a general (tropical) polynomial. May 17 at 19:58
• @J.M. thanks! I just asked, what does the /. mean in the code? I'm getting ready to try it now. May 17 at 20:02

I assume that you want to replace Addition by "Max" and Multiplication by addition. It is not clear how a negative term should be treated. For the time being I assume that it will be included in a factor.

Toward this aim, we define following rules:

Plus -> Max
Times -> Plus


In addition we need a rule for powers:

Power[x1_, x2_] -> Sum[x1, x2]


All together:

rules = { Plus -> Max, Times -> Plus, Power[x1_, x2_] -> Sum[x1, x2]};


Now we can give an example:

x + y + 2 x y + x^4 /. rules
(* Max[x, 4 x, y, 2 + x + y] *)

• Thank you and @J.M. for such a quick response! What does the /. mean exactly? May 17 at 20:01
• You might want to use a more restrictive pattern for Power, e.g. Power[a_, n_Integer?Positive]. May 17 at 20:01
• @king, anytime you encounter an unfamiliar symbol on the front end (in this case, /.), highlight it and press F1 to see more detail about it. May 17 at 20:02
• Great, I'll keep that in mind. And this method worked like a charm! Thank you for the help :) May 17 at 20:09

I'm not entirely sure if this is what you're looking for, but it seems you would just need to replace your x_ with x__

f[x__] := Total[{x}]
f[a, b, c, d, e]
(*a + b + c + d + e*)

f2[x__] := x /. Times -> Plus
f2[a b c]
(*a + b + c*)

• Appreciate the help. Daniel beat ya to it :P May 17 at 20:09