Download lean/OAI/Computability/BinPacking/PCP/RoundTableGap.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 64.1 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/BinPacking/PCP/RoundTableGap.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/BinPacking/PCP/RoundTableGap.lean
-
curl -L -o RoundTableGap.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/BinPacking/PCP/RoundTableGap.lean
64.1 kB
| import Mathlib.Algebra.BigOperators.Fin | |
| import Mathlib.List.OfFn | |
| import OAI.Computability.BinPacking.PCP.PCPIteration | |
| namespace OAI | |
| namespace BinPackingGames.Foundations.PCP.AlphabetTable.Enumeration | |
| open BinPackingGames.Foundations.Hastad | |
| open scoped BigOperators | |
| def bitValue (bit : Bool) : Nat := if bit then 1 else 0 | |
| def boolEquiv : Bool ≃ Fin 2 := finTwoEquiv.symm | |
| @[simp] theorem boolEquiv_val (bit : Bool) : (boolEquiv bit).val = bitValue bit := by | |
| cases bit <;> rfl | |
| def productEquiv {A B : Type*} {a b : Nat} (left : A ≃ Fin a) (right : B ≃ Fin b) : | |
| A × B ≃ Fin (a * b) := | |
| (Equiv.prodCongr left right).trans finProdFinEquiv | |
| @[simp] theorem productEquiv_val {A B : Type*} {a b : Nat} | |
| (left : A ≃ Fin a) (right : B ≃ Fin b) (x : A) (y : B) : | |
| (productEquiv left right (x, y)).val = (left x).val * b + (right y).val := by | |
| change (right y).val + b * (left x).val = _ | |
| simp [Nat.mul_comm, Nat.add_comm] | |
| def sumEquiv {A B : Type*} {a b : Nat} (left : A ≃ Fin a) (right : B ≃ Fin b) : | |
| A ⊕ B ≃ Fin (a + b) := | |
| (Equiv.sumCongr left right).trans finSumFinEquiv | |
| @[simp] theorem sumEquiv_inl_val {A B : Type*} {a b : Nat} | |
| (left : A ≃ Fin a) (right : B ≃ Fin b) (x : A) : | |
| (sumEquiv left right (.inl x)).val = (left x).val := rfl | |
| @[simp] theorem sumEquiv_inr_val {A B : Type*} {a b : Nat} | |
| (left : A ≃ Fin a) (right : B ≃ Fin b) (y : B) : | |
| (sumEquiv left right (.inr y)).val = a + (right y).val := rfl | |
| def tapeCount (q : Nat) : Nat := 2 ^ q | |
| def pairTapeCount (q : Nat) : Nat := 2 ^ (q * q) | |
| def fiveTapeCount (q : Nat) : Nat := pairTapeCount q ^ 5 | |
| def localCount (q : Nat) : Nat := 4 * (2 * tapeCount q) * fiveTapeCount q | |
| def eventCount (m q : Nat) : Nat := m * localCount q | |
| def addressCount (n m q : Nat) : Nat := n * tapeCount q + m * pairTapeCount q | |
| def vertexCount (n m q : Nat) : Nat := eventCount m q + addressCount n m q | |
| def dartCount (m q : Nat) : Nat := eventCount m q * 12 | |
| def cubeEquiv (q : Nat) : Cube (Fin q) ≃ Fin (tapeCount q) := | |
| (Equiv.arrowCongr (Equiv.refl (Fin q)) boolEquiv).trans finFunctionFinEquiv | |
| def cubeRank {q : Nat} (tape : Cube (Fin q)) : Fin (tapeCount q) := cubeEquiv q tape | |
| def cubeUnrank {q : Nat} (index : Fin (tapeCount q)) : Cube (Fin q) := | |
| (cubeEquiv q).symm index | |
| @[simp] theorem cubeUnrank_cubeRank {q : Nat} (tape : Cube (Fin q)) : | |
| cubeUnrank (cubeRank tape) = tape := (cubeEquiv q).symm_apply_apply tape | |
| @[simp] theorem cubeRank_cubeUnrank {q : Nat} (index : Fin (tapeCount q)) : | |
| cubeRank (cubeUnrank index) = index := (cubeEquiv q).apply_symm_apply index | |
| theorem cubeUnrank_digit {q : Nat} (index : Fin (tapeCount q)) (i : Fin q) : | |
| bitValue (cubeUnrank index i) = index.val / 2 ^ i.val % 2 := by | |
| have digit : boolEquiv (cubeUnrank index i) = | |
| (⟨index.val / 2 ^ i.val % 2, Nat.mod_lt _ (by decide)⟩ : Fin 2) := by | |
| change boolEquiv (boolEquiv.symm _) = _ | |
| exact boolEquiv.apply_symm_apply _ | |
| simpa only [boolEquiv_val] using congrArg Fin.val digit | |
| theorem cubeEquiv_val (q : Nat) (tape : Cube (Fin q)) : | |
| (cubeEquiv q tape).val = ∑ i : Fin q, bitValue (tape i) * 2 ^ i.val := by | |
| change (finFunctionFinEquiv (fun i => boolEquiv (tape i))).val = _ | |
| rw [finFunctionFinEquiv_apply] | |
| simp only [boolEquiv_val] | |
| def pairIndex (q : Nat) : Fin q × Fin q ≃ Fin (q * q) := finProdFinEquiv | |
| theorem pairIndex_val (q : Nat) (i j : Fin q) : | |
| (pairIndex q (i, j)).val = i.val * q + j.val := by | |
| change j.val + q * i.val = _ | |
| simp [Nat.mul_comm, Nat.add_comm] | |
| def pairCubeEquiv (q : Nat) : Cube (Fin q × Fin q) ≃ Fin (pairTapeCount q) := | |
| (Equiv.arrowCongr (pairIndex q) (Equiv.refl Bool)).trans (cubeEquiv (q * q)) | |
| def pairCubeRank {q : Nat} (tape : Cube (Fin q × Fin q)) : Fin (pairTapeCount q) := | |
| pairCubeEquiv q tape | |
| def pairCubeUnrank {q : Nat} (index : Fin (pairTapeCount q)) : Cube (Fin q × Fin q) := | |
| (pairCubeEquiv q).symm index | |
| @[simp] theorem pairCubeUnrank_pairCubeRank {q : Nat} (tape : Cube (Fin q × Fin q)) : | |
| pairCubeUnrank (pairCubeRank tape) = tape := (pairCubeEquiv q).symm_apply_apply tape | |
| @[simp] theorem pairCubeRank_pairCubeUnrank {q : Nat} (index : Fin (pairTapeCount q)) : | |
| pairCubeRank (pairCubeUnrank index) = index := (pairCubeEquiv q).apply_symm_apply index | |
| theorem pairCubeEquiv_val (q : Nat) (tape : Cube (Fin q × Fin q)) : | |
| (pairCubeEquiv q tape).val = | |
| ∑ i : Fin (q * q), bitValue (tape ((pairIndex q).symm i)) * 2 ^ i.val := | |
| cubeEquiv_val (q * q) _ | |
| def inputCoordinateEquiv (q : Nat) : | |
| AlphabetReduction.InputCoordinate (Fin q) ≃ Fin (2 * tapeCount q) := | |
| productEquiv boolEquiv (cubeEquiv q) | |
| def fivePairTapesEquiv (q : Nat) : | |
| (Cube (Fin q × Fin q) × Cube (Fin q × Fin q) × Cube (Fin q × Fin q) × | |
| Cube (Fin q × Fin q) × Cube (Fin q × Fin q)) ≃ Fin (fiveTapeCount q) := | |
| (productEquiv (pairCubeEquiv q) | |
| (productEquiv (pairCubeEquiv q) | |
| (productEquiv (pairCubeEquiv q) | |
| (productEquiv (pairCubeEquiv q) (pairCubeEquiv q))))).trans | |
| (finCongr (by simp [fiveTapeCount, pow_succ, Nat.mul_assoc])) | |
| def localEventEquiv (q : Nat) : AlphabetGraph.LocalEvent (Fin q) ≃ Fin (localCount q) := | |
| (productEquiv (Equiv.refl (Fin 4)) | |
| (productEquiv (inputCoordinateEquiv q) (fivePairTapesEquiv q))).trans | |
| (finCongr (by simp [localCount, Nat.mul_assoc])) | |
| def eventEquiv (m q : Nat) : | |
| AlphabetGraph.Event (Fin m) (Fin q) ≃ Fin (eventCount m q) := | |
| productEquiv (Equiv.refl (Fin m)) (localEventEquiv q) | |
| def addressEquiv (n m q : Nat) : | |
| AlphabetGraph.Address (Fin n) (Fin m) (Fin q) ≃ Fin (addressCount n m q) := | |
| sumEquiv (productEquiv (Equiv.refl (Fin n)) (cubeEquiv q)) | |
| (productEquiv (Equiv.refl (Fin m)) (pairCubeEquiv q)) | |
| def vertexEquiv (n m q : Nat) : | |
| QueryIncidence.Vertex (AlphabetGraph.Event (Fin m) (Fin q)) | |
| (AlphabetGraph.Address (Fin n) (Fin m) (Fin q)) ≃ Fin (vertexCount n m q) := | |
| sumEquiv (eventEquiv m q) (addressEquiv n m q) | |
| def dartEquiv (m q : Nat) : | |
| QueryIncidence.Dart (AlphabetGraph.Event (Fin m) (Fin q)) 6 ≃ Fin (dartCount m q) := | |
| (productEquiv (productEquiv (eventEquiv m q) (Equiv.refl (Fin 6))) boolEquiv).trans | |
| (finCongr (by simp [dartCount, Nat.mul_assoc])) | |
| def labelEquiv : QueryIncidence.Label 6 ≃ Fin 64 := cubeEquiv 6 | |
| theorem labelEquiv_val (label : QueryIncidence.Label 6) : | |
| (labelEquiv label).val = ∑ i : Fin 6, bitValue (label i) * 2 ^ i.val := | |
| cubeEquiv_val 6 label | |
| @[simp] theorem inputCoordinateEquiv_val (q : Nat) (side : Bool) (tape : Cube (Fin q)) : | |
| (inputCoordinateEquiv q (side, tape)).val = | |
| bitValue side * tapeCount q + (cubeEquiv q tape).val := by | |
| simp [inputCoordinateEquiv] | |
| theorem fivePairTapesEquiv_val (q : Nat) (f g r₀ r₁ r₂ : Cube (Fin q × Fin q)) : | |
| (fivePairTapesEquiv q (f, g, r₀, r₁, r₂)).val = | |
| (pairCubeEquiv q f).val * pairTapeCount q ^ 4 + | |
| (pairCubeEquiv q g).val * pairTapeCount q ^ 3 + | |
| (pairCubeEquiv q r₀).val * pairTapeCount q ^ 2 + | |
| (pairCubeEquiv q r₁).val * pairTapeCount q + (pairCubeEquiv q r₂).val := by | |
| simp [fivePairTapesEquiv, productEquiv_val, pow_succ, Nat.mul_assoc, Nat.add_assoc] | |
| theorem localEventEquiv_val (q : Nat) (kind : Fin 4) | |
| (coordinate : AlphabetReduction.InputCoordinate (Fin q)) | |
| (f g r₀ r₁ r₂ : Cube (Fin q × Fin q)) : | |
| (localEventEquiv q (kind, coordinate, f, g, r₀, r₁, r₂)).val = | |
| kind.val * (2 * tapeCount q * fiveTapeCount q) + | |
| (inputCoordinateEquiv q coordinate).val * fiveTapeCount q + | |
| (fivePairTapesEquiv q (f, g, r₀, r₁, r₂)).val := by | |
| simp [localEventEquiv, productEquiv_val, Nat.add_assoc] | |
| @[simp] theorem eventEquiv_val (m q : Nat) (edge : Fin m) | |
| (sample : AlphabetGraph.LocalEvent (Fin q)) : | |
| (eventEquiv m q (edge, sample)).val = edge.val * localCount q + | |
| (localEventEquiv q sample).val := by | |
| change (localEventEquiv q sample).val + localCount q * edge.val = _ | |
| simp [Nat.mul_comm, Nat.add_comm] | |
| @[simp] theorem addressEquiv_inl_val (n m q : Nat) (vertex : Fin n) | |
| (tape : Cube (Fin q)) : | |
| (addressEquiv n m q (.inl (vertex, tape))).val = | |
| vertex.val * tapeCount q + (cubeEquiv q tape).val := by | |
| change (cubeEquiv q tape).val + tapeCount q * vertex.val = _ | |
| simp [Nat.mul_comm, Nat.add_comm] | |
| @[simp] theorem addressEquiv_inr_val (n m q : Nat) (edge : Fin m) | |
| (tape : Cube (Fin q × Fin q)) : | |
| (addressEquiv n m q (.inr (edge, tape))).val = | |
| n * tapeCount q + (edge.val * pairTapeCount q + (pairCubeEquiv q tape).val) := by | |
| change n * tapeCount q + ((pairCubeEquiv q tape).val + pairTapeCount q * edge.val) = _ | |
| simp [Nat.mul_comm, Nat.add_comm] | |
| @[simp] theorem vertexEquiv_event_val (n m q : Nat) | |
| (event : AlphabetGraph.Event (Fin m) (Fin q)) : | |
| (vertexEquiv n m q (.inl event)).val = (eventEquiv m q event).val := rfl | |
| @[simp] theorem vertexEquiv_vertexAddress_val (n m q : Nat) (vertex : Fin n) | |
| (tape : Cube (Fin q)) : | |
| (vertexEquiv n m q (.inr (.inl (vertex, tape)))).val = | |
| eventCount m q + (vertex.val * tapeCount q + (cubeEquiv q tape).val) := by | |
| change eventCount m q + (addressEquiv n m q (.inl (vertex, tape))).val = _ | |
| rw [addressEquiv_inl_val] | |
| @[simp] theorem vertexEquiv_edgeAddress_val (n m q : Nat) (edge : Fin m) | |
| (tape : Cube (Fin q × Fin q)) : | |
| (vertexEquiv n m q (.inr (.inr (edge, tape)))).val = | |
| eventCount m q + (n * tapeCount q + | |
| (edge.val * pairTapeCount q + (pairCubeEquiv q tape).val)) := by | |
| change eventCount m q + (addressEquiv n m q (.inr (edge, tape))).val = _ | |
| rw [addressEquiv_inr_val] | |
| @[simp] theorem dartEquiv_val (m q : Nat) | |
| (event : AlphabetGraph.Event (Fin m) (Fin q)) (slot : Fin 6) (orientation : Bool) : | |
| (dartEquiv m q ((event, slot), orientation)).val = | |
| (eventEquiv m q event).val * 12 + slot.val * 2 + bitValue orientation := by | |
| change (boolEquiv orientation).val + 2 * (slot.val + 6 * (eventEquiv m q event).val) = _ | |
| rw [boolEquiv_val] | |
| omega | |
| theorem dartEquiv_reverse_val (m q : Nat) | |
| (event : AlphabetGraph.Event (Fin m) (Fin q)) (slot : Fin 6) (orientation : Bool) : | |
| (dartEquiv m q (QueryIncidence.reverse ((event, slot), orientation))).val = | |
| (eventEquiv m q event).val * 12 + slot.val * 2 + bitValue (!orientation) := | |
| dartEquiv_val m q event slot (!orientation) | |
| def ordered {A : Type*} {count : Nat} (order : A ≃ Fin count) : List A := | |
| List.ofFn order.symm | |
| @[simp] theorem ordered_length {A : Type*} {count : Nat} (order : A ≃ Fin count) : | |
| (ordered order).length = count := by simp [ordered] | |
| theorem mem_ordered {A : Type*} {count : Nat} (order : A ≃ Fin count) (x : A) : | |
| x ∈ ordered order := by | |
| simp only [ordered, List.mem_ofFn] | |
| exact ⟨order x, order.symm_apply_apply x⟩ | |
| theorem ordered_nodup {A : Type*} {count : Nat} (order : A ≃ Fin count) : | |
| (ordered order).Nodup := by | |
| rw [ordered, List.nodup_ofFn] | |
| exact order.symm.injective | |
| @[simp] theorem ordered_refl (n : Nat) : ordered (Equiv.refl (Fin n)) = List.finRange n := rfl | |
| @[simp] theorem ordered_bool : ordered boolEquiv = [false, true] := rfl | |
| theorem ordered_trans_finCongr {A : Type*} {a b : Nat} | |
| (order : A ≃ Fin a) (sameCount : a = b) : | |
| ordered (order.trans (finCongr sameCount)) = ordered order := by | |
| cases sameCount | |
| rfl | |
| theorem ordered_product {A B : Type*} {a b : Nat} | |
| (left : A ≃ Fin a) (right : B ≃ Fin b) : | |
| ordered (productEquiv left right) = | |
| (ordered left).flatMap (fun x => (ordered right).map (fun y => (x, y))) := by | |
| have atIndex (i : Fin a) (j : Fin b) (h : i.val * b + j.val < a * b) : | |
| (productEquiv left right).symm ⟨i.val * b + j.val, h⟩ = | |
| (left.symm i, right.symm j) := by | |
| have same : (⟨i.val * b + j.val, h⟩ : Fin (a * b)) = finProdFinEquiv (i, j) := by | |
| apply Fin.ext | |
| simp [finProdFinEquiv, Nat.mul_comm, Nat.add_comm] | |
| rw [same] | |
| simp [productEquiv] | |
| unfold ordered | |
| rw [List.ofFn_mul] | |
| simp only [atIndex, List.flatMap_def, List.map_ofFn, Function.comp_def] | |
| theorem ordered_sum {A B : Type*} {a b : Nat} | |
| (left : A ≃ Fin a) (right : B ≃ Fin b) : | |
| ordered (sumEquiv left right) = | |
| (ordered left).map Sum.inl ++ (ordered right).map Sum.inr := by | |
| have atLeft (i : Fin a) : | |
| (sumEquiv left right).symm (i.castLE (Nat.le_add_right a b)) = | |
| Sum.inl (left.symm i) := by | |
| change (Equiv.sumCongr left right).symm | |
| (finSumFinEquiv.symm (Fin.castAdd b i)) = _ | |
| rw [finSumFinEquiv_symm_apply_castAdd] | |
| rfl | |
| have atRight (j : Fin b) : | |
| (sumEquiv left right).symm (j.natAdd a) = Sum.inr (right.symm j) := by | |
| change (Equiv.sumCongr left right).symm (finSumFinEquiv.symm (j.natAdd a)) = _ | |
| rw [finSumFinEquiv_symm_apply_natAdd] | |
| rfl | |
| unfold ordered | |
| rw [List.ofFn_add] | |
| simp only [atLeft, atRight, List.map_ofFn, Function.comp_def] | |
| def localEvents (q : Nat) : List (AlphabetGraph.LocalEvent (Fin q)) := | |
| ordered (localEventEquiv q) | |
| @[simp] theorem localEvents_length (q : Nat) : (localEvents q).length = localCount q := | |
| ordered_length _ | |
| theorem ordered_event (m q : Nat) : | |
| ordered (eventEquiv m q) = | |
| (List.finRange m).flatMap (fun edge => (localEvents q).map (fun event => (edge, event))) := by | |
| change ordered (productEquiv (Equiv.refl (Fin m)) (localEventEquiv q)) = _ | |
| rw [ordered_product, ordered_refl] | |
| rfl | |
| theorem ordered_dart (m q : Nat) : | |
| ordered (dartEquiv m q) = | |
| (List.finRange m).flatMap (fun edge => | |
| (localEvents q).flatMap (fun event => | |
| (List.finRange 6).flatMap (fun slot => | |
| [(((edge, event), slot), false), (((edge, event), slot), true)]))) := by | |
| erw [dartEquiv, ordered_trans_finCongr, ordered_product, ordered_product, ordered_event] | |
| simp only [ordered_refl, ordered_bool, List.flatMap_assoc, List.flatMap_map, | |
| List.map_cons, List.map_nil] | |
| @[simp] theorem card_cube (q : Nat) : Fintype.card (Cube (Fin q)) = tapeCount q := by | |
| simpa using Fintype.card_congr (cubeEquiv q) | |
| @[simp] theorem card_pairCube (q : Nat) : | |
| Fintype.card (Cube (Fin q × Fin q)) = pairTapeCount q := by | |
| simpa using Fintype.card_congr (pairCubeEquiv q) | |
| @[simp] theorem card_localEvent (q : Nat) : | |
| Fintype.card (AlphabetGraph.LocalEvent (Fin q)) = localCount q := by | |
| simpa using Fintype.card_congr (localEventEquiv q) | |
| @[simp] theorem card_event (m q : Nat) : | |
| Fintype.card (AlphabetGraph.Event (Fin m) (Fin q)) = eventCount m q := by | |
| simpa using Fintype.card_congr (eventEquiv m q) | |
| @[simp] theorem card_address (n m q : Nat) : | |
| Fintype.card (AlphabetGraph.Address (Fin n) (Fin m) (Fin q)) = addressCount n m q := by | |
| simpa using Fintype.card_congr (addressEquiv n m q) | |
| @[simp] theorem card_vertex (n m q : Nat) : | |
| Fintype.card (QueryIncidence.Vertex (AlphabetGraph.Event (Fin m) (Fin q)) | |
| (AlphabetGraph.Address (Fin n) (Fin m) (Fin q))) = vertexCount n m q := by | |
| simpa using Fintype.card_congr (vertexEquiv n m q) | |
| @[simp] theorem card_dart (m q : Nat) : | |
| Fintype.card (QueryIncidence.Dart (AlphabetGraph.Event (Fin m) (Fin q)) 6) = | |
| dartCount m q := by | |
| simpa using Fintype.card_congr (dartEquiv m q) | |
| @[simp] theorem localCount_formula (q : Nat) : | |
| localCount q = 4 * (2 * 2 ^ q) * (2 ^ (q * q)) ^ 5 := rfl | |
| end BinPackingGames.Foundations.PCP.AlphabetTable.Enumeration | |
| namespace BinPackingGames.Foundations.PCP.AlphabetTable.Relations | |
| open Hastad | |
| open Queries | |
| variable {q : Nat} | |
| def sameAddress (selfLoop : Bool) : RawQuery q → RawQuery q → Bool | |
| | .inl (side, f), .inl (side', g) => ((side == side') || selfLoop) && decide (f = g) | |
| | .inr f, .inr g => decide (f = g) | |
| | _, _ => false | |
| @[simp] theorem sameAddress_refl (selfLoop : Bool) (x : RawQuery q) : | |
| sameAddress selfLoop x x = true := by | |
| rcases x with ⟨side, f⟩ | f <;> simp [sameAddress] | |
| theorem globalize_eq_iff {V E : Type*} [DecidableEq V] | |
| (tail head : V) (edge : E) (selfLoop : Bool) | |
| (hloop : selfLoop = decide (tail = head)) (x y : RawQuery q) : | |
| globalize tail head edge x = globalize tail head edge y ↔ | |
| sameAddress selfLoop x y = true := by | |
| rcases x with ⟨side, f⟩ | f <;> rcases y with ⟨side', g⟩ | g | |
| · cases side <;> cases side' | |
| · simp [globalize, sameAddress] | |
| · simp [globalize, sameAddress, hloop] | |
| · simp [globalize, sameAddress, hloop, | |
| show head = tail ↔ tail = head from eq_comm] | |
| · simp [globalize, sameAddress] | |
| · simp [globalize, sameAddress] | |
| · simp [globalize, sameAddress] | |
| · simp [globalize, sameAddress] | |
| def eqProfile (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (i j : Fin 6) : Bool := sameAddress selfLoop (queries i) (queries j) | |
| @[simp] theorem eqProfile_refl (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (i : Fin 6) : eqProfile selfLoop queries i i = true := sameAddress_refl _ _ | |
| def canonicalSlot (selfLoop : Bool) (queries : Fin 6 → RawQuery q) (i : Fin 6) : Fin 6 := | |
| Fin.find (fun j => eqProfile selfLoop queries j i = true) ⟨i, eqProfile_refl _ _ _⟩ | |
| theorem canonicalSlot_profile (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (i : Fin 6) : eqProfile selfLoop queries (canonicalSlot selfLoop queries i) i = true := by | |
| unfold canonicalSlot | |
| exact Fin.find_spec (p := fun j => eqProfile selfLoop queries j i = true) | |
| ⟨i, eqProfile_refl _ _ _⟩ | |
| theorem canonicalSlot_le (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (i j : Fin 6) (h : eqProfile selfLoop queries j i = true) : | |
| canonicalSlot selfLoop queries i ≤ j := | |
| Fin.find_le_of_pos ⟨i, eqProfile_refl _ _ _⟩ h | |
| def RepeatedConsistent (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (label : QueryIncidence.Label 6) : Prop := | |
| ∀ i j, eqProfile selfLoop queries i j = true → label i = label j | |
| instance repeatedConsistentDecidable (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (label : QueryIncidence.Label 6) : Decidable (RepeatedConsistent selfLoop queries label) := by | |
| unfold RepeatedConsistent | |
| infer_instance | |
| def incidenceAccept (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (accept : QueryIncidence.Label 6 → Bool) (slot : Fin 6) | |
| (left right : QueryIncidence.Label 6) : Bool := | |
| decide (accept left = true ∧ RepeatedConsistent selfLoop queries left) && | |
| decide (left (canonicalSlot selfLoop queries slot) = right 0) | |
| def predicate (selfLoop : Bool) (queries : Fin 6 → RawQuery q) | |
| (accept : QueryIncidence.Label 6 → Bool) (slot : Fin 6) (orientation : Bool) | |
| (a b : QueryIncidence.Label 6) : Bool := | |
| if orientation then incidenceAccept selfLoop queries accept slot b a | |
| else incidenceAccept selfLoop queries accept slot a b | |
| def relation (P : Fin q → Fin q → Bool) (selfLoop : Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) : | |
| GraphTables.RelationTable := | |
| GraphTables.relationOf fun a b => | |
| predicate selfLoop (query P event) (AssignmentTester.eventAccepts event.1) | |
| slot orientation (Enumeration.labelEquiv.symm a) (Enumeration.labelEquiv.symm b) | |
| @[simp] theorem relationAt_relation (P : Fin q → Fin q → Bool) (selfLoop : Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) | |
| (a b : GraphTables.Label) : | |
| GraphTables.relationAt (relation P selfLoop event slot orientation) a b = | |
| predicate selfLoop (query P event) (AssignmentTester.eventAccepts event.1) | |
| slot orientation (Enumeration.labelEquiv.symm a) (Enumeration.labelEquiv.symm b) := by | |
| exact GraphTables.relationAt_relationOf _ _ _ | |
| theorem relation_reverse (P : Fin q → Fin q → Bool) (selfLoop : Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) | |
| (a b : GraphTables.Label) : | |
| GraphTables.relationAt (relation P selfLoop event slot (!orientation)) b a = | |
| GraphTables.relationAt (relation P selfLoop event slot orientation) a b := by | |
| simp only [relationAt_relation] | |
| cases orientation <;> rfl | |
| def oldPredicate (old : Vector Bool (q * q)) (a b : Fin q) : Bool := | |
| old[(finProdFinEquiv (a, b) : Fin (q * q))] | |
| def relationFromTable (old : Vector Bool (q * q)) (selfLoop : Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) : | |
| GraphTables.RelationTable := relation (oldPredicate old) selfLoop event slot orientation | |
| @[simp] theorem oldPredicate_relationAt (old : GraphTables.RelationTable) | |
| (a b : GraphTables.Label) : oldPredicate old a b = GraphTables.relationAt old a b := rfl | |
| theorem relationFromTable_eq (old : GraphTables.RelationTable) (selfLoop : Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin 64)) (slot : Fin 6) (orientation : Bool) : | |
| relationFromTable old selfLoop event slot orientation = | |
| relation (GraphTables.relationAt old) selfLoop event slot orientation := rfl | |
| variable {V E : Type*} [DecidableEq V] [DecidableEq E] | |
| omit [DecidableEq E] in | |
| theorem eqProfile_query_iff (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (i j : Fin 6) : | |
| eqProfile (decide (G.tail e = G.head e)) (query (G.accepts e) event) i j = true ↔ | |
| (AlphabetGraph.verifier G).query (e, event) i = | |
| (AlphabetGraph.verifier G).query (e, event) j := by | |
| rw [← globalize_query G e event i, ← globalize_query G e event j] | |
| exact (globalize_eq_iff (G.tail e) (G.head e) e _ rfl _ _).symm | |
| theorem canonicalSlot_eq (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) : | |
| canonicalSlot (decide (G.tail e = G.head e)) (query (G.accepts e) event) slot = | |
| QueryIncidence.canonicalSlot (AlphabetGraph.verifier G) (e, event) slot := by | |
| unfold canonicalSlot QueryIncidence.canonicalSlot | |
| apply Fin.find_congr' | |
| exact eqProfile_query_iff G e event _ slot | |
| omit [DecidableEq E] in | |
| theorem repeatedConsistent_iff (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (label : QueryIncidence.Label 6) : | |
| RepeatedConsistent (decide (G.tail e = G.head e)) (query (G.accepts e) event) label ↔ | |
| QueryIncidence.RepeatedConsistent (AlphabetGraph.verifier G) (e, event) label := by | |
| constructor | |
| · intro h i j hij | |
| exact h i j ((eqProfile_query_iff G e event i j).mpr hij) | |
| · intro h i j hij | |
| exact h i j ((eqProfile_query_iff G e event i j).mp hij) | |
| omit [DecidableEq V] [DecidableEq E] in | |
| theorem verifier_accepts (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (label : QueryIncidence.Label 6) : | |
| (AlphabetGraph.verifier G).accepts (e, event) label = | |
| AssignmentTester.eventAccepts event.1 label := by | |
| rcases event with ⟨kind, k, f, g, r₀, r₁, r₂⟩ | |
| rfl | |
| theorem incidenceAccept_eq (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) | |
| (left right : QueryIncidence.Label 6) : | |
| incidenceAccept (decide (G.tail e = G.head e)) (query (G.accepts e) event) | |
| (AssignmentTester.eventAccepts event.1) slot left right = | |
| QueryIncidence.incidenceAccept (AlphabetGraph.verifier G) (by decide) (e, event) slot | |
| left right := by | |
| simp only [incidenceAccept, QueryIncidence.incidenceAccept, QueryIncidence.LeftValid, | |
| verifier_accepts, repeatedConsistent_iff, canonicalSlot_eq, | |
| QueryIncidence.decodeRight, QueryIncidence.zeroSlot] | |
| rfl | |
| theorem relationAt_relation_graph (G : ConstraintGraph V E (Fin q)) (e : E) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) | |
| (a b : GraphTables.Label) : | |
| GraphTables.relationAt | |
| (relation (G.accepts e) (decide (G.tail e = G.head e)) event slot orientation) a b = | |
| (AlphabetGraph.graph G).accepts (((e, event), slot), orientation) | |
| (Enumeration.labelEquiv.symm a) (Enumeration.labelEquiv.symm b) := by | |
| rw [relationAt_relation] | |
| cases orientation <;> | |
| exact incidenceAccept_eq G e event slot _ _ | |
| end BinPackingGames.Foundations.PCP.AlphabetTable.Relations | |
| namespace BinPackingGames.Foundations.PCP.AlphabetTable.Addresses | |
| open BinPackingGames.Foundations.Hastad | |
| open Enumeration | |
| abbrev Terms := List (Fin 5 × Nat) | |
| structure Field (bound : Nat) where | |
| terms : Terms | |
| offset : Fin bound | |
| def values (n m edge tail head : Nat) : Fin 5 → Nat := ![n, m, edge, tail, head] | |
| def eval {bound : Nat} (field : Field bound) (inputs : Fin 5 → Nat) : Nat := | |
| Emitter.affineValue field.terms inputs field.offset.val | |
| def fieldBound (q : Nat) : Nat := | |
| 12 * localCount q + tapeCount q + pairTapeCount q + 1 | |
| theorem fieldBound_pos (q : Nat) : 0 < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| theorem tapeCount_lt_bound (q : Nat) : tapeCount q < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| theorem pairTapeCount_lt_bound (q : Nat) : pairTapeCount q < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| theorem localCount_lt_bound (q : Nat) : localCount q < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| theorem local_add_pair_lt_bound (q : Nat) : localCount q + pairTapeCount q < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| theorem twelve_local_lt_bound (q : Nat) : 12 * localCount q < fieldBound q := by | |
| unfold fieldBound | |
| omega | |
| def zeroOffset (q : Nat) : Fin (fieldBound q) := ⟨0, fieldBound_pos q⟩ | |
| def eventOffset (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) : Fin (fieldBound q) := | |
| ⟨(localEventEquiv q event).val, | |
| (localEventEquiv q event).isLt.trans (localCount_lt_bound q)⟩ | |
| def rawQueryOffset (q : Nat) : Queries.RawQuery q → Fin (fieldBound q) | |
| | .inl (_, tape) => | |
| ⟨(cubeEquiv q tape).val, (cubeEquiv q tape).isLt.trans (tapeCount_lt_bound q)⟩ | |
| | .inr tape => | |
| ⟨(pairCubeEquiv q tape).val, (pairCubeEquiv q tape).isLt.trans (pairTapeCount_lt_bound q)⟩ | |
| def reverseOffset (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : Fin (fieldBound q) := | |
| ⟨(localEventEquiv q event).val * 12 + slot.val * 2 + bitValue (!orientation), by | |
| have he := (localEventEquiv q event).isLt | |
| have hs := slot.isLt | |
| have hb : bitValue (!orientation) < 2 := by | |
| simpa only [boolEquiv_val] using (boolEquiv (!orientation)).isLt | |
| have hbound := twelve_local_lt_bound q | |
| omega⟩ | |
| def headerVertices (q : Nat) : Field (fieldBound q) := | |
| ⟨[(0, tapeCount q), (1, localCount q + pairTapeCount q)], zeroOffset q⟩ | |
| def headerDarts (q : Nat) : Field (fieldBound q) := | |
| ⟨[(1, 12 * localCount q)], zeroOffset q⟩ | |
| def eventVertexField (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) : | |
| Field (fieldBound q) := | |
| ⟨[(2, localCount q)], eventOffset q event⟩ | |
| def vertexQueryTerms (q : Nat) (side : Bool) : Terms := | |
| [(1, localCount q), (if side then 4 else 3, tapeCount q)] | |
| def edgeQueryTerms (q : Nat) : Terms := | |
| [(1, localCount q), (0, tapeCount q), (2, pairTapeCount q)] | |
| def rawQueryTerms (q : Nat) : Queries.RawQuery q → Terms | |
| | .inl (side, _) => vertexQueryTerms q side | |
| | .inr _ => edgeQueryTerms q | |
| def rawQueryField (q : Nat) (query : Queries.RawQuery q) : Field (fieldBound q) := | |
| ⟨rawQueryTerms q query, rawQueryOffset q query⟩ | |
| def reverseDartField (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : Field (fieldBound q) := | |
| ⟨[(2, 12 * localCount q)], reverseOffset q event slot orientation⟩ | |
| theorem headerVertices_eval (q n m edge tail head : Nat) : | |
| eval (headerVertices q) (values n m edge tail head) = vertexCount n m q := by | |
| simp [eval, headerVertices, values, zeroOffset, Emitter.affineValue, | |
| vertexCount, eventCount, addressCount, Nat.mul_add, | |
| Nat.mul_comm, Nat.add_comm, Nat.add_assoc] | |
| theorem headerDarts_eval (q n m edge tail head : Nat) : | |
| eval (headerDarts q) (values n m edge tail head) = dartCount m q := by | |
| simp [eval, headerDarts, values, zeroOffset, Emitter.affineValue, | |
| dartCount, eventCount, Nat.mul_comm, Nat.mul_assoc] | |
| theorem eventVertexField_eval (n m q : Nat) (edge : Fin m) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (tail head : Nat) : | |
| eval (eventVertexField q event) (values n m edge.val tail head) = | |
| (vertexEquiv n m q (.inl (edge, event))).val := by | |
| rw [vertexEquiv_event_val, eventEquiv_val] | |
| simp [eval, eventVertexField, eventOffset, values, Emitter.affineValue, Nat.mul_comm] | |
| theorem rawQueryField_eval (n m q : Nat) (edge : Fin m) (tail head : Fin n) | |
| (query : Queries.RawQuery q) : | |
| eval (rawQueryField q query) (values n m edge.val tail.val head.val) = | |
| (vertexEquiv n m q (.inr (Queries.globalize tail head edge query))).val := by | |
| cases query with | |
| | inl query => | |
| rcases query with ⟨side, tape⟩ | |
| cases side <;> | |
| simp [eval, rawQueryField, rawQueryTerms, vertexQueryTerms, rawQueryOffset, | |
| values, Emitter.affineValue, Queries.globalize, eventCount, | |
| Nat.mul_comm, Nat.add_assoc] | |
| | inr tape => | |
| simp [eval, rawQueryField, rawQueryTerms, edgeQueryTerms, rawQueryOffset, | |
| values, Emitter.affineValue, Queries.globalize, eventCount, | |
| Nat.mul_comm, Nat.add_assoc] | |
| theorem reverseDartField_eval (n m q : Nat) (edge : Fin m) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) | |
| (tail head : Nat) : | |
| eval (reverseDartField q event slot orientation) (values n m edge.val tail head) = | |
| (dartEquiv m q (QueryIncidence.reverse (((edge, event), slot), orientation))).val := by | |
| rw [dartEquiv_reverse_val, eventEquiv_val] | |
| simp [eval, reverseDartField, reverseOffset, values, Emitter.affineValue, | |
| Nat.mul_add, Nat.mul_comm, Nat.mul_assoc, | |
| Nat.add_assoc] | |
| def queryEventTerms (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) : Terms := | |
| rawQueryTerms q (Queries.query (fun _ _ => false) event slot) | |
| theorem rawQueryTerms_query (q : Nat) (P : Fin q → Fin q → Bool) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) : | |
| rawQueryTerms q (Queries.query P event slot) = queryEventTerms q event slot := by | |
| rcases event with ⟨kind, ⟨side, tape⟩, f, g, r₀, r₁, r₂⟩ | |
| by_cases hk₀ : kind = 0 <;> by_cases hk₁ : kind = 1 <;> by_cases hk₂ : kind = 2 <;> | |
| simp only [queryEventTerms, Queries.query, hk₀, hk₁, hk₂, ite_true, ite_false] | |
| all_goals split_ifs <;> rfl | |
| def queryEventOffset (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (P : Fin q → Fin q → Bool) : Fin (fieldBound q) := | |
| rawQueryOffset q (Queries.query P event slot) | |
| def fieldForQueryEvent (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (P : Fin q → Fin q → Bool) : Field (fieldBound q) := | |
| ⟨queryEventTerms q event slot, queryEventOffset q event slot P⟩ | |
| theorem fieldForQueryEvent_eq_rawQueryField (q : Nat) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) | |
| (P : Fin q → Fin q → Bool) : | |
| fieldForQueryEvent q event slot P = rawQueryField q (Queries.query P event slot) := by | |
| unfold fieldForQueryEvent queryEventOffset rawQueryField | |
| rw [rawQueryTerms_query] | |
| theorem fieldForQueryEvent_eval (n m q : Nat) (edge : Fin m) (tail head : Fin n) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) | |
| (P : Fin q → Fin q → Bool) : | |
| eval (fieldForQueryEvent q event slot P) (values n m edge.val tail.val head.val) = | |
| (vertexEquiv n m q | |
| (.inr (Queries.globalize tail head edge (Queries.query P event slot)))).val := by | |
| rw [fieldForQueryEvent_eq_rawQueryField] | |
| exact rawQueryField_eval n m q edge tail head _ | |
| theorem fieldForQueryEvent_eval_verifier (n m q : Nat) | |
| (G : ConstraintGraph (Fin n) (Fin m) (Fin q)) (edge : Fin m) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) : | |
| eval (fieldForQueryEvent q event slot (G.accepts edge)) | |
| (values n m edge.val (G.tail edge).val (G.head edge).val) = | |
| (vertexEquiv n m q (.inr ((AlphabetGraph.verifier G).query (edge, event) slot))).val := by | |
| rw [← Queries.globalize_query G edge event slot] | |
| exact fieldForQueryEvent_eval n m q edge (G.tail edge) (G.head edge) event slot _ | |
| def dartTailTerms (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : Terms := | |
| if orientation then queryEventTerms q event slot else [(2, localCount q)] | |
| def dartTailOffset (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) (P : Fin q → Fin q → Bool) : Fin (fieldBound q) := | |
| if orientation then queryEventOffset q event slot P else eventOffset q event | |
| def fieldForDartTail (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) (P : Fin q → Fin q → Bool) : Field (fieldBound q) := | |
| ⟨dartTailTerms q event slot orientation, dartTailOffset q event slot orientation P⟩ | |
| theorem fieldForDartTail_eval (n m q : Nat) (edge : Fin m) (tail head : Fin n) | |
| (event : AlphabetGraph.LocalEvent (Fin q)) (slot : Fin 6) (orientation : Bool) | |
| (P : Fin q → Fin q → Bool) : | |
| eval (fieldForDartTail q event slot orientation P) | |
| (values n m edge.val tail.val head.val) = | |
| (vertexEquiv n m q (if orientation then | |
| .inr (Queries.globalize tail head edge (Queries.query P event slot)) | |
| else .inl (edge, event))).val := by | |
| cases orientation with | |
| | false => exact eventVertexField_eval n m q edge event tail.val head.val | |
| | true => exact fieldForQueryEvent_eval n m q edge tail head event slot P | |
| def CoefficientsBounded (q : Nat) (terms : Terms) : Prop := | |
| ∀ term ∈ terms, term.2 < fieldBound q | |
| theorem headerVertices_coefficients (q : Nat) : CoefficientsBounded q (headerVertices q).terms := by | |
| simp only [CoefficientsBounded, headerVertices, List.mem_cons, List.not_mem_nil, or_false] | |
| intro term h | |
| rcases h with rfl | rfl | |
| · exact tapeCount_lt_bound q | |
| · exact local_add_pair_lt_bound q | |
| theorem headerDarts_coefficients (q : Nat) : CoefficientsBounded q (headerDarts q).terms := by | |
| intro term h | |
| have heq : term = (1, 12 * localCount q) := by simpa [headerDarts] using h | |
| subst term | |
| exact twelve_local_lt_bound q | |
| theorem eventVertexField_coefficients (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) : | |
| CoefficientsBounded q (eventVertexField q event).terms := by | |
| intro term h | |
| have heq : term = (2, localCount q) := by simpa [eventVertexField] using h | |
| subst term | |
| exact localCount_lt_bound q | |
| theorem rawQueryTerms_coefficients (q : Nat) (query : Queries.RawQuery q) : | |
| CoefficientsBounded q (rawQueryTerms q query) := by | |
| cases query with | |
| | inl query => | |
| rcases query with ⟨side, tape⟩ | |
| intro term h | |
| simp only [rawQueryTerms, vertexQueryTerms, List.mem_cons, List.not_mem_nil, or_false] at h | |
| rcases h with rfl | rfl | |
| · exact localCount_lt_bound q | |
| · exact tapeCount_lt_bound q | |
| | inr tape => | |
| intro term h | |
| simp only [rawQueryTerms, edgeQueryTerms, List.mem_cons, List.not_mem_nil, or_false] at h | |
| rcases h with rfl | rfl | rfl | |
| · exact localCount_lt_bound q | |
| · exact tapeCount_lt_bound q | |
| · exact pairTapeCount_lt_bound q | |
| theorem queryEventTerms_coefficients (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) : CoefficientsBounded q (queryEventTerms q event slot) := | |
| rawQueryTerms_coefficients q _ | |
| theorem reverseDartField_coefficients (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : | |
| CoefficientsBounded q (reverseDartField q event slot orientation).terms := by | |
| intro term h | |
| have heq : term = (2, 12 * localCount q) := by simpa [reverseDartField] using h | |
| subst term | |
| exact twelve_local_lt_bound q | |
| theorem rawQueryTerms_length_le (q : Nat) (query : Queries.RawQuery q) : | |
| (rawQueryTerms q query).length ≤ 3 := by | |
| cases query with | |
| | inl query => rcases query with ⟨side, tape⟩; simp [rawQueryTerms, vertexQueryTerms] | |
| | inr tape => simp [rawQueryTerms, edgeQueryTerms] | |
| theorem queryEventTerms_length_le (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) : (queryEventTerms q event slot).length ≤ 3 := | |
| rawQueryTerms_length_le q _ | |
| theorem dartTailTerms_coefficients (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : | |
| CoefficientsBounded q (dartTailTerms q event slot orientation) := by | |
| cases orientation with | |
| | false => exact eventVertexField_coefficients q event | |
| | true => exact queryEventTerms_coefficients q event slot | |
| theorem dartTailTerms_length_le (q : Nat) (event : AlphabetGraph.LocalEvent (Fin q)) | |
| (slot : Fin 6) (orientation : Bool) : | |
| (dartTailTerms q event slot orientation).length ≤ 3 := by | |
| cases orientation with | |
| | false => simp [dartTailTerms] | |
| | true => exact queryEventTerms_length_le q event slot | |
| theorem offset_lt {bound : Nat} (field : Field bound) : field.offset.val < bound := | |
| field.offset.isLt | |
| end BinPackingGames.Foundations.PCP.AlphabetTable.Addresses | |
| namespace BinPackingGames.Foundations.PCP.AlphabetTable.Table | |
| variable {q : Nat} | |
| def rowFromDart (input : GenericGraphTables.Table q) | |
| (dart : QueryIncidence.Dart (AlphabetGraph.Event (Fin input.darts) (Fin q)) 6) : | |
| GraphTables.DartRow (Enumeration.vertexCount input.vertices input.darts q) | |
| (Enumeration.dartCount input.darts q) := | |
| let edge := dart.1.1.1 | |
| let event := dart.1.1.2 | |
| let slot := dart.1.2 | |
| let old := input.rows[edge] | |
| let head := input.rows[old.reverseIndex].tail | |
| { tail := Enumeration.vertexEquiv input.vertices input.darts q | |
| (if dart.2 then | |
| .inr (Queries.globalize old.tail head edge | |
| (Queries.query (GenericGraphTables.relationAt old.relation) event slot)) | |
| else .inl (edge, event)) | |
| reverseIndex := Enumeration.dartEquiv input.darts q (dart.1, !dart.2) | |
| relation := Relations.relationFromTable old.relation (decide (old.tail = head)) | |
| event slot dart.2 } | |
| def rows (input : GenericGraphTables.Table q) : | |
| GraphTables.Rows (Enumeration.vertexCount input.vertices input.darts q) | |
| (Enumeration.dartCount input.darts q) := | |
| Vector.ofFn (fun index => | |
| rowFromDart input ((Enumeration.dartEquiv input.darts q).symm index)) | |
| @[simp] theorem rows_at (input : GenericGraphTables.Table q) | |
| (index : Fin (Enumeration.dartCount input.darts q)) : | |
| (rows input)[index] = | |
| rowFromDart input ((Enumeration.dartEquiv input.darts q).symm index) := by | |
| simp [rows] | |
| theorem rows_reverseIndex (input : GenericGraphTables.Table q) | |
| (index : Fin (Enumeration.dartCount input.darts q)) : | |
| (rows input)[index].reverseIndex = | |
| Enumeration.dartEquiv input.darts q | |
| (((Enumeration.dartEquiv input.darts q).symm index).1, | |
| !((Enumeration.dartEquiv input.darts q).symm index).2) := by | |
| simp [rows, rowFromDart] | |
| private theorem dartRow_ext {n m : Nat} {left right : GraphTables.DartRow n m} | |
| (ht : left.tail = right.tail) (hr : left.reverseIndex = right.reverseIndex) | |
| (hp : left.relation = right.relation) : left = right := by | |
| cases left | |
| cases right | |
| cases ht | |
| cases hr | |
| cases hp | |
| rfl | |
| private theorem relation_ext {left right : GraphTables.RelationTable} | |
| (h : ∀ a b, GraphTables.relationAt left a b = GraphTables.relationAt right a b) : | |
| left = right := by | |
| apply Vector.ext | |
| intro i hi | |
| let labels := GraphTables.relationIndex.symm (⟨i, hi⟩ : Fin 4096) | |
| have index : GraphTables.relationIndex labels = (⟨i, hi⟩ : Fin 4096) := | |
| GraphTables.relationIndex.apply_symm_apply _ | |
| have point := h labels.1 labels.2 | |
| simpa only [GraphTables.relationAt, index, Fin.getElem_fin] using point | |
| theorem rowFromDart_eq_graphRow (input : GenericGraphTables.Table q) | |
| (dart : QueryIncidence.Dart (AlphabetGraph.Event (Fin input.darts) (Fin q)) 6) : | |
| rowFromDart input dart = | |
| { tail := Enumeration.vertexEquiv input.vertices input.darts q | |
| ((AlphabetGraph.graph (GenericGraphTables.semantics input)).tail dart) | |
| reverseIndex := Enumeration.dartEquiv input.darts q | |
| ((AlphabetGraph.graph (GenericGraphTables.semantics input)).reverse dart) | |
| relation := GraphTables.relationOf (fun a b => | |
| (AlphabetGraph.graph (GenericGraphTables.semantics input)).accepts dart | |
| (Enumeration.labelEquiv.symm a) (Enumeration.labelEquiv.symm b)) } := by | |
| rcases dart with ⟨⟨⟨edge, event⟩, slot⟩, orientation⟩ | |
| apply dartRow_ext | |
| · cases orientation with | |
| | false => rfl | |
| | true => | |
| have query := Queries.globalize_query (GenericGraphTables.semantics input) | |
| edge event slot | |
| have predicate : (GenericGraphTables.semantics input).accepts edge = | |
| GenericGraphTables.relationAt input.rows[edge].relation := rfl | |
| rw [predicate] at query | |
| simpa only [rowFromDart, AlphabetGraph.graph, QueryIncidence.graph, | |
| QueryIncidence.tail, GenericGraphTables.semantics_tail, | |
| ConstraintGraph.head, GenericGraphTables.semantics_reverse, | |
| ite_true] using | |
| congrArg (fun address => Enumeration.vertexEquiv input.vertices input.darts q | |
| (.inr address)) query | |
| · rfl | |
| · apply relation_ext | |
| intro a b | |
| rw [GraphTables.relationAt_relationOf] | |
| have relation := Relations.relationAt_relation_graph (GenericGraphTables.semantics input) | |
| edge event slot orientation a b | |
| have predicate : (GenericGraphTables.semantics input).accepts edge = | |
| Relations.oldPredicate input.rows[edge].relation := rfl | |
| rw [predicate] at relation | |
| simpa only [rowFromDart, Relations.relationFromTable, | |
| GenericGraphTables.semantics_tail, ConstraintGraph.head, | |
| GenericGraphTables.semantics_reverse] using! relation | |
| theorem rows_eq_graphRows (input : GenericGraphTables.Table q) : | |
| rows input = GraphTables.graphRows | |
| (GraphTables.enumeratedGraph (AlphabetGraph.graph (GenericGraphTables.semantics input)) | |
| (Enumeration.vertexEquiv input.vertices input.darts q) | |
| (Enumeration.dartEquiv input.darts q) Enumeration.labelEquiv) := by | |
| apply Vector.ext | |
| intro i hi | |
| simp only [rows, GraphTables.graphRows, Vector.getElem_ofFn] | |
| exact rowFromDart_eq_graphRow input | |
| ((Enumeration.dartEquiv input.darts q).symm ⟨i, hi⟩) | |
| theorem rows_valid (input : GenericGraphTables.Table q) : GraphTables.Valid (rows input) := by | |
| rw [rows_eq_graphRows] | |
| exact GraphTables.graphRows_valid _ | |
| def build (input : GenericGraphTables.Table q) : GraphTables.Table where | |
| vertices := Enumeration.vertexCount input.vertices input.darts q | |
| darts := Enumeration.dartCount input.darts q | |
| rows := rows input | |
| valid := rows_valid input | |
| @[simp] theorem build_vertices (input : GenericGraphTables.Table q) : | |
| (build input).vertices = Enumeration.vertexCount input.vertices input.darts q := rfl | |
| @[simp] theorem build_darts (input : GenericGraphTables.Table q) : | |
| (build input).darts = Enumeration.dartCount input.darts q := rfl | |
| private theorem table_rows_congr {n m : Nat} {left right : GraphTables.Rows n m} | |
| (h : left = right) (hl : GraphTables.Valid left) (hr : GraphTables.Valid right) : | |
| (⟨n, m, left, hl⟩ : GraphTables.Table) = ⟨n, m, right, hr⟩ := by | |
| subst right | |
| rfl | |
| private theorem semantics_rows_congr {n m : Nat} {left right : GraphTables.Rows n m} | |
| (h : left = right) (hl : GraphTables.Valid left) (hr : GraphTables.Valid right) : | |
| GraphTables.semantics (⟨n, m, left, hl⟩ : GraphTables.Table) = | |
| GraphTables.semantics (⟨n, m, right, hr⟩ : GraphTables.Table) := by | |
| subst right | |
| rfl | |
| theorem build_eq_ofEnumeratedGraph (input : GenericGraphTables.Table q) : | |
| build input = | |
| GraphTables.ofEnumeratedGraph (AlphabetGraph.graph (GenericGraphTables.semantics input)) | |
| (Enumeration.vertexEquiv input.vertices input.darts q) | |
| (Enumeration.dartEquiv input.darts q) Enumeration.labelEquiv := by | |
| exact table_rows_congr (rows_eq_graphRows input) (rows_valid input) | |
| (GraphTables.graphRows_valid _) | |
| theorem semantics_build (input : GenericGraphTables.Table q) : | |
| GraphTables.semantics (build input) = | |
| GraphTables.enumeratedGraph (AlphabetGraph.graph (GenericGraphTables.semantics input)) | |
| (Enumeration.vertexEquiv input.vertices input.darts q) | |
| (Enumeration.dartEquiv input.darts q) Enumeration.labelEquiv := by | |
| exact (semantics_rows_congr (rows_eq_graphRows input) (rows_valid input) | |
| (GraphTables.graphRows_valid _)).trans (GraphTables.semantics_ofGraph _) | |
| theorem decode_build (input : GenericGraphTables.Table q) : | |
| GraphTables.decodeTableBits (GraphTables.tableBits (build input)) = | |
| some (GraphTables.ofEnumeratedGraph | |
| (AlphabetGraph.graph (GenericGraphTables.semantics input)) | |
| (Enumeration.vertexEquiv input.vertices input.darts q) | |
| (Enumeration.dartEquiv input.darts q) Enumeration.labelEquiv) := by | |
| rw [GraphTables.decodeTableBits_encoded, build_eq_ofEnumeratedGraph] | |
| theorem edgeSatisfied_build (input : GenericGraphTables.Table q) | |
| (labeling : QueryIncidence.Vertex (AlphabetGraph.Event (Fin input.darts) (Fin q)) | |
| (AlphabetGraph.Address (Fin input.vertices) (Fin input.darts) (Fin q)) → | |
| QueryIncidence.Label 6) | |
| (dart : QueryIncidence.Dart (AlphabetGraph.Event (Fin input.darts) (Fin q)) 6) : | |
| (GraphTables.semantics (build input)).edgeSatisfied | |
| (fun v => Enumeration.labelEquiv | |
| (labeling ((Enumeration.vertexEquiv input.vertices input.darts q).symm v))) | |
| (Enumeration.dartEquiv input.darts q dart) = | |
| (AlphabetGraph.graph (GenericGraphTables.semantics input)).edgeSatisfied labeling dart := by | |
| rw [semantics_build] | |
| exact GraphTables.enumeratedGraph_edgeSatisfied _ _ _ _ labeling dart | |
| theorem rejectionCount_build (input : GenericGraphTables.Table q) | |
| (labeling : QueryIncidence.Vertex (AlphabetGraph.Event (Fin input.darts) (Fin q)) | |
| (AlphabetGraph.Address (Fin input.vertices) (Fin input.darts) (Fin q)) → | |
| QueryIncidence.Label 6) : | |
| (GraphTables.semantics (build input)).rejectionCount | |
| (fun v => Enumeration.labelEquiv | |
| (labeling ((Enumeration.vertexEquiv input.vertices input.darts q).symm v))) = | |
| (AlphabetGraph.graph (GenericGraphTables.semantics input)).rejectionCount labeling := by | |
| rw [semantics_build] | |
| exact GraphTables.enumeratedGraph_rejectionCount _ _ _ _ labeling | |
| theorem perfect_completeness [Nonempty (Fin q)] (input : GenericGraphTables.Table q) | |
| (satisfied : (GenericGraphTables.semantics input).Satisfiable) : | |
| (GraphTables.semantics (build input)).Satisfiable := by | |
| obtain ⟨labeling, accepted⟩ := | |
| AlphabetGraph.perfect_completeness (GenericGraphTables.semantics input) satisfied | |
| refine ⟨fun v => Enumeration.labelEquiv | |
| (labeling ((Enumeration.vertexEquiv input.vertices input.darts q).symm v)), ?_⟩ | |
| intro index | |
| have h := edgeSatisfied_build input labeling | |
| ((Enumeration.dartEquiv input.darts q).symm index) | |
| have index_eq := (Enumeration.dartEquiv input.darts q).apply_symm_apply index | |
| rw [index_eq] at h | |
| exact h.trans (accepted _) | |
| theorem gap_transfer [Nonempty (Fin q)] (input : GenericGraphTables.Table q) (a b : Nat) | |
| (source : ∀ labeling : Fin input.vertices → Fin q, | |
| a * input.darts ≤ b * (GenericGraphTables.semantics input).rejectionCount labeling) | |
| (labeling : Fin (build input).vertices → GraphTables.Label) : | |
| a * (build input).darts ≤ | |
| (b * 12288) * (GraphTables.semantics (build input)).rejectionCount labeling := by | |
| classical | |
| let lifted := fun vertex => Enumeration.labelEquiv.symm | |
| (labeling (Enumeration.vertexEquiv input.vertices input.darts q vertex)) | |
| have h := AlphabetGraph.gap_transfer (GenericGraphTables.semantics input) a b | |
| (by simpa only [Fintype.card_fin] using source) lifted | |
| rw [Enumeration.card_dart] at h | |
| have counts := rejectionCount_build input lifted | |
| have restored : (fun v : Fin (build input).vertices => Enumeration.labelEquiv | |
| (lifted ((Enumeration.vertexEquiv input.vertices input.darts q).symm v))) = labeling := by | |
| funext v | |
| dsimp only [lifted] | |
| rw [Enumeration.labelEquiv.apply_symm_apply] | |
| exact congrArg labeling | |
| ((Enumeration.vertexEquiv input.vertices input.darts q).apply_symm_apply v) | |
| rw [restored] at counts | |
| rw [← counts] at h | |
| exact h | |
| theorem rowList_eq_ordered (input : GenericGraphTables.Table q) : | |
| GraphTables.rowList (build input) = | |
| (Enumeration.ordered (Enumeration.dartEquiv input.darts q)).map | |
| (rowFromDart input) := by | |
| change (Vector.ofFn (fun index => rowFromDart input | |
| ((Enumeration.dartEquiv input.darts q).symm index))).toList = | |
| (List.ofFn (Enumeration.dartEquiv input.darts q).symm).map (rowFromDart input) | |
| simp only [Vector.toList_ofFn, List.map_ofFn, Function.comp_def] | |
| theorem tableWords_eq_ordered (input : GenericGraphTables.Table q) : | |
| GraphTables.tableWords (build input) = | |
| [Enumeration.vertexCount input.vertices input.darts q, | |
| Enumeration.dartCount input.darts q] ++ | |
| (Enumeration.ordered (Enumeration.dartEquiv input.darts q)).flatMap | |
| (fun dart => GraphTables.rowWords (rowFromDart input dart)) := by | |
| simp only [GraphTables.tableWords, rowList_eq_ordered, build_vertices, build_darts, | |
| List.flatMap_map] | |
| @[simp] theorem rowList_length (input : GenericGraphTables.Table q) : | |
| (GraphTables.rowList (build input)).length = Enumeration.dartCount input.darts q := by | |
| exact GraphTables.rowList_length (build input) | |
| theorem tableWords_length (input : GenericGraphTables.Table q) : | |
| (GraphTables.tableWords (build input)).length = | |
| 2 + 4098 * Enumeration.dartCount input.darts q := by | |
| exact GraphTables.tableWords_length (build input) | |
| theorem tableBits_length_le (input : GenericGraphTables.Table q) : | |
| (GraphTables.tableBits (build input)).length ≤ | |
| Enumeration.vertexCount input.vertices input.darts q + | |
| Enumeration.dartCount input.darts q + 2 + Enumeration.dartCount input.darts q * | |
| (Enumeration.vertexCount input.vertices input.darts q + | |
| Enumeration.dartCount input.darts q + 8192) := by | |
| exact GraphTables.tableBits_length_le (build input) | |
| end BinPackingGames.Foundations.PCP.AlphabetTable.Table | |
| namespace BinPackingGames.Foundations.PCP.AlphabetTableBounds | |
| open AlphabetTable | |
| variable {q : Nat} | |
| theorem gap_transfer_real (hq : 0 < q) (input : GenericGraphTables.Table q) | |
| (eps : ℝ) (eps_nonnegative : 0 ≤ eps) | |
| (source : ∀ labeling : Fin input.vertices → Fin q, | |
| eps * (input.darts : ℝ) ≤ | |
| ((GenericGraphTables.semantics input).rejectionCount labeling : ℝ)) | |
| (labeling : Fin (Table.build input).vertices → GraphTables.Label) : | |
| (eps / 12288) * ((Table.build input).darts : ℝ) ≤ | |
| ((GraphTables.semantics (Table.build input)).rejectionCount labeling : ℝ) := by | |
| classical | |
| let : Nonempty (Fin q) := ⟨⟨0, hq⟩⟩ | |
| let lifted := fun vertex => Enumeration.labelEquiv.symm | |
| (labeling (Enumeration.vertexEquiv input.vertices input.darts q vertex)) | |
| have h := AlphabetGraphBounds.gap_transfer_real | |
| (GenericGraphTables.semantics input) eps eps_nonnegative | |
| (by simpa only [Fintype.card_fin] using source) lifted | |
| rw [Enumeration.card_dart] at h | |
| have counts := Table.rejectionCount_build input lifted | |
| have restored : (fun v : Fin (Table.build input).vertices => Enumeration.labelEquiv | |
| (lifted ((Enumeration.vertexEquiv input.vertices input.darts q).symm v))) = labeling := by | |
| funext v | |
| dsimp only [lifted] | |
| rw [Enumeration.labelEquiv.apply_symm_apply] | |
| exact congrArg labeling | |
| ((Enumeration.vertexEquiv input.vertices input.darts q).apply_symm_apply v) | |
| rw [restored] at counts | |
| rw [← counts] at h | |
| exact h | |
| theorem build_vertices (input : GenericGraphTables.Table q) : | |
| (Table.build input).vertices = input.vertices * 2 ^ q + | |
| input.darts * AlphabetGraphBounds.vertexFactor q := by | |
| rw [Table.build_vertices] | |
| simp only [Enumeration.vertexCount, Enumeration.eventCount, Enumeration.addressCount, | |
| Enumeration.localCount, Enumeration.tapeCount, Enumeration.pairTapeCount, | |
| Enumeration.fiveTapeCount, AlphabetGraphBounds.vertexFactor, | |
| AlphabetGraphBounds.localEventFactor] | |
| ring | |
| theorem build_darts (input : GenericGraphTables.Table q) : | |
| (Table.build input).darts = input.darts * AlphabetGraphBounds.dartFactor q := by | |
| rw [Table.build_darts] | |
| simp only [Enumeration.dartCount, Enumeration.eventCount, Enumeration.localCount, | |
| Enumeration.tapeCount, Enumeration.pairTapeCount, Enumeration.fiveTapeCount, | |
| AlphabetGraphBounds.dartFactor, AlphabetGraphBounds.localEventFactor] | |
| ring | |
| theorem build_total (input : GenericGraphTables.Table q) : | |
| (Table.build input).vertices + (Table.build input).darts = | |
| input.vertices * 2 ^ q + input.darts * | |
| (AlphabetGraphBounds.vertexFactor q + AlphabetGraphBounds.dartFactor q) := by | |
| rw [build_vertices, build_darts] | |
| ring | |
| theorem build_total_le (input : GenericGraphTables.Table q) : | |
| (Table.build input).vertices + (Table.build input).darts ≤ | |
| AlphabetGraphBounds.sizeFactor q * (input.vertices + input.darts) := by | |
| rw [build_total] | |
| have hv : 2 ^ q ≤ AlphabetGraphBounds.sizeFactor q := by | |
| unfold AlphabetGraphBounds.sizeFactor | |
| omega | |
| have he : AlphabetGraphBounds.vertexFactor q + AlphabetGraphBounds.dartFactor q ≤ | |
| AlphabetGraphBounds.sizeFactor q := by | |
| unfold AlphabetGraphBounds.sizeFactor | |
| exact Nat.add_le_add_right (Nat.le_add_left _ _) _ | |
| calc | |
| _ ≤ input.vertices * AlphabetGraphBounds.sizeFactor q + | |
| input.darts * AlphabetGraphBounds.sizeFactor q := | |
| Nat.add_le_add (Nat.mul_le_mul_left _ hv) (Nat.mul_le_mul_left _ he) | |
| _ = _ := by ring | |
| theorem build_vertices_le (input : GenericGraphTables.Table q) : | |
| (Table.build input).vertices ≤ | |
| AlphabetGraphBounds.sizeFactor q * (input.vertices + input.darts) := | |
| (Nat.le_add_right _ _).trans (build_total_le input) | |
| theorem build_darts_le (input : GenericGraphTables.Table q) : | |
| (Table.build input).darts ≤ | |
| AlphabetGraphBounds.sizeFactor q * (input.vertices + input.darts) := | |
| (Nat.le_add_left _ _).trans (build_total_le input) | |
| theorem sizeFactor_positive : 0 < AlphabetGraphBounds.sizeFactor q := | |
| AlphabetGraphBounds.sizeFactor_positive q | |
| end BinPackingGames.Foundations.PCP.AlphabetTableBounds | |
| namespace BinPackingGames.Foundations.PCP.RoundTables | |
| abbrev BaseTable := PreprocessingTables.BaseTable | |
| opaque fixedWalkParameter : {n : Nat // n = 2 * FinalConstants.endpointLength} := | |
| ⟨2 * FinalConstants.endpointLength, rfl⟩ | |
| def walkParameter : Nat := fixedWalkParameter.val | |
| theorem walkParameter_eq : walkParameter = 2 * FinalConstants.endpointLength := | |
| fixedWalkParameter.property | |
| def alphabet : Nat := PoweringTables.labelCount PreprocessingTables.degree walkParameter | |
| theorem alphabet_positive : 0 < alphabet := by | |
| unfold alphabet PoweringTables.labelCount | |
| exact Nat.pow_pos (by decide) | |
| def powered (H : BaseTable) (table : GraphTables.Table) : GenericGraphTables.Table alphabet := | |
| PoweringTables.table (PreprocessingTables.preprocess H table) walkParameter | |
| def build (H : BaseTable) (table : GraphTables.Table) : GraphTables.Table := | |
| AlphabetTable.Table.build (powered H table) | |
| def sizeFactor : Nat := AlphabetGraphBounds.sizeFactor alphabet * | |
| (ExpanderFamily.growth ^ 2 * (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) | |
| theorem degree_positive : 0 < PreprocessingTables.degree := by | |
| unfold PreprocessingTables.degree | |
| omega | |
| theorem dartFactor_positive (q : Nat) : 0 < AlphabetGraphBounds.dartFactor q := by | |
| unfold AlphabetGraphBounds.dartFactor AlphabetGraphBounds.localEventFactor | |
| positivity | |
| theorem sizeFactor_positive : 0 < sizeFactor := by | |
| unfold sizeFactor | |
| apply Nat.mul_pos (AlphabetGraphBounds.sizeFactor_positive alphabet) | |
| apply Nat.mul_pos | |
| · exact Nat.pow_pos (Nat.zero_lt_one.trans ExpanderFamily.growth_gt_one) | |
| · omega | |
| theorem powered_vertices (H : BaseTable) (table : GraphTables.Table) : | |
| (powered H table).vertices = PreprocessingTables.vertices table := rfl | |
| theorem powered_darts (H : BaseTable) (table : GraphTables.Table) : | |
| (powered H table).darts = 2 * PreprocessingTables.vertices table * | |
| PreprocessingTables.degree ^ (walkParameter + 1) := rfl | |
| theorem build_darts_positive (H : BaseTable) (table : GraphTables.Table) : | |
| 0 < (build H table).darts := by | |
| change 0 < (AlphabetTable.Table.build (powered H table)).darts | |
| rw [AlphabetTableBounds.build_darts, powered_darts] | |
| exact Nat.mul_pos (Nat.mul_pos | |
| (Nat.mul_pos (by decide) (PreprocessingTables.vertices_positive table)) | |
| (Nat.pow_pos degree_positive)) (dartFactor_positive alphabet) | |
| theorem build_size_le (H : BaseTable) (table : GraphTables.Table) | |
| (ht : 0 < table.darts) : | |
| (build H table).vertices + (build H table).darts ≤ | |
| sizeFactor * (table.vertices + table.darts) := by | |
| have hv := PreprocessingTables.vertices_le_of_positive table ht | |
| have he : (powered H table).vertices + (powered H table).darts = | |
| PreprocessingTables.vertices table * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1)) := by | |
| rw [powered_vertices, powered_darts] | |
| ring | |
| have hp := Nat.mul_le_mul_right | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1)) hv | |
| calc | |
| _ ≤ AlphabetGraphBounds.sizeFactor alphabet * | |
| ((powered H table).vertices + (powered H table).darts) := | |
| AlphabetTableBounds.build_total_le (powered H table) | |
| _ = AlphabetGraphBounds.sizeFactor alphabet * | |
| (PreprocessingTables.vertices table * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) := by rw [he] | |
| _ ≤ AlphabetGraphBounds.sizeFactor alphabet * | |
| ((ExpanderFamily.growth ^ 2 * table.darts) * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) := | |
| Nat.mul_le_mul_left _ hp | |
| _ = sizeFactor * table.darts := by unfold sizeFactor; ring | |
| _ ≤ sizeFactor * (table.vertices + table.darts) := | |
| Nat.mul_le_mul_left _ (Nat.le_add_left _ _) | |
| theorem build_completeness (H : BaseTable) (table : GraphTables.Table) | |
| (sat : (GraphTables.semantics table).Satisfiable) : | |
| (GraphTables.semantics (build H table)).Satisfiable := by | |
| let : Nonempty (Fin alphabet) := ⟨⟨0, alphabet_positive⟩⟩ | |
| exact AlphabetTable.Table.perfect_completeness (powered H table) | |
| (PoweringTableSemantics.preserves_satisfiability | |
| (PreprocessingTables.preprocess H table) walkParameter | |
| (PreprocessingGuarantees.completeness H table sat)) | |
| abbrev Input := {table : GraphTables.Table // 0 < table.darts} | |
| instance (input : Input) : Nonempty (Fin input.val.darts) := ⟨⟨0, input.property⟩⟩ | |
| def step (H : BaseTable) (input : Input) : Input := | |
| ⟨build H input.val, build_darts_positive H input.val⟩ | |
| def initial (F : Target.Formula) : Input := | |
| ⟨RawInitialTables.table F, RawInitialTables.table_darts_positive F⟩ | |
| def size (input : Input) : Nat := input.val.vertices + input.val.darts | |
| def Satisfiable (input : Input) : Prop := (GraphTables.semantics input.val).Satisfiable | |
| noncomputable def gap (input : Input) : ℝ := (GraphTables.semantics input.val).gap | |
| theorem size_positive (input : Input) : 0 < size input := | |
| input.property.trans_le (Nat.le_add_left _ _) | |
| theorem gap_nonnegative (input : Input) : 0 ≤ gap input := | |
| (GraphTables.semantics input.val).gap_nonnegative | |
| theorem gap_eq_zero_iff (input : Input) : gap input = 0 ↔ Satisfiable input := | |
| (GraphTables.semantics input.val).gap_eq_zero_iff | |
| theorem one_le_size_mul_gap (input : Input) (unsat : ¬ Satisfiable input) : | |
| 1 ≤ (size input : ℝ) * gap input := by | |
| have h := (GraphTables.semantics input.val).inverse_card_le_gap_of_unsatisfiable unsat | |
| have hp : (0 : ℝ) < input.val.darts := Nat.cast_pos.mpr input.property | |
| simp only [Fintype.card_fin] at h | |
| have hd := (div_le_iff₀ hp).mp h | |
| have hsize : (input.val.darts : ℝ) ≤ (size input : ℝ) := by | |
| exact_mod_cast (Nat.le_add_left input.val.darts input.val.vertices) | |
| exact (show 1 ≤ (input.val.darts : ℝ) * gap input by | |
| simpa only [gap, mul_comm] using hd).trans | |
| (mul_le_mul_of_nonneg_right hsize (gap_nonnegative input)) | |
| theorem initial_satisfiable_iff (F : Target.Formula) : Satisfiable (initial F) ↔ F.Satisfiable := | |
| RawInitialTables.table_satisfiable_iff F | |
| theorem step_completeness (H : BaseTable) (input : Input) : | |
| Satisfiable input → Satisfiable (step H input) := build_completeness H input.val | |
| theorem step_size (H : BaseTable) (input : Input) : | |
| size (step H input) ≤ sizeFactor * size input := build_size_le H input.val input.property | |
| end BinPackingGames.Foundations.PCP.RoundTables | |
| namespace BinPackingGames.Foundations.PCP.RoundTableGap | |
| open RoundTables | |
| open PoweringWalks SpectralReturn | |
| variable (H : BaseTable) | |
| (certificate : SpectralCertificate (ExpanderTables.graph H) (1 / 100 : ℝ)) | |
| include certificate | |
| theorem powered_count_gap (input : Input) | |
| (labeling : Fin (powered H input.val).vertices → Fin alphabet) : | |
| RoundGap.poweredLower (gap input) * ((powered H input.val).darts : ℝ) ≤ | |
| ((GenericGraphTables.semantics (powered H input.val)).rejectionCount labeling : ℝ) := by | |
| let old := PreprocessingOverlayTables.overlay | |
| (PreprocessingTables.padded H input.val) (PreprocessingTables.overlayFamily H input.val) | |
| have hd : 0 < (PreprocessingRegularTables.internalDegree + 1) + | |
| PreprocessingRegularTables.internalDegree := by omega | |
| let : Nonempty (Fin ((PreprocessingRegularTables.internalDegree + 1) + | |
| PreprocessingRegularTables.internalDegree)) := ⟨⟨0, hd⟩⟩ | |
| have spectral : SpectralCertificate (lazyGraph (PortTables.portGraph old)) (31 / 32 : ℝ) := | |
| LazySpectral.lazy_certificate_31_32 (PortTables.portGraph old) | |
| (PreprocessingGuarantees.overlay_certificate H certificate input.val) | |
| have lower := PreprocessingGuarantees.gap_transfer_real H certificate input.val input.property | |
| (gap input) (gap_nonnegative input) | |
| (by simpa only [Fintype.card_fin] using | |
| ((GraphTables.semantics input.val).le_gap_iff (gap input)).mp le_rfl) | |
| have hs : (0 : ℝ) < Preprocessing.sizeFactor := Nat.cast_pos.mpr Preprocessing.sizeFactor_positive | |
| have hn : walkParameter = 2 * PoweringSoundness.center 64 FinalConstants.windowHalf := | |
| walkParameter_eq | |
| have bound := PoweringPortReindex.lazy_table_uniform_count_gap_at old | |
| (PreprocessingTables.vertices_positive input.val) hd (31 / 32) spectral | |
| FinalConstants.windowHalf FinalConstants.windowHalf_positive walkParameter hn | |
| (gap input / Preprocessing.sizeFactor) (div_nonneg (gap_nonnegative input) hs.le) | |
| lower labeling | |
| have hw : walkParameter + 1 = FinalConstants.walkLength := by | |
| rw [walkParameter_eq] | |
| rfl | |
| simpa only [RoundGap.poweredLower, PoweringFinalConstants.card_alphabet, | |
| hw, FinalConstants.cap, powered, PreprocessingTables.preprocess, old] using! bound | |
| theorem build_count_gap (input : Input) | |
| (labeling : Fin (build H input.val).vertices → GraphTables.Label) : | |
| min (2 * gap input) FinalConstants.cap * ((build H input.val).darts : ℝ) ≤ | |
| ((GraphTables.semantics (build H input.val)).rejectionCount labeling : ℝ) := by | |
| have h := AlphabetTableBounds.gap_transfer_real alphabet_positive (powered H input.val) | |
| (RoundGap.poweredLower (gap input)) | |
| (RoundGap.poweredLower_nonnegative (gap input) (gap_nonnegative input)) | |
| (powered_count_gap H certificate input) labeling | |
| have scalar : min (2 * gap input) FinalConstants.cap ≤ | |
| RoundGap.poweredLower (gap input) / 12288 := by | |
| simpa only [RoundGap.poweredLower, FinalConstants.cap, FinalConstants.walkLength, | |
| PoweringFinalConstants.center_eq] using | |
| PoweringFinalConstants.composed_scaled_gap (gap input) (gap_nonnegative input) | |
| exact (mul_le_mul_of_nonneg_right scalar (Nat.cast_nonneg _)).trans h | |
| theorem step_gap (input : Input) : | |
| min (2 * gap input) FinalConstants.cap ≤ gap (step H input) := by | |
| apply ((GraphTables.semantics (step H input).val).le_gap_iff _).mpr | |
| change ∀ labeling : Fin (build H input.val).vertices → GraphTables.Label, | |
| min (2 * gap input) FinalConstants.cap * | |
| (Fintype.card (Fin (build H input.val).darts) : ℝ) ≤ | |
| ((GraphTables.semantics (build H input.val)).rejectionCount labeling : ℝ) | |
| simpa only [Fintype.card_fin] using build_count_gap H certificate input | |
| end BinPackingGames.Foundations.PCP.RoundTableGap | |
| end OAI | |