math / data /lean /OAI /Computability /WitnessedChoice /SupportedForms.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
46.7 kB
import OAI.Computability.WitnessedChoice.Homogeneity namespace OAI namespace WitnessedSeparation.Grid noncomputable section open Classical Finset variable {n M : β„•} {b b' : Vertex n β†’ Scalar} theorem boundary_eq_incidence : (boundary : (Edge n β†’ Scalar) β†’β‚—[Scalar] (Vertex n β†’ Scalar)) = Flows.incidence tail head := rfl def GiantBound (n M : β„•) : Prop := ((12*(M:ℝ))/boxConstant)^((3:ℝ)/2) < ((n+1)^3:β„•) theorem giant_exists_of_bound (hbound : GiantBound n M) (T : Finset (Edge n)) (hT : T.card ≀ 6*M) : βˆƒ v, Flows.IsGiant tail head T v := by have hnum : ((2*T.card:ℝ)/boxConstant)^((3:ℝ)/2) < ((n+1)^3:β„•) := by apply lt_of_le_of_lt _ hbound apply Real.rpow_le_rpow (div_nonneg (by positivity) boxConstant_pos.le) _ (by norm_num) apply div_le_div_of_nonneg_right _ boxConstant_pos.le have hh : (T.card:ℝ) ≀ 6*M := by exact_mod_cast hT linarith obtain ⟨c,hc⟩ := exists_giant T hnum refine ⟨c.out,?_⟩ change Fintype.card (Vertex n) < 2*(Flows.cell tail head T c).card have hcard : Fintype.card (Vertex n) = (n+1)^3 := by simp only [Vertex,Fintype.card_prod,Fintype.card_fin]; ring simpa only [hcard] using hc theorem defect_transport (hbound : GiantBound n M) (T U : Finset (Edge n)) (hTU : T βŠ† U) (hU : U.card ≀ 6*M) (t : Edge n β†’ Scalar) (w : Vertex n) (hw : Flows.IsGiant tail head T w) (ht : boundary t = b'-b-Pi.single w 1) : βˆƒ t' : Edge n β†’ Scalar, βˆƒ w' : Vertex n, Flows.IsGiant tail head U w' ∧ boundary t' = b'-b-Pi.single w' 1 ∧ βˆ€ e ∈ T, t' e = t e := by obtain ⟨w',hw'⟩ := giant_exists_of_bound hbound U hU have hc := Flows.giants_connected tail head (Flows.giant_mono tail head hTU hw') hw obtain ⟨p,hp,hd⟩ := Flows.path_flow tail head T hc refine ⟨t+p,w',hw',?_,?_⟩ Β· rw [map_add,ht,boundary_eq_incidence,hd] abel Β· intro e he; simp [hp e he] def CompatibleAssignment {I : Type*} [DecidableEq I] (names : Finset I) (a : I β†’ Atom b) (a' : I β†’ Atom b') : Prop := βˆƒ t : Edge n β†’ Scalar, βˆƒ w : Vertex n, Flows.IsGiant tail head (touches names a) w ∧ boundary t = b'-b-Pi.single w 1 ∧ βˆ€ i ∈ names, AtomShift t (a i) (a' i) theorem CompatibleAssignment.mono {I : Type*} [DecidableEq I] {names small : Finset I} (hs : small βŠ† names) {a : I β†’ Atom b} {a' : I β†’ Atom b'} (h : CompatibleAssignment names a a') : CompatibleAssignment small a a' := by obtain ⟨t,w,hw,ht,ha⟩ := h exact ⟨t,w,Flows.giant_mono tail head (touches_mono hs a) hw,ht,fun i hi => ha i (hs hi)⟩ theorem CompatibleAssignment.extend (hn : 1 ≀ n) (hbound : GiantBound n M) (names : Finset (Fin M)) (a : Fin M β†’ Atom b) (a' : Fin M β†’ Atom b') (h : CompatibleAssignment names a a') (i : Fin M) : βˆƒ e : Atom b ≃ Atom b', βˆ€ x, CompatibleAssignment (insert i (names.erase i)) (Function.update a i x) (Function.update a' i (e x)) := by obtain ⟨t,w,hw,ht,ha⟩ := h.mono (erase_subset i names) let T := touches (names.erase i) a have hcard : (names.erase i).card + 1 ≀ M := by have hsub : names.erase i βŠ† (univ : Finset (Fin M)).erase i := erase_subset_erase i (subset_univ _) have hh := card_le_card hsub have hpos := i.isLt rw [card_erase_of_mem (mem_univ _),card_univ,Fintype.card_fin] at hh omega have hj (J : Block n) : (T βˆͺ blockEdges J).card ≀ 6*M := by calc _ ≀ T.card + (blockEdges J).card := card_union_le _ _ _ ≀ 6*(names.erase i).card + 6 := Nat.add_le_add (touches_card _ _) (blockEdges_card _) _ ≀ 6*M := by omega have hmove (J : Block n) := defect_transport hbound T (T βˆͺ blockEdges J) subset_union_left (hj J) t w hw ht choose tj wj hjg hjd hjs using hmove have hV : 2 ≀ Fintype.card (Vertex n) := by have hc : Fintype.card (Vertex n) = (n+1)^3 := by simp only [Vertex,Fintype.card_prod,Fintype.card_fin]; ring rw [hc] have hh : 2^3 ≀ (n+1)^3 := Nat.pow_le_pow_left (by omega) 3 omega have hv (v : Vertex n) : boundary (tj (.inr v)) v = b' v-b v := by have hwv : wj (.inr v) β‰  v := Flows.giant_ne_isolated tail head hV (hjg (.inr v)) (by intro e he exact mem_union_right _ (by simpa [blockEdges,incident,or_comm] using he)) have hh := congrFun (hjd (.inr v)) v simpa [Pi.single_apply,Ne.symm hwv] using hh let e := blockShiftEquiv (fun e => tj (.inl e)) (fun v => tj (.inr v)) hv refine ⟨e,fun x => ?_⟩ let J := atomBlock x refine ⟨tj J,wj J,?_,hjd J,?_⟩ Β· rw [touches_insert_update] exact hjg J Β· intro j hj' rcases mem_insert.mp hj' with rfl | hj' Β· simp only [Function.update_self] cases x with | inl x => rcases x with ⟨f,s⟩; exact AtomShift.edge f s | inr x => rcases x with ⟨v,s⟩; exact AtomShift.config v s (hv v) Β· have hji := (mem_erase.mp hj').1 simp only [Function.update_of_ne hji] exact (ha j hj').congr (fun f hf => (hjs J f (touch_subset_touches _ _ hj' hf)).symm) theorem base_equivalence_numeric (hn : 1 ≀ n) (hbound : GiantBound n M) (vstar : Vertex n) (Ο† : Counting.Formula AnalysisSymbol (Fin M)) (hΟ† : Ο†.free = βˆ…) (a : Fin M β†’ Atom (0 : Vertex n β†’ Scalar)) (a' : Fin M β†’ Atom (Pi.single vstar 1)) : Ο†.eval (analysisStructure (0 : Vertex n β†’ Scalar)) a ↔ Ο†.eval (analysisStructure (Pi.single vstar 1)) a' := by have heq : βˆ€ (names : Finset (Fin M)) (v : Fin M β†’ Atom (0 : Vertex n β†’ Scalar)) (w : Fin M β†’ Atom (Pi.single vstar 1)), CompatibleAssignment names v w β†’ βˆ€ i ∈ names, βˆ€ j ∈ names, (v i = v j ↔ w i = w j) := by intro names v w ⟨t,x,hg,hb,ha⟩ i hi j hj exact (ha i hi).equal_iff (ha j hj) have hrel : βˆ€ (names : Finset (Fin M)) (v : Fin M β†’ Atom (0 : Vertex n β†’ Scalar)) (w : Fin M β†’ Atom (Pi.single vstar 1)), CompatibleAssignment names v w β†’ βˆ€ r i, i ∈ names β†’ βˆ€ j, j ∈ names β†’ ((analysisStructure (0 : Vertex n β†’ Scalar)).rel r (v i) (v j) ↔ (analysisStructure (Pi.single vstar 1)).rel r (w i) (w j)) := by intro names v w ⟨t,x,hg,hb,ha⟩ r i hi j hj exact (ha i hi).analysisRelation (ha j hj) r apply Counting.Formula.eval_of_partialBijectionSystem _ _ CompatibleAssignment heq hrel (fun names v w hh i => CompatibleAssignment.extend hn hbound names v w hh i) Ο† βˆ… a a' _ (by simp [hΟ†]) refine ⟨0,vstar,?_,by simp,by simp⟩ simpa [touches] using grid_empty_giant vstar end end WitnessedSeparation.Grid namespace WitnessedSeparation.Forms noncomputable section open Classical open Counting Hereditary variable {R I J A B : Type*} inductive Form (J L : Type*) | atom (j : J) | set (n : β„•) (child : Fin n β†’ Form J L) (label : Fin n β†’ L) namespace Form variable [Fintype I] [Fintype J] [DecidableEq I] variable [Fintype A] [Nonempty A] def value (S : Structure R A) (e : J βŠ• J β†ͺ I) : Form J (Set (Formula R I)) β†’ (J β†’ A) β†’ HF A | .atom j, a => Hereditary.atom (a j) | .set _n child label, a => Hereditary.ofFinset (Finset.univ.biUnion fun i => (Finset.univ.filter fun b : J β†’ A => tupleType S e (Sum.elim b a) = label i).image (value S e (child i))) omit [Fintype I] in @[simp] theorem value_atom (S : Structure R A) (e : J βŠ• J β†ͺ I) (j : J) (a : J β†’ A) : value S e (.atom j) a = Hereditary.atom (a j) := rfl omit [Fintype I] in @[simp] theorem value_set_isSet (S : Structure R A) (e : J βŠ• J β†ͺ I) (n : β„•) (child : Fin n β†’ Form J (Set (Formula R I))) (label : Fin n β†’ Set (Formula R I)) (a : J β†’ A) : isSet (value S e (.set n child label) a) = true := rfl omit [Fintype I] in @[simp] theorem mem_value_set (S : Structure R A) (e : J βŠ• J β†ͺ I) (n : β„•) (child : Fin n β†’ Form J (Set (Formula R I))) (label : Fin n β†’ Set (Formula R I)) (a : J β†’ A) (x : HF A) : x ∈ value S e (.set n child label) a ↔ βˆƒ i b, tupleType S e (Sum.elim b a) = label i ∧ value S e (child i) b = x := by classical simp only [value,mem_ofFinset,Finset.mem_biUnion,Finset.mem_univ,true_and, Finset.mem_image,Finset.mem_filter,true_and] omit [Fintype I] in theorem value_iso [Fintype B] [Nonempty B] (S : Structure R A) (T : Structure R B) (e : J βŠ• J β†ͺ I) (f : A ≃ B) (hf : βˆ€ r a b, S.rel r a b ↔ T.rel r (f a) (f b)) (Ο† : Form J (Set (Formula R I))) (a : J β†’ A) : Hereditary.map f (value S e Ο† a) = value T e Ο† (f ∘ a) := by induction Ο† generalizing a with | atom j => rfl | set n child label ih => apply Hereditary.ext_sets (by simp [value]) (by simp) intro x change x ∈ elements (Hereditary.map f (value S e (.set n child label) a)) ↔ _ rw [Hereditary.elements_map] simp only [Finset.mem_image] constructor Β· rintro ⟨y,hy,rfl⟩ obtain ⟨i,b,ht,rfl⟩ := (mem_value_set S e n child label a y).mp hy apply (mem_value_set T e n child label (f ∘ a) _).mpr refine ⟨i,f ∘ b,?_,(ih i b).symm⟩ have heq : Sum.elim (f ∘ b) (f ∘ a) = f ∘ Sum.elim b a := by funext j; cases j <;> rfl rw [heq,← tupleType_iso S T e f hf,ht] Β· intro hx obtain ⟨i,b,ht,hx⟩ := (mem_value_set T e n child label (f ∘ a) x).mp hx let c := f.symm ∘ b have hc : f ∘ c = b := by funext j; simp [c] refine ⟨value S e (child i) c,?_,?_⟩ Β· apply (mem_value_set S e n child label a _).mpr refine ⟨i,c,?_,rfl⟩ rw [tupleType_iso S T e f hf] have heq : f ∘ Sum.elim c a = Sum.elim b (f ∘ a) := by funext j; cases j <;> simp [c] rw [heq,ht] Β· rw [ih,hc,hx] end Form def cross31 : J βŠ• J β†ͺ (J βŠ• J) βŠ• J where toFun := Sum.elim Sum.inr (fun j => Sum.inl (Sum.inl j)) inj' := by intro a b h; cases a <;> cases b <;> simp_all def cross42 : J βŠ• J β†ͺ ((J βŠ• J) βŠ• J) βŠ• J where toFun := Sum.elim Sum.inr (fun j => Sum.inl (Sum.inl (Sum.inr j))) inj' := by intro a b h; cases a <;> cases b <;> simp_all def cross34 : J βŠ• J β†ͺ ((J βŠ• J) βŠ• J) βŠ• J where toFun := Sum.elim (fun j => Sum.inl (Sum.inr j)) Sum.inr inj' := by intro a b h; cases a <;> cases b <;> simp_all theorem swap_type [Fintype J] [DecidableEq I] [Nonempty A] [Nonempty B] (S : Structure R A) (T : Structure R B) (e : J βŠ• J β†ͺ I) (a b : J β†’ A) (a' b' : J β†’ B) (h : tupleType S e (Sum.elim a b) = tupleType T e (Sum.elim a' b')) : tupleType S e (Sum.elim b a) = tupleType T e (Sum.elim b' a') := by have ht := tupleType_project S T e e (Equiv.sumComm J J).toEmbedding _ _ h have h1 : Sum.elim a b ∘ (Equiv.sumComm J J).toEmbedding = Sum.elim b a := by funext j; cases j <;> rfl have h2 : Sum.elim a' b' ∘ (Equiv.sumComm J J).toEmbedding = Sum.elim b' a' := by funext j; cases j <;> rfl simpa only [h1,h2] using ht @[simp] theorem elim_comp_cross31 (a b c : J β†’ A) : Sum.elim (Sum.elim a b) c ∘ cross31 = Sum.elim c a := by funext j; cases j <;> rfl @[simp] theorem elim_comp_cross42 (a b c d : J β†’ A) : Sum.elim (Sum.elim (Sum.elim a b) c) d ∘ cross42 = Sum.elim d b := by funext j; cases j <;> rfl @[simp] theorem elim_comp_cross34 (a b c d : J β†’ A) : Sum.elim (Sum.elim (Sum.elim a b) c) d ∘ cross34 = Sum.elim c d := by funext j; cases j <;> rfl section AtomicTransfer variable [Fintype I] [Fintype J] [DecidableEq I] variable [Fintype A] [Nonempty A] [Fintype B] [Nonempty B] variable (S : Structure R A) (T : Structure R B) variable (e2 : J βŠ• J β†ͺ I) (e3 : (J βŠ• J) βŠ• J β†ͺ I) variable (e4 : ((J βŠ• J) βŠ• J) βŠ• J β†ͺ I) open Form include e3 e4 private theorem set_subset_transfer (n k : β„•) (child : Fin n β†’ Form J (Set (Formula R I))) (other : Fin k β†’ Form J (Set (Formula R I))) (label : Fin n β†’ Set (Formula R I)) (lab : Fin k β†’ Set (Formula R I)) (hc : βˆ€ i j (c d : J β†’ A) (c' d' : J β†’ B), tupleType S e2 (Sum.elim c d) = tupleType T e2 (Sum.elim c' d') β†’ (value S e2 (child i) c = value S e2 (other j) d ↔ value T e2 (child i) c' = value T e2 (other j) d')) (a b : J β†’ A) (a' b' : J β†’ B) (ht : tupleType S e2 (Sum.elim a b) = tupleType T e2 (Sum.elim a' b')) (hsub : βˆ€ x, x ∈ value S e2 (.set n child label) a β†’ x ∈ value S e2 (.set k other lab) b) : βˆ€ x, x ∈ value T e2 (.set n child label) a' β†’ x ∈ value T e2 (.set k other lab) b' := by intro x hx obtain ⟨i,c',hl,rfl⟩ := (mem_value_set T e2 n child label a' x).mp hx obtain ⟨c,h3⟩ := tupleType_append T S e2 e3 (Sum.elim a' b') (Sum.elim a b) c' ht.symm have hca := tupleType_project T S e3 e2 cross31 _ _ h3 simp only [elim_comp_cross31] at hca have hmem : value S e2 (child i) c ∈ value S e2 (.set n child label) a := (mem_value_set S e2 n child label a _).mpr ⟨i,c,hca.symm.trans hl,rfl⟩ obtain ⟨j,d,hlab,heq⟩ := (mem_value_set S e2 k other lab b _).mp (hsub _ hmem) obtain ⟨d',h4⟩ := tupleType_append S T e3 e4 (Sum.elim (Sum.elim a b) c) (Sum.elim (Sum.elim a' b') c') d h3.symm have hdb := tupleType_project S T e4 e2 cross42 _ _ h4 have hcd := tupleType_project S T e4 e2 cross34 _ _ h4 simp only [elim_comp_cross42] at hdb simp only [elim_comp_cross34] at hcd exact (mem_value_set T e2 k other lab b' _).mpr ⟨j,d',hdb.symm.trans hlab,((hc i j c d c' d' hcd).mp heq.symm).symm⟩ private theorem set_eq_forward (n k : β„•) (child : Fin n β†’ Form J (Set (Formula R I))) (other : Fin k β†’ Form J (Set (Formula R I))) (label : Fin n β†’ Set (Formula R I)) (lab : Fin k β†’ Set (Formula R I)) (hc : βˆ€ i j (c d : J β†’ A) (c' d' : J β†’ B), tupleType S e2 (Sum.elim c d) = tupleType T e2 (Sum.elim c' d') β†’ (value S e2 (child i) c = value S e2 (other j) d ↔ value T e2 (child i) c' = value T e2 (other j) d')) (a b : J β†’ A) (a' b' : J β†’ B) (ht : tupleType S e2 (Sum.elim a b) = tupleType T e2 (Sum.elim a' b')) (h : value S e2 (.set n child label) a = value S e2 (.set k other lab) b) : value T e2 (.set n child label) a' = value T e2 (.set k other lab) b' := by apply Hereditary.ext_sets (by simp) (by simp) intro x constructor Β· exact set_subset_transfer S T e2 e3 e4 n k child other label lab hc a b a' b' ht (fun z hz => by rw [←h]; exact hz) x Β· apply set_subset_transfer S T e2 e3 e4 k n other child lab label (fun j i c d c' d' ht' => ?_) b a b' a' (swap_type S T e2 a b a' b' ht) (fun z hz => by rw [h]; exact hz) x have hh := hc i j d c d' c' (swap_type S T e2 c d c' d' ht') exact ⟨fun he => (hh.mp he.symm).symm,fun he => (hh.mpr he.symm).symm⟩ theorem equality_transfer (Ο† ψ : Form J (Set (Formula R I))) (a b : J β†’ A) (a' b' : J β†’ B) (ht : tupleType S e2 (Sum.elim a b) = tupleType T e2 (Sum.elim a' b')) : value S e2 Ο† a = value S e2 ψ b ↔ value T e2 Ο† a' = value T e2 ψ b' := by induction Ο† generalizing ψ a b a' b' with | atom i => cases ψ with | atom j => have he := (typeOf_eq_iff S T (tupleNames e2) _ _).mp ht (.equal (e2 (.inl i)) (e2 (.inr j))) (by intro p hp simp only [Formula.free,Finset.mem_insert,Finset.mem_singleton] at hp rcases hp with rfl | rfl <;> exact (mem_tupleNames _ _).mpr ⟨_,rfl⟩) simpa only [Formula.eval,tupleAssignment_apply,Sum.elim_inl,Sum.elim_inr, value_atom,Hereditary.atom_injective.eq_iff] using he | set k other lab => have hfalseA : value S e2 (.atom i) a β‰  value S e2 (.set k other lab) b := by intro h; have hh := congrArg isSet h; simp at hh have hfalseB : value T e2 (.atom i) a' β‰  value T e2 (.set k other lab) b' := by intro h; have hh := congrArg isSet h; simp at hh exact iff_of_false hfalseA hfalseB | set n child label ih => cases ψ with | atom j => have hfalseA : value S e2 (.set n child label) a β‰  value S e2 (.atom j) b := by intro h; have hh := congrArg isSet h; simp at hh have hfalseB : value T e2 (.set n child label) a' β‰  value T e2 (.atom j) b' := by intro h; have hh := congrArg isSet h; simp at hh exact iff_of_false hfalseA hfalseB | set k other lab => constructor Β· exact set_eq_forward S T e2 e3 e4 n k child other label lab (fun i j c d c' d' ht' => ih i (other j) c d c' d' ht') a b a' b' ht Β· exact set_eq_forward T S e2 e3 e4 n k child other label lab (fun i j c' d' c d ht' => (ih i (other j) c d c' d' ht'.symm).symm) a' b' a b ht.symm private theorem membership_forward (Ο† : Form J (Set (Formula R I))) (k : β„•) (other : Fin k β†’ Form J (Set (Formula R I))) (lab : Fin k β†’ Set (Formula R I)) (a b : J β†’ A) (a' b' : J β†’ B) (ht : tupleType S e2 (Sum.elim a b) = tupleType T e2 (Sum.elim a' b')) (hm : value S e2 Ο† a ∈ value S e2 (.set k other lab) b) : value T e2 Ο† a' ∈ value T e2 (.set k other lab) b' := by obtain ⟨i,c,hl,heq⟩ := (mem_value_set S e2 k other lab b _).mp hm obtain ⟨c',h3⟩ := tupleType_append S T e2 e3 (Sum.elim b a) (Sum.elim b' a') c (swap_type S T e2 a b a' b' ht) have hcb := tupleType_project S T e3 e2 cross31 _ _ h3 simp only [elim_comp_cross31] at hcb let u : J βŠ• J β†ͺ (J βŠ• J) βŠ• J := cross31.trans (Function.Embedding.sumMap (Equiv.sumComm J J).toEmbedding (Function.Embedding.refl J)) have hca := tupleType_project S T e3 e2 u _ _ h3 have hueq (a b c : J β†’ A) : Sum.elim (Sum.elim b a) c ∘ u = Sum.elim c a := by funext j; cases j <;> rfl have hueq' (a b c : J β†’ B) : Sum.elim (Sum.elim b a) c ∘ u = Sum.elim c a := by funext j; cases j <;> rfl rw [hueq,hueq'] at hca exact (mem_value_set T e2 k other lab b' _).mpr ⟨i,c',hcb.symm.trans hl, (equality_transfer S T e2 e3 e4 (other i) Ο† c a c' a' hca).mp heq⟩ theorem membership_transfer (Ο† ψ : Form J (Set (Formula R I))) (a b : J β†’ A) (a' b' : J β†’ B) (ht : tupleType S e2 (Sum.elim a b) = tupleType T e2 (Sum.elim a' b')) : value S e2 Ο† a ∈ value S e2 ψ b ↔ value T e2 Ο† a' ∈ value T e2 ψ b' := by cases ψ with | atom j => simp | set k other lab => exact ⟨membership_forward S T e2 e3 e4 Ο† k other lab a b a' b' ht, membership_forward T S e2 e3 e4 Ο† k other lab a' b' a b ht.symm⟩ end AtomicTransfer variable {G : Type*} [Group G] [MulAction G A] variable [Fintype I] [DecidableEq I] [Fintype A] [Nonempty A] {s : β„•} variable (S : Structure R A) (e2 : Fin s βŠ• Fin s β†ͺ I) variable (hAut : βˆ€ (g : G) r a b, S.rel r (g β€’ a) (g β€’ b) ↔ S.rel r a b) open Form include hAut in omit [Fintype I] in theorem value_smul (g : G) (Ο† : Form (Fin s) (Set (Formula R I))) (a : Fin s β†’ A) : g β€’ value S e2 Ο† a = value S e2 Ο† (fun i => g β€’ a i) := by exact value_iso S S e2 (MulAction.toPerm g) (fun r a b => (hAut g r a b).symm) Ο† a include hAut in omit [Fintype I] in theorem value_supported (Ο† : Form (Fin s) (Set (Formula R I))) (a : Fin s β†’ A) : Supports (G := G) a (value S e2 Ο† a) := by intro g hg rw [value_smul S e2 hAut] exact congrArg (value S e2 Ο†) (funext hg) omit [Fintype A] [Nonempty A] in private theorem hereditary_mem {x y : HF A} (hx : HereditarilySupported (G := G) s x) (hy : y ∈ x) : HereditarilySupported (G := G) s y := by intro z hz exact hx z (hz.trans (Relation.ReflTransGen.single hy)) omit [Fintype A] [Nonempty A] in private theorem hereditary_intro (x : HF A) (hx : Supported (G := G) s x) (hm : βˆ€ y ∈ x, HereditarilySupported (G := G) s y) : HereditarilySupported (G := G) s x := by intro y hy cases hy with | refl => exact hx | tail hpath hstep => exact hm _ hstep _ hpath include hAut in omit [Fintype I] in theorem value_hereditarily_supported (Ο† : Form (Fin s) (Set (Formula R I))) (a : Fin s β†’ A) : HereditarilySupported (G := G) s (value S e2 Ο† a) := by induction Ο† generalizing a with | atom i => apply hereditary_intro _ ⟨a,value_supported S e2 hAut _ a⟩ intro y hy exact (not_mem_atom y (a i) hy).elim | set n child label ih => apply hereditary_intro _ ⟨a,value_supported S e2 hAut _ a⟩ intro y hy obtain ⟨i,b,ht,rfl⟩ := (mem_value_set S e2 n child label a y).mp hy exact ih i b omit [Fintype A] [Nonempty A] in private theorem smul_mem (g : G) {x y : HF A} (h : y ∈ x) : g β€’ y ∈ g β€’ x := by change Hereditary.map (fun a => g β€’ a) y ∈ elements (Hereditary.map (fun a => g β€’ a) x) let := Hereditary.instDecidableEqHF (A := A) rw [elements_map] exact Finset.mem_image.mpr ⟨y,h,rfl⟩ include hAut in omit [Fintype I] in theorem representation (hs : 0 < s) (hHom : βˆ€ p q : Fin s βŠ• Fin s β†’ A, tupleType S e2 p = tupleType S e2 q β†’ βˆƒ g : G, βˆ€ i, g β€’ p i = q i) (x : HF A) (hx : HereditarilySupported (G := G) s x) : βˆƒ Ο† : Form (Fin s) (Set (Formula R I)), βˆƒ a : Fin s β†’ A, value S e2 Ο† a = x := by induction x using mem_wellFounded.induction with | h x ih => rcases atom_or_set x with ⟨b,rfl⟩ | hxset Β· exact ⟨.atom ⟨0,hs⟩,fun _ => b,rfl⟩ Β· obtain ⟨a,ha⟩ := hx x Relation.ReflTransGen.refl have hr : βˆ€ y : {y // y ∈ elements x}, βˆƒ Ο† : Form (Fin s) (Set (Formula R I)), βˆƒ b : Fin s β†’ A, value S e2 Ο† b = y.1 := by intro y exact ih y.1 y.2 (hereditary_mem hx y.2) choose form mol hvalue using hr let n := Fintype.card {y // y ∈ elements x} let en : Fin n ≃ {y // y ∈ elements x} := (Fintype.equivFin _).symm let child : Fin n β†’ Form (Fin s) (Set (Formula R I)) := fun i => form (en i) let Ξ² : Fin n β†’ Fin s β†’ A := fun i => mol (en i) let label : Fin n β†’ Set (Formula R I) := fun i => tupleType S e2 (Sum.elim (Ξ² i) a) refine ⟨.set n child label,a,?_⟩ apply Hereditary.ext_sets (by simp) (by rw [hxset]; rfl) intro y constructor Β· intro hy obtain ⟨i,b,ht,rfl⟩ := (mem_value_set S e2 n child label a y).mp hy obtain ⟨g,hg⟩ := hHom (Sum.elim (Ξ² i) a) (Sum.elim b a) ht.symm have hga : βˆ€ j, g β€’ a j = a j := fun j => hg (.inr j) have hgb : (fun j => g β€’ Ξ² i j) = b := funext (fun j => hg (.inl j)) have hyx : (en i).1 ∈ x := (en i).2 have hmap := smul_mem g hyx rw [ha g hga] at hmap have hv : value S e2 (child i) b = g β€’ (en i).1 := by rw [←hgb,←value_smul S e2 hAut] exact congrArg (fun z : HF A => g β€’ z) (hvalue (en i)) rw [hv] exact hmap Β· intro hy let y' : {y // y ∈ elements x} := ⟨y,hy⟩ let i := en.symm y' apply (mem_value_set S e2 n child label a y).mpr refine ⟨i,Ξ² i,rfl,?_⟩ have hv := hvalue (en i) simpa only [child,Ξ²,i,Equiv.apply_symm_apply] using hv end end WitnessedSeparation.Forms namespace WitnessedSeparation.Counting noncomputable section open Classical variable {R I J A B : Type*} [DecidableEq I] def triangular {X Y : Type*} (e : X ≃ Y) (f : X β†’ A ≃ B) : X Γ— A ≃ Y Γ— B where toFun p := (e p.1, f p.1 p.2) invFun p := (e.symm p.1, (f (e.symm p.1)).symm p.2) left_inv p := by simp right_inv p := by simp def snocTuple {n : β„•} (a : Fin n β†’ A) (x : A) : Fin (n+1) β†’ A := Fin.lastCases x a @[simp] theorem snocTuple_castSucc {n : β„•} (a : Fin n β†’ A) (x : A) (i : Fin n) : snocTuple a x i.castSucc = a i := by simp [snocTuple] @[simp] theorem snocTuple_last {n : β„•} (a : Fin n β†’ A) (x : A) : snocTuple a x (Fin.last n) = x := by simp [snocTuple] def snocEquiv (n : β„•) : (Fin (n+1) β†’ A) ≃ (Fin n β†’ A) Γ— A where toFun a := (fun i => a i.castSucc, a (Fin.last n)) invFun p := snocTuple p.1 p.2 left_inv a := by funext i induction i using Fin.lastCases <;> simp right_inv p := by ext <;> simp def appendPosition (J : Type*) (n : β„•) : (J βŠ• Fin n) βŠ• Unit ≃ J βŠ• Fin (n+1) where toFun := Sum.elim (Sum.elim Sum.inl (fun i => Sum.inr i.castSucc)) (fun _ => Sum.inr (Fin.last n)) invFun := Sum.elim (fun j => Sum.inl (Sum.inl j)) (Fin.lastCases (Sum.inr ()) (fun i => Sum.inl (Sum.inr i))) left_inv p := by rcases p with (j|i)|u <;> simp right_inv p := by rcases p with j|i Β· rfl Β· induction i using Fin.lastCases <;> simp variable [Fintype I] [Fintype J] [Fintype A] [Fintype B] [Nonempty A] [Nonempty B] theorem tupleType_append_one_bijection (S : Structure R A) (T : Structure R B) (e : J β†ͺ I) (E : J βŠ• Unit β†ͺ I) (a : J β†’ A) (b : J β†’ B) (ht : tupleType S e a = tupleType T e b) : βˆƒ f : A ≃ B, βˆ€ x, tupleType S E (Sum.elim a (fun _ => x)) = tupleType T E (Sum.elim b (fun _ => f x)) := by let ep := Function.Embedding.inl.trans E let i := E (Sum.inr ()) have hp := tupleType_project S T e ep (Function.Embedding.refl J) a b ht change tupleType S ep a = tupleType T ep b at hp have hi : i βˆ‰ tupleNames ep := by rintro hh obtain ⟨j,hj⟩ := (mem_tupleNames ep i).mp hh have hh := E.injective hj cases hh have hn : insert i (tupleNames ep) = tupleNames E := by ext p simp only [Finset.mem_insert,mem_tupleNames] constructor Β· rintro (rfl|⟨j,rfl⟩) Β· exact ⟨Sum.inr (),rfl⟩ Β· exact ⟨Sum.inl j,rfl⟩ Β· rintro ⟨j,rfl⟩ rcases j with j|u Β· exact Or.inr ⟨j,rfl⟩ Β· cases u; exact Or.inl rfl have ha (x : A) : tupleType S E (Sum.elim a (fun _ => x)) = typeOf S (tupleNames E) (Function.update (tupleAssignment ep a) i x) := by apply tupleType_assignment intro j rcases j with j|u Β· have hne : E (Sum.inl j) β‰  i := by intro h; have hh := E.injective h; cases hh rw [Function.update_of_ne hne] exact tupleAssignment_apply ep a j Β· cases u; simp [i] have hb (x : B) : tupleType T E (Sum.elim b (fun _ => x)) = typeOf T (tupleNames E) (Function.update (tupleAssignment ep b) i x) := by apply tupleType_assignment intro j rcases j with j|u Β· have hne : E (Sum.inl j) β‰  i := by intro h; have hh := E.injective h; cases hh rw [Function.update_of_ne hne] exact tupleAssignment_apply ep b j Β· cases u; simp [i] obtain ⟨f,hf⟩ := extension_bijection S T (tupleNames ep) i hi (tupleAssignment ep a) (tupleAssignment ep b) hp refine ⟨f,fun x => ?_⟩ rw [ha,hb] simpa only [hn] using hf x theorem tupleType_append_fin_bijection (S : Structure R A) (T : Structure R B) (e : J β†ͺ I) (n : β„•) (E : J βŠ• Fin n β†ͺ I) (a : J β†’ A) (b : J β†’ B) (ht : tupleType S e a = tupleType T e b) : βˆƒ f : (Fin n β†’ A) ≃ (Fin n β†’ B), βˆ€ c, tupleType S E (Sum.elim a c) = tupleType T E (Sum.elim b (f c)) := by induction n with | zero => let f : (Fin 0 β†’ A) ≃ (Fin 0 β†’ B) := ⟨fun _ => Fin.elim0,fun _ => Fin.elim0, fun _ => Subsingleton.elim _ _,fun _ => Subsingleton.elim _ _⟩ refine ⟨f,fun c => ?_⟩ let u : J βŠ• Fin 0 β†ͺ J := ⟨Sum.elim id Fin.elim0,by intro x y h rcases x with x|x Β· rcases y with y|y Β· exact congrArg Sum.inl h Β· exact Fin.elim0 y Β· exact Fin.elim0 x⟩ have h := tupleType_project S T e E u a b ht have ha : a ∘ u = Sum.elim a c := by funext j; rcases j with j|i Β· rfl Β· exact Fin.elim0 i have hb : b ∘ u = Sum.elim b (f c) := by funext j; rcases j with j|i Β· rfl Β· exact Fin.elim0 i simpa only [ha,hb] using h | succ n ih => let pre : J βŠ• Fin n β†ͺ J βŠ• Fin (n+1) := Function.Embedding.sumMap (Function.Embedding.refl J) Fin.castSuccEmb let ep := pre.trans E obtain ⟨f,hf⟩ := ih ep let E1 := (appendPosition J n).toEmbedding.trans E have h1 (c : Fin n β†’ A) : βˆƒ g : A ≃ B, βˆ€ x, tupleType S E1 (Sum.elim (Sum.elim a c) (fun _ => x)) = tupleType T E1 (Sum.elim (Sum.elim b (f c)) (fun _ => g x)) := tupleType_append_one_bijection S T ep E1 _ _ (hf c) choose g hg using h1 let F := (snocEquiv (A:=A) n).trans ((triangular f g).trans (snocEquiv (A:=B) n).symm) refine ⟨F,fun c => ?_⟩ have hh := tupleType_project S T E1 E (appendPosition J n).symm.toEmbedding _ _ (hg (fun i => c i.castSucc) (c (Fin.last n))) have ha : (Sum.elim (Sum.elim a (fun i => c i.castSucc)) (fun _ => c (Fin.last n))) ∘ (appendPosition J n).symm = Sum.elim a c := by funext j rcases j with j|i Β· rfl Β· induction i using Fin.lastCases <;> simp [appendPosition] have hb : (Sum.elim (Sum.elim b (f (fun i => c i.castSucc))) (fun _ => g (fun i => c i.castSucc) (c (Fin.last n)))) ∘ (appendPosition J n).symm = Sum.elim b (F c) := by funext j rcases j with j|i Β· rfl Β· induction i using Fin.lastCases <;> simp [appendPosition,F,snocEquiv,triangular,snocTuple] simpa only [Equiv.coe_toEmbedding,ha,hb] using hh theorem tupleType_append_bijection {D : Type*} [Fintype D] (S : Structure R A) (T : Structure R B) (e : J β†ͺ I) (E : J βŠ• D β†ͺ I) (a : J β†’ A) (b : J β†’ B) (ht : tupleType S e a = tupleType T e b) : βˆƒ f : (D β†’ A) ≃ (D β†’ B), βˆ€ c, tupleType S E (Sum.elim a c) = tupleType T E (Sum.elim b (f c)) := by let en := Fintype.equivFin D let E' := (Equiv.sumCongr (Equiv.refl J) en.symm).toEmbedding.trans E obtain ⟨f,hf⟩ := tupleType_append_fin_bijection S T e (Fintype.card D) E' a b ht let F := (Equiv.arrowCongr en (Equiv.refl A)).trans (f.trans (Equiv.arrowCongr en.symm (Equiv.refl B))) refine ⟨F,fun c => ?_⟩ have hh := tupleType_project S T E' E (Equiv.sumCongr (Equiv.refl J) en).toEmbedding _ _ (hf (c ∘ en.symm)) have ha : (Sum.elim a (c ∘ en.symm)) ∘ (Equiv.sumCongr (Equiv.refl J) en) = Sum.elim a c := by funext j; rcases j with j|j <;> simp have hb : (Sum.elim b (f (c ∘ en.symm))) ∘ (Equiv.sumCongr (Equiv.refl J) en) = Sum.elim b (F c) := by funext j; rcases j with j|j <;> rfl simpa only [Equiv.coe_toEmbedding,ha,hb] using hh theorem tupleType_extension_equiv {D : Type*} [Fintype D] (S : Structure R A) (T : Structure R B) (e : J β†ͺ I) (E : J βŠ• D β†ͺ I) (a : J β†’ A) (b : J β†’ B) (ht : tupleType S e a = tupleType T e b) (Ο„ : Set (Formula R I)) : Nonempty ({c : D β†’ A // tupleType S E (Sum.elim a c) = Ο„} ≃ {d : D β†’ B // tupleType T E (Sum.elim b d) = Ο„}) := by obtain ⟨f,hf⟩ := tupleType_append_bijection S T e E a b ht exact ⟨f.subtypeEquiv (fun c => by rw [hf c])⟩ end end WitnessedSeparation.Counting namespace WitnessedSeparation.Forms noncomputable section open Classical Counting Hereditary open scoped BigOperators private theorem card_eq_mul_fiber {X Y : Type*} [Fintype X] [Fintype Y] (f : X β†’ Y) (yβ‚€ : Y) (h : βˆ€ y, Fintype.card {x // f x = y} = Fintype.card {x // f x = yβ‚€}) : Fintype.card X = Fintype.card Y * Fintype.card {x // f x = yβ‚€} := by calc Fintype.card X = Fintype.card (Ξ£ y, {x // f x = y}) := Fintype.card_congr (Equiv.sigmaFiberEquiv f).symm _ = βˆ‘ y, Fintype.card {x // f x = y} := Fintype.card_sigma _ = _ := by simp only [h,Finset.sum_const,Finset.card_univ,smul_eq_mul] private theorem card_eq_of_uniform_fibers {X X' Y Y' : Type*} [Fintype X] [Fintype X'] [Fintype Y] [Fintype Y'] (f : X β†’ Y) (f' : X' β†’ Y') (y : Y) (y' : Y') (hx : Fintype.card X = Fintype.card X') (hf : βˆ€ z, Fintype.card {x // f x = z} = Fintype.card {x // f x = y}) (hf' : βˆ€ z, Fintype.card {x // f' x = z} = Fintype.card {x // f' x = y'}) (hy : 0 < Fintype.card {x // f x = y}) (he : Fintype.card {x // f x = y} = Fintype.card {x // f' x = y'}) : Fintype.card Y = Fintype.card Y' := by have h := (card_eq_mul_fiber f y hf).symm.trans (hx.trans (card_eq_mul_fiber f' y' hf')) rw [←he] at h exact Nat.eq_of_mul_eq_mul_right hy h private theorem range_card_mul_fiber {X Y : Type*} [Fintype X] (f : X β†’ Y) (xβ‚€ : X) (h : βˆ€ x, Nat.card {z // f z = f x} = Nat.card {z // f z = f xβ‚€}) : Fintype.card X = Nat.card (Set.range f) * Nat.card {z // f z = f xβ‚€} := by let := (Set.finite_range f).fintype let fR : X β†’ Set.range f := fun x => ⟨f x,⟨x,rfl⟩⟩ have k (y : Set.range f) : Nat.card {x // fR x = y} = Nat.card {z // f z = f xβ‚€} := by have hp (x : X) : fR x = y ↔ f x = y.1 := Subtype.ext_iff rw [Nat.card_congr (Equiv.subtypeEquivRight hp)] obtain ⟨x,hx⟩ := y.2 rw [←hx] exact h x have hh := card_eq_mul_fiber fR (fR xβ‚€) (fun y => by simpa only [←Nat.card_eq_fintype_card] using (k y).trans (k (fR xβ‚€)).symm) have hh' : Nat.card X = Nat.card (Set.range f) * Nat.card {x // fR x = fR xβ‚€} := by simpa only [←Nat.card_eq_fintype_card] using hh rw [k] at hh' simpa only [←Nat.card_eq_fintype_card] using hh' variable {R I A B P : Type*} [Fintype I] [DecidableEq I] variable [Fintype A] [Fintype B] [Nonempty A] [Nonempty B] [Fintype P] variable {s : β„•} def Molecules (S : Structure R A) (ep : P βŠ• Fin s β†ͺ I) (p : P β†’ A) (Ο„ : Set (Formula R I)) := {a : Fin s β†’ A // tupleType S ep (Sum.elim p a) = Ο„} instance (S : Structure R A) (ep : P βŠ• Fin s β†ͺ I) (p : P β†’ A) (Ο„ : Set (Formula R I)) : Fintype (Molecules S ep p Ο„) := inferInstanceAs (Fintype {a : Fin s β†’ A // tupleType S ep (Sum.elim p a) = Ο„}) def labelValues (S : Structure R A) (ep : P βŠ• Fin s β†ͺ I) (e2 : Fin s βŠ• Fin s β†ͺ I) (p : P β†’ A) (Ο„ : Set (Formula R I)) (Ο† : Form (Fin s) (Set (Formula R I))) : Set (HF A) := Set.range (fun a : Molecules S ep p Ο„ => Form.value S e2 Ο† a.1) instance (S : Structure R A) (ep : P βŠ• Fin s β†ͺ I) (e2 : Fin s βŠ• Fin s β†ͺ I) (p : P β†’ A) (Ο„ : Set (Formula R I)) (Ο† : Form (Fin s) (Set (Formula R I))) : Fintype (labelValues S ep e2 p Ο„ Ο†) := (Set.finite_range _).fintype section Group variable {G : Type*} [Group G] [MulAction G A] variable (S : Structure R A) (ep : P βŠ• Fin s β†ͺ I) (e2 : Fin s βŠ• Fin s β†ͺ I) variable (hAut : βˆ€ (g : G) r a b, S.rel r (g β€’ a) (g β€’ b) ↔ S.rel r a b) variable (p : P β†’ A) (Ο„ : Set (Formula R I)) include hAut in omit [Fintype I] [Fintype A] in private theorem mol_type_smul (g : G) (hp : βˆ€ i, g β€’ p i = p i) (a : Fin s β†’ A) : tupleType S ep (Sum.elim p (fun i => g β€’ a i)) = tupleType S ep (Sum.elim p a) := by have hh := tupleType_iso S S ep (MulAction.toPerm g) (fun r a b => (hAut g r a b).symm) (Sum.elim p a) have hh' : (MulAction.toPerm g) ∘ Sum.elim p a = Sum.elim p (fun i => g β€’ a i) := by funext i; rcases i with i|i Β· exact hp i Β· rfl rw [hh'] at hh exact hh.symm def moleculesPerm (g : G) (hp : βˆ€ i, g β€’ p i = p i) : Molecules S ep p Ο„ ≃ Molecules S ep p Ο„ := (Equiv.piCongrRight (fun _ : Fin s => MulAction.toPerm g)).subtypeEquiv (fun a => by change tupleType S ep (Sum.elim p a) = Ο„ ↔ tupleType S ep (Sum.elim p (fun i => g β€’ a i)) = Ο„ rw [mol_type_smul S ep hAut p g hp a]) include hAut in omit [Fintype I] in theorem uniform_value_fibers (hHom : βˆ€ a b : P βŠ• Fin s β†’ A, tupleType S ep a = tupleType S ep b β†’ βˆƒ g : G, βˆ€ i, g β€’ a i = b i) (Ο† : Form (Fin s) (Set (Formula R I))) (a a' : Molecules S ep p Ο„) : Fintype.card {b : Molecules S ep p Ο„ // Form.value S e2 Ο† b.1 = Form.value S e2 Ο† a.1} = Fintype.card {b : Molecules S ep p Ο„ // Form.value S e2 Ο† b.1 = Form.value S e2 Ο† a'.1} := by obtain ⟨g,hg⟩ := hHom (Sum.elim p a.1) (Sum.elim p a'.1) (a.2.trans a'.2.symm) have hp : βˆ€ i, g β€’ p i = p i := fun i => hg (.inl i) have ha : (fun i => g β€’ a.1 i) = a'.1 := funext (fun i => hg (.inr i)) let f := moleculesPerm S ep hAut p Ο„ g hp have hv (b : Molecules S ep p Ο„) : Form.value S e2 Ο† (f b).1 = g β€’ Form.value S e2 Ο† b.1 := by exact (value_smul S e2 hAut g Ο† b.1).symm have hv' : Form.value S e2 Ο† a'.1 = g β€’ Form.value S e2 Ο† a.1 := by rw [←ha] exact (value_smul S e2 hAut g Ο† a.1).symm apply Fintype.card_congr apply f.subtypeEquiv intro b rw [hv,hv'] exact (MulAction.injective g).eq_iff.symm include hAut in omit [Fintype I] in private theorem label_orbit (hHom : βˆ€ a b : P βŠ• Fin s β†’ A, tupleType S ep a = tupleType S ep b β†’ βˆƒ g : G, βˆ€ i, g β€’ a i = b i) (Ο† : Form (Fin s) (Set (Formula R I))) (x y : HF A) (hx : x ∈ labelValues S ep e2 p Ο„ Ο†) (hy : y ∈ labelValues S ep e2 p Ο„ Ο†) : βˆƒ g : G, (βˆ€ i, g β€’ p i = p i) ∧ g β€’ x = y := by obtain ⟨a,rfl⟩ := hx obtain ⟨b,rfl⟩ := hy obtain ⟨g,hg⟩ := hHom (Sum.elim p a.1) (Sum.elim p b.1) (a.2.trans b.2.symm) refine ⟨g,fun i => hg (.inl i),?_⟩ rw [value_smul S e2 hAut] exact congrArg (Form.value S e2 Ο†) (funext (fun i => hg (.inr i))) include hAut in omit [Fintype I] in private theorem label_smul_mem (g : G) (hp : βˆ€ i, g β€’ p i = p i) (Ο† : Form (Fin s) (Set (Formula R I))) (x : HF A) (hx : x ∈ labelValues S ep e2 p Ο„ Ο†) : g β€’ x ∈ labelValues S ep e2 p Ο„ Ο† := by obtain ⟨a,rfl⟩ := hx refine ⟨moleculesPerm S ep hAut p Ο„ g hp a,?_⟩ exact (value_smul S e2 hAut g Ο† a.1).symm include hAut in omit [Fintype I] in theorem label_partition (hHom : βˆ€ a b : P βŠ• Fin s β†’ A, tupleType S ep a = tupleType S ep b β†’ βˆƒ g : G, βˆ€ i, g β€’ a i = b i) (Ο† ψ : Form (Fin s) (Set (Formula R I))) (Οƒ : Set (Formula R I)) (x : HF A) (hx : x ∈ labelValues S ep e2 p Ο„ Ο†) (hx' : x ∈ labelValues S ep e2 p Οƒ ψ) : labelValues S ep e2 p Ο„ Ο† = labelValues S ep e2 p Οƒ ψ := by ext y constructor Β· intro hy obtain ⟨g,hp,hg⟩ := label_orbit S ep e2 hAut p Ο„ hHom Ο† x y hx hy rw [←hg] exact label_smul_mem S ep e2 hAut p Οƒ g hp ψ x hx' Β· intro hy obtain ⟨g,hp,hg⟩ := label_orbit S ep e2 hAut p Οƒ hHom ψ x y hx' hy rw [←hg] exact label_smul_mem S ep e2 hAut p Ο„ g hp Ο† x hx end Group variable (S : Structure R A) (T : Structure R B) variable (ep : P βŠ• Fin s β†ͺ I) (epp : (P βŠ• Fin s) βŠ• Fin s β†ͺ I) variable (e2 : Fin s βŠ• Fin s β†ͺ I) variable (e3 : (Fin s βŠ• Fin s) βŠ• Fin s β†ͺ I) variable (e4 : ((Fin s βŠ• Fin s) βŠ• Fin s) βŠ• Fin s β†ͺ I) private def skipMiddle : P βŠ• Fin s β†ͺ (P βŠ• Fin s) βŠ• Fin s := Function.Embedding.sumMap Function.Embedding.inl (Function.Embedding.refl _) private def lastTwo : Fin s βŠ• Fin s β†ͺ (P βŠ• Fin s) βŠ• Fin s := Function.Embedding.sumMap Function.Embedding.inr (Function.Embedding.refl _) omit [Fintype A] [Nonempty A] [Fintype P] in @[simp] private theorem elim_skipMiddle (p : P β†’ A) (a b : Fin s β†’ A) : (Sum.elim (Sum.elim p a) b) ∘ skipMiddle = Sum.elim p b := by funext j; cases j <;> rfl omit [Fintype A] [Nonempty A] [Fintype P] in @[simp] private theorem elim_lastTwo (p : P β†’ A) (a b : Fin s β†’ A) : (Sum.elim (Sum.elim p a) b) ∘ lastTwo = Sum.elim a b := by funext j; cases j <;> rfl include epp e3 e4 in theorem value_fiber_equiv (p : P β†’ A) (q : P β†’ B) (Ο„ : Set (Formula R I)) (Ο† : Form (Fin s) (Set (Formula R I))) (a : Molecules S ep p Ο„) (a' : Molecules T ep q Ο„) : Nonempty ({b : Molecules S ep p Ο„ // Form.value S e2 Ο† b.1 = Form.value S e2 Ο† a.1} ≃ {b : Molecules T ep q Ο„ // Form.value T e2 Ο† b.1 = Form.value T e2 Ο† a'.1}) := by obtain ⟨f,hf⟩ := tupleType_append_bijection S T ep epp (Sum.elim p a.1) (Sum.elim q a'.1) (a.2.trans a'.2.symm) have htype (b : Fin s β†’ A) : tupleType S ep (Sum.elim p b) = tupleType T ep (Sum.elim q (f b)) := by have hh := tupleType_project S T epp ep skipMiddle _ _ (hf b) simpa only [elim_skipMiddle] using hh have hval (b : Fin s β†’ A) : Form.value S e2 Ο† b = Form.value S e2 Ο† a.1 ↔ Form.value T e2 Ο† (f b) = Form.value T e2 Ο† a'.1 := by have hh := tupleType_project S T epp e2 lastTwo _ _ (hf b) simp only [elim_lastTwo] at hh simpa only [eq_comm] using equality_transfer S T e2 e3 e4 Ο† Ο† a.1 b a'.1 (f b) hh let F : {b : Fin s β†’ A // tupleType S ep (Sum.elim p b) = Ο„ ∧ Form.value S e2 Ο† b = Form.value S e2 Ο† a.1} ≃ {b : Fin s β†’ B // tupleType T ep (Sum.elim q b) = Ο„ ∧ Form.value T e2 Ο† b = Form.value T e2 Ο† a'.1} := f.subtypeEquiv (fun b => show (tupleType S ep (Sum.elim p b) = Ο„ ∧ Form.value S e2 Ο† b = Form.value S e2 Ο† a.1) ↔ (tupleType T ep (Sum.elim q (f b)) = Ο„ ∧ Form.value T e2 Ο† (f b) = Form.value T e2 Ο† a'.1) from and_congr (by rw [htype b]) (hval b)) exact ⟨(Equiv.subtypeSubtypeEquivSubtypeInter _ _).trans (F.trans (Equiv.subtypeSubtypeEquivSubtypeInter _ _).symm)⟩ include epp e3 e4 in theorem label_overlap_transfer (e0 : P β†ͺ I) (p : P β†’ A) (q : P β†’ B) (hp : tupleType S e0 p = tupleType T e0 q) (Ο† ψ : Form (Fin s) (Set (Formula R I))) (Ο„ Οƒ : Set (Formula R I)) (hx : βˆƒ x, x ∈ labelValues S ep e2 p Ο„ Ο† ∧ x ∈ labelValues S ep e2 p Οƒ ψ) : βˆƒ y, y ∈ labelValues T ep e2 q Ο„ Ο† ∧ y ∈ labelValues T ep e2 q Οƒ ψ := by obtain ⟨x,⟨a,ha⟩,⟨b,hb⟩⟩ := hx obtain ⟨a',ha'⟩ := tupleType_append S T e0 ep p q a.1 hp obtain ⟨b',hb'⟩ := tupleType_append S T ep epp (Sum.elim p a.1) (Sum.elim q a') b.1 ha' have ht := tupleType_project S T epp ep skipMiddle _ _ hb' simp only [elim_skipMiddle] at ht have he := tupleType_project S T epp e2 lastTwo _ _ hb' simp only [elim_lastTwo] at he have hv := (equality_transfer S T e2 e3 e4 Ο† ψ a.1 b.1 a' b' he).mp (ha.trans hb.symm) refine ⟨Form.value T e2 Ο† a',?_,?_⟩ Β· exact ⟨⟨a',ha'.symm.trans a.2⟩,rfl⟩ Β· exact ⟨⟨b',ht.symm.trans b.2⟩,hv.symm⟩ include epp e3 e4 in theorem label_values_card {G H : Type*} [Group G] [MulAction G A] [Group H] [MulAction H B] (hAutA : βˆ€ (g : G) r a b, S.rel r (g β€’ a) (g β€’ b) ↔ S.rel r a b) (hAutB : βˆ€ (g : H) r a b, T.rel r (g β€’ a) (g β€’ b) ↔ T.rel r a b) (hHomA : βˆ€ a b : P βŠ• Fin s β†’ A, tupleType S ep a = tupleType S ep b β†’ βˆƒ g : G, βˆ€ i, g β€’ a i = b i) (hHomB : βˆ€ a b : P βŠ• Fin s β†’ B, tupleType T ep a = tupleType T ep b β†’ βˆƒ g : H, βˆ€ i, g β€’ a i = b i) (p : P β†’ A) (q : P β†’ B) (Ο„ : Set (Formula R I)) (Ο† : Form (Fin s) (Set (Formula R I))) (a : Molecules S ep p Ο„) (a' : Molecules T ep q Ο„) : Nat.card (labelValues S ep e2 p Ο„ Ο†) = Nat.card (labelValues T ep e2 q Ο„ Ο†) := by let va : Molecules S ep p Ο„ β†’ HF A := fun b => Form.value S e2 Ο† b.1 let vb : Molecules T ep q Ο„ β†’ HF B := fun b => Form.value T e2 Ο† b.1 have ha := range_card_mul_fiber va a (fun b => by simpa only [←Nat.card_eq_fintype_card] using uniform_value_fibers S ep e2 hAutA p Ο„ hHomA Ο† b a) have hb := range_card_mul_fiber vb a' (fun b => by simpa only [←Nat.card_eq_fintype_card] using uniform_value_fibers T ep e2 hAutB q Ο„ hHomB Ο† b a') let e0 := Function.Embedding.inl.trans ep have hp := tupleType_project S T ep e0 Function.Embedding.inl (Sum.elim p a.1) (Sum.elim q a'.1) (a.2.trans a'.2.symm) change tupleType S e0 p = tupleType T e0 q at hp obtain ⟨f⟩ := tupleType_extension_equiv S T e0 ep p q hp Ο„ have hn : Fintype.card (Molecules S ep p Ο„) = Fintype.card (Molecules T ep q Ο„) := Fintype.card_congr f obtain ⟨fv⟩ := value_fiber_equiv S T ep epp e2 e3 e4 p q Ο„ Ο† a a' have he : Nat.card {b // va b = va a} = Nat.card {b // vb b = vb a'} := Nat.card_congr fv have hpos : 0 < Nat.card {b // va b = va a} := by rw [Nat.card_eq_fintype_card] exact Fintype.card_pos_iff.mpr ⟨⟨a,rfl⟩⟩ have hc := ha.symm.trans (hn.trans hb) rw [←he] at hc have hh := Nat.eq_of_mul_eq_mul_right hpos hc simpa only [←Nat.card_eq_fintype_card,labelValues,va,vb] using hh end end WitnessedSeparation.Forms namespace WitnessedSeparation noncomputable section open Classical private def cellSetoid {L X : Type*} (C : L β†’ Set X) : Setoid L := ⟨fun l k => C l = C k,⟨fun _ => rfl,Eq.symm,Eq.trans⟩⟩ theorem glue_finite_cells {L X Y : Type*} (C : L β†’ Set X) (D : L β†’ Set Y) (coverC : βˆ€ x, βˆƒ l, x ∈ C l) (coverD : βˆ€ y, βˆƒ l, y ∈ D l) (partC : βˆ€ l k x, x ∈ C l β†’ x ∈ C k β†’ C l = C k) (partD : βˆ€ l k y, y ∈ D l β†’ y ∈ D k β†’ D l = D k) (same : βˆ€ l k, C l = C k ↔ D l = D k) (finC : βˆ€ l, (C l).Finite) (finD : βˆ€ l, (D l).Finite) (card : βˆ€ l, Nat.card (C l) = Nat.card (D l)) : βˆƒ f : X ≃ Y, βˆ€ x, βˆƒ l, x ∈ C l ∧ f x ∈ D l := by let Q := Quotient (cellSetoid C) let lc : X β†’ L := fun x => (coverC x).choose let ld : Y β†’ L := fun y => (coverD y).choose have hc (x : X) : x ∈ C (lc x) := (coverC x).choose_spec have hd (y : Y) : y ∈ D (ld y) := (coverD y).choose_spec let c : X β†’ Q := fun x => Quotient.mk _ (lc x) let d : Y β†’ Q := fun y => Quotient.mk _ (ld y) have ce (x : X) (q : Q) : c x = q ↔ x ∈ C q.out := by constructor Β· intro h have he : C (lc x) = C q.out := Quotient.exact (h.trans (Quotient.out_eq q).symm) rw [←he]; exact hc x Β· intro h have he := partC (lc x) q.out x (hc x) h exact (Quotient.sound he).trans (Quotient.out_eq q) have de (y : Y) (q : Q) : d y = q ↔ y ∈ D q.out := by constructor Β· intro h have he : C (ld y) = C q.out := Quotient.exact (h.trans (Quotient.out_eq q).symm) rw [←(same _ _).mp he]; exact hd y Β· intro h have he := (same _ _).mpr (partD (ld y) q.out y (hd y) h) exact (Quotient.sound he).trans (Quotient.out_eq q) have ef (q : Q) : Nonempty ({x // c x = q} ≃ {y // d y = q}) := by let := (finC q.out).fintype let := (finD q.out).fintype have hcard : Fintype.card (C q.out) = Fintype.card (D q.out) := by simpa only [Nat.card_eq_fintype_card] using card q.out let e := Fintype.equivOfCardEq hcard exact ⟨(Equiv.subtypeEquivRight (fun x => ce x q)).trans (e.trans (Equiv.subtypeEquivRight (fun y => de y q)).symm)⟩ let F := Equiv.ofFiberEquiv (fun q => Classical.choice (ef q)) refine ⟨F,fun x => ⟨(c x).out,(ce x (c x)).mp rfl,?_⟩⟩ apply (de (F x) (c x)).mp exact Equiv.ofFiberEquiv_map _ x end end WitnessedSeparation end OAI
import OAI.Computability.WitnessedChoice.Homogeneity
namespace OAI
namespace WitnessedSeparation.Grid
noncomputable section
open Classical Finset
variable {n M : β„•} {b b' : Vertex n β†’ Scalar}
theorem boundary_eq_incidence : (boundary : (Edge n β†’ Scalar) β†’β‚—[Scalar] (Vertex n β†’ Scalar)) =
Flows.incidence tail head := rfl
def GiantBound (n M : β„•) : Prop :=
((12*(M:ℝ))/boxConstant)^((3:ℝ)/2) < ((n+1)^3:β„•)
theorem giant_exists_of_bound (hbound : GiantBound n M) (T : Finset (Edge n)) (hT : T.card ≀ 6*M) :
βˆƒ v, Flows.IsGiant tail head T v := by
have hnum : ((2*T.card:ℝ)/boxConstant)^((3:ℝ)/2) < ((n+1)^3:β„•) := by
apply lt_of_le_of_lt _ hbound
apply Real.rpow_le_rpow (div_nonneg (by positivity) boxConstant_pos.le) _ (by norm_num)
apply div_le_div_of_nonneg_right _ boxConstant_pos.le
have hh : (T.card:ℝ) ≀ 6*M := by exact_mod_cast hT
linarith
obtain ⟨c,hc⟩ := exists_giant T hnum
refine ⟨c.out,?_⟩
change Fintype.card (Vertex n) < 2*(Flows.cell tail head T c).card
have hcard : Fintype.card (Vertex n) = (n+1)^3 := by
simp only [Vertex,Fintype.card_prod,Fintype.card_fin]; ring
simpa only [hcard] using hc
theorem defect_transport (hbound : GiantBound n M) (T U : Finset (Edge n)) (hTU : T βŠ† U)
(hU : U.card ≀ 6*M) (t : Edge n β†’ Scalar) (w : Vertex n)
(hw : Flows.IsGiant tail head T w) (ht : boundary t = b'-b-Pi.single w 1) :
βˆƒ t' : Edge n β†’ Scalar, βˆƒ w' : Vertex n,
Flows.IsGiant tail head U w' ∧ boundary t' = b'-b-Pi.single w' 1 ∧ βˆ€ e ∈ T, t' e = t e := by
obtain ⟨w',hw'⟩ := giant_exists_of_bound hbound U hU
have hc := Flows.giants_connected tail head (Flows.giant_mono tail head hTU hw') hw
obtain ⟨p,hp,hd⟩ := Flows.path_flow tail head T hc
refine ⟨t+p,w',hw',?_,?_⟩
Β· rw [map_add,ht,boundary_eq_incidence,hd]
abel
Β· intro e he; simp [hp e he]
def CompatibleAssignment {I : Type*} [DecidableEq I] (names : Finset I)
(a : I β†’ Atom b) (a' : I β†’ Atom b') : Prop :=
βˆƒ t : Edge n β†’ Scalar, βˆƒ w : Vertex n,
Flows.IsGiant tail head (touches names a) w ∧ boundary t = b'-b-Pi.single w 1 ∧
βˆ€ i ∈ names, AtomShift t (a i) (a' i)
theorem CompatibleAssignment.mono {I : Type*} [DecidableEq I] {names small : Finset I}
(hs : small βŠ† names) {a : I β†’ Atom b} {a' : I β†’ Atom b'}
(h : CompatibleAssignment names a a') : CompatibleAssignment small a a' := by
obtain ⟨t,w,hw,ht,ha⟩ := h
exact ⟨t,w,Flows.giant_mono tail head (touches_mono hs a) hw,ht,fun i hi => ha i (hs hi)⟩
theorem CompatibleAssignment.extend (hn : 1 ≀ n) (hbound : GiantBound n M)
(names : Finset (Fin M)) (a : Fin M β†’ Atom b) (a' : Fin M β†’ Atom b')
(h : CompatibleAssignment names a a') (i : Fin M) :
βˆƒ e : Atom b ≃ Atom b', βˆ€ x,
CompatibleAssignment (insert i (names.erase i)) (Function.update a i x) (Function.update a' i (e x)) := by
obtain ⟨t,w,hw,ht,ha⟩ := h.mono (erase_subset i names)
let T := touches (names.erase i) a
have hcard : (names.erase i).card + 1 ≀ M := by
have hsub : names.erase i βŠ† (univ : Finset (Fin M)).erase i := erase_subset_erase i (subset_univ _)
have hh := card_le_card hsub
have hpos := i.isLt
rw [card_erase_of_mem (mem_univ _),card_univ,Fintype.card_fin] at hh
omega
have hj (J : Block n) : (T βˆͺ blockEdges J).card ≀ 6*M := by
calc
_ ≀ T.card + (blockEdges J).card := card_union_le _ _
_ ≀ 6*(names.erase i).card + 6 := Nat.add_le_add (touches_card _ _) (blockEdges_card _)
_ ≀ 6*M := by omega
have hmove (J : Block n) := defect_transport hbound T (T βˆͺ blockEdges J)
subset_union_left (hj J) t w hw ht
choose tj wj hjg hjd hjs using hmove
have hV : 2 ≀ Fintype.card (Vertex n) := by
have hc : Fintype.card (Vertex n) = (n+1)^3 := by
simp only [Vertex,Fintype.card_prod,Fintype.card_fin]; ring
rw [hc]
have hh : 2^3 ≀ (n+1)^3 := Nat.pow_le_pow_left (by omega) 3
omega
have hv (v : Vertex n) : boundary (tj (.inr v)) v = b' v-b v := by
have hwv : wj (.inr v) β‰  v := Flows.giant_ne_isolated tail head hV (hjg (.inr v)) (by
intro e he
exact mem_union_right _ (by simpa [blockEdges,incident,or_comm] using he))
have hh := congrFun (hjd (.inr v)) v
simpa [Pi.single_apply,Ne.symm hwv] using hh
let e := blockShiftEquiv (fun e => tj (.inl e)) (fun v => tj (.inr v)) hv
refine ⟨e,fun x => ?_⟩
let J := atomBlock x
refine ⟨tj J,wj J,?_,hjd J,?_⟩
Β· rw [touches_insert_update]
exact hjg J
Β· intro j hj'
rcases mem_insert.mp hj' with rfl | hj'