You can download a Python script for plotting tropical curves defined by a tropical polynomial by clicking here. The same script, but as a .exe file can be downloaded by clicking here.
The script also plots the dual subdivision and can print the tikz code for the figures.
It uses the packages numpy, matplotlib and tkinter.
If you are on Windows, you can just download the exe-version and are ready to go.
Here are short notes on how to use the program:
Starting the program or running the python code will open an empty window where the optional printed output will appear and a window where you can input a polynomial and change several options. It might take a few seconds for the second window to pop up.
Input of the polynomial: For a term "\( a\odot x^iy^j\oplus b\odot x^ky^l\)" the input has to be "axiyj+bxkyl". So for example the minimal input for
"\(0\oplus 2\odot x^{1}y^{1}\oplus 0\odot x^{2}\oplus (-0.1)\odot x^{2}y^{1}\)" is "x2+2xy-0.1x2y+0".
Hitting the plot button will generate two figures, one of the curve, one of its dual subdivision and print all the things you specified in the options.
For more details on how to make this script work, what the options do, which inputs are allowed and how to configure default values, see here.
An app to plot tropical curves
I wrote an android app that allows you to plot tropical curves and their dual subdivision. You can find an APK-file here. Run this file on an android device to install the app. Android will be suspicious about the file as it does not come from the app store.
The app is very simplistic and unpolished, however, it does its job. It was written and build using BeeWare. The input for the polynomial works like described above. The plotting range is adjusted automatically. There are no error messages implemented, so you should check if the plot looks weird yourself.
Plotting tropical hypersurfaces in three dimensions
You can find a Python script for plotting tropical hypersurfaces in \(\mathbb{R}^3\) here. It uses the packages matplotlib, numpy and scipy. An even easier-to-use program written
by Lars Allermann can be found here.
My script, however, does plot the edges of the dual subdivision, too. There is no support for min-convention yet and you have to do the input directly in the file. Running it will immediately show you the plots.
This script uses the packages numpy, matplotlib and scipy.
For more details on how to make this script work and how the input works, see here.
Disclaimer
Use all the scripts on this website at your own risk. I am confident that they work very well for reasonable input, however, I do not guarantee that all outputs are correct.
If you find any bugs, please contact me after you made sure that you are using the latest version.
I only learned Python to write these scripts, so don't be surprised if my codes might not be the most elegant or efficient ones ever written.
On plotting tropical curves
How to install Python and necessary packages
I use Windows, so here is how it worked for me: Download Python from the official website. Install it - AND make sure that you
pick the "Add Python to PATH" during the installation.
Download pip with the command "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py" in the command prompt (You find that by pressing the Windows key and then typing cmd. The "" are not part of the command).
Install pip with the command "python get-pip.py". Use the commands "pip install numpy", "pip install matplotlib" to install the two needed packages.
If you use Linux or macOS: Ask chatGPT how to install everything. You might need to install "tkinter" explicitly, too.
The options
If you tick "use max-convention", the polynomial will be interpreted as a tropical polynomial
where "+" means max. Else "+" will mean min.
If you tick the "auto-adjust range" option the range of x- and y-values will be chosen automatically in such a way that the minimal distance of the vertices to the boundary of the range is as specified in the next line.
If you tick "auto-adjust range" and "make it a square" the range will be generated as described above but additionally the range will be square.
x-range and y-range define the plotting range. These inputs will be ignored if you activate the "auto-adjust range"-option.
Color of curve/dual subdivision/Newton polygon: Changes the color of the curve/dual subdivision/Newton polygon, also in the tikz code.
If you tick "Draw a grid", the plot will show a grid. This does not affect the tikz code.
If you tick "Print ends of edges", the coordinates of the vertices of the curve and of its intersection points with the boundary of the plotting range will get printed.
If you tick "Show weights of edges", the weights bigger than 1 will occur both in the plot and in the tikz code.
The options "Size of weights" and "Color of weights" change size and color of the weights both in the plot and in the tikz code.
The last two options decide whether the tikz code for the curve, resp. its dual, will get printed. If you print the code for the curve, you will also get the LaTeX code of the tropical polynomial.
Input
Some remarks about the input
If you hit enter while in the input field this will start the plotting process.
In the input for the polynomial, blanks, "^", "*", parenthesis "(" and ")" will be ignored and "+-" will be handled like a "-". "+" and "-" always seperate monomials. For a monomial with no coefficient,
the coefficient is assumed to be 0. The order of x and y doesn't matter, that is "3x2y" and "3yx2" are interpreted as the same term. Coefficients of monomials will be added if possible, i.e. "3xy + 4yx" gets simplified to "4xy" if max-convention is active, else to "3xy".
Coefficients of the polynomial and the values for the x- and y-range should differ by more than 0.00000000000001. This is because two numbers are considered equal if they differ by less than this number.
The allowed colors are all colors allowed in matplotlib. However, the same color gets used for the tikz code, so if you use
this option, make sure that it is also a tikz-color. Colors that work for both are for example: blue, black, red, green, cyan, magenta, yellow, orange, purple, pink, brown, gray, lime, olive, violet and teal.
Change default values
If you open the file in your favorite editor, you will immediately see a comment that reads "#Default values". Change the variables
underneath to the values to the default values you want.
The algorithm
The idea is the following:
Go through all triples of monomials and solve for the point where they are equal and maximal. Store the point and which monomials were maximal.
Using this information generate the range if opted for auto-adjust. If there are no points found in the previous step, compute intersection points of the curve with the coordinate axes and use these.
For the edges of the plotting range, do the same for pairs of monomials
Go through all pairs of saved points and check whether they share two or more maximal monomials. If yes, connect the two points and remember the exponents for the dual.
Why I wrote this script
There are already existing programs to plot tropical curves. And they are probably faster, more elegant, and use only algebraic methods.
My motivations for writing this script were mostly the following two: Writing it was fun and it is easy to use. This is also why I tried to keep all explanations very low level.
About old versions of the algorithm
The very first version of this script used the following logic: "If you compute the vertices of a tropical curve and connect them if their middle point is part of the curve you end up with the curve".
However, this approach is not correct: For example if you consider the input "-4+y+x-1x2-1y2+1xy-1xy2-1yx2" the points (-4,-4) and (2,2) would falsely get connected.
After realizing this, I updated the code to also check if the maximum at the middle point was attained by monomials that are part of the maximal monomials at the vertices. However, this is not correct either:
For "y+x+x2+y2" the points on the diagonal that intersect with the boundary of the plotting range would get connected and this edge would get a weight 2 assigned.
Since version 2.3 of the .exe/.py file and 0.4 of the app the following statement is used: "Let x,y be two points on a tropical curve with 2 common monomials that are maximal. Then all convex combinations of them are part of the curve".
This follows from the convexity of the graphs of tropical polynomial functions.
On plotting tropical hypersurfaces in three dimensions
How to install Python and necessary packages
I use Windows, so here is how it worked for me: Download Python from the official website.
Install it - and make sure that you pick the "Add Python to PATH" during the installation.
Download pip with the command "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py" in the command prompt (You find that by pressing the Windows key and then typing cmd. The "" are not part of the command).
Install pip with the command "python get-pip.py". Use the commands "pip install numpy", "pip install matplotlib", "pip install scipy" to install the three packages. "math", "re" and "tkinter" are pre-installed.
If you use Linux or macOS: Ask chatGPT how to install everything. You might need to install "tkinter" explicitly, too.
Input
For this script, you have to manually adjust the input in the code. If you open the file, after line 15 (''' INPUT ''') there are more explanations on how to do this.
The algorithm
The idea, similarly to the two-dimensional case, is:
Solve for the points where four monomials are equal and maximal, remember the monomials too.
Solve for the points on the boundary of the plot where three monomials are equal and maximal, remember the monomials too.
Check which of these points to connect.
Solve for the points on the edges of the plotting range where two monomials are equal and maximal, remember the monomials.
Go through all possible pairs of monomials and check which of the computed points contain them in their maximal monomials.
Plot the polygons defined by these points, compute the edges of the dual from the exponents of the monomials.
Obviously, there are quite a few details I skipped here.
Why I wrote this script
There are already existing programs to plot tropical hypersurfaces. And they are probably faster, more elegant, and use only algebraic methods.
My motivations for writing this script were mostly the following two: Writing it was fun and it is easy to use (This is also why I tried to keep all explanations very low level.).
At the time I didn't know the program by Lars Allermann. Still, plotting the dual is an advantage my script has.
About old versions of the algorithm
The old versions of this script followed the same ideas as the algorithm for the two-dimensional case to construct the one-dimensional faces.
Since version 1.3 the following statement is used: "Let x,y be two points on a tropical hypersurface with 3 common monomials that are maximal. Then for all convex combinations of these two points the max is attained by these three monomials".
This follows from the convexity of the graphs of tropical polynomial functions.
How to get a website like this
Website Hosting
This website is hosted on GitHub. Here is a good reference on how to start your own website. Thanks to Thomas Brazelton for this hint!
Writing the HTML code
Here is the obvious hint: Describe to chatGPT how you want your website to look and the structure to be and ask it to give you the HTML code. This works incredibly well.