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

= Tropical Cubic Polynomials

#problem()
Consider the polynomial $f(x) = x^3 #tp 1x^2 #tp 3x #tp 6$. \
- sketch a graph of this polynomial
- use this graph to find the roots of $f$
- write (and expand) a product of linear factors with the same graph as $f$.

#if_no_solutions(graphgrid(none))

#solution([
  - Roots are 1, 2, and 3.
  - $accent(f, macron)(x) = x^3 #tp 1x^2 #tp 3x #tp 6 = (x #tp 1)(x #tp 2)(x #tp 3)$


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

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

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



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

#problem()
Consider the polynomial $f(x) = x^3 #tp 1x^2 #tp 6x #tp 6$. \
- sketch a graph of this polynomial
- use this graph to find the roots of $f$
- write (and expand) a product of linear factors with the same graph as $f$.

#if_no_solutions(graphgrid(none))

#solution([
  - Roots are 1, 2.5, and 2.5.
  - $accent(f, macron)(x) = x^3 #tp 1x^2 #tp 3.5x #tp 6 = (x #tp 1)(x #tp 2.5)^2$

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

    dotline((0, 0), (2.66 * step, 8 * step))
    dotline((0, 1 * step), (3.5 * step, 8 * step))
    dotline((0, 6 * step), (2 * step, 8 * step))
    dotline((0, 6 * step), (8 * step, 6 * step))

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


#v(1fr)

#problem()
Consider the polynomial $f(x) = x^3 #tp 6x^2 #tp 6x #tp 6$. \
- sketch a graph of this polynomial
- use this graph to find the roots of $f$
- write (and expand) a product of linear factors with the same graph as $f$.

#if_no_solutions(graphgrid(none))

#solution([
  - Roots are 2, 2, and 2.
  - $accent(f, macron)(x) = x^3 #tp 2x^2 #tp 4x #tp 6 = (x #tp 2)^3$

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

    dotline((0, 0), (2.66 * step, 8 * step))
    dotline((0, 6 * step), (1 * step, 8 * step))
    dotline((0, 6 * step), (2 * step, 8 * step))
    dotline((0, 6 * step), (8 * step, 6 * step))

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


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


#problem()
If $f(x) = a x^3 #tp b x^2 #tp c x #tp d$, then $accent(f, macron)(x) = a x^3 #tp B x^2 #tp C x #tp d$ for some $B$ and $C$. \
Using the last three problems, find formulas for $B$ and $C$ in terms of $a$, $b$, $c$, and $d$.

#solution([

  $
    B = min(b, (a+c)/2, (2a+d)/3)
  $
  $
    C = min(c, (b+d)/2, (a+2d)/3)
  $
])

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

#problem()
What are the roots of the following polynomial?

#align(
  center,
  box(
    inset: 3mm,
    $
      3 x^6 #tp 4 x^5 #tp 2 x^4 #tp x^3 #tp x^2 #tp 4 x #tp 5
    $,
  ),
)

#solution([
  We have
  $
    accent(f, macron)(x) = 3x^6 #tp 2x^5 #tp 1x^4 #tp x^3 #tp 1x^2 #tp 3x #tp 5
  $
  which has roots $-1$, $-1$, $-1$, $1$, $2$, $2$
])


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

#problem(label: "findci")
If
$
  f(x) = c_0 #tp c_1 x #tp c_2 x^2 #tp ... #tp c_n x^n
$
then
$
  accent(f, macron)(x) = c_0 #tp C_1 x #tp C_2 x^2 #tp ... #tp C_(n-1) x^(n-1) #tp c_n x^n
$

#v(2mm)

Find a formula for each $C_i$ in terms of $c_0, c_1, ..., c_n$.

#solution([
  $
    A_j
    &= min_(l<=j<k)( (a_l - a_k) / (k-l) (k-j) + a_k ) \
    &= min_(l<=j<k)( a_l (k-j) / (k-l) + a_k (j-l) / (k-l) )
  $

  #v(2mm)

  which is a weighted average of some $a_l$ and $a_k$, with $l<=j<k$
])

#v(1fr)


#problem()
With the same setup as @findci, \
find formulas for the roots $r_1, r_2, ..., r_n$.

#solution([
  The roots are the differences between consecutive coefficients of $accent(f, macron)$:
  $
    r_i = A_i - A_(i-1)
  $
  where we set $A_n = a_n$ and $A_0 = a_0$.
])

#v(1fr)

#problem()
Can you find a geometric interpretation of these formulas \
in terms of the points $(-i, c_i)$ for $0 <= i <= n$?

#solution([
  The inequality #note([(for $l <= k < k$)])
  $
    A_j <= (a_l - a_k) / (k-l) (k-j)+a_k
  $
  states that the point $(-j,A_j)$ must lie on or below the line segment between the points $(-k, a_k)$ and $(-l, a_l)$.
  This makes it easy to find the $A_j$ using a graph of the points $(-i, a_i)$ for $0 <= i <=n$.
])

#v(0.5fr)
