Buckets:
| import Mathlib | |
| import OAI.Computability.MinUncut.PCP.TupleBody | |
| import OAI.Computability.MinUncut.Machines.RuntimeFinish | |
| import OAI.Computability.MinUncut.Games.Parameters | |
| namespace OAI | |
| namespace MinUncutGames.Foundations.Hastad.SourceGap | |
| open Target SourceContexts SourceOccurrences SourceGame | |
| open MinUncutGames.Integration.SourceParameters | |
| open MinUncutGames.Reduction | |
| def ClauseGap (F : Formula) (η : ℚ) : Prop := | |
| F.clauses ≠ [] ∧ ∀ assignment : Fin F.«variables» → Bool, | |
| (η : ℝ) * F.clauses.length ≤ | |
| (PCP.failureCount F assignment (PCP.allIndices F) : ℝ) | |
| theorem third_pos {η : ℚ} (hη : 0 < η) : 0 < η / 3 := by positivity | |
| theorem third_le_one {η : ℚ} (hη : η ≤ 1) : η / 3 ≤ 1 := by linarith | |
| def repetitionCount (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (D : ℕ) (hD : 0 < D) : ℕ := | |
| repetitionLength (η / 3) ξ (third_pos hη) (third_le_one hη1) hξ D hD | |
| theorem repetitionCount_pos (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) | |
| (hξ : 0 < ξ) (D : ℕ) (hD : 0 < D) : | |
| 0 < repetitionCount η ξ hη hη1 hξ D hD := | |
| (repetitionLength_spec (η / 3) ξ (third_pos hη) (third_le_one hη1) hξ D hD).1 | |
| theorem repeated_game_bound (F : Formula) (η ξ : ℚ) | |
| (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) (D : ℕ) (hD : 0 < D) | |
| (hgap : ClauseGap F η) : | |
| ((baseGame F hgap.1).repetition | |
| (repetitionCount η ξ hη hη1 hξ D hD)).value ≤ | |
| 4 * (D : ℝ)⁻¹ * (ξ : ℝ)^2 := by | |
| have hb : (baseGame F hgap.1).value ≤ 1 - ((η / 3 : ℚ) : ℝ) := by | |
| simpa only [Rat.cast_div, Rat.cast_ofNat] using | |
| base_value_le_of_clause_gap F hgap.1 (η : ℝ) hgap.2 | |
| have hc : Fintype.card Bool * Fintype.card PCP.ClauseAnswer = 16 := by | |
| simp | |
| exact (game_repetition_rate (baseGame F hgap.1) (third_pos hη) | |
| (third_le_one hη1) hc hb _).trans | |
| (repetitionLength_real_bound (η / 3) ξ (third_pos hη) | |
| (third_le_one hη1) hξ D hD) | |
| def source (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (D : ℕ) (hD : 0 < D) (F : Formula) : SourceEncoding.Input := | |
| sourceInput F (repetitionCount η ξ hη hη1 hξ D hD) D hD | |
| theorem source_complete (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (D : ℕ) (hD : 0 < D) (hnoise : (D : ℚ)⁻¹ ≤ ξ) | |
| (F : Formula) (hF : F.Satisfiable) : | |
| ∃ bits : Fin (source η ξ hη hη1 hξ D hD F).«variables» → Bool, | |
| 1 - ξ ≤ (((source η ξ hη hη1 hξ D hD F).equations.countP | |
| (fun e => CloneGap.satisfied e bits) : ℚ) / | |
| (source η ξ hη hη1 hξ D hD F).equations.length) := by | |
| obtain ⟨assignment, hs⟩ := hF | |
| refine ⟨SourceHonest.honestBits F _ assignment, ?_⟩ | |
| have h := SourceHonest.sourceList_honest_acceptance_rat F | |
| (repetitionCount η ξ hη hη1 hξ D hD) D hD assignment hs | |
| exact (sub_le_sub_left hnoise 1).trans h | |
| theorem source_sound (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (D : ℕ) (hD : 0 < D) (hDtwo : 2 ≤ D) | |
| (F : Formula) (hgap : ClauseGap F η) | |
| (bits : Fin (source η ξ hη hη1 hξ D hD F).«variables» → Bool) : | |
| ((source η ξ hη hη1 hξ D hD F).equations.countP | |
| (fun e => CloneGap.satisfied e bits) : ℚ) / | |
| (source η ξ hη hη1 hξ D hD F).equations.length ≤ (1 + ξ) / 2 := | |
| SourceSoundness.sourceList_sound_rat F hgap.1 | |
| (repetitionCount η ξ hη hη1 hξ D hD) D hD hDtwo ξ hξ.le | |
| (repeated_game_bound F η ξ hη hη1 hξ D hD hgap) bits | |
| theorem source_size (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (D : ℕ) (hD : 0 < D) : | |
| ∃ p : Polynomial ℕ, ∀ F : Formula, | |
| (SourceEncoding.inputBits (source η ξ hη hη1 hξ D hD F)).length ≤ | |
| p.eval (Complexity.formulaBits F).length := | |
| SourceBounds.fixed_parameters_source_size (repetitionCount η ξ hη hη1 hξ D hD) D hD | |
| end MinUncutGames.Foundations.Hastad.SourceGap | |
| namespace MinUncutGames.Foundations.Hastad.SourceNoiseParameter | |
| def noiseDenominator (ξ : ℚ) : ℕ := ξ.den + 2 | |
| theorem noiseDenominator_ge_two (ξ : ℚ) : 2 ≤ noiseDenominator ξ := by | |
| unfold noiseDenominator | |
| omega | |
| theorem noiseDenominator_pos (ξ : ℚ) : 0 < noiseDenominator ξ := | |
| lt_of_lt_of_le (by decide) (noiseDenominator_ge_two ξ) | |
| theorem noiseDenominator_inv_pos (ξ : ℚ) : | |
| 0 < (noiseDenominator ξ : ℚ)⁻¹ := by | |
| apply inv_pos.mpr | |
| exact_mod_cast noiseDenominator_pos ξ | |
| theorem noiseDenominator_inv_le_half (ξ : ℚ) : | |
| (noiseDenominator ξ : ℚ)⁻¹ ≤ (1 / 2 : ℚ) := by | |
| rw [inv_eq_one_div] | |
| apply one_div_le_one_div_of_le (by norm_num) | |
| exact_mod_cast noiseDenominator_ge_two ξ | |
| theorem noiseDenominator_inv_le {ξ : ℚ} (hξ : 0 < ξ) : | |
| (noiseDenominator ξ : ℚ)⁻¹ ≤ ξ := by | |
| have hn : (1 : ℤ) ≤ ξ.num := by | |
| have h := Rat.num_pos.mpr hξ | |
| omega | |
| have hnq : (1 : ℚ) ≤ (ξ.num : ℚ) := by exact_mod_cast hn | |
| have hd : (0 : ℚ) < (ξ.den : ℚ) := by exact_mod_cast ξ.den_pos | |
| calc | |
| (noiseDenominator ξ : ℚ)⁻¹ = 1 / (noiseDenominator ξ : ℚ) := inv_eq_one_div _ | |
| _ ≤ 1 / (ξ.den : ℚ) := by | |
| apply one_div_le_one_div_of_le hd | |
| exact_mod_cast (show ξ.den ≤ noiseDenominator ξ by | |
| unfold noiseDenominator | |
| omega) | |
| _ ≤ (ξ.num : ℚ) / (ξ.den : ℚ) := div_le_div_of_nonneg_right hnq hd.le | |
| _ = ξ := ξ.num_div_den | |
| end MinUncutGames.Foundations.Hastad.SourceNoiseParameter | |
| namespace MinUncutGames.Foundations.Hastad.SourceGap | |
| open Target SourceNoiseParameter MinUncutGames.Reduction | |
| def forError (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) : | |
| Formula → SourceEncoding.Input := | |
| source η ξ hη hη1 hξ (noiseDenominator ξ) (noiseDenominator_pos ξ) | |
| theorem forError_complete (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (F : Formula) (hF : F.Satisfiable) : | |
| ∃ bits : Fin (forError η ξ hη hη1 hξ F).«variables» → Bool, | |
| 1 - ξ ≤ ((forError η ξ hη hη1 hξ F).equations.countP | |
| (fun e => CloneGap.satisfied e bits) : ℚ) / | |
| (forError η ξ hη hη1 hξ F).equations.length := | |
| source_complete η ξ hη hη1 hξ (noiseDenominator ξ) (noiseDenominator_pos ξ) | |
| (noiseDenominator_inv_le hξ) F hF | |
| theorem forError_sound (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (F : Formula) (hgap : ClauseGap F η) | |
| (bits : Fin (forError η ξ hη hη1 hξ F).«variables» → Bool) : | |
| ((forError η ξ hη hη1 hξ F).equations.countP | |
| (fun e => CloneGap.satisfied e bits) : ℚ) / | |
| (forError η ξ hη hη1 hξ F).equations.length ≤ (1 + ξ) / 2 := | |
| source_sound η ξ hη hη1 hξ (noiseDenominator ξ) (noiseDenominator_pos ξ) | |
| (noiseDenominator_ge_two ξ) F hgap bits | |
| theorem forError_size (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) : | |
| ∃ p : Polynomial ℕ, ∀ F : Formula, | |
| (SourceEncoding.inputBits (forError η ξ hη hη1 hξ F)).length ≤ | |
| p.eval (Complexity.formulaBits F).length := | |
| source_size η ξ hη hη1 hξ (noiseDenominator ξ) (noiseDenominator_pos ξ) | |
| end MinUncutGames.Foundations.Hastad.SourceGap | |
| namespace MinUncutGames.Foundations.Hastad.SourceGeneratorContract | |
| open Target Complexity | |
| abbrev NonemptyFormula := { F : Formula // F.clauses ≠ [] } | |
| def inputEncoding (F : NonemptyFormula) : List Bool := formulaBits F.val | |
| def sourceMap (u D : Nat) (hD : 0 < D) (F : NonemptyFormula) : | |
| MinUncutGames.Reduction.SourceEncoding.Input := | |
| SourceOccurrences.sourceInput F.val u D hD | |
| def errorMap (η ξ : ℚ) (hη : 0 < η) (hη1 : η ≤ 1) (hξ : 0 < ξ) | |
| (F : NonemptyFormula) : MinUncutGames.Reduction.SourceEncoding.Input := | |
| SourceGap.forError η ξ hη hη1 hξ F.val | |
| theorem inputEncoding_mk (F : Formula) (hne : F.clauses ≠ []) : | |
| inputEncoding ⟨F, hne⟩ = formulaBits F := rfl | |
| end MinUncutGames.Foundations.Hastad.SourceGeneratorContract | |
| namespace MinUncutGames.Foundations.Hastad.SourceOdometerSchedule | |
| open Turing Complexity MachineTupleOdometer | |
| open Reduction.MachineTransfer | |
| abbrev Tape := SourceContextLoad.Tape | |
| variable {u m : ℕ} {Extra Λ σ : Type} [DecidableEq Extra] | |
| def currentAt (accumulator : Extra) (i : ℕ) : Tape u Extra := | |
| if h : i < u then .current ⟨i, h⟩ else .extra accumulator | |
| def remainingAt (accumulator : Extra) (i : ℕ) : Tape u Extra := | |
| if h : i < u then .remaining ⟨i, h⟩ else .extra accumulator | |
| def setDigits (m : ℕ) {q : ℕ} (digits : Fin q → ℕ) | |
| (base : Tape u Extra → List Bool) : Tape u Extra → List Bool | |
| | .current i => if h : i.val < q then encodeWord (digits ⟨i.val, h⟩) | |
| else base (.current i) | |
| | .remaining i => if h : i.val < q then encodeWord (m - 1 - digits ⟨i.val, h⟩) | |
| else base (.remaining i) | |
| | k => base k | |
| def setAcc (accumulator : Extra) (base : Tape u Extra → List Bool) (bits : List Bool) : | |
| Tape u Extra → List Bool := Function.update base (.extra accumulator) bits | |
| def putDigit (i : Fin u) (base : Tape u Extra → List Bool) (d r : ℕ) : | |
| Tape u Extra → List Bool := digitTapes (.current i) (.remaining i) base d r [] [] | |
| omit [DecidableEq Extra] in | |
| @[simp] theorem setDigits_zero (m : ℕ) (digits : Fin 0 → ℕ) | |
| (base : Tape u Extra → List Bool) : setDigits m digits base = base := by | |
| funext k | |
| cases k <;> simp [setDigits] | |
| omit [DecidableEq Extra] in | |
| @[simp] theorem setDigits_extra (m : ℕ) {q : ℕ} (digits : Fin q → ℕ) | |
| (base : Tape u Extra → List Bool) (a : Extra) : | |
| setDigits m digits base (.extra a) = base (.extra a) := rfl | |
| @[simp] theorem setAcc_self (a : Extra) (base : Tape u Extra → List Bool) : | |
| setAcc a base (base (.extra a)) = base := by | |
| simp [setAcc] | |
| @[simp] theorem setAcc_setAcc (a : Extra) (base : Tape u Extra → List Bool) | |
| (first second : List Bool) : setAcc a (setAcc a base first) second = setAcc a base second := by | |
| simp [setAcc] | |
| @[simp] theorem setAcc_apply (a : Extra) (base : Tape u Extra → List Bool) (bits : List Bool) : | |
| setAcc a base bits (.extra a) = bits := by simp [setAcc] | |
| theorem setDigits_setAcc (m : ℕ) {q : ℕ} (digits : Fin q → ℕ) | |
| (a : Extra) (base : Tape u Extra → List Bool) (bits : List Bool) : | |
| setDigits m digits (setAcc a base bits) = setAcc a (setDigits m digits base) bits := by | |
| funext k | |
| cases k <;> simp [setDigits, setAcc, Function.update_apply] | |
| @[simp] theorem putDigit_extra (i : Fin u) (base : Tape u Extra → List Bool) | |
| (d r : ℕ) (a : Extra) : putDigit i base d r (.extra a) = base (.extra a) := by | |
| simp [putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt] | |
| theorem putDigit_setAcc (i : Fin u) (base : Tape u Extra → List Bool) | |
| (d r : ℕ) (a : Extra) (bits : List Bool) : | |
| putDigit i (setAcc a base bits) d r = setAcc a (putDigit i base d r) bits := by | |
| funext k | |
| cases k <;> simp [putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, | |
| setAcc, Function.update_apply] | |
| theorem setDigits_putDigit (m q : ℕ) (hq : q < u) (digits : Fin q → ℕ) | |
| (base : Tape u Extra → List Bool) (d r : ℕ) : | |
| setDigits m digits (putDigit ⟨q, hq⟩ base d r) = | |
| putDigit ⟨q, hq⟩ (setDigits m digits base) d r := by | |
| funext k | |
| cases k with | |
| | current i => | |
| by_cases hi : i.val < q | |
| · have hne : i ≠ ⟨q, hq⟩ := by intro h; have := congrArg Fin.val h; simp at this; omega | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, hi, hne] | |
| · simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, hi, | |
| Function.update_apply] | |
| | remaining i => | |
| by_cases hi : i.val < q | |
| · have hne : i ≠ ⟨q, hq⟩ := by intro h; have := congrArg Fin.val h; simp at this; omega | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, hi, hne] | |
| · simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, hi, | |
| Function.update_apply] | |
| | _ => simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt] | |
| theorem setDigits_snoc (m q : ℕ) (hq : q < u) (digits : Fin q → ℕ) | |
| (d : ℕ) (base : Tape u Extra → List Bool) : | |
| setDigits m (Fin.snoc digits d) base = | |
| putDigit ⟨q, hq⟩ (setDigits m digits base) d (m - 1 - d) := by | |
| funext k | |
| cases k with | |
| | current i => | |
| by_cases hi : i.val < q | |
| · have hi' : i.val < q + 1 := by omega | |
| have hne : i ≠ ⟨q, hq⟩ := by intro h; have := congrArg Fin.val h; simp at this; omega | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, | |
| hi, hi', hne, Fin.snoc] | |
| · by_cases he : i.val = q | |
| · have hie : i = ⟨q, hq⟩ := Fin.ext he | |
| subst i | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, Fin.snoc] | |
| · have hi' : ¬ i.val < q + 1 := by omega | |
| have hne : i ≠ ⟨q, hq⟩ := by intro h; exact he (congrArg Fin.val h) | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, | |
| hi, hi', hne] | |
| | remaining i => | |
| by_cases hi : i.val < q | |
| · have hi' : i.val < q + 1 := by omega | |
| have hne : i ≠ ⟨q, hq⟩ := by intro h; have := congrArg Fin.val h; simp at this; omega | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, | |
| hi, hi', hne, Fin.snoc] | |
| · by_cases he : i.val = q | |
| · have hie : i = ⟨q, hq⟩ := Fin.ext he | |
| subst i | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, Fin.snoc] | |
| · have hi' : ¬ i.val < q + 1 := by omega | |
| have hne : i ≠ ⟨q, hq⟩ := by intro h; exact he (congrArg Fin.val h) | |
| simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt, | |
| hi, hi', hne] | |
| | _ => simp [setDigits, putDigit, digitTapes, MachineUnaryAddAt.unaryTapes, tapesAt] | |
| theorem setDigits_snoc_base (m q : ℕ) (hq : q < u) (digits : Fin q → ℕ) | |
| (d : ℕ) (base : Tape u Extra → List Bool) : | |
| setDigits m digits (putDigit ⟨q, hq⟩ base d (m - 1 - d)) = | |
| setDigits m (Fin.snoc digits d) base := by | |
| rw [setDigits_putDigit, setDigits_snoc] | |
| def allBits {q : ℕ} (bits : (Fin q → Fin m) → List Bool) : List Bool := | |
| (tupleOrder m q).flatMap bits | |
| def blockPrefix (blocks : ℕ → List Bool) : ℕ → List Bool | |
| | 0 => [] | |
| | n + 1 => blockPrefix blocks n ++ blocks n | |
| theorem blockPrefix_eq_ofFn (blocks : ℕ → List Bool) (n : ℕ) : | |
| blockPrefix blocks n = (List.ofFn (fun i : Fin n => blocks i.val)).flatten := by | |
| induction n with | |
| | zero => simp [blockPrefix] | |
| | succ n ih => | |
| rw [blockPrefix, List.ofFn_succ', List.concat_eq_append, List.flatten_append] | |
| simpa only [Fin.val_castSucc, Fin.val_last, List.flatten_cons, | |
| List.flatten_nil, List.append_nil] using congrArg (fun xs => xs ++ blocks n) ih | |
| def blocks {q : ℕ} (bits : (Fin (q + 1) → Fin m) → List Bool) (d : ℕ) : List Bool := | |
| if h : d < m then allBits (fun c => bits (Fin.snoc c ⟨d, h⟩)) else [] | |
| theorem blockPrefix_all {q : ℕ} (bits : (Fin (q + 1) → Fin m) → List Bool) : | |
| blockPrefix (blocks bits) m = allBits bits := by | |
| rw [blockPrefix_eq_ofFn] | |
| simp only [blocks, Fin.isLt, ↓reduceDIte, allBits, tupleOrder_snoc] | |
| simp only [List.flatMap_assoc, List.flatMap_map] | |
| simp only [List.flatMap_def, List.map_ofFn, Function.comp_def] | |
| def configuration (label : Λ) (canonical : σ) (tapes : Tape u Extra → List Bool) : | |
| Configuration (Tape u Extra) Λ σ := ⟨some label, (canonical, none), tapes⟩ | |
| def BodyTrace (program : Λ → TM2.Stmt (fun _ : Tape u Extra => Bool) Λ (σ × Option Bool)) | |
| (bodyLabel returnLabel : Λ) (canonical : σ) (accumulator : Extra) | |
| {q : ℕ} (base : Tape u Extra → List Bool) | |
| (bits : (Fin q → Fin m) → List Bool) (B : ℕ) : Prop := | |
| ∀ c output, ∃ count, count ≤ B ∧ (MachineComposition.advance (TM2.step program))^[count] | |
| (some (configuration bodyLabel canonical | |
| (setDigits m (fun i => (c i).val) (setAcc accumulator base output)))) = | |
| some (configuration returnLabel canonical | |
| (setDigits m (fun i => (c i).val) | |
| (setAcc accumulator base ((bits c).reverse ++ output)))) | |
| theorem val_snoc {q : ℕ} (c : Fin q → Fin m) (d : Fin m) : | |
| (fun i : Fin (q + 1) => (Fin.snoc (α := fun _ => Fin m) c d i).val) = | |
| Fin.snoc (fun i => (c i).val) d.val := by | |
| funext i | |
| refine Fin.lastCases ?_ (fun j => ?_) i <;> simp | |
| theorem zeros_snoc (q : ℕ) : | |
| Fin.snoc (fun _ : Fin q => (0 : ℕ)) 0 = fun _ : Fin (q + 1) => 0 := by | |
| funext i | |
| refine Fin.lastCases ?_ (fun j => ?_) i <;> simp | |
| def initialConfiguration (q : ℕ) (bodyLabel : Λ) (canonical : σ) | |
| (base : Tape u Extra → List Bool) : Configuration (Tape u Extra) Λ σ := | |
| configuration bodyLabel canonical (setDigits m (fun _ : Fin q => 0) base) | |
| def finalConfiguration {q : ℕ} (exitLabel : Λ) (canonical : σ) (accumulator : Extra) | |
| (base : Tape u Extra → List Bool) (bits : (Fin q → Fin m) → List Bool) : | |
| Configuration (Tape u Extra) Λ σ := | |
| configuration exitLabel canonical (setDigits m (fun _ : Fin q => 0) | |
| (setAcc accumulator base ((allBits bits).reverse ++ base (.extra accumulator)))) | |
| theorem exists_schedule | |
| (program : Λ → TM2.Stmt (fun _ : Tape u Extra => Bool) Λ (σ × Option Bool)) | |
| (bodyLabel : Λ) (next resetLabel : ℕ → Λ) (canonical : σ) (accumulator : Extra) | |
| (positive : 0 < m) (B q : ℕ) (hq : q ≤ u) | |
| (base : Tape u Extra → List Bool) (bits : (Fin q → Fin m) → List Bool) | |
| (atCheck : ∀ i, i < q → program (next i) = | |
| increment (currentAt accumulator i) (remainingAt accumulator i) bodyLabel (resetLabel i)) | |
| (atReset : ∀ i, i < q → program (resetLabel i) = | |
| reset (currentAt accumulator i) (remainingAt accumulator i) (resetLabel i) (next (i + 1))) | |
| (bodies : BodyTrace program bodyLabel (next 0) canonical accumulator base bits B) : | |
| ∃ tree : NestedCycle m (currentAt accumulator) (remainingAt accumulator) bodyLabel | |
| next resetLabel program q (next q) | |
| (initialConfiguration (m := m) q bodyLabel canonical base) | |
| (finalConfiguration (next q) canonical accumulator base bits), tree.LeafBound B := by | |
| classical | |
| induction q generalizing base with | |
| | zero => | |
| let empty : Fin 0 → Fin m := fun i => Fin.elim0 i | |
| obtain ⟨count, hcount, run⟩ := bodies empty (base (.extra accumulator)) | |
| have hrun : (MachineComposition.advance (TM2.step program))^[count] | |
| (some (initialConfiguration (m := m) 0 bodyLabel canonical base)) = | |
| some (finalConfiguration (next 0) canonical accumulator base bits) := by | |
| simpa only [initialConfiguration, finalConfiguration, allBits, | |
| tupleOrder_dimension_zero, List.flatMap_cons, List.flatMap_nil, List.append_nil, | |
| setDigits_zero, setAcc_self] using run | |
| let tree := NestedCycle.leaf (n := m) (current := currentAt accumulator) | |
| (remaining := remainingAt accumulator) (bodyLabel := bodyLabel) | |
| (checkLabel := next) (resetLabel := resetLabel) (program := program) | |
| (next 0) (initialConfiguration (m := m) 0 bodyLabel canonical base) | |
| (finalConfiguration (next 0) canonical accumulator base bits) count rfl rfl hrun | |
| refine ⟨tree, ?_⟩ | |
| dsimp only [tree] | |
| erw [NestedCycle.LeafBound] | |
| exact hcount | |
| | succ q ih => | |
| have hqu : q < u := by omega | |
| let s : CycleSchedule (Tape u Extra) σ := { | |
| currentSuffix := [] | |
| remainingSuffix := [] | |
| ambient := fun _ => canonical | |
| register := fun _ => none | |
| base := fun r => setDigits m (fun _ : Fin q => 0) | |
| (setAcc accumulator base | |
| ((blockPrefix (blocks bits) (m - r)).reverse ++ base (.extra accumulator))) } | |
| have childrenExist (r : Fin m) : | |
| ∃ tree : NestedCycle m (currentAt accumulator) (remainingAt accumulator) bodyLabel | |
| next resetLabel program q (next q) | |
| (bodyConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| bodyLabel (m - 1) r.val s.currentSuffix s.remainingSuffix s.ambient s.base) | |
| (checkConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| (next q) (m - 1) r.val s.currentSuffix s.remainingSuffix | |
| s.ambient s.register s.base), tree.LeafBound B := by | |
| let d : Fin m := NestedCycle.reverseDigit r | |
| let childBits : (Fin q → Fin m) → List Bool := fun c => bits (Fin.snoc c d) | |
| let childBase := putDigit ⟨q, hqu⟩ | |
| (setAcc accumulator base | |
| ((blockPrefix (blocks bits) (m - (r.val + 1))).reverse ++ base (.extra accumulator))) | |
| d.val (m - 1 - d.val) | |
| have hrem : m - 1 - d.val = r.val := by | |
| dsimp [d, NestedCycle.reverseDigit] | |
| omega | |
| have hbefore : m - (r.val + 1) = d.val := by | |
| dsimp [d, NestedCycle.reverseDigit] | |
| omega | |
| have hafter : m - r.val = d.val + 1 := by | |
| dsimp [d, NestedCycle.reverseDigit] | |
| omega | |
| have hprefix : blockPrefix (blocks bits) (m - r.val) = | |
| blockPrefix (blocks bits) (m - (r.val + 1)) ++ allBits childBits := by | |
| rw [hafter, hbefore, blockPrefix] | |
| simp only [blocks, d.isLt, ↓reduceDIte, childBits] | |
| have childBodies : BodyTrace program bodyLabel (next 0) canonical accumulator | |
| childBase childBits B := by | |
| intro c output | |
| obtain ⟨count, hcount, h⟩ := bodies (Fin.snoc c d) output | |
| refine ⟨count, hcount, ?_⟩ | |
| simpa only [childBase, childBits, ← putDigit_setAcc, | |
| setAcc_setAcc, setDigits_snoc_base, ← val_snoc] using h | |
| have lower := ih (by omega) childBase childBits | |
| (fun i hi => atCheck i (by omega)) (fun i hi => atReset i (by omega)) | |
| childBodies | |
| have hstart : initialConfiguration (m := m) q bodyLabel canonical childBase = | |
| bodyConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| bodyLabel (m - 1) r.val s.currentSuffix s.remainingSuffix s.ambient s.base := by | |
| simp only [initialConfiguration, configuration, bodyConfiguration, s, childBase, | |
| currentAt, remainingAt, hqu, ↓reduceDIte, setDigits_putDigit, hrem] | |
| rfl | |
| have hfinish : finalConfiguration (next q) canonical accumulator childBase childBits = | |
| checkConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| (next q) (m - 1) r.val s.currentSuffix s.remainingSuffix | |
| s.ambient s.register s.base := by | |
| simp only [finalConfiguration, configuration, checkConfiguration, s, childBase, | |
| currentAt, remainingAt, hqu, ↓reduceDIte, putDigit_extra, setAcc_apply, | |
| ← putDigit_setAcc, setAcc_setAcc, setDigits_putDigit, hrem, hprefix, | |
| List.reverse_append, List.append_assoc] | |
| rfl | |
| rw [hstart, hfinish] at lower | |
| exact lower | |
| let children := fun r : Fin m => Classical.choose (childrenExist r) | |
| let tree := NestedCycle.node q (next (q + 1)) positive | |
| (by simp [currentAt, remainingAt, hqu]) | |
| (atCheck q (by omega)) (atReset q (by omega)) s children | |
| have hbounded : tree.LeafBound B := by | |
| simp only [tree, NestedCycle.LeafBound] | |
| intro r | |
| exact Classical.choose_spec (childrenExist r) | |
| have hstart : bodyConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| bodyLabel (m - 1) (m - 1) s.currentSuffix s.remainingSuffix s.ambient s.base = | |
| initialConfiguration (m := m) (q + 1) bodyLabel canonical base := by | |
| have hm : m - 1 + 1 = m := by omega | |
| simp only [bodyConfiguration, initialConfiguration, configuration, s, | |
| currentAt, remainingAt, hqu, ↓reduceDIte, Nat.sub_self, hm, | |
| blockPrefix, List.reverse_nil, List.nil_append, setAcc_self] | |
| rw [← zeros_snoc q, setDigits_snoc m q hqu] | |
| rfl | |
| have hfinish : cycleExit (currentAt accumulator q) (remainingAt accumulator q) | |
| (next (q + 1)) (m - 1) s.currentSuffix s.remainingSuffix s.ambient s.base = | |
| finalConfiguration (next (q + 1)) canonical accumulator base bits := by | |
| simp only [cycleExit, finalConfiguration, configuration, s, currentAt, remainingAt, | |
| hqu, ↓reduceDIte, Nat.sub_zero, blockPrefix_all] | |
| rw [← zeros_snoc q, setDigits_snoc m q hqu] | |
| rfl | |
| have result := (show ∃ t : NestedCycle m (currentAt accumulator) (remainingAt accumulator) | |
| bodyLabel next resetLabel program (q + 1) (next (q + 1)) | |
| (bodyConfiguration (currentAt accumulator q) (remainingAt accumulator q) | |
| bodyLabel (m - 1) (m - 1) s.currentSuffix s.remainingSuffix s.ambient s.base) | |
| (cycleExit (currentAt accumulator q) (remainingAt accumulator q) | |
| (next (q + 1)) (m - 1) s.currentSuffix s.remainingSuffix s.ambient s.base), | |
| t.LeafBound B from ⟨tree, hbounded⟩) | |
| rw [hstart, hfinish] at result | |
| exact result | |
| theorem traversalInTime | |
| (program : Λ → TM2.Stmt (fun _ : Tape u Extra => Bool) Λ (σ × Option Bool)) | |
| (bodyLabel : Λ) (next resetLabel : ℕ → Λ) (canonical : σ) (accumulator : Extra) | |
| (positive : 0 < m) (B : ℕ) (base : Tape u Extra → List Bool) | |
| (bits : (Fin u → Fin m) → List Bool) | |
| (atCheck : ∀ i, i < u → program (next i) = | |
| increment (currentAt accumulator i) (remainingAt accumulator i) bodyLabel (resetLabel i)) | |
| (atReset : ∀ i, i < u → program (resetLabel i) = | |
| reset (currentAt accumulator i) (remainingAt accumulator i) (resetLabel i) (next (i + 1))) | |
| (bodies : BodyTrace program bodyLabel (next 0) canonical accumulator base bits B) : | |
| Nonempty (StateTransition.EvalsToInTime (TM2.step program) | |
| (initialConfiguration (m := m) u bodyLabel canonical base) | |
| (some (finalConfiguration (next u) canonical accumulator base bits)) | |
| ((B + 2 * u) * m ^ u)) := by | |
| obtain ⟨tree, ht⟩ := exists_schedule program bodyLabel next resetLabel canonical accumulator | |
| positive B u (Nat.le_refl _) base bits atCheck atReset bodies | |
| exact ⟨{ | |
| steps := tree.steps | |
| evals_in_steps := tree.trace | |
| steps_le_m := tree.steps_le_power positive B ht }⟩ | |
| omit [DecidableEq Extra] in | |
| @[simp] theorem initial_current (base : Tape u Extra → List Bool) | |
| (bodyLabel : Λ) (canonical : σ) (i : Fin u) : | |
| (initialConfiguration (m := m) u bodyLabel canonical base).stk (.current i) = | |
| encodeWord 0 := by simp [initialConfiguration, configuration, setDigits] | |
| omit [DecidableEq Extra] in | |
| @[simp] theorem initial_remaining (base : Tape u Extra → List Bool) | |
| (bodyLabel : Λ) (canonical : σ) (i : Fin u) : | |
| (initialConfiguration (m := m) u bodyLabel canonical base).stk (.remaining i) = | |
| encodeWord (m - 1) := by simp [initialConfiguration, configuration, setDigits] | |
| @[simp] theorem final_current (base : Tape u Extra → List Bool) | |
| (exitLabel : Λ) (canonical : σ) (accumulator : Extra) | |
| (bits : (Fin u → Fin m) → List Bool) (i : Fin u) : | |
| (finalConfiguration exitLabel canonical accumulator base bits).stk (.current i) = | |
| encodeWord 0 := by simp [finalConfiguration, configuration, setDigits] | |
| @[simp] theorem final_remaining (base : Tape u Extra → List Bool) | |
| (exitLabel : Λ) (canonical : σ) (accumulator : Extra) | |
| (bits : (Fin u → Fin m) → List Bool) (i : Fin u) : | |
| (finalConfiguration exitLabel canonical accumulator base bits).stk (.remaining i) = | |
| encodeWord (m - 1) := by simp [finalConfiguration, configuration, setDigits] | |
| @[simp] theorem final_accumulator (base : Tape u Extra → List Bool) | |
| (exitLabel : Λ) (canonical : σ) (accumulator : Extra) | |
| (bits : (Fin u → Fin m) → List Bool) : | |
| (finalConfiguration exitLabel canonical accumulator base bits).stk (.extra accumulator) = | |
| ((tupleOrder m u).flatMap bits).reverse ++ base (.extra accumulator) := by | |
| simp [finalConfiguration, configuration, allBits] | |
| end MinUncutGames.Foundations.Hastad.SourceOdometerSchedule | |
| namespace MinUncutGames.Foundations.Hastad.SourceGeneratorProgram | |
| open Turing Complexity SourceGeneratorModel | |
| noncomputable section | |
| abbrev Tape (u D : Nat) := SourceGeneratorModel.Tape u D | |
| abbrev Ambient (u D : Nat) := SourceGeneratorModel.ControlAmbient u D | |
| abbrev State (u D : Nat) := Ambient u D × Option Bool | |
| local instance sourceGeneratorProgramExtraDecidableEq (u D : Nat) : | |
| DecidableEq (Extra u D) := Classical.decEq _ | |
| inductive Label (u D : Nat) | |
| | startup (label : SourceStartup.Label u D) | |
| | body (label : SourceTupleBody.Label u D (Extra u D)) | |
| | check (coordinate : Fin u) | |
| | reset (coordinate : Fin u) | |
| | finishEnter | |
| | finish (label : SourceRuntimeFinish.Label (clearKeys u D)) | |
| deriving DecidableEq, Fintype | |
| def bodyEntry (u D : Nat) : Label u D := .body SourceTupleBody.main | |
| def next (u D : Nat) (i : Nat) : Label u D := | |
| if h : i < u then .check ⟨i, h⟩ else .finishEnter | |
| def sourceStateEquiv (u D : Nat) : SourceRuntimeModel.State u D × Unit ≃ State u D where | |
| toFun x := (controlStateEquiv u D).symm x.1 | |
| invFun x := (controlStateEquiv u D x, ()) | |
| left_inv x := by cases x with | mk x y => cases y; simp | |
| right_inv x := by simp | |
| def program (u D : Nat) (hD : 0 < D) : | |
| Label u D → TM2.Stmt (fun _ : Tape u D => Bool) (Label u D) (State u D) | |
| | .startup l => SourceTupleBody.framed (sourceStateEquiv u D) Label.startup | |
| (some (bodyEntry u D)) (SourceStartup.program l) | |
| | .body l => SourceTupleBody.framed (sourceStateEquiv u D) Label.body | |
| (some (next u D 0)) | |
| (SourceTupleBody.program (initialQuery u D hD) none l) | |
| | .check i => MachineTupleOdometer.increment | |
| (.current i) (.remaining i) (bodyEntry u D) (.reset i) | |
| | .reset i => MachineTupleOdometer.reset | |
| (.current i) (.remaining i) (.reset i) (next u D (i.val + 1)) | |
| | .finishEnter => Reduction.MachineTransfer.exitAt (accumulatorTape u D) | |
| (SourceRuntimeFinish.entry (clearKeys u D) Label.finish) | |
| | .finish l => SourceRuntimeFinish.statement (clearKeys u D) | |
| (accumulatorTape u D) (outputTape u D) (initialAmbient u D hD) | |
| Label.finish none l | |
| def main (u D : Nat) : Label u D := .startup (.inl .inputCopyOut) | |
| def machine (u D : Nat) (hD : 0 < D) : FinTM2 where | |
| K := Tape u D | |
| k₀ := .formula | |
| k₁ := outputTape u D | |
| Γ _ := Bool | |
| Λ := Label u D | |
| main := main u D | |
| σ := State u D | |
| initialState := (initialAmbient u D hD, none) | |
| m := program u D hD | |
| theorem finite_work_alphabets (u D : Nat) (hD : 0 < D) | |
| (k : (machine u D hD).K) : Finite ((machine u D hD).Γ k) := by | |
| change Finite Bool | |
| infer_instance | |
| theorem atCheck (u D : Nat) (hD : 0 < D) (i : Fin u) : | |
| program u D hD (.check i) = MachineTupleOdometer.increment | |
| (.current i) (.remaining i) (bodyEntry u D) (.reset i) := rfl | |
| theorem atReset (u D : Nat) (hD : 0 < D) (i : Fin u) : | |
| program u D hD (.reset i) = MachineTupleOdometer.reset | |
| (.current i) (.remaining i) (.reset i) (next u D (i.val + 1)) := rfl | |
| end | |
| end MinUncutGames.Foundations.Hastad.SourceGeneratorProgram | |
| namespace MinUncutGames.Foundations.Hastad.SourceGenerator | |
| open Turing Complexity Target | |
| open SourceGeneratorModel SourceGeneratorProgram SourceGeneratorContract | |
| noncomputable section | |
| variable {u D : Nat} | |
| local instance sourceGeneratorExtraDecidableEq : DecidableEq (Extra u D) := Classical.decEq _ | |
| theorem source_initial (u D : Nat) (hD : 0 < D) : | |
| sourceStateEquiv u D (SourceGeneratorModel.initialState u D hD, ()) = | |
| (initialAmbient u D hD, none) := rfl | |
| theorem initial_configuration (F : Formula) (hD : 0 < D) : | |
| initList (SourceGeneratorProgram.machine u D hD) (formulaBits F) = | |
| (⟨some (SourceGeneratorProgram.main u D), (initialAmbient u D hD, none), | |
| SourceStartup.initialTapes F⟩ : (SourceGeneratorProgram.machine u D hD).Cfg) := by | |
| simp only [initList, SourceGeneratorProgram.machine] | |
| congr 1 | |
| funext k | |
| by_cases hk : k = SourceContextLoad.Tape.formula | |
| · subst k | |
| simp [SourceStartup.initialTapes] | |
| rfl | |
| · simp [SourceStartup.initialTapes, hk] | |
| def startupInTime (F : Formula) (hm : 0 < F.clauses.length) (hD : 0 < D) : | |
| StateTransition.EvalsToInTime (SourceGeneratorProgram.machine u D hD).step | |
| (initList (SourceGeneratorProgram.machine u D hD) (formulaBits F)) | |
| (some ⟨some (bodyEntry u D), (initialAmbient u D hD, none), SourceStartup.readyTapes F⟩) | |
| ((SourceStartup.timePolynomial u D).eval (formulaBits F).length) := by | |
| have run := SourceTupleBody.framedExecution (sourceStateEquiv u D) | |
| SourceGeneratorProgram.Label.startup (some (bodyEntry u D)) () | |
| SourceStartup.program (SourceGeneratorProgram.program u D hD) (fun _ => rfl) | |
| (SourceStartup.startupInPolynomialTime (u := u) F hm hD) | |
| rw [initial_configuration F hD] | |
| simpa only [SourceTupleBody.framedConfiguration, MachineStateFrame.configuration, | |
| MachineControl.configuration, MachineSubroutine.configuration, | |
| MachineStateFrame.frameConfiguration, MachineSubroutine.label, source_initial, | |
| Option.map_some, Option.map_none, id_eq, SourceGeneratorProgram.main, | |
| FinTM2.step, FinTM2.Cfg, SourceGeneratorProgram.machine] using! run | |
| end | |
| end MinUncutGames.Foundations.Hastad.SourceGenerator | |
| end OAI | |
Xet Storage Details
- Size:
- 33.1 kB
- Xet hash:
- dc13ed67c1a916343b81d4a5b2ea907d0666f9edd204d2a1f7662d244d8bc136
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.