#import "@local/handout:0.1.0": *
#import "../macros.typ": *
#import "@preview/cetz:0.3.1"

= Tropical Polynomials

#definition()
A _polynomial_ is an expression formed by adding and multiplying numbers and a variable $x$. \
Every polynomial can be written as
#align(
  center,
  box(
    inset: 3mm,
    $
      c_0 + c_1 x + c_2 x^2 + ... + c_n x^n
    $,
  ),
)
for some nonnegative integer $n$ and coefficients $c_0, c_1, ..., c_n$. \
The _degree_ of a polynomial is the largest $n$ for which $c_n$ is nonzero.

#theorem()
The _fundamental theorem of algebra_ implies that any non-constant polynomial with real coefficients
can be written as a product of polynomials of degree 1 or 2 with real coefficients.

#v(2mm)

For example, the polynomial $-160 - 64x - 2x^2 + 17x^3 + 8x^4 + x^5$ \
can be written as $(x^2 + 2x+5)(x-2)(x+4)(x+4)$

#v(2mm)
A similar theorem exists for polynomials with complex coefficients. \
These coefficients may be found using the roots of this polynomial. \
As it turns out, there are formulas that determine the roots of quadratic, cubic, and quartic #note([(degree 2, 3, and 4)]) polynomials. There are no formulas for the roots of polynomials with larger degrees---in this case, we usually rely on approximate roots found by computers.

#v(2mm)
In this section, we will analyze tropical polynomials:
- Is there a fundamental theorem of tropical algebra?
- Is there a tropical quadratic formula? How about a cubic formula?
- Is it difficult to find the roots of tropical polynomials with large degrees?


#definition()
A _tropical_ polynomial is a polynomial that uses tropical addition and multiplication. \
In other words, it is an expression of the form
#align(
  center,
  box(
    inset: 3mm,
    $
      c_0 #tp (c_1 #tm x) #tp (c_2 #tm x^2) #tp ... #tp (c_n #tm x^n)
    $,
  ),
)
where all exponents represent repeated tropical multiplication.

#pagebreak() // MARK: page




#problem()
Draw a graph of the tropical polynomial $f(x) = x^2 #tp 1x #tp 4$. \
#hint([$1x$ is not equal to $x$.])

#if_no_solutions(graphgrid(none))

#solution([
  $f(x) = min(2x , 1+x, 4)$, which looks like:

  #graphgrid({
    import cetz.draw: *
    let step = 0.75

    dotline((0, 0), (4 * step, 8 * step))
    dotline((0, 1 * step), (7 * step, 8 * step))
    dotline((0, 4 * step), (8 * step, 4 * step))

    line(
      (0, 0),
      (1 * step, 2 * step),
      (3 * step, 4 * step),
      (7.5 * step, 4 * step),
      stroke: 1mm + oblue,
    )
  })
])


#problem()
Now, factor $f(x) = x^2 #tp 1x #tp 4$ into two polynomials with degree 1. \
In other words, find $r$ and $s$ so that
#align(
  center,
  box(
    inset: 3mm,
    $
      x^2 #tp 1x #tp 4 = (x #tp r)(x #tp s)
    $,
  ),
)

we will call $r$ and $s$ the _roots_ of $f$.

#solution([
  Because $(x #tp r)(x #tp s) = x^2 #tp (r #tp s)x #tp s r$, we must have $r #tp s = 1$ and $r #tm s = 4$. \
  In standard notation, we need $min(r, s) = 1$ and $r + s = 4$, so we take $r = 1$ and $s = 3$:

  #v(2mm)

  $
    f(x) = x^2 #tp 1x #tp 4 = (x #tp 1)(x #tp 3)
  $
])

#v(1fr)

#problem()
How can we use the graph to determine these roots?

#solution([The roots are the corners of the graph.])

#v(0.5fr)
#pagebreak() // MARK: page






#problem()
Graph $f(x) = -2x^2 #tp x #tp 8$. \
#hint([Use half scale. 1 box = 2 units.])

#if_no_solutions(graphgrid(none))

#solution([
  #graphgrid({
    import cetz.draw: *
    let step = 0.75

    dotline((0, 0), (8 * step, 8 * step))
    dotline((0.5 * step, 0), (4.5 * step, 8 * step))
    dotline((0, 4 * step), (8 * step, 4 * step))

    line(
      (0.5 * step, 0),
      (1 * step, 1 * step),
      (4 * step, 4 * step),
      (7.5 * step, 4 * step),
      stroke: 1mm + oblue,
    )
  })
])

#problem()
Find a factorization of $f$ in the form $a(x #tp r)(x#tp s)$.

#solution([
  We (tropically) factor out $-2$ to get

  #eqnbox($
    f(x) = -2(x^2 #tp 2x #tp 10)
  $)


  by the same process as the previous problem, we get
  #eqnbox($
    f(x) = -2(x #tp 2)(x #tp 8)
  $)
])

#v(1fr)

#problem()
Can you see the roots $r$ and $s$ in the graph? \
How are the roots related to the coefficients of $f$? \
#hint([look at consecutive coefficients: $0 - (-2) = 2$])

#solution([
  The roots are the differences between consecutive coefficients of $f$:
  - $0-(-2) = 2$
  - $8 - 0 = 8$
])

#v(0.5fr)


#problem()
Find a tropical polynomial that has roots $4$ and $5$ \
and always produces $7$ for sufficiently large inputs.

#solution([
  We are looking for $f(x) = a x^2 #tp b x #tp c$. \
  Since $f(#sym.infinity) = 7$, we know that $c = 7$. \
  Using the pattern from the previous problem, we'll subtract $5$ from $c$ to get $b = 2$, \
  and $4$ from $b$ to get $a = -2$.

  And so, $f(x) = -2x^2 #tp 2x #tp 7$

  #v(2mm)

  Subtracting roots in the opposite order does not work.
])

#v(1fr)
#pagebreak() // MARK: page


#problem()
Graph $f(x) = 1x^2 #tp 3x #tp 5$.

#if_no_solutions(graphgrid(none))

#solution([
  The graphs of all three terms intersect at the same point:

  #graphgrid({
    import cetz.draw: *
    let step = 0.75

    dotline((0, 1 * step), (3.5 * step, 8 * step))
    dotline((0, 5 * step), (8 * step, 5 * step))
    dotline((0, 3 * step), (5 * step, 8 * step))

    line(
      (0, 1 * step),
      (2 * step, 5 * step),
      (7.5 * step, 5 * step),
      stroke: 1mm + oblue,
    )
  })
])


#problem()
Find a factorization of $f$ in the form $a(x #tp r)(x#tp s)$.

#solution(
  eqnbox($
    f(x) = 1x^2 #tp 3 x #tp 5 = 1(x #tp 2)^2
  $),
)

#v(1fr)

#problem()
How is this graph different from the previous two? \
How is this polynomial's factorization different from the previous two? \
How are the roots of $f$ related to its coefficients?

#solution([
  The factorization contains the same term twice. \
  Also note that the differences between consecutive coefficients of $f$ are both two.
])

#v(0.5fr)
#pagebreak() // MARK: page


#problem()
Graph $f(x) = 2x^2 #tp 4x #tp 4$.

#if_no_solutions(graphgrid(none))

#solution(
  graphgrid({
    import cetz.draw: *
    let step = 0.75

    dotline((0, 2 * step), (3 * step, 8 * step))
    dotline((0, 4 * step), (5 * step, 8 * step))
    dotline((0, 4 * step), (8 * step, 4 * step))

    line(
      (0, 2 * step),
      (1 * step, 4 * step),
      (7.5 * step, 4 * step),
      stroke: 1mm + oblue,
    )
  }),
)


#problem()
Find a factorization of $f$ in the form $a(x #tp r)(x#tp s)$, or show that one does not exist.

#solution([
  We can factor out a 2 to get $f(x) = 2(x^2 #tp 2x #tp 2)$,
  but $x^2 #tp 2x #tp 2$ does not factor. \
  There are no $a$ and $b$ with minimum 2 and sum 2.
])

#v(1fr)

#problem()
Find a polynomial that has the same graph as $f$, but can be factored.

#solution([
  $
    2x^2 #tp 3x #tp 4 = 2(x #tp 1)^2
  $
])


#v(1fr)

#pagebreak() // MARK: page


#theorem()
The _fundamental thorem of tropical algebra_ states that for every tropical polynomial $f$, \
there exists a _unique_ tropical polynomial $accent(f, macron)$ with the same graph that can be factored \
into linear factors.

#v(2mm)

Whenever we say "the roots of $f$", we really mean "the roots of $accent(f, macron)$." \
$f$ and $accent(f, macron)$ might be the same polynomial.

#problem()
If $f(x) = a x^2 #tp b x #tp c$, then $accent(f, macron)(x) = a x^2 #tp B x #tp c$ for some $B$. \
Find a formula for $B$ in terms of $a$, $b$, and $c$. \
#hint([there are two cases to consider.])

#solution([
  If we want to factor $a(x^2 #tp (b-a)x #tp (c-a))$, we need to find $r$ and $s$ so that
  - $min(r,s) = b-a$, and
  - $r + s = c - a$

  #v(2mm)

  This is possible if and only if $2(b-a) <= c-a$, \
  or equivalently if $b <= (a+c) #sym.div 2$

  #v(8mm)

  *Case 1:* If $b <= (a + c #sym.div) 2$, then $accent(f, macron) = f$ and $b = B$.

  #v(2mm)

  *Case 2:* If $b > (a + c #sym.div) 2$, then
  $
    accent(f, macron)(x)
    &= a x^2 #tp ((a+c)/2)x #tp c \
    &= a(x #tp (c-a)/2)^2
  $
  has the same graph as $f$, and thus $B = (a+c) #sym.div 2$

  #v(8mm)

  We can combine these results as follows:
  $
    B = min(b, (a+c)/2)
  $
])


#v(1fr)

#problem()
Find a tropical quadratic formula in terms of $a$, $b$, and $c$ \
for the roots $x$ of a tropical polynomial $f(x) = a x^2 #tp b x #tp c$. \
#hint([
  again, there are two cases. \
  Remember that "roots of $f$" means "roots of $accent(f, macron)$".
])

#solution([
  *Case 1:* If $b <= (a+c) #sym.div 2$, then $accent(f, macron) = f$ has roots $b-a$ and $c-b$, so
  $
    accent(f, macron)(x) = a(x #tp (b-a))(x #tp (c-b))
  $

  #v(8mm)

  *Case 2:* If $b > (a+c) #sym.div 2$, then $accent(f, macron)$ has root $(c-a) #sym.div$ with multiplicity 2, so
  $
    accent(f, macron)(x) = a(x #tp (c-a)/2)^2
  $

  #v(8mm)

  It is interesting to note that the condition $2b < a+ c$ for there to be two distinct roots becomes $b^2 > a c$ in tropical notation. This is reminiscent of the discriminant condition for standard polynomials!
])

#v(1fr)
