Files
handouts/src/Warm-Ups/Snakes/main.typ
2025-10-26 11:12:35 -07:00

90 lines
1.9 KiB
Typst

#import "@local/handout:0.1.0": *
#import "@preview/cetz:0.4.2"
#show: handout.with(
title: [Warm-Up: Snakes!],
by: "Mark",
page_numbers: false,
)
#box(place(box(width: 100%, height: 8in, align(horizon, image(
"7.svg",
width: 360mm,
)))))
#problem()
Evaluate this integral. \
All integrals are of the form $integral_a^b 1 #h(1mm) d x$.
#if_solutions(pagebreak())
#solution[
This integral is drawn recursively with the following code: \
#v(2mm)
#let snake(depth, x, y) = {
if depth == 0 {
math.attach(math.integral, br: x, tr: y)
} else {
let bot = snake(depth - 1, x, "1")
let top = snake(depth - 1, "0", y)
snake(depth - 1, bot, top)
}
}
```typst
#let snake(depth, x, y) = {
if depth == 0 {
$integral_#x ^#y$
} else {
let bot = snake(depth - 1, x, "1")
let top = snake(depth - 1, "0", y)
snake(depth - 1, bot, top)
}
}
```
#v(5mm)
For example:
$ snake\(0, x, y) = #snake(0, "x", "y") $
#v(2mm)
$ snake\(1, x, y) = #snake(1, "x", "y") $
#v(2mm)
$ snake\(2, x, y) = #snake(2, "x", "y") $
In other words, we want $f_7 (0, 1)$, where...
- $f_0(x, y) := integral_x^y$
- $f_(n+1)(x, y) := f_n [f_n (x, 1), f_n (0, y)]$
#v(5mm)
Expanding a few iterations, we find:
- $f_0(x, y) = integral_x^y = y-x$
- $f_1(x, y) = f_0 [f_0 (x, 1), f_0 (0, y)] = y+x-1$
- $f_2(x, y) = f_1 [f_1 (x, 1), f_1 (0, y)] = y+x-2$
#v(5mm)
We can use induction to show that this pattern continues. \
If $g_n = y+x+c$, then $g_(n+1) = y+x+(3c+1)$.
#v(5mm)
Finally, use this recursion to find that
$f_0, f_1, ..., f_7 = 1, 0, -1, -4, -13, -40, -121, -364$
One can also find an explicit formula for $g_n$:
$
f_(n+1) = g_n & = x + y + 3^n c + 3^0 + 3^1 + ... + 3^n \
& = x + y + 3^n c + sum_(i=0)^n 3^i \
& = x + y + 3^n c + (3^(n+1) + 1)/2
$
]