Add conditionals to plot in sage

283 Views Asked by At

I am trying to implement an algorithm which plots a tropical curve given a tropical polynomial $P(x,y)$. So for instance the graph of $P(x,y)=x+y+0$ should be a union of three half rays, starting at the origin, with respective directions $(-1,0),(0,-1),(1,1)$.

The method I am trying to use is as follows: Given a tropical polynomial written as a sum of monomials, $P(x,y)=m_1+\dots+ m_k$, we start by looking at two tropical monomials at a time, say $m_1$ and $m_2$, and then implicitly plotting $m_1-m_2=0$, but this graph should only show up at a point $(x,y)$ in the final picture if both $m_1$ and $m_2$ are in fact equal to $\max\{m_1,\dots,m_k\}$ at $(x,y)$. Then iterate this process for all such pairs of monomials.

To do this, I want to use Sage's implicit_plot function with an added conditional. So in (half) pseudocode for the example $P(x,y)=x+y+0$ I want to say something like

implicit_plot(x-0, if x == max(x,y,0), (x,-3,3),(y,-3,3))

implicit_plot(y-0, if y == max(x,y,0), (x,-3,3),(y,-3,3))

implicit_plot(x-y, if x == max(x,y,0), (x,-3,3),(y,-3,3)).

Does Sage have functionality which allows this type of plotting? I have looked through the documentation but could not find an example exhibiting this. If not, would there be a better way of going about this? Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

Not sure if you are asking for the complete solution to get the plot starting from a sum of monomials, or just for a hint on using implicit_plot.

Here is an illustration of using implicit_plot in the way suggested in the question.

Say we defined functions f, g, h by:

def f(x, y):
    if x == max(x, y, 0): return x - 0

def g(x, y):
    if y == max(x, y, 0): return y - 0

def h(x, y):
    if x == max(x, y, 0): return x - y

then we can call implicit_plot on them to define:

sage: pf = implicit_plot(f, (-3, 3), (-3, 3), color='blue')
sage: pg = implicit_plot(g, (-3, 3), (-3, 3), color='red')
sage: ph = implicit_plot(h, (-3, 3), (-3, 3), color='green')

and assemble all these plots:

sage: p = pf + pg + ph

Here is what we got:

sage: p
Launched png viewer for Graphics object consisting of 3 graphics primitives

Tropical curve for $P(x, y) = x + y + 0$: three half-rays