# How to draw a tropical surface?

By definition, a tropical surface in $\mathbb R^3$ is the set of points $(x,y,z)$ where the maximum $f=\max(f_1,f_2,\dots,f_n)$ is attained at least twice, here $f_i$ stand for some linear functions of the type $a+ix+jy+kz, a\in \mathbb R,i,j,k\in\mathbb Z$.

The most basic example is a tropical plane, which is given by $f=\max(x,y,z,0)$. It is easy to see that the set of points which we interested in, is $\{(x,y,z)|x=y\geq \max(z,0)$ or $x=z\geq \max(y,0)$ or$... x=0\geq \max(y,z)...\}$, so it is a union of six hyperplanes.

One can use an equivalent definition: the tropical surface is the set of points where $f$ is not smooth (or, equivalently, not linear).

Here is the question: given $f_1,f_2,\dots$ of the above form we need to draw the set where $f=\max(f_1,f_2,\dots,f_n)$ is not smooth. In principle, one can elaborate all all the possible inequalities ($f_1=f_2\geq f_i$ for all $i$ etc), but there should be more elegant way to do that. Could you help me?

Added: the simplest way, proposed by belisarius Apr 13 at 16:12, seems to be

fns[u_, v_, w_] := {u, v, w, 0}; k = 20;
RegionPlot3D[First@Differences[Sort[fns[u, v, w]][[1 ;; 2]]] == 0,
{u, -k, k}, {v, -k, k}, {w, -k, k}, PlotPoints -> 50]


but it draws only a part of all points (for the function $\min(x,y,z,0)$ attained twice), without the points $(0,a,b),(a,0,b),(a,b,0)$ with $a,b>0$. How could that be?

• Please include in your question the Mathematica code you have developed so far to address your problem. – bbgodfrey Apr 13 '15 at 15:38
• somewhat related Plot the plane so different condition has a different color? – kglr Apr 13 '15 at 15:38
• to bbgodfrey: I produced the code illustrating the last idea: for each pair of indices $i,j$ we construct the inequalities $f_i=f_j\geq f_k$ for all $k$. The problem is not in this code. I believe that there should be a fast way for a function of type $\max(,,,)$ to find the set where it is not linear, or where the maximum is attained twice. – Nikita Kalinin Apr 13 '15 at 15:42
• to kguler: Yes, thank you, it seems it will work. I try to do like there. – Nikita Kalinin Apr 13 '15 at 15:51
• Perhaps fns[u_, v_, w_] := {u, v, w, 0}; k = 20; RegionPlot3D[ First@Differences[Sort[fns[u, v, w]][[1 ;; 2]]] == 0, {u, -k, k}, {v, -k, k}, {w, -k, k}, PlotPoints -> 50] – Dr. belisarius Apr 13 '15 at 16:12

Here's a simple way to enumerate all the conditions:

fs = {x, y, z, 0};
conds = Table[{Equal @@ fs1,
And @@ Table[First@fs1 >= f, {f, Complement[fs, fs1]}]},
{fs1, Subsets[fs, {2}]}]
(* {{x == y, x >= 0 && x >= z}, {x == z, x >= 0 && x >= y},
{x == 0, x >= y && x >= z}, {y == z, y >= 0 && y >= x},
{y == 0, y >= x && y >= z}, {z == 0, z >= x && z >= y}} *)


Each item {e, i} in the list is a pair containing an equality and a conjunction of inequalities, which you can use as ContourPlot3D[e, ..., RegionFunction -> Function[{x, y, z}, i]]. Draw the whole surface by using Show to put them all together.

Show[Table[
ContourPlot3D[Evaluate@First@c, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
RegionFunction -> Function[{x, y, z}, Last@c]], {c, conds}]]


• This is fun! $(x^2-y^2,y^2-z^2+1,z^2-x^2-1)$: i.stack.imgur.com/MBoL0.png – user484 Apr 24 '15 at 20:06