// Difference table for triangular numbers.
// Compile: typst compile triangular_diff.typ triangular_diff.png --ppi 500 --root ..
#import "../_diagram-style.typ": *
#set page(width: 570pt, height: 250pt, margin: 12pt)
#set text(font: base-font, size: label-size)

#let cell(body, color: fg) = {
  box(inset: (x: 6pt, y: 3pt), text(fill: color, weight: "regular")[#body])
}

#let hl(body) = text(weight: "bold", fill: blue.text)[#body]

#align(center)[
  #grid(
    columns: (auto,) * 7,
    column-gutter: 4pt,
    row-gutter: 6pt,
    // Row 0: sequence
    cell[1], cell[3], cell[6], cell[10], cell[15], cell[21], cell[28],
    // Row 1: first differences
    [], cell(color: fg2)[2], cell(color: fg2)[3], cell(color: fg2)[4], cell(color: fg2)[5], cell(color: fg2)[6], cell(color: fg2)[7],
    // Row 2: second differences (constant!)
    [], [], cell(color: blue.text)[#hl[1]], cell(color: blue.text)[#hl[1]], cell(color: blue.text)[#hl[1]], cell(color: blue.text)[#hl[1]], cell(color: blue.text)[#hl[1]],
    // Row 3: third differences (zero)
    [], [], [], cell(color: fg3)[0], cell(color: fg3)[0], cell(color: fg3)[0], cell(color: fg3)[0],
  )

  #v(8pt)
  #text(annot-size, fill: fg2, style: "italic")[
    Triangular numbers: second differences are constant at 1. Third differences are zero. The sequence is quadratic.
  ]

  #v(4pt)
  #text(annot-size, fill: blue.text)[
    Left edge: #hl[1], 2, #hl[1], 0 #h(6pt) $arrow.r$ #h(6pt) $a_n = binom(n,0) dot 1 + binom(n,1) dot 2 + binom(n,2) dot 1$
  ]
]
