Buckets:
cfahlgren1/math / lean /OAI /Computability /UniqueGames /PCP /PreprocessingRegularLoopWordsLemmas.lean
| import Mathlib.Tactic.DeriveFintype | |
| import OAI.Computability.UniqueGames.Machines.MachineDrain | |
| import OAI.Computability.UniqueGames.Machines.MachineFiniteTable | |
| import OAI.Computability.UniqueGames.Machines.MachineInitialHeaders | |
| import OAI.Computability.UniqueGames.Machines.MachineLemmas | |
| import OAI.Computability.UniqueGames.PCP.PreprocessingRegularWords | |
| import OAI.Computability.UniqueGames.PCP.PreprocessingTablesLemmas | |
| import OAI.Computability.UniqueGames.PCP.RawInitialTablesLemmas | |
| import OAI.Computability.UniqueGames.PCP.SourceMachine | |
| namespace OAI | |
| section | |
| /-! | |
| # Prefix and suffix invariants for regular-table row loops | |
| These finite block identities apply to original-vertex blocks, to dummy blocks | |
| within an owner, and to whole owner blocks. They expose exactly the next emitted | |
| block while preserving the codec's established order. | |
| -/ | |
| namespace UniqueGamesTheorem.Foundations.PCP.PreprocessingRegularLoopWords | |
| /-- Bits emitted by the first `k` blocks. -/ | |
| def blocksPrefix {n : Nat} (f : Fin n → List Bool) (k : Nat) : List Bool := | |
| ((List.ofFn f).take k).flatten | |
| /-- Bits remaining after the first `k` blocks. -/ | |
| def blocksSuffix {n : Nat} (f : Fin n → List Bool) (k : Nat) : List Bool := | |
| ((List.ofFn f).drop k).flatten | |
| @[simp] theorem blocksPrefix_zero {n : Nat} (f : Fin n → List Bool) : | |
| blocksPrefix f 0 = [] := by | |
| simp only [blocksPrefix, List.take_zero, List.flatten_nil] | |
| @[simp] theorem blocksPrefix_all {n : Nat} (f : Fin n → List Bool) : | |
| blocksPrefix f n = (List.ofFn f).flatten := by | |
| have h : (List.ofFn f).take n = List.ofFn f := by | |
| simpa only [List.length_ofFn] using (List.take_length (l := List.ofFn f)) | |
| exact congrArg List.flatten h | |
| theorem blocksPrefix_succ {n : Nat} (f : Fin n → List Bool) (k : Nat) (h : k < n) : | |
| blocksPrefix f (k + 1) = blocksPrefix f k ++ f ⟨k, h⟩ := by | |
| unfold blocksPrefix | |
| rw [List.take_succ_eq_append_getElem | |
| (show k < (List.ofFn f).length by simpa only [List.length_ofFn] using h)] | |
| simp only [List.flatten_append, List.flatten_cons, List.flatten_nil, | |
| List.append_nil, List.getElem_ofFn] | |
| @[simp] theorem blocksSuffix_zero {n : Nat} (f : Fin n → List Bool) : | |
| blocksSuffix f 0 = (List.ofFn f).flatten := by | |
| simp only [blocksSuffix, List.drop_zero] | |
| @[simp] theorem blocksSuffix_all {n : Nat} (f : Fin n → List Bool) : | |
| blocksSuffix f n = [] := by | |
| have h : (List.ofFn f).drop n = [] := by | |
| simpa only [List.length_ofFn] using (List.drop_length (l := List.ofFn f)) | |
| exact congrArg List.flatten h | |
| theorem blocksSuffix_succ {n : Nat} (f : Fin n → List Bool) (k : Nat) (h : k < n) : | |
| blocksSuffix f k = f ⟨k, h⟩ ++ blocksSuffix f (k + 1) := by | |
| unfold blocksSuffix | |
| rw [List.drop_eq_getElem_cons | |
| (show k < (List.ofFn f).length by simpa only [List.length_ofFn] using h)] | |
| simp only [List.flatten_cons, List.getElem_ofFn] | |
| /-- The completed and remaining portions partition the original bitstream. -/ | |
| theorem blocksPrefix_append_suffix {n : Nat} (f : Fin n → List Bool) (k : Nat) : | |
| blocksPrefix f k ++ blocksSuffix f k = (List.ofFn f).flatten := by | |
| unfold blocksPrefix blocksSuffix | |
| rw [← List.flatten_append, List.take_append_drop] | |
| end UniqueGamesTheorem.Foundations.PCP.PreprocessingRegularLoopWords | |
| end | |
| section | |
| /-! Bounds on the actual output prefixes used by the regularization loops. | |
| The bounds include the stored headers and all earlier original/owner blocks. | |
| They concern actual serialized words; machine executions are proved separately. -/ | |
| namespace UniqueGamesTheorem.Foundations.PCP.PreprocessingRegularBounds | |
| open PreprocessingRegularTables PreprocessingRegularWords PreprocessingRegularLoopWords | |
| open UniqueGamesTheorem.Foundations.Complexity | |
| open scoped BigOperators | |
| theorem offset_succ {n : Nat} (p : Fin n → Nat) (k : Nat) (h : k < n) : | |
| PreprocessingPaddingOffsets.offset p (k + 1) = | |
| PreprocessingPaddingOffsets.offset p k + p ⟨k, h⟩ := by | |
| unfold PreprocessingPaddingOffsets.offset | |
| rw [List.take_succ_eq_append_getElem (show k < (List.finRange n).length by simpa using h)] | |
| simp only [List.map_append, List.sum_append, List.map_cons, List.map_nil, | |
| List.sum_cons, List.sum_nil, Nat.add_zero, List.finRange, List.getElem_ofFn] | |
| theorem blocksPrefix_length_le {n : Nat} (f : Fin n → List Bool) (k : Nat) : | |
| (blocksPrefix f k).length ≤ (List.ofFn f).flatten.length := by | |
| have h := congrArg List.length (blocksPrefix_append_suffix f k) | |
| simp only [List.length_append] at h | |
| omega | |
| def header (t : GraphTables.Table) (p : Fin t.vertices → Nat) (q : Nat) : List Bool := | |
| encodeWords [vertexCount t p, vertexCount t p * (q + 1)] | |
| def ownerBits (t : GraphTables.Table) (p : Fin t.vertices → Nat) {q : Nat} | |
| (tables : ∀ v, ExpanderTables.Table (PreprocessingCloudIndex.cloudSize t v + p v) q) | |
| (v : Fin t.vertices) : List Bool := | |
| (List.ofFn (dummyVertexBits t p tables v)).flatten | |
| def originalPrefix (t : GraphTables.Table) (p : Fin t.vertices → Nat) {q : Nat} | |
| (tables : ∀ v, ExpanderTables.Table (PreprocessingCloudIndex.cloudSize t v + p v) q) | |
| (k : Nat) : List Bool := | |
| header t p q ++ blocksPrefix (originalVertexBits t p tables) k | |
| def ownerPrefix (t : GraphTables.Table) (p : Fin t.vertices → Nat) {q : Nat} | |
| (tables : ∀ v, ExpanderTables.Table (PreprocessingCloudIndex.cloudSize t v + p v) q) | |
| (k : Nat) : List Bool := | |
| header t p q ++ (List.ofFn (originalVertexBits t p tables)).flatten ++ | |
| blocksPrefix (ownerBits t p tables) k | |
| def dummyPrefix (t : GraphTables.Table) (p : Fin t.vertices → Nat) {q : Nat} | |
| (tables : ∀ v, ExpanderTables.Table (PreprocessingCloudIndex.cloudSize t v + p v) q) | |
| (v : Fin t.vertices) (k : Nat) : List Bool := | |
| ownerPrefix t p tables v.val ++ blocksPrefix (dummyVertexBits t p tables v) k | |
| variable (t : GraphTables.Table) (p : Fin t.vertices → Nat) {q : Nat} | |
| variable (tables : ∀ v, ExpanderTables.Table (PreprocessingCloudIndex.cloudSize t v + p v) q) | |
| theorem originalPrefix_length_le (k : Nat) : | |
| (originalPrefix t p tables k).length ≤ | |
| (PortTables.tableBits (ofCloudTables t p tables)).length := by | |
| have h := blocksPrefix_length_le (originalVertexBits t p tables) k | |
| rw [tableBits_ofCloudTables] | |
| simp only [originalPrefix, header, List.length_append] | |
| omega | |
| theorem ownerPrefix_length_le (k : Nat) : | |
| (ownerPrefix t p tables k).length ≤ | |
| (PortTables.tableBits (ofCloudTables t p tables)).length := by | |
| have h := blocksPrefix_length_le (ownerBits t p tables) k | |
| have he : ownerBits t p tables = | |
| (fun v => (List.ofFn (dummyVertexBits t p tables v)).flatten) := rfl | |
| rw [tableBits_ofCloudTables] | |
| simp only [ownerPrefix, header, List.length_append] at * | |
| simp only [he] at * | |
| omega | |
| theorem dummyPrefix_length_le (v : Fin t.vertices) (k : Nat) : | |
| (dummyPrefix t p tables v k).length ≤ | |
| (PortTables.tableBits (ofCloudTables t p tables)).length := by | |
| have hi := blocksPrefix_length_le (dummyVertexBits t p tables v) k | |
| have ho := blocksPrefix_length_le (ownerBits t p tables) (v.val + 1) | |
| rw [blocksPrefix_succ _ _ v.isLt] at ho | |
| have he : ownerBits t p tables = | |
| (fun v => (List.ofFn (dummyVertexBits t p tables v)).flatten) := rfl | |
| simp only [Fin.eta] at ho | |
| rw [tableBits_ofCloudTables] | |
| simp only [dummyPrefix, ownerPrefix, header, ownerBits, List.length_append] at * | |
| simp only [he] at * | |
| omega | |
| theorem regular_originalPrefix_le (H : BaseTable) (k : Nat) : | |
| (originalPrefix t (padding t) (familyCloudTable H t) k).length ≤ | |
| PreprocessingMachineBounds.regularPolynomial.eval | |
| (PreprocessingMachineBounds.inputLength t) := | |
| (originalPrefix_length_le t (padding t) (familyCloudTable H t) k).trans | |
| (PreprocessingMachineBounds.regularBits_le H t) | |
| theorem regular_ownerPrefix_le (H : BaseTable) (k : Nat) : | |
| (ownerPrefix t (padding t) (familyCloudTable H t) k).length ≤ | |
| PreprocessingMachineBounds.regularPolynomial.eval | |
| (PreprocessingMachineBounds.inputLength t) := | |
| (ownerPrefix_length_le t (padding t) (familyCloudTable H t) k).trans | |
| (PreprocessingMachineBounds.regularBits_le H t) | |
| theorem regular_dummyPrefix_le (H : BaseTable) (v : Fin t.vertices) (k : Nat) : | |
| (dummyPrefix t (padding t) (familyCloudTable H t) v k).length ≤ | |
| PreprocessingMachineBounds.regularPolynomial.eval | |
| (PreprocessingMachineBounds.inputLength t) := | |
| (dummyPrefix_length_le t (padding t) (familyCloudTable H t) v k).trans | |
| (PreprocessingMachineBounds.regularBits_le H t) | |
| /-- The number of original and dummy vertex visits is exactly the constructed | |
| vertex count; adding owner visits still gives a linear bound in input bits. -/ | |
| theorem visits_le_input : | |
| t.darts + t.vertices + (∑ v, padding t v) + 1 ≤ | |
| (ExpanderFamily.growth + 1) * PreprocessingMachineBounds.inputLength t + 1 := by | |
| have hv := PreprocessingMachineBounds.regularVertices_le_input t | |
| have hn := GraphTables.vertices_le_tableBits_length t | |
| change t.vertices ≤ PreprocessingMachineBounds.inputLength t at hn | |
| unfold vertexCount at hv | |
| rw [Nat.add_mul, one_mul] | |
| omega | |
| /-- An elementary budget aggregation for the actual three finite loops. The | |
| per-call bounds must be supplied from the separately checked subprogram runs. -/ | |
| theorem sum_body_costs_le (old : Fin t.darts → Nat) (owners : Fin t.vertices → Nat) | |
| (dummy : ∀ v : Fin t.vertices, Fin (padding t v) → Nat) (setup cap : Nat) | |
| (hs : setup ≤ cap) (ho : ∀ e, old e ≤ cap) (hv : ∀ v, owners v ≤ cap) | |
| (hd : ∀ v j, dummy v j ≤ cap) : | |
| setup + (∑ e, old e) + (∑ v, owners v) + (∑ v, ∑ j, dummy v j) ≤ | |
| ((ExpanderFamily.growth + 1) * PreprocessingMachineBounds.inputLength t + 1) * cap := by | |
| have hOld : (∑ e, old e) ≤ t.darts * cap := by | |
| simpa using Finset.sum_le_sum (fun e (_ : e ∈ Finset.univ) => ho e) | |
| have hOwners : (∑ v, owners v) ≤ t.vertices * cap := by | |
| simpa using Finset.sum_le_sum (fun v (_ : v ∈ Finset.univ) => hv v) | |
| have hDummy : (∑ v, ∑ j, dummy v j) ≤ (∑ v, padding t v) * cap := by | |
| calc | |
| _ ≤ ∑ v, padding t v * cap := by | |
| apply Finset.sum_le_sum | |
| intro v _ | |
| simpa using Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ) => hd v j) | |
| _ = _ := (Finset.sum_mul ..).symm | |
| calc | |
| _ ≤ (t.darts + t.vertices + (∑ v, padding t v) + 1) * cap := by | |
| rw [Nat.add_mul, Nat.add_mul, Nat.add_mul, one_mul] | |
| omega | |
| _ ≤ _ := Nat.mul_le_mul_right cap (visits_le_input t) | |
| end UniqueGamesTheorem.Foundations.PCP.PreprocessingRegularBounds | |
| end | |
| section | |
| namespace UniqueGamesTheorem.Foundations.PCP.RawInitialMachineModel | |
| open Turing Complexity Hastad | |
| inductive Tape | |
| | input | variables | counter | index | field (slot : Fin 6) | |
| | scratch | reversed | output | |
| deriving DecidableEq, Fintype | |
| abbrev Signs := Bool × Bool × Bool | |
| abbrev State := Signs × Option Bool | |
| abbrev Alphabet (_ : Tape) := Bool | |
| inductive CopyPhase | |
| | tailVariables (slot : Fin 3) | |
| | tailIndex (slot : Fin 3) | |
| | variableName (slot : Fin 3) | |
| | reverseIndex (slot : Fin 3) (orientation : Bool) | |
| | dummyVariables | dummyIndex | dummyReverse | |
| deriving DecidableEq, Fintype | |
| inductive Label | |
| | headerStart (slot : Fin 2) | headerLoop (slot : Fin 2) | |
| | scanN | restoreN | scanM1 | restoreM1 | closeFirst | |
| | scanM6 | restoreM6 | closeSecond | initializeIndex | guard | |
| | fieldStart (slot : Fin 6) | fieldLoop (slot : Fin 6) | loadSigns | |
| | scan (phase : CopyPhase) | restore (phase : CopyPhase) | |
| | closeTail (slot : Fin 3) (orientation : Bool) | |
| | closeReverse (slot : Fin 3) (orientation : Bool) | |
| | relation (slot : Fin 3) (orientation : Bool) | |
| | cleanupField (slot : Fin 6) | incrementIndex | |
| | closeDummyTail | closeDummyReverse | dummyRelation | |
| | cleanupFinal (slot : Fin 3) | reset | finalReverse | |
| deriving DecidableEq, Fintype | |
| def initialState : State := ((false, false, false), none) | |
| def stateKeys : List State := | |
| [false, true].flatMap fun a => [false, true].flatMap fun b => | |
| [false, true].flatMap fun c => | |
| [none, some false, some true].map fun register => ((a, b, c), register) | |
| theorem stateKeys_complete (state : State) : state ∈ stateKeys := by | |
| rcases state with ⟨⟨a, b, c⟩, register⟩ | |
| cases a <;> cases b <;> cases c <;> cases register with | |
| | none => simp [stateKeys] | |
| | some bit => cases bit <;> simp [stateKeys] | |
| def nameField (slot : Fin 3) : Fin 6 := ⟨2 * slot.val, by omega⟩ | |
| def copySource : CopyPhase → Tape | |
| | .tailVariables _ | .dummyVariables => .variables | |
| | .variableName slot => .field (nameField slot) | |
| | _ => .index | |
| def copyScale : CopyPhase → Nat | |
| | .reverseIndex _ _ | .dummyReverse => 6 | |
| | _ => 1 | |
| def copyNext : CopyPhase → Label | |
| | .tailVariables slot => .scan (.tailIndex slot) | |
| | .tailIndex slot => .closeTail slot false | |
| | .variableName slot => .closeTail slot true | |
| | .reverseIndex slot orientation => .closeReverse slot orientation | |
| | .dummyVariables => .scan .dummyIndex | |
| | .dummyIndex => .closeDummyTail | |
| | .dummyReverse => .closeDummyReverse | |
| def relationNext (slot : Fin 3) (orientation : Bool) : Label := | |
| if orientation then | |
| if h : slot.val + 1 < 3 then .scan (.tailVariables ⟨slot.val + 1, h⟩) | |
| else .cleanupField 0 | |
| else .scan (.variableName slot) | |
| def finalTape (slot : Fin 3) : Tape := | |
| if slot.val = 0 then .variables else if slot.val = 1 then .counter else .index | |
| def drain (tape : Tape) (again next : Label) : TM2.Stmt Alphabet Label State := | |
| MachineDrain.drain tape again (some next) | |
| def headerTape (slot : Fin 2) : Tape := if slot.val = 0 then .variables else .counter | |
| def relationOutput (slot : Fin 3) (orientation : Bool) (state : State) : List Bool := | |
| (encodeWords (RawInitialRows.relationWordsFor state.1 | |
| (RawInitialTables.slotOrder.symm slot) orientation)).reverse | |
| def program : Label → TM2.Stmt Alphabet Label State | |
| | .headerStart slot => SourceMachine.fieldStart (headerTape slot) (.headerLoop slot) | |
| | .headerLoop slot => SourceMachine.fieldLoop .input (headerTape slot) (.headerLoop slot) | |
| (if slot.val = 0 then some (.headerStart 1) else some .scanN) | |
| | .scanN => MachineInitialHeaders.prefixScan .variables .scratch .reversed 1 .scanN .restoreN | |
| | .restoreN => Reduction.MachineTransfer.loopAt .scratch .variables id false .restoreN (some .scanM1) | |
| | .scanM1 => MachineInitialHeaders.prefixScan .counter .scratch .reversed 1 .scanM1 .restoreM1 | |
| | .restoreM1 => Reduction.MachineTransfer.loopAt .scratch .counter id false .restoreM1 (some .closeFirst) | |
| | .closeFirst => Reduction.MachineSubstitution.pushWord .reversed [true, false] | |
| (.goto fun _ => .scanM6) | |
| | .scanM6 => MachineInitialHeaders.prefixScan .counter .scratch .reversed 6 .scanM6 .restoreM6 | |
| | .restoreM6 => Reduction.MachineTransfer.loopAt .scratch .counter id false .restoreM6 (some .closeSecond) | |
| | .closeSecond => Reduction.MachineSubstitution.pushWord .reversed [true, false] | |
| (.goto fun _ => .initializeIndex) | |
| | .initializeIndex => .push .index (fun _ => false) (.goto fun _ => .guard) | |
| | .guard => MachineUnaryCounter.guard .counter (.fieldStart 0) (.scan .dummyVariables) | |
| | .fieldStart slot => SourceMachine.fieldStart (.field slot) (.fieldLoop slot) | |
| | .fieldLoop slot => SourceMachine.fieldLoop .input (.field slot) (.fieldLoop slot) | |
| (if h : slot.val + 1 < 6 then some (.fieldStart ⟨slot.val + 1, h⟩) | |
| else some .loadSigns) | |
| | .loadSigns => | |
| .peek (.field 1) (fun state head => ((head.getD false, state.1.2), state.2)) | |
| (.peek (.field 3) (fun state head => ((state.1.1, head.getD false, state.1.2.2), state.2)) | |
| (.peek (.field 5) (fun state head => ((state.1.1, state.1.2.1, head.getD false), state.2)) | |
| (.load (fun state => (state.1, none)) (.goto fun _ => .scan (.tailVariables 0))))) | |
| | .scan phase => MachineInitialHeaders.prefixScan (copySource phase) .scratch .reversed | |
| (copyScale phase) (.scan phase) (.restore phase) | |
| | .restore phase => Reduction.MachineTransfer.loopAt .scratch (copySource phase) id false | |
| (.restore phase) (some (copyNext phase)) | |
| | .closeTail slot orientation => .push .reversed (fun _ => false) | |
| (.goto fun _ => .scan (.reverseIndex slot orientation)) | |
| | .closeReverse slot orientation => Reduction.MachineSubstitution.pushWord .reversed | |
| (encodeWord (2 * slot.val + if orientation then 0 else 1)) | |
| (.goto fun _ => .relation slot orientation) | |
| | .relation slot orientation => MachineFiniteTable.emit .reversed | |
| (relationOutput slot orientation) | |
| stateKeys (.goto fun _ => relationNext slot orientation) | |
| | .cleanupField slot => drain (.field slot) (.cleanupField slot) | |
| (if h : slot.val + 1 < 6 then .cleanupField ⟨slot.val + 1, h⟩ else .incrementIndex) | |
| | .incrementIndex => .push .index (fun _ => true) (.goto fun _ => .guard) | |
| | .closeDummyTail => .push .reversed (fun _ => false) (.goto fun _ => .scan .dummyReverse) | |
| | .closeDummyReverse => .push .reversed (fun _ => false) (.goto fun _ => .dummyRelation) | |
| | .dummyRelation => Reduction.MachineSubstitution.pushWord .reversed | |
| (encodeWords (GraphTables.relationWords (GraphTables.relationOf (fun _ _ => true)))) | |
| (.goto fun _ => .cleanupFinal 0) | |
| | .cleanupFinal slot => drain (finalTape slot) (.cleanupFinal slot) | |
| (if h : slot.val + 1 < 3 then .cleanupFinal ⟨slot.val + 1, h⟩ else .reset) | |
| | .reset => .load (fun _ => initialState) (.goto fun _ => .finalReverse) | |
| | .finalReverse => Reduction.MachineTransfer.loopAt .reversed .output id false .finalReverse none | |
| def machine : FinTM2 where | |
| K := Tape | |
| k₀ := .input | |
| k₁ := .output | |
| Γ := Alphabet | |
| Λ := Label | |
| main := .headerStart 0 | |
| σ := State | |
| initialState := initialState | |
| m := program | |
| end UniqueGamesTheorem.Foundations.PCP.RawInitialMachineModel | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 17.8 kB
- Xet hash:
- 1e1255e4c627db1812c3192b2c37a88801a5ecbe6ca992ae5939a75e5af955b7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.