roseking's picture
Add lean source and binary files (part 59)
8df23f4 verified
Raw History Blame Contribute Delete
47.7 kB
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Fin.Basic
import Mathlib.Data.Fin.Tuple.Basic
import Mathlib.Data.Finset.Max
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Sigma
import Mathlib.Data.List.OfFn
import Mathlib.Basic.Real.Basic
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Tactic.NormNum
namespace OAI
namespace BinPackingGames.Foundations.PCP.PoweringWalks
structure PortGraph (V D : Type*) where
rot : (V × D) ≃ (V × D)
rot_involutive : Function.Involutive rot
abbrev Edge (V D : Type*) := V × D
abbrev Walk (V D : Type*) (t : Nat) := V × (Fin t → D)
variable {V D : Type*}
def next (G : PortGraph V D) (v : V) (d : D) : V := (G.rot (v, d)).1
@[simp] theorem rot_rot (G : PortGraph V D) (e : Edge V D) :
G.rot (G.rot e) = e := G.rot_involutive e
def walkEnd (G : PortGraph V D) : V → List D → V
| v, [] => v
| v, d :: ds => walkEnd G (next G v d) ds
@[simp] theorem walkEnd_nil (G : PortGraph V D) (v : V) : walkEnd G v [] = v := rfl
@[simp] theorem walkEnd_cons (G : PortGraph V D) (v : V) (d : D) (ds : List D) :
walkEnd G v (d :: ds) = walkEnd G (next G v d) ds := rfl
theorem walkEnd_append (G : PortGraph V D) (v : V) (as bs : List D) :
walkEnd G v (as ++ bs) = walkEnd G (walkEnd G v as) bs := by
induction as generalizing v with
| nil => rfl
| cons d ds ih => exact ih (next G v d)
def splitHead (V D : Type*) (n : Nat) :
Walk V D (n + 1) ≃ ((V × D) × (Fin n → D)) where
toFun w := ((w.1, w.2 0), fun j => w.2 j.succ)
invFun z := (z.1.1, Fin.cases z.1.2 z.2)
left_inv w := by
apply Prod.ext
· rfl
funext j
exact Fin.cases rfl (fun _ => rfl) j
right_inv z := rfl
def rotateHead (G : PortGraph V D) (n : Nat) : Walk V D (n + 1) ≃ Walk V D (n + 1) :=
(splitHead V D n).trans
((Equiv.prodCongr G.rot (Equiv.refl (Fin n → D))).trans (splitHead V D n).symm)
@[simp] theorem rotateHead_vertex (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) :
(rotateHead G n w).1 = next G w.1 (w.2 0) := rfl
@[simp] theorem rotateHead_zero (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) :
(rotateHead G n w).2 0 = (G.rot (w.1, w.2 0)).2 := rfl
@[simp] theorem rotateHead_succ (G : PortGraph V D) (n : Nat)
(w : Walk V D (n + 1)) (j : Fin n) :
(rotateHead G n w).2 j.succ = w.2 j.succ := rfl
def permutePorts {t : Nat} (σ : Fin t ≃ Fin t) : Walk V D t ≃ Walk V D t where
toFun w := (w.1, fun j => w.2 (σ j))
invFun w := (w.1, fun j => w.2 (σ.symm j))
left_inv w := by
apply Prod.ext
· rfl
funext j
exact congrArg w.2 (σ.apply_symm_apply j)
right_inv w := by
apply Prod.ext
· rfl
funext j
exact congrArg w.2 (σ.symm_apply_apply j)
def wordEnd (G : PortGraph V D) : (n : Nat) → V → (Fin n → D) → V
| 0, v, _ => v
| n + 1, v, p => wordEnd G n (next G v (p 0)) (fun j => p j.succ)
def endpoint (G : PortGraph V D) {n : Nat} (w : Walk V D n) : V :=
wordEnd G n w.1 w.2
theorem natCard_walk [Finite V] [Finite D] (n : Nat) :
Nat.card (Walk V D n) = Nat.card V * Nat.card D ^ n := by
simp [Walk, Nat.card_prod, Nat.card_fun]
def headTailEquiv (V D : Type*) (n : Nat) :
Walk V D (n + 1) ≃ (Walk V D n × D) where
toFun w := ((w.1, fun j => w.2 j.succ), w.2 0)
invFun z := (z.1.1, Fin.cases z.2 z.1.2)
left_inv w := by
apply Prod.ext
· rfl
· funext j
exact Fin.cases rfl (fun _ => rfl) j
right_inv z := rfl
def advanceTail {n : Nat} (G : PortGraph V D) (w : Walk V D (n + 1)) : Walk V D n :=
((G.rot (w.1, w.2 0)).1, fun j => w.2 j.succ)
def edgeAt (G : PortGraph V D) :
(n : Nat) → Walk V D (n + 1) → Fin (n + 1) → Edge V D
| 0, w, _ => (w.1, w.2 0)
| n + 1, w, k => Fin.cases (w.1, w.2 0)
(fun j => edgeAt G n (advanceTail G w) j) k
def pivotEquiv (G : PortGraph V D) :
(n : Nat) → Fin (n + 1) →
(Walk V D (n + 1) ≃ (Edge V D × (Fin n → D)))
| 0, _ => splitHead V D 0
| n + 1, k => Fin.cases (splitHead V D (n + 1))
(fun j => (rotateHead G (n + 1)).trans
((headTailEquiv V D (n + 1)).trans
((Equiv.prodCongr (pivotEquiv G n j) (Equiv.refl D)).trans
(headTailEquiv (Edge V D) D n).symm))) k
theorem pivotEquiv_fst (G : PortGraph V D) :
∀ (n : Nat) (k : Fin (n + 1)) (w : Walk V D (n + 1)),
(pivotEquiv G n k w).1 = edgeAt G n w k := by
intro n
induction n with
| zero => intro k w; rfl
| succ n ih =>
intro k w
refine Fin.cases ?_ (fun j => ?_) k
· rfl
· change (pivotEquiv G n j (advanceTail G w)).1 =
edgeAt G n (advanceTail G w) j
exact ih j (advanceTail G w)
theorem edgeAt_port (G : PortGraph V D) :
∀ (n : Nat) (w : Walk V D (n + 1)) (k : Fin (n + 1)),
(edgeAt G n w k).2 = w.2 k := by
intro n
induction n with
| zero =>
intro w k
have hk : k = 0 := Fin.eq_zero k
subst k
rfl
| succ n ih =>
intro w k
refine Fin.cases ?_ (fun j => ?_) k
· rfl
· exact ih (advanceTail G w) j
theorem pivotEquiv_zero_apply (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) :
pivotEquiv G n 0 w = ((w.1, w.2 0), fun j => w.2 j.succ) := by
cases n <;> rfl
theorem pivotEquiv_succ_apply (G : PortGraph V D)
(n : Nat) (k : Fin (n + 1)) (w : Walk V D (n + 2)) :
pivotEquiv G (n + 1) k.succ w =
((pivotEquiv G n k (advanceTail G w)).1,
Fin.cases (G.rot (w.1, w.2 0)).2
(pivotEquiv G n k (advanceTail G w)).2) := rfl
def projectedFiberEquiv {X E R : Type*} (e : X ≃ E × R) (f : X → E)
(he : ∀ x, (e x).1 = f x) (a : E) : {x // f x = a} ≃ R where
toFun x := (e x.val).2
invFun r := ⟨e.symm (a, r), by
exact (he _).symm.trans (congrArg Prod.fst (e.apply_symm_apply (a, r)))⟩
left_inv x := by
apply Subtype.ext
apply e.injective
rw [e.apply_symm_apply]
exact Prod.ext ((he x.val).trans x.property).symm rfl
right_inv r := congrArg Prod.snd (e.apply_symm_apply (a, r))
def projectedEventEquiv {X E R : Type*} (e : X ≃ E × R) (f : X → E)
(he : ∀ x, (e x).1 = f x) (P : E → Prop) :
{x // P (f x)} ≃ ({a // P a} × R) where
toFun x := (⟨(e x.val).1, by rw [he]; exact x.property⟩, (e x.val).2)
invFun ar := ⟨e.symm (ar.1.val, ar.2), by
have h : f (e.symm (ar.1.val, ar.2)) = ar.1.val :=
(he _).symm.trans (congrArg Prod.fst (e.apply_symm_apply (ar.1.val, ar.2)))
simpa only [h] using ar.1.property⟩
left_inv x := by
apply Subtype.ext
exact e.symm_apply_apply x.val
right_inv ar := by
apply Prod.ext
· apply Subtype.ext
exact congrArg Prod.fst (e.apply_symm_apply (ar.1.val, ar.2))
· change (e (e.symm (ar.1.val, ar.2))).2 = ar.2
exact congrArg Prod.snd (e.apply_symm_apply (ar.1.val, ar.2))
theorem natCard_edgeAt_fiber (G : PortGraph V D) (n : Nat) (k : Fin (n + 1))
(a : Edge V D) :
Nat.card {w : Walk V D (n + 1) // edgeAt G n w k = a} = Nat.card D ^ n := by
calc
_ = Nat.card (Fin n → D) := Nat.card_congr
(projectedFiberEquiv (pivotEquiv G n k) (fun w => edgeAt G n w k)
(pivotEquiv_fst G n k) a)
_ = _ := by simp [Nat.card_fun]
theorem natCard_edgeAt_event (G : PortGraph V D) (n : Nat) (k : Fin (n + 1))
(P : Edge V D → Prop) :
Nat.card {w : Walk V D (n + 1) // P (edgeAt G n w k)} =
Nat.card {a : Edge V D // P a} * Nat.card D ^ n := by
calc
_ = Nat.card ({a : Edge V D // P a} × (Fin n → D)) := Nat.card_congr
(projectedEventEquiv (pivotEquiv G n k) (fun w => edgeAt G n w k)
(pivotEquiv_fst G n k) P)
_ = _ := by simp [Nat.card_prod, Nat.card_fun]
def leftFromPivot (G : PortGraph V D) :
(n : Nat) → Fin (n + 1) → V → (Fin n → D) → V
| 0, _, v, _ => v
| n + 1, k, v, r => Fin.cases v
(fun j => next G (leftFromPivot G n j v (fun m => r m.succ)) (r 0)) k
def rightFromPivot (G : PortGraph V D) :
(n : Nat) → Fin (n + 1) → Edge V D → (Fin n → D) → V
| 0, _, e, _ => next G e.1 e.2
| n + 1, k, e, r => Fin.cases
(wordEnd G (n + 1) (next G e.1 e.2) r)
(fun j => rightFromPivot G n j e (fun m => r m.succ)) k
theorem leftFromPivot_zero (G : PortGraph V D) (n : Nat)
(v : V) (r : Fin n → D) : leftFromPivot G n 0 v r = v := by
cases n <;> rfl
theorem rightFromPivot_zero (G : PortGraph V D) (n : Nat)
(e : Edge V D) (r : Fin n → D) :
rightFromPivot G n 0 e r = wordEnd G n (next G e.1 e.2) r := by
cases n <;> rfl
theorem leftFromPivot_actual (G : PortGraph V D) :
∀ (n : Nat) (k : Fin (n + 1)) (w : Walk V D (n + 1)),
leftFromPivot G n k (pivotEquiv G n k w).1.1 (pivotEquiv G n k w).2 = w.1 := by
intro n
induction n with
| zero => intro k w; rfl
| succ n ih =>
intro k w
refine Fin.cases ?_ (fun j => ?_) k
· rfl
· rw [pivotEquiv_succ_apply]
change next G
(leftFromPivot G n j (pivotEquiv G n j (advanceTail G w)).1.1
(pivotEquiv G n j (advanceTail G w)).2)
(G.rot (w.1, w.2 0)).2 = w.1
rw [ih j (advanceTail G w)]
change (G.rot ((G.rot (w.1, w.2 0)).1, (G.rot (w.1, w.2 0)).2)).1 = w.1
exact congrArg Prod.fst (rot_rot G (w.1, w.2 0))
theorem rightFromPivot_actual (G : PortGraph V D) :
∀ (n : Nat) (k : Fin (n + 1)) (w : Walk V D (n + 1)),
rightFromPivot G n k (pivotEquiv G n k w).1 (pivotEquiv G n k w).2 =
endpoint G w := by
intro n
induction n with
| zero => intro k w; rfl
| succ n ih =>
intro k w
refine Fin.cases ?_ (fun j => ?_) k
· rfl
· rw [pivotEquiv_succ_apply]
change rightFromPivot G n j (pivotEquiv G n j (advanceTail G w)).1
(pivotEquiv G n j (advanceTail G w)).2 = endpoint G w
rw [ih j (advanceTail G w)]
rfl
end BinPackingGames.Foundations.PCP.PoweringWalks
namespace BinPackingGames.Foundations.PCP
structure ConstraintGraph (V E A : Type*) where
reverse : E ≃ E
reverse_involutive : Function.Involutive reverse
tail : E → V
accepts : E → A → A → Bool
reverse_accepts : ∀ e a b, accepts (reverse e) b a = accepts e a b
namespace ConstraintGraph
variable {V E A : Type*}
def head (G : ConstraintGraph V E A) (e : E) : V := G.tail (G.reverse e)
@[simp] theorem head_reverse (G : ConstraintGraph V E A) (e : E) :
G.head (G.reverse e) = G.tail e := by
simp only [head, G.reverse_involutive e]
def edgeSatisfied (G : ConstraintGraph V E A) (labeling : V → A) (e : E) : Bool :=
G.accepts e (labeling (G.tail e)) (labeling (G.head e))
@[simp] theorem edgeSatisfied_reverse (G : ConstraintGraph V E A)
(labeling : V → A) (e : E) :
G.edgeSatisfied labeling (G.reverse e) = G.edgeSatisfied labeling e := by
simpa only [edgeSatisfied, head, G.reverse_involutive e] using
G.reverse_accepts e (labeling (G.tail e)) (labeling (G.tail (G.reverse e)))
def Satisfiable (G : ConstraintGraph V E A) : Prop :=
∃ labeling : V → A, ∀ e, G.edgeSatisfied labeling e = true
def rejectedDarts [Fintype E] (G : ConstraintGraph V E A) (labeling : V → A) :
Finset E := Finset.univ.filter (fun e => G.edgeSatisfied labeling e = false)
def rejectionCount [Fintype E] (G : ConstraintGraph V E A) (labeling : V → A) : Nat :=
(G.rejectedDarts labeling).card
theorem mem_rejectedDarts [Fintype E] (G : ConstraintGraph V E A)
(labeling : V → A) (e : E) :
e ∈ G.rejectedDarts labeling ↔ G.edgeSatisfied labeling e = false := by
simp [rejectedDarts]
theorem rejectionCount_le [Fintype E] (G : ConstraintGraph V E A)
(labeling : V → A) : G.rejectionCount labeling ≤ Fintype.card E := by
exact Finset.card_le_card (Finset.filter_subset _ _)
theorem rejected_exists_of_not_satisfiable (G : ConstraintGraph V E A)
(unsat : ¬ G.Satisfiable) (labeling : V → A) :
∃ e, G.edgeSatisfied labeling e = false := by
classical
by_contra none
apply unsat
refine ⟨labeling, fun e => ?_⟩
have notFalse : G.edgeSatisfied labeling e ≠ false := by
intro h
exact none ⟨e, h⟩
cases h : G.edgeSatisfied labeling e <;> simp_all
theorem rejectionCount_positive [Fintype E] (G : ConstraintGraph V E A)
(unsat : ¬ G.Satisfiable) (labeling : V → A) :
1 ≤ G.rejectionCount labeling := by
obtain ⟨e, he⟩ := G.rejected_exists_of_not_satisfiable unsat labeling
exact Finset.one_le_card.mpr ⟨e, (G.mem_rejectedDarts labeling e).mpr he⟩
end ConstraintGraph
end BinPackingGames.Foundations.PCP
namespace BinPackingGames.Foundations.PCP.PoweringLabels
open PoweringWalks
open scoped BigOperators
variable {V D A : Type*}
abbrev PortWords (D : Type*) (t : Nat) := (n : Fin (t + 1)) × (Fin n.val → D)
instance finitePortWords [Finite D] (t : Nat) : Finite (PortWords D t) := by
let := Fintype.ofFinite D
exact Finite.of_fintype _
def Ball (G : PortGraph V D) (t : Nat) (v : V) :=
{u : V // ∃ n, n ≤ t ∧ ∃ p : Fin n → D, wordEnd G n v p = u}
def wordToBall (G : PortGraph V D) (t : Nat) (v : V) (w : PortWords D t) : Ball G t v :=
⟨wordEnd G w.1.val v w.2, w.1.val, Nat.le_of_lt_succ w.1.isLt, w.2, rfl⟩
theorem wordToBall_surjective (G : PortGraph V D) (t : Nat) (v : V) :
Function.Surjective (wordToBall G t v) := by
intro u
obtain ⟨n, hn, p, hp⟩ := u.property
refine ⟨⟨⟨n, Nat.lt_succ_of_le hn⟩, p⟩, ?_⟩
exact Subtype.ext hp
instance finiteBall [Finite D] (G : PortGraph V D) (t : Nat) (v : V) :
Finite (Ball G t v) :=
Finite.of_surjective (wordToBall G t v) (wordToBall_surjective G t v)
theorem card_portWords [Finite D] (t : Nat) :
Nat.card (PortWords D t) = ∑ n : Fin (t + 1), Nat.card D ^ n.val := by
simp [PortWords, Nat.card_sigma, Nat.card_fun]
theorem card_ball_le [Finite D] (G : PortGraph V D) (t : Nat) (v : V) :
Nat.card (Ball G t v) ≤ ∑ n : Fin (t + 1), Nat.card D ^ n.val := by
calc
_ ≤ Nat.card (PortWords D t) := Nat.card_le_card_of_surjective
(wordToBall G t v) (wordToBall_surjective G t v)
_ = _ := card_portWords t
structure AddressSelector (G : PortGraph V D) (t : Nat) (v : V) where
address : Ball G t v → PortWords D t
correct : ∀ u, wordToBall G t v (address u) = u
noncomputable def classicalSelector (G : PortGraph V D) (t : Nat) (v : V) :
AddressSelector G t v where
address u := Classical.choose (wordToBall_surjective G t v u)
correct u := Classical.choose_spec (wordToBall_surjective G t v u)
def scanWitness {A : Type*} (p : A → Prop) [DecidablePred p] :
(xs : List A) → (∃ a ∈ xs, p a) → {a // p a}
| [], h => False.elim (by simp at h)
| a :: xs, h =>
if ha : p a then ⟨a, ha⟩ else
scanWitness p xs (by
obtain ⟨b, hb, hp⟩ := h
rcases List.mem_cons.mp hb with he | hm
· exact False.elim (ha (he ▸ hp))
· exact ⟨b, hm, hp⟩)
def listSelector [DecidableEq V] (G : PortGraph V D) (t : Nat) (v : V)
(addresses : List (PortWords D t)) (complete : ∀ w, w ∈ addresses) :
AddressSelector G t v where
address u := (scanWitness (fun w => (wordToBall G t v w).val = u.val) addresses (by
obtain ⟨w, hw⟩ := wordToBall_surjective G t v u
exact ⟨w, complete w, congrArg Subtype.val hw⟩)).val
correct u := Subtype.ext (scanWitness
(fun w => (wordToBall G t v w).val = u.val) addresses (by
obtain ⟨w, hw⟩ := wordToBall_surjective G t v u
exact ⟨w, complete w, congrArg Subtype.val hw⟩)).property
abbrev PaddedLabel (D : Type*) (t : Nat) (A : Type*) := PortWords D t → A
def encode (G : PortGraph V D) (t : Nat) (v : V) (ℓ : Ball G t v → A) :
PaddedLabel D t A := fun w => ℓ (wordToBall G t v w)
def decode {G : PortGraph V D} {t : Nat} {v : V} (S : AddressSelector G t v)
(a : PaddedLabel D t A) : Ball G t v → A := fun u => a (S.address u)
theorem decode_encode {G : PortGraph V D} {t : Nat} {v : V}
(S : AddressSelector G t v) (ℓ : Ball G t v → A) :
decode S (encode G t v ℓ) = ℓ := by
funext u
change ℓ (wordToBall G t v (S.address u)) = ℓ u
rw [S.correct]
theorem decode_surjective {G : PortGraph V D} {t : Nat} {v : V}
(S : AddressSelector G t v) : Function.Surjective (decode (A := A) S) :=
fun ℓ => ⟨encode G t v ℓ, decode_encode S ℓ⟩
theorem encode_injective (G : PortGraph V D) (t : Nat) (v : V) :
Function.Injective (encode (A := A) G t v) := by
intro a b h
funext u
obtain ⟨w, rfl⟩ := wordToBall_surjective G t v u
exact congrFun h w
theorem decoded_word_collision {G : PortGraph V D} {t : Nat} {v : V}
(S : AddressSelector G t v) (a : PaddedLabel D t A) (w z : PortWords D t)
(h : (wordToBall G t v w).val = (wordToBall G t v z).val) :
decode S a (wordToBall G t v w) = decode S a (wordToBall G t v z) :=
congrArg (decode S a) (Subtype.ext h)
theorem card_paddedLabel [Finite D] [Finite A] (t : Nat) :
Nat.card (PaddedLabel D t A) =
Nat.card A ^ (∑ n : Fin (t + 1), Nat.card D ^ n.val) := by
rw [Nat.card_fun, card_portWords]
end BinPackingGames.Foundations.PCP.PoweringLabels
section
open scoped BigOperators
namespace BinPackingGames.Foundations.PCP.DegreeReplacement
open PoweringWalks
variable {V E A D : Type*}
abbrev Cloud (G : ConstraintGraph V E A) (v : V) := {e : E // G.tail e = v}
def cloudIndexEquiv (G : ConstraintGraph V E A) :
(E × D) ≃ (Σ v : V, Cloud G v × D) where
toFun p := ⟨G.tail p.1, (⟨p.1, rfl⟩, p.2)⟩
invFun p := (p.2.1.val, p.2.2)
left_inv _ := rfl
right_inv := by
rintro ⟨v, ⟨⟨e, he⟩, d⟩⟩
cases he
rfl
def cloudRotation (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) :
(Σ v : V, Cloud G v × D) ≃ (Σ v : V, Cloud G v × D) :=
Equiv.sigmaCongrRight (fun v => (H v).rot)
theorem cloudRotation_involutive (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) :
Function.Involutive (cloudRotation G H) := by
rintro ⟨v, p⟩
change (⟨v, (H v).rot ((H v).rot p)⟩ : Σ v : V, Cloud G v × D) = ⟨v, p⟩
rw [(H v).rot_involutive p]
def innerRotation (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) : (E × D) ≃ (E × D) :=
((cloudIndexEquiv G).trans (cloudRotation G H)).trans (cloudIndexEquiv G).symm
theorem innerRotation_involutive (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) :
Function.Involutive (innerRotation G H) := by
intro p
apply (cloudIndexEquiv G).injective
simp only [innerRotation, Equiv.trans_apply, Equiv.apply_symm_apply]
exact cloudRotation_involutive G H _
theorem innerRotation_tail (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (e : E) (d : D) :
G.tail (innerRotation G H (e, d)).1 = G.tail e := by
change G.tail (((H (G.tail e)).rot (⟨e, rfl⟩, d)).1.val) = G.tail e
exact ((H (G.tail e)).rot (⟨e, rfl⟩, d)).1.property
def replacementStep (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) : E × (D ⊕ Unit) → E × (D ⊕ Unit)
| (e, Sum.inl d) =>
let p := innerRotation G H (e, d)
(p.1, Sum.inl p.2)
| (e, Sum.inr u) => (G.reverse e, Sum.inr u)
theorem replacementStep_involutive (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) :
Function.Involutive (replacementStep G H) := by
rintro ⟨e, p⟩
rcases p with d | u
· change ((innerRotation G H (innerRotation G H (e, d))).1,
(Sum.inl ((innerRotation G H (innerRotation G H (e, d))).2) : D ⊕ Unit)) =
(e, Sum.inl d)
rw [innerRotation_involutive G H (e, d)]
· change (G.reverse (G.reverse e), (Sum.inr u : D ⊕ Unit)) = (e, Sum.inr u)
rw [G.reverse_involutive e]
def replacementPortGraph (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) : PortGraph E (D ⊕ Unit) where
rot :=
{ toFun := replacementStep G H
invFun := replacementStep G H
left_inv := replacementStep_involutive G H
right_inv := replacementStep_involutive G H }
rot_involutive := replacementStep_involutive G H
def replacementGraph [DecidableEq A] (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) :
ConstraintGraph E (E × (D ⊕ Unit)) A where
reverse := (replacementPortGraph G H).rot
reverse_involutive := (replacementPortGraph G H).rot_involutive
tail := Prod.fst
accepts p a b := match p.2 with
| Sum.inl _ => decide (a = b)
| Sum.inr _ => G.accepts p.1 a b
reverse_accepts := by
rintro ⟨e, p⟩ a b
rcases p with d | u
· change decide (b = a) = decide (a = b)
simp [eq_comm]
· exact G.reverse_accepts e a b
def liftLabel (G : ConstraintGraph V E A) (labeling : V → A) : E → A :=
fun e => labeling (G.tail e)
@[simp] theorem replacement_satisfied_inl [DecidableEq A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(labeling : V → A) (e : E) (d : D) :
(replacementGraph G H).edgeSatisfied (liftLabel G labeling) (e, Sum.inl d) =
true := by
change decide (labeling (G.tail e) =
labeling (G.tail (innerRotation G H (e, d)).1)) = true
rw [innerRotation_tail G H e d]
simp
@[simp] theorem replacement_satisfied_inr [DecidableEq A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(labeling : V → A) (e : E) (u : Unit) :
(replacementGraph G H).edgeSatisfied (liftLabel G labeling) (e, Sum.inr u) =
G.edgeSatisfied labeling e := rfl
theorem replacement_complete [DecidableEq A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(labeling : V → A) (h : ∀ e, G.edgeSatisfied labeling e = true) :
∀ p, (replacementGraph G H).edgeSatisfied (liftLabel G labeling) p = true := by
rintro ⟨e, p⟩
rcases p with d | u
· exact replacement_satisfied_inl G H labeling e d
· rw [replacement_satisfied_inr]
exact h e
theorem replacement_satisfiable [DecidableEq A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(h : G.Satisfiable) : (replacementGraph G H).Satisfiable := by
obtain ⟨labeling, hlabeling⟩ := h
exact ⟨liftLabel G labeling, replacement_complete G H labeling hlabeling⟩
theorem rejectionCount_eq_sum [Fintype E] (G : ConstraintGraph V E A)
(labeling : V → A) :
G.rejectionCount labeling =
∑ e, if G.edgeSatisfied labeling e = false then 1 else 0 := by
classical
simp only [ConstraintGraph.rejectionCount, ConstraintGraph.rejectedDarts,
Finset.card_eq_sum_ones, Finset.sum_filter]
theorem replacement_rejectionCount [Fintype E] [Fintype D] [DecidableEq A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(labeling : V → A) :
(replacementGraph G H).rejectionCount (liftLabel G labeling) =
G.rejectionCount labeling := by
classical
simp only [rejectionCount_eq_sum, Fintype.sum_prod_type, Fintype.sum_sum_type]
simp
simp only [Finset.card_eq_sum_ones, Finset.sum_filter]
apply Finset.sum_congr rfl
intro edge _
split <;> simp_all
abbrev PaddedDart (_G : ConstraintGraph V E A) (dummy : V → Type*) :=
E ⊕ (Σ v : V, dummy v)
def paddedOwner (G : ConstraintGraph V E A) (dummy : V → Type*) :
PaddedDart G dummy → V
| Sum.inl e => G.tail e
| Sum.inr z => z.1
def paddedReverse (G : ConstraintGraph V E A) (dummy : V → Type*) :
PaddedDart G dummy ≃ PaddedDart G dummy :=
Equiv.sumCongr G.reverse (Equiv.refl (Σ v : V, dummy v))
theorem paddedReverse_involutive (G : ConstraintGraph V E A) (dummy : V → Type*) :
Function.Involutive (paddedReverse G dummy) := by
intro z
cases z with
| inl e =>
change (Sum.inl (G.reverse (G.reverse e)) : PaddedDart G dummy) = Sum.inl e
rw [G.reverse_involutive e]
| inr z => rfl
def paddedGraph (G : ConstraintGraph V E A) (dummy : V → Type*) :
ConstraintGraph V (PaddedDart G dummy) A where
reverse := paddedReverse G dummy
reverse_involutive := paddedReverse_involutive G dummy
tail := paddedOwner G dummy
accepts e a b := match e with
| Sum.inl e => G.accepts e a b
| Sum.inr _ => true
reverse_accepts := by
intro e a b
cases e with
| inl e => exact G.reverse_accepts e a b
| inr z => rfl
@[simp] theorem padded_satisfied_inl (G : ConstraintGraph V E A)
(dummy : V → Type*) (labeling : V → A) (e : E) :
(paddedGraph G dummy).edgeSatisfied labeling (Sum.inl e) =
G.edgeSatisfied labeling e := rfl
@[simp] theorem padded_satisfied_inr (G : ConstraintGraph V E A)
(dummy : V → Type*) (labeling : V → A) (z : Σ v : V, dummy v) :
(paddedGraph G dummy).edgeSatisfied labeling (Sum.inr z) = true := rfl
theorem padded_complete (G : ConstraintGraph V E A) (dummy : V → Type*)
(labeling : V → A) (h : ∀ e, G.edgeSatisfied labeling e = true) :
∀ c, (paddedGraph G dummy).edgeSatisfied labeling c = true := by
intro c
cases c with
| inl e => exact h e
| inr z => rfl
theorem padded_satisfiable (G : ConstraintGraph V E A) (dummy : V → Type*)
(h : G.Satisfiable) : (paddedGraph G dummy).Satisfiable := by
obtain ⟨labeling, hlabeling⟩ := h
exact ⟨labeling, padded_complete G dummy labeling hlabeling⟩
theorem card_paddedDart [Fintype V] [Fintype E] (G : ConstraintGraph V E A)
(dummy : V → Type*) [∀ v, Fintype (dummy v)] :
Fintype.card (PaddedDart G dummy) =
Fintype.card E + ∑ v, Fintype.card (dummy v) := by
rw [Fintype.card_sum, Fintype.card_sigma]
theorem padded_rejectionCount [Fintype V] [Fintype E]
(G : ConstraintGraph V E A) (dummy : V → Type*) [∀ v, Fintype (dummy v)]
(labeling : V → A) :
(paddedGraph G dummy).rejectionCount labeling = G.rejectionCount labeling := by
classical
simp only [rejectionCount_eq_sum, Fintype.sum_sum_type]
simp
simp only [Finset.card_eq_sum_ones, Finset.sum_filter]
apply Finset.sum_congr rfl
intro edge _
split <;> simp_all
def paddedReplacementPortGraph (G : ConstraintGraph V E A) (dummy : V → Type*)
(H : ∀ v, PortGraph (Cloud (paddedGraph G dummy) v) D) :
PortGraph (PaddedDart G dummy) (D ⊕ Unit) :=
replacementPortGraph (paddedGraph G dummy) H
def paddedReplacementGraph [DecidableEq A]
(G : ConstraintGraph V E A) (dummy : V → Type*)
(H : ∀ v, PortGraph (Cloud (paddedGraph G dummy) v) D) :
ConstraintGraph (PaddedDart G dummy) (PaddedDart G dummy × (D ⊕ Unit)) A :=
replacementGraph (paddedGraph G dummy) H
theorem paddedReplacement_rejectionCount
[Fintype V] [Fintype E] [Fintype D] [DecidableEq A]
(G : ConstraintGraph V E A) (dummy : V → Type*) [∀ v, Fintype (dummy v)]
(H : ∀ v, PortGraph (Cloud (paddedGraph G dummy) v) D) (labeling : V → A) :
(paddedReplacementGraph G dummy H).rejectionCount
(liftLabel (paddedGraph G dummy) labeling) = G.rejectionCount labeling :=
(replacement_rejectionCount (paddedGraph G dummy) H labeling).trans
(padded_rejectionCount G dummy labeling)
def noDummyEquiv (G : ConstraintGraph V E A) :
PaddedDart G (fun _ : V => Empty) ≃ E where
toFun z := match z with
| Sum.inl e => e
| Sum.inr z => Empty.elim z.2
invFun := Sum.inl
left_inv := by
intro z
cases z with
| inl e => rfl
| inr z => exact Empty.elim z.2
right_inv _ := rfl
end BinPackingGames.Foundations.PCP.DegreeReplacement
end
namespace BinPackingGames.Foundations.PCP.PoweringAddresses
open PoweringWalks PoweringLabels
open scoped BigOperators
variable {V : Type*}
def allWords (d : Nat) : (n : Nat) → List (Fin n → Fin d)
| 0 => [Fin.elim0]
| n + 1 => (List.finRange d).flatMap fun a =>
(allWords d n).map fun p => Fin.cases a p
theorem mem_allWords (d : Nat) :
∀ n (p : Fin n → Fin d), p ∈ allWords d n := by
intro n
induction n with
| zero =>
intro p
simp only [allWords, List.mem_singleton]
funext i
exact Fin.elim0 i
| succ n ih =>
intro p
simp only [allWords, List.mem_flatMap, List.mem_map]
refine ⟨p 0, List.mem_finRange (p 0), (fun j => p j.succ), ih _, ?_⟩
funext j
exact Fin.cases rfl (fun _ => rfl) j
def allAddresses (d t : Nat) : List (PortWords (Fin d) t) :=
(List.finRange (t + 1)).flatMap fun n =>
(allWords d n.val).map fun p => Sigma.mk n p
theorem mem_allAddresses (d t : Nat) (w : PortWords (Fin d) t) :
w ∈ allAddresses d t := by
rcases w with ⟨n, p⟩
unfold allAddresses
apply List.mem_flatMap.mpr
refine ⟨n, List.mem_finRange n, ?_⟩
exact List.mem_map.mpr ⟨p, mem_allWords d n.val p, rfl⟩
theorem length_allWords (d : Nat) :
∀ n, (allWords d n).length = d ^ n := by
intro n
induction n with
| zero => rfl
| succ n ih =>
simp only [allWords, List.length_flatMap, List.length_map, ih,
List.map_const', List.length_finRange, List.sum_replicate_nat]
exact (Nat.mul_comm d (d ^ n)).trans (Nat.pow_succ d n).symm
theorem length_allAddresses (d t : Nat) :
(allAddresses d t).length = ∑ n : Fin (t + 1), d ^ n.val := by
unfold allAddresses
simp only [List.length_flatMap, List.length_map, length_allWords]
exact (Fin.sum_univ_def (fun n : Fin (t + 1) => d ^ n.val)).symm
def finitePortSelector {d : Nat} [DecidableEq V] (G : PortGraph V (Fin d))
(t : Nat) (v : V) : AddressSelector G t v :=
listSelector G t v (allAddresses d t) (mem_allAddresses d t)
end BinPackingGames.Foundations.PCP.PoweringAddresses
namespace BinPackingGames.Foundations.PCP.PoweringDecoding
open scoped BigOperators
variable {Ω A : Type*} [Fintype Ω] [Nonempty Ω] [Fintype A] [Nonempty A]
noncomputable def mass (opinion : Ω → A) (a : A) : ℝ := by
classical
exact Finset.univ.expect (fun ω => if opinion ω = a then 1 else 0)
omit [Nonempty A] in
theorem mass_sum (opinion : Ω → A) : (∑ a, mass opinion a) = 1 := by
classical
calc
(∑ a, mass opinion a) =
(Finset.univ : Finset Ω).expect
(fun ω => ∑ a : A, if opinion ω = a then (1 : ℝ) else 0) :=
(Finset.expect_sum_comm (Finset.univ : Finset Ω) (Finset.univ : Finset A)
(fun ω a => if opinion ω = a then (1 : ℝ) else 0)).symm
_ = (Finset.univ : Finset Ω).expect (fun _ => (1 : ℝ)) := by
apply Finset.expect_congr rfl
intro ω _
simp
_ = 1 := Finset.expect_const Finset.univ_nonempty 1
omit [Nonempty Ω] in
theorem exists_mode (opinion : Ω → A) :
∃ a : A, ∀ b : A, mass opinion b ≤ mass opinion a := by
obtain ⟨a, _, ha⟩ := Finset.exists_max_image (Finset.univ : Finset A)
(mass opinion) Finset.univ_nonempty
exact ⟨a, fun b => ha b (Finset.mem_univ b)⟩
noncomputable def mode (opinion : Ω → A) : A := Classical.choose (exists_mode opinion)
omit [Nonempty Ω] in
theorem mode_max (opinion : Ω → A) (b : A) :
mass opinion b ≤ mass opinion (mode opinion) :=
Classical.choose_spec (exists_mode opinion) b
theorem mode_mass_lower (opinion : Ω → A) :
1 / (Fintype.card A : ℝ) ≤ mass opinion (mode opinion) := by
have hk : 0 < (Fintype.card A : ℝ) := Nat.cast_pos.mpr Fintype.card_pos
have hsum : (1 : ℝ) ≤ mass opinion (mode opinion) * (Fintype.card A : ℝ) := by
calc
(1 : ℝ) = ∑ a : A, mass opinion a := (mass_sum opinion).symm
_ ≤ ∑ _a : A, mass opinion (mode opinion) :=
Finset.sum_le_sum (fun a _ => mode_max opinion a)
_ = mass opinion (mode opinion) * (Fintype.card A : ℝ) := by simp [mul_comm]
exact (div_le_iff₀ hk).2 hsum
theorem exists_letter_mass_lower (opinion : Ω → A) :
∃ a : A, 1 / (Fintype.card A : ℝ) ≤ mass opinion a :=
⟨mode opinion, mode_mass_lower opinion⟩
end BinPackingGames.Foundations.PCP.PoweringDecoding
namespace BinPackingGames.Foundations.PCP.CloudRounding
open scoped BigOperators
theorem dart_rejection_count_le
{E V A : Type*} [Fintype E] [DecidableEq A]
(tail : E → V) (reverse : E ≃ E) (accepts : E → A → A → Bool)
(ell : E → A) (rounded : V → A) :
(Finset.univ.filter (fun e =>
accepts e (rounded (tail e)) (rounded (tail (reverse e))) = false)).card ≤
(Finset.univ.filter (fun e => accepts e (ell e) (ell (reverse e)) = false)).card +
2 * (Finset.univ.filter (fun e => ell e ≠ rounded (tail e))).card := by
classical
let R : Finset E := Finset.univ.filter (fun e =>
accepts e (rounded (tail e)) (rounded (tail (reverse e))) = false)
let B : Finset E := Finset.univ.filter (fun e =>
accepts e (ell e) (ell (reverse e)) = false)
let M : Finset E := Finset.univ.filter (fun e => ell e ≠ rounded (tail e))
let MR : Finset E := Finset.univ.filter (fun e =>
ell (reverse e) ≠ rounded (tail (reverse e)))
have hrev : MR.card = M.card := by
have hsets : MR = M.map reverse.symm.toEmbedding := by
ext e
constructor
· intro he
apply Finset.mem_map.mpr
refine ⟨reverse e, ?_, reverse.symm_apply_apply e⟩
simpa [MR, M] using he
· intro he
obtain ⟨d, hd, rfl⟩ := Finset.mem_map.mp he
simpa [MR, M] using hd
rw [hsets, Finset.card_map]
have hsub : R ⊆ (B ∪ M) ∪ MR := by
intro e he
by_cases hl : ell e = rounded (tail e)
· by_cases hr : ell (reverse e) = rounded (tail (reverse e))
· have hb : e ∈ B := by simpa [B, R, hl, hr] using he
exact Finset.mem_union_left _ (Finset.mem_union_left _ hb)
· exact Finset.mem_union_right _ (by simp [MR, hr])
· exact Finset.mem_union_left _ (Finset.mem_union_right _ (by simp [M, hl]))
change R.card ≤ B.card + 2 * M.card
calc
R.card ≤ ((B ∪ M) ∪ MR).card := Finset.card_le_card hsub
_ ≤ (B ∪ M).card + MR.card := Finset.card_union_le _ _
_ ≤ (B.card + M.card) + MR.card :=
Nat.add_le_add_right (Finset.card_union_le B M) _
_ = B.card + 2 * M.card := by rw [hrev]; omega
section CloudCounts
variable {X A D : Type*} [Fintype X] [Fintype A] [Fintype D]
variable [DecidableEq X] [DecidableEq A]
def colorSet (ell : X → A) (a : A) : Finset X :=
Finset.univ.filter (fun x => ell x = a)
def minoritySet (ell : X → A) (m : A) : Finset X :=
Finset.univ.filter (fun x => ell x ≠ m)
def directedCut (next : X × D → X) (S : Finset X) : Finset (X × D) :=
Finset.univ.filter (fun xd => xd.1 ∈ S ∧ next xd ∉ S)
def disagreementSet (ell : X → A) (next : X × D → X) : Finset (X × D) :=
Finset.univ.filter (fun xd => ell xd.1 ≠ ell (next xd))
abbrev Nonmajor (m : A) := {a : A // a ≠ m}
omit [DecidableEq X] in
theorem exists_max_color (ell : X → A) [Nonempty A] :
∃ m : A, ∀ a, (colorSet ell a).card ≤ (colorSet ell m).card := by
classical
obtain ⟨m, _, hm⟩ := Finset.exists_max_image Finset.univ
(fun a : A => (colorSet ell a).card) Finset.univ_nonempty
exact ⟨m, fun a => hm a (Finset.mem_univ a)⟩
noncomputable def majority (ell : X → A) [Nonempty A] : A :=
Classical.choose (exists_max_color ell)
omit [DecidableEq X] in
theorem majority_maximal (ell : X → A) [Nonempty A] (a : A) :
(colorSet ell a).card ≤ (colorSet ell (majority ell)).card :=
Classical.choose_spec (exists_max_color ell) a
omit [Fintype A] in
theorem nonchosen_color_twice_le (ell : X → A) (m : A)
(maximal : ∀ a, (colorSet ell a).card ≤ (colorSet ell m).card)
(a : A) (ha : a ≠ m) :
2 * (colorSet ell a).card ≤ Fintype.card X := by
have hd : Disjoint (colorSet ell a) (colorSet ell m) := by
apply Finset.disjoint_left.mpr
intro x hx hm
have hxa : ell x = a := by simpa [colorSet] using hx
have hxm : ell x = m := by simpa [colorSet] using hm
exact ha (hxa.symm.trans hxm)
have hu : (colorSet ell a).card + (colorSet ell m).card ≤ Fintype.card X := by
calc
_ = (colorSet ell a ∪ colorSet ell m).card :=
(Finset.card_union_of_disjoint hd).symm
_ ≤ Finset.univ.card := Finset.card_le_card (Finset.subset_univ _)
_ = Fintype.card X := Finset.card_univ
have hm := maximal a
omega
def minorityEquiv (ell : X → A) (m : A) :
(Σ a : Nonmajor m, ↥(colorSet ell a.val)) ≃ ↥(minoritySet ell m) where
toFun t := ⟨t.2.val, by
have hc : ell t.2.val = t.1.val := (Finset.mem_filter.mp t.2.property).2
have hn : ell t.2.val ≠ m := fun h => t.1.property (hc.symm.trans h)
simpa [minoritySet] using hn⟩
invFun x :=
⟨⟨ell x.val, by simpa [minoritySet] using x.property⟩,
⟨x.val, by simp [colorSet]⟩⟩
left_inv t := by
rcases t with ⟨⟨a, ha⟩, ⟨x, hx⟩⟩
have hxa : ell x = a := by simpa [colorSet] using hx
cases hxa
rfl
right_inv x := by apply Subtype.ext; rfl
omit [DecidableEq X] in
theorem minority_card_eq_sum (ell : X → A) (m : A) :
(minoritySet ell m).card = ∑ a : Nonmajor m, (colorSet ell a.val).card := by
have h := Fintype.card_congr (minorityEquiv ell m)
simpa only [Fintype.card_sigma, Fintype.card_coe] using h.symm
def minorityCutEmbedding (ell : X → A) (next : X × D → X) (m : A) :
(Σ a : Nonmajor m, ↥(directedCut next (colorSet ell a.val))) ↪
↥(disagreementSet ell next) where
toFun t := ⟨t.2.val, by
have hc : ell t.2.val.1 = t.1.val ∧ ell (next t.2.val) ≠ t.1.val := by
simpa [directedCut, colorSet] using t.2.property
have hn : ell t.2.val.1 ≠ ell (next t.2.val) :=
fun h => hc.2 (h.symm.trans hc.1)
simpa [disagreementSet] using hn⟩
inj' p q h := by
rcases p with ⟨⟨a, ha⟩, ⟨x, hx⟩⟩
rcases q with ⟨⟨b, hb⟩, ⟨y, hy⟩⟩
have hxy : x = y := congrArg Subtype.val h
cases hxy
have hxa : ell x.1 = a := by
have hc : ell x.1 = a ∧ ell (next x) ≠ a := by
simpa [directedCut, colorSet] using hx
exact hc.1
have hxb : ell x.1 = b := by
have hc : ell x.1 = b ∧ ell (next x) ≠ b := by
simpa [directedCut, colorSet] using hy
exact hc.1
have hab : a = b := hxa.symm.trans hxb
cases hab
rfl
theorem minority_cut_sum_le (ell : X → A) (next : X × D → X) (m : A) :
(∑ a : Nonmajor m, (directedCut next (colorSet ell a.val)).card) ≤
(disagreementSet ell next).card := by
have h := Fintype.card_le_of_injective
(minorityCutEmbedding ell next m) (minorityCutEmbedding ell next m).injective
simpa only [Fintype.card_sigma, Fintype.card_coe] using h
theorem minority_expansion_bound (ell : X → A) (next : X × D → X) (m : A)
(h : ℚ)
(maximal : ∀ a, (colorSet ell a).card ≤ (colorSet ell m).card)
(expansion : ∀ S : Finset X, S.card ≤ Fintype.card X / 2 →
h * (S.card : ℚ) ≤ ((directedCut next S).card : ℚ)) :
h * ((minoritySet ell m).card : ℚ) ≤ ((disagreementSet ell next).card : ℚ) := by
have each (a : Nonmajor m) :
h * ((colorSet ell a.val).card : ℚ) ≤
((directedCut next (colorSet ell a.val)).card : ℚ) := by
apply expansion
have ha := nonchosen_color_twice_le ell m maximal a.val a.property
omega
calc
h * ((minoritySet ell m).card : ℚ) =
∑ a : Nonmajor m, h * ((colorSet ell a.val).card : ℚ) := by
rw [minority_card_eq_sum, Nat.cast_sum, Finset.mul_sum]
_ ≤ ∑ a : Nonmajor m, ((directedCut next (colorSet ell a.val)).card : ℚ) :=
Finset.sum_le_sum (fun a _ => each a)
_ ≤ ((disagreementSet ell next).card : ℚ) := by
exact_mod_cast minority_cut_sum_le ell next m
end CloudCounts
section GraphRounding
open DegreeReplacement PoweringWalks
variable {V E A D : Type*} [Fintype V] [Fintype E] [Fintype A] [Fintype D]
variable [DecidableEq V] [DecidableEq E] [DecidableEq A]
def mismatchSet (G : ConstraintGraph V E A) (ell : E → A) (rounded : V → A) :
Finset E :=
Finset.univ.filter (fun e => ell e ≠ rounded (G.tail e))
def copiedRejectionCount (G : ConstraintGraph V E A) (ell : E → A) : Nat :=
(Finset.univ.filter (fun e => G.accepts e (ell e) (ell (G.reverse e)) = false)).card
def innerDisagreementSet (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) : Finset (E × D) :=
Finset.univ.filter (fun ed => ell ed.1 ≠ ell (innerRotation G H ed).1)
noncomputable def roundLabels [Nonempty A]
(G : ConstraintGraph V E A) (ell : E → A) : V → A :=
fun v => majority (fun e : Cloud G v => ell e.val)
def mismatchFiberEquiv (G : ConstraintGraph V E A) (ell : E → A)
(rounded : V → A) :
(Σ v, ↥(minoritySet (fun e : Cloud G v => ell e.val) (rounded v))) ≃
↥(mismatchSet G ell rounded) where
toFun := by
rintro ⟨v, ⟨⟨e, he⟩, hbad⟩⟩
cases he
exact ⟨e, by simpa [mismatchSet, minoritySet] using hbad⟩
invFun e :=
⟨G.tail e.val, ⟨⟨e.val, rfl⟩, by
simpa [mismatchSet, minoritySet] using e.property⟩⟩
left_inv := by
rintro ⟨v, ⟨⟨e, he⟩, hbad⟩⟩
cases he
rfl
right_inv := by intro e; apply Subtype.ext; rfl
omit [Fintype A] [DecidableEq E] in
theorem mismatch_card_eq_sum (G : ConstraintGraph V E A) (ell : E → A)
(rounded : V → A) :
(mismatchSet G ell rounded).card =
∑ v, (minoritySet (fun e : Cloud G v => ell e.val) (rounded v)).card := by
have h := Fintype.card_congr (mismatchFiberEquiv G ell rounded)
simpa only [Fintype.card_sigma, Fintype.card_coe] using h.symm
def disagreementFiberEquiv (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) :
(Σ v, ↥(disagreementSet (fun e : Cloud G v => ell e.val)
(fun ed => ((H v).rot ed).1))) ≃ ↥(innerDisagreementSet G H ell) where
toFun := by
rintro ⟨v, ⟨⟨⟨e, he⟩, d⟩, hbad⟩⟩
cases he
refine ⟨(e, d), ?_⟩
simpa [disagreementSet, innerDisagreementSet, innerRotation,
cloudIndexEquiv, cloudRotation] using hbad
invFun := by
rintro ⟨⟨e, d⟩, hbad⟩
refine ⟨G.tail e, ⟨(⟨e, rfl⟩, d), ?_⟩⟩
simpa [disagreementSet, innerDisagreementSet, innerRotation,
cloudIndexEquiv, cloudRotation] using hbad
left_inv := by
rintro ⟨v, ⟨⟨⟨e, he⟩, d⟩, hbad⟩⟩
cases he
rfl
right_inv := by intro ed; apply Subtype.ext; rfl
omit [Fintype A] [DecidableEq E] in
theorem disagreement_card_eq_sum (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) :
(innerDisagreementSet G H ell).card =
∑ v, (disagreementSet (fun e : Cloud G v => ell e.val)
(fun ed => ((H v).rot ed).1)).card := by
have h := Fintype.card_congr (disagreementFiberEquiv G H ell)
simpa only [Fintype.card_sigma, Fintype.card_coe] using h.symm
theorem rounded_mismatch_expansion [Nonempty A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(ell : E → A) (h : ℚ)
(expansion : ∀ v (S : Finset (Cloud G v)),
S.card ≤ Fintype.card (Cloud G v) / 2 →
h * (S.card : ℚ) ≤ ((directedCut (fun ed => ((H v).rot ed).1) S).card : ℚ)) :
h * ((mismatchSet G ell (roundLabels G ell)).card : ℚ) ≤
((innerDisagreementSet G H ell).card : ℚ) := by
rw [mismatch_card_eq_sum, disagreement_card_eq_sum, Nat.cast_sum, Nat.cast_sum,
Finset.mul_sum]
apply Finset.sum_le_sum
intro v _
exact minority_expansion_bound (fun e : Cloud G v => ell e.val)
(fun ed => ((H v).rot ed).1) (roundLabels G ell v) h
(majority_maximal (fun e : Cloud G v => ell e.val)) (expansion v)
omit [Fintype V] [Fintype A] [DecidableEq V] [DecidableEq E] in
theorem rounded_endpoint_bound (G : ConstraintGraph V E A)
(ell : E → A) (rounded : V → A) :
G.rejectionCount rounded ≤ copiedRejectionCount G ell +
2 * (mismatchSet G ell rounded).card :=
dart_rejection_count_le G.tail G.reverse G.accepts ell rounded
omit [Fintype V] [Fintype E] [Fintype A] [Fintype D] [DecidableEq V] [DecidableEq E] in
@[simp] theorem copied_satisfied_inl (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) (e : E) (d : D) :
(replacementGraph G H).edgeSatisfied ell (e, Sum.inl d) =
decide (ell e = ell (innerRotation G H (e, d)).1) := rfl
omit [Fintype V] [Fintype E] [Fintype A] [Fintype D] [DecidableEq V] [DecidableEq E] in
@[simp] theorem copied_satisfied_inr (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) (e : E) (u : Unit) :
(replacementGraph G H).edgeSatisfied ell (e, Sum.inr u) =
G.accepts e (ell e) (ell (G.reverse e)) := rfl
omit [Fintype V] [Fintype A] [DecidableEq V] [DecidableEq E] in
theorem replacement_rejection_split (G : ConstraintGraph V E A)
(H : ∀ v, PortGraph (Cloud G v) D) (ell : E → A) :
(replacementGraph G H).rejectionCount ell =
copiedRejectionCount G ell + (innerDisagreementSet G H ell).card := by
classical
simp only [rejectionCount_eq_sum, Fintype.sum_prod_type, Fintype.sum_sum_type,
copied_satisfied_inl, copied_satisfied_inr, decide_eq_false_iff_not,
Fintype.sum_unique, Finset.sum_add_distrib]
simp only [copiedRejectionCount, innerDisagreementSet, Finset.card_eq_sum_ones,
Finset.sum_filter, Fintype.sum_prod_type]
exact Nat.add_comm _ _
theorem replacement_soundness [Nonempty A]
(G : ConstraintGraph V E A) (H : ∀ v, PortGraph (Cloud G v) D)
(expansion : ∀ v (S : Finset (Cloud G v)),
S.card ≤ Fintype.card (Cloud G v) / 2 →
2 * S.card ≤ (directedCut (fun ed => ((H v).rot ed).1) S).card)
(ell : E → A) :
G.rejectionCount (roundLabels G ell) ≤ (replacementGraph G H).rejectionCount ell := by
have hc := rounded_mismatch_expansion G H ell 2 (by
intro v S hS
exact_mod_cast expansion v S hS)
have hcNat : 2 * (mismatchSet G ell (roundLabels G ell)).card ≤
(innerDisagreementSet G H ell).card := by exact_mod_cast hc
rw [replacement_rejection_split]
exact (rounded_endpoint_bound G ell (roundLabels G ell)).trans
(Nat.add_le_add_left hcNat _)
theorem padded_replacement_soundness [Nonempty A]
(G : ConstraintGraph V E A) (dummy : V → Type*) [∀ v, Fintype (dummy v)]
[∀ v, DecidableEq (dummy v)]
(H : ∀ v, PortGraph (Cloud (paddedGraph G dummy) v) D)
(expansion : ∀ v (S : Finset (Cloud (paddedGraph G dummy) v)),
S.card ≤ Fintype.card (Cloud (paddedGraph G dummy) v) / 2 →
2 * S.card ≤ (directedCut (fun ed => ((H v).rot ed).1) S).card)
(ell : PaddedDart G dummy → A) :
G.rejectionCount (roundLabels (paddedGraph G dummy) ell) ≤
(paddedReplacementGraph G dummy H).rejectionCount ell := by
simpa only [paddedReplacementGraph, padded_rejectionCount] using
replacement_soundness (paddedGraph G dummy) H expansion ell
end GraphRounding
theorem combine_counts (R b M c : Nat) (h : ℚ) (hh : 0 < h)
(endpoint : R ≤ b + 2 * M) (cloud : h * (M : ℚ) ≤ (c : ℚ)) :
(R : ℚ) ≤ max 1 (2 / h) * ((b : ℚ) + (c : ℚ)) := by
let K : ℚ := max 1 (2 / h)
have hK : 1 ≤ K := le_max_left _ _
have hK0 : 0 ≤ K := le_trans zero_le_one hK
have hcoef : 2 ≤ K * h := (div_le_iff₀ hh).mp (le_max_right _ _)
have hm : (2 : ℚ) * M ≤ K * c := by
calc
(2 : ℚ) * M ≤ (K * h) * M :=
mul_le_mul_of_nonneg_right hcoef (Nat.cast_nonneg M)
_ = K * (h * M) := mul_assoc _ _ _
_ ≤ K * c := mul_le_mul_of_nonneg_left cloud hK0
have hb : (b : ℚ) ≤ K * b := by
simpa only [one_mul] using mul_le_mul_of_nonneg_right hK (Nat.cast_nonneg b)
have hr : (R : ℚ) ≤ (b : ℚ) + 2 * (M : ℚ) := by exact_mod_cast endpoint
exact hr.trans ((add_le_add hb hm).trans_eq (mul_add K (b : ℚ) (c : ℚ)).symm)
end BinPackingGames.Foundations.PCP.CloudRounding
end OAI