Download data/lean/OAI/Computability/WitnessedChoice/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 22.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WitnessedChoice/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/WitnessedChoice/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WitnessedChoice/Model.lean
22.5 kB
| import Mathlib | |
| namespace OAI | |
| universe u v w | |
| namespace WitnessedSeparation.Hereditary | |
| noncomputable section | |
| abbrev HF (A : Type u) := Quotient (@Lists.instSetoidLists A) | |
| variable {A : Type u} {B : Type v} | |
| local instance {A : Type u} : DecidableEq (HF A) := Classical.decEq _ | |
| def mk (l : Lists A) : HF A := Quotient.mk Lists.instSetoidLists l | |
| def atom (a : A) : HF A := mk (Lists.atom a) | |
| @[simp] theorem mk_eq_mk {l r : Lists A} : mk l = mk r β Lists.Equiv l r := | |
| Quotient.eq | |
| def isSet (x : HF A) : Bool := Quotient.liftOn x (fun l => l.1) | |
| (by intro l r h; cases h <;> rfl) | |
| def rawElements (l : Lists A) : Finset (HF A) := by | |
| classical | |
| exact l.toList.toFinset.image mk | |
| theorem mem_rawElements (a l : Lists A) : mk a β rawElements l β a β l := by | |
| classical | |
| rcases l with β¨(_ | _), lβ© | |
| Β· cases l | |
| change mk a β (β : Finset (HF A)) β False | |
| simp | |
| Β· change mk a β (Lists'.toList l).toFinset.image mk β a β l | |
| simp only [Finset.mem_image, List.mem_toFinset, Lists'.mem_def, mk_eq_mk] | |
| constructor | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| theorem raw_mem_congr_right {l r : Lists A} (h : Lists.Equiv l r) (a : Lists A) : | |
| a β l β a β r := by | |
| cases h with | |
| | refl => rfl | |
| | antisymm hl hr => | |
| exact β¨Lists'.mem_of_subset hl, Lists'.mem_of_subset hrβ© | |
| theorem rawElements_congr {l r : Lists A} (h : Lists.Equiv l r) : | |
| rawElements l = rawElements r := by | |
| ext x | |
| induction x using Quotient.inductionOn with | |
| | _ a => | |
| change mk a β rawElements l β mk a β rawElements r | |
| rw [mem_rawElements, mem_rawElements] | |
| exact raw_mem_congr_right h a | |
| def elements (x : HF A) : Finset (HF A) := Quotient.liftOn x rawElements (by | |
| have mem_rawElements (a l : Lists A) : mk a β rawElements l β a β l := by | |
| classical | |
| rcases l with β¨(_ | _), lβ© | |
| Β· cases l | |
| change mk a β (β : Finset (HF A)) β False | |
| simp | |
| Β· change mk a β (Lists'.toList l).toFinset.image mk β a β l | |
| simp only [Finset.mem_image, List.mem_toFinset, Lists'.mem_def, mk, Quotient.eq] | |
| constructor | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| have raw_mem_congr_right {l r : Lists A} (h : Lists.Equiv l r) (a : Lists A) : | |
| a β l β a β r := by | |
| cases h with | |
| | refl => rfl | |
| | antisymm hl hr => | |
| exact β¨Lists'.mem_of_subset hl, Lists'.mem_of_subset hrβ© | |
| intro l r h | |
| ext z | |
| induction z using Quotient.inductionOn with | |
| | _ a => | |
| change mk a β rawElements l β mk a β rawElements r | |
| rw [mem_rawElements, mem_rawElements] | |
| exact raw_mem_congr_right h a) | |
| instance : Membership (HF A) (HF A) := β¨fun y x => x β elements yβ© | |
| @[simp] theorem mem_mk (a l : Lists A) : mk a β mk l β a β l := mem_rawElements a l | |
| def ofFinset (s : Finset (HF A)) : HF A := | |
| mk (Lists.ofList (s.toList.map Quotient.out)) | |
| def rawRank' : {b : Bool} β Lists' A b β β | |
| | _, .atom _ => 0 | |
| | _, .nil => 0 | |
| | _, .cons' a l => max (rawRank' a + 1) (rawRank' l) | |
| def rawRank (l : Lists A) : β := rawRank' l.2 | |
| theorem rawRank_lt_of_mem {b : Bool} (l : Lists' A b) (a : Lists A) | |
| (ha : a β l.toList) : rawRank a < rawRank' l := by | |
| induction l with | |
| | atom => simp at ha | |
| | nil => simp at ha | |
| | cons' c l ihc ihl => | |
| rcases List.mem_cons.mp ha with rfl | ha | |
| Β· exact lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_left _ _) | |
| Β· exact lt_of_lt_of_le (ihl ha) (le_max_right _ _) | |
| theorem rawRank_congr {l r : Lists A} (h : Lists.Equiv l r) : rawRank l = rawRank r := by | |
| induction h using Lists.Equiv.rec | |
| (motive_2 := fun l r _ => rawRank' l β€ rawRank' r) with | |
| | refl => rfl | |
| | antisymm hl hr ihl ihr => exact Nat.le_antisymm ihl ihr | |
| | nil => exact Nat.zero_le _ | |
| | @cons a a' l r heq hmem hsub iheq ihsub => | |
| change max (rawRank a + 1) (rawRank' l) β€ rawRank' r | |
| refine max_le ?_ ihsub | |
| rw [iheq] | |
| exact rawRank_lt_of_mem r a' hmem | |
| def rank (x : HF A) : β := Quotient.liftOn x rawRank (by | |
| have rawRank_lt_of_mem {b : Bool} (l : Lists' A b) (a : Lists A) | |
| (ha : a β l.toList) : rawRank a < rawRank' l := by | |
| induction l with | |
| | atom => simp at ha | |
| | nil => simp at ha | |
| | cons' c l ihc ihl => | |
| rcases List.mem_cons.mp ha with rfl | ha | |
| Β· exact lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_left _ _) | |
| Β· exact lt_of_lt_of_le (ihl ha) (le_max_right _ _) | |
| have rawRank_congr {l r : Lists A} (h : Lists.Equiv l r) : rawRank l = rawRank r := by | |
| induction h using Lists.Equiv.rec | |
| (motive_2 := fun l r _ => rawRank' l β€ rawRank' r) with | |
| | refl => rfl | |
| | antisymm _ _ ihl ihr => exact Nat.le_antisymm ihl ihr | |
| | nil => exact Nat.zero_le _ | |
| | @cons a a' l r _ hmem _ iheq ihsub => | |
| change max (rawRank a + 1) (rawRank' l) β€ rawRank' r | |
| refine max_le ?_ ihsub | |
| rw [iheq] | |
| exact rawRank_lt_of_mem r a' hmem | |
| exact fun _ _ h => rawRank_congr h) | |
| theorem rank_lt_of_mem {x y : HF A} (h : x β y) : rank x < rank y := by | |
| induction y using Quotient.inductionOn with | |
| | _ l => | |
| induction x using Quotient.inductionOn with | |
| | _ a => | |
| have h' := (mem_mk a l).mp h | |
| rcases l with β¨(_ | _), lβ© | |
| Β· exact False.elim h' | |
| Β· obtain β¨a',ha',heqβ© := h' | |
| change rawRank a < rawRank' l | |
| rw [rawRank_congr heq] | |
| exact rawRank_lt_of_mem l a' ha' | |
| def rawMap' (f : A β B) : {b : Bool} β Lists' A b β Lists' B b | |
| | _, .atom a => .atom (f a) | |
| | _, .nil => .nil | |
| | _, .cons' a l => .cons' (rawMap' f a) (rawMap' f l) | |
| def rawMap (f : A β B) (l : Lists A) : Lists B := β¨l.1, rawMap' f l.2β© | |
| theorem toList_rawMap' (f : A β B) {b : Bool} (l : Lists' A b) : | |
| (rawMap' f l).toList = l.toList.map (rawMap f) := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', Lists'.toList, ihl]; rfl | |
| theorem rawMap_congr (f : A β B) {l r : Lists A} (h : Lists.Equiv l r) : | |
| Lists.Equiv (rawMap f l) (rawMap f r) := by | |
| induction h using Lists.Equiv.rec | |
| (motive_2 := fun l r _ => Lists'.Subset (rawMap' f l) (rawMap' f r)) with | |
| | refl => exact Lists.Equiv.refl _ | |
| | antisymm hl hr ihl ihr => exact Lists.Equiv.antisymm ihl ihr | |
| | nil => exact Lists'.Subset.nil | |
| | @cons a a' l r heq hmem hsub iheq ihsub => | |
| apply Lists'.Subset.cons iheq _ ihsub | |
| rw [toList_rawMap'] | |
| exact List.mem_map.mpr β¨a',hmem,rflβ© | |
| def map (f : A β B) (x : HF A) : HF B := by | |
| have toList_rawMap' (f : A β B) {b : Bool} (l : Lists' A b) : | |
| (rawMap' f l).toList = l.toList.map (rawMap f) := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', Lists'.toList, ihl]; rfl | |
| have rawMap_congr (f : A β B) {l r : Lists A} (h : Lists.Equiv l r) : | |
| Lists.Equiv (rawMap f l) (rawMap f r) := by | |
| induction h using Lists.Equiv.rec | |
| (motive_2 := fun l r _ => Lists'.Subset (rawMap' f l) (rawMap' f r)) with | |
| | refl => exact Lists.Equiv.refl _ | |
| | antisymm hl hr ihl ihr => exact Lists.Equiv.antisymm ihl ihr | |
| | nil => exact Lists'.Subset.nil | |
| | @cons a a' l r _ hmem _ iheq ihsub => | |
| apply Lists'.Subset.cons iheq _ ihsub | |
| rw [toList_rawMap'] | |
| exact List.mem_map.mpr β¨a',hmem,rflβ© | |
| exact Quotient.liftOn x (fun l => mk (rawMap f l)) (fun _ _ h => Quotient.eq.mpr (rawMap_congr f h)) | |
| @[simp] theorem map_mk (f : A β B) (l : Lists A) : map f (mk l) = mk (rawMap f l) := rfl | |
| @[simp] theorem rawMap_id : β l : Lists A, rawMap id l = l := by | |
| rintro β¨b,lβ© | |
| have h : rawMap' id l = l := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', iha,ihl] | |
| exact congrArg (Sigma.mk b) h | |
| @[simp] theorem map_id (x : HF A) : map id x = x := by | |
| induction x using Quotient.inductionOn with | |
| | _ l => | |
| change map id (mk l) = mk l | |
| rw [map_mk, rawMap_id] | |
| theorem rawMap_comp {C : Type w} (g : B β C) (f : A β B) (l : Lists A) : | |
| rawMap g (rawMap f l) = rawMap (g β f) l := by | |
| rcases l with β¨b,lβ© | |
| have h : rawMap' g (rawMap' f l) = rawMap' (g β f) l := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', iha,ihl] | |
| exact congrArg (Sigma.mk b) h | |
| @[simp] theorem map_comp {C : Type w} (g : B β C) (f : A β B) (x : HF A) : | |
| map g (map f x) = map (g β f) x := by | |
| induction x using Quotient.inductionOn with | |
| | _ l => | |
| change map g (map f (mk l)) = map (g β f) (mk l) | |
| simp only [map_mk,rawMap_comp] | |
| instance {G : Type w} [Group G] [MulAction G A] : MulAction G (HF A) := by | |
| have map_mk {A B : Type u} (f : A β B) (l : Lists A) : map f (mk l) = mk (rawMap f l) := rfl | |
| have rawMap_id {A : Type u} : β l : Lists A, rawMap id l = l := by | |
| rintro β¨b,lβ© | |
| have h : rawMap' id l = l := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', iha,ihl] | |
| exact congrArg (Sigma.mk b) h | |
| have map_id {A : Type u} (x : HF A) : map id x = x := by | |
| induction x using Quotient.inductionOn with | |
| | _ l => | |
| change map id (mk l) = mk l | |
| rw [map_mk, rawMap_id] | |
| have rawMap_comp {A B : Type u} {C : Type u} (g : B β C) (f : A β B) (l : Lists A) : | |
| rawMap g (rawMap f l) = rawMap (g β f) l := by | |
| rcases l with β¨b,lβ© | |
| have h : rawMap' g (rawMap' f l) = rawMap' (g β f) l := by | |
| induction l with | |
| | atom => rfl | |
| | nil => rfl | |
| | cons' a l iha ihl => simp only [rawMap', iha,ihl] | |
| exact congrArg (Sigma.mk b) h | |
| have map_comp {A B : Type u} {C : Type u} (g : B β C) (f : A β B) (x : HF A) : | |
| map g (map f x) = map (g β f) x := by | |
| induction x using Quotient.inductionOn with | |
| | _ l => | |
| change map g (map f (mk l)) = map (g β f) (mk l) | |
| simp only [map_mk,rawMap_comp] | |
| exact { | |
| smul g x := map (fun a => g β’ a) x | |
| one_smul x := by | |
| change map (fun a : A => (1 : G) β’ a) x = x | |
| have h : (fun a : A => (1 : G) β’ a) = id := by funext a; simp | |
| rw [h,map_id] | |
| mul_smul g h x := by | |
| change map (fun a : A => (g*h) β’ a) x = map (fun a => g β’ a) (map (fun a => h β’ a) x) | |
| rw [map_comp] | |
| congr 1 | |
| funext a | |
| exact mul_smul g h a } | |
| end | |
| end WitnessedSeparation.Hereditary | |
| namespace WitnessedSeparation.Hereditary | |
| noncomputable section | |
| open Classical Finset | |
| variable {A : Type u} {B : Type v} | |
| def singleton (a : HF A) : HF A := ofFinset {a} | |
| def double (a b : HF A) : HF A := ofFinset {a,b} | |
| def pair (a b : HF A) : HF A := double (singleton a) (double a b) | |
| def ordinal : β β HF A | |
| | 0 => ofFinset β | |
| | i+1 => ofFinset (insert (ordinal i) (elements (ordinal i))) | |
| end | |
| end WitnessedSeparation.Hereditary | |
| namespace WitnessedSeparation | |
| abbrev Scalar := ZMod 3 | |
| inductive Symbol | |
| | Ed | Cf | EB | VB | I | Z (Ξ΄ : Scalar) | |
| deriving DecidableEq, Fintype | |
| structure Input (A : Type) where | |
| rel : Symbol β A β A β Bool | |
| end WitnessedSeparation | |
| namespace WitnessedSeparation.Hereditary | |
| noncomputable section | |
| open Classical Finset | |
| variable {A : Type u} {B : Type v} | |
| local instance {C : Type w} : DecidableEq (HF C) := Classical.decEq _ | |
| def closure (x : HF A) : Finset (HF A) := | |
| insert x ((elements x).attach.biUnion (fun y => closure y.val)) | |
| termination_by rank x | |
| decreasing_by | |
| have mem_rawElements (a l : Lists A) : mk a β rawElements l β a β l := by | |
| classical | |
| rcases l with β¨(_ | _), lβ© | |
| Β· cases l | |
| change mk a β (β : Finset (HF A)) β False | |
| simp | |
| Β· change mk a β (Lists'.toList l).toFinset.image mk β a β l | |
| simp only [Finset.mem_image, List.mem_toFinset, Lists'.mem_def, mk, Quotient.eq] | |
| constructor | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| Β· rintro β¨a',ha',heqβ© | |
| exact β¨a',ha',heq.symmβ© | |
| have rawRank_lt_of_mem {b : Bool} (l : Lists' A b) (a : Lists A) | |
| (ha : a β l.toList) : rawRank a < rawRank' l := by | |
| induction l with | |
| | atom => simp at ha | |
| | nil => simp at ha | |
| | cons' c l ihc ihl => | |
| rcases List.mem_cons.mp ha with rfl | ha | |
| Β· exact lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_left _ _) | |
| Β· exact lt_of_lt_of_le (ihl ha) (le_max_right _ _) | |
| have rawRank_congr {l r : Lists A} (h : Lists.Equiv l r) : rawRank l = rawRank r := by | |
| induction h using Lists.Equiv.rec | |
| (motive_2 := fun l r _ => rawRank' l β€ rawRank' r) with | |
| | refl => rfl | |
| | antisymm _ _ ihl ihr => exact Nat.le_antisymm ihl ihr | |
| | nil => exact Nat.zero_le _ | |
| | @cons a a' l r _ hmem _ iheq ihsub => | |
| change max (rawRank a + 1) (rawRank' l) β€ rawRank' r | |
| refine max_le ?_ ihsub | |
| rw [iheq] | |
| exact rawRank_lt_of_mem r a' hmem | |
| have rank_lt_of_mem {x y : HF A} (h : x β y) : rank x < rank y := by | |
| induction y using Quotient.inductionOn with | |
| | _ l => | |
| induction x using Quotient.inductionOn with | |
| | _ a => | |
| have h' := (mem_rawElements a l).mp h | |
| rcases l with β¨(_ | _), lβ© | |
| Β· exact False.elim h' | |
| Β· obtain β¨a',ha',heqβ© := h' | |
| change rawRank a < rawRank' l | |
| rw [rawRank_congr heq] | |
| exact rawRank_lt_of_mem l a' ha' | |
| exact rank_lt_of_mem y.property | |
| end | |
| end WitnessedSeparation.Hereditary | |
| namespace WitnessedChoice.BGS | |
| noncomputable section | |
| open Classical WitnessedSeparation WitnessedSeparation.Hereditary | |
| mutual | |
| inductive Term : β β Type | |
| | var {n} (i : Fin n) : Term n | |
| | empty {n} : Term n | |
| | atoms {n} : Term n | |
| | pair {n} (a b : Term n) : Term n | |
| | union {n} (a : Term n) : Term n | |
| | unique {n} (a : Term n) : Term n | |
| | card {n} (a : Term n) : Term n | |
| | comprehend {n} (body : Term (n+1)) (range : Term n) | |
| (guard : Formula (n+1)) : Term n | |
| | iterate {n} (step : Term (n+1)) : Term n | |
| inductive Formula : β β Type | |
| | equal {n} (a b : Term n) : Formula n | |
| | input {n} (r : Symbol) (a b : Term n) : Formula n | |
| | neg {n} (a : Formula n) : Formula n | |
| | and {n} (a b : Formula n) : Formula n | |
| | or {n} (a b : Formula n) : Formula n | |
| | wsc {n} (step : Term (n+2)) (choice : Term (n+1)) | |
| (witness : Term (n+2)) (output : Formula (n+1)) : Formula n | |
| end | |
| def dropFree {n} (f : Finset (Fin (n+1))) : Finset (Fin n) := | |
| Finset.univ.filter (fun i => i.succ β f) | |
| mutual | |
| def Term.free : {n : β} β Term n β Finset (Fin n) | |
| | _, .var i => {i} | |
| | _, .empty | _, .atoms => β | |
| | _, .pair a b => a.free βͺ b.free | |
| | _, .union a | _, .unique a | _, .card a => a.free | |
| | _, .comprehend body range guard => range.free βͺ dropFree (body.free βͺ guard.free) | |
| | _, .iterate step => dropFree step.free | |
| def Formula.free : {n : β} β Formula n β Finset (Fin n) | |
| | _, .equal a b | _, .input _ a b => a.free βͺ b.free | |
| | _, .neg a => a.free | |
| | _, .and a b | _, .or a b => a.free βͺ b.free | |
| | _, .wsc step choice witness output => | |
| dropFree (dropFree (step.free βͺ witness.free)) βͺ dropFree (choice.free βͺ output.free) | |
| end | |
| mutual | |
| def Term.wscCount : {n : β} β Term n β β | |
| | _, .var _ | _, .empty | _, .atoms => 0 | |
| | _, .pair a b => a.wscCount + b.wscCount | |
| | _, .union a | _, .unique a | _, .card a => a.wscCount | |
| | _, .comprehend body range guard => body.wscCount + range.wscCount + guard.wscCount | |
| | _, .iterate step => step.wscCount | |
| def Formula.wscCount : {n : β} β Formula n β β | |
| | _, .equal a b | _, .input _ a b => a.wscCount + b.wscCount | |
| | _, .neg a => a.wscCount | |
| | _, .and a b | _, .or a b => a.wscCount + b.wscCount | |
| | _, .wsc step choice witness output => | |
| 1 + step.wscCount + choice.wscCount + witness.wscCount + output.wscCount | |
| end | |
| variable {A : Type} | |
| abbrev Result (Ξ± : Type) := Option Ξ± | |
| def emptyHF : HF A := ofFinset β | |
| def TC (x : HF A) : Finset (HF A) := (elements x).biUnion closure | |
| def unionHF (x : HF A) : HF A := ofFinset ((elements x).biUnion elements) | |
| def uniqueHF (x : HF A) : HF A := | |
| if h : β y, elements x = {y} then h.choose else emptyHF | |
| def cardHF (x : HF A) : HF A := ordinal (elements x).card | |
| def inputHF (S : Input A) (r : Symbol) (x y : HF A) : Bool := | |
| decide (β a b, x = atom a β§ y = atom b β§ S.rel r a b = true) | |
| def liftβ {X Y Z : Type} (f : X β Y β Z) (a : Result X) (b : Result Y) : Result Z := | |
| a.bind (fun x => b.map (f x)) | |
| def collect (r : HF A) (guard : HF A β Result Bool) (body : HF A β Result (HF A)) : | |
| Result (HF A) := | |
| if (β x β elements r, (guard x).isSome) β§ | |
| (β x β elements r, guard x = some true β (body x).isSome) then | |
| some (ofFinset (((elements r).filter (fun x => guard x = some true)).image | |
| (fun x => (body x).getD emptyHF))) | |
| else none | |
| def iterationLoop (p : β) (step : HF A β Result (HF A)) : β β HF A β Result (HF A) | |
| | 0, _ => some emptyHF | |
| | fuel+1, x => | |
| if (TC x).card β€ p then | |
| (step x).bind (fun y => | |
| if x = y then some x else iterationLoop p step fuel y) | |
| else some emptyHF | |
| def ordinaryIteration (p : β) (step : HF A β Result (HF A)) : Result (HF A) := | |
| iterationLoop p step (p+1) emptyHF | |
| def resource (p : Polynomial β) (n : β) : β := βp.eval (n : β)ββ | |
| variable [Fintype A] | |
| def permutationGraph (g : Equiv.Perm A) : HF A := | |
| ofFinset (Finset.univ.image (fun a => pair (atom a) (atom (g a)))) | |
| def Automorphism (S : Input A) (g : Equiv.Perm A) : Prop := | |
| β r a b, S.rel r (g a) (g b) = S.rel r a b | |
| def ChoicePrefix (step : HF A β HF A β Result (HF A)) | |
| (choice : HF A β Result (HF A)) (b c : β β HF A) (k : β) : Prop := | |
| b 0 = emptyHF β§ β i < k, | |
| (β D, choice (b i) = some D β§ c i β elements D) β§ | |
| step (b i) (c i) = some (b (i+1)) | |
| def StrictPrefix (b : β β HF A) (k : β) : Prop := β i < k, b i β b (i+1) | |
| def FirstPath (step : HF A β HF A β Result (HF A)) | |
| (choice : HF A β Result (HF A)) (b c : β β HF A) (t : β) : Prop := | |
| ChoicePrefix step choice b c (t+1) β§ StrictPrefix b t β§ b t = b (t+1) | |
| def FixesParameters {n : β} (free : Finset (Fin n)) (env : Fin n β HF A) | |
| (g : Equiv.Perm A) : Prop := β i β free, g β’ env i = env i | |
| def WitnessesHistory {n : β} (S : Input A) (free : Finset (Fin n)) | |
| (env : Fin n β HF A) (b : β β HF A) (i : β) (D M : HF A) : Prop := | |
| isSet M = true β§ | |
| (β w β elements M, β g : Equiv.Perm A, | |
| w = permutationGraph g β§ Automorphism S g β§ FixesParameters free env g β§ | |
| β j β€ i, g β’ b j = b j) β§ | |
| (β u β elements D, β v β elements D, β g : Equiv.Perm A, | |
| permutationGraph g β elements M β§ g β’ u = v) | |
| def GoodWSC {n : β} (S : Input A) (p : β) (free : Finset (Fin n)) | |
| (env : Fin n β HF A) (step : HF A β HF A β Result (HF A)) | |
| (choice : HF A β Result (HF A)) (witness : HF A β HF A β Result (HF A)) | |
| (output : HF A β Result Bool) : Prop := | |
| (β b c k, ChoicePrefix step choice b c k β StrictPrefix b k β | |
| k β€ p β§ (TC (b k)).card β€ p β§ β D, choice (b k) = some D β§ | |
| (elements D).Nonempty β§ β u β elements D, (step (b k) u).isSome) β§ | |
| (β b c t, FirstPath step choice b c t β t+2 β€ p β§ | |
| (β i β€ t, β D M, choice (b i) = some D β§ witness (b t) (b i) = some M β§ | |
| WitnessesHistory S free env b i D M) β§ (output (b t)).isSome) | |
| def witnessedIteration {n : β} (S : Input A) (p : β) (free : Finset (Fin n)) | |
| (env : Fin n β HF A) (step : HF A β HF A β Result (HF A)) | |
| (choice : HF A β Result (HF A)) (witness : HF A β HF A β Result (HF A)) | |
| (output : HF A β Result Bool) : Result Bool := | |
| if GoodWSC S p free env step choice witness output then | |
| some (decide (β b c t, FirstPath step choice b c t β output (b t) = some true)) | |
| else none | |
| mutual | |
| def Term.eval (S : Input A) (p : Polynomial β) : {n : β} β Term n β | |
| (Fin n β HF A) β Result (HF A) | |
| | _, .var i, env => some (env i) | |
| | _, .empty, _ => some emptyHF | |
| | _, .atoms, _ => some (ofFinset (Finset.univ.image atom)) | |
| | _, .pair a b, env => liftβ double (a.eval S p env) (b.eval S p env) | |
| | _, .union a, env => (a.eval S p env).map unionHF | |
| | _, .unique a, env => (a.eval S p env).map uniqueHF | |
| | _, .card a, env => (a.eval S p env).map cardHF | |
| | _, .comprehend body range guard, env => | |
| (range.eval S p env).bind (fun r => collect r | |
| (fun x => guard.eval S p (Fin.cons x env)) | |
| (fun x => body.eval S p (Fin.cons x env))) | |
| | _, .iterate step, env => ordinaryIteration (resource p (Fintype.card A)) | |
| (fun x => step.eval S p (Fin.cons x env)) | |
| def Formula.eval (S : Input A) (p : Polynomial β) : {n : β} β Formula n β | |
| (Fin n β HF A) β Result Bool | |
| | _, .equal a b, env => liftβ (fun x y => decide (x = y)) (a.eval S p env) (b.eval S p env) | |
| | _, .input r a b, env => liftβ (inputHF S r) (a.eval S p env) (b.eval S p env) | |
| | _, .neg a, env => (a.eval S p env).map Bool.not | |
| | _, .and a b, env => liftβ Bool.and (a.eval S p env) (b.eval S p env) | |
| | _, .or a b, env => liftβ Bool.or (a.eval S p env) (b.eval S p env) | |
| | _, .wsc step choice witness output, env => | |
| witnessedIteration S (resource p (Fintype.card A)) | |
| (Formula.wsc step choice witness output).free env | |
| (fun x y => step.eval S p (Fin.cons y (Fin.cons x env))) | |
| (fun x => choice.eval S p (Fin.cons x env)) | |
| (fun z x => witness.eval S p (Fin.cons x (Fin.cons z env))) | |
| (fun x => output.eval S p (Fin.cons x env)) | |
| end | |
| structure FiniteInput where | |
| Carrier : Type | |
| finite : Fintype Carrier | |
| input : Input Carrier | |
| attribute [instance] FiniteInput.finite | |
| structure Sentence where | |
| formula : Formula 0 | |
| polynomial : Polynomial β | |
| def Sentence.eval (Ο : Sentence) (S : FiniteInput) : Result Bool := | |
| Ο.formula.eval S.input Ο.polynomial Fin.elim0 | |
| def Sentence.isCPT (Ο : Sentence) : Prop := Ο.formula.wscCount = 0 | |
| def Sentence.BooleanOnAllInputs (Ο : Sentence) : Prop := | |
| β S, β b : Bool, Ο.eval S = some b | |
| def Sentence.TrueModels (Ο : Sentence) : Set FiniteInput := {S | Ο.eval S = some true} | |
| def MainStatement : Prop := β Ο : Sentence, | |
| Ο.formula.wscCount = 1 β§ Ο.BooleanOnAllInputs β§ | |
| β Ο : Sentence, Ο.isCPT β Ο.TrueModels β Ο.TrueModels | |
| end | |
| end WitnessedChoice.BGS | |
| end OAI | |