math / data /lean /OAI /Combinatorics /IndependentSets /PCP /LabelCoverData.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
17.9 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Reduction.WalkLength
namespace OAI
namespace LargeIndependentSets
open scoped ENNReal NNReal
structure LabelCoverData (U V L R C : Type*) where
left : C β†’ U
right : C β†’ V
project : C β†’ L β†’ R
def LabelCoverData.Satisfied {U V L R C : Type*} (lc : LabelCoverData U V L R C)
(β„“ : U β†’ L) (ρ : V β†’ R) : Prop :=
βˆ€ c, lc.project c (β„“ (lc.left c)) = ρ (lc.right c)
def MixedTuple (A B : Type*) (n i : β„•) :=
{x : Fin n β†’ B βŠ• A // βˆ€ h, (x h).isLeft = decide (h.val < i)}
noncomputable def MixedTuple.map {A B A' B' : Type*} {n i : β„•}
(l : A β†’ A') (r : B β†’ B') (x : MixedTuple A B n i) : MixedTuple A' B' n i :=
⟨fun h => Sum.map r l (x.val h), by
intro h
simpa only [Sum.isLeft_map] using x.property h⟩
def mixedProject {L R : Type*} {n : β„•} (h : Fin n) (Ο€ : L β†’ R)
(x : MixedTuple L R n h.val) : MixedTuple L R n (h.val + 1) :=
⟨fun k => if k = h then Sum.inl ((x.val k).elim id Ο€) else x.val k, by
intro k
by_cases hk : k = h
Β· subst k
simp
Β· simp only [ite_eq_right hk, x.property k]
have hne : k.val β‰  h.val := fun e => hk (Fin.ext e)
have he : (k.val < h.val) = (k.val < h.val + 1) := propext (by omega)
simp only [he]⟩
abbrev LayerQuestion (U V : Type*) (n : β„•) :=
Ξ£ i : Fin (n + 1), MixedTuple U V n i.val
abbrev LayerAnswer {U V : Type*} (L R : Type*) {n : β„•}
(q : LayerQuestion U V n) := MixedTuple L R n q.1.val
inductive LayerImposed {U V L R C : Type*} (lc : LabelCoverData U V L R C) (n : β„•) :
(q q' : LayerQuestion U V n) β†’ (LayerAnswer L R q β†’ LayerAnswer L R q') β†’ Prop
| adjacent (h : Fin n) (q : MixedTuple U V n h.val)
(q' : MixedTuple U V n (h.val + 1)) (c : C)
(hleft : q.val h = Sum.inr (lc.left c))
(hright : q'.val h = Sum.inl (lc.right c))
(houtside : βˆ€ k, k β‰  h β†’ q.val k = q'.val k) :
LayerImposed lc n ⟨h.castSucc, q⟩ ⟨h.succ, q'⟩ (mixedProject h (lc.project c))
def layeredSystem {U V L R C : Type*} (lc : LabelCoverData U V L R C) (n : β„•) :
ProjectionSystem (LayerQuestion U V n) (LayerAnswer L R) where
imposed := LayerImposed lc n
noncomputable def productLabeling {U V L R : Type*} {n : β„•}
(β„“ : U β†’ L) (ρ : V β†’ R) (q : LayerQuestion U V n) : LayerAnswer L R q :=
MixedTuple.map β„“ ρ q.2
theorem productLabeling_consistent {U V L R C : Type*}
(lc : LabelCoverData U V L R C) (n : β„•) (β„“ : U β†’ L) (ρ : V β†’ R)
(hsat : lc.Satisfied β„“ ρ) :
(layeredSystem lc n).Consistent (productLabeling β„“ ρ) := by
intro q q' Ο€ hΟ€
cases hΟ€ with
| adjacent h q q' c hleft hright houtside =>
apply Subtype.ext
funext k
by_cases hk : k = h
Β· subst k
simp [mixedProject, productLabeling, MixedTuple.map,
hleft, hright, hsat c]
Β· simp only [mixedProject, productLabeling, MixedTuple.map, ite_eq_right hk,
houtside k hk]
theorem layered_completeness {U V L R C : Type*}
(lc : LabelCoverData U V L R C) (n : β„•) (β„“ : U β†’ L) (ρ : V β†’ R)
(hsat : lc.Satisfied β„“ ρ) {D : β„•} [NeZero D] (hD : Even D) :
(βˆ€ x : GridLocation (LayerAnswer L R (U := U) (V := V) (n := n)) D,
Β¬pathDistance (layeredSystem lc n).linkLength x (gridAntipode x) ≀
ENNReal.ofReal (1 / 8)) ∧
(βˆ€ (W : Type*) (location : W β†’ GridLocation (LayerAnswer L R
(U := U) (V := V) (n := n)) D),
βˆƒ color : W β†’ Fin 3, βˆ€ u v, (gridGraph (layeredSystem lc n) hD location).Adj u v β†’
color u β‰  color v) := by
have h := productLabeling_consistent lc n β„“ ρ hsat
exact ⟨(projection_grid_completeness.{_, _, 0} (layeredSystem lc n) hD _ h).1,
fun W location => gridGraph_three_coloring (layeredSystem lc n) hD _ h location⟩
noncomputable def distanceBump (d : ℝβ‰₯0∞) : ℝ :=
if d = ⊀ then 0 else max (1 - 32 * d.toReal) 0
lemma distanceBump_bounds (d : ℝβ‰₯0∞) : 0 ≀ distanceBump d ∧ distanceBump d ≀ 1 := by
unfold distanceBump
split_ifs
Β· norm_num
· refine ⟨le_max_right _ _, max_le ?_ (by norm_num)⟩
have := ENNReal.toReal_nonneg (a := d)
linarith
@[simp] lemma distanceBump_zero : distanceBump 0 = 1 := by
norm_num [distanceBump]
lemma distanceBump_vanish {d : ℝβ‰₯0∞} (hd : ENNReal.ofReal (1 / 32) ≀ d) :
distanceBump d = 0 := by
unfold distanceBump
split_ifs with htop
Β· rfl
Β· have hr := ENNReal.toReal_mono htop hd
norm_num at hr
exact max_eq_right (by linarith)
lemma distanceBump_difference {a b c : ℝβ‰₯0∞} (hc : c β‰  ⊀)
(hab : a ≀ c + b) (hba : b ≀ c + a) :
|distanceBump a - distanceBump b| ≀ 32 * c.toReal := by
by_cases ha : a = ⊀
· by_cases hb : b = ⊀
Β· simp only [distanceBump, ha, hb, ite_eq_left, sub_self, abs_zero]
exact mul_nonneg (by norm_num) ENNReal.toReal_nonneg
Β· have htop : c + b = ⊀ := top_le_iff.mp (ha β–Έ hab)
exact False.elim ((ENNReal.add_ne_top.mpr ⟨hc, hb⟩) htop)
· by_cases hb : b = ⊀
Β· have htop : c + a = ⊀ := top_le_iff.mp (hb β–Έ hba)
exact False.elim ((ENNReal.add_ne_top.mpr ⟨hc, ha⟩) htop)
· have har := (ENNReal.toReal_le_toReal ha (ENNReal.add_ne_top.mpr ⟨hc, hb⟩)).mpr hab
have hbr := (ENNReal.toReal_le_toReal hb (ENNReal.add_ne_top.mpr ⟨hc, ha⟩)).mpr hba
rw [ENNReal.toReal_add hc hb] at har
rw [ENNReal.toReal_add hc ha] at hbr
simp only [distanceBump, ite_eq_right ha, ite_eq_right hb]
calc
_ ≀ max |(1 - 32 * a.toReal) - (1 - 32 * b.toReal)| |(0 : ℝ) - 0| :=
abs_max_sub_max_le_max _ _ _ _
_ = |(1 - 32 * a.toReal) - (1 - 32 * b.toReal)| := by simp
_ ≀ 32 * c.toReal := by
rw [abs_le]
constructor <;> linarith
noncomputable def setBump {X : Type*} [PseudoEMetricSpace X] (A : Set X) (x : X) : ℝ :=
distanceBump (Metric.infEDist x A)
lemma setBump_lipschitz {X : Type*} [PseudoEMetricSpace X] (A : Set X) :
LipschitzWith 32 (setBump A) := by
intro x y
by_cases hc : edist x y = ⊀
Β· simp [hc]
Β· have h := distanceBump_difference hc
(Metric.infEDist_le_edist_add_infEDist (x := x) (y := y) (s := A))
(by simpa only [edist_comm x y] using
(Metric.infEDist_le_edist_add_infEDist (x := y) (y := x) (s := A)))
have hh := ENNReal.ofReal_le_ofReal h
simpa only [setBump, edist_dist, Real.dist_eq, ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≀ 32),
ENNReal.ofReal_toReal hc, ENNReal.ofReal_ofNat, ENNReal.coe_ofNat] using hh
noncomputable def oddBump {X : Type*} [PseudoEMetricSpace X]
(T : X β†’ X) (A : Set X) (x : X) : ℝ := setBump A x - setBump A (T x)
lemma oddBump_bounds {X : Type*} [PseudoEMetricSpace X]
(T : X β†’ X) (A : Set X) (x : X) : -1 ≀ oddBump T A x ∧ oddBump T A x ≀ 1 := by
have hx := distanceBump_bounds (Metric.infEDist x A)
have htx := distanceBump_bounds (Metric.infEDist (T x) A)
unfold oddBump setBump
constructor <;> linarith
lemma oddBump_odd {X : Type*} [PseudoEMetricSpace X] (T : X β†’ X)
(hT : Function.Involutive T) (A : Set X) (x : X) :
oddBump T A (T x) = -oddBump T A x := by
simp only [oddBump, hT x]
ring
lemma oddBump_lipschitz {X : Type*} [PseudoEMetricSpace X]
(T : X β†’ X) (hT : Isometry T) (A : Set X) : LipschitzWith 64 (oddBump T A) := by
have h := (setBump_lipschitz A).sub ((setBump_lipschitz A).comp hT.lipschitzWith)
norm_num only [mul_one, Nat.reduceAdd] at h
exact h
lemma oddBump_eq_one {X : Type*} [PseudoEMetricSpace X]
(T : X β†’ X) (A : Set X)
(hsep : βˆ€ x ∈ A, βˆ€ y ∈ A, ENNReal.ofReal (1 / 8) < edist x (T y))
{x : X} (hx : x ∈ A) : oddBump T A x = 1 := by
have hdist : ENNReal.ofReal (1 / 32) ≀ Metric.infEDist (T x) A := by
apply Metric.le_infEDist.mpr
intro y hy
rw [edist_comm]
exact (by norm_num : ENNReal.ofReal (1 / 32) ≀ ENNReal.ofReal (1 / 8)).trans
(hsep y hy x hx).le
simp only [oddBump, setBump, Metric.infEDist_zero_of_mem hx,
distanceBump_zero, distanceBump_vanish hdist, sub_zero]
lemma linkLength_le_copyLength {Q : Type*} {M : Q β†’ Type*}
(S : ProjectionSystem Q M) {D : β„•} [NeZero D] (x y : GridLocation M D) :
S.linkLength x y ≀ copyLength x y := by
classical
unfold ProjectionSystem.linkLength
split_ifs <;> simp
lemma grid_independent_separation {Q : Type*} {M : Q β†’ Type*}
(S : ProjectionSystem Q M) {D : β„•} [NeZero D] (hD : Even D)
(hnoclique : βˆ€ x : GridLocation M D,
Β¬pathDistance S.linkLength x (gridAntipode x) ≀ ENNReal.ofReal (1 / 8))
{V : Type*} (location : V β†’ GridLocation M D) (A : Set V)
(hA : (gridGraph S hD location).IsIndepSet A) :
βˆ€ x ∈ location '' A, βˆ€ y ∈ location '' A,
ENNReal.ofReal (1 / 8) < pathDistance S.linkLength x (gridAntipode y) := by
rintro x ⟨u, hu, rfl⟩ y ⟨v, hv, rfl⟩
by_contra hn
have hle := le_of_not_gt hn
by_cases h : u = v
Β· subst v
exact hnoclique (location u) hle
· exact ((gridGraph S hD location).isIndepSet_iff.mp hA) hu hv h ⟨h, hle⟩
noncomputable def gridBump {Q : Type*} {M : Q β†’ Type*}
(S : ProjectionSystem Q M) {D : β„•} [NeZero D]
(A : Set (GridLocation M D)) (x : GridLocation M D) : ℝ := by
letI := linkPseudoEMetric (S.linkLength (D := D)) (linkLength_self S) (linkLength_symm S)
exact oddBump gridAntipode A x
theorem grid_independent_bump {Q : Type*} {M : Q β†’ Type*} [βˆ€ q, Fintype (M q)]
(S : ProjectionSystem Q M) {D : β„•} [NeZero D] (hD : Even D)
(hnoclique : βˆ€ x : GridLocation M D,
Β¬pathDistance S.linkLength x (gridAntipode x) ≀ ENNReal.ofReal (1 / 8))
{V : Type*} (location : V β†’ GridLocation M D) (A : Set V)
(hA : (gridGraph S hD location).IsIndepSet A) :
let f := gridBump S (location '' A)
(βˆ€ x, -1 ≀ f x ∧ f x ≀ 1) ∧
(βˆ€ x, f (gridAntipode x) = -f x) ∧
(βˆ€ v ∈ A, f (location v) = 1) ∧
(βˆ€ x y, S.ZeroLink D x y β†’ f x = f y) ∧
(βˆ€ q (u v : M q β†’ ZMod D),
edist (f ⟨q, u⟩) (f ⟨q, v⟩) ≀ (64 : ℝβ‰₯0∞) *
edist (fun k => ZMod.toAddCircle (u k)) (fun k => ZMod.toAddCircle (v k))) := by
let := linkPseudoEMetric (S.linkLength (D := D)) (linkLength_self S) (linkLength_symm S)
have hT : Isometry (gridAntipode : GridLocation M D β†’ GridLocation M D) :=
pathDistance_invariant S.linkLength gridAntipode (gridAntipode_involutive hD)
(linkLength_antipode S hD)
have hf : LipschitzWith 64 (gridBump S (location '' A)) :=
oddBump_lipschitz gridAntipode hT (location '' A)
refine ⟨oddBump_bounds gridAntipode (location '' A),
oddBump_odd gridAntipode (gridAntipode_involutive hD) (location '' A), ?_, ?_, ?_⟩
Β· intro v hv
exact oddBump_eq_one gridAntipode (location '' A)
(grid_independent_separation S hD hnoclique location A hA) ⟨v, hv, rfl⟩
Β· intro x y hxy
have hpath : pathDistance S.linkLength x y = 0 := by
apply le_antisymm _ bot_le
apply (pathDistance_le_link S.linkLength x y).trans
simp [ProjectionSystem.linkLength, hxy]
have h := hf x y
change edist (gridBump S (location '' A) x) (gridBump S (location '' A) y) ≀
(64 : ℝβ‰₯0∞) * pathDistance S.linkLength x y at h
rw [hpath, mul_zero] at h
exact edist_eq_zero.mp (le_antisymm h bot_le)
Β· intro q u v
apply (hf ⟨q, u⟩ ⟨q, v⟩).trans
simp only [ENNReal.coe_ofNat]
apply mul_le_mul_right
change pathDistance S.linkLength ⟨q, u⟩ ⟨q, v⟩ ≀ _
apply (pathDistance_le_link S.linkLength _ _).trans
apply (linkLength_le_copyLength S _ _).trans_eq
rw [copyLength_same, edist_pi_def]
simp only [Finset.sup_univ_eq_iSup]
noncomputable def finiteMcShane {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (x : X) : ℝ :=
Finset.univ.inf' Finset.univ_nonempty (fun y => f y + L * dist x (e y))
lemma finiteMcShane_le {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (x : X) (y : G) :
finiteMcShane e f L x ≀ f y + L * dist x (e y) :=
Finset.inf'_le _ (Finset.mem_univ y)
lemma finiteMcShane_on_grid {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0)
(hf : βˆ€ x y, |f x - f y| ≀ L * dist (e x) (e y)) (x : G) :
finiteMcShane e f L (e x) = f x := by
apply le_antisymm
Β· simpa using finiteMcShane_le e f L (e x) x
Β· apply Finset.le_inf'
intro y _
have := (abs_le.mp (hf x y)).2
linarith
lemma finiteMcShane_lipschitz {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) :
LipschitzWith L (finiteMcShane e f L) := by
have hle (x y : X) : finiteMcShane e f L x ≀ finiteMcShane e f L y + L * dist x y := by
obtain ⟨g, _, hg⟩ := Finset.exists_mem_eq_inf' (s := (Finset.univ : Finset G))
Finset.univ_nonempty (fun g => f g + L * dist y (e g))
change finiteMcShane e f L y = _ at hg
have hm := mul_le_mul_of_nonneg_left (dist_triangle x y (e g)) L.coe_nonneg
have h := finiteMcShane_le e f L x g
rw [hg]
linarith
apply LipschitzWith.of_dist_le_mul
intro x y
rw [Real.dist_eq, abs_le]
have h₁ := hle x y
have hβ‚‚ := hle y x
rw [dist_comm y x] at hβ‚‚
constructor <;> linarith
def clipUnit (x : ℝ) : ℝ := max (-1) (min 1 x)
lemma clipUnit_bounds (x : ℝ) : -1 ≀ clipUnit x ∧ clipUnit x ≀ 1 := by
exact ⟨le_max_left _ _, max_le (by norm_num) (min_le_left _ _)⟩
lemma clipUnit_eq {x : ℝ} (hx : -1 ≀ x ∧ x ≀ 1) : clipUnit x = x := by
simp [clipUnit, min_eq_right hx.2, max_eq_right hx.1]
lemma clipUnit_lipschitz : LipschitzWith 1 clipUnit :=
(LipschitzWith.id.const_min 1).const_max (-1)
noncomputable def finiteOddExtension {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (T : X β†’ X) (x : X) : ℝ :=
(clipUnit (finiteMcShane e f L x) - clipUnit (finiteMcShane e f L (T x))) / 2
lemma finiteOddExtension_bounds {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (T : X β†’ X) (x : X) :
-1 ≀ finiteOddExtension e f L T x ∧ finiteOddExtension e f L T x ≀ 1 := by
have hx := clipUnit_bounds (finiteMcShane e f L x)
have htx := clipUnit_bounds (finiteMcShane e f L (T x))
unfold finiteOddExtension
constructor <;> linarith
lemma finiteOddExtension_odd {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (T : X β†’ X)
(hT : Function.Involutive T) (x : X) :
finiteOddExtension e f L T (T x) = -finiteOddExtension e f L T x := by
simp only [finiteOddExtension, hT x]
ring
lemma finiteOddExtension_on_grid {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (T : X β†’ X) (Tg : G β†’ G)
(hT : βˆ€ x, T (e x) = e (Tg x))
(hf : βˆ€ x y, |f x - f y| ≀ L * dist (e x) (e y))
(hb : βˆ€ x, -1 ≀ f x ∧ f x ≀ 1) (ho : βˆ€ x, f (Tg x) = -f x) (x : G) :
finiteOddExtension e f L T (e x) = f x := by
simp only [finiteOddExtension, hT x, finiteMcShane_on_grid e f L hf,
clipUnit_eq (hb x), clipUnit_eq (hb (Tg x))]
rw [ho x]
ring
lemma finiteOddExtension_lipschitz {G X : Type*} [Fintype G] [Nonempty G]
[PseudoMetricSpace X] (e : G β†’ X) (f : G β†’ ℝ) (L : ℝβ‰₯0) (T : X β†’ X)
(hT : Isometry T) : LipschitzWith L (finiteOddExtension e f L T) := by
have hg : LipschitzWith L (fun x => clipUnit (finiteMcShane e f L x)) := by
simpa only [one_mul, Function.comp_def] using clipUnit_lipschitz.comp (finiteMcShane_lipschitz e f L)
apply LipschitzWith.of_dist_le_mul
intro x y
have h₁ := hg.dist_le_mul x y
have hβ‚‚ := hg.dist_le_mul (T x) (T y)
rw [hT.dist_eq] at hβ‚‚
simp only [Real.dist_eq] at h₁ hβ‚‚ ⊒
unfold finiteOddExtension
rw [abs_le] at h₁ hβ‚‚ ⊒
constructor <;> linarith
noncomputable def torusAntipode {ΞΉ : Type*} (x : ΞΉ β†’ UnitAddCircle) : ΞΉ β†’ UnitAddCircle :=
fun k => x k + ((1 / 2 : ℝ) : UnitAddCircle)
lemma torusAntipode_involutive {ΞΉ : Type*} :
Function.Involutive (torusAntipode : (ΞΉ β†’ UnitAddCircle) β†’ (ΞΉ β†’ UnitAddCircle)) := by
intro x
funext k
simp only [torusAntipode, add_assoc, ← AddCircle.coe_add]
norm_num
lemma torusAntipode_isometry {ΞΉ : Type*} [Fintype ΞΉ] :
Isometry (torusAntipode : (ΞΉ β†’ UnitAddCircle) β†’ (ΞΉ β†’ UnitAddCircle)) := by
intro x y
simp only [edist_pi_def, torusAntipode, edist_add_right]
noncomputable def torusGrid {ΞΉ : Type*} {D : β„•} [NeZero D]
(x : ΞΉ β†’ ZMod D) : ΞΉ β†’ UnitAddCircle := fun k => ZMod.toAddCircle (x k)
lemma torusGrid_antipode {ΞΉ : Type*} {D : β„•} [NeZero D] (hD : Even D)
(x : ΞΉ β†’ ZMod D) :
torusAntipode (torusGrid x) = torusGrid (fun k => x k + ((D / 2 : β„•) : ZMod D)) := by
funext k
simp only [torusAntipode, torusGrid, map_add, ZMod.toAddCircle_natCast,
grid_half_real D hD]
noncomputable def tupleExtension {Q : Type*} {M : Q β†’ Type*} [βˆ€ q, Fintype (M q)]
(S : ProjectionSystem Q M) {D : β„•} [NeZero D]
(A : Set (GridLocation M D)) (q : Q) (x : M q β†’ UnitAddCircle) : ℝ := by
classical
exact finiteOddExtension torusGrid (fun u => gridBump S A ⟨q, u⟩) 64 torusAntipode x
lemma tupleExtension_bounds {Q : Type*} {M : Q β†’ Type*} [βˆ€ q, Fintype (M q)]
(S : ProjectionSystem Q M) {D : β„•} [NeZero D]
(A : Set (GridLocation M D)) (q : Q) (x : M q β†’ UnitAddCircle) :
-1 ≀ tupleExtension S A q x ∧ tupleExtension S A q x ≀ 1 := by
classical
exact finiteOddExtension_bounds _ _ _ _ _
end LargeIndependentSets
end OAI