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 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 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 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 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