This journal is in preparation. Submissions are open as a pilot and the editorial board is being formed. Articles marked Demonstration show the format only.
Journal of Machine-Verified MathematicsPeer-reviewed mathematics with machine-checked proofs, for the age of AI

E424/Input/Words.lean

All files · 53 lines · source at the verified commit

1module
2
3public import E424.Input.Gen
4
5@[expose] public section
6
7/-!
8# Input, part 2: words (needed downstream by `S2.L2` and `RoughElements/L6`)
9
10`eval w x` applies the maps `y ↦ a y - 1`, first letter first. `evalInt` is the same over `ℤ`.
11-/
12
13set_option linter.style.header false
14
15namespace E424.Inp
16
17def eval : List ℕ → ℕ → ℕ
18 | [], x => x
19 | a :: w, x => eval w (a * x - 1)
20
21def evalInt : List ℕ → ℤ → ℤ
22 | [], x => x
23 | a :: w, x => evalInt w (a * x - 1)
24
25@[simp] theorem eval_cons (a : ℕ) (w : List ℕ) (x : ℕ) : eval (a :: w) x = eval w (a * x - 1) := rfl
26@[simp] theorem evalInt_cons (a : ℕ) (w : List ℕ) (x : ℤ) :
27 evalInt (a :: w) x = evalInt w (a * x - 1) := rfl
28
29theorem eval_cast_eq_evalInt (w : List ℕ) {x : ℕ} (hx : 1 ≤ x) (hw : ∀ a ∈ w, 2 ≤ a) :
30 (eval w x : ℤ) = evalInt w x := by
31 induction w generalizing x with
32 | nil => rfl
33 | cons a w ih =>
34 have ha : 2 ≤ a := hw a (by simp)
35 have h1 : 2 * 1 ≤ a * x := Nat.mul_le_mul ha hx
36 rw [eval_cons, evalInt_cons, ih (by omega) fun b hb => hw b (by simp [hb])]
37 congr 1
38 push_cast [Nat.cast_sub (by omega : 1 ≤ a * x)]
39 ring
40
41/-- Words in the letters preserve the elements above 14 (v2, Lemma 2). -/
42theorem eval_gen {x : ℕ} (hx : Gen x) (h14 : 14 < x) (w : List ℕ) (hw : ∀ a ∈ w, Letter a) :
43 Gen (eval w x) := by
44 induction w generalizing x with
45 | nil => exact hx
46 | cons a w ih =>
47 have ha := hw a (by simp)
48 have h := (IsMap.one.step ha).2 x hx h14
49 simp only [mul_one, mul_zero, zero_add] at h
50 exact ih h.1 h.2 fun b hb => hw b (by simp [hb])
51
52end E424.Inp
53