Download data/lean/OAI/Combinatorics/BinaryEdit/FiniteTreeGeometry.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.06 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BinaryEdit/FiniteTreeGeometry.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/BinaryEdit/FiniteTreeGeometry.lean
-
curl -L -o FiniteTreeGeometry.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BinaryEdit/FiniteTreeGeometry.lean
7.06 kB
| import OAI.Combinatorics.BinaryEdit.FiniteTreeWords | |
| namespace OAI | |
| /-! Concrete tagged leaf states and subtree locality for the finite tree. -/ | |
| noncomputable section | |
| namespace TreeEdit.BinaryLower.FiniteTree | |
| /-- The finite leaf set, represented by ordered paths of exactly `k` edges. -/ | |
| abbrev Leaf (m k : β) := Word (Fin m) k | |
| /-- The manuscript's product of cyclic leaf coordinates. -/ | |
| abbrev State {m k : β} (Q : Leaf m k β β) := β l, ZMod (Q l) | |
| /-- A symbol retains both its leaf tag and its cyclic state. -/ | |
| abbrev Symbol {m k : β} (Q : Leaf m k β β) := Ξ£ l, ZMod (Q l) | |
| /-- Decode an actual leaf path. The fallback only totalizes this function on | |
| paths of the wrong length; the root construction never evaluates that branch. -/ | |
| def leafDecoder {m k : β} (Q : Leaf m k β β) (base : Leaf m k) | |
| (p : List (Fin m)) (x : State Q) : Symbol Q := | |
| if hp : p.length = k then β¨β¨p, hpβ©, x β¨p, hpβ©β© else β¨base, x baseβ© | |
| @[simp] theorem leafDecoder_of_length {m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (p : List (Fin m)) (hp : p.length = k) (x : State Q) : | |
| leafDecoder Q base p x = β¨β¨p, hpβ©, x β¨p, hpβ©β© := by | |
| simp [leafDecoder, hp] | |
| /-- At a valid leaf, equality is exactly equality of that leaf's state. -/ | |
| theorem leafDecoder_eq_iff {m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (p : List (Fin m)) (hp : p.length = k) (x y : State Q) : | |
| leafDecoder Q base p x = leafDecoder Q base p y β | |
| x β¨p, hpβ© = y β¨p, hpβ© := by | |
| simp [leafDecoder, hp] | |
| /-- The recursive word depends only on the coordinates below its prefix, | |
| even though ancestor shifts may offset all coordinates of the supplied state. -/ | |
| theorem nodeWord_state_congr {T m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (u : List (Fin m) β State Q) | |
| (h : β) (p : List (Fin m)) (hlen : p.length + h = k) | |
| (x y : State Q) (hagree : β l : Leaf m k, p <+: l.val β x l = y l) : | |
| nodeWord T (leafDecoder Q base) u h p x = | |
| nodeWord T (leafDecoder Q base) u h p y := by | |
| induction h generalizing p x y with | |
| | zero => | |
| have hp : p.length = k := by simpa using hlen | |
| simp only [nodeWord, List.singleton_inj] | |
| apply (leafDecoder_eq_iff Q base p hp x y).2 | |
| exact hagree β¨p, hpβ© (by rfl) | |
| | succ h ih => | |
| simp only [nodeWord] | |
| apply List.flatMap_congr | |
| intro a ha | |
| apply List.flatMap_congr | |
| intro i hi | |
| apply ih | |
| Β· simp only [List.length_append, List.length_singleton] | |
| omega | |
| Β· intro l hl | |
| have hp : p <+: l.val := (List.prefix_append p [i]).trans hl | |
| simp only [Pi.add_apply, hagree l hp] | |
| /-- The list-path and function-path presentations of the same leaf set. -/ | |
| def leafEquiv (m k : β) : Leaf m k β (Fin k β Fin m) := | |
| Equiv.vectorEquivFin (Fin m) k | |
| /-- Pull back a function-indexed cyclic state to the list-path presentation. | |
| This is just relabeling coordinates, used to connect the closed-form vectors | |
| to the list recursion. -/ | |
| def pullState {m k : β} (Q : (Fin k β Fin m) β β) | |
| (x : β l, ZMod (Q l)) : State (fun l => Q (leafEquiv m k l)) := | |
| fun l => x (leafEquiv m k l) | |
| @[simp] theorem pullState_add {m k : β} (Q : (Fin k β Fin m) β β) | |
| (x y : β l, ZMod (Q l)) : | |
| pullState Q (x + y) = pullState Q x + pullState Q y := rfl | |
| @[simp] theorem pullState_nsmul {m k : β} (Q : (Fin k β Fin m) β β) | |
| (n : β) (x : β l, ZMod (Q l)) : | |
| pullState Q (n β’ x) = n β’ pullState Q x := rfl | |
| @[simp] theorem pullState_zsmul {m k : β} (Q : (Fin k β Fin m) β β) | |
| (n : β€) (x : β l, ZMod (Q l)) : | |
| pullState Q (n β’ x) = n β’ pullState Q x := rfl | |
| /-- A nonzero residue shift changes the tagged symbol at a leaf. -/ | |
| theorem leafDecoder_ne_of_not_dvd {m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (p : List (Fin m)) (hp : p.length = k) | |
| (x z : State Q) (hz : z β¨p, hpβ© = 1) (t : β€) | |
| (ht : Β¬ (Q β¨p, hpβ© : β€) β£ t) : | |
| leafDecoder Q base p (x + t β’ z) β leafDecoder Q base p x := by | |
| intro he | |
| have he' := (leafDecoder_eq_iff Q base p hp (x + t β’ z) x).1 he | |
| have hcast : (t : ZMod (Q β¨p, hpβ©)) = 0 := by | |
| simpa [hz, add_eq_left] using he' | |
| exact ht ((ZMod.intCast_zmod_eq_zero_iff_dvd t _).1 hcast) | |
| /-- Two different singleton words have unit one-sided deficit. -/ | |
| theorem singleton_deficit_of_ne {Ξ : Type*} (a b : Ξ) (hab : a β b) : | |
| deficit 1 [a] [b] = 1 := by | |
| have hset : {n : β | β z : List Ξ, z.Sublist [a] β§ z.Sublist [b] β§ z.length = n} | |
| = {0} := by | |
| ext n | |
| constructor | |
| Β· rintro β¨z, hza, hzb, rflβ© | |
| rcases List.sublist_singleton.1 hza with rfl | rfl | |
| Β· simp | |
| Β· have : a = b := by simpa using hzb | |
| exact (hab this).elim | |
| Β· intro hn | |
| have : n = 0 := by simpa using hn | |
| subst n | |
| exact β¨[], by simpβ© | |
| unfold deficit lcs | |
| rw [hset] | |
| simp | |
| /-- The base case of finite separation, with the actual canonical deficit. -/ | |
| theorem leaf_deficit_of_not_dvd {m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (p : List (Fin m)) (hp : p.length = k) | |
| (x z : State Q) (hz : z β¨p, hpβ© = 1) (t : β€) | |
| (ht : Β¬ (Q β¨p, hpβ© : β€) β£ t) : | |
| deficit 1 [leafDecoder Q base p x] [leafDecoder Q base p (x + t β’ z)] = 1 := by | |
| apply singleton_deficit_of_ne | |
| exact (leafDecoder_ne_of_not_dvd Q base p hp x z hz t ht).symm | |
| /-- State shifts agreeing below one node produce exactly the same subtree | |
| word, giving support locality for the closed-form vectors. -/ | |
| theorem nodeWord_shift_congr {T m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (u : List (Fin m) β State Q) | |
| (h : β) (p : List (Fin m)) (hlen : p.length + h = k) | |
| (x z w : State Q) (hagree : β l : Leaf m k, p <+: l.val β z l = w l) : | |
| nodeWord T (leafDecoder Q base) u h p (x + z) = | |
| nodeWord T (leafDecoder Q base) u h p (x + w) := by | |
| apply nodeWord_state_congr Q base u h p hlen | |
| intro l hl | |
| simp only [Pi.add_apply, hagree l hl] | |
| /-- The relative input shift between source row `a` and target row `b` in a | |
| child is `(b-a+tR)` times its distinguished vector. The two support hypotheses | |
| are precisely the coordinate restrictions of the explicit subtree vectors. -/ | |
| theorem child_relative_shift {T m k : β} (Q : Leaf m k β β) | |
| (base : Leaf m k) (u : List (Fin m) β State Q) | |
| (h : β) (p : List (Fin m)) (hlen : p.length + h = k) | |
| (x wp up wc : State Q) (R t : β€) (a b : β) | |
| (hu : β l : Leaf m k, p <+: l.val β up l = wc l) | |
| (hw : β l : Leaf m k, p <+: l.val β wp l = R β’ wc l) : | |
| nodeWord T (leafDecoder Q base) u h p (x + t β’ wp + b β’ up) = | |
| nodeWord T (leafDecoder Q base) u h p | |
| (x + a β’ up + ((b : β€) - (a : β€) + t * R) β’ wc) := by | |
| apply nodeWord_state_congr Q base u h p hlen | |
| intro l hl | |
| simp only [Pi.add_apply, Pi.smul_apply, hu l hl, hw l hl] | |
| simp only [zsmul_eq_mul, nsmul_eq_mul, Int.cast_add, Int.cast_sub, Int.cast_mul, | |
| Int.cast_natCast] | |
| ring | |
| end TreeEdit.BinaryLower.FiniteTree | |
| end | |
| end OAI | |