Download data/lean/OAI/Computability/DeterministicSum/PrunedTree.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.41 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DeterministicSum/PrunedTree.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/DeterministicSum/PrunedTree.lean
-
curl -L -o PrunedTree.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DeterministicSum/PrunedTree.lean
5.41 kB
| import Mathlib | |
| namespace OAI | |
| /-! Prefix-pruned coordinate trees and enumeration bounds. -/ | |
| namespace DeterministicThreeSum.Pruned | |
| open Finset | |
| structure Alphabet where | |
| radix : β | |
| weight : β β β | |
| abbrev Node := β Γ β | |
| def next (A : Alphabet) (p : Node) (v : β) : Node := | |
| (p.1*A.radix+v,p.2+A.weight v) | |
| def children (A : Alphabet) (D : β) (p : Node) : List Node := | |
| ((List.range A.radix).filter (fun v => p.2+A.weight vβ€D)).map (next A p) | |
| def expand (A : Alphabet) (D : β) (l : List Node) : List Node := | |
| l.flatMap (children A D) | |
| lemma children_length_le (A : Alphabet) (D : β) (p : Node) : | |
| (children A D p).lengthβ€A.radix := by | |
| simpa [children] using List.length_filter_le (fun v => decide (p.2+A.weight vβ€D)) (List.range A.radix) | |
| lemma mem_children_iff (A : Alphabet) (D : β) (p z : Node) : | |
| zβchildren A D p β β v, v<A.radix β§ p.2+A.weight vβ€D β§ z=next A p v := by | |
| simp only [children,List.mem_map,List.mem_filter,List.mem_range,decide_eq_true_eq] | |
| constructor | |
| Β· rintro β¨v,β¨hv,hdβ©,heβ©; exact β¨v,hv,hd,he.symmβ© | |
| Β· rintro β¨v,hv,hd,heβ©; exact β¨v,β¨hv,hdβ©,he.symmβ© | |
| lemma expand_length_le (A : Alphabet) (D : β) (l : List Node) : | |
| (expand A D l).lengthβ€l.length*A.radix := by | |
| induction l with | |
| | nil => simp [expand] | |
| | cons p l ih => | |
| have hh:=children_length_le A D p | |
| simpa only [expand,List.flatMap_cons,List.length_append,List.length_cons,Nat.add_mul,one_mul,Nat.add_comm] using Nat.add_le_add hh ih | |
| lemma expand_append (A : Alphabet) (D : β) (l m : List Node) : | |
| expand A D (l++m)=expand A D l++expand A D m := by simp [expand] | |
| lemma children_valid (A : Alphabet) (D : β) (p : Node) (z : Node) (hz : zβchildren A D p) : z.2β€D := by | |
| obtain β¨v,hv,hd,rflβ©:=(mem_children_iff ..).mp hz | |
| exact hd | |
| lemma expand_valid (A : Alphabet) (D : β) (l : List Node) : | |
| β zβexpand A D l, z.2β€D := by | |
| intro z hz | |
| obtain β¨p,hp,hzβ©:=List.mem_flatMap.mp hz | |
| exact children_valid A D p z hz | |
| lemma children_nonempty (A : Alphabet) (hA : 0<A.radix) (h0 : A.weight 0=0) | |
| (D : β) (p : Node) (hp : p.2β€D) : 0<(children A D p).length := by | |
| have hh : next A p 0βchildren A D p := (mem_children_iff ..).mpr β¨0,hA,by simpa [h0] using hp,rflβ© | |
| exact List.length_pos_of_mem hh | |
| lemma length_le_expand (A : Alphabet) (hA : 0<A.radix) (h0 : A.weight 0=0) | |
| (D : β) (l : List Node) (hl : β pβl, p.2β€D) : l.lengthβ€(expand A D l).length := by | |
| induction l with | |
| | nil => simp | |
| | cons p l ih => | |
| have hp:=children_nonempty A hA h0 D p (hl p (by simp)) | |
| have hi:=ih (by intro p hp; exact hl p (by simp [hp])) | |
| simp only [List.length_cons,expand,List.flatMap_cons,List.length_append] at * | |
| omega | |
| def enumerate (D : β) : List Alphabet β List Node | |
| | [] => [(0,0)] | |
| | A::rest => expand A D (enumerate D rest) | |
| def volume : List Alphabet β β | |
| | [] => 1 | |
| | A::rest => volume rest*A.radix | |
| def degree : List Alphabet β β β β | |
| | [],_ => 0 | |
| | A::rest,c => degree rest (c/A.radix)+A.weight (c%A.radix) | |
| lemma enumerate_valid (D : β) (shape : List Alphabet) : β pβenumerate D shape, p.2β€D := by | |
| cases shape with | |
| | nil => simp [enumerate] | |
| | cons A rest => exact expand_valid A D _ | |
| lemma enumerate_child (D : β) (shape : List Alphabet) (hpos : β Aβshape, 0<A.radix) : | |
| β p, pβenumerate D shape β p.1<volume shape β§ p.2=degree shape p.1 β§ p.2β€D := by | |
| induction shape with | |
| | nil => | |
| intro p | |
| simp only [enumerate,List.mem_singleton,volume,degree] | |
| rcases p with β¨c,dβ© | |
| simp only [Prod.mk.injEq] | |
| omega | |
| | cons A rest ih => | |
| intro p | |
| have hA:=hpos A (by simp) | |
| have hrest : β Aβrest, 0<A.radix := by intro B hB; exact hpos B (by simp [hB]) | |
| rw [enumerate,expand,List.mem_flatMap] | |
| constructor | |
| Β· rintro β¨z,hz,hpβ© | |
| obtain β¨v,hv,hd,rflβ©:=(mem_children_iff ..).mp hp | |
| obtain β¨hc,he,hd'β©:=(ih hrest z).mp hz | |
| refine β¨?_,?_,hdβ© | |
| Β· simp only [next,volume] | |
| nlinarith only [Nat.mul_le_mul_right A.radix hc,hv] | |
| Β· simp only [next,degree] | |
| rw [Nat.mul_comm z.1 A.radix,Nat.mul_add_div hA,Nat.div_eq_of_lt hv] | |
| simp [Nat.add_mod,Nat.mod_eq_of_lt hv,he] | |
| Β· rintro β¨hc,he,hdβ© | |
| have hq : p.1/A.radix<volume rest := (Nat.div_lt_iff_lt_mul hA).mpr hc | |
| have hv : p.1%A.radix<A.radix := Nat.mod_lt _ hA | |
| have hdeg : degree rest (p.1/A.radix)β€D := by simp only [degree] at he; omega | |
| refine β¨(p.1/A.radix,degree rest (p.1/A.radix)),(ih hrest _).mpr β¨hq,rfl,hdegβ©,?_β© | |
| apply (mem_children_iff ..).mpr | |
| refine β¨p.1%A.radix,hv,?_,?_β© | |
| Β· change degree (A::rest) p.1β€D | |
| rw [βhe]; exact hd | |
| Β· apply Prod.ext | |
| Β· exact (Nat.div_add_mod' p.1 A.radix).symm | |
| Β· exact he | |
| lemma length_enumerate_suffix (D : β) (front back : List Alphabet) | |
| (hpos : β Aβfront, 0<A.radix) (hzero : β Aβfront, A.weight 0=0) : | |
| (enumerate D back).lengthβ€(enumerate D (front++back)).length := by | |
| induction front with | |
| | nil => simp | |
| | cons A front ih => | |
| have hA:=hpos A (by simp) | |
| have h0:=hzero A (by simp) | |
| have hi:=ih (by intro B h; exact hpos B (by simp [h])) (by intro B h; exact hzero B (by simp [h])) | |
| exact hi.trans (length_le_expand A hA h0 D _ (enumerate_valid D _)) | |
| end DeterministicThreeSum.Pruned | |
| end OAI | |