Download data/lean/OAI/Computability/FiniteCompiler/Quotients.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 87.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FiniteCompiler/Quotients.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/FiniteCompiler/Quotients.lean
-
curl -L -o Quotients.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FiniteCompiler/Quotients.lean
87.5 kB
import OAI.Computability.FiniteCompiler.Selectors
import OAI.Computability.FiniteCompiler.Effectivity
import OAI.GroupTheory.BooneHigman.Basic
import OAI.GroupTheory.BooneHigman.WordProblem
namespace OAI
/-!
Canonical compiler quotients and effective tested classes for word problems.
-/
namespace FiniteAlgebraicEnvelopes.Bootstrap
open Relation
namespace BlockCode
variable {A B S : Type*} (C : BlockCode A S)
def Alphabet : Set S := {s | β a, s β C.block a}
theorem mem_alphabet {w : List A} {s : S} (h : s β C.encode w) : s β C.Alphabet := by
obtain β¨a,_,haβ© := List.mem_flatMap.mp h
exact β¨a,haβ©
theorem encode_ne_nil {w : List A} (h : w β []) : C.encode w β [] := by
intro he
exact h (C.encode_injective (he.trans C.encode_nil.symm))
theorem disjoint_infix (D : BlockCode B S) (hd : Disjoint C.Alphabet D.Alphabet)
{w : List A} {v : List B} (hv : v β []) (hi : D.encode v <:+: C.encode w) : False := by
obtain β¨s,hsβ© := List.exists_mem_of_ne_nil _ (D.encode_ne_nil hv)
exact Set.disjoint_left.mp hd (C.mem_alphabet (hi.subset hs)) (D.mem_alphabet hs)
theorem disjoint_overlap (D : BlockCode B S) (hd : Disjoint C.Alphabet D.Alphabet)
{u : List A} {v : List B} {p m q : List S} (hm : m β [])
(hu : C.encode u=p++m) (hv : D.encode v=m++q) : False := by
obtain β¨s,hsβ© := List.exists_mem_of_ne_nil _ hm
exact Set.disjoint_left.mp hd (C.mem_alphabet (hu βΈ List.mem_append_right p hs))
(D.mem_alphabet (hv βΈ List.mem_append_left q hs))
end BlockCode
namespace Static
variable {S A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (z : S)
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_support {n : β} {p : List S Γ List S} (hp : p β table C wf q z n) :
p.1 β [] β§ β s β p.1,s β C.Alphabet := by
rcases p with β¨u,vβ©
obtain β¨w,_,hn,_,rfl,rflβ© := (mem_table C wf q z).mp hp
exact β¨C.encode_ne_nil hn,fun _ hs => C.mem_alphabet hsβ©
omit [DecidableEq A] [DecidableEq Q] in
theorem table_decrease {s : S β S β Prop} (hwidth : 1<C.width+1)
(hc : β a b, r a b β List.Lex s (C.block a) (C.block b)) (n : β) :
β p β table C wf q z n,List.Shortlex s p.2 p.1 := by
intro β¨u,vβ© hp
obtain β¨w,_,hn,he,rfl,rflβ© := (mem_table C wf q z).mp hp
unfold output
split
Β· apply List.Shortlex.of_length_lt
simp only [List.length_singleton,C.encode_length]
have hw : 1 β€ w.length := by have := List.length_pos_iff.mpr hn; omega
nlinarith
Β· obtain h | h := Canonical.least_lt_or_eq wf q w
Β· exact C.encode_shortlex hc h
Β· exact False.elim (he (by simp_all [output]))
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_bounded {k n : β} (hkn : k β€ n) :
Selectors.BoundedEq (table C wf q z (k/(C.width+1))) (table C wf q z (n/(C.width+1))) k := by
intro β¨u,vβ© hu
simp only [mem_table]
constructor
Β· rintro β¨w,hw,hn,he,rfl,rflβ©
exact β¨w,hw.trans (Nat.div_le_div_right hkn),hn,he,rfl,rflβ©
Β· rintro β¨w,hw,hn,he,rfl,rflβ©
refine β¨w,?_,hn,he,rfl,rflβ©
apply (Nat.le_div_iff_mul_le (Nat.succ_pos _)).mpr
simpa only [C.encode_length,Nat.mul_comm] using hu
omit [DecidableEq A] [DecidableEq Q] in
theorem critical_containment_bound {n : β} {rs : List (List S Γ List S)}
(hzero : q [] β none) (hz : Absorbs rs z)
(ht : β p β table C wf q z (n/(C.width+1)), p β rs)
(hc : Contextual q (n/(C.width+1))) (hi : ZeroIdeal q (n/(C.width+1)))
{u u' v v' x y : List S}
(hu : (u,u') β table C wf q z (n/(C.width+1)))
(hv : (v,v') β table C wf q z (n/(C.width+1)))
(he : u=x++v++y) (hlen : u.length β€ n) : Join (Steps rs) u' (x++v'++y) := by
apply critical_containment C wf q z hzero hz ht hc hi hu hv he
obtain β¨w,hw,_,_,rfl,_β© := (mem_table C wf q z).mp hu
simpa only [C.encode_length] using Nat.mul_le_mul_left (C.width+1) hw
omit [DecidableEq A] [DecidableEq Q] in
theorem critical_overlap_bound {n : β} {rs : List (List S Γ List S)}
(hzero : q [] β none) (hz : Absorbs rs z)
(ht : β p β table C wf q z (n/(C.width+1)), p β rs)
(hc : Contextual q (n/(C.width+1))) (hi : ZeroIdeal q (n/(C.width+1)))
{u u' v v' p m t : List S}
(hu : (u,u') β table C wf q z (n/(C.width+1)))
(hv : (v,v') β table C wf q z (n/(C.width+1)))
(hm : m β []) (he : u=p++m) (hf : v=m++t) (hlen : (p++m++t).length β€ n) :
Join (Steps rs) (u'++t) (p++v') := by
apply critical_overlap C wf q z hzero hz ht hc hi hu hv hm he hf
obtain β¨a,_,_,_,rfl,_β© := (mem_table C wf q z).mp hu
obtain β¨b,_,_,_,rfl,_β© := (mem_table C wf q z).mp hv
obtain β¨c,d,e,rfl,rfl,rfl,rfl,rflβ© := C.overlap_decode hm he hf
have hh : (C.width+1)*(c++d++e).length β€ n := by
simpa only [β C.encode_append,C.encode_length] using hlen
have hdiv : (c++d++e).length β€ n/(C.width+1) :=
(Nat.le_div_iff_mul_le (Nat.succ_pos _)).mpr (by simpa [Nat.mul_comm] using hh)
simpa only [β C.encode_append,C.encode_length] using Nat.mul_le_mul_left (C.width+1) hdiv
end Static
namespace Base
variable {S A B Q R : Type*} [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop} [Std.Trichotomous r] [Std.Trichotomous s]
variable (C : BlockCode A S) (D : BlockCode B S) (wf : WellFounded r) (wg : WellFounded s)
(f : List A β Option Q) (g : List B β Option R) (z : S)
noncomputable def absorption : List (List S Γ List S) :=
(Static.letters S).flatMap fun a => [([z,a],[z]),([a,z],[z])]
omit [DecidableEq S] in
@[simp] theorem mem_absorption {u v : List S} : (u,v) β absorption z β
β a, (u=[z,a] β¨ u=[a,z]) β§ v=[z] := by
simp only [absorption,Static.letters,List.mem_flatMap,Finset.mem_toList,Finset.mem_univ,true_and,
List.mem_cons,List.not_mem_nil,or_false,Prod.mk.injEq]
aesop
noncomputable def table (n : β) : List (List S Γ List S) :=
absorption z ++ Static.table C wf f z (n/(C.width+1)) ++ Static.table D wg g z (n/(D.width+1))
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem mem_table {n : β} {p : List S Γ List S} : p β table C D wf wg f g z n β
p β absorption z β¨ p β Static.table C wf f z (n/(C.width+1)) β¨
p β Static.table D wg g z (n/(D.width+1)) := by
simp only [table,List.mem_append,or_assoc]
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem absorbs (n : β) : Absorbs (table C D wf wg f g z n) z := by
intro a
constructor <;> apply (mem_table C D wf wg f g z).mpr <;> apply Or.inl <;>
apply (mem_absorption z).mpr
Β· exact β¨a,Or.inl rfl,rflβ©
Β· exact β¨a,Or.inr rfl,rflβ©
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem preserves_zero (hC : z β C.Alphabet) (hD : z β D.Alphabet) (n : β) :
β p β table C D wf wg f g z n, z β p.1 β z β p.2 := by
intro β¨u,vβ© hp hu
rcases (mem_table C D wf wg f g z).mp hp with hp | hp | hp
Β· obtain β¨a,_,rflβ© := (mem_absorption z).mp hp
simp
Β· exact False.elim (hC ((Static.table_support C wf f z hp).2 z hu))
Β· exact False.elim (hD ((Static.table_support D wg g z hp).2 z hu))
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R] in
/-- All static and absorption critical pairs for the literal two-code base table. -/
theorem critical (hC : z β C.Alphabet) (hD : z β D.Alphabet)
(hdis : Disjoint C.Alphabet D.Alphabet) {n : β}
(hf : f [] β none) (hg : g [] β none)
(hfc : Static.Contextual f (n/(C.width+1))) (hfi : Static.ZeroIdeal f (n/(C.width+1)))
(hgc : Static.Contextual g (n/(D.width+1))) (hgi : Static.ZeroIdeal g (n/(D.width+1))) :
Critical (table C D wf wg f g z n) n := by
let rs := table C D wf wg f g z n
have hz : Absorbs rs z := absorbs C D wf wg f g z n
have hp := preserves_zero C D wf wg f g z hC hD n
have hCt : β p β Static.table C wf f z (n/(C.width+1)),p β rs :=
fun _ h => (mem_table C D wf wg f g z).mpr (.inr (.inl h))
have hDt : β p β Static.table D wg g z (n/(D.width+1)),p β rs :=
fun _ h => (mem_table C D wf wg f g z).mpr (.inr (.inr h))
have hzero {w u v : List S} (hw : z β w) (hu : Step rs w u) (hv : Step rs w v) :
Join (Steps rs) u v :=
β¨[z],absorbs_mem hz (step_preserves_letter hp hw hu),
absorbs_mem hz (step_preserves_letter hp hw hv)β©
have hnabs {u v : List S} (h : z β u) : (u,v) β absorption z := by
rintro hh
obtain β¨a,ha,_β© := (mem_absorption z).mp hh
rcases ha with rfl | rfl <;> simp at h
constructor
Β· intro u u' v v' hu hv x y he hlen
by_cases huz : z β u
Β· apply hzero huz
Β· simpa using Step.apply hu [] []
Β· simpa only [he] using Step.apply hv x y
have hvz : z β v := fun hh => huz (by simp [he,hh])
have hu' := (mem_table C D wf wg f g z).mp hu
have hv' := (mem_table C D wf wg f g z).mp hv
simp only [hnabs huz,hnabs hvz,false_or] at hu' hv'
rcases hu' with hu' | hu' <;> rcases hv' with hv' | hv'
Β· exact Static.critical_containment_bound C wf f z hf hz hCt hfc hfi hu' hv' he hlen
Β· obtain β¨a,_,_,_,rfl,_β© := (Static.mem_table C wf f z).mp hu'
obtain β¨b,_,hb,_,rfl,_β© := (Static.mem_table D wg g z).mp hv'
exact False.elim (C.disjoint_infix D hdis hb β¨x,y,he.symmβ©)
Β· obtain β¨a,_,_,_,rfl,_β© := (Static.mem_table D wg g z).mp hu'
obtain β¨b,_,hb,_,rfl,_β© := (Static.mem_table C wf f z).mp hv'
exact False.elim (D.disjoint_infix C hdis.symm hb β¨x,y,he.symmβ©)
Β· exact Static.critical_containment_bound D wg g z hg hz hDt hgc hgi hu' hv' he hlen
Β· intro u u' v v' hu hv p m t hm he hh hlen
by_cases hwz : z β p++m++t
Β· apply hzero hwz
Β· simpa only [he,List.nil_append,List.append_assoc] using Step.apply hu [] t
Β· simpa only [hh,List.append_nil,List.append_assoc] using Step.apply hv p []
have huz : z β u := fun h => hwz (by simp [βhe,h])
have hvz : z β v := fun h => hwz (by simpa only [List.append_assoc,βhh,List.mem_append] using Or.inr h)
have hu' := (mem_table C D wf wg f g z).mp hu
have hv' := (mem_table C D wf wg f g z).mp hv
simp only [hnabs huz,hnabs hvz,false_or] at hu' hv'
rcases hu' with hu' | hu' <;> rcases hv' with hv' | hv'
Β· exact Static.critical_overlap_bound C wf f z hf hz hCt hfc hfi hu' hv' hm he hh hlen
Β· obtain β¨a,_,_,_,rfl,_β© := (Static.mem_table C wf f z).mp hu'
obtain β¨b,_,_,_,rfl,_β© := (Static.mem_table D wg g z).mp hv'
exact False.elim (C.disjoint_overlap D hdis hm he hh)
Β· obtain β¨a,_,_,_,rfl,_β© := (Static.mem_table D wg g z).mp hu'
obtain β¨b,_,_,_,rfl,_β© := (Static.mem_table C wf f z).mp hv'
exact False.elim (D.disjoint_overlap C hdis.symm hm he hh)
Β· exact Static.critical_overlap_bound D wg g z hg hz hDt hgc hgi hu' hv' hm he hh hlen
end Base
open Relation
variable {S : Type*} [DecidableEq S] {r : S β S β Prop}
omit [DecidableEq S] in
theorem steps_bounded {rs rt : List (List S Γ List S)} {k : β}
(hh : Selectors.BoundedEq rs rt k)
(hd : β p β rs,List.Shortlex r p.2 p.1) {u v : List S} (hu : u.length β€ k)
(h : Steps rs u v) : Steps rt u v := by
induction h with
| refl => exact .refl
| tail h hs ih => exact ih.tail ((step_stable hh ((steps_length hd h).trans hu)).mp hs)
/-- The actual partial table-first procedure used at the fixed point. -/
def tableNormal (T : β β Part (List (List S Γ List S))) (w : List S) : Part (List S) :=
(T w.length).bind (fun rs => evaluate rs w)
/-- A successful table has all the finite mathematical certificates needed by
the bounded Newman argument. No totality of the program is part of this. -/
def GoodTable (T : β β Part (List (List S Γ List S))) (n : β) : Prop :=
β rs β T n, (β p β rs,List.Shortlex r p.2 p.1) β§ Critical rs n
theorem tableNormal_at {T : β β Part (List (List S Γ List S))} {n : β}
(wf : WellFounded r) (ht : β k β€ n,GoodTable (r:=r) T k)
(hs : β k β€ n,β rk β T k,β rn β T n,Selectors.BoundedEq rk rn k)
{rn : List (List S Γ List S)} (hrn : rn β T n) {w : List S} (hw : w.length β€ n) :
tableNormal T w=evaluate rn w := by
obtain β¨rk,hrk,hdk,hckβ© := ht w.length hw
obtain β¨rt,hrt,hdt,hctβ© := ht n le_rfl
have he := Part.mem_unique hrt hrn
subst rt
obtain β¨u,huβ© := Part.dom_iff_mem.mp (evaluate_total (steps_wellFounded wf hdk) w)
obtain β¨v,hvβ© := Part.dom_iff_mem.mp (evaluate_total (steps_wellFounded wf hdt) w)
obtain β¨hwu,huIβ© := evaluate_sound hu
obtain β¨hwv,hvIβ© := evaluate_sound hv
have hstab := hs w.length hw rk hrk rn hrn
have hwu' := steps_bounded hstab hdk le_rfl hwu
have huI' := (Selectors.irreducible_bounded hstab (steps_length hdk hwu)).mp huI
have huv := evaluate_unique_on wf hdt n (fun _ _ _ h => critical_localJoin hct h)
hw hwu' hwv huI' hvI
subst v
rw [tableNormal,Part.eq_some_iff.mpr hrk,Part.bind_some]
exact (Part.eq_some_iff.mpr hu).trans (Part.eq_some_iff.mpr hv).symm
/-- This is the whole contextual-induction step, including the table at the
shortened contextual endpoint and irreducibility in the larger table. -/
theorem tableNormal_budget {T : β β Part (List (List S Γ List S))} {n : β}
(wf : WellFounded r) (ht : β k β€ n,GoodTable (r:=r) T k)
(hs : β k m, k β€ m β m β€ n β β rk β T k,β rm β T m,Selectors.BoundedEq rk rm k) :
Compiler.PartialBudget (tableNormal T) n := by
have htotal (w : List S) (hw : w.length β€ n) : (tableNormal T w).Dom := by
obtain β¨rs,hrs,hd,hcβ© := ht w.length hw
rw [tableNormal,Part.eq_some_iff.mpr hrs,Part.bind_some]
exact evaluate_total (steps_wellFounded wf hd) w
have hlen (w : List S) (hw : w.length β€ n) (out : List S) (ho : out β tableNormal T w) :
out.length β€ w.length := by
obtain β¨rs,hrs,hd,hcβ© := ht w.length hw
rw [tableNormal,Part.eq_some_iff.mpr hrs,Part.bind_some] at ho
exact steps_length hd (evaluate_sound ho).1
refine β¨htotal,hlen,?_β©
intro x w y hlenxy out hout
obtain β¨rs,hrs,hd,hcβ© := ht n le_rfl
have hw : w.length β€ n := by simp only [List.length_append] at hlenxy; omega
have hlenout := hlen w hw out hout
have hshort : (x++out++y).length β€ n := by simp only [List.length_append] at hlenxy β’; omega
have heq (v : List S) (hv : v.length β€ n) : tableNormal T v = evaluate rs v :=
tableNormal_at wf ht (fun k hk => hs k n hk le_rfl) hrs hv
have ehw := heq w hw
rw [ehw] at hout
rw [heq _ hshort,heq _ hlenxy]
exact evaluate_context_on wf hd n (fun _ _ _ h => critical_localJoin hc h) hout x y hlenxy
/-- The source's simultaneous length induction, for the table builder actually
fed to the recursion theorem. `build` only receives strictly smaller budgets.
Thus this lemma never assumes the desired total/contextual program outright. -/
theorem bootstrap_length_induction (wf : WellFounded r)
(T : β β Part (List (List S Γ List S))) (f : List S β Part (List S))
(fixed : f=tableNormal T)
(stable : β k n, k β€ n β β rk β T k,β rn β T n,Selectors.BoundedEq rk rn k)
(build : β n, (β m<n,Compiler.PartialBudget f m) β GoodTable (r:=r) T n) :
β n, GoodTable (r:=r) T n β§ Compiler.PartialBudget f n := by
intro n
induction n using Nat.strong_induction_on with
| h n ih =>
have hn := build n (fun m hm => (ih m hm).2)
refine β¨hn,?_β©
rw [fixed]
apply tableNormal_budget wf
Β· intro k hk
rcases lt_or_eq_of_le hk with hk | rfl
Β· exact (ih k hk).1
Β· exact hn
Β· intro k m hkm _
exact stable k m hkm
end FiniteAlgebraicEnvelopes.Bootstrap
namespace FiniteAlgebraicEnvelopes
namespace Effect
variable {X A B : Type*}
theorem traverse_comp (f : A β Part B) (g : X β A) (l : List X) :
traverse (fun x => f (g x)) l=traverse f (l.map g) := by
induction l with
| nil => rfl
| cons x l ih => simp only [traverse,List.map_cons,ih]
theorem traverse_domain {f : A β Part B} {l : List A} (h : (traverse f l).Dom) :
β aβl,(f a).Dom := by
induction l with
| nil => simp
| cons a l ih =>
obtain β¨out,hoβ© := Part.dom_iff_mem.mp h
obtain β¨b,hb,htβ© := Part.mem_bind_iff.mp ho
obtain β¨bs,hbs,_β© := (Part.mem_map_iff _).mp ht
intro x hx
rcases List.mem_cons.mp hx with rfl | hx
Β· exact hb.1
Β· exact ih hbs.1 x hx
theorem partrec_traverse_parameter [Primcodable X] [Primcodable A] [Primcodable B]
{f : X β A β Part B} (hf : Partrecβ f) : Partrecβ (fun x => traverse (f x)) := by
have hp : Primrec (fun p : X Γ List A => p.2.map (p.1,Β·)) :=
Primrec.list_map Primrec.snd ((Primrec.fst.comp Primrec.fst).pair Primrec.snd).toβ
exact ((partrec_traverse hf).comp hp.to_comp).of_eq (by
intro p
exact (traverse_comp (Function.uncurry f) (p.1,Β·) p.2).symm)
end Effect
namespace Bootstrap
namespace Search
variable {A S Q : Type*} [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [DecidableRel (List.Shortlex r)]
noncomputable def value (f : List A β Part (Option Q)) (w : List A) : Option Q := by
classical
exact if h : (f w).Dom then (f w).get h else none
omit [DecidableEq A] [DecidableEq S] [DecidableEq Q] [DecidableRel (List.Shortlex r)] in
theorem value_mem {f : List A β Part (Option Q)} {w : List A} (h : (f w).Dom) : value f w β f w := by
simp only [value,dite_eq_left h]
exact Part.get_mem h
variable [Fintype A] [Std.Trichotomous r] (wf : WellFounded r)
omit [DecidableEq A] [Std.Trichotomous r] in
theorem compute_domain (C : BlockCode A S) (z : S) {f : List A β Part (Option Q)} {n : β}
(hc : (compute (r:=r) C z f n).Dom) : β w,w.length β€ n β (f w).Dom := by
obtain β¨rs,hrsβ© := Part.dom_iff_mem.mp hc
obtain β¨ps,hps,_β© := (Part.mem_map_iff _).mp hrs
have ht := Effect.traverse_domain hps.1
intro w hw
have hww := ht w ((Static.mem_words _ _).mpr hw)
obtain β¨p,hpβ© := Part.dom_iff_mem.mp hww
obtain β¨v,hv,_β© := (Part.mem_map_iff _).mp hp
exact hv.1
omit [DecidableEq A] in
theorem compute_eq (C : BlockCode A S) (z : S) {f : List A β Part (Option Q)} {n : β}
{rs : List (List S Γ List S)} (hc : rs β compute (r:=r) C z f n) :
rs=Static.table C wf (value f) z n := by
exact Part.mem_unique hc (compute_full wf (value f) C z
(fun w hw => value_mem (compute_domain C z hc.1 w hw)))
omit [DecidableEq A] [Std.Trichotomous r] in
theorem partrec_compute_parameter {X : Type*} [Primcodable X]
[Primcodable A] [Primcodable S] [Primcodable Q]
(C : BlockCode A S) (z : S) (hr : PrimrecRel (List.Shortlex r))
{f : X β List A β Part (Option Q)} (hf : Partrecβ f) :
Partrecβ (fun x => compute (r:=r) C z (f x)) := by
have hp : Partrecβ (fun x w => (f x w).map (w,Β·)) :=
(hf.map ((Computable.snd.comp Computable.fst).pair Computable.snd).toβ).toβ
exact (((Effect.partrec_traverse_parameter hp).comp Computable.fst
(primrec_words.to_comp.comp Computable.snd)).map
((primrec_table (Q:=Q) C z hr).to_comp.comp Computable.snd).toβ).toβ
end Search
namespace Build
variable {S A B Q R : Type*} [Primcodable S] [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop}
[DecidableRel (List.Shortlex r)] [DecidableRel (List.Shortlex s)]
variable (a : Selectors.Markers S) (C : BlockCode A S) (D : BlockCode B S)
noncomputable def bases (f : List A β Part (Option Q)) (g : List B β Part (Option R)) (n : β) :
Part (List (List S Γ List S)) :=
(Search.compute (r:=r) C a.zero f (n/(C.width+1))).bind fun rc =>
(Search.compute (r:=s) D a.zero g (n/(D.width+1))).map fun rd => Base.absorption a.zero ++ rc ++ rd
noncomputable def tables (f : List A β Part (Option Q)) (g : List B β Part (Option R)) (n : β) :
Part (List (List S Γ List S)) :=
(bases (r:=r) (s:=s) a C D f g n).map fun b =>
Selectors.process (a:=a) b (Selectors.stages a.zero) n n
variable [Std.Trichotomous r] [Std.Trichotomous s] (wf : WellFounded r) (wg : WellFounded s)
omit [Primcodable S] [DecidableEq A] [DecidableEq B] in
theorem bases_eq {f : List A β Part (Option Q)} {g : List B β Part (Option R)}
{n : β} {rs : List (List S Γ List S)} (h : rs β bases (r:=r) (s:=s) a C D f g n) :
rs=Base.table C D wf wg (Search.value f) (Search.value g) a.zero n := by
obtain β¨rc,hrc,htβ© := Part.mem_bind_iff.mp h
obtain β¨rd,hrd,rflβ© := (Part.mem_map_iff _).mp ht
rw [Search.compute_eq wf C a.zero hrc,Search.compute_eq wg D a.zero hrd]
rfl
omit [DecidableEq A] [DecidableEq B] in
theorem tables_eq {f : List A β Part (Option Q)} {g : List B β Part (Option R)}
{n : β} {rs : List (List S Γ List S)} (h : rs β tables (r:=r) (s:=s) a C D f g n) :
rs=Selectors.process (a:=a) (Base.table C D wf wg (Search.value f) (Search.value g) a.zero n)
(Selectors.stages a.zero) n n := by
obtain β¨b,hb,rflβ© := (Part.mem_map_iff _).mp h
rw [bases_eq a C D wf wg hb]
variable [Primcodable A] [Primcodable B] [Primcodable Q] [Primcodable R]
variable {X : Type*} [Primcodable X]
variable {F : X β List A β Part (Option Q)} {G : X β List B β Part (Option R)}
omit [DecidableEq A] [DecidableEq B] [Std.Trichotomous r] [Std.Trichotomous s] in
theorem partrec_bases_parameter (hr : PrimrecRel (List.Shortlex r))
(hs : PrimrecRel (List.Shortlex s)) (hF : Partrecβ F) (hG : Partrecβ G) :
Partrecβ (fun x => bases (r:=r) (s:=s) a C D (F x) (G x)) := by
have hc : Partrec (fun p : X Γ β => Search.compute (r:=r) C a.zero (F p.1) (p.2/(C.width+1))) :=
(Search.partrec_compute_parameter C a.zero hr hF).comp Computable.fst
(Primrec.nat_div.to_comp.comp Computable.snd (Computable.const _))
have hd : Partrec (fun p : (X Γ β) Γ List (List S Γ List S) =>
Search.compute (r:=s) D a.zero (G p.1.1) (p.1.2/(D.width+1))) :=
(Search.partrec_compute_parameter D a.zero hs hG).comp (Computable.fst.comp Computable.fst)
(Primrec.nat_div.to_comp.comp (Computable.snd.comp Computable.fst) (Computable.const _))
exact (hc.bind (hd.map (Primrec.list_append.to_comp.comp
(Primrec.list_append.to_comp.comp (Computable.const (Base.absorption a.zero))
(Computable.snd.comp Computable.fst)) Computable.snd).toβ).toβ).toβ
omit [DecidableEq A] [DecidableEq B] [Std.Trichotomous r] [Std.Trichotomous s] in
theorem partrec_tables_parameter (hr : PrimrecRel (List.Shortlex r))
(hs : PrimrecRel (List.Shortlex s)) (hF : Partrecβ F) (hG : Partrecβ G) :
Partrecβ (fun x => tables (r:=r) (s:=s) a C D (F x) (G x)) := by
have hb := partrec_bases_parameter a C D hr hs hF hG
exact (hb.map ((Selectors.primrec_process a _ (Selectors.primrec_stages a.zero)).to_comp.comp
(Computable.snd.pair (Computable.snd.comp Computable.fst))
(Computable.snd.comp Computable.fst)).toβ).toβ
end Build
theorem partrec_tableNormal_parameter {X S : Type*} [DecidableEq S]
[Primcodable X] [Primcodable S] {T : X β β β Part (List (List S Γ List S))}
(ht : Partrecβ T) : Partrecβ (fun x => tableNormal (T x)) := by
exact ((ht.comp Computable.fst (Primrec.list_length.to_comp.comp Computable.snd)).bind
(partrec_evaluate.comp Computable.snd (Computable.snd.comp Computable.fst)).toβ).toβ
end Bootstrap
end FiniteAlgebraicEnvelopes
namespace FiniteAlgebraicEnvelopes.Bootstrap
section
namespace Base
variable {S A B Q R : Type*} [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop} [Std.Trichotomous r] [Std.Trichotomous s]
variable (C : BlockCode A S) (D : BlockCode B S) (wf : WellFounded r) (wg : WellFounded s)
(f : List A β Option Q) (g : List B β Option R) (z : S)
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem bounded {k n : β} (hkn : k β€ n) :
Selectors.BoundedEq (table C D wf wg f g z k) (table C D wf wg f g z n) k := by
intro p hp
rw [mem_table,mem_table]
exact or_congr Iff.rfl (or_congr (Static.table_bounded C wf f z hkn p hp)
(Static.table_bounded D wg g z hkn p hp))
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R] in
theorem decrease {t : S β S β Prop} (hcw : 1<C.width+1) (hdw : 1<D.width+1)
(hc : β a b,r a b β List.Lex t (C.block a) (C.block b))
(hd : β a b,s a b β List.Lex t (D.block a) (D.block b)) (n : β) :
β p β table C D wf wg f g z n,List.Shortlex t p.2 p.1 := by
intro β¨u,vβ© hp
rcases (mem_table C D wf wg f g z).mp hp with hp | hp | hp
Β· obtain β¨a,hu,rflβ© := (mem_absorption z).mp hp
rcases hu with rfl | rfl <;> exact List.Shortlex.of_length_lt (by simp)
Β· exact Static.table_decrease C wf f z hcw hc _ _ hp
Β· exact Static.table_decrease D wg g z hdw hd _ _ hp
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem shapes (a : Selectors.Markers S)
(hC : β bβ[a.d,a.l,a.r,a.h],bβC.Alphabet)
(hD : β bβ[a.d,a.l,a.r,a.h],bβD.Alphabet) (n : β) :
β p β table C D wf wg f g a.zero n,
a.zeroβp.1 β¨ (p.1β [] β§ a.dβp.1 β§ a.lβp.1 β§ a.rβp.1 β§ a.hβp.1) := by
intro β¨u,vβ© hp
rcases (mem_table C D wf wg f g a.zero).mp hp with hp | hp | hp
Β· obtain β¨b,hu,_β© := (mem_absorption a.zero).mp hp
rcases hu with rfl | rfl <;> exact Or.inl (by simp)
Β· obtain β¨hn,hsβ© := Static.table_support C wf f a.zero hp
exact Or.inr β¨hn,fun h => hC _ (by simp) (hs _ h),fun h => hC _ (by simp) (hs _ h),
fun h => hC _ (by simp) (hs _ h),fun h => hC _ (by simp) (hs _ h)β©
Β· obtain β¨hn,hsβ© := Static.table_support D wg g a.zero hp
exact Or.inr β¨hn,fun h => hD _ (by simp) (hs _ h),fun h => hD _ (by simp) (hs _ h),
fun h => hD _ (by simp) (hs _ h),fun h => hD _ (by simp) (hs _ h)β©
end Base
namespace Build
variable {S A B Q R : Type*} [Primcodable S] [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop}
[DecidableRel (List.Shortlex r)] [DecidableRel (List.Shortlex s)]
[Std.Trichotomous r] [Std.Trichotomous s]
variable (a : Selectors.Markers S) (C : BlockCode A S) (D : BlockCode B S)
(wf : WellFounded r) (wg : WellFounded s)
variable (f : List A β Part (Option Q)) (g : List B β Part (Option R))
omit [Primcodable S] [DecidableEq A] [DecidableEq B] in
theorem bases_full {n : β}
(hf : β w,w.length β€ n/(C.width+1) β (f w).Dom)
(hg : β w,w.length β€ n/(D.width+1) β (g w).Dom) :
Base.table C D wf wg (Search.value f) (Search.value g) a.zero n β bases (r:=r) (s:=s) a C D f g n := by
refine Part.mem_bind_iff.mpr β¨_,Search.compute_full wf (Search.value f) C a.zero
(fun w hw => Search.value_mem (hf w hw)),?_β©
exact (Part.mem_map_iff _).mpr β¨_,Search.compute_full wg (Search.value g) D a.zero
(fun w hw => Search.value_mem (hg w hw)),rflβ©
omit [DecidableEq A] [DecidableEq B] in
theorem tables_full {n : β}
(hf : β w,w.length β€ n/(C.width+1) β (f w).Dom)
(hg : β w,w.length β€ n/(D.width+1) β (g w).Dom) :
Selectors.process (a:=a) (Base.table C D wf wg (Search.value f) (Search.value g) a.zero n)
(Selectors.stages a.zero) n n β tables (r:=r) (s:=s) a C D f g n :=
(Part.mem_map_iff _).mpr β¨_,bases_full a C D wf wg f g hf hg,rflβ©
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
theorem stable {k n : β} (hkn : k β€ n) {rk rn : List (List S Γ List S)}
(hk : rk β tables (r:=r) (s:=s) a C D f g k)
(hn : rn β tables (r:=r) (s:=s) a C D f g n) : Selectors.BoundedEq rk rn k := by
rw [tables_eq a C D wf wg hk,tables_eq a C D wf wg hn]
exact Selectors.tables_bounded
(fun _ _ hh => Base.bounded C D wf wg (Search.value f) (Search.value g) a.zero hh)
(fun j w hw => Selectors.body_lt_size a.zero j hw)
(Selectors.index_lt_size a.zero) hkn
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
theorem good {t : S β S β Prop} (hcw : 1<C.width+1) (hdw : 1<D.width+1)
(hc : β a b,r a b β List.Lex t (C.block a) (C.block b))
(hd : β a b,s a b β List.Lex t (D.block a) (D.block b))
(hC : β bβ[a.zero,a.d,a.l,a.r,a.h],bβC.Alphabet)
(hD : β bβ[a.zero,a.d,a.l,a.r,a.h],bβD.Alphabet)
(hCD : Disjoint C.Alphabet D.Alphabet) {n : β}
(hf : β w,w.length β€ n/(C.width+1) β (f w).Dom)
(hg : β w,w.length β€ n/(D.width+1) β (g w).Dom)
(hf0 : Search.value f []β none) (hg0 : Search.value g []β none)
(hfc : Static.Contextual (Search.value f) (n/(C.width+1)))
(hfi : Static.ZeroIdeal (Search.value f) (n/(C.width+1)))
(hgc : Static.Contextual (Search.value g) (n/(D.width+1)))
(hgi : Static.ZeroIdeal (Search.value g) (n/(D.width+1))) :
GoodTable (r:=t) (tables (r:=r) (s:=s) a C D f g) n := by
refine β¨_,tables_full a C D wf wg f g hf hg,?_,?_β©
Β· exact Selectors.process_decrease
(Base.decrease C D wf wg (Search.value f) (Search.value g) a.zero hcw hdw hc hd n) _ _ _
Β· apply Selectors.process_critical
Β· exact Base.absorbs C D wf wg (Search.value f) (Search.value g) a.zero n
Β· exact Base.preserves_zero C D wf wg (Search.value f) (Search.value g) a.zero
(hC _ (by simp)) (hD _ (by simp)) n
Β· exact Base.shapes C D wf wg (Search.value f) (Search.value g) a
(fun b hb => hC b (List.mem_cons_of_mem _ hb))
(fun b hb => hD b (List.mem_cons_of_mem _ hb)) n
Β· intro j w hw
exact β¨Selectors.body_lt_size a.zero j hw,(Selectors.tuples_valid a.zero j).2.2 w hwβ©
Β· exact fun _ _ hh _ hw => Selectors.stage_spacing a hh hw
Β· exact Base.critical C D wf wg (Search.value f) (Search.value g) a.zero
(hC _ (by simp)) (hD _ (by simp)) hCD hf0 hg0 hfc hfi hgc hgi
end Build
namespace Quotient
open Relation
variable {S : Type*} [DecidableEq S]
variable (T : β β Part (List (List S Γ List S)))
/-- Literal equations of the stabilized infinite table. Restricting a stage to
its own budget removes only premature copies of the fixed absorption rules. -/
def Rel (u v : FreeMonoid S) : Prop :=
β n rs, rs β T n β§ (u.toList,v.toList) β rs β§ u.toList.length β€ n
abbrev Mon := PresentedMonoid (Rel T)
def present (w : List S) : Mon T := PresentedMonoid.mk (Rel T) (FreeMonoid.ofList w)
noncomputable def normal (w : List S) : List S := Compiler.partValue (tableNormal T w)
omit [DecidableEq S] in
@[simp] theorem present_nil : present T []=1 := rfl
omit [DecidableEq S] in
@[simp] theorem present_append (u v : List S) : present T (u++v)=present T u * present T v := rfl
omit [DecidableEq S] in
theorem present_step {n : β} {rs : List (List S Γ List S)} (hrs : rs β T n)
{u v : List S} (hu : u.length β€ n) (h : Step rs u v) : present T u=present T v := by
cases h with
| @apply a b hab x y =>
have ha : a.length β€ n := by simp only [List.length_append] at hu; omega
have hh : present T a=present T b :=
PresentedMonoid.mk_eq_mk_of_rel β¨n,rs,hrs,hab,haβ©
simp only [present_append,hh]
omit [DecidableEq S] in
theorem present_steps {r : S β S β Prop} {n : β} {rs : List (List S Γ List S)}
(hrs : rs β T n) (hd : β pβrs,List.Shortlex r p.2 p.1)
{u v : List S} (hu : u.length β€ n) (h : Steps rs u v) : present T u=present T v := by
induction h with
| refl => rfl
| tail h hs ih => exact ih.trans (present_step T hrs ((steps_length hd h).trans hu) hs)
variable {r : S β S β Prop} (wf : WellFounded r)
(good : β n,GoodTable (r:=r) T n)
(stable : β k n,k β€ n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
include wf good stable
theorem budget (n : β) : Compiler.PartialBudget (tableNormal T) n :=
tableNormal_budget wf (fun _ _ => good _) (fun k m h _ => stable k m h)
theorem normal_mem (w : List S) : normal T w β tableNormal T w :=
Compiler.partValue_mem ((budget T wf good stable w.length).total w le_rfl)
theorem present_normal (w : List S) : present T w=present T (normal T w) := by
obtain β¨rs,hrs,hd,_β© := good w.length
have h := normal_mem T wf good stable w
rw [tableNormal,Part.eq_some_iff.mpr hrs,Part.bind_some] at h
exact present_steps T hrs hd le_rfl (evaluate_sound h).1
theorem normal_context (x w y : List S) :
normal T (x++normal T w++y)=normal T (x++w++y) := by
exact congrArg Compiler.partValue ((budget T wf good stable (x++w++y).length).context
x w y le_rfl _ (normal_mem T wf good stable w))
theorem normal_append (u v : List S) :
normal T (u++v)=normal T (normal T u++normal T v) := by
have hu := normal_context T wf good stable [] u v
have hv := normal_context T wf good stable (normal T u) v []
simp only [List.nil_append,List.append_nil] at hu hv
exact hu.symm.trans hv.symm
theorem normal_rel {u v : FreeMonoid S} (h : Rel T u v) : normal T u.toList=normal T v.toList := by
obtain β¨n,rs,hrs,huv,huβ© := h
obtain β¨rt,hrt,hd,hcβ© := good n
have he := Part.mem_unique hrt hrs
subst rt
have hstep : Step rs u.toList v.toList := by
simpa only [List.nil_append,List.append_nil] using Step.apply huv [] []
have hv : v.toList.length β€ n := (steps_length hd (.single hstep)).trans hu
have hat (w : List S) (hw : w.length β€ n) : tableNormal T w=evaluate rs w :=
tableNormal_at wf (fun _ _ => good _) (fun k hk => stable k n hk) hrs hw
have hnu := normal_mem T wf good stable u.toList
have hnv := normal_mem T wf good stable v.toList
rw [hat _ hu] at hnu
rw [hat _ hv] at hnv
exact evaluate_unique_on wf hd n (fun _ _ _ h => critical_localJoin hc h) hu
(evaluate_sound hnu).1 ((ReflTransGen.single hstep).trans (evaluate_sound hnv).1)
(evaluate_sound hnu).2 (evaluate_sound hnv).2
noncomputable def normalCon : Con (FreeMonoid S) where
r u v := normal T u.toList=normal T v.toList
iseqv := β¨fun _ => rfl, fun h => h.symm, fun h g => h.trans gβ©
mul' := by
intro u v x y huv hxy
change normal T (u.toList++x.toList)=normal T (v.toList++y.toList)
exact (normal_append T wf good stable _ _).trans
((congrArgβ (fun a b => normal T (a++b)) huv hxy).trans
(normal_append T wf good stable _ _).symm)
theorem present_eq_iff (u v : List S) : present T u=present T v β normal T u=normal T v := by
constructor
Β· intro h
exact (Con.conGen_le.mpr (fun _ _ h => normal_rel T wf good stable h) :
conGen (Rel T) β€ normalCon T wf good stable) (PresentedMonoid.mk_eq_mk_iff.mp h)
Β· intro h
exact (present_normal T wf good stable u).trans (h βΈ (present_normal T wf good stable v).symm)
variable [Primcodable S]
theorem computable_normal (hT : Partrec T) : Computable (normal T) := by
have hp : Partrec (tableNormal T) :=
((hT.comp Primrec.list_length.to_comp).bind
(partrec_evaluate.comp Computable.snd (Computable.fst)).toβ)
apply hp.of_eq
intro w
exact Part.eq_some_iff.mpr (normal_mem T wf good stable w)
theorem computable_wordProblem (hT : Partrec T) :
ComputablePred (fun p : List S Γ List S => present T p.1=present T p.2) := by
have hn := computable_normal T wf good stable hT
have hh : ComputablePred (fun p : List S Γ List S => normal T p.1=normal T p.2) :=
β¨inferInstance, Primrec.eq.computablePred.decide.comp
((hn.comp Computable.fst).pair (hn.comp Computable.snd))β©
exact hh.of_eq (fun p => (present_eq_iff T wf good stable p.1 p.2).symm)
end Quotient
open Relation
namespace Selectors
variable {S : Type*} [DecidableEq S] {a : Markers S}
theorem process_mono (base : List (List S Γ List S)) (stages : β β Stage S)
(n : β) {j k : β} (hjk : j β€ k) :
β pβprocess (a:=a) base stages n j,pβprocess (a:=a) base stages n k := by
induction hjk with
| refl => exact fun _ h => h
| @step k h ih =>
exact fun p hp => choose_contains _ _ _ p (ih p hp)
theorem selected_mem {base : List (List S Γ List S)} {stages : β β Stage S}
{n j : β} (hjn : j<n) (hs : (stages j).sizeβ€n)
(ha : allowed (process (a:=a) base stages n j) (stages j)=true) :
β pβrules a (stages j).size (stages j).bodies,pβprocess (a:=a) base stages n n := by
intro p hp
apply process_mono base stages n (Nat.succ_le_of_lt hjn) p
change pβchoose (a:=a) (process base stages n j) (stages j) n
rw [choose,ite_eq_left β¨hs,haβ©]
exact List.mem_append_right _ hp
end Selectors
namespace Quotient
variable {S : Type*} [DecidableEq S]
variable (T : β β Part (List (List S Γ List S)))
variable {r : S β S β Prop} (wf : WellFounded r)
(good : β n,GoodTable (r:=r) T n)
(stable : β k n,k β€ n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
include wf good stable
theorem normal_irreducible (w : List S) {n : β} {rs : List (List S Γ List S)}
(hrs : rsβT n) (hwlen : w.lengthβ€n) : Irreducible (Step rs) (normal T w) := by
have hw := normal_mem T wf good stable w
rw [tableNormal_at wf (fun k _ => good k)
(fun k hk => stable k _ hk) hrs hwlen] at hw
exact (evaluate_sound hw).2
theorem normal_idempotent (w : List S) : normal T (normal T w)=normal T w := by
simpa only [List.nil_append,List.append_nil] using normal_context T wf good stable [] w []
theorem normal_eq_self {w : List S} {rs : List (List S Γ List S)} (hrs : rsβT w.length)
(hi : Irreducible (Step rs) w) : normal T w=w := by
have hw := normal_mem T wf good stable w
rw [tableNormal,Part.eq_some_iff.mpr hrs,Part.bind_some] at hw
exact (irreducible_reaches (Step rs) hi (evaluate_sound hw).1).symm
omit [DecidableEq S] wf good stable in
theorem present_surjective : Function.Surjective (present T) := by
intro x
obtain β¨w,rflβ© := PresentedMonoid.surjective_mk x
exact β¨w.toList,rflβ©
noncomputable def representative (x : Mon T) : List S :=
normal T (Classical.choose (present_surjective T x))
theorem present_representative (x : Mon T) : present T (representative T x)=x := by
rw [representative,βpresent_normal T wf good stable]
exact Classical.choose_spec (present_surjective T x)
theorem representative_injective : Function.Injective (representative T) := by
intro x y he
rw [βpresent_representative T wf good stable x,βpresent_representative T wf good stable y,he]
theorem representative_irreducible (x : Mon T) {n : β} {rs : List (List S Γ List S)}
(hrs : rsβT n) (hx : (representative T x).lengthβ€n) :
Irreducible (Step rs) (representative T x) := by
have h := normal_irreducible T wf good stable (representative T x) hrs hx
simpa only [representative,normal_idempotent T wf good stable] using h
omit [DecidableEq S] wf good stable in
theorem irreducible_of_short {rs : List (List S Γ List S)} {w : List S}
(h : β pβrs,w.length<p.1.length) : Irreducible (Step rs) w := by
intro v hv
cases hv with
| @apply u v huv x y =>
have hh := h (u,v) huv
simp only [List.length_append] at hh
omega
theorem present_nil_ne_zero (z : S)
(hshort : β n rs,rsβT n β β pβrs,1<p.1.length) :
(1 : Mon T)β present T [z] := by
obtain β¨r0,hr0,_β© := good 0
obtain β¨r1,hr1,_β© := good 1
have h0 : normal T []=[] := normal_eq_self T wf good stable hr0
(irreducible_of_short (fun p hp => by simpa using Nat.lt_trans Nat.zero_lt_one (hshort 0 r0 hr0 p hp)))
have h1 : normal T [z]=[z] := normal_eq_self T wf good stable hr1
(irreducible_of_short (fun p hp => hshort 1 r1 hr1 p hp))
intro he
have hh := (present_eq_iff T wf good stable [] [z]).mp he
rw [h0,h1] at hh
simp at hh
omit [DecidableEq S] wf good stable in
theorem present_absorbs (z : S) {rs : List (List S Γ List S)}
(hrs : rsβT 2) (hz : Absorbs rs z) :
β w,present T [z]*present T w=present T [z] β§
present T w*present T [z]=present T [z] := by
have hza (a : S) : present T [z]*present T [a]=present T [z] :=
PresentedMonoid.mk_eq_mk_of_rel β¨2,rs,hrs,(hz a).1,by simpβ©
have haz (a : S) : present T [a]*present T [z]=present T [z] :=
PresentedMonoid.mk_eq_mk_of_rel β¨2,rs,hrs,(hz a).2,by simpβ©
intro w
induction w with
| nil => simp
| cons a w ih =>
have hh : present T (a::w)=present T [a]*present T w := rfl
rw [hh]
exact β¨by rw [βmul_assoc,hza,ih.1],by rw [mul_assoc,ih.2,haz]β©
@[instance_reducible]
noncomputable def monoidWithZero (z : S) {rs : List (List S Γ List S)}
(hrs : rsβT 2) (hz : Absorbs rs z) : MonoidWithZero (Mon T) where
__ := (inferInstance : Monoid (Mon T))
zero := present T [z]
zero_mul x := by
obtain β¨w,rflβ© := PresentedMonoid.surjective_mk x
exact (present_absorbs T z hrs hz w.toList).1
mul_zero x := by
obtain β¨w,rflβ© := PresentedMonoid.surjective_mk x
exact (present_absorbs T z hrs hz w.toList).2
theorem representative_avoids_zero (z : S) (x : Mon T)
(hx : xβ present T [z])
(hz : β n rs,rsβT n β Absorbs rs z) : zβrepresentative T x := by
intro hzx
let w := representative T x
obtain β¨rs,hrs,hd,_β© := good w.length
have he := present_steps T hrs hd le_rfl (absorbs_mem (hz _ _ hrs) hzx)
exact hx ((present_representative T wf good stable x).symm.trans he)
end Quotient
namespace Selectors
variable {S : Type*} [DecidableEq S] [Primcodable S]
/-- Every nonzero irreducible ordered tuple receives its literal selector.
The finite processing stage is chosen beyond the complete selector word. -/
theorem tuple_selected (a : Markers S) (T : β β Part (List (List S Γ List S)))
(bases : β β List (List S Γ List S))
(hT : β n,process (a:=a) (bases n) (stages a.zero) n n β T n)
{ws : List (List S)} (hne : wsβ []) (hd : ws.Nodup) (hz : β wβws,a.zeroβw)
(hi : β wβws,β n rs,rsβT n β w.lengthβ€n β Irreducible (Step rs) w) :
β N,β wβws,Quotient.present T (a.wrap N w)=
Quotient.present T (if ws.head?=some w then [] else [a.zero]) := by
let j := Encodable.encode ws
let N := sizes a.zero j
let n := 3*N+2
have he : (stages a.zero j).bodies=ws := tuples_complete a.zero hne hd hz
have hsize : (stages a.zero j).size=N := rfl
have hjN : j<N := index_lt_size a.zero j
have hNn : Nβ€n := by omega
have hjn : j<n := lt_of_lt_of_le hjN hNn
have hlen (w : List S) (hw : wβws) : w.length<N := by
apply body_lt_size a.zero j
change wβ(stages a.zero j).bodies
rw [he]
exact hw
have hall : allowed (process (a:=a) (bases n) (stages a.zero) n j) (stages a.zero j)=true := by
apply allowed_iff.mpr
intro w hw
have hw' : wβws := he βΈ hw
have nh := hi w hw' n _ (hT n) (le_trans (Nat.le_of_lt (hlen w hw')) hNn)
intro v hv
apply nh v
exact step_mono (process_mono (bases n) (stages a.zero) n (Nat.le_of_lt hjn)) hv
refine β¨N,?_β©
intro w hw
have hp : (a.wrap N w,if ws.head?=some w then [] else [a.zero])βrules a
(stages a.zero j).size (stages a.zero j).bodies := by
rw [he,hsize]
exact (mem_rules a).mpr β¨w,hw,rfl,rflβ©
have hmem := selected_mem hjn (hsize βΈ hNn) hall _ hp
apply PresentedMonoid.mk_eq_mk_of_rel
refine β¨n,_,hT n,hmem,?_β©
change (a.wrap N w).lengthβ€n
simp only [Markers.wrap,Envelopes.length_frame]
have := hlen w hw
omega
end Selectors
namespace Quotient
variable {S : Type*} [DecidableEq S] [Primcodable S]
variable (T : β β Part (List (List S Γ List S)))
variable {r : S β S β Prop} (wf : WellFounded r)
(good : β n,GoodTable (r:=r) T n)
(stable : β k n,k β€ n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
include wf good stable
/-- Source selectors for the stabilized quotient, with the distinguished element
first in the tuple. Not an extra algebraic assumption on that quotient. -/
theorem selectors (a : Selectors.Markers S) (bases : β β List (List S Γ List S))
(hT : β n,Selectors.process (a:=a) (bases n) (Selectors.stages a.zero) n nβT n)
(hz : β n rs,rsβT n β Absorbs rs a.zero)
(X : Finset (Mon T)) (hX : present T [a.zero]βX) (x : Mon T) (hx : xβX) :
β L R : Mon T,L*x*R=1 β§ β yβX,yβ x β L*y*R=present T [a.zero] := by
classical
let xs := x::(X.erase x).toList
have xsne : xsβ [] := List.cons_ne_nil _ _
have xsd : xs.Nodup := List.nodup_cons.mpr β¨by simp,Finset.nodup_toList _β©
have xsmem (y : Mon T) : yβxs β yβX := by
simp only [xs,List.mem_cons,Finset.mem_toList,Finset.mem_erase]
constructor
Β· rintro (rfl | β¨_,hhβ©)
Β· exact hx
Β· exact hh
Β· intro hh
by_cases he : y=x
Β· exact Or.inl he
Β· exact Or.inr β¨he,hhβ©
let rep := representative T
have hrep : Function.Injective rep := representative_injective T wf good stable
let ws := xs.map rep
have hwsne : wsβ [] := by simp [ws,xs]
have hwsd : ws.Nodup := xsd.map hrep
have hwsz : β wβws,a.zeroβw := by
intro w hw
obtain β¨y,hy,rflβ© := List.mem_map.mp hw
exact representative_avoids_zero T wf good stable a.zero y
(fun he => hX (he βΈ (xsmem y).mp hy)) hz
have hwsi : β wβws,β n rs,rsβT n β w.lengthβ€n β Irreducible (Step rs) w := by
intro w hw n rs hrs hlen
obtain β¨y,hy,rflβ© := List.mem_map.mp hw
exact representative_irreducible T wf good stable y hrs hlen
obtain β¨N,hNβ© := Selectors.tuple_selected a T bases hT hwsne hwsd hwsz hwsi
let L := present T (a.d::List.replicate N a.l)
let R := present T (List.replicate N a.r++[a.h])
have heq (y : Mon T) : present T (a.wrap N (rep y))=L*y*R := by
change present T (a.d::(List.replicate N a.l++rep y++List.replicate N a.r++[a.h]))=_
have he : a.d::(List.replicate N a.l++rep y++List.replicate N a.r++[a.h])=
(a.d::List.replicate N a.l)++rep y++(List.replicate N a.r++[a.h]) := by simp [List.append_assoc]
rw [he,present_append,present_append,present_representative T wf good stable]
refine β¨L,R,?_,?_β©
Β· have hw : rep xβws := List.mem_map.mpr β¨x,(xsmem x).mpr hx,rflβ©
have hs := hN _ hw
rw [heq] at hs
simpa only [ws,xs,List.map_cons,List.head?_cons,ite_true,present_nil] using hs
Β· intro y hy hyx
have hw : rep yβws := List.mem_map.mpr β¨y,(xsmem y).mpr hy,rflβ©
have hs := hN _ hw
rw [heq] at hs
have hne : ws.head?β some (rep y) := by
simp only [ws,xs,List.map_cons,List.head?_cons]
exact fun h => hyx (hrep (Option.some.inj h)).symm
simpa only [ite_eq_right hne] using hs
end Quotient
end
namespace Static
variable {S A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (z : S)
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_short (hc : 1<C.width+1) {n : β} {p : List S Γ List S}
(hp : pβtable C wf q z n) : 1<p.1.length := by
obtain β¨w,_,hn,_,he,_β© := (mem_table C wf q z).mp hp
rw [he,C.encode_length]
have hl : 1β€w.length := List.length_pos_iff.mpr hn
exact hc.trans_le (by simpa using Nat.mul_le_mul_left (C.width+1) hl)
end Static
namespace Build
variable {S A B Q R : Type*} [Primcodable S] [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop}
[DecidableRel (List.Shortlex r)] [DecidableRel (List.Shortlex s)]
[Std.Trichotomous r] [Std.Trichotomous s]
variable (a : Selectors.Markers S) (C : BlockCode A S) (D : BlockCode B S)
(wf : WellFounded r) (wg : WellFounded s)
variable (f : List A β Part (Option Q)) (g : List B β Part (Option R))
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
theorem tables_absorb {n : β} {rs : List (List S Γ List S)}
(hrs : rsβtables (r:=r) (s:=s) a C D f g n) : Absorbs rs a.zero := by
rw [tables_eq a C D wf wg hrs]
have hh := Selectors.process_contains (a:=a)
(Base.table C D wf wg (Search.value f) (Search.value g) a.zero n)
(Selectors.stages a.zero) n n
intro b
exact β¨hh _ (Base.absorbs C D wf wg (Search.value f) (Search.value g) a.zero n b).1,
hh _ (Base.absorbs C D wf wg (Search.value f) (Search.value g) a.zero n b).2β©
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
theorem tables_short (hc : 1<C.width+1) (hd : 1<D.width+1) {n : β}
{rs : List (List S Γ List S)} (hrs : rsβtables (r:=r) (s:=s) a C D f g n) :
β pβrs,1<p.1.length := by
rw [tables_eq a C D wf wg hrs]
intro p hp
rcases Selectors.process_members hp with hp | β¨j,hj,hpβ©
Β· rcases (Base.mem_table C D wf wg (Search.value f) (Search.value g) a.zero).mp hp with hp | hp | hp
Β· obtain β¨b,(he | he),_β© := (Base.mem_absorption a.zero).mp hp <;> rw [he] <;> simp
Β· exact Static.table_short C wf (Search.value f) a.zero hc hp
Β· exact Static.table_short D wg (Search.value g) a.zero hd hp
Β· obtain β¨w,_,he,_β© := (Selectors.mem_rules a).mp hp
rw [he]
simp only [Selectors.Markers.wrap,Envelopes.length_frame]
omega
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
/-- Once bounded induction has proved total tables, their process descriptions
are genuine members. No totality of static programs is added here. -/
theorem tables_process {t : S β S β Prop}
(good : β n,GoodTable (r:=t) (tables (r:=r) (s:=s) a C D f g) n) (n : β) :
Selectors.process (a:=a) (Base.table C D wf wg (Search.value f) (Search.value g) a.zero n)
(Selectors.stages a.zero) n nβtables (r:=r) (s:=s) a C D f g n := by
obtain β¨rs,hrs,_β© := good n
rw [βtables_eq a C D wf wg hrs]
exact hrs
end Build
end FiniteAlgebraicEnvelopes.Bootstrap
namespace FiniteAlgebraicEnvelopes
namespace Compiler.Word
variable {S Ξ Q : Type*}
variable (A : Simulator.Alphabet S Ξ) (M : Simulator.Machine Q Ξ)
[DecidableEq S] [DecidableEq Ξ] [DecidableEq Q]
[Fintype S] [Fintype Ξ] [Fintype Q] [LinearOrder (Control.Sector S Ξ Q)]
omit [DecidableEq Q] [Fintype S] [Fintype Ξ] [Fintype Q]
[LinearOrder (Control.Sector S Ξ Q)] in
theorem present_surjective : Function.Surjective (present A M) := by
intro x
obtain β¨w,rflβ© := PresentedMonoid.surjective_mk x
exact β¨w.toList,rflβ©
omit [DecidableEq Q] [Fintype S] [Fintype Ξ] [Fintype Q]
[LinearOrder (Control.Sector S Ξ Q)] in
theorem present_zero_mul (w : List (Letter S Ξ Q)) :
present A M [.zero] * present A M w=present A M [.zero] := by
induction w with
| nil => exact mul_one _
| cons c w ih =>
have hh : present A M [.zero,c]=present A M [.zero] :=
PresentedMonoid.mk_eq_mk_of_rel (.zero (.pair _ _ (by simp [Path.typeOf])))
have hp : present A M (c::w)=present A M [c]*present A M w := rfl
rw [hp,βmul_assoc]
change present A M [.zero,c]*present A M w=_
rw [hh,ih]
omit [DecidableEq Q] [Fintype S] [Fintype Ξ] [Fintype Q]
[LinearOrder (Control.Sector S Ξ Q)] in
theorem present_mul_zero (w : List (Letter S Ξ Q)) :
present A M w * present A M [.zero]=present A M [.zero] := by
induction w with
| nil => exact one_mul _
| cons c w ih =>
have hh : present A M [c,.zero]=present A M [.zero] :=
PresentedMonoid.mk_eq_mk_of_rel (.zero (.pair _ _ (by simp [Path.typeOf])))
have hp : present A M (c::w)=present A M [c]*present A M w := rfl
rw [hp,mul_assoc,ih]
exact hh
@[instance_reducible]
noncomputable def monoidWithZero : MonoidWithZero (Presentation A M) where
__ := (inferInstance : Monoid (Presentation A M))
zero := present A M [.zero]
zero_mul x := by
obtain β¨w,rflβ© := present_surjective A M x
exact present_zero_mul A M w
mul_zero x := by
obtain β¨w,rflβ© := present_surjective A M x
exact present_mul_zero A M w
variable [Primcodable S]
variable (hle : PrimrecRel (fun a b : Control.Sector S Ξ Q => aβ€b))
variable {f : List S β Part (List S)} (hf : Partrec f)
variable (budget : β n,PartialBudget f n)
include hle hf budget
theorem computable_normal : Computable (normal A M (fun w => partValue (f w))) := by
apply (partrec_partialNormal A M hle hf).of_eq
intro w
exact partialNormal_eq_some A M (budget (grade w)) w le_rfl
theorem computable_wordProblem
(hdecode : β g a,A.output g=some a β g=A.input a) (hr : Realizes A M f) :
ComputablePred (fun p : List (Letter S Ξ Q) Γ List (Letter S Ξ Q) =>
present A M p.1=present A M p.2) := by
have hn := computable_normal A M hle hf budget
have he : ComputablePred (fun p : List (Letter S Ξ Q) Γ List (Letter S Ξ Q) =>
normal A M (fun w => partValue (f w)) p.1=normal A M (fun w => partValue (f w)) p.2) :=
β¨inferInstance,Primrec.eq.computablePred.decide.comp
((hn.comp Computable.fst).pair (hn.comp Computable.snd))β©
exact he.of_eq (fun p => (present_eq_iff_normal A M hdecode (fun n => (budget n).totalize)
(fun n => hr.computesAt A M (budget n)) p.1 p.2).symm)
end Compiler.Word
namespace Bootstrap.Quotient
variable {S : Type*} [DecidableEq S]
variable (T : β β Part (List (List S Γ List S)))
variable {r : S β S β Prop} (wf : WellFounded r)
(good : β n,GoodTable (r:=r) T n)
(stable : β k n,k β€ n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
include wf good stable
theorem representative_mul (x y : Mon T) : representative T (x*y)=
normal T (representative T x++representative T y) := by
have he : present T (representative T (x*y))=
present T (representative T x++representative T y) := by
rw [present_append,present_representative T wf good stable,
present_representative T wf good stable,present_representative T wf good stable]
have hn := (present_eq_iff T wf good stable _ _).mp he
simpa only [representative,normal_idempotent T wf good stable] using hn
variable {Ξ Q : Type*} [Fintype S] [Fintype Ξ] [Fintype Q]
[DecidableEq Ξ] [DecidableEq Q] [LinearOrder (Compiler.Control.Sector S Ξ Q)]
variable (A : Compiler.Simulator.Alphabet S Ξ) (M : Compiler.Simulator.Machine Q Ξ)
variable (hdecode : β g a,A.output g=some a β g=A.input a)
variable (hr : Compiler.Word.Realizes A M (tableNormal T))
noncomputable def rawMap (hdecode : β g a,A.output g=some a β g=A.input a)
(hr : Compiler.Word.Realizes A M (tableNormal T)) : Mon T ββ* Compiler.Word.Presentation A M where
toFun x := Compiler.Word.present A M (Compiler.Word.raw A.blank (representative T x))
map_mul' x y := by
have hb := fun n => (budget T wf good stable n).totalize
have hc := fun n => Compiler.Word.Realizes.computesAt A M hr (budget T wf good stable n)
apply (Compiler.Word.present_eq_iff_normal A M hdecode hb hc _ _).mpr
change Compiler.Word.normal A M (fun w => Compiler.partValue (tableNormal T w))
(Compiler.Word.raw A.blank (representative T (x*y))) =
Compiler.Word.normal A M (fun w => Compiler.partValue (tableNormal T w))
(Compiler.Word.raw A.blank (representative T x) ++
Compiler.Word.raw A.blank (representative T y))
rw [Compiler.Word.normal_raw,Compiler.Word.normal_raw_product,
representative_mul T wf good stable]
rfl
include hdecode hr in
theorem rawMap_injective : Function.Injective (rawMap T wf good stable A M hdecode hr) := by
intro x y hxy
have hn := (Compiler.Word.present_eq_iff_normal A M hdecode
(fun n => (budget T wf good stable n).totalize)
(fun n => Compiler.Word.Realizes.computesAt A M hr (budget T wf good stable n)) _ _).mp hxy
simp only [Compiler.Word.normal_raw] at hn
have he := congrArg Compiler.Word.rawLetters hn
simp only [Compiler.Word.rawLetters_raw] at he
exact representative_injective T wf good stable he
include hdecode hr in
theorem rawMap_ne_one (x : Mon T) : rawMap T wf good stable A M hdecode hr xβ 1 := by
intro hx
have hn := (Compiler.Word.present_eq_iff_normal A M hdecode
(fun n => (budget T wf good stable n).totalize)
(fun n => Compiler.Word.Realizes.computesAt A M hr (budget T wf good stable n))
(Compiler.Word.raw A.blank (representative T x)) []).mp hx
simp only [Compiler.Word.normal_raw,Compiler.Word.normal_nil] at hn
simp [Compiler.Word.raw,Compiler.Word.encode,Compiler.Surface.raw,Compiler.Scan.literal,
Compiler.Path.encode,Compiler.Path.headed] at hn
include hdecode hr in
theorem rawMap_ne_zero (x : Mon T) :
rawMap T wf good stable A M hdecode hr xβ Compiler.Word.present A M [.zero] := by
intro hx
have hn := (Compiler.Word.present_eq_iff_normal A M hdecode
(fun n => (budget T wf good stable n).totalize)
(fun n => Compiler.Word.Realizes.computesAt A M hr (budget T wf good stable n))
(Compiler.Word.raw A.blank (representative T x)) [.zero]).mp hx
simp only [Compiler.Word.normal_raw,Compiler.Word.normal_omega] at hn
simp [Compiler.Word.raw,Compiler.Word.encode,Compiler.Surface.raw,Compiler.Scan.literal,
Compiler.Path.encode,Compiler.Path.headed] at hn
end Bootstrap.Quotient
end FiniteAlgebraicEnvelopes
namespace FiniteAlgebraicEnvelopes.Bootstrap
section
open Relation
variable {S : Type*}
theorem irreducible_of_no_infix {rs : List (List S Γ List S)} {w : List S}
(h : β pβrs, Β¬ p.1 <:+: w) : Irreducible (Step rs) w := by
intro v hv
cases hv with
| @apply u v hp x y => exact h (u,v) hp β¨x,y,rflβ©
namespace Static
variable {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (z : S)
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_mono {k n : β} (hkn : kβ€n) {p : List S Γ List S}
(hp : pβtable C wf q z k) : pβtable C wf q z n := by
obtain β¨w,hw,hn,he,hl,hrβ© := (mem_table C wf q z).mp hp
exact (mem_table C wf q z).mpr β¨w,hw.trans hkn,hn,he,hl,hrβ©
omit [DecidableEq A] [DecidableEq Q] in
theorem canonical_no_infix (hc : β n,Contextual q n) (hi : β n,ZeroIdeal q n)
{w : List A} (hw : q wβ none) {n : β} {u v : List S}
(hp : (u,v)βtable C wf q z n) : Β¬ u <:+: C.encode (Canonical.least wf q w) := by
obtain β¨c,_,hcn,hn,rfl,rflβ© := (mem_table C wf q z).mp hp
rintro β¨x,y,heβ©
obtain β¨a,b,hab,hx,hyβ© := C.occurrence_decode hcn he.symm
have hq : q (a++c++b)=q w := hab βΈ Canonical.least_class wf q w
by_cases hz : q c=none
Β· exact hw (hq.symm.trans (hi _ a b c le_rfl hz))
Β· have hlt : List.Shortlex r (Canonical.least wf q c) c := by
rcases Canonical.least_lt_or_eq wf q c with h | h
Β· exact h
Β· exact False.elim (hn (by simp [output,hz,h]))
have hb : (a++Canonical.least wf q c++b).lengthβ€(a++c++b).length := by
have hh := Canonical.least_length wf q c
simp only [List.length_append]
omega
have hclass : q (a++Canonical.least wf q c++b)=q w :=
(hc _ a b _ c hb le_rfl (Canonical.least_class wf q c)).trans hq
apply Canonical.least_global_min wf q hclass
rw [hab]
exact shortlex_context hlt a b
omit [DecidableEq A] [DecidableEq Q] in
/-- Rules of the other code and selector/zero rules cannot occur in a pure code. -/
theorem canonical_irreducible {rs : List (List S Γ List S)} {n : β}
(hiso : β pβrs,pβtable C wf q z n β¨ β sβp.1,sβC.Alphabet)
(hc : β k,Contextual q k) (hi : β k,ZeroIdeal q k)
{w : List A} (hw : q wβ none) :
Irreducible (Step rs) (C.encode (Canonical.least wf q w)) := by
apply irreducible_of_no_infix
intro p hp hif
rcases hiso p hp with hp | β¨s,hs,hnβ©
Β· exact canonical_no_infix C wf q z hc hi hw hp hif
Β· exact hn (C.mem_alphabet (hif.subset hs))
omit [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q] in
theorem output_eq_iff (hz : zβC.Alphabet) (u v : List A) :
output C wf q z u=output C wf q z v β q u=q v := by
constructor
Β· intro he
by_cases hu : q u=none <;> by_cases hv : q v=none
Β· exact hu.trans hv.symm
Β· have hh : zβC.encode (Canonical.least wf q v) := by
rw [output,ite_eq_left hu,output,ite_eq_right hv] at he
rw [βhe]; simp
exact False.elim (hz (C.mem_alphabet hh))
Β· have hh : zβC.encode (Canonical.least wf q u) := by
rw [output,ite_eq_right hu,output,ite_eq_left hv] at he
rw [he]; simp
exact False.elim (hz (C.mem_alphabet hh))
Β· rw [output,ite_eq_right hu,output,ite_eq_right hv] at he
have h := C.encode_injective he
exact (Canonical.least_class wf q u).symm.trans
((congrArg q h).trans (Canonical.least_class wf q v))
Β· exact output_congr C wf q z
end Static
namespace Quotient
variable [DecidableEq S]
variable (T : β β Part (List (List S Γ List S)))
variable {t : S β S β Prop} (wt : WellFounded t)
(good : β n,GoodTable (r:=t) T n)
(stable : β k n,kβ€n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
variable {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq Q]
{r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (z : S)
variable (hshort : β n rs,rsβT n β β pβrs,1<p.1.length)
variable (hiso : β n rs,rsβT n β β pβrs,pβStatic.table C wf q z n β¨ β sβp.1,sβC.Alphabet)
variable (hstatic : β n rs,rsβT ((C.width+1)*n) β β pβStatic.table C wf q z n,pβrs)
variable (hc : β n,Static.Contextual q n) (hi : β n,Static.ZeroIdeal q n) (hzero : q []β none)
include wt good stable hshort hiso hstatic hc hi hzero
omit [DecidableEq A] [DecidableEq Q] in
theorem normal_encode (w : List A) : normal T (C.encode w)=Static.output C wf q z w := by
have hfixed : normal T (Static.output C wf q z w)=Static.output C wf q z w := by
by_cases hq : q w=none
Β· rw [Static.output,ite_eq_left hq]
obtain β¨rs,hrs,_β© := good 1
exact normal_eq_self T wt good stable hrs
(irreducible_of_short (fun p hp => hshort 1 rs hrs p hp))
Β· rw [Static.output,ite_eq_right hq]
obtain β¨rs,hrs,_β© := good (C.encode (Canonical.least wf q w)).length
exact normal_eq_self T wt good stable hrs
(Static.canonical_irreducible C wf q z (hiso _ rs hrs) hc hi hq)
have hpres : present T (C.encode w)=present T (Static.output C wf q z w) := by
obtain β¨rs,hrs,hd,_β© := good ((C.width+1)*w.length)
exact present_steps T hrs hd (by rw [C.encode_length])
(steps_mono (hstatic w.length rs hrs) (Static.whole_steps C wf q z hzero le_rfl))
exact ((present_eq_iff T wt good stable _ _).mp hpres).trans hfixed
omit [DecidableEq A] [DecidableEq Q] in
theorem present_encode_iff (hz : zβC.Alphabet) (u v : List A) :
present T (C.encode u)=present T (C.encode v) β q u=q v := by
rw [present_eq_iff T wt good stable,
normal_encode T wt good stable C wf q z hshort hiso hstatic hc hi hzero,
normal_encode T wt good stable C wf q z hshort hiso hstatic hc hi hzero]
exact Static.output_eq_iff C wf q z hz u v
end Quotient
namespace Base
variable {A B Q R : Type*} [Fintype S] [Fintype A] [Fintype B]
[DecidableEq A] [DecidableEq B] [DecidableEq S] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop} [Std.Trichotomous r] [Std.Trichotomous s]
variable (C : BlockCode A S) (D : BlockCode B S) (wf : WellFounded r) (wg : WellFounded s)
(q : List A β Option Q) (g : List B β Option R) (z : S)
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem isolate_left (hz : zβC.Alphabet) (hd : Disjoint C.Alphabet D.Alphabet)
{n : β} {p : List S Γ List S} (hp : pβtable C D wf wg q g z n) :
pβStatic.table C wf q z n β¨ β sβp.1,sβC.Alphabet := by
rcases (mem_table C D wf wg q g z).mp hp with hp | hp | hp
Β· obtain β¨b,hb,_β© := (mem_absorption z).mp hp
exact Or.inr β¨z,by rcases hb with h | h <;> simp [h],hzβ©
Β· exact Or.inl (Static.table_mono C wf q z (Nat.div_le_self n _) hp)
Β· obtain β¨hn,hsβ© := Static.table_support D wg g z hp
obtain β¨b,hbβ© := List.exists_mem_of_ne_nil _ hn
exact Or.inr β¨b,hb,fun hc => Set.disjoint_left.mp hd hc (hs b hb)β©
end Base
namespace Selectors
variable [DecidableEq S] (a : Markers S)
theorem process_isolate {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq Q]
{r : A β A β Prop} [Std.Trichotomous r]
(C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q)
{rs : List (List S Γ List S)} {n : β}
(hbase : β pβrs,pβStatic.table C wf q a.zero n β¨ β sβp.1,sβC.Alphabet)
(hd : a.dβC.Alphabet) (stages : β β Stage S) (budget j : β)
{p : List S Γ List S} (hp : pβprocess (a:=a) rs stages budget j) :
pβStatic.table C wf q a.zero n β¨ β sβp.1,sβC.Alphabet := by
rcases process_members hp with hp | β¨i,_,hpβ©
Β· exact hbase p hp
Β· obtain β¨w,_,he,_β© := (mem_rules a).mp hp
exact Or.inr β¨a.d,by simp [he,Markers.wrap,Envelopes.frame],hdβ©
end Selectors
namespace Build
variable {A B Q R : Type*} [Primcodable S] [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop}
[DecidableRel (List.Shortlex r)] [DecidableRel (List.Shortlex s)]
[Std.Trichotomous r] [Std.Trichotomous s]
variable (a : Selectors.Markers S) (C : BlockCode A S) (D : BlockCode B S)
(wf : WellFounded r) (wg : WellFounded s)
variable (f : List A β Part (Option Q)) (g : List B β Part (Option R))
include wf wg in
omit [DecidableEq B] in
theorem tables_isolate (hz : a.zeroβC.Alphabet) (hd : a.dβC.Alphabet)
(hCD : Disjoint C.Alphabet D.Alphabet) {n : β} {rs : List (List S Γ List S)}
(hrs : rsβtables (r:=r) (s:=s) a C D f g n) :
β pβrs,pβStatic.table C wf (Search.value f) a.zero n β¨ β bβp.1,bβC.Alphabet := by
rw [tables_eq a C D wf wg hrs]
intro p hp
exact Selectors.process_isolate a C wf (Search.value f)
(fun p hp => Base.isolate_left C D wf wg (Search.value f) (Search.value g) a.zero hz hCD hp)
hd _ _ _ hp
include wf wg in
omit [DecidableEq A] [DecidableEq B] in
theorem tables_static (n : β) {rs : List (List S Γ List S)}
(hrs : rsβtables (r:=r) (s:=s) a C D f g ((C.width+1)*n)) :
β pβStatic.table C wf (Search.value f) a.zero n,pβrs := by
rw [tables_eq a C D wf wg hrs]
intro p hp
apply Selectors.process_contains
apply (Base.mem_table C D wf wg (Search.value f) (Search.value g) a.zero).mpr
exact Or.inr (Or.inl (by simpa using hp))
end Build
namespace Quotient
variable [DecidableEq S] {A M : Type*} [Monoid M]
variable {T : β β Part (List (List S Γ List S))} (C : BlockCode A S)
def codeHom : FreeMonoid A β* Mon T where
toFun w := present T (C.encode w.toList)
map_one' := by simp
map_mul' u v := by simp only [FreeMonoid.toList_mul,BlockCode.encode_append,present_append]
variable (e : FreeMonoid A β* M) (he : Function.Surjective e)
(hc : β u v : List A,present T (C.encode u)=present T (C.encode v) β
e (FreeMonoid.ofList u)=e (FreeMonoid.ofList v))
noncomputable def descendCode : M β* Mon T where
toFun x := codeHom C (he x).choose
map_one' := by
have hx : e (he 1).choose=e 1 := (he 1).choose_spec.trans e.map_one.symm
exact (hc _ []).mpr hx
map_mul' x y := by
change present T (C.encode ((he (x*y)).choose.toList)) =
present T (C.encode ((he x).choose.toList))*present T (C.encode ((he y).choose.toList))
rw [βpresent_append,βBlockCode.encode_append]
apply (hc _ _).mpr
change e (he (x*y)).choose=e ((he x).choose * (he y).choose)
rw [e.map_mul,(he (x*y)).choose_spec,(he x).choose_spec,(he y).choose_spec]
omit [DecidableEq S] in
theorem descendCode_apply (w : List A) :
descendCode C e he hc (e (FreeMonoid.ofList w))=present T (C.encode w) :=
(hc _ w).mpr (he (e (FreeMonoid.ofList w))).choose_spec
omit [DecidableEq S] in
theorem descendCode_injective : Function.Injective (descendCode C e he hc) := by
intro x y h
exact (he x).choose_spec.symm.trans (((hc _ _).mp h).trans (he y).choose_spec)
end Quotient
end
variable {S : Type*}
namespace Separator
theorem prefix_before {z : S} {p u v : List S} (hz : zβp)
(h : p <+: u++z::v) : p <+: u := by
induction u generalizing p with
| nil =>
have hnil : p=[] := by
cases p with
| nil => rfl
| cons a p =>
have ha := (List.cons_prefix_cons.mp h).1
exact False.elim (hz (by simp [ha]))
simp [hnil]
| cons a u ih =>
cases p with
| nil => simp
| cons b p =>
obtain β¨rfl,hpβ© := List.cons_prefix_cons.mp h
exact List.cons_prefix_cons.mpr β¨rfl,ih (fun hh => hz (List.mem_cons_of_mem _ hh)) hpβ©
theorem infix_split {z : S} {p u v : List S} (hz : zβp)
(h : p <:+: u++z::v) : p <:+: u β¨ p <:+: v := by
induction u with
| nil =>
rcases List.infix_cons_iff.mp h with hp | hp
Β· have he := List.prefix_nil.mp (prefix_before (u:=[]) hz hp)
exact Or.inl (by simp [he])
Β· exact Or.inr hp
| cons a u ih =>
rcases List.infix_cons_iff.mp h with hp | hp
Β· exact Or.inl (prefix_before hz hp).isInfix
Β· rcases ih hp with hu | hv
Β· exact Or.inl (List.infix_cons_iff.mpr (Or.inr hu))
Β· exact Or.inr hv
theorem split_injective {z : S} {u v u' v' : List S}
(hu : zβu) (hu' : zβu') (he : u++z::v=u'++z::v') : u=u' β§ v=v' := by
induction u generalizing u' with
| nil =>
cases u' with
| nil => exact β¨rfl,(List.cons.inj he).2β©
| cons a u' =>
have ha : z=a := (List.cons.inj he).1
exact False.elim (hu' (by simp [ha]))
| cons a u ih =>
cases u' with
| nil =>
have ha : a=z := (List.cons.inj he).1
exact False.elim (hu (by simp [ha]))
| cons b u' =>
obtain β¨rfl,hrestβ© := List.cons.inj he
obtain β¨rfl,hvβ© := ih (fun h => hu (List.mem_cons_of_mem _ h))
(fun h => hu' (List.mem_cons_of_mem _ h)) hrest
exact β¨rfl,hvβ©
end Separator
namespace Static
variable {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (zero sep : S)
omit [DecidableEq A] [DecidableEq Q] in
theorem separator_irreducible (hs : sepβC.Alphabet)
{rs : List (List S Γ List S)} {n : β}
(hiso : β pβrs,pβtable C wf q zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep)
(hc : β k,Contextual q k) (hi : β k,ZeroIdeal q k)
{u v : List A} (hu : q uβ none) (hv : q vβ none) :
Irreducible (Step rs)
(C.encode (Canonical.least wf q u)++sep::C.encode (Canonical.least wf q v)) := by
apply irreducible_of_no_infix
intro p hp hif
rcases hiso p hp with hp | β¨b,hb,hbc,hbsβ©
Β· have hs' : sepβp.1 := fun hh => hs ((table_support C wf q zero hp).2 sep hh)
rcases Separator.infix_split hs' hif with hif | hif
Β· exact canonical_no_infix C wf q zero hc hi hu hp hif
Β· exact canonical_no_infix C wf q zero hc hi hv hp hif
Β· have hh := hif.subset hb
simp only [List.mem_append,List.mem_cons] at hh
rcases hh with hh | hh | hh
Β· exact hbc (C.mem_alphabet hh)
Β· exact hbs hh
Β· exact hbc (C.mem_alphabet hh)
omit [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q] [Std.Trichotomous r] in
theorem separator_literal_injective (hs : sepβC.Alphabet)
{u v u' v' : List A}
(he : C.encode (Canonical.least wf q u)++sep::C.encode (Canonical.least wf q v)=
C.encode (Canonical.least wf q u')++sep::C.encode (Canonical.least wf q v')) :
q u=q u' β§ q v=q v' := by
have hh := Separator.split_injective (fun h => hs (C.mem_alphabet h))
(fun h => hs (C.mem_alphabet h)) he
have hu := C.encode_injective hh.1
have hv := C.encode_injective hh.2
exact β¨(Canonical.least_class wf q u).symm.trans
((congrArg q hu).trans (Canonical.least_class wf q u')),
(Canonical.least_class wf q v).symm.trans
((congrArg q hv).trans (Canonical.least_class wf q v'))β©
end Static
namespace Base
variable {A B Q R : Type*} [Fintype S] [Fintype A] [Fintype B]
[DecidableEq A] [DecidableEq B] [DecidableEq S] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop} [Std.Trichotomous r] [Std.Trichotomous s]
variable (C : BlockCode A S) (D : BlockCode B S) (wf : WellFounded r) (wg : WellFounded s)
(q : List A β Option Q) (g : List B β Option R) (zero sep : S)
omit [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
[Std.Trichotomous r] [Std.Trichotomous s] in
theorem isolate_separator (hz : zeroβC.Alphabet) (hsep : zeroβ sep)
(hsD : sepβD.Alphabet) (hd : Disjoint C.Alphabet D.Alphabet)
{n : β} {p : List S Γ List S} (hp : pβtable C D wf wg q g zero n) :
pβStatic.table C wf q zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep := by
rcases (mem_table C D wf wg q g zero).mp hp with hp | hp | hp
Β· obtain β¨b,hb,_β© := (mem_absorption zero).mp hp
exact Or.inr β¨zero,by rcases hb with h | h <;> simp [h],hz,hsepβ©
Β· exact Or.inl (Static.table_mono C wf q zero (Nat.div_le_self n _) hp)
Β· obtain β¨hn,hsβ© := Static.table_support D wg g zero hp
obtain β¨b,hbβ© := List.exists_mem_of_ne_nil _ hn
exact Or.inr β¨b,hb,(fun hc => Set.disjoint_left.mp hd hc (hs b hb)),
fun he => hsD (he βΈ hs b hb)β©
end Base
namespace Selectors
variable [DecidableEq S] (a : Markers S)
theorem process_isolate_separator {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq Q]
{r : A β A β Prop} [Std.Trichotomous r]
(C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (sep : S)
{rs : List (List S Γ List S)} {n : β}
(hbase : β pβrs,pβStatic.table C wf q a.zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep)
(hd : a.dβC.Alphabet) (hds : a.dβ sep) (stages : β β Stage S) (budget j : β)
{p : List S Γ List S} (hp : pβprocess (a:=a) rs stages budget j) :
pβStatic.table C wf q a.zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep := by
rcases process_members hp with hp | β¨i,_,hpβ©
Β· exact hbase p hp
Β· obtain β¨w,_,he,_β© := (mem_rules a).mp hp
exact Or.inr β¨a.d,by simp [he,Markers.wrap,Envelopes.frame],hd,hdsβ©
end Selectors
namespace Build
variable {A B Q R : Type*} [Primcodable S] [Fintype S] [Fintype A] [Fintype B]
[DecidableEq S] [DecidableEq A] [DecidableEq B] [DecidableEq Q] [DecidableEq R]
variable {r : A β A β Prop} {s : B β B β Prop}
[DecidableRel (List.Shortlex r)] [DecidableRel (List.Shortlex s)]
[Std.Trichotomous r] [Std.Trichotomous s]
variable (a : Selectors.Markers S) (C : BlockCode A S) (D : BlockCode B S)
(wf : WellFounded r) (wg : WellFounded s)
variable (f : List A β Part (Option Q)) (g : List B β Part (Option R)) (sep : S)
include wf wg in
omit [DecidableEq B] in
theorem tables_isolate_separator (hz : a.zeroβC.Alphabet) (hd : a.dβC.Alphabet)
(hzs : a.zeroβ sep) (hds : a.dβ sep) (hsD : sepβD.Alphabet)
(hCD : Disjoint C.Alphabet D.Alphabet) {n : β} {rs : List (List S Γ List S)}
(hrs : rsβtables (r:=r) (s:=s) a C D f g n) :
β pβrs,pβStatic.table C wf (Search.value f) a.zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep := by
rw [tables_eq a C D wf wg hrs]
intro p hp
exact Selectors.process_isolate_separator a C wf (Search.value f) sep
(fun p hp => Base.isolate_separator C D wf wg (Search.value f) (Search.value g)
a.zero sep hz hzs hsD hCD hp) hd hds _ _ _ hp
end Build
namespace Quotient
variable [DecidableEq S]
variable (T : β β Part (List (List S Γ List S)))
variable {t : S β S β Prop} (wt : WellFounded t)
(good : β n,GoodTable (r:=t) T n)
(stable : β k n,kβ€n β β rkβT k,β rnβT n,Selectors.BoundedEq rk rn k)
variable {A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq Q]
{r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (zero sep : S)
variable (hshort : β n rs,rsβT n β β pβrs,1<p.1.length)
variable (hiso : β n rs,rsβT n β β pβrs,pβStatic.table C wf q zero n β¨ β bβp.1,bβC.Alphabet β§ bβ sep)
variable (hstatic : β n rs,rsβT ((C.width+1)*n) β β pβStatic.table C wf q zero n,pβrs)
variable (hc : β n,Static.Contextual q n) (hi : β n,Static.ZeroIdeal q n) (hzero : q []β none)
variable (hs : sepβC.Alphabet)
include wt good stable hshort hiso hstatic hc hi hzero hs
omit [DecidableEq A] [DecidableEq Q] in
theorem normal_separator {u v : List A} (hu : q uβ none) (hv : q vβ none) :
normal T (C.encode u++sep::C.encode v)=
C.encode (Canonical.least wf q u)++sep::C.encode (Canonical.least wf q v) := by
have hcode (w : List A) (hw : q wβ none) :
normal T (C.encode w)=C.encode (Canonical.least wf q w) := by
rw [normal_encode T wt good stable C wf q zero hshort
(fun n rs hrs p hp => (hiso n rs hrs p hp).imp id (by rintro β¨b,hb,hbc,_β©; exact β¨b,hb,hbcβ©))
hstatic hc hi hzero,Static.output,ite_eq_right hw]
have hleft : normal T (C.encode u++sep::C.encode v)=
normal T (normal T (C.encode u)++sep::C.encode v) := by
simpa only [List.nil_append] using
(normal_context T wt good stable [] (C.encode u) (sep::C.encode v)).symm
have hright : normal T (normal T (C.encode u)++sep::C.encode v)=
normal T (normal T (C.encode u)++sep::normal T (C.encode v)) := by
simpa only [List.append_nil,List.append_assoc,List.singleton_append] using
(normal_context T wt good stable (normal T (C.encode u)++[sep]) (C.encode v) []).symm
rw [hleft,hright,hcode u hu,hcode v hv]
obtain β¨rs,hrs,_β© := good
(C.encode (Canonical.least wf q u)++sep::C.encode (Canonical.least wf q v)).length
exact normal_eq_self T wt good stable hrs
(Static.separator_irreducible C wf q zero sep hs (hiso _ rs hrs) hc hi hu hv)
omit [DecidableEq A] [DecidableEq Q] in
theorem present_separator_iff {u v u' v' : List A}
(hu : q uβ none) (hv : q vβ none) (hu' : q u'β none) (hv' : q v'β none) :
present T (C.encode u++sep::C.encode v)=present T (C.encode u'++sep::C.encode v') β
q u=q u' β§ q v=q v' := by
rw [present_eq_iff T wt good stable,
normal_separator T wt good stable C wf q zero sep hshort hiso hstatic hc hi hzero hs hu hv,
normal_separator T wt good stable C wf q zero sep hshort hiso hstatic hc hi hzero hs hu' hv']
constructor
Β· exact Static.separator_literal_injective C wf q sep hs
Β· rintro β¨hu,hvβ©
rw [Canonical.least_congr wf q hu,Canonical.least_congr wf q hv]
omit [DecidableEq A] [DecidableEq Q] in
theorem present_separator_ne_zero (hz : zeroβC.Alphabet) (hzs : zeroβ sep)
{u v : List A} (hu : q uβ none) (hv : q vβ none) :
present T (C.encode u++sep::C.encode v)β present T [zero] := by
intro he
have hn := (present_eq_iff T wt good stable _ _).mp he
rw [normal_separator T wt good stable C wf q zero sep hshort hiso hstatic hc hi hzero hs hu hv] at hn
obtain β¨rs,hrs,_β© := good 1
have hz0 : normal T [zero]=[zero] := normal_eq_self T wt good stable hrs
(irreducible_of_short (fun p hp => hshort 1 rs hrs p hp))
rw [hz0] at hn
have hm : zeroβC.encode (Canonical.least wf q u)++sep::C.encode (Canonical.least wf q v) := by
rw [hn]; simp
simp only [List.mem_append,List.mem_cons] at hm
rcases hm with hm | hm | hm
Β· exact hz (C.mem_alphabet hm)
Β· exact hzs hm
Β· exact hz (C.mem_alphabet hm)
end Quotient
end FiniteAlgebraicEnvelopes.Bootstrap
namespace FiniteAlgebraicEnvelopes.Bootstrap.Uniform
variable {A B : Type*}
/-- The finite word ball over an explicit finite support. -/
def words (letters : List A) : β β List (List A)
| 0 => [[]]
| n+1 => [] :: letters.flatMap (fun a => (words letters n).map (a::Β·))
@[simp] theorem mem_words (letters : List A) (n : β) (w : List A) :
wβwords letters n β w.lengthβ€n β§ β aβw,aβletters := by
induction n generalizing w with
| zero => cases w <;> simp [words]
| succ n ih =>
cases w with
| nil => simp [words]
| cons a w =>
rw [words,List.mem_cons]
constructor
Β· rintro (he | h)
Β· cases he
Β· obtain β¨b,hb,hβ© := List.mem_flatMap.mp h
obtain β¨v,hv,heβ© := List.mem_map.mp h
obtain β¨rfl,rflβ© := List.cons.inj he
obtain β¨hlen,hsβ© := (ih v).mp hv
exact β¨by simpa using Nat.succ_le_succ hlen,by simpa [List.mem_cons] using And.intro hb hsβ©
Β· rintro β¨hlen,hsβ©
right
refine List.mem_flatMap.mpr β¨a,hs a List.mem_cons_self,List.mem_map.mpr β¨w,?_,rflβ©β©
exact (ih w).mpr β¨by simpa using hlen,fun b hb => hs b (List.mem_cons_of_mem _ hb)β©
theorem words_map (i : A β B) (ls : List A) (n : β) :
words (ls.map i) n = (words ls n).map (List.map i) := by
induction n with
| zero => rfl
| succ n ih =>
simp only [words,ih,List.map_cons,List.map_nil,List.flatMap_map,List.map_flatMap,List.map_map,Function.comp_def]
theorem words_specialize [Fintype A] (n : β) : words (Static.letters A) n=Static.words A n := by
induction n <;> simp_all only [words,Static.words]
theorem primrec_words [Primcodable A] : Primrecβ (@words A) := by
exact (Primrec.nat_rec (Primrec.const [[]])
(Primrec.list_cons.comp (Primrec.const [])
(Primrec.list_flatMap Primrec.fst
(Primrec.list_map (Primrec.snd.comp (Primrec.snd.comp Primrec.fst))
(Primrec.list_cons.comp (Primrec.snd.comp Primrec.fst) Primrec.snd).toβ).toβ)).toβ).of_eq
fun ls n => by induction n <;> simp_all [words]
end FiniteAlgebraicEnvelopes.Bootstrap.Uniform
namespace FiniteAlgebraicEnvelopes
namespace Effect
variable {X A B : Type*} [Primcodable X] [Primcodable A] [Primcodable B]
/-- Finite traversal of a total computable family is a computable list map. -/
theorem computable_map_parameter {f : X β A β B} (hf : Computableβ f) :
Computableβ (fun x (l : List A) => l.map (f x)) := by
apply (partrec_traverse_parameter hf.partrecβ).of_eq_tot
intro p
exact Bootstrap.Search.traverse_map _ _ _ (fun a _ => Part.mem_some _)
end Effect
namespace Bootstrap.Canonical
variable {A Q : Type*} [Fintype A] [Primcodable A]
{r : A β A β Prop} [DecidableRel (List.Shortlex r)] [Std.Trichotomous r]
(wf : WellFounded r) (q : List A β Q)
/-- Canonical representatives do not require a coding of the semantic class
type. Only its word-equivalence test must be algorithmic. -/
theorem computable_least (hr : PrimrecRel (List.Shortlex r))
(hq : ComputablePred (fun p : List A Γ List A => q p.1=q p.2)) : Computable (least wf q) := by
classical
let e (w v : List A) : Option Bool := some (decide (q v=q w))
have he : Computableβ e := (Primrec.option_some.to_comp.comp (hq.decide.comp (Computable.snd.pair Computable.fst))).toβ
let ps (w : List A) := (Static.words A w.length).map (fun v => (v,e w v))
have hp : Computable ps :=
(Effect.computable_map_parameter (Computable.snd.pair he).toβ).comp
Computable.id (Search.primrec_words.to_comp.comp Primrec.list_length.to_comp)
have hc : Computable (fun w => pick (r:=r) (ps w) w (some true)) :=
((Search.primrec_pick (Q:=Bool) hr Primrec.snd Primrec.fst (Primrec.const (some true))).to_comp.comp
(Computable.id.pair hp))
apply hc.of_eq
intro w
have hew : e w w=some true := by simp [e]
have heq : least wf (e w) w=least wf q w := by
apply (eq_least_iff wf q).mpr
refine β¨least_length wf (e w) w,?_,?_β©
Β· have hh := least_class wf (e w) w
simpa [e] using hh
Β· intro v hv hh
apply least_min wf (e w) hv
simp [e,hh]
rw [β hew]
rw [pick_eq_least wf (e w) (fun p hp => by
obtain β¨v,_,rflβ© := List.mem_map.mp hp
rfl)]
Β· exact heq
Β· apply List.mem_map.mpr
refine β¨least wf (e w) w,(Static.mem_words _ _).mpr (least_length wf (e w) w),?_β©
simp only [Prod.mk.injEq,true_and]
exact least_class wf (e w) w
omit [Fintype A] [Primcodable A] [DecidableRel (List.Shortlex r)] in
/-- Equality of computed representatives is exactly equality in the semantic
quotient, not merely equality of a chosen noncanonical encoding. -/
theorem least_eq_iff {u v : List A} : least wf q u=least wf q v β q u=q v := by
constructor
Β· intro h
exact (least_class wf q u).symm.trans ((congrArg q h).trans (least_class wf q v))
Β· exact least_congr wf q
end Bootstrap.Canonical
namespace WordProblem
variable {G : Type*} [Group G] {n : β} (s : Fin n β G)
/-- The original word-problem algorithm gives a genuine two-word comparison. -/
theorem computable_word_equiv (h : ComputablePred (fun w : Word n => evalWord s w=1)) :
ComputablePred (fun p : Word n Γ Word n => evalWord s p.1=evalWord s p.2) := by
classical
have hc : ComputablePred (fun p : Word n Γ Word n =>
evalWord s (p.1 ++ FreeGroup.invRev p.2)=1) :=
β¨inferInstance,h.decide.comp (Primrec.list_append.comp Primrec.fst
((invRev_primrec n).comp Primrec.snd)).to_compβ©
exact hc.of_eq (fun p => by rw [evalWord_append,evalWord_invRev,mul_inv_eq_one])
end WordProblem
end FiniteAlgebraicEnvelopes
namespace FiniteAlgebraicEnvelopes.WordProblem
def letterRel (n : β) (a b : Fin n Γ Bool) : Prop := Encodable.encode a<Encodable.encode b
local instance (n : β) : DecidableRel (letterRel n) := fun _ _ => inferInstanceAs (Decidable (_ < _))
local instance (n : β) : Std.Trichotomous (letterRel n) := β¨fun a b hab hba => by
apply Encodable.encode_injective
change Β¬Encodable.encode a<Encodable.encode b at hab
change Β¬Encodable.encode b<Encodable.encode a at hba
omegaβ©
theorem letterRel_wf (n : β) : WellFounded (letterRel n) := InvImage.wf Encodable.encode Nat.lt_wfRel.wf
theorem primrec_letterShortlex (n : β) : PrimrecRel (List.Shortlex (letterRel n)) := by
let ord : LinearOrder (Fin n Γ Bool) := LinearOrder.lift' Encodable.encode Encodable.encode_injective
exact @Bootstrap.Search.primrec_shortlex _ _ _ ord β¨inferInstance,Primrec.dom_finite _β©
variable {G : Type*} [Group G] {n : β} (s : Fin n β G)
noncomputable def testedClass : Word n β Word n :=
Bootstrap.Canonical.least (letterRel_wf n) (evalWord s)
theorem computable_testedClass (h : ComputablePred (fun w : Word n => evalWord s w=1)) :
Computable (testedClass s) := by
classical
exact Bootstrap.Canonical.computable_least (letterRel_wf n) (evalWord s)
(primrec_letterShortlex n) (computable_word_equiv s h)
theorem testedClass_eq_iff (u v : Word n) : testedClass s u=testedClass s v β evalWord s u=evalWord s v := by
classical
exact Bootstrap.Canonical.least_eq_iff _ _
end FiniteAlgebraicEnvelopes.WordProblem
end OAI
import OAI.Computability.FiniteCompiler.Selectors
import OAI.Computability.FiniteCompiler.Effectivity
import OAI.GroupTheory.BooneHigman.Basic
import OAI.GroupTheory.BooneHigman.WordProblem
namespace OAI
/-!
Canonical compiler quotients and effective tested classes for word problems.
-/
namespace FiniteAlgebraicEnvelopes.Bootstrap
open Relation
namespace BlockCode
variable {A B S : Type*} (C : BlockCode A S)
def Alphabet : Set S := {s | β a, s β C.block a}
theorem mem_alphabet {w : List A} {s : S} (h : s β C.encode w) : s β C.Alphabet := by
obtain β¨a,_,haβ© := List.mem_flatMap.mp h
exact β¨a,haβ©
theorem encode_ne_nil {w : List A} (h : w β []) : C.encode w β [] := by
intro he
exact h (C.encode_injective (he.trans C.encode_nil.symm))
theorem disjoint_infix (D : BlockCode B S) (hd : Disjoint C.Alphabet D.Alphabet)
{w : List A} {v : List B} (hv : v β []) (hi : D.encode v <:+: C.encode w) : False := by
obtain β¨s,hsβ© := List.exists_mem_of_ne_nil _ (D.encode_ne_nil hv)
exact Set.disjoint_left.mp hd (C.mem_alphabet (hi.subset hs)) (D.mem_alphabet hs)
theorem disjoint_overlap (D : BlockCode B S) (hd : Disjoint C.Alphabet D.Alphabet)
{u : List A} {v : List B} {p m q : List S} (hm : m β [])
(hu : C.encode u=p++m) (hv : D.encode v=m++q) : False := by
obtain β¨s,hsβ© := List.exists_mem_of_ne_nil _ hm
exact Set.disjoint_left.mp hd (C.mem_alphabet (hu βΈ List.mem_append_right p hs))
(D.mem_alphabet (hv βΈ List.mem_append_left q hs))
end BlockCode
namespace Static
variable {S A Q : Type*} [Fintype A] [DecidableEq A] [DecidableEq S] [DecidableEq Q]
variable {r : A β A β Prop} [Std.Trichotomous r]
variable (C : BlockCode A S) (wf : WellFounded r) (q : List A β Option Q) (z : S)
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_support {n : β} {p : List S Γ List S} (hp : p β table C wf q z n) :
p.1 β [] β§ β s β p.1,s β C.Alphabet := by
rcases p with β¨u,vβ©
obtain β¨w,_,hn,_,rfl,rflβ© := (mem_table C wf q z).mp hp
exact β¨C.encode_ne_nil hn,fun _ hs => C.mem_alphabet hsβ©
omit [DecidableEq A] [DecidableEq Q] in
theorem table_decrease {s : S β S β Prop} (hwidth : 1<C.width+1)
(hc : β a b, r a b β List.Lex s (C.block a) (C.block b)) (n : β) :
β p β table C wf q z n,List.Shortlex s p.2 p.1 := by
intro β¨u,vβ© hp
obtain β¨w,_,hn,he,rfl,rflβ© := (mem_table C wf q z).mp hp
unfold output
split
Β· apply List.Shortlex.of_length_lt
simp only [List.length_singleton,C.encode_length]
have hw : 1 β€ w.length := by have := List.length_pos_iff.mpr hn; omega
nlinarith
Β· obtain h | h := Canonical.least_lt_or_eq wf q w
Β· exact C.encode_shortlex hc h
Β· exact False.elim (he (by simp_all [output]))
omit [DecidableEq A] [DecidableEq Q] [Std.Trichotomous r] in
theorem table_bounded {k n : β} (hkn : k β€ n) :
Selectors.BoundedEq (table C wf q z (k/(C.width+1))) (table C wf q z (n/(C.width+1))) k := by
intro β¨u,vβ© hu
simp only [mem_table]
constructor
Β· rintro β¨w,hw,hn,he,rfl,rflβ©
exact β¨w,hw.trans (Nat.div_le_div_right hkn),hn,he,rfl,rflβ©
Β· rintro β¨w,hw,hn,he,rfl,rflβ©
refine β¨w,?_,hn,he,rfl,rflβ©
apply (Nat.le_div_iff_mul_le (Nat.succ_pos _)).mpr
simpa only [C.encode_length,Nat.mul_comm] using hu
omit [DecidableEq A] [DecidableEq Q] in
theorem critical_containment_bound {n : β} {rs : List (List S Γ List S)}
(hzero : q [] β none) (hz : Absorbs rs z)
(ht : β p β table C wf q z (n/(C.width+1)), p β rs)
(hc : Contextual q (n/(C.width+1))) (hi : ZeroIdeal q (n/(C.width+1)))
{u u' v v' x y : List S}
(hu : (u,u') β table C wf q z (n/(C.width+1)))
(hv : (v,v') β table C wf q z (n/(C.width+1)))
(he : u=x++v++y) (hlen : u.length β€ n) : Join (Steps rs) u' (x++v'++y) := by
apply critical_containment C wf q z hzero hz ht hc hi hu hv he
obtain β¨w,hw,_,_,rfl,_β© := (mem_table C wf q z).mp hu
simpa only [C.encode_length] using Nat.mul_le_mul_left (C.width+1) hw
omit [DecidableEq A] [DecidableEq Q] in
theorem critical_overlap_bound {n : β} {rs : List (List S Γ List S)}
(hzero : q [] β none) (hz : Absorbs rs z)
(ht : β p β table C wf q z (n/(C.width+1)), p β rs)
(hc : Contextual q (n/(C.width+1))) (hi : ZeroIdeal q (n/(C.width+1)))
{u u' v v' p m t : List S}
(hu : (u,u') β table C wf q z (n/(C.width+1)))