introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
9.37 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Reduction.OccurrenceTuple
namespace OAI
namespace LargeIndependentSets
open scoped Classical BigOperators
@[ext] structure SubchainView (U V L R : Type*) (n : β„•) (I : Finset (Fin (n+1))) where
question : βˆ€ j : I, MixedTuple U V n j.val.val
projection : βˆ€ i j : I, i.val ≀ j.val β†’
MixedTuple L R n i.val.val β†’ MixedTuple L R n j.val.val
def chainView {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} (c : Fin n β†’ C) (I : Finset (Fin (n+1))) : SubchainView U V L R n I where
question j := occurrenceTuple lc c j.val.val
projection i j hij := chainComposite lc c i.val.val j.val.val hij
lemma occurrenceTuple_local_left {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} {c c' : Fin n β†’ C} (h : Fin n)
(hout : βˆ€ k, k β‰  h β†’ c k = c' k) (hown : lc.left (c h) = lc.left (c' h))
{i : β„•} (hi : i ≀ h.val) : occurrenceTuple lc c i = occurrenceTuple lc c' i := by
apply Subtype.ext; funext k
by_cases hk : k = h
Β· subst k; simp [occurrenceTuple, show Β¬ h.val < i by omega, hown]
Β· simp [occurrenceTuple, hout k hk]
lemma occurrenceTuple_local_right {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} {c c' : Fin n β†’ C} (h : Fin n)
(hout : βˆ€ k, k β‰  h β†’ c k = c' k) (hown : lc.right (c h) = lc.right (c' h))
{i : β„•} (hi : h.val < i) : occurrenceTuple lc c i = occurrenceTuple lc c' i := by
apply Subtype.ext; funext k
by_cases hk : k = h
Β· subst k; simp [occurrenceTuple, hi, hown]
Β· simp [occurrenceTuple, hout k hk]
lemma chainComposite_local {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} {c c' : Fin n β†’ C} (h : Fin n)
(hout : βˆ€ k, k β‰  h β†’ c k = c' k) {i j : β„•} (hij : i ≀ j)
(haway : j ≀ h.val ∨ h.val < i) :
chainComposite lc c i j hij = chainComposite lc c' i j hij := by
funext x; apply Subtype.ext; funext k
by_cases hk : k = h
Β· subst k
have hh : Β¬(i ≀ h.val ∧ h.val < j) := by omega
simp [chainComposite, hh]
Β· simp [chainComposite, hout k hk]
lemma chainView_local_left {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} {c c' : Fin n β†’ C} (h : Fin n)
(hout : βˆ€ k, k β‰  h β†’ c k = c' k) (hown : lc.left (c h) = lc.left (c' h))
(I : Finset (Fin (n+1))) (hI : βˆ€ i ∈ I, i.val ≀ h.val) :
chainView lc c I = chainView lc c' I := by
apply SubchainView.ext
Β· funext i; exact occurrenceTuple_local_left lc h hout hown (hI i.val i.property)
Β· funext i j hij
exact chainComposite_local lc h hout hij (Or.inl (hI j.val j.property))
lemma chainView_local_right {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} {c c' : Fin n β†’ C} (h : Fin n)
(hout : βˆ€ k, k β‰  h β†’ c k = c' k) (hown : lc.right (c h) = lc.right (c' h))
(I : Finset (Fin (n+1))) (hI : βˆ€ i ∈ I, h.val < i.val) :
chainView lc c I = chainView lc c' I := by
apply SubchainView.ext
Β· funext i; exact occurrenceTuple_local_right lc h hout hown (hI i.val i.property)
Β· funext i j hij
exact chainComposite_local lc h hout hij (Or.inr (hI i.val i.property))
abbrev SubchainCoord (L R : Type*) (n : β„•) (I : Finset (Fin (n+1))) :=
Ξ£ j : I, MixedTuple L R n j.val.val
noncomputable def leftEntry {L R : Type*} [Nonempty L] {n i : β„•}
(h : Fin n) (x : MixedTuple L R n i) : L := (x.val h).elim (fun _ => Classical.arbitrary L) id
noncomputable def rightEntry {L R : Type*} [Nonempty R] {n i : β„•}
(h : Fin n) (x : MixedTuple L R n i) : R := (x.val h).elim id (fun _ => Classical.arbitrary R)
lemma leftEntry_spec {L R : Type*} [Nonempty L] {n i : β„•}
(h : Fin n) (x : MixedTuple L R n i) (hi : i ≀ h.val) :
x.val h = Sum.inr (leftEntry h x) := by
have hp := x.property h
simp only [show Β¬h.val < i by omega, decide_false] at hp
unfold leftEntry
cases he : x.val h <;> simp_all
lemma rightEntry_spec {L R : Type*} [Nonempty R] {n i : β„•}
(h : Fin n) (x : MixedTuple L R n i) (hi : h.val < i) :
x.val h = Sum.inl (rightEntry h x) := by
have hp := x.property h
simp only [hi, decide_true] at hp
unfold rightEntry
cases he : x.val h <;> simp_all
noncomputable def terminalList {U V L R C : Type*} (lc : LabelCoverData U V L R C)
{n : β„•} (c : Fin n β†’ C) (I : Finset (Fin (n+1)))
(S : Finset (SubchainCoord L R n I)) : Finset (MixedTuple L R n n) :=
S.image (fun x => chainComposite lc c x.1.val.val n (by have := x.1.val.isLt; omega) x.2)
lemma terminal_intersection_decodes {U V L R C : Type*} [Nonempty L] [Nonempty R]
(lc : LabelCoverData U V L R C) {n : β„•} (c : Fin n β†’ C) (h : Fin n)
(I J : Finset (Fin (n+1))) (hI : βˆ€ i ∈ I, i.val ≀ h.val)
(hJ : βˆ€ j ∈ J, h.val < j.val)
(S : Finset (SubchainCoord L R n I)) (S' : Finset (SubchainCoord L R n J))
(hinter : Β¬ Disjoint (terminalList lc c I S) (terminalList lc c J S')) :
βˆƒ l ∈ S.image (fun x => leftEntry h x.2),
βˆƒ r ∈ S'.image (fun x => rightEntry h x.2), lc.project (c h) l = r := by
obtain ⟨z,hz,hz'⟩ := Finset.not_disjoint_iff.mp hinter
obtain ⟨x,hx,he⟩ := Finset.mem_image.mp hz
obtain ⟨y,hy,he'⟩ := Finset.mem_image.mp hz'
refine ⟨leftEntry h x.2, Finset.mem_image.mpr ⟨x,hx,rfl⟩,
rightEntry h y.2, Finset.mem_image.mpr ⟨y,hy,rfl⟩,?_⟩
have hp := congrArg (fun z : MixedTuple L R n n => z.val h) (he.trans he'.symm)
have hix := hI x.1.val x.1.property
have hjy := hJ y.1.val y.1.property
simp only [chainComposite, hix, h.isLt, and_self, ite_true,
show Β¬ y.1.val.val ≀ h.val by omega, false_and, ite_false,
leftEntry_spec h x.2 hix, rightEntry_spec h y.2 hjy, Sum.elim_inr] at hp
exact Sum.inl.inj hp
noncomputable def ownQuestionList {C U X : Type*} (q : C β†’ U) (f : C β†’ Finset X)
(u : U) : Finset X :=
if h : βˆƒ c, q c = u then f h.choose else βˆ…
lemma ownQuestionList_apply {C U X : Type*} (q : C β†’ U) (f : C β†’ Finset X)
(hf : βˆ€ c c', q c = q c' β†’ f c = f c') (c : C) :
ownQuestionList q f (q c) = f c := by
simp only [ownQuestionList, dite_eq_left (show βˆƒ c', q c' = q c from ⟨c,rfl⟩)]
exact hf _ _ (Exists.choose_spec (show βˆƒ c', q c' = q c from ⟨c,rfl⟩))
lemma ownQuestionList_card {C U X : Type*} (q : C β†’ U) (f : C β†’ Finset X)
{d : β„•} (hf : βˆ€ c, (f c).card ≀ d) (u : U) :
(ownQuestionList q f u).card ≀ d := by
unfold ownQuestionList; split_ifs <;> simp_all
theorem separated_lists_conditioned {U V L R C : Type*}
[Fintype C] [Nonempty L] [Nonempty R]
(lc : LabelCoverData U V L R C) {Οƒ : ℝ} (hsound : lc.Sound Οƒ)
{n : β„•} (background : Fin n β†’ C) (h : Fin n)
(I J : Finset (Fin (n+1))) (hI : βˆ€ i ∈ I, i.val ≀ h.val)
(hJ : βˆ€ j ∈ J, h.val < j.val) (d : β„•)
(ruleI : SubchainView U V L R n I β†’ Finset (SubchainCoord L R n I))
(ruleJ : SubchainView U V L R n J β†’ Finset (SubchainCoord L R n J))
(hcardI : βˆ€ v, (ruleI v).card ≀ d) (hcardJ : βˆ€ v, (ruleJ v).card ≀ d) :
((Finset.univ.filter (fun c : C =>
let chain := Function.update background h c
Β¬ Disjoint (terminalList lc chain I (ruleI (chainView lc chain I)))
(terminalList lc chain J (ruleJ (chainView lc chain J))))).card : ℝ) ≀
(d : ℝ)^2 * Οƒ * Fintype.card C := by
let chain := fun c => Function.update background h c
let lefts := fun c => (ruleI (chainView lc (chain c) I)).image (fun x => leftEntry h x.2)
let rights := fun c => (ruleJ (chainView lc (chain c) J)).image (fun x => rightEntry h x.2)
have hout (c c' : C) (k : Fin n) (hk : k β‰  h) : chain c k = chain c' k := by
simp [chain, Function.update_of_ne hk]
have hleft (c c' : C) (he : lc.left c = lc.left c') : lefts c = lefts c' := by
have hv := chainView_local_left lc h (hout c c') (by simpa [chain] using he) I hI
simp only [lefts, hv]
have hright (c c' : C) (he : lc.right c = lc.right c') : rights c = rights c' := by
have hv := chainView_local_right lc h (hout c c') (by simpa [chain] using he) J hJ
simp only [rights, hv]
let A := ownQuestionList lc.left lefts
let B := ownQuestionList lc.right rights
have hA (u) : (A u).card ≀ d :=
ownQuestionList_card _ _ (fun c => Finset.card_image_le.trans (hcardI _)) u
have hB (v) : (B v).card ≀ d :=
ownQuestionList_card _ _ (fun c => Finset.card_image_le.trans (hcardJ _)) v
have hcover : Finset.univ.filter (fun c : C =>
Β¬Disjoint (terminalList lc (chain c) I (ruleI (chainView lc (chain c) I)))
(terminalList lc (chain c) J (ruleJ (chainView lc (chain c) J)))) βŠ†
Finset.univ.filter (fun c => βˆƒ l ∈ A (lc.left c), βˆƒ r ∈ B (lc.right c), lc.project c l = r) := by
intro c hc
have hd := terminal_intersection_decodes lc (chain c) h I J hI hJ _ _
(Finset.mem_filter.mp hc).2
apply Finset.mem_filter.mpr
refine ⟨Finset.mem_univ _,?_⟩
change βˆƒ l ∈ ownQuestionList lc.left lefts (lc.left c),
βˆƒ r ∈ ownQuestionList lc.right rights (lc.right c), lc.project c l = r
rw [ownQuestionList_apply _ _ hleft, ownQuestionList_apply _ _ hright]
simpa only [chain, Function.update_self] using hd
exact (show (_ : ℝ) ≀ _ from Nat.cast_le.mpr (Finset.card_le_card hcover)).trans
(bounded_list_decoding lc hsound d A B hA hB)
end LargeIndependentSets
end OAI