Download lean/OAI/MathematicalPhysics/NavierStokes/BalancedTransport/PrefixCoding.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
induction first with
| refl => simpa using second
| cons step _ inductionHypothesis =>
simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using
(Exec.cons step (inductionHypothesis second))
theorempreparation (q : Q) (hq : q ≠M.halt) (a : Γ) (w : List Γ)
(LBJ : Stream' (LetterQ Γ)) :
ExecM (2 * w.length + 3)
⟨ready q, L, work a :: (w.map work ++ₛ (boundary :: work M.blank :: B)), J⟩
⟨execute q, L, work a :: (w.map work ++ₛ (boundary :: B)), work M.blank :: J⟩ :=by
proof · 18
lines
have h₁ := row_step M (.enter q a) hq
⟨L, w.map work ++ₛ (boundary :: work M.blank :: B), J⟩
have h₂ := outward_scan M q hq w (marked a :: L) (boundary :: work M.blank :: B) Jhave h₃ := row_step M (.supply q) hq
⟨w.reverse.map work ++ₛ (marked a :: L), B, J⟩
have h₄ := returning_scan M q hq w.reverse (marked a :: L)
(boundary :: B) (work M.blank :: J)
have h₅ := row_step M (.restore q a) hq
⟨L, w.map work ++ₛ (boundary :: B), work M.blank :: J⟩
simp only [List.reverse_reverse, List.length_reverse] at h₄
have h₁' :=Exec.single h₁
have h₃' :=Exec.single h₃
have h₅' :=Exec.single h₅
simp only [Row.instruction, Instruction.source, Instruction.target,
Stream'.appendStream'] at h₁' h₃' h₅'
have hh := (((h₁'.trans h₂).trans h₃').trans h₄).trans h₅'
convert hh using1
omega
theorempreparation_blank_tail (q : Q) (hq : q ≠M.halt) (a : Γ) (w : List Γ)
(LJ : Stream' (LetterQ Γ)) :
ExecM (2 * w.length + 3)
⟨ready q, L,
work a :: (w.map work ++ₛ (boundary :: Stream'.const (work M.blank))), J⟩
⟨execute q, L,
work a :: (w.map work ++ₛ (boundary :: Stream'.const (work M.blank))),
work M.blank :: J⟩ :=by
proof · 6
lines
have hh := preparation M q hq a w L (Stream'.const (work M.blank)) Jhavehb : (work M.blank :: Stream'.const (work M.blank) : Stream' (LetterQ Γ)) =
Stream'.const (work M.blank) :=by
ext n
cases n <;> rfl
simpa only [hb] using hh
theoremcheckpoint_left (q : Q) (hq : q ≠M.halt) (a c : Γ)
(hm : (M.transition q a).move = .left) (w : List Γ)
(LJ : Stream' (LetterQ Γ)) :
ExecM (2 * (w.length + 1) + 2)
⟨ready q, work c :: L,
work a :: (w.map work ++ₛ (boundary :: Stream'.const (work M.blank))), J⟩
⟨ready (M.transition q a).state, L,
work c :: work (M.transition q a).write ::
(w.map work ++ₛ (boundary :: Stream'.const (work M.blank))),
record (.left q a c) :: J⟩ :=by
proof · 3
lines
apply checkpoint_length M q hq a w (work c :: L) J
exact row_step M (.left q a c) ⟨hq, hm⟩
⟨L, w.map work ++ₛ (boundary :: Stream'.const (work M.blank)), J⟩
theoremcheckpoint_right (q : Q) (hq : q ≠M.halt) (a c : Γ)
(hm : (M.transition q a).move = .right) (w : List Γ)
(LJ : Stream' (LetterQ Γ)) :
ExecM (2 * (w.length + 2) + 2)
⟨ready q, L,
work a :: work c :: (w.map work ++ₛ (boundary :: Stream'.const (work M.blank))), J⟩
⟨ready (M.transition q a).state, work (M.transition q a).write :: L,
work c :: (w.map work ++ₛ (boundary :: Stream'.const (work M.blank))),
record (.right q a c) :: J⟩ :=by
proof · 4
lines
have hh := checkpoint_length M q hq a (c :: w) LJ _
(row_step M (.right q a c) ⟨hq, hm⟩
⟨L, w.map work ++ₛ (boundary :: Stream'.const (work M.blank)), J⟩)
simpa [Nat.add_assoc, Row.instruction, Instruction.target, Stream'.appendStream'] using hh
@[simp]theoremprefix_cons (r : ℝ) (digit : S→ℝ) (a : S)
(w : ListS) (z : ℝ) :
prefixPoint r digit (a :: w) z = r * (digit a + prefixPoint r digit w z) :=by
proof · 2
lines
simp only [prefixPoint, word, List.length_cons, pow_succ]
ring
theoremprefix_append (r : ℝ) (digit : S→ℝ) (u v : ListS) (z : ℝ) :
prefixPoint r digit (u ++ v) z = prefixPoint r digit u (prefixPoint r digit v z) :=by
proof · 2
lines
simp only [prefixPoint, word_append, List.length_append, pow_add]
ring
theoremreplacement_prefix {r : ℝ} (hr : r ≠0) (digit : S→ℝ)
(u v : ListS) (z : ℝ) :
replacement r digit u v (prefixPoint r digit u z) = prefixPoint r digit v z :=by
theoremdeterminant_one {r : ℝ} (hr : r ≠0) (u v : Fin3→ListS)
(h : ∑ i, (u i).length = ∑ i, (v i).length) :
Matrix.det (Matrix.diagonal (scales r u v)) = 1:=by
theoremreplacement_stream {B : ℕ} (hB : B≠0) (digit : S→FinB)
(u v : ListS) (s : Stream'S) :
replacement (B : ℝ)⁻¹ (fun a => (digit a : ℝ)) u v (stream digit (u ++ₛ s)) =
stream digit (v ++ₛ s) :=by
theoremprefix_mem_unit {r : ℝ} (hr : 0≤ r) (digit : S→ℝ)
(hd₀ : ∀ a, 0≤ digit a) (hd₁ : ∀ a, r * (digit a + 1) ≤1)
(w : ListS) {z : ℝ} (hz : z ∈Set.Icc (0 : ℝ) 1) :
prefixPoint r digit w z ∈Set.Icc (0 : ℝ) 1:=by
proof · 7
lines
induction w with
| nil => simpa using hz
| cons a w ih =>
rw [prefix_cons]
exact ⟨mul_nonneg hr (add_nonneg (hd₀ a) ih.1),
(mul_le_mul_of_nonneg_left (show digit a + prefixPoint r digit w z ≤
digit a + 1by linarith [ih.2]) hr).trans (hd₁ a)⟩
theoremprefix_gap {r : ℝ} (hr : 0 < r) (digit : S→ℝ)
(hd₀ : ∀ a, 0≤ digit a) (hd₁ : ∀ a, r * (digit a + 1) ≤1)
(p u v : ListS) (a b : S) {x y : ℝ}
(hx : x ∈ interval r digit (p ++ a :: u))
(hy : y ∈ interval r digit (p ++ b :: v)) :
r ^ (p.length + 1) * (digit b - digit a - 1) ≤ y - x :=by
proof · 14
lines
rw [interval_eq_image hr] at hx hy
obtain ⟨s, hs, rfl⟩ := hx
obtain ⟨t, ht, rfl⟩ := hy
have hs' := prefix_mem_unit hr.le digit hd₀ hd₁ u hs
have ht' := prefix_mem_unit hr.le digit hd₀ hd₁ v ht
rw [prefix_append, prefix_append, prefix_cons, prefix_cons]
dsimp [prefixPoint]
havehn : 0≤ r ^ p.length * r := mul_nonneg (pow_nonneg hr.le _) hr.le
havehh : 0≤ r ^ p.length * r *
(prefixPoint r digit v t - prefixPoint r digit u s + 1) :=
mul_nonneg hn (by linarith [hs'.2, ht'.1])
dsimp [prefixPoint] at hh
rw [pow_succ]
nlinarith only [hh]