Download data/lean/OAI/Computability/WitnessedChoice/TermGraphs.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 51.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WitnessedChoice/TermGraphs.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/WitnessedChoice/TermGraphs.lean
-
curl -L -o TermGraphs.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WitnessedChoice/TermGraphs.lean
51.1 kB
import OAI.Computability.WitnessedChoice.ChoiceTrace
namespace OAI
section
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.HFCoding
variable {A : Type}
def LoopGraph (d : Set (HF A)) (p : β) {n : β}
(step : Domain d β (Fin (n+1) β Domain d) β Prop) :
β β Domain d β Domain d β (Fin n β Domain d) β Prop
| 0, z, _, _ => z.val = emptyHF
| fuel+1, z, x, env =>
((TC x.val).card > p β§ z.val = emptyHF) β¨
((TC x.val).card β€ p β§ β y : Domain d, step y (Fin.cons x env) β§
((x = y β§ z = x) β¨ (x β y β§ LoopGraph d p step fuel z y env)))
mutual
def Term.Graph [Fintype A] (d : Set (HF A)) (S : Input A) (p K : β) :
{n : β} β Term n β Domain d β (Fin n β Domain d) β Prop
| _, .var j, z, env => z = env j
| _, .empty, z, _ => z.val = emptyHF
| _, .atoms, z, _ => z.val = ofFinset (Finset.univ.image atom)
| _, .pair a b, z, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ z.val = double x.val y.val
| _, .union a, z, env => β x : Domain d, a.Graph d S p K x env β§ z.val = unionHF x.val
| _, .unique a, z, env => β x : Domain d, a.Graph d S p K x env β§ z.val = uniqueHF x.val
| _, .card a, z, env => β x : Domain d, a.Graph d S p K x env β§
(elements x.val).card β€ K β§ z.val = cardHF x.val
| _, .comprehend body range guard, z, env => β r : Domain d,
range.Graph d S p K r env β§
(β x : Domain d, x.val β r.val β β b : Bool,
guard.Graph d S p K b (Fin.cons x env) β§
(b = true β β y : Domain d, body.Graph d S p K y (Fin.cons x env))) β§
isSet z.val = true β§ β y : Domain d, y.val β z.val β β x : Domain d,
x.val β r.val β§ guard.Graph d S p K true (Fin.cons x env) β§
body.Graph d S p K y (Fin.cons x env)
| _, .iterate step, z, env => β x : Domain d, x.val = emptyHF β§
LoopGraph d p (step.Graph d S p K) (p+1) z x env
def Formula.Graph [Fintype A] (d : Set (HF A)) (S : Input A) (p K : β) :
{n : β} β Formula n β Bool β (Fin n β Domain d) β Prop
| _, .equal a b, v, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ v = decide (x.val = y.val)
| _, .input r a b, v, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ v = inputHF S r x.val y.val
| _, .neg a, v, env => β b : Bool, a.Graph d S p K b env β§ v = !b
| _, .and a b, v, env => β c e : Bool, a.Graph d S p K c env β§
b.Graph d S p K e env β§ v = (c && e)
| _, .or a b, v, env => β c e : Bool, a.Graph d S p K c env β§
b.Graph d S p K e env β§ v = (c || e)
| _, .wsc _ _ _ _, _, _ => False
end
lemma domain_cons_val {d : Set (HF A)} {n : β} (x : Domain d) (env : Fin n β Domain d) :
(fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val) = Fin.cons x.val (fun j => (env j).val) := by
funext j
exact Fin.cases rfl (fun _ => rfl) j
lemma LoopGraph.sound {d : Set (HF A)} (p : β) {n : β}
(step : Domain d β (Fin (n+1) β Domain d) β Prop)
(ts : HF A β Traced A (HF A)) (env : Fin n β Domain d)
(hs : β x y : Domain d, step y (Fin.cons x env) β y.val = (ts x.val).1)
(fuel : β) (z x : Domain d) (h : LoopGraph d p step fuel z x env) :
z.val = (tracedLoop p ts fuel x.val).1 := by
induction fuel generalizing z x with
| zero => exact h
| succ fuel ih =>
rcases h with β¨hb,hzβ© | β¨hb,y,hy,heβ©
Β· simpa only [tracedLoop,ite_eq_right (by omega : Β¬ (TC x.val).card β€ p)] using hz
Β· have hval := hs x y hy
rcases he with β¨rfl,rflβ© | β¨hne,hrecβ©
Β· simp only [tracedLoop,ite_eq_left hb,ite_eq_left hval]
Β· have hn : x.val β (ts x.val).1 := fun h => hne (Subtype.ext (h.trans hval.symm))
simp only [tracedLoop,ite_eq_left hb,ite_eq_right hn]
rw [β hval]
exact ih z y hrec
variable [Fintype A]
mutual
lemma Term.graph_sound (d : Set (HF A)) (S : Input A) (p K : β)
(hd : β x β d, β y, y β x β y β d) {n : β}
(t : Term n) (z : Domain d) (env : Fin n β Domain d)
(h : t.Graph d S p K z env) : z.val = (t.traced S p (fun j => (env j).val)).1 := by
cases t with
| var j => exact congrArg Subtype.val h
| empty => exact h
| atoms => exact h
| pair a b =>
obtain β¨x,y,hx,hy,hzβ© := h
change z.val = double (a.traced S p (fun j => (env j).val)).1
(b.traced S p (fun j => (env j).val)).1
exact hz.trans (congrArgβ double (a.graph_sound d S p K hd x env hx)
(b.graph_sound d S p K hd y env hy))
| union a =>
obtain β¨x,hx,hzβ© := h
exact hz.trans (congrArg unionHF (a.graph_sound d S p K hd x env hx))
| unique a =>
obtain β¨x,hx,hzβ© := h
exact hz.trans (congrArg uniqueHF (a.graph_sound d S p K hd x env hx))
| card a =>
obtain β¨x,hx,_,hzβ© := h
exact hz.trans (congrArg cardHF (a.graph_sound d S p K hd x env hx))
| comprehend body range guard =>
obtain β¨r,hr,hall,hz,hmemβ© := h
have her := range.graph_sound d S p K hd r env hr
apply ext_sets hz (isSet_ofFinset _)
intro y
simp only [mem_ofFinset,Finset.mem_image,Finset.mem_filter]
constructor
Β· intro hy
obtain β¨x,hx,hg,hbβ© := (hmem β¨y,hd _ z.property _ hyβ©).mp hy
refine β¨x.val,β¨by rwa [β her],?_β©,?_β©
Β· have hh := guard.graph_sound d S p K hd true (Fin.cons x env) hg
simpa only [domain_cons_val] using hh.symm
Β· have hh := body.graph_sound d S p K hd β¨y,hd _ z.property _ hyβ© (Fin.cons x env) hb
simpa only [domain_cons_val] using hh.symm
Β· rintro β¨x,β¨hxr,hgtβ©,heyβ©
have hxd : x β d := hd _ r.property _ (by rwa [her])
let xx : Domain d := β¨x,hxdβ©
have hxx : xx.val β r.val := by change x β r.val; rwa [her]
obtain β¨v,hv,hbodyβ© := hall xx hxx
have he := guard.graph_sound d S p K hd v (Fin.cons xx env) hv
simp only [domain_cons_val] at he
have hvt : v = true := he.trans hgt
obtain β¨w,hwβ© := hbody hvt
have hew := body.graph_sound d S p K hd w (Fin.cons xx env) hw
simp only [domain_cons_val] at hew
have hwval : w.val = y := hew.trans hey
have hyd : y β d := hwval βΈ w.property
apply (hmem β¨y,hydβ©).mpr
refine β¨xx,hxx,hvt βΈ hv,?_β©
have heq : w = (β¨y,hydβ© : Domain d) := Subtype.ext hwval
rwa [β heq]
| iterate step =>
obtain β¨x,hx,hlβ© := h
have hh := LoopGraph.sound p (step.Graph d S p K)
(fun y => step.traced S p (Fin.cons y (fun j => (env j).val))) env
(fun x y h => by simpa only [domain_cons_val] using
step.graph_sound d S p K hd y (Fin.cons x env) h) (p+1) z x hl
simpa only [Term.traced,hx] using hh
termination_by sizeOf t
decreasing_by all_goals subst_vars; simp_wf <;> omega
lemma Formula.graph_sound (d : Set (HF A)) (S : Input A) (p K : β)
(hd : β x β d, β y, y β x β y β d) {n : β}
(f : Formula n) (v : Bool) (env : Fin n β Domain d)
(h : f.Graph d S p K v env) : v = (f.traced S p (fun j => (env j).val)).1 := by
cases f with
| equal a b =>
obtain β¨x,y,hx,hy,hvβ© := h
exact hv.trans (congrArgβ (fun x y : HF A => decide (x = y))
(a.graph_sound d S p K hd x env hx) (b.graph_sound d S p K hd y env hy))
| input r a b =>
obtain β¨x,y,hx,hy,hvβ© := h
exact hv.trans (congrArgβ (inputHF S r)
(a.graph_sound d S p K hd x env hx) (b.graph_sound d S p K hd y env hy))
| neg a =>
obtain β¨b,hb,hvβ© := h
change v = !(a.traced S p (fun j => (env j).val)).1
exact hv.trans (congrArg Bool.not (a.graph_sound d S p K hd b env hb))
| and a b =>
obtain β¨c,e,hc,he,hvβ© := h
exact hv.trans (congrArgβ Bool.and (a.graph_sound d S p K hd c env hc)
(b.graph_sound d S p K hd e env he))
| or a b =>
obtain β¨c,e,hc,he,hvβ© := h
exact hv.trans (congrArgβ Bool.or (a.graph_sound d S p K hd c env hc)
(b.graph_sound d S p K hd e env he))
| wsc step choice witness output => exact h.elim
termination_by sizeOf f
decreasing_by all_goals subst_vars; simp_wf <;> omega
end
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.HFCoding
variable {A : Type}
def AdmissibleTrace (d : Set (HF A)) (K : β) (F : Finset (HF A)) : Prop :=
β x β F, x β d β§ (elements x).card β€ K
lemma AdmissibleTrace.mono {d : Set (HF A)} {K : β} {F G : Finset (HF A)}
(h : AdmissibleTrace d K F) (hg : G β F) : AdmissibleTrace d K G :=
fun x hx => h x (hg hx)
lemma admissibleTrace_of_closed {F : Finset (HF A)} (hF : ClosedTrace F) :
AdmissibleTrace (F : Set (HF A)) F.card F := by
intro x hx
exact β¨hx,Finset.card_le_card ((elements_subset_closure x).trans (hF x hx))β©
lemma LoopGraph.complete {d : Set (HF A)} (p K : β) {n : β}
(step : Domain d β (Fin (n+1) β Domain d) β Prop)
(ts : HF A β Traced A (HF A)) (env : Fin n β Domain d)
(hout : β x, (ts x).1 β (ts x).2)
(hs : β x y : Domain d, AdmissibleTrace d K (ts x.val).2 β
y.val = (ts x.val).1 β step y (Fin.cons x env))
(fuel : β) (z x : Domain d)
(ht : AdmissibleTrace d K (tracedLoop p ts fuel x.val).2)
(hz : z.val = (tracedLoop p ts fuel x.val).1) :
LoopGraph d p step fuel z x env := by
induction fuel generalizing z x with
| zero => exact hz
| succ fuel ih =>
by_cases hb : (TC x.val).card β€ p
Β· have htstep : AdmissibleTrace d K (ts x.val).2 := by
simp only [tracedLoop,ite_eq_left hb] at ht
split_ifs at ht with he
Β· exact ht
Β· exact ht.mono Finset.subset_union_left
let y : Domain d := β¨(ts x.val).1,(htstep _ (hout _)).1β©
refine Or.inr β¨hb,y,hs x y htstep rfl,?_β©
by_cases he : x.val = (ts x.val).1
Β· left
exact β¨Subtype.ext he,Subtype.ext (by simpa only [tracedLoop,ite_eq_left hb,ite_eq_left he] using hz)β©
Β· right
refine β¨fun h => he (congrArg Subtype.val h),?_β©
apply ih z y
Β· exact ht.mono (by simp only [tracedLoop,ite_eq_left hb,ite_eq_right he]; exact Finset.subset_union_right)
Β· simpa only [tracedLoop,ite_eq_left hb,ite_eq_right he] using hz
Β· exact Or.inl β¨by omega,by simpa only [tracedLoop,ite_eq_right hb] using hzβ©
variable [Fintype A]
mutual
lemma Term.graph_complete (d : Set (HF A)) (S : Input A) (p K : β)
(hd : β x β d, β y, y β x β y β d) (hempty : emptyHF β d) {n : β} (t : Term n) (hzero : t.wscCount = 0)
(z : Domain d) (env : Fin n β Domain d)
(ht : AdmissibleTrace d K (t.traced S p (fun j => (env j).val)).2)
(hz : z.val = (t.traced S p (fun j => (env j).val)).1) : t.Graph d S p K z env := by
cases t with
| var j => exact Subtype.ext hz
| empty => exact hz
| atoms => exact hz
| pair a b =>
have h := Nat.add_eq_zero_iff.mp hzero
have ha := ht.mono (Finset.subset_union_left.trans (Finset.subset_insert _ _))
have hb := ht.mono (Finset.subset_union_right.trans (Finset.subset_insert _ _))
let x : Domain d := β¨(a.traced S p (fun j => (env j).val)).1,(ha _ (a.traced_self S p _)).1β©
let y : Domain d := β¨(b.traced S p (fun j => (env j).val)).1,(hb _ (b.traced_self S p _)).1β©
exact β¨x,y,a.graph_complete d S p K hd hempty h.1 x env ha rfl,
b.graph_complete d S p K hd hempty h.2 y env hb rfl,hzβ©
| union a | unique a =>
have ha := ht.mono (Finset.subset_insert _ _)
let x : Domain d := β¨(a.traced S p (fun j => (env j).val)).1,(ha _ (a.traced_self S p _)).1β©
exact β¨x,a.graph_complete d S p K hd hempty hzero x env ha rfl,hzβ©
| card a =>
have ha := ht.mono Finset.subset_union_right
let x : Domain d := β¨(a.traced S p (fun j => (env j).val)).1,(ha _ (a.traced_self S p _)).1β©
exact β¨x,a.graph_complete d S p K hd hempty hzero x env ha rfl,
(ha _ (a.traced_self S p _)).2,hzβ©
| comprehend body range guard =>
have h := Nat.add_eq_zero_iff.mp hzero
have h' := Nat.add_eq_zero_iff.mp h.1
have hr := ht.mono (Finset.subset_union_left.trans
(Finset.subset_union_left.trans (Finset.subset_insert _ _)))
let r : Domain d := β¨(range.traced S p (fun j => (env j).val)).1,
(hr _ (range.traced_self S p _)).1β©
have hg (x : Domain d) (hx : x.val β r.val) :
AdmissibleTrace d K (guard.traced S p (fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val)).2 := by
rw [domain_cons_val]
apply ht.mono
intro y hy
exact Finset.mem_insert_of_mem (Finset.mem_union_left _
(Finset.mem_union_right _ (Finset.mem_biUnion.mpr β¨x.val,hx,hyβ©)))
have hb (x : Domain d) (hx : x.val β r.val)
(hxg : (guard.traced S p (fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val)).1 = true) :
AdmissibleTrace d K (body.traced S p (fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val)).2 := by
rw [domain_cons_val] at hxg β’
apply ht.mono
intro y hy
exact Finset.mem_insert_of_mem (Finset.mem_union_right _
(Finset.mem_biUnion.mpr β¨x.val,Finset.mem_filter.mpr β¨hx,hxgβ©,hyβ©))
refine β¨r,range.graph_complete d S p K hd hempty h'.2 r env hr rfl,?_,?_,?_β©
Β· intro x hx
refine β¨(guard.traced S p (fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val)).1,
guard.graph_complete d S p K hd hempty h.2 _ _ (hg x hx) rfl,?_β©
intro hxg
let y : Domain d := β¨(body.traced S p (fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val)).1,
((hb x hx hxg) _ (body.traced_self S p _)).1β©
exact β¨y,body.graph_complete d S p K hd hempty h'.1 y _ (hb x hx hxg) rflβ©
Β· rw [hz]; exact isSet_ofFinset _
Β· intro y
rw [hz]
change y.val β ofFinset _ β _
simp only [mem_ofFinset,Finset.mem_image,Finset.mem_filter]
constructor
Β· rintro β¨x,β¨hx,hxgβ©,hyβ©
have hxd : x β d := (hr x (range.traced_closure S p _ (elements_subset_closure _ hx))).1
let xx : Domain d := β¨x,hxdβ©
have hxg' : (guard.traced S p (fun j => ((Fin.cons xx env : Fin (_+1) β Domain d) j).val)).1 = true := by
simpa only [domain_cons_val] using hxg
refine β¨xx,hx,guard.graph_complete d S p K hd hempty h.2 true _ (hg xx hx) hxg'.symm,?_β©
apply body.graph_complete d S p K hd hempty h'.1 y _ (hb xx hx hxg')
simpa only [domain_cons_val] using hy.symm
Β· rintro β¨x,hx,hxg,hyβ©
have hgt := guard.graph_sound d S p K hd true (Fin.cons x env) hxg
have hbt := body.graph_sound d S p K hd y (Fin.cons x env) hy
simp only [domain_cons_val] at hgt hbt
exact β¨x.val,β¨hx,hgt.symmβ©,hbt.symmβ©
| iterate step =>
let x : Domain d := β¨emptyHF,hemptyβ©
refine β¨x,rfl,LoopGraph.complete p K (step.Graph d S p K)
(fun y => step.traced S p (Fin.cons y (fun j => (env j).val))) env
(fun y => step.traced_self S p _) ?_ (p+1) z x ht hzβ©
intro a b ha hb
apply step.graph_complete d S p K hd hempty hzero b (Fin.cons a env)
Β· simpa only [domain_cons_val] using ha
Β· simpa only [domain_cons_val] using hb
termination_by sizeOf t
decreasing_by all_goals subst_vars; simp_wf <;> omega
lemma Formula.graph_complete (d : Set (HF A)) (S : Input A) (p K : β)
(hd : β x β d, β y, y β x β y β d) (hempty : emptyHF β d) {n : β} (f : Formula n) (hzero : f.wscCount = 0)
(v : Bool) (env : Fin n β Domain d)
(ht : AdmissibleTrace d K (f.traced S p (fun j => (env j).val)).2)
(hv : v = (f.traced S p (fun j => (env j).val)).1) : f.Graph d S p K v env := by
cases f with
| equal a b | input r a b =>
have h := Nat.add_eq_zero_iff.mp hzero
have ha := ht.mono Finset.subset_union_left
have hb := ht.mono Finset.subset_union_right
let x : Domain d := β¨(a.traced S p (fun j => (env j).val)).1,(ha _ (a.traced_self S p _)).1β©
let y : Domain d := β¨(b.traced S p (fun j => (env j).val)).1,(hb _ (b.traced_self S p _)).1β©
exact β¨x,y,a.graph_complete d S p K hd hempty h.1 x env ha rfl,
b.graph_complete d S p K hd hempty h.2 y env hb rfl,hvβ©
| neg a => exact β¨_,a.graph_complete d S p K hd hempty hzero _ env ht rfl,hvβ©
| and a b | or a b =>
have h := Nat.add_eq_zero_iff.mp hzero
exact β¨_,_,a.graph_complete d S p K hd hempty h.1 _ env (ht.mono Finset.subset_union_left) rfl,
b.graph_complete d S p K hd hempty h.2 _ env (ht.mono Finset.subset_union_right) rfl,hvβ©
| wsc step choice witness output => simp only [Formula.wscCount] at hzero; omega
termination_by sizeOf f
decreasing_by all_goals subst_vars; simp_wf <;> omega
end
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.Counting WitnessedSeparation.HFCoding
variable {ΞΉ R : Type} {D : ΞΉ β Type} {S : β i, Counting.Structure R (D i)} {m n : β}
lemma uniform_const (P : Prop) : UniformDefinable S m n (fun _ _ => P) := by
by_cases h : P
Β· exact UniformDefinable.falsum.neg.congr (fun _ _ => by simp [h])
Β· exact UniformDefinable.falsum.congr (fun _ _ => by simp [h])
lemma uniform_exists_finite {X : Type} [Fintype X] {P : X β β i, (Fin n β D i) β Prop}
(h : β x, UniformDefinable S m n (P x)) :
UniformDefinable S m n (fun i v => β x, P x i v) := by
simpa only [Finset.mem_univ,true_and] using
UniformDefinable.exists_finset Finset.univ (fun x _ => h x)
lemma uniform_decide {P : β i, (Fin n β D i) β Prop}
(h : UniformDefinable S m n P) (b : Bool) :
UniformDefinable S m n (fun i v => b = decide (P i v)) := by
cases b
Β· exact h.neg.congr (fun _ _ => by simp)
Β· exact h.congr (fun _ _ => by simp)
lemma uniform_formula_binary
{P Q : β i, (Fin (n+1) β D i) β Prop} {T : β i, (Fin 2 β D i) β Prop}
(hP : UniformDefinable S m (n+1) P) (hQ : UniformDefinable S m (n+1) Q)
(hT : UniformDefinable S m 2 T) (hr : n+1 < m) :
UniformDefinable S m n (fun i v => β x y,
P i (Fin.cons x v) β§ Q i (Fin.cons y v) β§ T i ![x,y]) := by
have h1 := hP.reindex (Fin.cons 1 (fun j => j.succ.succ) : Fin (n+1) β Fin (n+2))
have h2 := hQ.reindex (Fin.cons 0 (fun j => j.succ.succ) : Fin (n+1) β Fin (n+2))
have h3 := hT.reindex (![1,0] : Fin 2 β Fin (n+2))
apply (((h1.and (h2.and h3)).ex hr).ex (by omega)).congr
intro i v
apply exists_congr; intro x
apply exists_congr; intro y
have h1' : Fin.cons y (Fin.cons x v) β
(Fin.cons 1 (fun j => j.succ.succ) : Fin (n+1) β Fin (n+2)) = Fin.cons x v := by
funext j; exact Fin.cases rfl (fun _ => rfl) j
have h2' : Fin.cons y (Fin.cons x v) β
(Fin.cons 0 (fun j => j.succ.succ) : Fin (n+1) β Fin (n+2)) = Fin.cons y v := by
funext j; exact Fin.cases rfl (fun _ => rfl) j
have h3' : Fin.cons y (Fin.cons x v) β (![1,0] : Fin 2 β Fin (n+2)) = ![x,y] := by
funext j; fin_cases j <;> rfl
simp only [h1',h2',h3']
variable {A : ΞΉ β Type} (d : β i, Set (HF (A i)))
variable (T : β i, Counting.Structure R (Domain (d i)))
variable (hmem : UniformDefinable T m 2 (fun _ v => (v 0).val β (v 1).val))
variable (hset : UniformDefinable T m 1 (fun _ v => isSet (v 0).val = true))
include hmem hset in
lemma uniform_BGS_comprehension
{P : β i, Domain (d i) β (Fin n β Domain (d i)) β Prop}
{Q : β i, Bool β (Fin (n+1) β Domain (d i)) β Prop}
{B : β i, Domain (d i) β (Fin (n+1) β Domain (d i)) β Prop}
(hP : UniformDefinable T m (n+1) (fun i v => P i (v 0) (Fin.tail v)))
(hQ : β b, UniformDefinable T m (n+1) (fun i v => Q i b v))
(hB : UniformDefinable T m (n+2) (fun i v => B i (v 0) (Fin.tail v)))
(hm : n+4 β€ m) : UniformDefinable T m (n+1) (fun i v => β r,
P i r (Fin.tail v) β§
(β x : Domain (d i), x.val β r.val β β b : Bool,
Q i b (Fin.cons x (Fin.tail v)) β§
(b = true β β y : Domain (d i), B i y (Fin.cons x (Fin.tail v)))) β§
isSet (v 0).val = true β§ β y : Domain (d i), y.val β (v 0).val β
β x : Domain (d i), x.val β r.val β§ Q i true (Fin.cons x (Fin.tail v)) β§
B i y (Fin.cons x (Fin.tail v))) := by
have hBtotal := (hB.reindex
(Fin.cons 0 (Fin.cons 1 (fun j => j.succ.succ.succ.succ)) : Fin (n+2) β Fin (n+4))).ex (by omega)
have htotal := ((hmem.reindex (![0,1] : Fin 2 β Fin (n+3))).imp
(uniform_exists_finite (fun b : Bool =>
((hQ b).reindex (Fin.cons 0 (fun j => j.succ.succ.succ) : Fin (n+1) β Fin (n+3))).and
((uniform_const (b = true)).imp hBtotal)))).all (by omega)
have hguard := (hQ true).reindex
(Fin.cons 0 (fun j => j.succ.succ.succ.succ) : Fin (n+1) β Fin (n+4))
have hbody := hB.reindex
(Fin.cons 1 (Fin.cons 0 (fun j => j.succ.succ.succ.succ)) : Fin (n+2) β Fin (n+4))
have hrhs := ((hmem.reindex (![0,2] : Fin 2 β Fin (n+4))).and (hguard.and hbody)).ex (by omega)
have hext := ((hmem.reindex (![0,2] : Fin 2 β Fin (n+3))).iff hrhs).all (by omega)
have hbound := hP.reindex (Fin.cons 0 (fun j => j.succ.succ) : Fin (n+1) β Fin (n+2))
have hset' := hset.reindex (![1] : Fin 1 β Fin (n+2))
apply ((hbound.and (htotal.and (hset'.and hext))).ex (by omega)).congr
intro i v
simp only [Fin.comp_cons,Fin.cons_zero,Fin.tail_cons,Function.comp_apply]
rfl
lemma LoopGraph.uniform (p : β)
(step : β i, Domain (d i) β (Fin (n+1) β Domain (d i)) β Prop)
(hstep : UniformDefinable T m (n+2) (fun i v => step i (v 0) (Fin.tail v)))
(hcut : UniformDefinable T m 1 (fun _ v => (TC (v 0).val).card β€ p))
(hemp : UniformDefinable T m 1 (fun _ v => (v 0).val = emptyHF))
(hm : n+2 < m) (fuel : β) : UniformDefinable T m (n+2)
(fun i v => LoopGraph (d i) p (step i) fuel (v 0) (v 1) (Fin.tail (Fin.tail v))) := by
induction fuel with
| zero => exact hemp.reindex ![0]
| succ fuel ih =>
have hc := hcut.reindex (![1] : Fin 1 β Fin (n+2))
have hz := hemp.reindex (![0] : Fin 1 β Fin (n+2))
have hs := hstep.reindex (Fin.cons 0 (Fin.cons 2 (fun j => j.succ.succ.succ)) : Fin (n+2) β Fin (n+3))
have hxy : UniformDefinable T m (n+3) (fun _ v => v 2 = v 0) := UniformDefinable.equal 2 0
have hzx : UniformDefinable T m (n+3) (fun _ v => v 1 = v 2) := UniformDefinable.equal 1 2
have hrec := ih.reindex (Fin.cons 1 (Fin.cons 0 (fun j => j.succ.succ.succ)) : Fin (n+2) β Fin (n+3))
have hy := (hs.and ((hxy.and hzx).or (hxy.neg.and hrec))).ex hm
apply ((hc.neg.and hz).or (hc.and hy)).congr
intro i v
have hvc : v β (![1] : Fin 1 β Fin (n+2)) = ![v 1] := by
funext j; fin_cases j; rfl
have hvz : v β (![0] : Fin 1 β Fin (n+2)) = ![v 0] := by
funext j; fin_cases j; rfl
have hs' (y : Domain (d i)) : Fin.cons y v β
(Fin.cons 0 (Fin.cons 2 (fun j => j.succ.succ.succ)) : Fin (n+2) β Fin (n+3)) =
Fin.cons y (Fin.cons (v 1) (Fin.tail (Fin.tail v))) := by
funext j; refine Fin.cases rfl (fun j => ?_) j
exact Fin.cases rfl (fun _ => rfl) j
have hr' (y : Domain (d i)) : Fin.cons y v β
(Fin.cons 1 (Fin.cons 0 (fun j => j.succ.succ.succ)) : Fin (n+2) β Fin (n+3)) =
Fin.cons (v 0) (Fin.cons y (Fin.tail (Fin.tail v))) := by
funext j; refine Fin.cases rfl (fun j => ?_) j
exact Fin.cases rfl (fun _ => rfl) j
simp only [hvc,hvz,hs',hr',Fin.cons_zero,Fin.tail_cons]
simp only [LoopGraph,not_le]
rfl
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.Counting WitnessedSeparation.HFCoding
lemma unionHF_eq_operational {A : Type} (x : HF A) : unionHF x = Operational.unionHF x := by
unfold unionHF Operational.unionHF
congr 1
ext y
simp only [Finset.mem_biUnion]
lemma uniqueHF_eq_operational {A : Type} (x : HF A) : uniqueHF x = Operational.uniqueHF x := rfl
lemma cardHF_eq_operational {A : Type} (x : HF A) : cardHF x = Operational.cardinalityHF x := rfl
lemma atomsHF_eq_operational {A : Type} [Fintype A] :
ofFinset (Finset.univ.image (atom (A := A))) = (Operational.allAtoms : HF A) := by
unfold Operational.allAtoms
congr 1
ext y
simp only [Finset.mem_image]
mutual
def Term.graphWidth : {n : β} β Term n β β
| n, .var _ | n, .empty | n, .atoms => n+8
| n, .pair a b => n+8+a.graphWidth+b.graphWidth
| n, .union a | n, .unique a | n, .card a => n+8+a.graphWidth
| n, .comprehend b r g => n+8+b.graphWidth+r.graphWidth+g.graphWidth
| n, .iterate step => n+8+step.graphWidth
def Formula.graphWidth : {n : β} β Formula n β β
| n, .equal a b | n, .input _ a b => n+8+a.graphWidth+b.graphWidth
| n, .neg a => n+8+a.graphWidth
| n, .and a b | n, .or a b => n+8+a.graphWidth+b.graphWidth
| n, .wsc _ _ _ _ => n+8
end
variable {ΞΉ R : Type} {A : ΞΉ β Type} [β i, Fintype (A i)]
variable (d : β i, Set (HF (A i))) (T : β i, Counting.Structure R (Domain (d i))) {m : β}
variable (hd : β i, β x β d i, β y, y β x β y β d i)
variable (hp : β i k, ordinal (A := A i) k β d i)
variable (ha : β i a, atom a β d i)
variable (hmem : UniformDefinable T m 2 (fun _ v => (v 0).val β (v 1).val))
variable (hset : UniformDefinable T m 1 (fun _ v => isSet (v 0).val = true))
variable (S : β i, Input (A i))
variable (hinput : β r, UniformDefinable T m 2
(fun i v => Operational.inputRelation (S i).rel r (v 0).val (v 1).val))
mutual
lemma Term.uniform_graph (d : β i, Set (HF (A i))) (T : β i, Counting.Structure R (Domain (d i)))
(hd : β i, β x β d i, β y, y β x β y β d i)
(hp : β i k, ordinal (A := A i) k β d i)
(ha : β i a, atom a β d i)
(hmem : UniformDefinable T m 2 (fun _ v => (v 0).val β (v 1).val))
(hset : UniformDefinable T m 1 (fun _ v => isSet (v 0).val = true))
(S : β i, Input (A i))
(hinput : β r, UniformDefinable T m 2
(fun i v => Operational.inputRelation (S i).rel r (v 0).val (v 1).val)) (p K : β) {n : β} (t : Term n) (hm : t.graphWidth β€ m) :
UniformDefinable T m (n+1) (fun i v => t.Graph (d i) (S i) p K (v 0) (Fin.tail v)) := by
cases t with
| var j => exact UniformDefinable.equal 0 j.succ
| empty =>
simp only [Term.graphWidth] at hm
exact (HFCoding.uniform_ordinal T hmem hset (by omega) hd hp 0).reindex ![0]
| atoms =>
simp only [Term.graphWidth] at hm
apply ((Operational.uniform_atoms d T hd ha hmem hset (by omega)).reindex ![0]).congr
intro i v
simp only [Term.Graph,atomsHF_eq_operational,Function.comp_apply]
rfl
| pair a b =>
simp only [Term.graphWidth] at hm
exact UniformDefinable.compose_binary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(b.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(Operational.uniform_double_value d T hd hmem hset (by omega)) (by omega)
| union a =>
simp only [Term.graphWidth] at hm
have hh := UniformDefinable.compose_unary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(Operational.uniform_union d T hd hmem hset (by omega)) (by omega : n+1 < m)
apply hh.congr
intro i v
simp only [Term.Graph,unionHF_eq_operational,Fin.cons_zero,Fin.tail_cons]
rfl
| unique a =>
simp only [Term.graphWidth] at hm
exact UniformDefinable.compose_unary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(Operational.uniform_unique d T hd hp hmem hset (by omega)) (by omega)
| card a =>
simp only [Term.graphWidth] at hm
exact UniformDefinable.compose_unary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(Operational.uniform_card d T hd hp hmem hset (by omega) K) (by omega)
| comprehend body range guard =>
simp only [Term.graphWidth] at hm
exact uniform_BGS_comprehension d T hmem hset
(range.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(fun b => guard.uniform_graph d T hd hp ha hmem hset S hinput p K b (by omega))
(body.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega)) (by omega)
| iterate step =>
simp only [Term.graphWidth] at hm
have hs := step.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega)
have hc := uniform_TC_bound d T hd hmem (by omega) p
have he : UniformDefinable T m 1 (fun _ v => (v 0).val = emptyHF) :=
HFCoding.uniform_ordinal T hmem hset (by omega) hd hp 0
have hl := (LoopGraph.uniform d T p (fun i => step.Graph (d i) (S i) p K)
hs hc he (by omega : n+2 < m) (p+1)).reindex
(Fin.cons 1 (Fin.cons 0 (fun j => j.succ.succ)) : Fin (n+2) β Fin (n+2))
apply (((he.reindex (![0] : Fin 1 β Fin (n+2))).and hl).ex (by omega)).congr
intro i v
simp only [Term.Graph,Fin.comp_cons,Fin.cons_zero,Fin.tail_cons,Function.comp_apply]
rfl
termination_by sizeOf t
decreasing_by all_goals subst_vars; simp_wf <;> omega
lemma Formula.uniform_graph (d : β i, Set (HF (A i))) (T : β i, Counting.Structure R (Domain (d i)))
(hd : β i, β x β d i, β y, y β x β y β d i)
(hp : β i k, ordinal (A := A i) k β d i)
(ha : β i a, atom a β d i)
(hmem : UniformDefinable T m 2 (fun _ v => (v 0).val β (v 1).val))
(hset : UniformDefinable T m 1 (fun _ v => isSet (v 0).val = true))
(S : β i, Input (A i))
(hinput : β r, UniformDefinable T m 2
(fun i v => Operational.inputRelation (S i).rel r (v 0).val (v 1).val)) (p K : β) {n : β} (f : Formula n) (b : Bool)
(hm : f.graphWidth β€ m) :
UniformDefinable T m n (fun i v => f.Graph (d i) (S i) p K b v) := by
cases f with
| equal a c =>
simp only [Formula.graphWidth] at hm
have he : UniformDefinable T m 2 (fun _ v => (v 0).val = (v 1).val) :=
(UniformDefinable.equal 0 1).congr (fun _ _ => Subtype.ext_iff)
apply (uniform_formula_binary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(c.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(uniform_decide he b) (by omega : n+1 < m)).congr
intro i v
simp only [Formula.Graph,Fin.cons_zero,Fin.tail_cons]
apply exists_congr; intro x
apply exists_congr; intro y
simp only [Matrix.cons_val_zero,Matrix.cons_val_one]
apply and_congr_right; intro _
apply and_congr_right; intro _
apply Iff.of_eq
apply congrArg (fun z : Bool => b = z)
exact decide_eq_decide.mpr Iff.rfl
| input r a c =>
simp only [Formula.graphWidth] at hm
exact uniform_formula_binary
(a.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(c.uniform_graph d T hd hp ha hmem hset S hinput p K (by omega))
(uniform_decide (hinput r) b) (by omega)
| neg a =>
simp only [Formula.graphWidth] at hm
exact uniform_exists_finite (fun c : Bool =>
(a.uniform_graph d T hd hp ha hmem hset S hinput p K c (by omega)).and
(uniform_const (b = !c)))
| and a c =>
simp only [Formula.graphWidth] at hm
exact uniform_exists_finite (fun x : Bool => uniform_exists_finite (fun y : Bool =>
(a.uniform_graph d T hd hp ha hmem hset S hinput p K x (by omega)).and
((c.uniform_graph d T hd hp ha hmem hset S hinput p K y (by omega)).and
(uniform_const (b = (x && y))))))
| or a c =>
simp only [Formula.graphWidth] at hm
exact uniform_exists_finite (fun x : Bool => uniform_exists_finite (fun y : Bool =>
(a.uniform_graph d T hd hp ha hmem hset S hinput p K x (by omega)).and
((c.uniform_graph d T hd hp ha hmem hset S hinput p K y (by omega)).and
(uniform_const (b = (x || y))))))
| wsc step choice witness output => exact UniformDefinable.falsum
termination_by sizeOf f
decreasing_by all_goals subst_vars; simp_wf <;> omega
end
end
end WitnessedChoice.BGS
end
section
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary Finset
open WitnessedSeparation.Operational (lift lift_elements lift_ofFinset lift_empty lift_double)
variable {A B : Type}
lemma lift_emptyHF (e : A β B) : lift e emptyHF = emptyHF := Operational.lift_empty e
lemma lift_unionHF (e : A β B) (x : HF A) : lift e (unionHF x) = unionHF (lift e x) := by
simpa only [unionHF_eq_operational] using Operational.lift_union e x
lemma lift_uniqueHF (e : A β B) (x : HF A) : lift e (uniqueHF x) = uniqueHF (lift e x) :=
Operational.lift_unique e x
lemma lift_cardHF (e : A β B) (x : HF A) : lift e (cardHF x) = cardHF (lift e x) :=
Operational.lift_card e x
lemma lift_atomsHF [Fintype A] [Fintype B] (e : A β B) :
lift e (ofFinset (univ.image (atom (A := A)))) = ofFinset (univ.image atom) := by
simpa only [atomsHF_eq_operational] using Operational.lift_allAtoms e
lemma lift_inputHF (e : A β B) (S : Input A) (T : Input B)
(h : β r a b, T.rel r (e a) (e b) = S.rel r a b) (r : Symbol) (x y : HF A) :
inputHF T r (lift e x) (lift e y) = inputHF S r x y := by
apply Bool.eq_iff_iff.mpr
simpa only [inputHF,decide_eq_true_eq,Operational.inputRelation] using
Operational.lift_input e S.rel T.rel h r x y
variable [Fintype A] [Fintype B]
omit [Fintype A] [Fintype B] in
lemma lift_closureHF (e : A β B) (x : HF A) :
closure (lift e x) = (closure x).image (lift e) := by
ext y
have hh := congrArg (fun z : Finset (HF B) => y β z) (Operational.lift_closure e x)
simpa only [mem_image] using Iff.of_eq hh
omit [Fintype A] [Fintype B] in
lemma lift_TC (e : A β B) (x : HF A) : TC (lift e x) = (TC x).image (lift e) := by
simp only [TC,lift_elements,biUnion_image,image_biUnion,lift_closureHF]
omit [Fintype A] [Fintype B] in
lemma lift_TC_card (e : A β B) (x : HF A) : (TC (lift e x)).card = (TC x).card := by
rw [lift_TC,card_image_of_injective _ (lift e).injective]
omit [Fintype A] [Fintype B] in
lemma lift_cons (e : A β B) {n : β} (env : Fin n β HF A) (x : HF A) :
(fun j => lift e ((Fin.cons x env : Fin (n+1) β HF A) j)) =
Fin.cons (lift e x) (fun j => lift e (env j)) := by
funext j; exact Fin.cases rfl (fun _ => rfl) j
omit [Fintype A] [Fintype B] in
lemma tracedLoop_transport (e : A β B) (p : β)
(a : HF A β Traced A (HF A)) (b : HF B β Traced B (HF B))
(h : β x, b (lift e x) = (lift e (a x).1,(a x).2.image (lift e)))
(fuel : β) (x : HF A) :
tracedLoop p b fuel (lift e x) =
(lift e (tracedLoop p a fuel x).1,(tracedLoop p a fuel x).2.image (lift e)) := by
induction fuel generalizing x with
| zero => simp only [tracedLoop,lift_emptyHF,closure_emptyHF,image_singleton]
| succ fuel ih =>
simp only [tracedLoop,lift_TC_card,h,Equiv.apply_eq_iff_eq]
split_ifs with hb he
Β· rfl
Β· simp only [ih,image_union]
Β· simp only [lift_emptyHF,closure_emptyHF,image_singleton]
omit [Fintype A] [Fintype B] in
lemma selected_transport (e : A β B) (r : HF A)
(a : HF A β Bool) (b : HF B β Bool) (h : β x, b (lift e x) = a x) :
((elements (lift e r)).filter (fun y => b y = true)) =
((elements r).filter (fun x => a x = true)).image (lift e) := by
rw [lift_elements]
ext y
simp only [mem_filter,mem_image]
constructor
Β· rintro β¨β¨x,hx,rflβ©,hyβ©
exact β¨x,β¨hx,by rwa [h] at hyβ©,rflβ©
Β· rintro β¨x,β¨hx,hyβ©,rflβ©
exact β¨β¨x,hx,rflβ©,by rwa [h]β©
mutual
theorem Term.traced_transport (e : A β B) (S : Input A) (T : Input B)
(h : β r a b, T.rel r (e a) (e b) = S.rel r a b) (p : β)
{n : β} (t : Term n) (env : Fin n β HF A) :
t.traced T p (fun j => lift e (env j)) =
(lift e (t.traced S p env).1,(t.traced S p env).2.image (lift e)) := by
cases t with
| var j => exact Prod.ext rfl (lift_closureHF e _)
| empty => simp only [Term.traced,lift_emptyHF,closure_emptyHF,image_singleton]
| atoms => simp only [Term.traced,β lift_atomsHF e,lift_closureHF]
| pair a b =>
simp only [Term.traced,a.traced_transport e S T h p env,b.traced_transport e S T h p env,
image_insert,image_union,lift_double]
| union a =>
simp only [Term.traced,a.traced_transport e S T h p env,image_insert,lift_unionHF]
| unique a =>
simp only [Term.traced,a.traced_transport e S T h p env,image_insert,lift_uniqueHF]
| card a =>
simp only [Term.traced,a.traced_transport e S T h p env,image_union,β lift_cardHF,lift_closureHF]
| comprehend body range guard =>
have hr := range.traced_transport e S T h p env
have hg (x : HF A) := guard.traced_transport e S T h p (Fin.cons x env)
have hb (x : HF A) := body.traced_transport e S T h p (Fin.cons x env)
simp only [lift_cons] at hg hb
have hs := selected_transport e (range.traced S p env).1
(fun x => (guard.traced S p (Fin.cons x env)).1)
(fun x => (guard.traced T p (Fin.cons x (fun j => lift e (env j)))).1)
(fun x => congrArg Prod.fst (hg x))
simp only [Term.traced,hr]
rw [hs]
simp only [image_image,Function.comp_def,hb,lift_ofFinset,
lift_elements,biUnion_image,image_insert,image_union,image_biUnion,hg]
congr 2 <;> first | rfl | (apply congrArg ofFinset; ext z; simp only [mem_image]) | (ext z; simp only [mem_image])
| iterate step =>
have hh (x : HF A) := step.traced_transport e S T h p (Fin.cons x env)
simp only [lift_cons] at hh
have hx := tracedLoop_transport e p
(fun x => step.traced S p (Fin.cons x env))
(fun x => step.traced T p (Fin.cons x (fun j => lift e (env j)))) hh (p+1) emptyHF
simpa only [Term.traced,lift_emptyHF] using hx
theorem Formula.traced_transport (e : A β B) (S : Input A) (T : Input B)
(h : β r a b, T.rel r (e a) (e b) = S.rel r a b) (p : β)
{n : β} (f : Formula n) (env : Fin n β HF A) :
f.traced T p (fun j => lift e (env j)) =
((f.traced S p env).1,(f.traced S p env).2.image (lift e)) := by
cases f with
| equal a b =>
simp only [Formula.traced,a.traced_transport e S T h p env,b.traced_transport e S T h p env,
Equiv.apply_eq_iff_eq,image_union]
| input r a b =>
simp only [Formula.traced,a.traced_transport e S T h p env,b.traced_transport e S T h p env,
lift_inputHF e S T h,image_union]
| neg a => simp only [Formula.traced,a.traced_transport e S T h p env]
| and a b | or a b =>
simp only [Formula.traced,a.traced_transport e S T h p env,b.traced_transport e S T h p env,image_union]
| wsc step choice witness output => simp only [Formula.traced,image_empty]
end
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation
lemma realPolynomial_majorant (p : Polynomial β) :
β q : Polynomial β, β n : β, p.eval (n : β) β€ ((q.eval n : β) : β) := by
induction p using Polynomial.induction_on' with
| add a b ha hb =>
obtain β¨q,hqβ© := ha
obtain β¨r,hrβ© := hb
refine β¨q+r,fun n => ?_β©
simpa only [Polynomial.eval_add,Nat.cast_add] using add_le_add (hq n) (hr n)
| monomial k a =>
refine β¨Polynomial.monomial k β|a|ββ,fun n => ?_β©
simp only [Polynomial.eval_monomial,Nat.cast_mul,Nat.cast_pow]
apply mul_le_mul_of_nonneg_right ((le_abs_self a).trans (Nat.le_ceil _))
positivity
lemma resource_majorant (p : Polynomial β) :
β q : Polynomial β, β n : β, resource p n β€ q.eval n := by
obtain β¨q,hqβ© := realPolynomial_majorant p
refine β¨q,fun n => ?_β©
have hh := Nat.floor_mono (hq n)
simpa only [resource,Nat.floor_natCast] using hh
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.HFCoding
open WitnessedSeparation.Grid WitnessedSeparation.Counting Finset
open WitnessedSeparation.Operational (lift)
variable {n : β}
lemma Formula.grid_trace_invariant (f : Formula 0) (b : Vertex n β Grid.Scalar)
(p : β) : β g : BoxGroup n, β x β (f.traced (atomInput b) p Fin.elim0).2,
g β’ x β (f.traced (atomInput b) p Fin.elim0).2 := by
intro g x hx
have ht := f.traced_transport (actionIso (b := b) g).toEquiv (atomInput b) (atomInput b)
(fun r a c => (actionIso g).rel_eq r a c) p Fin.elim0
have he : (fun j : Fin 0 => lift (actionIso (b := b) g).toEquiv (Fin.elim0 j)) = Fin.elim0 :=
funext (fun j => Fin.elim0 j)
rw [he] at ht
have hm : g β’ x β (f.traced (atomInput b) p Fin.elim0).2.image
(lift (actionIso (b := b) g).toEquiv) := mem_image.mpr β¨x,hx,rflβ©
exact (congrArg (fun z => g β’ x β z.2) ht).mpr hm
lemma Formula.grid_trace_supported (f : Formula 0) (b : Vertex n β Grid.Scalar)
(hn : 1 β€ n) (p K N q : β) (hN : 0 < N)
(hb : (f.traced (atomInput b) p Fin.elim0).2.card β€ K) (hK : K β€ N^q) :
β x β (f.traced (atomInput b) p Fin.elim0).2,
HereditarilySupported (G := CentralGroup n)
β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ x := by
apply invariant_family_hereditarily_supported hn _ (f.grid_trace_invariant b p)
(fun x hx y hy => f.traced_closed (atomInput b) p Fin.elim0 x hx
(closure_member_subset hy (mem_closure_self y))) N hN (q:β) (by positivity)
rw [Real.rpow_natCast]
exact_mod_cast hb.trans hK
lemma Formula.grid_traced_agrees (f : Formula 0) (hf : f.wscCount = 0)
{m M N : β} (vstar : Vertex n) (hn : 1 β€ n) (p K q : β)
(hN : 0 < N) (hK : K β€ N^q)
(hb : β i : Bool, (f.traced (atomInput (twoCharges vstar i)) p Fin.elim0).2.card β€ K)
(hm : f.graphWidth β€ m) (hmpos : 0 < m)
(hs : 0 < β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ)
(hwidth : max 4 (m+1)*β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ β€ M)
(hhom : (7*(max 2 m*β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ):β)+
7*((6*(max 2 m*β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ):β)/boxConstant)^((3:β)/2)+1 β€ M)
(hgiant : GiantBound n M) :
(f.traced (atomInput (twoCharges vstar false)) p Fin.elim0).1 =
(f.traced (atomInput (twoCharges vstar true)) p Fin.elim0).1 := by
let s := β2*(n+1:β)*((q:β)*Real.logb 3 N)^2ββ
let D := programDomain (twoCharges vstar) (s := s)
let C := programHF (twoCharges vstar) (s := s)
have ht (i : Bool) : AdmissibleTrace (D i) K
(f.traced (atomInput (twoCharges vstar i)) p Fin.elim0).2 := by
intro x hx
refine β¨f.grid_trace_supported (twoCharges vstar i) hn p K N q hN (hb i) hK x hx,?_β©
exact (card_le_card ((elements_subset_closure x).trans
(f.traced_closed (atomInput (twoCharges vstar i)) p Fin.elim0 x hx))).trans (hb i)
have hu := f.uniform_graph D C (program_domain_transitive (twoCharges vstar))
(program_pure (twoCharges vstar) hn) (program_atom_mem (twoCharges vstar) hs)
(program_mem_uniform (twoCharges vstar)) (program_set_uniform (twoCharges vstar))
(fun i => atomInput (twoCharges vstar i)) (op_input_uniform (twoCharges vstar)) p K true hm
have he : UniformDefinable C m 0 (fun i _ =>
(f.traced (atomInput (twoCharges vstar i)) p Fin.elim0).1 = true) := by
apply hu.congr
intro i env
have he : (fun j : Fin 0 => (env j).val) = Fin.elim0 := funext (fun j => Fin.elim0 j)
constructor
Β· intro hg
have hh := f.graph_sound (D i) (atomInput (twoCharges vstar i)) p K
(program_domain_transitive (twoCharges vstar) i) true env hg
simpa only [he] using hh.symm
Β· intro hg
apply f.graph_complete (D i) (atomInput (twoCharges vstar i)) p K
(program_domain_transitive (twoCharges vstar) i)
(program_pure (twoCharges vstar) hn i 0) hf true env
Β· simpa only [he] using ht i
Β· simpa only [he] using hg.symm
obtain β¨Ο,hΟ,hΟsemβ© := he (Fin.elim0 : Fin 0 β Fin m)
have hfree : Ο.free = β
:= subset_empty.mp (by simpa using hΟ)
let v : Fin m β Domain (D false) := fun _ => β¨ordinal 0,program_pure (twoCharges vstar) hn false 0β©
let w : Fin m β Domain (D true) := fun _ => β¨ordinal 0,program_pure (twoCharges vstar) hn true 0β©
let := atom_nonempty hn (0 : Vertex n β Grid.Scalar)
let := atom_nonempty hn (Pi.single vstar 1)
apply Bool.eq_iff_iff.mpr
exact (hΟsem false v).symm.trans ((grid_hf_transfer hn hs hmpos vstar
hwidth hhom hgiant Ο hfree v w).trans (hΟsem true w))
end
end WitnessedChoice.BGS
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary
open WitnessedSeparation.Grid WitnessedSeparation.Quantitative
def gridInput {n : β} (b : Vertex n β Grid.Scalar) : FiniteInput :=
β¨Atom b,inferInstance,atomInput bβ©
theorem Sentence.agrees_on_some_grid_pair (Ο : Sentence) (hΟ : Ο.isCPT) :
β n : β, 1 β€ n β§ β vstar : Vertex n,
Ο.eval (gridInput (0 : Vertex n β Grid.Scalar)) =
Ο.eval (gridInput (Pi.single vstar 1)) := by
obtain β¨r,hrβ© := resource_majorant Ο.polynomial
let Q : Polynomial β := Ο.formula.traceBound.comp (Polynomial.X+r+1)
obtain β¨c,d,hcdβ© := PolynomialCost.eval_bound Q
let q := timeExponent c d
let m := Ο.formula.graphWidth+1
obtain β¨n,hn,hnumβ© := exists_numeric_box q (by
have h := timeExponent_ge_two c d; omega) m
refine β¨n,hn,fun vstar => ?_β©
let N := atomSizeConstant*(n+1)^3
let p := resource Ο.polynomial (Fintype.card (Atom (0 : Vertex n β Grid.Scalar)))
let K := N^q
have hN : 2 β€ N := hnum.1
have hc : Fintype.card (Atom (0 : Vertex n β Grid.Scalar)) =
Fintype.card (Atom (Pi.single vstar 1)) := atom_card_independent hn _ _
have hinput (i : Bool) : Fintype.card (Atom (twoCharges vstar i)) β€ N :=
(atom_card_bounds hn _).2
have hres (i : Bool) : resource Ο.polynomial
(Fintype.card (Atom (twoCharges vstar i))) = p := by
cases i
Β· rfl
Β· exact congrArg (resource Ο.polynomial) hc.symm
have hp : p β€ r.eval N := (hr _).trans (PolynomialCost.eval_mono r (hinput false))
have hb (i : Bool) : (Ο.formula.traced (atomInput (twoCharges vstar i)) p Fin.elim0).2.card β€ K := by
calc
_ β€ Ο.formula.traceBound.eval (N+r.eval N+1) :=
Ο.formula.traced_card_le _ p Fin.elim0 _ (by
simp only [tracePotential,Fin.sum_univ_zero,Nat.add_zero]
have hi := hinput i
omega)
_ = Q.eval N := by simp only [Q,Polynomial.eval_comp,Polynomial.eval_add,
Polynomial.eval_X,Polynomial.eval_one]
_ β€ c*(N+1)^d := hcd N
_ β€ K := (polynomial_bounds c d N hN).2.2.1
have hh := Ο.formula.grid_traced_agrees hΟ (m := m) vstar hn p K q
(by omega : 0 < N) (le_refl K) hb (by omega) (by omega)
hnum.2.1 hnum.2.2.1 (by simpa only [N,Nat.cast_mul] using hnum.2.2.2.1) hnum.2.2.2.2
dsimp only [Sentence.eval,gridInput]
rw [Ο.formula.eval_traced _ _ hΟ,Ο.formula.eval_traced _ _ hΟ]
change some (Ο.formula.traced (atomInput (0 : Vertex n β Grid.Scalar)) p Fin.elim0).1 = _
rw [β hc]
exact congrArg some hh
end
end WitnessedChoice.BGS
end
section
namespace WitnessedChoice
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary
variable {A : Type} [Fintype A]
def fullAut (S : Input A) : Subgroup (Equiv.Perm A) where
carrier := {g | β r a b, S.rel r (g a) (g b) = S.rel r a b}
one_mem' := by intro r a b; rfl
mul_mem' := by
intro g h hg hh r a b
exact (hg r (h a) (h b)).trans (hh r a b)
inv_mem' := by
intro g hg r a b
symm
simpa using hg r (gβ»ΒΉ a) (gβ»ΒΉ b)
def paramAut (S : Input A) (Ξ± : HF A) : Subgroup (Equiv.Perm A) :=
fullAut S β MulAction.stabilizer (Equiv.Perm A) Ξ±
def stateCode (x : Finset A) : HF A := ofFinset (x.image atom)
def choiceCode : Option A β HF A
| none => ordinal 0
| some a => atom a
structure Selection (A : Type) where
candidates : Finset A β Finset A
witnesses : Finset A β Finset (Equiv.Perm A)
namespace Selection
variable (P : Selection A)
def TransitiveAt (x : Finset A) : Prop :=
β a β P.candidates x, β b β P.candidates x,
β g β P.witnesses x, g a = b
def choices (x : Finset A) : Finset (Option A) :=
if (P.candidates x).Nonempty β§ P.TransitiveAt x then
(P.candidates x).image some
else {none}
def advance (x : Finset A) : Option A β Finset A
| none => x
| some a => insert a x
def Prefix (b : β β Finset A) (c : β β Option A) (k : β) : Prop :=
b 0 = β
β§ β i < k, c i β P.choices (b i) β§ b (i+1) = advance (b i) (c i)
def FirstStabilization (b : β β Finset A) (c : β β Option A) (t : β) : Prop :=
P.Prefix b c (t+1) β§ (β i < t, b i β b (i+1)) β§ b t = b (t+1)
def witnessAt (_terminal intermediate : Finset A) : Finset (Equiv.Perm A) :=
P.witnesses intermediate
def HistoryAut (S : Input A) (Ξ± : HF A) (b : β β Finset A) (i : β)
(g : Equiv.Perm A) : Prop :=
g β paramAut S Ξ± β§ β j β€ i, g β’ stateCode (b j) = stateCode (b j)
def WitnessedAt (S : Input A) (Ξ± : HF A) (b : β β Finset A)
(terminal : Finset A) (i : β) : Prop :=
(P.choices (b i)).Nonempty β§
(β g β P.witnessAt terminal (b i), HistoryAut S Ξ± b i g) β§
β u β P.choices (b i), β v β P.choices (b i),
β g β P.witnessAt terminal (b i), g β’ choiceCode u = choiceCode v
def Filtered (S : Input A) (Ξ± : HF A) : Prop :=
(β x, (1 : Equiv.Perm A) β P.witnesses x) β§
(β x g, g β P.witnesses x β g β paramAut S Ξ±) β§
(β x g, g β P.witnesses x β β a β x, g a = a)
def Fresh : Prop := β x a, a β P.candidates x β a β x
def Equivariant (S : Input A) (Ξ± : HF A) : Prop :=
β g β paramAut S Ξ±, β x,
P.candidates (x.image g) = (P.candidates x).image g β§
P.witnesses (x.image g) = (P.witnesses x).image (fun h => g * h * gβ»ΒΉ)
end Selection
end
end WitnessedChoice
end
end OAI
import OAI.Computability.WitnessedChoice.ChoiceTrace
namespace OAI
section
namespace WitnessedChoice.BGS
noncomputable section
open Classical WitnessedSeparation WitnessedSeparation.Hereditary WitnessedSeparation.HFCoding
variable {A : Type}
def LoopGraph (d : Set (HF A)) (p : β) {n : β}
(step : Domain d β (Fin (n+1) β Domain d) β Prop) :
β β Domain d β Domain d β (Fin n β Domain d) β Prop
| 0, z, _, _ => z.val = emptyHF
| fuel+1, z, x, env =>
((TC x.val).card > p β§ z.val = emptyHF) β¨
((TC x.val).card β€ p β§ β y : Domain d, step y (Fin.cons x env) β§
((x = y β§ z = x) β¨ (x β y β§ LoopGraph d p step fuel z y env)))
mutual
def Term.Graph [Fintype A] (d : Set (HF A)) (S : Input A) (p K : β) :
{n : β} β Term n β Domain d β (Fin n β Domain d) β Prop
| _, .var j, z, env => z = env j
| _, .empty, z, _ => z.val = emptyHF
| _, .atoms, z, _ => z.val = ofFinset (Finset.univ.image atom)
| _, .pair a b, z, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ z.val = double x.val y.val
| _, .union a, z, env => β x : Domain d, a.Graph d S p K x env β§ z.val = unionHF x.val
| _, .unique a, z, env => β x : Domain d, a.Graph d S p K x env β§ z.val = uniqueHF x.val
| _, .card a, z, env => β x : Domain d, a.Graph d S p K x env β§
(elements x.val).card β€ K β§ z.val = cardHF x.val
| _, .comprehend body range guard, z, env => β r : Domain d,
range.Graph d S p K r env β§
(β x : Domain d, x.val β r.val β β b : Bool,
guard.Graph d S p K b (Fin.cons x env) β§
(b = true β β y : Domain d, body.Graph d S p K y (Fin.cons x env))) β§
isSet z.val = true β§ β y : Domain d, y.val β z.val β β x : Domain d,
x.val β r.val β§ guard.Graph d S p K true (Fin.cons x env) β§
body.Graph d S p K y (Fin.cons x env)
| _, .iterate step, z, env => β x : Domain d, x.val = emptyHF β§
LoopGraph d p (step.Graph d S p K) (p+1) z x env
def Formula.Graph [Fintype A] (d : Set (HF A)) (S : Input A) (p K : β) :
{n : β} β Formula n β Bool β (Fin n β Domain d) β Prop
| _, .equal a b, v, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ v = decide (x.val = y.val)
| _, .input r a b, v, env => β x y : Domain d,
a.Graph d S p K x env β§ b.Graph d S p K y env β§ v = inputHF S r x.val y.val
| _, .neg a, v, env => β b : Bool, a.Graph d S p K b env β§ v = !b
| _, .and a b, v, env => β c e : Bool, a.Graph d S p K c env β§
b.Graph d S p K e env β§ v = (c && e)
| _, .or a b, v, env => β c e : Bool, a.Graph d S p K c env β§
b.Graph d S p K e env β§ v = (c || e)
| _, .wsc _ _ _ _, _, _ => False
end
lemma domain_cons_val {d : Set (HF A)} {n : β} (x : Domain d) (env : Fin n β Domain d) :
(fun j => ((Fin.cons x env : Fin (_+1) β Domain d) j).val) = Fin.cons x.val (fun j => (env j).val) := by
funext j
exact Fin.cases rfl (fun _ => rfl) j
lemma LoopGraph.sound {d : Set (HF A)} (p : β) {n : β}
(step : Domain d β (Fin (n+1) β Domain d) β Prop)
(ts : HF A β Traced A (HF A)) (env : Fin n β Domain d)
(hs : β x y : Domain d, step y (Fin.cons x env) β y.val = (ts x.val).1)
(fuel : β) (z x : Domain d) (h : LoopGraph d p step fuel z x env) :
z.val = (tracedLoop p ts fuel x.val).1 := by
induction fuel generalizing z x with
| zero => exact h
| succ fuel ih =>
rcases h with β¨hb,hzβ© | β¨hb,y,hy,heβ©
Β· simpa only [tracedLoop,ite_eq_right (by omega : Β¬ (TC x.val).card β€ p)] using hz
Β· have hval := hs x y hy
rcases he with β¨rfl,rflβ© | β¨hne,hrecβ©
Β· simp only [tracedLoop,ite_eq_left hb,ite_eq_left hval]
Β· have hn : x.val β (ts x.val).1 := fun h => hne (Subtype.ext (h.trans hval.symm))
simp only [tracedLoop,ite_eq_left hb,ite_eq_right hn]
rw [β hval]
exact ih z y hrec
variable [Fintype A]
mutual
lemma Term.graph_sound (d : Set (HF A)) (S : Input A) (p K : β)
(hd : β x β d, β y, y β x β y β d) {n : β}
(t : Term n) (z : Domain d) (env : Fin n β Domain d)
(h : t.Graph d S p K z env) : z.val = (t.traced S p (fun j => (env j).val)).1 := by
cases t with
| var j => exact congrArg Subtype.val h
| empty => exact h
| atoms => exact h
| pair a b =>
obtain β¨x,y,hx,hy,hzβ© := h
change z.val = double (a.traced S p (fun j => (env j).val)).1
(b.traced S p (fun j => (env j).val)).1
exact hz.trans (congrArgβ double (a.graph_sound d S p K hd x env hx)
(b.graph_sound d S p K hd y env hy))