diff --git a/.github/workflows/lean_action_ci.yml b/.github/workflows/lean_action_ci.yml index b6035a75..56232cea 100644 --- a/.github/workflows/lean_action_ci.yml +++ b/.github/workflows/lean_action_ci.yml @@ -46,14 +46,17 @@ jobs: sudo apt-get install -y -qq bubblewrap >/dev/null sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 - - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 - - uses: leanprover/lean-action@24581d74d674803a25a81b10b059c5c0cdd344c6 # v1 + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + - uses: leanprover/lean-action@fe408643ea7367d8c0404a8be3975bb145f5fb64 # v1.7.0 with: build-args: "Cryptids Challenge" env: LEAN_NUM_THREADS: "1" - - name: Verify constructive reductions and ZF proof-search equivalences (no Classical.choice) + - name: Verify zero-axiom state counts and PA consistency (no axioms) + run: lake comparator --config comparator/zero_axioms.json + + - name: Verify constructive reductions, ZF proof-search, and PA adequacy (no Classical.choice) run: lake comparator --config comparator/constructive.json - name: Verify all theorems against Challenge with comparator diff --git a/BusyBeaver/Bridge.lean b/BusyBeaver/Bridge.lean index 44ef97dd..6317e27c 100644 --- a/BusyBeaver/Bridge.lean +++ b/BusyBeaver/Bridge.lean @@ -105,28 +105,88 @@ variable {states symbols : ℕ} [NeZero states] [NeZero symbols] /-- Embed `ConjectureMachines.ListBlank Γ` into Mathlib's `Turing.ListBlank Γ`. -/ def ListBlank.toTuring {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : Turing.ListBlank Γ := - l.liftOn Turing.ListBlank.mk fun _ _ h => Quotient.sound' (Or.inl h) + Turing.ListBlank.mk l.toList + +private theorem ListBlank.not_isTrimmed_replicate {Γ : Type*} [Inhabited Γ] : + ∀ i : ℕ, 1 ≤ i → ¬ ListBlank.IsTrimmed (List.replicate i (default : Γ)) + | 0, h => absurd h (Nat.not_succ_le_zero 0) + | 1, _ => fun ht => ht rfl + | i + 2, _ => fun ht => ListBlank.not_isTrimmed_replicate (i + 1) (Nat.succ_pos i) ht + +private theorem ListBlank.eq_of_isTrimmed_blankExtends {Γ : Type*} [Inhabited Γ] : + ∀ {xs ys : List Γ}, ListBlank.IsTrimmed xs → ListBlank.IsTrimmed ys → + Turing.BlankExtends xs ys → xs = ys + | [], [], _, _, _ => rfl + | [], [b], _, hy, ⟨i, hi⟩ => by + cases i with + | zero => cases hi + | succ j => + simp only [List.nil_append, List.replicate_succ] at hi + injection hi with hb _ + exact False.elim (hy hb) + | [], b :: c :: ys, _, hy, ⟨i, hi⟩ => by + cases i with + | zero => cases hi + | succ j => + simp only [List.nil_append] at hi + exact False.elim (ListBlank.not_isTrimmed_replicate (j + 1) (Nat.succ_pos j) (hi ▸ hy)) + | _ :: _, [], _, _, ⟨_, hi⟩ => by cases hi + | [a], [b], _, _, ⟨i, hi⟩ => by + cases i with + | zero => + simp only [List.replicate_zero, List.append_nil] at hi + exact hi.symm + | succ j => + simp only [List.singleton_append, List.replicate_succ] at hi + injection hi with _ hnil + cases hnil + | [_], _ :: c :: ys, _, hy, ⟨i, hi⟩ => by + simp only [List.singleton_append] at hi + injection hi with _ htl + cases i with + | zero => cases htl + | succ j => + exact False.elim (ListBlank.not_isTrimmed_replicate (j + 1) (Nat.succ_pos j) (htl ▸ hy)) + | _ :: _ :: _, [_], _, _, ⟨_, hi⟩ => by + injection hi with _ htl + cases htl + | _ :: b :: xs, c :: d :: ys, hx, hy, ⟨i, hi⟩ => by + injection hi with hac htl + rw [← hac] + exact congrArg (c :: ·) (ListBlank.eq_of_isTrimmed_blankExtends hx hy ⟨i, htl⟩) @[simp] theorem ListBlank.toTuring_inj {Γ : Type*} [Inhabited Γ] {l₁ l₂ : ListBlank Γ} : - l₁.toTuring = l₂.toTuring ↔ l₁ = l₂ := - ⟨l₁.induction_on fun _ => l₂.induction_on fun _ h => Quot.sound (Quotient.exact' h), - congrArg _⟩ + l₁.toTuring = l₂.toTuring ↔ l₁ = l₂ := by + constructor + · intro h + apply ListBlank.ext + rcases Quotient.exact' h with h₁ | h₂ + · exact ListBlank.eq_of_isTrimmed_blankExtends l₁.isTrimmed l₂.isTrimmed h₁ + · exact (ListBlank.eq_of_isTrimmed_blankExtends l₂.isTrimmed l₁.isTrimmed h₂).symm + · exact congrArg _ @[simp] theorem ListBlank.toTuring_head {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : l.toTuring.head = l.head := - l.induction_on fun _ => rfl + rfl @[simp] theorem ListBlank.toTuring_tail {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : l.toTuring.tail = l.tail.toTuring := - l.induction_on fun _ => rfl + rfl @[simp] -theorem ListBlank.toTuring_cons {Γ : Type*} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : - l.toTuring.cons a = (l.cons a).toTuring := - l.induction_on fun _ => rfl +theorem ListBlank.toTuring_cons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + (a : Γ) (l : ListBlank Γ) : + l.toTuring.cons a = (l.cons a).toTuring := by + rcases l with ⟨_ | ⟨b, xs⟩, _⟩ + · change Turing.ListBlank.mk [a] = Turing.ListBlank.mk (if a = default then [] else [a]) + by_cases ha : a = default + · rw [ite_eq_left ha, ha] + exact Quotient.sound' (Or.inr ⟨1, rfl⟩) + · rw [ite_eq_right ha] + · rfl /-- Embed `ConjectureMachines.Tape Γ` into Mathlib's `Turing.Tape Γ`. -/ def Tape.toTuring {Γ : Type*} [Inhabited Γ] (T : Tape Γ) : Turing.Tape Γ := diff --git a/BusyBeaverChallenge.lean b/BusyBeaverChallenge.lean index dce54077..4baa6c77 100644 --- a/BusyBeaverChallenge.lean +++ b/BusyBeaverChallenge.lean @@ -17,6 +17,28 @@ meta import Lean.Elab.Term namespace ConjectureMachines open Turing +scoped instance (priority := 10000) instZeroNatConstructive : Zero ℕ := ⟨0⟩ +scoped instance (priority := 10000) instLTNatConstructive : LT ℕ := instLTNat + +theorem pos_of_neZero (n : ℕ) [h : NeZero n] : 0 < n := + Nat.casesOn (motive := fun k => NeZero k → 0 < k) n + (fun h0 => False.elim (h0.out rfl)) + (fun k _ => Nat.zero_lt_succ k) + h + +scoped instance (priority := 10000) instOfNatFinConstructive (n : ℕ) [NeZero n] (i : ℕ) : + OfNat (Fin n) i := + ⟨⟨i % n, Nat.mod_lt i (pos_of_neZero n)⟩⟩ +scoped instance (priority := 10000) instInhabitedFinConstructive (n : ℕ) [NeZero n] : + Inhabited (Fin n) := + ⟨0⟩ + +@[simp] +def listGetD {α : Type*} : List α → ℕ → α → α + | [], _, d => d + | a :: _, 0, _ => a + | _ :: xs, n + 1, d => listGetD xs n d + /-- A Turing machine transition table over `states` states and `symbols` symbols. -/ structure Machine (states symbols : ℕ) where transition : Fin states → Fin symbols → Option (Fin symbols × Dir × Fin states) @@ -25,7 +47,7 @@ variable {states symbols : ℕ} [NeZero states] [NeZero symbols] /-- Build a `Machine states symbols` from a list of per-state transition rows. -/ def Machine.ofRows (rows : List (List (Option (Fin symbols × Dir × Fin states)))) : - Machine states symbols := ⟨fun q a => (rows.getD q.val []).getD a.val none⟩ + Machine states symbols := ⟨fun q a => listGetD (listGetD rows q.val []) a.val none⟩ end ConjectureMachines end diff --git a/Challenge.lean b/Challenge.lean index 60991aec..040c9efe 100644 --- a/Challenge.lean +++ b/Challenge.lean @@ -18,32 +18,34 @@ meta import Lean.Elab.Term Self-contained specification module audited against `Cryptids` by `leanprover/comparator`: +- **Zero-axiom gate (`comparator/zero_axioms.json`; `permitted_axioms = []`):** + Specification definitions (`ListBlank`, `Tape`, `Halts`, `Machine`, `BundledMachine`, `candidate`, + `reference`, `PAProvable`) are quotient-free and axiom-free (`ListBlank` stores a canonical + blank-trimmed `List Γ`), and all five `candidate_fewer_states` theorems together with syntactic + `PA` consistency (`Semantics.PA.not_paProvable_false`) depend on **zero axioms (`[]`)**. - **Constructive gate (`comparator/constructive.json`, `goldbach_21.json`, `zf_380.json`, - `riemann_104.json`; `permitted_axioms = ["propext", "Quot.sound"]`):** - The direct simulation state reductions (`Goldbach21`, `Zf380`, `Riemann104`), the `ErdosTernary14` - reduction, all five `candidate_fewer_states` theorems (including - `Riemann95.candidate_fewer_states`), all ZF - machine-to-proof-search equivalences (`Zf393.halts_zf393_iff_zfInconsistent`, + `riemann_104.json`, `riemann_95_reduction.json`; + `permitted_axioms = ["propext", "Quot.sound"]`):** + All five state reductions (`Goldbach21`, `Zf380`, `Riemann104`, `Riemann95`, `ErdosTernary14`), + all ZF machine-to-proof-search equivalences (`Zf393.halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, - `Semantics.Zf.halts_zf432_iff_wadeZFInconsistent`), and first-order Peano Arithmetic (`PA`) + `Semantics.Zf.halts_zf432_iff_wadeZFInconsistent`), first-order Peano Arithmetic (`PA`) consistency and $\Sigma_1^0$ standard-model adequacy (`Semantics.PA.not_paProvable_false`, `Semantics.PA.paHalts_holds_iff_halts`, `Semantics.PA.paZFInconsistent_holds_iff_zfInconsistent`), and the `brocard_28` equivalence `Brocard28.halts_brocard28_iff_exists_square` - are verified **without `Classical.choice`** (`ListBlank` uses primitive `Quot` rather than - `Quotient` so `Halts` is choice-free). Because `Zf/Soundness.lean` proves `not_zfInconsistent` - via `ZFSet.{0}` (`Classical.choice`)—and `CIC + EM` proves `Con(ZF)` without choice - (`digama0/ConZF`)—disallowing `Classical.choice` blocks classical `Con(ZF)` shortcuts for + are verified **without `Classical.choice`**. Because `Zf/Soundness.lean` proves + `not_zfInconsistent` via `ZFSet.{0}` (`Classical.choice`)—and `CIC + EM` proves `Con(ZF)` without + choice (`digama0/ConZF`)—disallowing `Classical.choice` blocks classical `Con(ZF)` shortcuts for `Halts M ↔ ZFInconsistent`, while deeply embedded `PAProvable` provides a weak first-order metatheory that cannot prove `Con(PA)` or `Con(ZF)` (see `Cryptids/Semantics/README.md`). - **Full gate (`comparator/all.json`; `permitted_axioms = ["propext", "Quot.sound", "Classical.choice"]`):** - Audits all 36 theorems, including `Riemann95.candidate_equivalent` (which uses `Classical.choice` - via `Nat.Prime`), classical `PA` and `ZFSet.{0}` soundness/non-halting, negated-`Π₁⁰` Goldbach - (`¬ GoldbachConjecture`, which uses Markov's Principle), analytic `RiemannHypothesis` - equivalences, and the `erdos_ternary_15` and `erdos_ternary_14` equivalences with - `ErdosTernaryConjecture` (`Nat.digits` uses `Classical.choice`; `¬ ErdosTernaryConjecture` also - uses Markov's Principle), and the `brocard_28` equivalence with `¬ BrocardConjecture` (Markov's - Principle). + Audits all 36 theorems, including classical `PA` and `ZFSet.{0}` soundness/non-halting, + negated-`Π₁⁰` Goldbach (`¬ GoldbachConjecture`, which uses Markov's Principle), analytic + `RiemannHypothesis` equivalences, the `erdos_ternary_15` and `erdos_ternary_14` equivalences + with `ErdosTernaryConjecture` (`Nat.digits` uses `Classical.choice`; `¬ ErdosTernaryConjecture` + also uses Markov's Principle), and the `brocard_28` equivalence with `¬ BrocardConjecture` + (Markov's Principle). -/ meta section @@ -81,6 +83,28 @@ open Turing (Dir) open StateTransition export Turing (Dir) +scoped instance (priority := 10000) instZeroNatConstructive : Zero ℕ := ⟨0⟩ +scoped instance (priority := 10000) instLTNatConstructive : LT ℕ := instLTNat +scoped instance (priority := 10000) instLENatConstructive : LE ℕ := instLENat +scoped instance (priority := 10000) instDecidableLTNatConstructive : DecidableLT ℕ := + fun a b => Nat.decLt a b +scoped instance (priority := 10000) instDecidableLENatConstructive : DecidableLE ℕ := + fun a b => Nat.decLe a b + +theorem pos_of_neZero (n : ℕ) [h : NeZero n] : 0 < n := + Nat.casesOn (motive := fun k => NeZero k → 0 < k) n + (fun h0 => False.elim (h0.out rfl)) + (fun k _ => Nat.zero_lt_succ k) + h + +scoped instance (priority := 10000) instNeZeroSuccConstructive (n : ℕ) : NeZero (n + 1) := + ⟨fun h => Nat.noConfusion h⟩ +scoped instance (priority := 10000) instOfNatFinConstructive (n : ℕ) [NeZero n] (i : ℕ) : + OfNat (Fin n) i := + ⟨⟨i % n, Nat.mod_lt i (pos_of_neZero n)⟩⟩ +scoped instance (priority := 10000) instInhabitedFinConstructive (n : ℕ) [NeZero n] : + Inhabited (Fin n) := + ⟨0⟩ scoped instance (priority := 10000) instLTFinConstructive (n : ℕ) : LT (Fin n) := instLTFin scoped instance (priority := 10000) instLEFinConstructive (n : ℕ) : LE (Fin n) := instLEFin scoped instance (priority := 10000) instDecidableEqFinConstructive (n : ℕ) : DecidableEq (Fin n) := @@ -108,42 +132,75 @@ scoped instance (priority := 10000) instLinearOrderFinConstructive (n : ℕ) : compare a b := compareOfLessAndEq a b compare_eq_compareOfLessAndEq _ _ := rfl -/-- Half-tape of a Turing machine, quotienting `List Γ` by trailing blank symbols -(`Turing.BlankRel`) via Lean's primitive `Quot` rather than `Quotient (BlankRel.setoid Γ)` so that -`ListBlank`, `Tape`, and `Halts` carry zero `Classical.choice` dependency. -/ -def ListBlank (Γ : Type*) [Inhabited Γ] := - Quot (@Turing.BlankRel Γ _) +/-- Predicate that a `List Γ` has no trailing blank (`default`) symbol. -/ +def ListBlank.IsTrimmed {Γ : Type*} [Inhabited Γ] : List Γ → Prop + | [] => True + | [a] => a ≠ default + | _ :: b :: xs => ListBlank.IsTrimmed (b :: xs) + +/-- Prepend `a` onto a blank-trimmed `List Γ`, dropping `a` iff `a = default` on `[]`. -/ +def ListBlank.trimCons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) : List Γ → List Γ + | [] => if a = default then [] else [a] + | b :: xs => a :: b :: xs + +/-- Half-tape of a Turing machine, represented concretely as a `List Γ` in canonical blank-trimmed +normal form (no trailing `default` symbols) so `ListBlank`, `Tape`, and `Halts` require zero +axioms (`Quot`, `Quot.sound`, `propext`, and `Classical.choice` are all avoided). -/ +structure ListBlank (Γ : Type*) [Inhabited Γ] where + ofTrimmed :: + toList : List Γ + isTrimmed : ListBlank.IsTrimmed toList instance ListBlank.inhabited {Γ : Type*} [Inhabited Γ] : Inhabited (ListBlank Γ) := - ⟨Quot.mk _ []⟩ - -/-- Quotient map turning a `List Γ` into a `ListBlank Γ`. -/ -def ListBlank.mk {Γ : Type*} [Inhabited Γ] : List Γ → ListBlank Γ := - Quot.mk _ - -/-- Lift a blank-extension-invariant function from `List Γ` to `ListBlank Γ`. -/ -protected abbrev ListBlank.liftOn {Γ : Type*} [Inhabited Γ] {α : Sort*} (l : ListBlank Γ) - (f : List Γ → α) (H : ∀ a b, Turing.BlankExtends a b → f a = f b) : α := - Quot.liftOn l f fun a b h => h.elim (H a b) fun h' => (H b a h').symm + ⟨⟨[], trivial⟩⟩ /-- Head symbol of a `ListBlank`. -/ def ListBlank.head {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : Γ := - l.liftOn List.headI <| by - rintro (_ | _) _ ⟨_ | _, rfl⟩ <;> rfl + l.toList.headI + +theorem ListBlank.isTrimmed_tail {Γ : Type*} [Inhabited Γ] {l : List Γ} : + ListBlank.IsTrimmed l → ListBlank.IsTrimmed l.tail := + List.casesOn (motive := fun xs => ListBlank.IsTrimmed xs → ListBlank.IsTrimmed xs.tail) l + (fun _ => trivial) + (fun a tl => + List.casesOn (motive := fun ys => ListBlank.IsTrimmed (a :: ys) → ListBlank.IsTrimmed ys) tl + (fun _ => trivial) + (fun _ _ h => h)) /-- Tail of a `ListBlank`. -/ def ListBlank.tail {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := - l.liftOn (fun l => ListBlank.mk l.tail) <| by - rintro (_ | _) _ ⟨i, rfl⟩ - · rcases i with - | i <;> - [exact Quot.sound (Or.inl ⟨0, rfl⟩); exact Quot.sound (Or.inl ⟨i, rfl⟩)] - · exact Quot.sound (Or.inl ⟨i, rfl⟩) + ⟨l.toList.tail, ListBlank.isTrimmed_tail l.isTrimmed⟩ + +theorem ListBlank.isTrimmed_trimCons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) + {l : List Γ} : ListBlank.IsTrimmed l → ListBlank.IsTrimmed (ListBlank.trimCons a l) := + List.casesOn (motive := fun xs => + ListBlank.IsTrimmed xs → ListBlank.IsTrimmed (ListBlank.trimCons a xs)) l + (fun _ => by + change ListBlank.IsTrimmed (if a = default then [] else [a]) + by_cases h : a = default + · rw [ite_eq_left h]; exact trivial + · rw [ite_eq_right h]; exact h) + (fun b tl => + List.casesOn (motive := fun ys => + ListBlank.IsTrimmed (b :: ys) → ListBlank.IsTrimmed (a :: b :: ys)) tl + (fun h => h) + (fun _ _ h => h)) /-- Prepend a symbol onto a `ListBlank`. -/ -def ListBlank.cons {Γ : Type*} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := - l.liftOn (fun l => ListBlank.mk (a :: l)) <| by - rintro _ _ ⟨i, rfl⟩ - exact Quot.sound (Or.inl ⟨i, rfl⟩) +def ListBlank.cons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) (l : ListBlank Γ) : + ListBlank Γ := + ⟨ListBlank.trimCons a l.toList, ListBlank.isTrimmed_trimCons a l.isTrimmed⟩ + +/-- Prepend a finite `List` of symbols onto a `ListBlank`. -/ +@[simp] +def ListBlank.append {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : + List Γ → ListBlank Γ → ListBlank Γ + | [], L => L + | a :: l, L => ListBlank.cons a (ListBlank.append l L) + +/-- Canonical map turning a `List Γ` into a `ListBlank Γ` by trimming trailing blanks. -/ +def ListBlank.mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : ListBlank Γ := + ListBlank.append l default /-- Bidirectional Turing machine tape over alphabet `Γ`. -/ structure Tape (Γ : Type*) [Inhabited Γ] where @@ -155,7 +212,7 @@ instance Tape.inhabited {Γ : Type*} [Inhabited Γ] : Inhabited (Tape Γ) := ⟨⟨default, default, default⟩⟩ /-- Shift the tape in response to a head movement `Dir.left` or `Dir.right`. -/ -def Tape.move {Γ : Type*} [Inhabited Γ] : Dir → Tape Γ → Tape Γ +def Tape.move {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : Dir → Tape Γ → Tape Γ | Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩ | Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩ @@ -168,13 +225,19 @@ def Tape.mk' {Γ : Type*} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ := ⟨R.head, L, R.tail⟩ /-- Construct a tape from left and inclusive-right `List`s. -/ -def Tape.mk₂ {Γ : Type*} [Inhabited Γ] (L R : List Γ) : Tape Γ := +def Tape.mk₂ {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (L R : List Γ) : Tape Γ := Tape.mk' (ListBlank.mk L) (ListBlank.mk R) /-- Construct a tape with `l` starting at the head and blanks to the left. -/ -def Tape.mk₁ {Γ : Type*} [Inhabited Γ] (l : List Γ) : Tape Γ := +def Tape.mk₁ {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : Tape Γ := Tape.mk₂ [] l +@[simp] +def listGetD {α : Type*} : List α → ℕ → α → α + | [], _, d => d + | a :: _, 0, _ => a + | _ :: xs, n + 1, d => listGetD xs n d + /-- A Turing machine transition table over `states` states and `symbols` symbols. -/ structure Machine (states symbols : ℕ) where transition : Fin states → Fin symbols → Option (Fin symbols × Dir × Fin states) @@ -199,7 +262,7 @@ def Halts (M : Machine states symbols) : Prop := (StateTransition.eval (step M) /-- Build a `Machine states symbols` from a list of per-state transition rows. -/ def Machine.ofRows (rows : List (List (Option (Fin symbols × Dir × Fin states)))) : - Machine states symbols := ⟨fun q a => (rows.getD q.val []).getD a.val none⟩ + Machine states symbols := ⟨fun q a => listGetD (listGetD rows q.val []) a.val none⟩ end /-- A Turing machine over `symbols` tape symbols bundled with its non-zero state count. -/ @@ -212,7 +275,10 @@ attribute [instance] BundledMachine.neZeroStates /-- Bundle a `Machine (states + 1) symbols` into a `BundledMachine symbols`. -/ abbrev Machine.bundle {states symbols : ℕ} (M : Machine (states + 1) symbols) : - BundledMachine symbols := ⟨states + 1, M⟩ + BundledMachine symbols := + { states := states + 1 + neZeroStates := ⟨fun h => Nat.noConfusion h⟩ + toMachine := M } /-- `M` halts when started in state `0` on the all-blank tape. -/ abbrev BundledMachine.Halts {symbols : ℕ} [NeZero symbols] (M : BundledMachine symbols) : Prop := @@ -220,6 +286,10 @@ abbrev BundledMachine.Halts {symbols : ℕ} [NeZero symbols] (M : BundledMachine export BundledMachine (Halts) +/-- info: 'ConjectureMachines.BundledMachine.Halts' does not depend on any axioms -/ +#guard_msgs in +#print axioms ConjectureMachines.BundledMachine.Halts + namespace Machines /-- Rows of `goldbach25`. -/ def goldbach25Rows : List (List (Option (Fin 2 × Dir × Fin 25))) := load_machine_rows% "baselines/tables/goldbach_25.txt" diff --git a/Cryptids/Goldbach21.lean b/Cryptids/Goldbach21.lean index 77fba1e5..43d8d926 100644 --- a/Cryptids/Goldbach21.lean +++ b/Cryptids/Goldbach21.lean @@ -152,7 +152,7 @@ theorem step_one {M : Machine 25 2} {c c₁ : Cfg 25 2} (h : step M c = some c theorem mk_append_replicate_zero (l : List (Fin 2)) (n : ℕ) : ListBlank.mk (l ++ List.replicate n 0) = ListBlank.mk l := - Quot.sound (Or.inr ⟨n, rfl⟩) + ListBlank.mk_append_replicate_default l n theorem boot_reference_47 : nSteps refM 47 init = diff --git a/Cryptids/Machines.lean b/Cryptids/Machines.lean index 345a59a2..12d0a898 100644 --- a/Cryptids/Machines.lean +++ b/Cryptids/Machines.lean @@ -57,6 +57,28 @@ open Turing (Dir) open StateTransition export Turing (Dir) +scoped instance (priority := 10000) instZeroNatConstructive : Zero ℕ := ⟨0⟩ +scoped instance (priority := 10000) instLTNatConstructive : LT ℕ := instLTNat +scoped instance (priority := 10000) instLENatConstructive : LE ℕ := instLENat +scoped instance (priority := 10000) instDecidableLTNatConstructive : DecidableLT ℕ := + fun a b => Nat.decLt a b +scoped instance (priority := 10000) instDecidableLENatConstructive : DecidableLE ℕ := + fun a b => Nat.decLe a b + +theorem pos_of_neZero (n : ℕ) [h : NeZero n] : 0 < n := + Nat.casesOn (motive := fun k => NeZero k → 0 < k) n + (fun h0 => False.elim (h0.out rfl)) + (fun k _ => Nat.zero_lt_succ k) + h + +scoped instance (priority := 10000) instNeZeroSuccConstructive (n : ℕ) : NeZero (n + 1) := + ⟨fun h => Nat.noConfusion h⟩ +scoped instance (priority := 10000) instOfNatFinConstructive (n : ℕ) [NeZero n] (i : ℕ) : + OfNat (Fin n) i := + ⟨⟨i % n, Nat.mod_lt i (pos_of_neZero n)⟩⟩ +scoped instance (priority := 10000) instInhabitedFinConstructive (n : ℕ) [NeZero n] : + Inhabited (Fin n) := + ⟨0⟩ scoped instance (priority := 10000) instLTFinConstructive (n : ℕ) : LT (Fin n) := instLTFin scoped instance (priority := 10000) instLEFinConstructive (n : ℕ) : LE (Fin n) := instLEFin scoped instance (priority := 10000) instDecidableEqFinConstructive (n : ℕ) : DecidableEq (Fin n) := @@ -84,42 +106,80 @@ scoped instance (priority := 10000) instLinearOrderFinConstructive (n : ℕ) : compare a b := compareOfLessAndEq a b compare_eq_compareOfLessAndEq _ _ := rfl -/-- Half-tape of a Turing machine, quotienting `List Γ` by trailing blank symbols -(`Turing.BlankRel`) via Lean's primitive `Quot` rather than `Quotient (BlankRel.setoid Γ)` so that -`ListBlank`, `Tape`, and `Halts` carry zero `Classical.choice` dependency. -/ -def ListBlank (Γ : Type*) [Inhabited Γ] := - Quot (@Turing.BlankRel Γ _) +/-- Predicate that a `List Γ` has no trailing blank (`default`) symbol. -/ +def ListBlank.IsTrimmed {Γ : Type*} [Inhabited Γ] : List Γ → Prop + | [] => True + | [a] => a ≠ default + | _ :: b :: xs => ListBlank.IsTrimmed (b :: xs) + +/-- Prepend `a` onto a blank-trimmed `List Γ`, dropping `a` iff `a = default` on `[]`. -/ +def ListBlank.trimCons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) : List Γ → List Γ + | [] => if a = default then [] else [a] + | b :: xs => a :: b :: xs + +/-- Half-tape of a Turing machine, represented concretely as a `List Γ` in canonical blank-trimmed +normal form (no trailing `default` symbols) so `ListBlank`, `Tape`, and `Halts` require zero +axioms (`Quot`, `Quot.sound`, `propext`, and `Classical.choice` are all avoided). -/ +structure ListBlank (Γ : Type*) [Inhabited Γ] where + ofTrimmed :: + toList : List Γ + isTrimmed : ListBlank.IsTrimmed toList instance ListBlank.inhabited {Γ : Type*} [Inhabited Γ] : Inhabited (ListBlank Γ) := - ⟨Quot.mk _ []⟩ - -/-- Quotient map turning a `List Γ` into a `ListBlank Γ`. -/ -def ListBlank.mk {Γ : Type*} [Inhabited Γ] : List Γ → ListBlank Γ := - Quot.mk _ + ⟨⟨[], trivial⟩⟩ /-- Lift a blank-extension-invariant function from `List Γ` to `ListBlank Γ`. -/ protected abbrev ListBlank.liftOn {Γ : Type*} [Inhabited Γ] {α : Sort*} (l : ListBlank Γ) - (f : List Γ → α) (H : ∀ a b, Turing.BlankExtends a b → f a = f b) : α := - Quot.liftOn l f fun a b h => h.elim (H a b) fun h' => (H b a h').symm + (f : List Γ → α) (_H : ∀ a b, Turing.BlankExtends a b → f a = f b) : α := + f l.toList /-- Head symbol of a `ListBlank`. -/ def ListBlank.head {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : Γ := - l.liftOn List.headI <| by - rintro (_ | _) _ ⟨_ | _, rfl⟩ <;> rfl + l.toList.headI + +theorem ListBlank.isTrimmed_tail {Γ : Type*} [Inhabited Γ] {l : List Γ} : + ListBlank.IsTrimmed l → ListBlank.IsTrimmed l.tail := + List.casesOn (motive := fun xs => ListBlank.IsTrimmed xs → ListBlank.IsTrimmed xs.tail) l + (fun _ => trivial) + (fun a tl => + List.casesOn (motive := fun ys => ListBlank.IsTrimmed (a :: ys) → ListBlank.IsTrimmed ys) tl + (fun _ => trivial) + (fun _ _ h => h)) /-- Tail of a `ListBlank`. -/ def ListBlank.tail {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := - l.liftOn (fun l => ListBlank.mk l.tail) <| by - rintro (_ | _) _ ⟨i, rfl⟩ - · rcases i with - | i <;> - [exact Quot.sound (Or.inl ⟨0, rfl⟩); exact Quot.sound (Or.inl ⟨i, rfl⟩)] - · exact Quot.sound (Or.inl ⟨i, rfl⟩) + ⟨l.toList.tail, ListBlank.isTrimmed_tail l.isTrimmed⟩ + +theorem ListBlank.isTrimmed_trimCons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) + {l : List Γ} : ListBlank.IsTrimmed l → ListBlank.IsTrimmed (ListBlank.trimCons a l) := + List.casesOn (motive := fun xs => + ListBlank.IsTrimmed xs → ListBlank.IsTrimmed (ListBlank.trimCons a xs)) l + (fun _ => by + change ListBlank.IsTrimmed (if a = default then [] else [a]) + by_cases h : a = default + · rw [ite_eq_left h]; exact trivial + · rw [ite_eq_right h]; exact h) + (fun b tl => + List.casesOn (motive := fun ys => + ListBlank.IsTrimmed (b :: ys) → ListBlank.IsTrimmed (a :: b :: ys)) tl + (fun h => h) + (fun _ _ h => h)) /-- Prepend a symbol onto a `ListBlank`. -/ -def ListBlank.cons {Γ : Type*} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := - l.liftOn (fun l => ListBlank.mk (a :: l)) <| by - rintro _ _ ⟨i, rfl⟩ - exact Quot.sound (Or.inl ⟨i, rfl⟩) +def ListBlank.cons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) (l : ListBlank Γ) : + ListBlank Γ := + ⟨ListBlank.trimCons a l.toList, ListBlank.isTrimmed_trimCons a l.isTrimmed⟩ + +/-- Prepend a finite `List` of symbols onto a `ListBlank`. -/ +@[simp] +def ListBlank.append {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : + List Γ → ListBlank Γ → ListBlank Γ + | [], L => L + | a :: l, L => ListBlank.cons a (ListBlank.append l L) + +/-- Canonical map turning a `List Γ` into a `ListBlank Γ` by trimming trailing blanks. -/ +def ListBlank.mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : ListBlank Γ := + ListBlank.append l default /-- Bidirectional Turing machine tape over alphabet `Γ`. -/ structure Tape (Γ : Type*) [Inhabited Γ] where @@ -131,7 +191,7 @@ instance Tape.inhabited {Γ : Type*} [Inhabited Γ] : Inhabited (Tape Γ) := ⟨⟨default, default, default⟩⟩ /-- Shift the tape in response to a head movement `Dir.left` or `Dir.right`. -/ -def Tape.move {Γ : Type*} [Inhabited Γ] : Dir → Tape Γ → Tape Γ +def Tape.move {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : Dir → Tape Γ → Tape Γ | Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩ | Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩ @@ -144,13 +204,19 @@ def Tape.mk' {Γ : Type*} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ := ⟨R.head, L, R.tail⟩ /-- Construct a tape from left and inclusive-right `List`s. -/ -def Tape.mk₂ {Γ : Type*} [Inhabited Γ] (L R : List Γ) : Tape Γ := +def Tape.mk₂ {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (L R : List Γ) : Tape Γ := Tape.mk' (ListBlank.mk L) (ListBlank.mk R) /-- Construct a tape with `l` starting at the head and blanks to the left. -/ -def Tape.mk₁ {Γ : Type*} [Inhabited Γ] (l : List Γ) : Tape Γ := +def Tape.mk₁ {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : Tape Γ := Tape.mk₂ [] l +@[simp] +def listGetD {α : Type*} : List α → ℕ → α → α + | [], _, d => d + | a :: _, 0, _ => a + | _ :: xs, n + 1, d => listGetD xs n d + /-- A transition table: for a state and the symbol under the head, either the symbol to write, the direction to move and the state to enter, or `none` to halt. -/ @@ -177,7 +243,7 @@ def Halts (M : Machine states symbols) : Prop := (StateTransition.eval (step M) /-- Build a `Machine states symbols` from a list of per-state transition rows. -/ def Machine.ofRows (rows : List (List (Option (Fin symbols × Dir × Fin states)))) : - Machine states symbols := ⟨fun q a => (rows.getD q.val []).getD a.val none⟩ + Machine states symbols := ⟨fun q a => listGetD (listGetD rows q.val []) a.val none⟩ /-- A Turing machine over `symbols` tape symbols bundled with its non-zero state count. -/ structure BundledMachine (symbols : ℕ) where @@ -189,7 +255,10 @@ attribute [instance] BundledMachine.neZeroStates /-- Bundle a `Machine (states + 1) symbols` into a `BundledMachine symbols`. -/ abbrev Machine.bundle {states symbols : ℕ} (M : Machine (states + 1) symbols) : - BundledMachine symbols := ⟨states + 1, M⟩ + BundledMachine symbols := + { states := states + 1 + neZeroStates := ⟨fun h => Nat.noConfusion h⟩ + toMachine := M } /-- `M` halts when started in state `0` on the all-blank tape. -/ abbrev BundledMachine.Halts {symbols : ℕ} [NeZero symbols] (M : BundledMachine symbols) : Prop := @@ -197,6 +266,10 @@ abbrev BundledMachine.Halts {symbols : ℕ} [NeZero symbols] (M : BundledMachine export BundledMachine (Halts) +/-- info: 'ConjectureMachines.BundledMachine.Halts' does not depend on any axioms -/ +#guard_msgs in +#print axioms ConjectureMachines.BundledMachine.Halts + namespace Machines /-- Rows of `goldbach25`. -/ def goldbach25Rows : List (List (Option (Fin 2 × Dir × Fin 25))) := load_machine_rows% "baselines/tables/goldbach_25.txt" @@ -344,46 +417,108 @@ def Runs (M : Machine states symbols) (n : ℕ) : Prop := (run M n).isSome instance (M : Machine states symbols) (n : ℕ) : Decidable (Runs M n) := inferInstanceAs (Decidable ((run M n).isSome = true)) -@[elab_as_elim] -protected theorem ListBlank.induction_on {Γ : Type*} [Inhabited Γ] {p : ListBlank Γ → Prop} - (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := - Quot.ind h q +@[ext] +theorem ListBlank.ext {Γ : Type*} [Inhabited Γ] {l₁ l₂ : ListBlank Γ} + (h : l₁.toList = l₂.toList) : l₁ = l₂ := by + cases l₁; cases l₂; cases h; rfl @[simp] -theorem ListBlank.head_mk {Γ : Type*} [Inhabited Γ] (l : List Γ) : - ListBlank.head (ListBlank.mk l) = l.headI := - rfl +theorem ListBlank.cons_default_default {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : + (default : ListBlank Γ).cons default = default := by + apply ListBlank.ext + exact ite_eq_left rfl @[simp] -theorem ListBlank.tail_mk {Γ : Type*} [Inhabited Γ] (l : List Γ) : - ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := - rfl +theorem ListBlank.head_cons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) + (l : ListBlank Γ) : (l.cons a).head = a := by + rcases l with ⟨_ | ⟨b, xs⟩, _⟩ + · change (if a = default then [] else [a]).headI = a + by_cases h : a = default + · rw [ite_eq_left h]; exact h.symm + · rw [ite_eq_right h]; rfl + · rfl @[simp] -theorem ListBlank.cons_mk {Γ : Type*} [Inhabited Γ] (a : Γ) (l : List Γ) : +theorem ListBlank.tail_cons {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) + (l : ListBlank Γ) : (l.cons a).tail = l := by + apply ListBlank.ext + rcases l with ⟨_ | ⟨b, xs⟩, _⟩ + · change (if a = default then [] else [a]).tail = [] + by_cases h : a = default + · rw [ite_eq_left h]; rfl + · rw [ite_eq_right h]; rfl + · rfl + +@[simp] +theorem ListBlank.cons_head_tail {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + (l : ListBlank Γ) : l.tail.cons l.head = l := by + apply ListBlank.ext + rcases l with ⟨_ | ⟨a, _ | ⟨b, xs⟩⟩, h⟩ + · exact ite_eq_left rfl + · exact ite_eq_right h + · rfl + +@[simp] +theorem ListBlank.cons_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (a : Γ) (l : List Γ) : ListBlank.cons a (ListBlank.mk l) = ListBlank.mk (a :: l) := rfl @[simp] -theorem ListBlank.head_cons {Γ : Type*} [Inhabited Γ] (a : Γ) : - ∀ l : ListBlank Γ, (l.cons a).head = a := - Quot.ind fun _ => rfl +theorem ListBlank.head_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : + ListBlank.head (ListBlank.mk l) = l.headI := by + cases l with + | nil => rfl + | cons a xs => exact ListBlank.head_cons a (ListBlank.mk xs) @[simp] -theorem ListBlank.tail_cons {Γ : Type*} [Inhabited Γ] (a : Γ) : - ∀ l : ListBlank Γ, (l.cons a).tail = l := - Quot.ind fun _ => rfl +theorem ListBlank.tail_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : List Γ) : + ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := by + cases l with + | nil => rfl + | cons a xs => exact ListBlank.tail_cons a (ListBlank.mk xs) + +private theorem ListBlank.mk_list_aux {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] : + ∀ (xs : List Γ) (h : ListBlank.IsTrimmed xs), ListBlank.mk xs = ⟨xs, h⟩ + | [], _ => rfl + | [a], h => by + apply ListBlank.ext + exact ite_eq_right h + | a :: b :: xs, h => by + change ListBlank.cons a (ListBlank.mk (b :: xs)) = ⟨a :: b :: xs, h⟩ + rw [ListBlank.mk_list_aux (b :: xs) h] + rfl @[simp] -theorem ListBlank.cons_head_tail {Γ : Type*} [Inhabited Γ] : - ∀ l : ListBlank Γ, l.tail.cons l.head = l := - Quot.ind fun l => by - change ListBlank.cons (ListBlank.mk l).head (ListBlank.mk l).tail = ListBlank.mk l - rw [ListBlank.head_mk, ListBlank.tail_mk, ListBlank.cons_mk] - refine Quot.sound (Or.inr ?_) - cases l - · exact ⟨1, rfl⟩ - · exact ⟨0, by simp⟩ +theorem ListBlank.mk_toList {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l : ListBlank Γ) : + ListBlank.mk l.toList = l := + ListBlank.mk_list_aux l.toList l.isTrimmed + +@[elab_as_elim] +protected theorem ListBlank.induction_on {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + {p : ListBlank Γ → Prop} (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := + q.mk_toList ▸ h q.toList + +theorem ListBlank.blankExtends_toList_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + (l : List Γ) : Turing.BlankExtends (ListBlank.mk l).toList l := by + induction l with + | nil => exact ⟨0, rfl⟩ + | cons a xs ih => + obtain ⟨i, hi⟩ := ih + change Turing.BlankExtends (ListBlank.trimCons a (ListBlank.mk xs).toList) (a :: xs) + rcases hmk : (ListBlank.mk xs).toList with _ | ⟨b, ys⟩ + · rw [hmk, List.nil_append] at hi + dsimp only [ListBlank.trimCons] + by_cases ha : a = default + · refine ⟨i + 1, ?_⟩ + rw [ite_eq_left ha, ha, hi, List.nil_append, List.replicate_succ] + · exact ⟨i, by rw [ite_eq_right ha, hi]; rfl⟩ + · rw [hmk] at hi + exact ⟨i, by rw [hi]; rfl⟩ + +theorem ListBlank.liftOn_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] {α : Sort*} + (l : List Γ) (f : List Γ → α) (H : ∀ a b, Turing.BlankExtends a b → f a = f b) : + (ListBlank.mk l).liftOn f H = f l := + H _ _ (ListBlank.blankExtends_toList_mk l) /-- The `n`-th symbol of a `ListBlank`. -/ def ListBlank.nth {Γ : Type*} [Inhabited Γ] : ListBlank Γ → ℕ → Γ @@ -399,22 +534,29 @@ theorem ListBlank.nth_succ {Γ : Type*} [Inhabited Γ] (l : ListBlank Γ) (n : l.nth (n + 1) = l.tail.nth n := rfl -/-- Prepend a finite `List` of symbols onto a `ListBlank`. -/ @[simp] -def ListBlank.append {Γ : Type*} [Inhabited Γ] : List Γ → ListBlank Γ → ListBlank Γ - | [], L => L - | a :: l, L => ListBlank.cons a (ListBlank.append l L) - -@[simp] -theorem ListBlank.append_mk {Γ : Type*} [Inhabited Γ] (l₁ l₂ : List Γ) : +theorem ListBlank.append_mk {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (l₁ l₂ : List Γ) : ListBlank.append l₁ (ListBlank.mk l₂) = ListBlank.mk (l₁ ++ l₂) := by induction l₁ <;> simp only [*, ListBlank.append, List.nil_append, List.cons_append, ListBlank.cons_mk] -theorem ListBlank.append_assoc {Γ : Type*} [Inhabited Γ] (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) : +theorem ListBlank.append_assoc {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) : ListBlank.append (l₁ ++ l₂) l₃ = ListBlank.append l₁ (ListBlank.append l₂ l₃) := by - refine l₃.induction_on fun l => ?_ - simp only [ListBlank.append_mk, List.append_assoc] + induction l₁ with + | nil => rfl + | cons a xs ih => exact congrArg (ListBlank.cons a) ih + +theorem ListBlank.mk_append_replicate_default {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] + (l : List Γ) (n : ℕ) : + ListBlank.mk (l ++ List.replicate n default) = ListBlank.mk l := by + have hrep : ListBlank.mk (List.replicate n (default : Γ)) = default := by + induction n with + | zero => rfl + | succ n ih => + rw [List.replicate_succ, ← ListBlank.cons_mk, ih, ListBlank.cons_default_default] + rw [← ListBlank.append_mk, hrep] + rfl @[simp] theorem Tape.write_self {Γ : Type*} [Inhabited Γ] : ∀ T : Tape Γ, T.write T.1 = T @@ -440,18 +582,18 @@ theorem Tape.mk'_right {Γ : Type*} [Inhabited Γ] (L R : ListBlank Γ) : rfl @[simp] -theorem Tape.move_left_mk' {Γ : Type*} [Inhabited Γ] (L R : ListBlank Γ) : +theorem Tape.move_left_mk' {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.left = Tape.mk' L.tail (R.cons L.head) := by simp only [Tape.move, Tape.mk', ListBlank.head_cons, ListBlank.cons_head_tail, ListBlank.tail_cons] @[simp] -theorem Tape.move_right_mk' {Γ : Type*} [Inhabited Γ] (L R : ListBlank Γ) : +theorem Tape.move_right_mk' {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.right = Tape.mk' (L.cons R.head) R.tail := rfl @[simp] -theorem Tape.write_mk' {Γ : Type*} [Inhabited Γ] (b : Γ) (L R : ListBlank Γ) : +theorem Tape.write_mk' {Γ : Type*} [Inhabited Γ] [DecidableEq Γ] (b : Γ) (L R : ListBlank Γ) : (Tape.mk' L R).write b = Tape.mk' L (R.tail.cons b) := by simp only [Tape.write, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons] @@ -529,7 +671,7 @@ private theorem rtg_cases_head {α : Type*} {r : α → α → Prop} {a b : α} · exact Or.inr ⟨y, hxy, Relation.ReflTransGen.refl⟩ · exact Or.inr ⟨c, hac, Relation.ReflTransGen.tail hcx hxy⟩ -private theorem reaches_total_det {σ : Type*} {f : σ → Option σ} {a b c : σ} +theorem reaches_total_det {σ : Type*} {f : σ → Option σ} {a b c : σ} (hab : Reaches f a b) (hac : Reaches f a c) : Reaches f b c ∨ Reaches f c b := by induction hab using Relation.ReflTransGen.head_induction_on generalizing c with | refl => exact Or.inl hac @@ -539,12 +681,18 @@ private theorem reaches_total_det {σ : Type*} {f : σ → Option σ} {a b c : · cases Option.mem_unique hx₁ hc₁ exact ih hc₁c -private theorem reaches_of_none {σ : Type*} {f : σ → Option σ} {b c : σ} +theorem reaches_of_none {σ : Type*} {f : σ → Option σ} {b c : σ} (hb : f b = none) (hbc : Reaches f b c) : b = c := by rcases rtg_cases_head hbc with rfl | ⟨d, hbd, _⟩ · rfl · cases hb.symm.trans hbd +theorem list_length_five {α : Type*} : ∀ (l : List α), l.length = 5 → + ∃ a b c d e, l = [a, b, c, d, e] + | [a, b, c, d, e], _ => ⟨a, b, c, d, e, rfl⟩ + | [], h | [_], h | [_, _], h | [_, _, _], h | [_, _, _, _], h + | _ :: _ :: _ :: _ :: _ :: _ :: _, h => nomatch h + theorem reaches_eval' {σ : Type*} {f : σ → Option σ} {a b : σ} (ab : Reaches f a b) : eval f a = eval f b := by refine Part.ext fun c => ⟨fun h => ?_, fun h => ?_⟩ diff --git a/Cryptids/README.md b/Cryptids/README.md index 3702997a..f03c2fa3 100644 --- a/Cryptids/README.md +++ b/Cryptids/README.md @@ -24,10 +24,10 @@ See [`RELATED_WORK.md`](../RELATED_WORK.md) for the historical progression acros All proofs in [`Cryptids/`](./) are checked by the Lean 4 kernel (`v4.35.0-rc4`) without `sorry`: -1. **State reductions:** Each reduced machine (`goldbach_21`, `zf_380`, `riemann_104`, `riemann_95`, `erdos_ternary_14`) has fewer states than its reference machine (`goldbach_25`, `zf_393`, `riemann_120`, `riemann_104`, `erdos_ternary_15`) and halts from the blank tape if and only if the reference machine halts ([`Goldbach21.lean`](./Goldbach21.lean), [`Zf380.lean`](./Zf380.lean), [`Riemann104.lean`](./Riemann104.lean), [`Riemann95.lean`](./Riemann95.lean), [`ErdosTernary14.lean`](./ErdosTernary14.lean)). The direct simulation reductions (`goldbach_21`, `zf_380`, `riemann_104`), the `erdos_ternary_14` reduction, and all five `candidate_fewer_states` theorems are completely constructive (`["propext", "Quot.sound"]`, zero `Classical.choice`), audited via [`comparator/constructive.json`](../comparator/constructive.json), [`comparator/goldbach_21.json`](../comparator/goldbach_21.json), [`comparator/zf_380.json`](../comparator/zf_380.json), and [`comparator/riemann_104.json`](../comparator/riemann_104.json), while [`riemann_95`](./Riemann95.lean) routes through the arithmetic stage predicate `ShuniaCounterexample` (`Nat.Prime`, audited via [`comparator/riemann_95.json`](../comparator/riemann_95.json)). +1. **State reductions:** Each reduced machine (`goldbach_21`, `zf_380`, `riemann_104`, `riemann_95`, `erdos_ternary_14`) has fewer states than its reference machine (`goldbach_25`, `zf_393`, `riemann_120`, `riemann_104`, `erdos_ternary_15`) and halts from the blank tape if and only if the reference machine halts ([`Goldbach21.lean`](./Goldbach21.lean), [`Zf380.lean`](./Zf380.lean), [`Riemann104.lean`](./Riemann104.lean), [`Riemann95.lean`](./Riemann95.lean), [`ErdosTernary14.lean`](./ErdosTernary14.lean)). All five `candidate_fewer_states` theorems depend on **zero axioms (`[]`)** ([`comparator/zero_axioms.json`](../comparator/zero_axioms.json)), and **all five** `candidate_equivalent` reductions (`goldbach_21`, `zf_380`, `riemann_104`, `riemann_95`, `erdos_ternary_14`) are completely constructive (`["propext", "Quot.sound"]`, zero `Classical.choice`), audited via [`comparator/constructive.json`](../comparator/constructive.json), [`comparator/goldbach_21.json`](../comparator/goldbach_21.json), [`comparator/zf_380.json`](../comparator/zf_380.json), [`comparator/riemann_104.json`](../comparator/riemann_104.json), and [`comparator/riemann_95_reduction.json`](../comparator/riemann_95_reduction.json). 2. **End-to-end mathematical semantics ([`Cryptids/Semantics/`](./Semantics/README.md)):** - **ZF Consistency (`zf_380`, `zf_393`, and `zf_432`):** Both `zf_380` and Wade's 393-state machine `zf_393` (incorporating upstream fix `10fcf152b3`) halt if and only if O'Rear's `zf2.nql` Hilbert system proves $v_0 \in v_0$ (`Halts candidate ↔ ZFInconsistent`, `Halts zf393 ↔ ZFInconsistent`), while `zf_432` halts if and only if the 20-clause deductive system enumerated by `zf_432_wade.tm` derives $v_0 \in v_0$ (`WadeZFInconsistent`). **All three proof-search equivalences are proved constructively in Lean using only `["propext", "Quot.sound"]` (no `Classical.choice`, no Excluded Middle, and no Markov's Principle)** and audited via [`comparator/constructive.json`](../comparator/constructive.json), blocking classical `Con(ZF)` shortcuts via [`Zf/Soundness.lean`](./Semantics/Zf/Soundness.lean) or `Classical.em` (object-level `PA` internalization for `zf_393` and `zf_380` is proved separately below via `PAProvable`, while `zf_432` internalization and establishing full two-way `ZF`-independence remain separate; see [`Semantics/README.md`](./Semantics/README.md#foundational-note-conzf-in-lean-and-constructive-equivalence)). Separately, [`Zf/Soundness.lean`](./Semantics/Zf/Soundness.lean) uses classical `ZFSet.{0}` (`Classical.choice`) to establish `not_zfInconsistent` and deduce unconditional non-halting (`not_halts_zf393`, `not_halts_candidate`) inside Lean's stronger meta-theory. - - **First-Order Peano Arithmetic (`PAProvable`, [`Semantics/PA.lean`](./Semantics/PA.lean)):** Deeply embeds first-order Peano Arithmetic (`PATerm`, `PAFormula`, `PAProvable`) and $\Sigma_1^0$ encodings `paHalts M` and `paZFInconsistent` in [`Propositions.lean`](./Propositions.lean) and [`Challenge.lean`](../Challenge.lean), proving constructive consistency (`not_paProvable_false`) and constructive standard-model adequacy (`paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`; all three audited without `Classical.choice` in [`comparator/constructive.json`](../comparator/constructive.json)), along with classical standard-model soundness (`paProvable_sound_nat`) and full object-level `PA` proofs that `zf_380` and `zf_393` halt iff `ZF` is inconsistent (`paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, `paProvable_halts_zf380_iff_zfInconsistent`, audited in [`comparator/pa_semantics.json`](../comparator/pa_semantics.json) and [`comparator/all.json`](../comparator/all.json); these three `PAProvable` theorems use `Classical.choice` because they reason in arbitrary `PAModel`s and reflect back to `PAProvable` via internal Gödel–Henkin completeness `paProvable_iff_holdsIn_all_models`). + - **First-Order Peano Arithmetic (`PAProvable`, [`Semantics/PA.lean`](./Semantics/PA.lean)):** Deeply embeds first-order Peano Arithmetic (`PATerm`, `PAFormula`, `PAProvable`) and $\Sigma_1^0$ encodings `paHalts M` and `paZFInconsistent` in [`Propositions.lean`](./Propositions.lean) and [`Challenge.lean`](../Challenge.lean), proving zero-axiom syntactic consistency (`not_paProvable_false`, audited with `permitted_axioms = []` in [`comparator/zero_axioms.json`](../comparator/zero_axioms.json)) and constructive standard-model adequacy (`paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`; all three audited without `Classical.choice` in [`comparator/constructive.json`](../comparator/constructive.json)), along with standard-model soundness (`paProvable_sound_nat`) and full object-level `PA` proofs that `zf_380` and `zf_393` halt iff `ZF` is inconsistent (`paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, `paProvable_halts_zf380_iff_zfInconsistent`, audited in [`comparator/pa_semantics.json`](../comparator/pa_semantics.json) and [`comparator/all.json`](../comparator/all.json); these three `PAProvable` theorems use `Classical.choice` because they reason in arbitrary `PAModel`s and reflect back to `PAProvable` via internal Gödel–Henkin completeness `paProvable_iff_holdsIn_all_models`). - **Goldbach (`goldbach_21` and `goldbach_25`):** Both `goldbach_21` and `goldbach_25` constructively satisfy `Halts M ↔ ∃ w, ¬ HasGoldbachPair (2 * w + 4)` without `Classical.choice` ([`Goldbach21.lean`](./Goldbach21.lean)), and with `Classical.choice` (for Markov's Principle on `¬ ∀ n, ...`) satisfy `Halts candidate ↔ ¬ GoldbachConjecture` ([`Semantics/Goldbach.lean`](./Semantics/Goldbach.lean)). - **Erdős's ternary conjecture (`erdos_ternary_15` and `erdos_ternary_14`):** Stérin and Woods's 15-state machine constructively satisfies `Halts erdosTernary15 ↔ ∃ n, 8 < n ∧ 2 ∉ pw n`, where `pw n` is the base-3 digit list of `2 ^ n` computed by repeated doubling ([`ErdosTernary15.lean`](./ErdosTernary15.lean)), and with `Classical.choice` (Mathlib's `Nat.digits`, and Markov's Principle on `¬ ∀ n, ...`) satisfies `Halts erdosTernary15 ↔ ¬ ErdosTernaryConjecture` ([`Semantics/ErdosTernary15.lean`](./Semantics/ErdosTernary15.lean)). Stérin's 14-state machine `erdos_ternary_14` constructively satisfies `Halts erdosTernary14 ↔ ∃ n, 8 < n ∧ 2 ∉ pw n` and hence `Halts candidate ↔ Halts reference` against `erdos_ternary_15` ([`ErdosTernary14.lean`](./ErdosTernary14.lean)), and `Halts candidate ↔ ¬ ErdosTernaryConjecture` ([`Semantics/ErdosTernary14.lean`](./Semantics/ErdosTernary14.lean)). - **Brocard's problem (`brocard_28`):** The machine keeps `n! / 8` in unary and tests it for triangularity by subtracting `1, 2, 3, …`; it constructively satisfies `Halts brocard28 ↔ ∃ n, 8 ≤ n ∧ IsTri (n! / 8)` and `Halts brocard28 ↔ ∃ n, 7 < n ∧ IsSquare (n! + 1)` without `Classical.choice` ([`Brocard28.lean`](./Brocard28.lean), [`Semantics/Brocard28.lean`](./Semantics/Brocard28.lean)), and with Markov's Principle `Halts brocard28 ↔ ¬ BrocardConjecture`. @@ -64,6 +64,7 @@ Independently audit the proofs against [`Challenge.lean`](../Challenge.lean) wit [`leanprover/comparator`](../comparator/README.md): ```bash +lake comparator --config comparator/zero_axioms.json lake comparator --config comparator/constructive.json lake comparator --config comparator/all.json ``` diff --git a/Cryptids/ReductionSupport/Riemann95/Auxiliary95Physical.lean b/Cryptids/ReductionSupport/Riemann95/Auxiliary95Physical.lean index ab506cc2..7db803d4 100644 --- a/Cryptids/ReductionSupport/Riemann95/Auxiliary95Physical.lean +++ b/Cryptids/ReductionSupport/Riemann95/Auxiliary95Physical.lean @@ -36,16 +36,16 @@ def rawRoot98 (pad : Nat) (w : List (Fin 2)) (bank : List Nat) : Cfg 98 2 := 0] ++ encodeRegs bank) default)⟩ theorem swap_incLeaf (r : Fin 5) : - Renaming.swap (PhysicalRaw.incLeaf98 r) = incLeaf98 r := by fin_cases r <;> rfl + Renaming.swap (PhysicalRaw.incLeaf98 r) = incLeaf98 r := by revert r; decide theorem swap_decLeaf (r : Fin 5) : - Renaming.swap (PhysicalRaw.decLeaf98 r) = decLeaf98 r := by fin_cases r <;> rfl + Renaming.swap (PhysicalRaw.decLeaf98 r) = decLeaf98 r := by revert r; decide theorem rename_rawRoot (pad : Nat) (word : List (Fin 2)) (bank : List Nat) : Renaming.renameCfg (PhysicalRaw.rawRoot98 pad word bank) = rawRoot98 pad word bank := rfl theorem swap_fence (k : Fin 2) : - Renaming.swap (if k = 0 then 9 else 63) = (if k = 0 then 9 else 63) := by fin_cases k <;> rfl + Renaming.swap (if k = 0 then 9 else 63) = (if k = 0 then 9 else 63) := by revert k; decide theorem unary98_dec_pos (r : Fin 5) (bank : List Nat) (hr : r.val < bank.length) (hpos : 0 < bank.getD r.val 0) (L : ListBlank (Fin 2)) : ∃ s ≥ 1, nSteps s ⟨decLeaf98 r, Tape.mk' L diff --git a/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawPhysical.lean b/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawPhysical.lean index f9f467eb..985ab664 100644 --- a/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawPhysical.lean +++ b/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawPhysical.lean @@ -32,6 +32,12 @@ def incLeaf98 : Fin 5 → Fin 98 | ⟨3, _⟩ => 23 | _ => 55 +private theorem list_getD_eq_getElem {α : Type*} : + ∀ (l : List α) (d : α) {i : ℕ} (hi : i < l.length), l.getD i d = l[i] + | [], _, _, hi => absurd hi (Nat.not_lt_zero _) + | _ :: _, _, 0, _ => rfl + | _ :: xs, d, _ + 1, hi => list_getD_eq_getElem xs d (Nat.lt_of_succ_lt_succ hi) + theorem nSteps98_eq (n : Nat) (c : Cfg 98 2) : Raw.nSteps n c = ConjectureMachines.Semantics.Riemann.Layer1.nSteps Raw.machine n c := by induction n generalizing c with @@ -167,7 +173,7 @@ private theorem dec_select_one (m : Nat) (hm1 : 1 ≤ m) (hm4 : m ≤ 4) : private theorem dec_leaf_transition (r : Fin 5) : Raw.machine.transition (decLeaf98 r) 1 = some (0, .right, decSelect (r.val + 1)) := by - fin_cases r <;> rfl + revert r; decide private theorem dec_select_scan : ∀ (pref : List Nat), pref.length ≤ 4 → ∀ (L R : ListBlank (Fin 2)), @@ -279,7 +285,7 @@ theorem unary98_dec_pos (r : Fin 5) (bank : List Nat) (hr : r.val < bank.length) have hsplit : regsTape bank = ListBlank.append (encodeRegs pref) (regsTape ((m + 1) :: suff)) := by have hb : bank = pref ++ (m + 1) :: suff := by - rw [← hv, List.getD_eq_getElem bank 0 hr] + rw [← hv, list_getD_eq_getElem bank 0 hr] exact (list_take_cons_drop bank r.val hr).symm rw [hb, regsTape_append] have h0 : step Raw.machine @@ -506,8 +512,9 @@ theorem unary98_inc (r : Fin 5) (bank : List Nat) (hr : r.val < bank.length) (L have hbank : regsTape bank = ListBlank.append (encodeRegs pref) (regsTape (v :: suff)) := by dsimp only [pref, v, suff] rw [← regsTape_append, list_take_cons_drop bank r.val hr] - have hleaf : Raw.machine.transition (incLeaf98 r) 1 = some (0, .right, chain (r.val + 1)) := by - fin_cases r <;> decide + have hleaf : Raw.machine.transition (incLeaf98 r) 1 = some (0, .right, chain (r.val + 1)) := + (by decide : ∀ s : Fin 5, + Raw.machine.transition (incLeaf98 s) 1 = some (0, .right, chain (s.val + 1))) r have h0 : step Raw.machine ⟨incLeaf98 r, Tape.mk' L (ListBlank.append [1, 0] (regsTape bank))⟩ = some ⟨chain (pref.length + 1), Tape.mk' (L.cons 0) ((ListBlank.append (encodeRegs pref) (regsTape (v :: suff))).cons 0)⟩ := by @@ -532,7 +539,7 @@ theorem unary98_inc (r : Fin 5) (bank : List Nat) (hr : r.val < bank.length) (L have hret := return_regs8 pref ((L.cons 0).cons 0) (regsTape ((v + 1) :: suff)) have hset : ListBlank.append (encodeRegs pref) (regsTape ((v + 1) :: suff)) = regsTape (bank.set r.val (bank.getD r.val 0 + 1)) := by - rw [← regsTape_append, List.getD_eq_getElem bank 0 hr] + rw [← regsTape_append, list_getD_eq_getElem bank 0 hr] congr 1 exact list_take_set_drop bank r.val (v + 1) hr rw [hset] at hret diff --git a/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawReturn.lean b/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawReturn.lean index 1bc10620..8a0bd99d 100644 --- a/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawReturn.lean +++ b/Cryptids/ReductionSupport/Riemann95/Auxiliary95RawReturn.lean @@ -196,7 +196,7 @@ theorem run_return98_after_one (word : List (Fin 2)) (stackLeftOf true word).tail R obtain ⟨s, hpos, hs⟩ := run_return98 word hok R cases s with - | zero => omega + | zero => cases hpos | succ s => rw [nSteps_succ, hfirst, Option.bind_some] at hs have hnonzero : s ≠ 0 := by @@ -204,7 +204,7 @@ theorem run_return98_after_one (word : List (Fin 2)) rw [hz, nSteps_zero] at hs have heq := Option.some.inj hs have hbad : (5 : Fin 98) = 15 := congrArg Cfg.state heq - norm_num at hbad - exact ⟨s, by omega, hs⟩ + exact absurd (congrArg Fin.val hbad) (by decide) + exact ⟨s, Nat.pos_of_ne_zero hnonzero, hs⟩ end ConjectureMachines.Riemann95Auxiliary.ReturnRaw diff --git a/Cryptids/ReductionSupport/Riemann95/BoundedUnwind95.lean b/Cryptids/ReductionSupport/Riemann95/BoundedUnwind95.lean index 8ab81f82..690f8a29 100644 --- a/Cryptids/ReductionSupport/Riemann95/BoundedUnwind95.lean +++ b/Cryptids/ReductionSupport/Riemann95/BoundedUnwind95.lean @@ -60,9 +60,18 @@ theorem bounded_unwind_eval (B d x f : Nat) (hB : 5 * d + 18 ≤ B) : ⟨unwind d,[0,0,f,x,0]⟩ := Relation.TransGen.single (bounded_unwind_edge B (d+1) (f+1) x hB _ (unwind_succ_positive_step d f x)) have hc : (f+1 ≤ d+1 ∧ (d+1-(f+1))%2 = 0) ↔ - (f ≤ d ∧ (d-f)%2 = 0) := by omega + (f ≤ d ∧ (d-f)%2 = 0) := by + constructor <;> intro ⟨h1, h2⟩ <;> exact ⟨by omega, by omega⟩ have hsub : f+1-(d+1+1) = f-(d+1) := by omega - simpa only [hc,hsub] using hs.trans (ih d (by omega) f (by omega)) + have hite : (if f+1 ≤ d+1 ∧ (d+1-(f+1))%2 = 0 then ControlWord.outside 0 + else .outside finalTestId) = + (if f ≤ d ∧ (d-f)%2 = 0 then ControlWord.outside 0 + else .outside finalTestId) := by + by_cases hcond : f ≤ d ∧ (d - f) % 2 = 0 + · rw [ite_eq_left (hc.mpr hcond), ite_eq_left hcond] + · rw [ite_eq_right (fun h => hcond (hc.mp h)), ite_eq_right hcond] + rw [hite, hsub] + exact hs.trans (ih d (by omega) f (by omega)) theorem outside_frontier_bound (s : Fin 97) : (walked (.outside s)).length + 3 ≤ 19 := diff --git a/Cryptids/ReductionSupport/Riemann95/ControlStep95.lean b/Cryptids/ReductionSupport/Riemann95/ControlStep95.lean index 157ad6c8..d8047c40 100644 --- a/Cryptids/ReductionSupport/Riemann95/ControlStep95.lean +++ b/Cryptids/ReductionSupport/Riemann95/ControlStep95.lean @@ -342,12 +342,13 @@ theorem entry_instruction_words (d : Nat) : theorem local_instruction_words (d : Nat) (s : Fin 22) : rawInstr (.local d s) = toRhInstr (instruction (.local d s)) := by cases d with - | zero => fin_cases s <;> rfl + | zero => revert s; decide | succ d => cases d with - | zero => fin_cases s <;> rfl + | zero => revert s; decide | succ d => - fin_cases s <;> + rcases s with ⟨sv, hsv⟩ + interval_cases sv <;> simp [rawInstr,effect,walked,instruction,localInstr,toRhInstr,returned, word,localWalk,localWalkSuffix,localWalkSuffixes,suffix,suffixes,localEffects, callerPrefix,popBreakRev,popContinueRev, diff --git a/Cryptids/ReductionSupport/Riemann95/Initializer95.lean b/Cryptids/ReductionSupport/Riemann95/Initializer95.lean index 862097a2..3c8ea945 100644 --- a/Cryptids/ReductionSupport/Riemann95/Initializer95.lean +++ b/Cryptids/ReductionSupport/Riemann95/Initializer95.lean @@ -103,7 +103,7 @@ theorem post_reference_trace (M : Nat) : ⟨ReferenceProgram.word 88,[0,0,Riemann120.shuniaDeficit (M+2),0,M+1]⟩ := by intro he exact reference_word3_ne88 (congrArg RhRegCfg.stack he) - rcases StateTransition.reaches_total hi hf with hpost | hback + rcases ConjectureMachines.reaches_total_det hi hf with hpost | hback · rcases Relation.reflTransGen_iff_eq_or_transGen.mp hpost with he | ht · exact False.elim (hne he.symm) · exact ht @@ -111,9 +111,7 @@ theorem post_reference_trace (M : Nat) : ⟨ReferenceProgram.word 88,[0,0,Riemann120.shuniaDeficit (M+2),0,M+1]⟩ = none := by unfold ReferencePreStep95 exact ite_eq_left rfl - have he := (Relation.reflTransGen_iff_eq - (Option.eq_none_iff_forall_not_mem.mp hsink)).mp hback - exact False.elim (hne he) + exact False.elim (hne (ConjectureMachines.reaches_of_none hsink hback).symm) theorem initializer (M f : Nat) : Relation.TransGen (Control.BoundedEdge 19) diff --git a/Cryptids/ReductionSupport/Riemann95/PaddingRaw95.lean b/Cryptids/ReductionSupport/Riemann95/PaddingRaw95.lean index 87ff157a..348285cf 100644 --- a/Cryptids/ReductionSupport/Riemann95/PaddingRaw95.lean +++ b/Cryptids/ReductionSupport/Riemann95/PaddingRaw95.lean @@ -35,7 +35,7 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil ((ListBlank.append (List.replicate (rev.length - (popBreakRev j rev).length) 0) R).cons 1)⟩ := by induction rev generalizing j R with - | nil => simp only [List.count_nil] at hc; omega + | nil => simp only [List.count_nil] at hc; exact (Nat.not_lt_zero _ hc).elim | cons b xs ih => rcases Semantics.Riemann.Layer1.fin2_cases b with rfl | rfl · cases j with @@ -79,26 +79,26 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil some ⟨(if k.val = 0 then 11 else 2), mkL (stackLeftOf true walked) (ListBlank.append (List.replicate fill 0) R)⟩ := by rcases Semantics.Riemann.Layer1.fin2_cases k with rfl | rfl - · obtain ⟨f, hf⟩ : ∃ f, fill = f + 1 := ⟨fill - 1, by omega⟩ - subst fill - have h1 := step_mk'_left (q := 9) (q' := 11) (a := 0) (b := 1) (by rfl) - (ListBlank.append (List.replicate (f + 1) 1) (stackLeftOf true walked)) - ((Semantics.Riemann.Layer1.regsTape bank).cons 0) - have h2 := step_mkL_left (q := 11) (q' := 11) (a := 1) (b := 0) (by rfl) - (ListBlank.append (List.replicate f 1) (stackLeftOf true walked)) R - have hscan := scanL (q := 11) (a := 1) (b := 0) (by rfl) f - (stackLeftOf true walked) (R.cons 0) - have ht := Semantics.Riemann.Layer1.step_nSteps h1 - (Semantics.Riemann.Layer1.step_nSteps h2 hscan) - rw [Semantics.Riemann.Layer1.append_replicate_cons] at ht - refine ⟨f + 1 + 1, by omega, ?_⟩ - simpa only [Fin.val_zero, ↓reduceIte, List.replicate_succ, ListBlank.append, R] using ht + · rcases fill with _ | f + · cases hfill + · have h1 := step_mk'_left (q := 9) (q' := 11) (a := 0) (b := 1) (by rfl) + (ListBlank.append (List.replicate (f + 1) 1) (stackLeftOf true walked)) + ((Semantics.Riemann.Layer1.regsTape bank).cons 0) + have h2 := step_mkL_left (q := 11) (q' := 11) (a := 1) (b := 0) (by rfl) + (ListBlank.append (List.replicate f 1) (stackLeftOf true walked)) R + have hscan := scanL (q := 11) (a := 1) (b := 0) (by rfl) f + (stackLeftOf true walked) (R.cons 0) + have ht := Semantics.Riemann.Layer1.step_nSteps h1 + (Semantics.Riemann.Layer1.step_nSteps h2 hscan) + rw [Semantics.Riemann.Layer1.append_replicate_cons] at ht + refine ⟨f + 1 + 1, Nat.le_add_left 1 (f + 1), ?_⟩ + simpa only [Fin.val_zero, ↓reduceIte, List.replicate_succ, ListBlank.append, R] using ht · have h1 := step_mk'_left (q := 63) (q' := 2) (a := 0) (b := 1) (by rfl) (ListBlank.append (List.replicate fill 1) (stackLeftOf true walked)) ((Semantics.Riemann.Layer1.regsTape bank).cons 0) have hscan := scanL (q := 2) (a := 1) (b := 0) (by rfl) fill (stackLeftOf true walked) R - refine ⟨fill + 1, by omega, ?_⟩ + refine ⟨fill + 1, Nat.le_add_left 1 fill, ?_⟩ simpa only [Fin.val_one, Nat.one_ne_zero, ↓reduceIte, show (1 : Fin 2) ≠ 0 by decide, ListBlank.append, R] using Semantics.Riemann.Layer1.step_nSteps h1 hscan let w := (popBreakRev k.val walked.reverse).reverse @@ -110,9 +110,10 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil (ListBlank.append (List.replicate fill 0) R)⟩ = some ⟨5, mkL (stackLeftOf true w).tail ((ListBlank.append (List.replicate (pad' - w.length) 0) R).cons 1)⟩ := by + clear hinit by_cases hc : k.val < walked.count 0 · have hc' : k.val < walked.reverse.count 0 := by simpa only [List.count_reverse] using hc - obtain ⟨t, ht, hscan⟩ := popscan walked.reverse k.val (by omega) hc' + obtain ⟨t, ht, hscan⟩ := popscan walked.reverse k.val (by clear popscan; omega) hc' (rootLeftOf true) (ListBlank.append (List.replicate fill 0) R) rw [append_replicate_zeros_eq] at hscan have he : walked.reverse.length - (popBreakRev k.val walked.reverse).length + fill = @@ -120,11 +121,13 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil have hl : (popBreakRev k.val walked.reverse).length = w.length := by simp only [w, List.length_reverse] rw [List.length_reverse, hl] + clear popscan hscan omega refine ⟨walked.length + fill, by simp only [exactPad, hc, ite_true, Nat.add_zero], t, ht, ?_⟩ simpa only [he, stackLeftOf, w, List.reverse_reverse] using hscan - · have heq : walked.reverse.count 0 = k.val := by rw [List.count_reverse]; omega + · have heq : walked.reverse.count 0 = k.val := by + rw [List.count_reverse]; clear popscan; omega have hnil : w = [] := by simp only [w, (popBreakRev_of_count_eq k.val walked.reverse heq).1, List.reverse_nil] have heq' : (walked.reverse ++ [1]).count 0 = k.val := by @@ -134,18 +137,18 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil have hp := (popBreakRev_of_count_eq k.val (walked.reverse ++ [1]) heq').2 have hc' : k.val < ((walked.reverse ++ [1]) ++ [0]).count 0 := by simp only [List.count_append, heq', List.count_cons_self, List.count_nil] - omega + clear popscan; omega have hstack : stackLeftOf true walked = ListBlank.append ((walked.reverse ++ [1]) ++ [0]) default := by simp only [stackLeftOf, rootLeftOf, ↓reduceIte, ListBlank.append_assoc, ListBlank.append, Semantics.Riemann.Layer1.default_cons_zero] obtain ⟨t, ht, hscan⟩ := popscan ((walked.reverse ++ [1]) ++ [0]) k.val - (by omega) hc' default (ListBlank.append (List.replicate fill 0) R) + (by clear popscan; omega) hc' default (ListBlank.append (List.replicate fill 0) R) rw [← hstack, hp, append_replicate_zeros_eq] at hscan have he : ((walked.reverse ++ [1]) ++ [0]).length - ([1] : List (Fin 2)).length + fill = walked.length + fill + 1 := by simp only [List.length_append, List.length_reverse, List.length_cons, List.length_nil] - omega + clear popscan hscan; omega rw [he] at hscan refine ⟨walked.length + fill + 1, by simp only [exactPad, hc, ite_false], t, ht, ?_⟩ @@ -188,7 +191,7 @@ theorem fenceReturn_exact (k : Fin 2) (walked : List (Fin 2)) (fill : Nat) (hfil obtain ⟨t₀, ht₀, h₀⟩ := hinit obtain ⟨pad', hpad', t₁, ht₁, h₁⟩ := hmid obtain ⟨t₂, ht₂, h₂⟩ := finish pad' w hguard hheadw - refine ⟨t₀ + (t₁ + t₂), by omega, ?_⟩ + refine ⟨t₀ + (t₁ + t₂), Nat.le_trans ht₀ (Nat.le_add_right t₀ (t₁ + t₂)), ?_⟩ rw [← hpad'] rw [nSteps98_eq] exact Semantics.Riemann.Layer1.nSteps_bind_eq h₀ diff --git a/Cryptids/ReductionSupport/Riemann95/PhysicalTrace95.lean b/Cryptids/ReductionSupport/Riemann95/PhysicalTrace95.lean index eab6d651..40256537 100644 --- a/Cryptids/ReductionSupport/Riemann95/PhysicalTrace95.lean +++ b/Cryptids/ReductionSupport/Riemann95/PhysicalTrace95.lean @@ -25,6 +25,12 @@ open Riemann120.Layer2 Schema Control attribute [local irreducible] Control.instruction Control.effect Control.walked Control.localEffects Control.outsideEffects Control.outsideInstrs Control.localInstr +private theorem list_getD_append_left {α : Type*} : ∀ (l₁ l₂ : List α) (d : α) (i : ℕ), + i < l₁.length → (l₁ ++ l₂).getD i d = l₁.getD i d + | [], _, _, _, hi => absurd hi (Nat.not_lt_zero _) + | _ :: _, _, _, 0, _ => rfl + | _ :: xs, l₂, d, n + 1, hi => list_getD_append_left xs l₂ d n (Nat.lt_of_succ_lt_succ hi) + theorem physical_arithmetic_step (c : ControlWord) (regs extra : List Nat) (hlen : regs.length = 5) (P : Nat) (hP : (walked c).length + 3 ≤ P) (next : RhRegCfg) (hnext : applyInstr (rawInstr c) regs = some next) @@ -36,7 +42,7 @@ theorem physical_arithmetic_step (c : ControlWord) (regs extra : List Nat) have hr : r.val < regs.length := by omega have hrbank : r.val < (regs ++ extra).length := by simp only [List.length_append]; omega obtain ⟨n,hn,hsteps⟩ := Dispatch.root_native c r inc he P (regs ++ extra) hrbank (by omega) - simp only [List.getD_append regs extra 0 r.val hr] at hsteps + simp only [list_getD_append_left regs extra 0 r.val hr] at hsteps have strict (k : Fin 2) (hk : k.val ≤ (walked c).count 0) (hempty : (popBreakRev k.val (walked c).reverse).reverse = []) : P + 1 ≤ Physical.exactPad k (walked c) (P - (walked c).length) := by diff --git a/Cryptids/ReductionSupport/Riemann95/ReferenceBridge95.lean b/Cryptids/ReductionSupport/Riemann95/ReferenceBridge95.lean index 563b1c4c..089af4fb 100644 --- a/Cryptids/ReductionSupport/Riemann95/ReferenceBridge95.lean +++ b/Cryptids/ReductionSupport/Riemann95/ReferenceBridge95.lean @@ -355,12 +355,7 @@ theorem original_scoped_fold95 : OriginalScopedSubEval95 102 (fun regs => [regs. ((Relation.TransGen.single s3).trans (ih m (x + 1) f (v + 1))))) simpa only [Nat.succ_eq_add_one, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using ht intro regs hlen - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, tail⟩⟩⟩⟩⟩ <;> - simp only [List.length_nil, List.length_cons] at hlen - all_goals try omega - have htail : tail = [] := by simpa only [List.length_eq_zero_iff] using (show tail.length = 0 - by omega) - subst tail + obtain ⟨m, j, x, f, v, rfl⟩ := ConjectureMachines.list_length_five regs hlen exact ⟨hbank j m x f v, rfl⟩ have hmove := original_scoped_move95 60 73 74 44 4 1 (by decide) (by decide) (by decide) rfl rfl rfl rfl rfl rfl rfl rfl rfl rfl rfl @@ -466,10 +461,8 @@ theorem original_scoped_divide95 : OriginalScopedSubEval95 54 OriginalDivideFn95 · intro regs hlen simp only [List.length_cons, List.length_nil] · intro regs hlen hm - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> - try simp only [List.length_nil, OfNat.zero_ne_ofNat, List.length_cons, zero_add, - OfNat.one_ne_ofNat, Nat.reduceAdd, Nat.reduceEqDiff, List.getD_eq_getElem?_getD, - Nat.ofNat_pos, getElem?_pos, List.getElem_cons_zero, Option.getD_some] at hlen hm + obtain ⟨m, j, x, f, v, rfl⟩ := ConjectureMachines.list_length_five regs hlen + simp only [List.getD_cons_zero] at hm subst hm simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.add_zero] have hj_lt : j < j + v + 1 := by omega @@ -479,28 +472,25 @@ theorem original_scoped_divide95 : OriginalScopedSubEval95 54 OriginalDivideFn95 rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt hj_lt] simp [hdiv, hmod] · intro regs k hlen hm - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> - try simp only [List.length_nil, OfNat.zero_ne_ofNat, List.length_cons, zero_add, - OfNat.one_ne_ofNat, Nat.reduceAdd, Nat.reduceEqDiff, List.getD_eq_getElem?_getD, - Nat.ofNat_pos, getElem?_pos, List.getElem_cons_zero, Option.getD_some] at hlen hm + obtain ⟨m, j, x, f, v, rfl⟩ := ConjectureMachines.list_length_five regs hlen + simp only [List.getD_cons_zero] at hm subst hm rcases v with _ | v' · simp only [OriginalTickFn95, List.set, List.getD_cons_zero, List.getD_cons_succ, ↓reduceIte, Nat.zero_add, Nat.add_zero] - have hN : (x + 1) * (j + 1) + k = x * (j + 1) + j + (k + 1) := by ring + have hN : (x + 1) * (j + 1) + k = x * (j + 1) + j + (k + 1) := by + rw [Nat.succ_mul]; omega rw [hN] · simp only [OriginalTickFn95, List.set, List.getD_cons_zero, List.getD_cons_succ, Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] have hJ : j + 1 + v' + 1 = j + (v' + 1) + 1 := by omega have hJ2 : j + 1 + v' = j + (v' + 1) := by omega have hN : x * (j + (v' + 1) + 1) + (j + 1) + k = - x * (j + (v' + 1) + 1) + j + (k + 1) := by ring + x * (j + (v' + 1) + 1) + j + (k + 1) := by omega rw [hJ, hJ2, hN] · intro regs k hlen hm - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> - try simp only [List.length_nil, OfNat.zero_ne_ofNat, List.length_cons, zero_add, - OfNat.one_ne_ofNat, Nat.reduceAdd, Nat.reduceEqDiff, List.getD_eq_getElem?_getD, - Nat.ofNat_pos, getElem?_pos, List.getElem_cons_zero, Option.getD_some] at hlen hm + obtain ⟨m, j, x, f, v, rfl⟩ := ConjectureMachines.list_length_five regs hlen + simp only [List.getD_cons_zero] at hm subst hm rcases v with _ | v' <;> simp [OriginalTickFn95] have hjv := original_scoped_move95 65 47 80 70 1 4 (by decide) (by decide) @@ -510,10 +500,10 @@ theorem original_scoped_divide95 : OriginalScopedSubEval95 54 OriginalDivideFn95 have h66 := original_scoped_combinators95.1 66 81 82 _ _ rfl rfl rfl rfl hxm hloop apply hcongr (original_scoped_combinators95.1 54 65 66 _ _ rfl rfl rfl rfl hjv h66) intro regs hlen - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen + obtain ⟨m, j, x, f, v, rfl⟩ := ConjectureMachines.list_length_five regs hlen simp only [OriginalDivideFn95, List.set, List.getD_cons_zero, List.getD_cons_succ, Nat.zero_add, Nat.add_zero, Nat.zero_mul] - have h1 : m + x = x + m := by ring + have h1 : m + x = x + m := Nat.add_comm m x have h2 : j + v + 1 - 1 = j + v := by omega have h3 : v + j = j + v := by omega simp [h1, h2, h3] @@ -584,10 +574,8 @@ theorem original_digits_scoped95 (j x f v : Nat) (hJ : 2 ≤ j + v + 1) : Relati simp only [Fin.isValue, Riemann120.Layer2.trimZeros, List.reverse_cons, List.reverse_nil, List.nil_append, List.cons_append, Riemann120.Layer2.dropLeadingZeros, BEq.rfl, ↓reduceIte, Fin.reduceBEq, Bool.false_eq_true, Riemann120.Layer2.retStack, - Riemann120.Layer2.popBreakRev, OriginalDivideFn95, List.getD_eq_getElem?_getD, - List.length_cons, List.length_nil, zero_add, Nat.reduceAdd, Nat.ofNat_pos, getElem?_pos, - List.getElem_cons_zero, Option.getD_some, Nat.reduceLT, List.getElem_cons_succ, - Nat.one_lt_ofNat, Nat.lt_add_one, add_tsub_cancel_right] at hd' + Riemann120.Layer2.popBreakRev, OriginalDivideFn95, List.getD_cons_zero, + List.getD_cons_succ, Nat.zero_add, add_tsub_cancel_right] at hd' have hf := hdecf (x % J) (x / J) f (J - 1 - x % J) have hc : Riemann120.Layer2.rhRegStep ⟨[1,1,1,0,0,1,1,1], [0,x % J,x / J,f-1,J-1-x % J]⟩ = @@ -678,7 +666,9 @@ theorem original_scoped_transform95 : OriginalScopedSubEval95 84 OriginalTransfo have hs_c := Riemann120.Layer2.rhRegStep_of_jump (regs := [k,j+v,x+j+1,f,0]) hev_cont have hi := ih (j+v) (x+j+1) f 0 - have h2 : x+j+1+k*(j+v+0+1)+(j+v) = x+(k+1)*(j+v+1)+j := by ring + have h1 : j+v+0 = j+v := by omega + have h2 : x+j+1+k*(j+v+0+1)+(j+v) = x+(k+1)*(j+v+1)+j := by + rw [h1, Nat.succ_mul]; omega simp only [Nat.add_zero] at hi h2 rw [h2] at hi have hm : R ⟨P ++ [1], [k+1,j+v,x+j,f,0]⟩ diff --git a/Cryptids/ReductionSupport/Riemann95/ReferencePermutation95.lean b/Cryptids/ReductionSupport/Riemann95/ReferencePermutation95.lean index c879b72b..e0cb0ff3 100644 --- a/Cryptids/ReductionSupport/Riemann95/ReferencePermutation95.lean +++ b/Cryptids/ReductionSupport/Riemann95/ReferencePermutation95.lean @@ -26,13 +26,8 @@ def decodeBank (regs : List Nat) : List Nat := [regs.getD 3 0,regs.getD 4 0,regs.getD 0 0,regs.getD 2 0,regs.getD 1 0] theorem bank_five (regs : List Nat) (hlen : regs.length = 5) : - ∃ a b c d e, regs = [a,b,c,d,e] := by - rcases regs with _ | ⟨a, _ | ⟨b, _ | ⟨c, _ | ⟨d, _ | ⟨e, rest⟩⟩⟩⟩⟩ <;> - simp only [List.length_nil, List.length_cons] at hlen - all_goals try omega - have he : rest = [] := List.eq_nil_of_length_eq_zero (by omega) - subst rest - exact ⟨a,b,c,d,e,rfl⟩ + ∃ a b c d e, regs = [a,b,c,d,e] := + ConjectureMachines.list_length_five regs hlen theorem encodeBank_length (regs : List Nat) : (encodeBank regs).length = 5 := rfl theorem decodeBank_length (regs : List Nat) : (decodeBank regs).length = 5 := rfl diff --git a/Cryptids/ReductionSupport/Riemann95/Return95.lean b/Cryptids/ReductionSupport/Riemann95/Return95.lean index eaeeca1b..482264f5 100644 --- a/Cryptids/ReductionSupport/Riemann95/Return95.lean +++ b/Cryptids/ReductionSupport/Riemann95/Return95.lean @@ -336,18 +336,21 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) some ⟨target, bank⟩ := by rw [h]; rfl have hg := (Control.decoded_next_noThree (.local d s) bank _ hnext).2 have hp := localWalk_parse d s - fin_cases s <;> first + rcases s with ⟨sv, hsv⟩ + interval_cases sv <;> first | (solve | cases h) | skip - case «3» => - have ht : target = callerPrefix d ++ [1] := by + · have ht : target = callerPrefix d ++ [1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨3, by decide⟩ : Fin 22) = [1, 0, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨3, by decide⟩ : Fin 22) = [1, 0, 0, 1, 1] := by decide +kernel - have hq : localTerminal (⟨3, by decide⟩ : Fin 22) = 43 := by decide +kernel + have hsuf : suffix ⟨3, hsv⟩ = [1, 0, 0, 1, 1, 1] := + (by decide +kernel : suffix 3 = [1, 0, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨3, hsv⟩ = [1, 0, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 3 = [1, 0, 0, 1, 1]) + have hq : localTerminal ⟨3, hsv⟩ = 43 := + (by decide +kernel : localTerminal 3 = 43) have hp' : walkInternal 15 ((callerPrefix d) ++ [1, 0, 0, 1, 1]) = some 43 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp @@ -359,15 +362,17 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) List.cons_append, List.nil_append] using hpad simpa only [word, hsuf, List.append_assoc, List.cons_append, List.nil_append] using root43 (callerPrefix d) pad bank hp' hg' hpad' - case «6» => - have ht : target = callerPrefix d ++ [1, 0, 1] := by + · have ht : target = callerPrefix d ++ [1, 0, 1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨6, by decide⟩ : Fin 22) = [1, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨6, by decide⟩ : Fin 22) = [1, 0, 1, 1] := by decide +kernel - have hq : localTerminal (⟨6, by decide⟩ : Fin 22) = 59 := by decide +kernel + have hsuf : suffix ⟨6, hsv⟩ = [1, 0, 1, 1, 1] := + (by decide +kernel : suffix 6 = [1, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨6, hsv⟩ = [1, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 6 = [1, 0, 1, 1]) + have hq : localTerminal ⟨6, hsv⟩ = 59 := + (by decide +kernel : localTerminal 6 = 59) have hp' : walkInternal 15 ((callerPrefix d ++ [1, 0]) ++ [1, 1]) = some 59 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp @@ -380,15 +385,17 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) List.cons_append, List.nil_append] using hpad simpa only [word, hsuf, List.append_assoc, List.cons_append, List.nil_append] using root59 (callerPrefix d ++ [1, 0]) pad bank hp' hg' hpad' - case «10» => - have ht : target = callerPrefix d ++ [1, 1] := by + · have ht : target = callerPrefix d ++ [1, 1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨10, by decide⟩ : Fin 22) = [1, 1, 0, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨10, by decide⟩ : Fin 22) = [1, 1, 0, 0, 1, 1] := by decide +kernel - have hq : localTerminal (⟨10, by decide⟩ : Fin 22) = 43 := by decide +kernel + have hsuf : suffix ⟨10, hsv⟩ = [1, 1, 0, 0, 1, 1, 1] := + (by decide +kernel : suffix 10 = [1, 1, 0, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨10, hsv⟩ = [1, 1, 0, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 10 = [1, 1, 0, 0, 1, 1]) + have hq : localTerminal ⟨10, hsv⟩ = 43 := + (by decide +kernel : localTerminal 10 = 43) have hp' : walkInternal 15 ((callerPrefix d ++ [1]) ++ [1, 0, 0, 1, 1]) = some 43 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp @@ -401,15 +408,17 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) List.cons_append, List.nil_append] using hpad simpa only [word, hsuf, List.append_assoc, List.cons_append, List.nil_append] using root43 (callerPrefix d ++ [1]) pad bank hp' hg' hpad' - case «13» => - have ht : target = callerPrefix d ++ [1, 1, 0, 1] := by + · have ht : target = callerPrefix d ++ [1, 1, 0, 1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨13, by decide⟩ : Fin 22) = [1, 1, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨13, by decide⟩ : Fin 22) = [1, 1, 0, 1, 1] := by decide +kernel - have hq : localTerminal (⟨13, by decide⟩ : Fin 22) = 59 := by decide +kernel + have hsuf : suffix ⟨13, hsv⟩ = [1, 1, 0, 1, 1, 1] := + (by decide +kernel : suffix 13 = [1, 1, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨13, hsv⟩ = [1, 1, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 13 = [1, 1, 0, 1, 1]) + have hq : localTerminal ⟨13, hsv⟩ = 59 := + (by decide +kernel : localTerminal 13 = 59) have hp' : walkInternal 15 ((callerPrefix d ++ [1, 1, 0]) ++ [1, 1]) = some 59 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp @@ -422,16 +431,17 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) List.cons_append, List.nil_append] using hpad simpa only [word, hsuf, List.append_assoc, List.cons_append, List.nil_append] using root59 (callerPrefix d ++ [1, 1, 0]) pad bank hp' hg' hpad' - case «17» => - have ht : target = callerPrefix d ++ [1, 1, 1] := by + · have ht : target = callerPrefix d ++ [1, 1, 1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨17, by decide⟩ : Fin 22) = [1, 1, 1, 0, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨17, by decide⟩ : Fin 22) = [1, 1, 1, 0, 0, 1, 1] := by - decide +kernel - have hq : localTerminal (⟨17, by decide⟩ : Fin 22) = 43 := by decide +kernel + have hsuf : suffix ⟨17, hsv⟩ = [1, 1, 1, 0, 0, 1, 1, 1] := + (by decide +kernel : suffix 17 = [1, 1, 1, 0, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨17, hsv⟩ = [1, 1, 1, 0, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 17 = [1, 1, 1, 0, 0, 1, 1]) + have hq : localTerminal ⟨17, hsv⟩ = 43 := + (by decide +kernel : localTerminal 17 = 43) have hp' : walkInternal 15 ((callerPrefix d ++ [1, 1]) ++ [1, 0, 0, 1, 1]) = some 43 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp @@ -444,15 +454,17 @@ theorem root_local (d : Nat) (s : Fin 22) (target : Word) List.cons_append, List.nil_append] using hpad simpa only [word, hsuf, List.append_assoc, List.cons_append, List.nil_append] using root43 (callerPrefix d ++ [1, 1]) pad bank hp' hg' hpad' - case «20» => - have ht : target = callerPrefix d ++ [1, 1, 1, 0, 1] := by + · have ht : target = callerPrefix d ++ [1, 1, 1, 0, 1] := by simpa [Control.rawInstr, Control.effect, Control.localEffects, Control.walked, Control.returned, localWalk, localWalkSuffix, localWalkSuffixes, Riemann120.Layer2.popContinueRev, List.reverse_append] using h.symm subst target - have hsuf : suffix (⟨20, by decide⟩ : Fin 22) = [1, 1, 1, 0, 1, 1, 1] := by decide +kernel - have hw : localWalkSuffix (⟨20, by decide⟩ : Fin 22) = [1, 1, 1, 0, 1, 1] := by decide +kernel - have hq : localTerminal (⟨20, by decide⟩ : Fin 22) = 19 := by decide +kernel + have hsuf : suffix ⟨20, hsv⟩ = [1, 1, 1, 0, 1, 1, 1] := + (by decide +kernel : suffix 20 = [1, 1, 1, 0, 1, 1, 1]) + have hw : localWalkSuffix ⟨20, hsv⟩ = [1, 1, 1, 0, 1, 1] := + (by decide +kernel : localWalkSuffix 20 = [1, 1, 1, 0, 1, 1]) + have hq : localTerminal ⟨20, hsv⟩ = 19 := + (by decide +kernel : localTerminal 20 = 19) have hp' : walkInternal 15 ((callerPrefix d ++ [1, 1, 1, 0]) ++ [1, 1]) = some 19 := by simpa only [localWalk, hw, hq, List.append_assoc, List.cons_append, List.nil_append] using hp diff --git a/Cryptids/ReductionSupport/Riemann95/Terminal95.lean b/Cryptids/ReductionSupport/Riemann95/Terminal95.lean index 2cfa9f17..9fc01b98 100644 --- a/Cryptids/ReductionSupport/Riemann95/Terminal95.lean +++ b/Cryptids/ReductionSupport/Riemann95/Terminal95.lean @@ -107,7 +107,8 @@ theorem entry_arithmeticPrefix (d : Nat) : arithmeticPrefix (.entry d) := by rfl theorem local_arithmeticPrefix (d : Nat) (s : Fin 22) : arithmeticPrefix (.local d s) := by - fin_cases s <;> + rcases s with ⟨sv, hsv⟩ + interval_cases sv <;> simp [arithmeticPrefix, Control.effect, Control.localEffects, Control.walked, Schema.word, Schema.localWalk, Schema.localWalkSuffix, Schema.localWalkSuffixes, Schema.suffix, Schema.suffixes, List.length_append, Nat.add_sub_add_left, @@ -152,7 +153,10 @@ theorem physical_halt_word (P : Nat) (bank : List Nat) : refine ⟨6, ⟨61, Tape.mk' (ListBlank.append bits.reverse L) R⟩, ?_, ?_⟩ · rw [hroot] exact ConjectureMachines.Riemann95.Parser.walkInternal_nSteps bits 15 61 L R hwalk - · rfl + · have hR : R.head = 1 := by + simp only [R, List.cons_append, List.nil_append, ← ListBlank.cons_mk, ListBlank.head_cons] + simp only [step, Tape.mk'_head, hR] + rfl end ConjectureMachines.Riemann95 diff --git a/Cryptids/ReductionSupport/Riemann95/WidthSteps95.lean b/Cryptids/ReductionSupport/Riemann95/WidthSteps95.lean index 4dda3473..e94fd936 100644 --- a/Cryptids/ReductionSupport/Riemann95/WidthSteps95.lean +++ b/Cryptids/ReductionSupport/Riemann95/WidthSteps95.lean @@ -33,45 +33,45 @@ def halfCfg (k : Fin 3) (d : Nat) (s : Fin 8) (m v a x other : Nat) : Cfg := theorem half_step0 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 0 m v a x other) = some (halfCfg k d (if a = 0 then 4 else 1) m v (a-1) x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step1 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 1 m v a x other) = some (halfCfg k d (if a = 0 then 4 else 2) m v (a-1) x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step2 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 2 m v a x other) = some (halfCfg k d 3 m (v+1) a x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step3 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 3 m v a x other) = some (halfCfg k d 0 m v a x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step4 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 4 m v a x other) = some (halfCfg k d (if v = 0 then 7 else 5) m (v-1) a x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step5 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 5 m v a x other) = some (halfCfg k d 6 m v (a+1) x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] theorem half_step6 (k : Fin 3) (d : Nat) (m v a x other : Nat) : step (halfCfg k d 6 m v a x other) = some (halfCfg k d 4 m v a x other) := by - fin_cases k <;> rcases d with _ | (_ | d) <;> + rcases k with ⟨kv, hkv⟩; interval_cases kv <;> rcases d with _ | (_ | d) <;> by_cases ha : a = 0 <;> by_cases hv : v = 0 <;> simp [step, instruction, localInstr, halfCfg, halfWord, ha, hv] diff --git a/Cryptids/Riemann120.lean b/Cryptids/Riemann120.lean index f3950d82..a02aa255 100644 --- a/Cryptids/Riemann120.lean +++ b/Cryptids/Riemann120.lean @@ -1548,10 +1548,14 @@ theorem halts_riemann120_iff_halts_riemann121 : +/-- Constructive trial-division primality test for `p : ℕ` avoiding `Classical.choice`. -/ +def isPrimeBool (p : ℕ) : Bool := + decide (2 ≤ p) && (List.range p).all fun d => decide (d < 2) || (p % d != 0) + /-- Product of all primes `p ≤ n`. -/ def primorial : ℕ → ℕ | 0 => 1 - | n + 1 => if Nat.Prime (n + 1) then (n + 1) * primorial n else primorial n + | n + 1 => if isPrimeBool (n + 1) then (n + 1) * primorial n else primorial n /-- Self-sieving sequence `A_n = n! * P(n)`. -/ def shuniaProd (n : ℕ) : ℕ := diff --git a/Cryptids/Semantics/PA/Adequacy.lean b/Cryptids/Semantics/PA/Adequacy.lean index 84c973c7..6af1e831 100644 --- a/Cryptids/Semantics/PA/Adequacy.lean +++ b/Cryptids/Semantics/PA/Adequacy.lean @@ -431,16 +431,18 @@ def decodeHalf (n : ℕ) : ListBlank (Fin 2) := ListBlank.mk (decodeListBin n) @[simp] -theorem encodeHalf_mk (xs : List (Fin 2)) : encodeHalf (ListBlank.mk xs) = encodeListBin xs := - rfl +theorem encodeHalf_mk (xs : List (Fin 2)) : encodeHalf (ListBlank.mk xs) = encodeListBin xs := by + unfold encodeHalf + exact ListBlank.liftOn_mk xs encodeListBin _ @[simp] theorem encodeHalf_default : encodeHalf default = 0 := rfl @[simp] theorem encodeHalf_cons (l : ListBlank (Fin 2)) (a : Fin 2) : - encodeHalf (l.cons a) = 2 * encodeHalf l + a.val := - l.induction_on fun _ ↦ rfl + encodeHalf (l.cons a) = 2 * encodeHalf l + a.val := by + refine l.induction_on fun xs ↦ ?_ + rw [ListBlank.cons_mk, encodeHalf_mk, encodeHalf_mk, encodeListBin] theorem encodeHalf_eq_tail_head (l : ListBlank (Fin 2)) : encodeHalf l = 2 * encodeHalf l.tail + l.head.val := by @@ -459,8 +461,9 @@ private theorem encodeListBin_decodeListBin (n : ℕ) : encodeListBin (decodeLis omega @[simp] -theorem encodeHalf_decodeHalf (n : ℕ) : encodeHalf (decodeHalf n) = n := - encodeListBin_decodeListBin n +theorem encodeHalf_decodeHalf (n : ℕ) : encodeHalf (decodeHalf n) = n := by + rw [decodeHalf, encodeHalf_mk] + exact encodeListBin_decodeListBin n private theorem mk_decodeListBin_encodeListBin (xs : List (Fin 2)) : ListBlank.mk (decodeListBin (encodeListBin xs)) = ListBlank.mk xs := by @@ -480,7 +483,7 @@ private theorem mk_decodeListBin_encodeListBin (xs : List (Fin 2)) : have hcons : ListBlank.mk ((default : Fin 2) :: xs) = (ListBlank.mk xs).cons default := rfl rw [hcons, ← ih] - exact Quot.sound (Or.inl ⟨1, rfl⟩) + exact ListBlank.cons_default_default.symm · obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero hne rw [hk, decodeListBin] have hdiv : (k + 1) / 2 = encodeListBin xs := by @@ -495,7 +498,9 @@ private theorem mk_decodeListBin_encodeListBin (xs : List (Fin 2)) : @[simp] theorem decodeHalf_encodeHalf (l : ListBlank (Fin 2)) : decodeHalf (encodeHalf l) = l := - l.induction_on mk_decodeListBin_encodeListBin + l.induction_on fun xs ↦ by + rw [decodeHalf, encodeHalf_mk] + exact mk_decodeListBin_encodeListBin xs theorem encodeHalf_injective {l₁ l₂ : ListBlank (Fin 2)} (h : encodeHalf l₁ = encodeHalf l₂) : l₁ = l₂ := by diff --git a/Cryptids/Semantics/PA/Syntax.lean b/Cryptids/Semantics/PA/Syntax.lean index 41090600..0921d65b 100644 --- a/Cryptids/Semantics/PA/Syntax.lean +++ b/Cryptids/Semantics/PA/Syntax.lean @@ -394,19 +394,108 @@ theorem paProvable_sound {M : Type*} [PAStructure M] [PAModel M] {φ : PAFormula theorem paProvable_sound_nat (φ : PAFormula) (h : PAProvable φ) (v : ℕ → ℕ) : φ.Holds v := (holdsIn_nat_iff v φ).mp (paProvable_sound h v) -/-! ## Section 4: Constructive Consistency via Negative Translation (`not_paProvable_false`) -/ +/-! ## Section 4: Zero-Axiom Consistency via Negative Translation (`not_paProvable_false`) -/ + +/-- Environment update avoiding `Function.update` so `not_paProvable_false` uses zero axioms. -/ +def envUpdate (v : ℕ → ℕ) (x a y : ℕ) : ℕ := + match Nat.decEq y x with + | isTrue _ => a + | isFalse _ => v y + +private theorem envUpdate_self (v : ℕ → ℕ) (x a : ℕ) : envUpdate v x a x = a := by + dsimp only [envUpdate] + cases Nat.decEq x x with + | isTrue _ => rfl + | isFalse h => exact False.elim (h rfl) + +private theorem envUpdate_of_ne (v : ℕ → ℕ) {x y : ℕ} (h : y ≠ x) (a : ℕ) : + envUpdate v x a y = v y := by + dsimp only [envUpdate] + cases Nat.decEq y x with + | isTrue he => exact False.elim (h he) + | isFalse _ => rfl /-- Gödel–Gentzen negative satisfaction of a `PAFormula` in `ℕ`, replacing positive disjunction and existential quantification by their double-negated counterparts so every formula is -constructively `¬¬`-stable without `Classical.choice`. -/ +constructively `¬¬`-stable with zero axioms (`[]`). -/ def PAFormula.NHolds (v : ℕ → ℕ) : PAFormula → Prop | .bot => False | .eq t₁ t₂ => t₁.eval v = t₂.eval v | .and φ ψ => PAFormula.NHolds v φ ∧ PAFormula.NHolds v ψ | .or φ ψ => ¬¬ (PAFormula.NHolds v φ ∨ PAFormula.NHolds v ψ) | .imp φ ψ => PAFormula.NHolds v φ → PAFormula.NHolds v ψ - | .all x φ => ∀ a : ℕ, PAFormula.NHolds (Function.update v x a) φ - | .ex x φ => ¬¬ ∃ a : ℕ, PAFormula.NHolds (Function.update v x a) φ + | .all x φ => ∀ a : ℕ, PAFormula.NHolds (envUpdate v x a) φ + | .ex x φ => ¬¬ ∃ a : ℕ, PAFormula.NHolds (envUpdate v x a) φ + +private theorem nat_beq_refl : ∀ x : ℕ, (x == x) = true + | 0 => rfl + | x + 1 => nat_beq_refl x + +private theorem nat_beq_eq_false : ∀ {x y : ℕ}, x ≠ y → (x == y) = false + | 0, 0, h => False.elim (h rfl) + | 0, _ + 1, _ => rfl + | _ + 1, 0, _ => rfl + | x + 1, y + 1, h => nat_beq_eq_false (x := x) (y := y) fun heq ↦ h (congrArg (· + 1) heq) + +private theorem bool_or_inl {a b : Bool} (ha : a = true) : (a || b) = true := by + rw [ha]; rfl + +private theorem bool_or_inr {a b : Bool} (hb : b = true) : (a || b) = true := by + cases a with + | true => rfl + | false => exact hb + +private theorem bool_and_left {a b : Bool} (h : (a && b) = true) : a = true := by + cases a with + | false => exact Bool.noConfusion h + | true => rfl + +private theorem bool_and_right {a b : Bool} (h : (a && b) = true) : b = true := by + cases a with + | false => exact Bool.noConfusion h + | true => exact h + +private theorem bool_or_false_left {a b : Bool} (h : (a || b) = false) : a = false := by + cases a with + | false => rfl + | true => exact Bool.noConfusion h + +private theorem bool_or_false_right {a b : Bool} (h : (a || b) = false) : b = false := by + cases a with + | false => exact h + | true => exact Bool.noConfusion h + +private theorem bool_or_cases {a b : Bool} (h : (a || b) = true) : a = true ∨ b = true := by + cases a with + | true => exact Or.inl rfl + | false => exact Or.inr h + +private theorem bool_not_eq_true_iff {a : Bool} (h : (!a) = true) : a = false := by + cases a with + | false => rfl + | true => exact Bool.noConfusion h + +private theorem iff_and_zero {A B C D : Prop} (h₁ : A ↔ C) (h₂ : B ↔ D) : + (A ∧ B) ↔ (C ∧ D) := + ⟨fun ⟨a, b⟩ ↦ ⟨h₁.mp a, h₂.mp b⟩, fun ⟨c, d⟩ ↦ ⟨h₁.mpr c, h₂.mpr d⟩⟩ + +private theorem iff_imp_zero {A B C D : Prop} (h₁ : A ↔ C) (h₂ : B ↔ D) : + (A → B) ↔ (C → D) := + ⟨fun f c ↦ h₂.mp (f (h₁.mpr c)), fun g a ↦ h₂.mpr (g (h₁.mp a))⟩ + +private theorem iff_nn_or_zero {A B C D : Prop} (h₁ : A ↔ C) (h₂ : B ↔ D) : + ¬¬ (A ∨ B) ↔ ¬¬ (C ∨ D) := + ⟨fun h hn ↦ h fun d ↦ hn (d.elim (fun a ↦ Or.inl (h₁.mp a)) (fun b ↦ Or.inr (h₂.mp b))), + fun h hn ↦ h fun d ↦ hn (d.elim (fun c ↦ Or.inl (h₁.mpr c)) (fun d ↦ Or.inr (h₂.mpr d)))⟩ + +private theorem iff_all_zero {P Q : ℕ → Prop} (h : ∀ a, P a ↔ Q a) : + (∀ a, P a) ↔ (∀ a, Q a) := + ⟨fun f a ↦ (h a).mp (f a), fun g a ↦ (h a).mpr (g a)⟩ + +private theorem iff_nn_ex_zero {P Q : ℕ → Prop} (h : ∀ a, P a ↔ Q a) : + (¬¬ ∃ a, P a) ↔ (¬¬ ∃ a, Q a) := + ⟨fun f hn ↦ f fun ⟨a, pa⟩ ↦ hn ⟨a, (h a).mp pa⟩, + fun g hn ↦ g fun ⟨a, qa⟩ ↦ hn ⟨a, (h a).mpr qa⟩⟩ theorem nHolds_stable (φ : PAFormula) (v : ℕ → ℕ) : ¬¬ PAFormula.NHolds v φ → PAFormula.NHolds v φ := by @@ -414,9 +503,9 @@ theorem nHolds_stable (φ : PAFormula) (v : ℕ → ℕ) : | bot => intro h; exact h id | eq t₁ t₂ => intro h - by_cases he : t₁.eval v = t₂.eval v - · exact he - · exact False.elim (h he) + cases Nat.decEq (t₁.eval v) (t₂.eval v) with + | isFalse hne => exact False.elim (h hne) + | isTrue he => exact he | and φ ψ ih₁ ih₂ => intro h exact ⟨ih₁ v fun h₁ ↦ h fun hp ↦ h₁ hp.1, ih₂ v fun h₂ ↦ h fun hp ↦ h₂ hp.2⟩ @@ -428,137 +517,349 @@ theorem nHolds_stable (φ : PAFormula) (v : ℕ → ℕ) : exact ih₂ v fun hψ ↦ h fun himp ↦ hψ (himp hφ) | all x φ ih => intro h a - exact ih (Function.update v x a) fun ha ↦ h fun hall ↦ ha (hall a) + exact ih (envUpdate v x a) fun ha ↦ h fun hall ↦ ha (hall a) | ex _ _ _ => intro h hn exact h fun hnn ↦ hnn hn +private theorem eval_congr_zero {v₁ v₂ : ℕ → ℕ} : + ∀ {t : PATerm}, (∀ x, t.hasVar x = true → v₁ x = v₂ x) → t.eval v₁ = t.eval v₂ + | .var x, h => h x (nat_beq_refl x) + | .zero, _ => rfl + | .succ _, h => congrArg (· + 1) (eval_congr_zero h) + | .add _ _, h => + congrArg₂ (· + ·) + (eval_congr_zero fun x hx ↦ h x (bool_or_inl hx)) + (eval_congr_zero fun x hx ↦ h x (bool_or_inr hx)) + | .mul _ _, h => + congrArg₂ (· * ·) + (eval_congr_zero fun x hx ↦ h x (bool_or_inl hx)) + (eval_congr_zero fun x hx ↦ h x (bool_or_inr hx)) + +private theorem eval_update_of_hasVar_false_zero (v : ℕ → ℕ) {x : ℕ} (a : ℕ) {t : PATerm} + (hx : t.hasVar x = false) : t.eval (envUpdate v x a) = t.eval v := + eval_congr_zero fun y hy ↦ + have hne : y ≠ x := fun h ↦ by subst h; rw [hx] at hy; exact Bool.noConfusion hy + envUpdate_of_ne v hne a + +private theorem eval_subst_zero (v : ℕ → ℕ) (x : ℕ) (s : PATerm) : + ∀ t : PATerm, (t.subst x s).eval v = t.eval (envUpdate v x (s.eval v)) + | .var y => by + dsimp only [PATerm.subst] + cases Nat.decEq y x with + | isTrue h => + subst h + rw [nat_beq_refl] + exact (envUpdate_self v y (s.eval v)).symm + | isFalse h => + rw [nat_beq_eq_false h] + exact (envUpdate_of_ne v h (s.eval v)).symm + | .zero => rfl + | .succ t => congrArg (· + 1) (eval_subst_zero v x s t) + | .add t₁ t₂ => congrArg₂ (· + ·) (eval_subst_zero v x s t₁) (eval_subst_zero v x s t₂) + | .mul t₁ t₂ => congrArg₂ (· * ·) (eval_subst_zero v x s t₁) (eval_subst_zero v x s t₂) + +private theorem term_subst_eq_self_zero {x : ℕ} (s : PATerm) : + ∀ {t : PATerm}, t.hasVar x = false → t.subst x s = t + | .var y, ht => by + dsimp only [PATerm.subst] + have hyx : (y == x) = false := by + cases Nat.decEq y x with + | isTrue h => + subst h + change (y == y) = false at ht + rw [nat_beq_refl] at ht + exact Bool.noConfusion ht + | isFalse h => exact nat_beq_eq_false h + rw [hyx] + rfl + | .zero, _ => rfl + | .succ _, ht => congrArg PATerm.succ (term_subst_eq_self_zero s ht) + | .add _ _, ht => + congrArg₂ PATerm.add + (term_subst_eq_self_zero s (bool_or_false_left ht)) + (term_subst_eq_self_zero s (bool_or_false_right ht)) + | .mul _ _, ht => + congrArg₂ PATerm.mul + (term_subst_eq_self_zero s (bool_or_false_left ht)) + (term_subst_eq_self_zero s (bool_or_false_right ht)) + +private theorem subst_eq_self_zero {x : ℕ} (s : PATerm) : + ∀ {φ : PAFormula}, φ.hasFree x = false → φ.subst x s = φ + | .bot, _ => rfl + | .eq _ _, hx => + congrArg₂ PAFormula.eq + (term_subst_eq_self_zero s (bool_or_false_left hx)) + (term_subst_eq_self_zero s (bool_or_false_right hx)) + | .and _ _, hx => + congrArg₂ PAFormula.and + (subst_eq_self_zero s (bool_or_false_left hx)) + (subst_eq_self_zero s (bool_or_false_right hx)) + | .or _ _, hx => + congrArg₂ PAFormula.or + (subst_eq_self_zero s (bool_or_false_left hx)) + (subst_eq_self_zero s (bool_or_false_right hx)) + | .imp _ _, hx => + congrArg₂ PAFormula.imp + (subst_eq_self_zero s (bool_or_false_left hx)) + (subst_eq_self_zero s (bool_or_false_right hx)) + | .all y φ, hx => by + dsimp only [PAFormula.subst] + cases Nat.decEq y x with + | isTrue h => + subst h + rw [nat_beq_refl] + rfl + | isFalse h => + have hb : (y == x) = false := nat_beq_eq_false h + rw [hb] + have hfree : φ.hasFree x = false := by + change (!(y == x) && φ.hasFree x) = false at hx + rw [hb] at hx + exact hx + exact congrArg (PAFormula.all y) (subst_eq_self_zero s hfree) + | .ex y φ, hx => by + dsimp only [PAFormula.subst] + cases Nat.decEq y x with + | isTrue h => + subst h + rw [nat_beq_refl] + rfl + | isFalse h => + have hb : (y == x) = false := nat_beq_eq_false h + rw [hb] + have hfree : φ.hasFree x = false := by + change (!(y == x) && φ.hasFree x) = false at hx + rw [hb] at hx + exact hx + exact congrArg (PAFormula.ex y) (subst_eq_self_zero s hfree) + +private theorem freeFor_zero_zero (x : ℕ) : ∀ φ : PAFormula, φ.freeFor x .zero = true + | .bot | .eq _ _ => rfl + | .and φ ψ | .or φ ψ | .imp φ ψ => by + change (φ.freeFor x .zero && ψ.freeFor x .zero) = true + rw [freeFor_zero_zero x φ, freeFor_zero_zero x ψ] + rfl + | .all y φ | .ex y φ => by + change ((y == x) || ((!φ.hasFree x || !PATerm.zero.hasVar y) && φ.freeFor x .zero)) = true + have hor : (!φ.hasFree x || !PATerm.zero.hasVar y) = true := bool_or_inr rfl + rw [hor, freeFor_zero_zero x φ] + exact bool_or_inr rfl + +private theorem freeFor_succ_self_zero (x : ℕ) : + ∀ φ : PAFormula, φ.freeFor x (.succ (.var x)) = true + | .bot | .eq _ _ => rfl + | .and φ ψ | .or φ ψ | .imp φ ψ => by + change (φ.freeFor x (.succ (.var x)) && ψ.freeFor x (.succ (.var x))) = true + rw [freeFor_succ_self_zero x φ, freeFor_succ_self_zero x ψ] + rfl + | .all y φ | .ex y φ => by + change ((y == x) || + ((!φ.hasFree x || !(PATerm.succ (.var x)).hasVar y) && + φ.freeFor x (.succ (.var x)))) = true + cases Nat.decEq y x with + | isTrue h => + subst h + exact bool_or_inl (nat_beq_refl y) + | isFalse h => + have hxy : (x == y) = false := nat_beq_eq_false (Ne.symm h) + have hnot : (!(PATerm.succ (.var x)).hasVar y) = true := by + change (!(x == y)) = true + rw [hxy] + rfl + have hor : (!φ.hasFree x || !(PATerm.succ (.var x)).hasVar y) = true := bool_or_inr hnot + rw [hor, freeFor_succ_self_zero x φ] + exact bool_or_inr rfl + private theorem nHolds_congr {v₁ v₂ : ℕ → ℕ} {φ : PAFormula} (h : ∀ x, φ.hasFree x = true → v₁ x = v₂ x) : PAFormula.NHolds v₁ φ ↔ PAFormula.NHolds v₂ φ := by induction φ generalizing v₁ v₂ with - | bot => exact Iff.rfl + | bot => exact ⟨id, id⟩ | eq t₁ t₂ => - have e₁ : t₁.eval v₁ = t₁.eval v₂ := by - rw [← evalIn_nat_eq, ← evalIn_nat_eq] - exact evalIn_congr fun x hx ↦ h x (by simp [PAFormula.hasFree, hx]) - have e₂ : t₂.eval v₁ = t₂.eval v₂ := by - rw [← evalIn_nat_eq, ← evalIn_nat_eq] - exact evalIn_congr fun x hx ↦ h x (by simp [PAFormula.hasFree, hx]) - simp only [PAFormula.NHolds, e₁, e₂] + have e₁ : t₁.eval v₁ = t₁.eval v₂ := eval_congr_zero fun x hx ↦ h x (bool_or_inl hx) + have e₂ : t₂.eval v₁ = t₂.eval v₂ := eval_congr_zero fun x hx ↦ h x (bool_or_inr hx) + exact ⟨fun he ↦ e₁.symm.trans (he.trans e₂), fun he ↦ e₁.trans (he.trans e₂.symm)⟩ | and _ _ ih₁ ih₂ => - refine and_congr (ih₁ fun x hx ↦ h x ?_) (ih₂ fun x hx ↦ h x ?_) <;> - simp [PAFormula.hasFree, hx] + exact iff_and_zero + (ih₁ fun x hx ↦ h x (bool_or_inl hx)) + (ih₂ fun x hx ↦ h x (bool_or_inr hx)) | or _ _ ih₁ ih₂ => - have c₁ := ih₁ (v₁ := v₁) (v₂ := v₂) fun x hx ↦ h x (by simp [PAFormula.hasFree, hx]) - have c₂ := ih₂ (v₁ := v₁) (v₂ := v₂) fun x hx ↦ h x (by simp [PAFormula.hasFree, hx]) - exact not_congr (not_congr (or_congr c₁ c₂)) + exact iff_nn_or_zero + (ih₁ fun x hx ↦ h x (bool_or_inl hx)) + (ih₂ fun x hx ↦ h x (bool_or_inr hx)) | imp _ _ ih₁ ih₂ => - refine imp_congr (ih₁ fun x hx ↦ h x ?_) (ih₂ fun x hx ↦ h x ?_) <;> - simp [PAFormula.hasFree, hx] + exact iff_imp_zero + (ih₁ fun x hx ↦ h x (bool_or_inl hx)) + (ih₂ fun x hx ↦ h x (bool_or_inr hx)) | all y _ ih => - refine forall_congr' fun a ↦ ih fun x hx ↦ ?_ - rcases Decidable.eq_or_ne x y with rfl | hxy - · simp - · simp only [Function.update_of_ne hxy] - exact h x (by simp [PAFormula.hasFree, Ne.symm hxy, hx]) + refine iff_all_zero fun a ↦ ih fun x hx ↦ ?_ + cases Nat.decEq x y with + | isTrue heq => + subst heq + exact (envUpdate_self v₁ x a).trans (envUpdate_self v₂ x a).symm + | isFalse hxy => + have hu₁ := envUpdate_of_ne v₁ hxy a + have hu₂ := envUpdate_of_ne v₂ hxy a + refine hu₁.trans ((h x ?_).trans hu₂.symm) + change (!(y == x) && _) = true + rw [nat_beq_eq_false (Ne.symm hxy)] + exact hx | ex y _ ih => - refine not_congr (not_congr (exists_congr fun a ↦ ih fun x hx ↦ ?_)) - rcases Decidable.eq_or_ne x y with rfl | hxy - · simp - · simp only [Function.update_of_ne hxy] - exact h x (by simp [PAFormula.hasFree, Ne.symm hxy, hx]) + refine iff_nn_ex_zero fun a ↦ ih fun x hx ↦ ?_ + cases Nat.decEq x y with + | isTrue heq => + subst heq + exact (envUpdate_self v₁ x a).trans (envUpdate_self v₂ x a).symm + | isFalse hxy => + have hu₁ := envUpdate_of_ne v₁ hxy a + have hu₂ := envUpdate_of_ne v₂ hxy a + refine hu₁.trans ((h x ?_).trans hu₂.symm) + change (!(y == x) && _) = true + rw [nat_beq_eq_false (Ne.symm hxy)] + exact hx private theorem nHolds_update_of_hasFree_false (v : ℕ → ℕ) {x : ℕ} (a : ℕ) {φ : PAFormula} (hx : φ.hasFree x = false) : - PAFormula.NHolds (Function.update v x a) φ ↔ PAFormula.NHolds v φ := by - refine nHolds_congr fun y hy ↦ ?_ - have hne : y ≠ x := fun h ↦ by subst h; rw [hx] at hy; cases hy - exact Function.update_of_ne hne a v + PAFormula.NHolds (envUpdate v x a) φ ↔ PAFormula.NHolds v φ := + nHolds_congr fun y hy ↦ + have hne : y ≠ x := fun h ↦ by subst h; rw [hx] at hy; exact Bool.noConfusion hy + envUpdate_of_ne v hne a private theorem nHolds_update_idem (v : ℕ → ℕ) (x a b : ℕ) (φ : PAFormula) : - PAFormula.NHolds (Function.update (Function.update v x a) x b) φ ↔ - PAFormula.NHolds (Function.update v x b) φ := by - refine nHolds_congr fun z _ ↦ ?_ - rcases Decidable.eq_or_ne z x with rfl | hzx - · simp only [Function.update_self] - · simp only [Function.update_of_ne hzx] + PAFormula.NHolds (envUpdate (envUpdate v x a) x b) φ ↔ + PAFormula.NHolds (envUpdate v x b) φ := + nHolds_congr fun z _ ↦ by + cases Nat.decEq z x with + | isTrue h => + subst h + exact (envUpdate_self (envUpdate v z a) z b).trans (envUpdate_self v z b).symm + | isFalse hzx => + exact (envUpdate_of_ne (envUpdate v x a) hzx b).trans + ((envUpdate_of_ne v hzx a).trans (envUpdate_of_ne v hzx b).symm) private theorem nHolds_update_comm (v : ℕ → ℕ) {x y : ℕ} (hxy : x ≠ y) (a b : ℕ) (φ : PAFormula) : - PAFormula.NHolds (Function.update (Function.update v x a) y b) φ ↔ - PAFormula.NHolds (Function.update (Function.update v y b) x a) φ := by - refine nHolds_congr fun z _ ↦ ?_ - rcases Decidable.eq_or_ne z y with rfl | hzy - · rw [Function.update_self, Function.update_of_ne hxy.symm, Function.update_self] - · rw [Function.update_of_ne hzy] - rcases Decidable.eq_or_ne z x with rfl | hzx - · rw [Function.update_self, Function.update_self] - · rw [Function.update_of_ne hzx, Function.update_of_ne hzx, Function.update_of_ne hzy] + PAFormula.NHolds (envUpdate (envUpdate v x a) y b) φ ↔ + PAFormula.NHolds (envUpdate (envUpdate v y b) x a) φ := + nHolds_congr fun z _ ↦ by + cases Nat.decEq z y with + | isTrue hzy => + subst hzy + exact (envUpdate_self (envUpdate v x a) z b).trans + ((envUpdate_of_ne (envUpdate v z b) (Ne.symm hxy) a).trans + (envUpdate_self v z b)).symm + | isFalse hzy => + cases Nat.decEq z x with + | isTrue hzx => + subst hzx + exact (envUpdate_of_ne (envUpdate v z a) hzy b).trans + ((envUpdate_self v z a).trans (envUpdate_self (envUpdate v y b) z a).symm) + | isFalse hzx => + exact (envUpdate_of_ne (envUpdate v x a) hzy b).trans + ((envUpdate_of_ne v hzx a).trans + ((envUpdate_of_ne (envUpdate v y b) hzx a).trans (envUpdate_of_ne v hzy b)).symm) private theorem nHolds_subst (v : ℕ → ℕ) {x : ℕ} {s : PATerm} {φ : PAFormula} (hf : φ.freeFor x s = true) : PAFormula.NHolds v (φ.subst x s) ↔ - PAFormula.NHolds (Function.update v x (s.eval v)) φ := by + PAFormula.NHolds (envUpdate v x (s.eval v)) φ := by induction φ generalizing v with - | bot => exact Iff.rfl + | bot => exact ⟨id, id⟩ | eq t₁ t₂ => - simp only [PAFormula.subst, PAFormula.NHolds, ← evalIn_nat_eq, evalIn_subst] + have e₁ := eval_subst_zero v x s t₁ + have e₂ := eval_subst_zero v x s t₂ + exact ⟨fun he ↦ e₁.symm.trans (he.trans e₂), fun he ↦ e₁.trans (he.trans e₂.symm)⟩ | and _ _ ih₁ ih₂ => - simp only [PAFormula.freeFor, Bool.and_eq_true] at hf - exact and_congr (ih₁ v hf.1) (ih₂ v hf.2) + exact iff_and_zero (ih₁ v (bool_and_left hf)) (ih₂ v (bool_and_right hf)) | or _ _ ih₁ ih₂ => - simp only [PAFormula.freeFor, Bool.and_eq_true] at hf - exact not_congr (not_congr (or_congr (ih₁ v hf.1) (ih₂ v hf.2))) + exact iff_nn_or_zero (ih₁ v (bool_and_left hf)) (ih₂ v (bool_and_right hf)) | imp _ _ ih₁ ih₂ => - simp only [PAFormula.freeFor, Bool.and_eq_true] at hf - exact imp_congr (ih₁ v hf.1) (ih₂ v hf.2) + exact iff_imp_zero (ih₁ v (bool_and_left hf)) (ih₂ v (bool_and_right hf)) | all y φ ih => - simp only [PAFormula.subst] - rcases Decidable.eq_or_ne y x with rfl | hxy - · simp only [beq_self_eq_true, ↓reduceIte, PAFormula.NHolds] - refine forall_congr' fun a ↦ ?_ - exact (nHolds_update_idem v y (s.eval v) a φ).symm - · have hb : (y == x) = false := beq_eq_false_iff_ne.mpr hxy - simp only [hb, Bool.false_eq_true, ↓reduceIte, PAFormula.NHolds] - simp only [PAFormula.freeFor, hb, Bool.false_or, Bool.and_eq_true, - Bool.or_eq_true, Bool.not_eq_true'] at hf - rcases hf with ⟨hno | hsy, hf'⟩ - · refine forall_congr' fun a ↦ ?_ - rw [subst_eq_self_of_hasFree_false s hno, - nHolds_update_comm v (Ne.symm hxy), - nHolds_update_of_hasFree_false _ _ hno] - · refine forall_congr' fun a ↦ ?_ - have hev : s.eval (Function.update v y a) = s.eval v := by - rw [← evalIn_nat_eq, ← evalIn_nat_eq] - exact evalIn_update_of_hasVar_false v a hsy - rw [ih (Function.update v y a) hf', hev, nHolds_update_comm v hxy] + cases Nat.decEq y x with + | isTrue heq => + subst heq + have hsub : (PAFormula.all y φ).subst y s = PAFormula.all y φ := by + dsimp only [PAFormula.subst] + rw [nat_beq_refl] + rfl + rw [hsub] + exact iff_all_zero fun a ↦ + have hid := nHolds_update_idem v y (s.eval v) a φ + ⟨hid.mpr, hid.mp⟩ + | isFalse hxy => + have hb : (y == x) = false := nat_beq_eq_false hxy + have hsub : (PAFormula.all y φ).subst x s = PAFormula.all y (φ.subst x s) := by + dsimp only [PAFormula.subst] + rw [hb] + rfl + rw [hsub] + have hconj : ((!φ.hasFree x || !s.hasVar y) && φ.freeFor x s) = true := by + change ((y == x) || ((!φ.hasFree x || !s.hasVar y) && φ.freeFor x s)) = true at hf + rw [hb] at hf + exact hf + have hf' : φ.freeFor x s = true := bool_and_right hconj + rcases bool_or_cases (bool_and_left hconj) with hno | hsy + · have hno' : φ.hasFree x = false := bool_not_eq_true_iff hno + refine iff_all_zero fun a ↦ ?_ + rw [subst_eq_self_zero s hno'] + have h₁ := nHolds_update_of_hasFree_false (envUpdate v y a) (s.eval v) hno' + have h₂ := nHolds_update_comm v hxy a (s.eval v) φ + exact ⟨fun u ↦ h₂.mp (h₁.mpr u), fun w ↦ h₁.mp (h₂.mpr w)⟩ + · have hsy' : s.hasVar y = false := bool_not_eq_true_iff hsy + refine iff_all_zero fun a ↦ ?_ + have hev : s.eval (envUpdate v y a) = s.eval v := + eval_update_of_hasVar_false_zero v a hsy' + have hstep := ih (envUpdate v y a) hf' + rw [hev] at hstep + have hcomm := nHolds_update_comm v hxy a (s.eval v) φ + exact ⟨fun u ↦ hcomm.mp (hstep.mp u), fun w ↦ hstep.mpr (hcomm.mpr w)⟩ | ex y φ ih => - simp only [PAFormula.subst] - rcases Decidable.eq_or_ne y x with rfl | hxy - · simp only [beq_self_eq_true, ↓reduceIte, PAFormula.NHolds] - refine not_congr (not_congr (exists_congr fun a ↦ ?_)) - exact (nHolds_update_idem v y (s.eval v) a φ).symm - · have hb : (y == x) = false := beq_eq_false_iff_ne.mpr hxy - simp only [hb, Bool.false_eq_true, ↓reduceIte, PAFormula.NHolds] - simp only [PAFormula.freeFor, hb, Bool.false_or, Bool.and_eq_true, - Bool.or_eq_true, Bool.not_eq_true'] at hf - rcases hf with ⟨hno | hsy, hf'⟩ - · refine not_congr (not_congr (exists_congr fun a ↦ ?_)) - rw [subst_eq_self_of_hasFree_false s hno, - nHolds_update_comm v (Ne.symm hxy), - nHolds_update_of_hasFree_false _ _ hno] - · refine not_congr (not_congr (exists_congr fun a ↦ ?_)) - have hev : s.eval (Function.update v y a) = s.eval v := by - rw [← evalIn_nat_eq, ← evalIn_nat_eq] - exact evalIn_update_of_hasVar_false v a hsy - rw [ih (Function.update v y a) hf', hev, nHolds_update_comm v hxy] - -/-- Constructive soundness of `PAProvable` under `NHolds` (zero `Classical.choice`). -/ + cases Nat.decEq y x with + | isTrue heq => + subst heq + have hsub : (PAFormula.ex y φ).subst y s = PAFormula.ex y φ := by + dsimp only [PAFormula.subst] + rw [nat_beq_refl] + rfl + rw [hsub] + exact iff_nn_ex_zero fun a ↦ + have hid := nHolds_update_idem v y (s.eval v) a φ + ⟨hid.mpr, hid.mp⟩ + | isFalse hxy => + have hb : (y == x) = false := nat_beq_eq_false hxy + have hsub : (PAFormula.ex y φ).subst x s = PAFormula.ex y (φ.subst x s) := by + dsimp only [PAFormula.subst] + rw [hb] + rfl + rw [hsub] + have hconj : ((!φ.hasFree x || !s.hasVar y) && φ.freeFor x s) = true := by + change ((y == x) || ((!φ.hasFree x || !s.hasVar y) && φ.freeFor x s)) = true at hf + rw [hb] at hf + exact hf + have hf' : φ.freeFor x s = true := bool_and_right hconj + rcases bool_or_cases (bool_and_left hconj) with hno | hsy + · have hno' : φ.hasFree x = false := bool_not_eq_true_iff hno + refine iff_nn_ex_zero fun a ↦ ?_ + rw [subst_eq_self_zero s hno'] + have h₁ := nHolds_update_of_hasFree_false (envUpdate v y a) (s.eval v) hno' + have h₂ := nHolds_update_comm v hxy a (s.eval v) φ + exact ⟨fun u ↦ h₂.mp (h₁.mpr u), fun w ↦ h₁.mp (h₂.mpr w)⟩ + · have hsy' : s.hasVar y = false := bool_not_eq_true_iff hsy + refine iff_nn_ex_zero fun a ↦ ?_ + have hev : s.eval (envUpdate v y a) = s.eval v := + eval_update_of_hasVar_false_zero v a hsy' + have hstep := ih (envUpdate v y a) hf' + rw [hev] at hstep + have hcomm := nHolds_update_comm v hxy a (s.eval v) φ + exact ⟨fun u ↦ hcomm.mp (hstep.mp u), fun w ↦ hstep.mpr (hcomm.mpr w)⟩ + +/-- Soundness of `PAProvable` under Gödel–Gentzen negative satisfaction `NHolds` (zero axioms). -/ theorem paProvable_nSound {φ : PAFormula} (h : PAProvable φ) (v : ℕ → ℕ) : PAFormula.NHolds v φ := by induction h generalizing v with | mp _ _ ihφ ihimp => exact ihimp v (ihφ v) - | gen x _ ih => intro a; exact ih (Function.update v x a) + | gen x _ ih => intro a; exact ih (envUpdate v x a) | imp_k _ _ => intro h₁ _; exact h₁ | imp_s _ _ _ => intro h₁ h₂ h₃; exact h₁ h₃ (h₂ h₃) | dne φ => exact nHolds_stable φ v @@ -591,7 +892,7 @@ theorem paProvable_nSound {φ : PAFormula} (h : PAProvable φ) (v : ℕ → ℕ) have h1 := (nHolds_subst v hs).mp hφs rw [heq] at h1 exact (nHolds_subst v ht).mpr h1 - | pa_zero_ne_succ => exact Nat.succ_ne_zero (v 0) + | pa_zero_ne_succ => exact fun h ↦ Nat.noConfusion h | pa_succ_inj => exact Nat.succ.inj | pa_add_zero => exact Nat.add_zero (v 0) | pa_add_succ => exact Nat.add_succ (v 0) (v 1) @@ -599,21 +900,23 @@ theorem paProvable_nSound {φ : PAFormula} (h : PAProvable φ) (v : ℕ → ℕ) | pa_mul_succ => exact Nat.mul_succ (v 0) (v 1) | pa_ind x φ => intro h0 hs a - have h0' : PAFormula.NHolds (Function.update v x 0) φ := - (nHolds_subst v (freeFor_zero x φ)).mp h0 - have hs' : ∀ b : ℕ, PAFormula.NHolds (Function.update v x b) φ → - PAFormula.NHolds (Function.update v x (b + 1)) φ := by + have h0' : PAFormula.NHolds (envUpdate v x 0) φ := + (nHolds_subst v (freeFor_zero_zero x φ)).mp h0 + have hs' : ∀ b : ℕ, PAFormula.NHolds (envUpdate v x b) φ → + PAFormula.NHolds (envUpdate v x (b + 1)) φ := by intro b hb have hstep := hs b hb - have hsub := (nHolds_subst (Function.update v x b) (freeFor_succ_self x φ)).mp hstep - simp only [PATerm.eval, Function.update_self] at hsub + have hsub := (nHolds_subst (envUpdate v x b) (freeFor_succ_self_zero x φ)).mp hstep + have hev : (PATerm.succ (.var x)).eval (envUpdate v x b) = b + 1 := + congrArg (· + 1) (envUpdate_self v x b) + rw [hev] at hsub exact (nHolds_update_idem v x b (b + 1) φ).mp hsub induction a with | zero => exact h0' | succ a ih => exact hs' a ih -/-- Consistency of first-order Peano Arithmetic (`¬ PAProvable .bot`), proved constructively -without `Classical.choice`. -/ +/-- Consistency of first-order Peano Arithmetic (`¬ PAProvable .bot`), proved with **zero axioms** +(`[]`) in Lean's Calculus of Inductive Constructions. -/ theorem not_paProvable_false : ¬ PAProvable .bot := fun h ↦ paProvable_nSound h (fun _ ↦ 0) diff --git a/Cryptids/Semantics/README.md b/Cryptids/Semantics/README.md index dab7e202..c3e1a0dd 100644 --- a/Cryptids/Semantics/README.md +++ b/Cryptids/Semantics/README.md @@ -359,15 +359,17 @@ Care is required when interpreting a Lean theorem of type `Halts M ↔ ZFInconsi 1. **Why classical Lean vacuously satisfies `Halts M ↔ ZFInconsistent` for any non-halting machine:** Lean's type theory is proof-theoretically stronger than first-order $\mathrm{ZF}$. Using `Classical.choice` and Mathlib's cumulative hierarchy `ZFSet.{0} : Type 1`, [`Zf/Soundness.lean`](./Zf/Soundness.lean) proves `not_zfInconsistent : ¬ ZFInconsistent` inside Lean itself (and deduces `not_halts_zf393` and `not_halts_candidate`). Moreover, as noted by Elliot Glazer and formalized in Lean 4 by Mario Carneiro ([`digama0/ConZF`](https://github.com/digama0/ConZF), *"CIC + EM $\vdash$ Con(ZF): the consistency of ZF in type theory with excluded middle and no choice"*), Lean's Calculus of Inductive Constructions (`CIC`) plus Excluded Middle alone (or `¬¬ ∀ p : Prop, p ∨ ¬p`, via large elimination of `Acc`) proves $\operatorname{Con}(\mathrm{ZF})$ without `Classical.choice`, `propext`, or `Quot.sound`. Consequently, if `Classical.choice` (which yields Excluded Middle together with `propext` and `Quot.sound` by Diaconescu's theorem) or `not_zfInconsistent` is allowed, **any** provably non-halting machine—such as the 1-state machine `0R0 0R0` that moves right forever—vacuously satisfies the bare material biconditional `Halts M ↔ ZFInconsistent` (`False ↔ False`). -2. **Constructive proof-search equivalence (`["propext", "Quot.sound"]` only, enforced by `comparator`):** - To rule out classical shortcuts through `Classical.choice`, `Classical.em`, or `not_zfInconsistent`, `ConjectureMachines.ListBlank` quotients half-tapes directly via Lean's primitive `Quot (@Turing.BlankRel Γ _)` (`Challenge.lean`, `Cryptids/Machines.lean`), and **the direct state-reduction halting equivalences (`Goldbach21.candidate_equivalent`, `Zf380.candidate_equivalent`, `Riemann104.candidate_equivalent`), the `ErdosTernary14.candidate_equivalent` reduction, all five `candidate_fewer_states` theorems (including `Riemann95.candidate_fewer_states`; `Riemann95.candidate_equivalent` uses `Classical.choice`), and all three ZF machine-to-proof-search equivalences (`Zf393.halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, `Semantics.Zf.halts_zf432_iff_wadeZFInconsistent`)** are proved **constructively in Lean** using only `["propext", "Quot.sound"]`—with **zero `Classical.choice`, zero Excluded Middle, and zero Markov's Principle**: +2. **Zero-axiom specification & constructive proof-search equivalence (enforced by `comparator`):** + To eliminate quotient axioms from the specification layer itself and rule out classical shortcuts through `Classical.choice`, `Classical.em`, or `not_zfInconsistent`: + - **Quotient-free, zero-axiom specification (`comparator/zero_axioms.json`, `permitted_axioms = []`):** `ConjectureMachines.ListBlank` represents half-tapes concretely as canonical blank-trimmed lists (`structure ListBlank (Γ : Type*) [Inhabited Γ] where ofTrimmed ::`, `Challenge.lean`, `Cryptids/Machines.lean`), so `ListBlank`, `Tape`, `Halts`, `Machine`, `BundledMachine`, `PAProvable`, all five `candidate_fewer_states` theorems, and syntactic `PA` consistency (`Semantics.PA.not_paProvable_false`) depend on **zero axioms (`[]`)**. + - **Constructive equivalences (`comparator/constructive.json`, `permitted_axioms = ["propext", "Quot.sound"]`):** **All five** state-reduction halting equivalences (`Goldbach21.candidate_equivalent`, `Zf380.candidate_equivalent`, `Riemann104.candidate_equivalent`, `Riemann95.candidate_equivalent`, `ErdosTernary14.candidate_equivalent`), **all three** ZF machine-to-proof-search equivalences (`Zf393.halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, `Semantics.Zf.halts_zf432_iff_wadeZFInconsistent`), and $\Sigma_1^0$ `PA` standard-model adequacy (`paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`) are proved **constructively in Lean** with **zero `Classical.choice`, zero Excluded Middle, and zero Markov's Principle**: - **Forward completeness (`ZFInconsistent → Halts M`):** Given a finite derivation tree `d : ZFProvable (zfMem 0 0)`, structural induction extracts an explicit step count `s` and halting configuration `c` with `nSteps M s init = some c ∧ step M c = none` (no `by_contra` / unbounded search). - **Backward soundness (`Halts M → ZFInconsistent`):** Given `h : Halts M`, constructive induction along `StateTransition.evalInduction'` extracts the finite execution trace from `init` and decodes a valid `ZFProvable (zfMem 0 0)` derivation. - - **Comparator gate:** [`comparator/constructive.json`](../../comparator/constructive.json), [`comparator/zf_380.json`](../../comparator/zf_380.json), [`comparator/goldbach_21.json`](../../comparator/goldbach_21.json), and [`comparator/riemann_104.json`](../../comparator/riemann_104.json) enforce `"permitted_axioms": ["propext", "Quot.sound"]` in CI, automatically rejecting any proof that invokes `Classical.choice` (including `not_zfInconsistent` in [`Zf/Soundness.lean`](./Zf/Soundness.lean) or `Classical.em` + [`digama0/ConZF`](https://github.com/digama0/ConZF)). + - **Comparator gate:** [`comparator/zero_axioms.json`](../../comparator/zero_axioms.json) (`[]`), [`comparator/constructive.json`](../../comparator/constructive.json), [`comparator/zf_380.json`](../../comparator/zf_380.json), [`comparator/goldbach_21.json`](../../comparator/goldbach_21.json), [`comparator/riemann_104.json`](../../comparator/riemann_104.json), and [`comparator/riemann_95_reduction.json`](../../comparator/riemann_95_reduction.json) (`["propext", "Quot.sound"]`) enforce these axiom bounds in CI, automatically rejecting any proof that invokes `Classical.choice` (including `not_zfInconsistent` in [`Zf/Soundness.lean`](./Zf/Soundness.lean) or `Classical.em` + [`digama0/ConZF`](https://github.com/digama0/ConZF)). 3. **Metamathematical scope — Lean's type theory, `PA`/`ZF` internalization, and `ZF`-independence:** Care must also be taken not to conflate a constructive Lean theorem `Halts M ↔ ZFInconsistent` with a formal proof of $\mathrm{ZF}$-independence: - **Strength of constructive Lean (`CIC` vs. `PA`/`ZF`):** Even without `Classical.choice` or Excluded Middle, Lean's Calculus of Inductive Constructions provides constructions absent from first-order $\mathrm{PA}$ and $\mathrm{ZF}$—an impredicative `Prop`, inductive families (`ZFProvable`, `Acc`, `PSet`), and a predicative universe hierarchy `Type u` (already strong enough to validate Zermelo set theory, and whether axiom-free `CIC` itself proves $\operatorname{Con}(\mathrm{ZF})$ remains an open question; see [`digama0/ConZF`](https://github.com/digama0/ConZF)). An axiom check in Lean therefore blocks classical `Con(ZF)` shortcuts, rather than restricting reasoning to $\mathrm{PA}$ or $\mathrm{ZF}$. - - **Internalizing the reduction inside first-order `PA` (`PAProvable`):** Our constructive Lean proofs of `ZFInconsistent → Halts M` and `Halts M → ZFInconsistent` establish a meta-level correspondence in Lean. To formulate and verify object-level provability inside weak first-order arithmetic—whose consistency strength is strictly below $\mathrm{ZF}$, so it cannot trivialize $\operatorname{Con}(\mathrm{ZF})$—Section 6 ([`Cryptids/Semantics/PA/`](./PA/)) deeply embeds first-order Peano Arithmetic (`PATerm`, `PAFormula`, `PAProvable`), proves constructive consistency (`not_paProvable_false : ¬ PAProvable .bot`), proves constructive standard-model adequacy of the $\Sigma_1^0$ encodings `paHalts M` and `paZFInconsistent` (`paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`), and internalizes the entire Layer 1–3 verification of `zf_393` and `zf_380` inside `PAProvable` (`paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, and `paProvable_halts_zf380_iff_zfInconsistent`; `zf_432` is not yet internalized in `PA`). Note why these three `PAProvable` theorems live in the classical `comparator` gates (`pa_semantics.json`, `all.json`) rather than `constructive.json`: instead of constructing raw Hilbert proof trees directly, we carry out the argument in an arbitrary first-order model `[PAModel M]` via `PAM.ind1` and reflect to syntactic `PAProvable` via Gödel–Henkin completeness (`paProvable_iff_holdsIn_all_models`), whose Henkin–Lindenbaum maximal consistent extension uses `Classical.choice`. Using `Classical.choice` in the meta-proof does not create a `Con(ZF)` shortcut here because the conclusion `PAProvable ((paHalts M).iff paZFInconsistent)` asserts syntactic derivability inside weak first-order `PA` (which cannot prove `¬ paZFInconsistent` if `ZF` is consistent). + - **Internalizing the reduction inside first-order `PA` (`PAProvable`):** Our constructive Lean proofs of `ZFInconsistent → Halts M` and `Halts M → ZFInconsistent` establish a meta-level correspondence in Lean. To formulate and verify object-level provability inside weak first-order arithmetic—whose consistency strength is strictly below $\mathrm{ZF}$, so it cannot trivialize $\operatorname{Con}(\mathrm{ZF})$—Section 6 ([`Cryptids/Semantics/PA/`](./PA/)) deeply embeds first-order Peano Arithmetic (`PATerm`, `PAFormula`, `PAProvable`), proves zero-axiom syntactic consistency (`not_paProvable_false : ¬ PAProvable .bot`), proves constructive standard-model adequacy of the $\Sigma_1^0$ encodings `paHalts M` and `paZFInconsistent` (`paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`), and internalizes the entire Layer 1–3 verification of `zf_393` and `zf_380` inside `PAProvable` (`paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, and `paProvable_halts_zf380_iff_zfInconsistent`; `zf_432` is not yet internalized in `PA`). Note why these three `PAProvable` theorems live in the classical `comparator` gates (`pa_semantics.json`, `all.json`) rather than `constructive.json`: instead of constructing raw Hilbert proof trees directly, we carry out the argument in an arbitrary first-order model `[PAModel M]` via `PAM.ind1` and reflect to syntactic `PAProvable` via Gödel–Henkin completeness (`paProvable_iff_holdsIn_all_models`), whose Henkin–Lindenbaum maximal consistent extension uses `Classical.choice`. Using `Classical.choice` in the meta-proof does not create a `Con(ZF)` shortcut here because the conclusion `PAProvable ((paHalts M).iff paZFInconsistent)` asserts syntactic derivability inside weak first-order `PA` (which cannot prove `¬ paZFInconsistent` if `ZF` is consistent). - **Assumptions required for both directions of `ZF`-independence:** Even once $\mathrm{ZF} \vdash \ulcorner \operatorname{Halts}(M) \leftrightarrow \neg\operatorname{Con}(\mathrm{ZF}) \urcorner$ is established, $\operatorname{Con}(\mathrm{ZF})$ alone yields only **one** direction of independence: $\mathrm{ZF} \nvdash \neg\ulcorner\operatorname{Halts}(M)\urcorner$ (by Gödel's Second Incompleteness Theorem). Ruling out the **other** direction, $\mathrm{ZF} \vdash \ulcorner\operatorname{Halts}(M)\urcorner$ (since $\mathrm{ZF} + \neg\operatorname{Con}(\mathrm{ZF})$ can still be consistent when $\mathrm{ZF}$ is consistent), requires $\operatorname{Con}(\mathrm{ZF} + \operatorname{Con}(\mathrm{ZF}))$—for example $\Sigma_1$-soundness ($1$-consistency) of $\mathrm{ZF}$, as assumed in Yedidia & Aaronson (2016). ### Formal Discovery of the `B6a` Register-Restoration Bug in `zf_432_wade.tm` @@ -558,8 +560,9 @@ theorem paProvable_halts_zf380_iff_zfInconsistent : 1. **Models, Classical Soundness, & Constructive Consistency ([`PA/Syntax.lean`](./PA/Syntax.lean))**: Defines first-order $\mathcal{L}_{\mathrm{PA}}$-structures (`PAStructure M`) and Peano models (`PAModel M`), proves soundness of `PAProvable` in any `[PAModel M]` (`paProvable_sound`, - specializing to `paProvable_sound_nat` on `ℕ`), and proves `not_paProvable_false` constructively - (zero `Classical.choice`, audited in [`comparator/constructive.json`](../../comparator/constructive.json)) + specializing to `paProvable_sound_nat` on `ℕ`), and proves `not_paProvable_false` with **zero + axioms (`[]`)** (audited in [`comparator/zero_axioms.json`](../../comparator/zero_axioms.json) + and [`comparator/constructive.json`](../../comparator/constructive.json)) via the Gödel–Gentzen negative translation (`PAFormula.NHolds`, translating `.or` and `.ex` via double negation so `PAProvable.dne` is constructively valid on `ℕ`). 2. **Constructive $\Sigma_1^0$ Standard-Model Adequacy ([`PA/Adequacy.lean`](./PA/Adequacy.lean))**: diff --git a/Cryptids/Semantics/Riemann/Gadgets.lean b/Cryptids/Semantics/Riemann/Gadgets.lean index e86a6d38..218e0ec1 100644 --- a/Cryptids/Semantics/Riemann/Gadgets.lean +++ b/Cryptids/Semantics/Riemann/Gadgets.lean @@ -718,7 +718,7 @@ theorem mem_eval_iff_nSteps {K : ℕ} [NeZero K] {M : Machine K 2} {c₀ ch : Cf theorem mk_append_replicate_zero (l : List (Fin 2)) (n : ℕ) : ListBlank.mk (l ++ List.replicate n 0) = ListBlank.mk l := - Quot.sound (Or.inr ⟨n, rfl⟩) + ListBlank.mk_append_replicate_default l n theorem default_eq_mk_nil : (default : ListBlank (Fin 2)) = ListBlank.mk [] := rfl diff --git a/Cryptids/Semantics/Riemann120/Analytic.lean b/Cryptids/Semantics/Riemann120/Analytic.lean index 469ca1a6..0c179d13 100644 --- a/Cryptids/Semantics/Riemann120/Analytic.lean +++ b/Cryptids/Semantics/Riemann120/Analytic.lean @@ -50,6 +50,16 @@ abbrev primorial : ℕ → ℕ := ConjectureMachines.Riemann120.primorial ## 2. Arithmetic & Logarithmic Lemmas -/ +theorem isPrimeBool_eq_true_iff (p : ℕ) : + ConjectureMachines.Riemann120.isPrimeBool p = true ↔ Nat.Prime p := by + simp only [ConjectureMachines.Riemann120.isPrimeBool, Bool.and_eq_true, decide_eq_true_eq, + List.all_eq_true, List.mem_range, Bool.or_eq_true, bne_iff_ne, ne_eq, + ← Nat.dvd_iff_mod_eq_zero] + rw [Nat.prime_def_lt'] + exact ⟨fun ⟨hp, hall⟩ => ⟨hp, fun m hm hmp hdiv => (hall m hmp).resolve_left (by omega) hdiv⟩, + fun ⟨hp, hall⟩ => ⟨hp, fun d hdp => + if hd2 : d < 2 then Or.inl hd2 else Or.inr (hall d (by omega) hdp)⟩⟩ + theorem primorial_eq_root_primorial (n : ℕ) : primorial n = _root_.primorial n := by induction n with | zero => rfl @@ -57,10 +67,13 @@ theorem primorial_eq_root_primorial (n : ℕ) : primorial n = _root_.primorial n dsimp only [primorial] at ih ⊢ rw [ConjectureMachines.Riemann120.primorial, ih] conv_rhs => rw [_root_.primorial, Finset.range_add_one, Finset.filter_insert] - split_ifs with hp - · rw [Finset.prod_insert (by simp)] - rfl - · rfl + by_cases hp : Nat.Prime (n + 1) + · have hpb : ConjectureMachines.Riemann120.isPrimeBool (n + 1) = true := + (isPrimeBool_eq_true_iff (n + 1)).mpr hp + simp [hp, hpb, _root_.primorial] + · have hpb : ConjectureMachines.Riemann120.isPrimeBool (n + 1) = false := + Bool.eq_false_iff.mpr fun h => hp ((isPrimeBool_eq_true_iff (n + 1)).mp h) + simp [hp, hpb, _root_.primorial] theorem primorial_pos (n : ℕ) : 0 < primorial n := by rw [primorial_eq_root_primorial] diff --git a/Cryptids/Semantics/Riemann120/Backend.lean b/Cryptids/Semantics/Riemann120/Backend.lean index 0802b364..08ae2c3e 100644 --- a/Cryptids/Semantics/Riemann120/Backend.lean +++ b/Cryptids/Semantics/Riemann120/Backend.lean @@ -3609,11 +3609,13 @@ theorem rhReg_eval_dom_of_tm_halt (isEd : Bool) : · obtain ⟨hv', hregs', padTotal', hpad', s, hs_pos, extra', hsteps⟩ := hsim.2 c'.stack c'.regs hs have hle : s ≤ N := by - by_contra hlt - have hgt : 1 ≤ s - N := by omega - have hsplit : s = N + (s - N) := by omega - rw [hsplit, nSteps_add, hN, Option.bind_some, nSteps_of_halt hnone hgt] at hsteps - cases hsteps + by_cases h : s ≤ N + · exact h + · exfalso + have hgt : 1 ≤ s - N := by omega + have hsplit : s = N + (s - N) := by omega + rw [hsplit, nSteps_add, hN, Option.bind_some, nSteps_of_halt hnone hgt] at hsteps + cases hsteps have hsplit : N = s + (N - s) := by omega rw [hsplit, nSteps_add, hsteps, Option.bind_some] at hN have hDom' := ih (N - s) (by omega) hpad' hv' hregs' hN hnone diff --git a/Cryptids/Semantics/Riemann120/Program.lean b/Cryptids/Semantics/Riemann120/Program.lean index 16d583f5..09e2e039 100644 --- a/Cryptids/Semantics/Riemann120/Program.lean +++ b/Cryptids/Semantics/Riemann120/Program.lean @@ -49,7 +49,8 @@ namespace ConjectureMachines.Riemann120.Layer2 open Turing (Dir) open StateTransition open ConjectureMachines.Riemann120 - (rh121Trans primorial shuniaProd offsetDigits shuniaDeficit quarterClock ShuniaCounterexample) + (rh121Trans isPrimeBool primorial shuniaProd offsetDigits shuniaDeficit quarterClock + ShuniaCounterexample) set_option linter.style.setOption false set_option linter.flexible false @@ -94,8 +95,10 @@ theorem mem_dagExactPaths_of_walkInternal {P : List (Fin 2)} {q q' : Fin 121} · simp only [hcond, ↓reduceIte] at h have hmem := ih h simp only [List.length_cons, dagExactPaths, hi, ↓reduceIte, List.mem_flatMap] - refine ⟨b, by fin_cases b <;> simp, ?_⟩ - simp [htr, hcond, hmem] + refine ⟨b, ?_, ?_⟩ + · rcases ConjectureMachines.Semantics.Riemann.Layer1.fin2_cases b with rfl | rfl <;> + simp + · simp [htr, hcond, hmem] · simp [hcond] at h · simp [hi] at h @@ -303,42 +306,80 @@ theorem primorial_pos (n : ℕ) : 0 < primorial n := by | zero => decide | succ n ih => unfold primorial - split - · exact Nat.mul_pos (Nat.succ_pos n) ih + cases isPrimeBool (n + 1) <;> simp only [Bool.false_eq_true, ↓reduceIte] · exact ih + · exact Nat.mul_pos (Nat.succ_pos n) ih theorem shuniaProd_pos (n : ℕ) : 0 < shuniaProd n := Nat.mul_pos (Nat.factorial_pos n) (primorial_pos n) -theorem prime_le_of_dvd_primorial {p m : ℕ} (hp : p.Prime) : +private theorem isPrimeBool_two_le {p : ℕ} (hp : isPrimeBool p = true) : 2 ≤ p := by + simp only [isPrimeBool, Bool.and_eq_true, decide_eq_true_eq] at hp + exact hp.1 + +private theorem isPrimeBool_not_dvd {p d : ℕ} (hp : isPrimeBool p = true) + (hd2 : 2 ≤ d) (hdp : d < p) : ¬ (d ∣ p) := by + simp only [isPrimeBool, Bool.and_eq_true, decide_eq_true_eq, List.all_eq_true, + List.mem_range, Bool.or_eq_true, bne_iff_ne, ne_eq, ← Nat.dvd_iff_mod_eq_zero] at hp + rcases hp.2 d hdp with hlt | hndvd + · omega + · exact hndvd + +private theorem isPrimeBool_dvd_mul {p a b : ℕ} (hp : isPrimeBool p = true) + (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := by + have hp2 := isPrimeBool_two_le hp + let g := Nat.gcd p a + have hgp : g ∣ p := Nat.gcd_dvd_left p a + have hga : g ∣ a := Nat.gcd_dvd_right p a + have hg_pos : 0 < g := Nat.pos_of_dvd_of_pos hgp (by omega) + have hg_le : g ≤ p := Nat.le_of_dvd (by omega) hgp + by_cases hg1 : g = 1 + · exact Or.inr (Nat.Coprime.dvd_of_dvd_mul_left hg1 h) + · by_cases hgp_eq : g = p + · exact Or.inl (hgp_eq ▸ hga) + · exfalso + exact isPrimeBool_not_dvd hp (by omega) (by omega) hgp + +private theorem exists_of_all_false : ∀ (l : List ℕ) (f : ℕ → Bool), + l.all f = false → ∃ x ∈ l, f x = false + | [], _, h => by cases h + | x :: xs, f, h => by + simp only [List.all_cons] at h + cases hfx : f x + · exact ⟨x, List.mem_cons_self, hfx⟩ + · rw [hfx, Bool.true_and] at h + obtain ⟨y, hy, hfy⟩ := exists_of_all_false xs f h + exact ⟨y, List.mem_cons_of_mem x hy, hfy⟩ + +theorem prime_le_of_dvd_primorial {p m : ℕ} (hp : isPrimeBool p = true) : p ∣ primorial m → p ≤ m := by + have hp2 := isPrimeBool_two_le hp induction m with | zero => intro h have h1 : p = 1 := Nat.eq_one_of_dvd_one h - have hgt := hp.one_lt omega | succ m ih => unfold primorial - split + cases isPrimeBool (m + 1) <;> simp only [Bool.false_eq_true, ↓reduceIte] + · exact fun h => Nat.le_succ_of_le (ih h) · intro h - rcases hp.dvd_mul.mp h with h1 | h2 + rcases isPrimeBool_dvd_mul hp h with h1 | h2 · exact Nat.le_of_dvd (by omega) h1 · exact Nat.le_succ_of_le (ih h2) - · exact fun h => Nat.le_succ_of_le (ih h) -theorem prime_le_of_dvd_factorial {p m : ℕ} (hp : p.Prime) : +theorem prime_le_of_dvd_factorial {p m : ℕ} (hp : isPrimeBool p = true) : p ∣ m.factorial → p ≤ m := by + have hp2 := isPrimeBool_two_le hp induction m with | zero => intro h have h1 : p = 1 := Nat.eq_one_of_dvd_one h - have hgt := hp.one_lt omega | succ m ih => rw [Nat.factorial_succ] intro h - rcases hp.dvd_mul.mp h with h1 | h2 + rcases isPrimeBool_dvd_mul hp h with h1 | h2 · exact Nat.le_of_dvd (by omega) h1 · exact Nat.le_succ_of_le (ih h2) @@ -356,34 +397,35 @@ theorem mul_dvd_factorial_of_lt {a b n : ℕ} (ha : 1 ≤ a) (hab : a < b) (hbn /-- Lemma 2.1 of `rhtm.tex`: $J \ge 2$ is prime iff $J \nmid A_{J - 1}$. -/ theorem prime_iff_not_dvd_shuniaProd {J : ℕ} (hJ : 2 ≤ J) : - J.Prime ↔ ¬ (J ∣ shuniaProd (J - 1)) := by + isPrimeBool J = true ↔ ¬ (J ∣ shuniaProd (J - 1)) := by constructor · intro hprime hdvd unfold shuniaProd at hdvd - rcases hprime.dvd_mul.mp hdvd with hfac | hprim + rcases isPrimeBool_dvd_mul hprime hdvd with hfac | hprim · have hle := prime_le_of_dvd_factorial hprime hfac omega · have hle := prime_le_of_dvd_primorial hprime hprim omega · intro hnotdvd - if hnotprime : J.Prime then - exact hnotprime - else - exfalso + cases hpb : isPrimeBool J + · exfalso apply hnotdvd by_cases hJ4 : J = 4 · subst hJ4; decide - · have hfac_dvd : J ∣ (J - 1).factorial := by - let d := J.minFac - have hd_prime : d.Prime := Nat.minFac_prime (by omega) - have hd_gt1 : 1 < d := hd_prime.one_lt - have hd_dvd : d ∣ J := Nat.minFac_dvd J - have hd_ne : d ≠ J := fun heq => hnotprime (heq ▸ hd_prime) - have hd_le : d ≤ J := Nat.minFac_le (by omega) - have hd_lt : d < J := lt_of_le_of_ne hd_le hd_ne + · have hall_false : + ((List.range J).all fun d => decide (d < 2) || (J % d != 0)) = false := by + unfold isPrimeBool at hpb + rw [decide_eq_true hJ, Bool.true_and] at hpb + exact hpb + obtain ⟨d, hd_mem, hd_false⟩ := exists_of_all_false _ _ hall_false + have hd_lt : d < J := List.mem_range.mp hd_mem + simp only [Bool.or_eq_false_iff, decide_eq_false_iff_not, bne_eq_false_iff_eq] at hd_false + have hd_ge2 : 2 ≤ d := by omega + have hd_dvd : d ∣ J := Nat.dvd_of_mod_eq_zero hd_false.2 + have hfac_dvd : J ∣ (J - 1).factorial := by let q := J / d have hdq : d * q = J := Nat.mul_div_cancel' hd_dvd - have hq_lt : q < J := Nat.div_lt_self (by omega) hd_gt1 + have hq_lt : q < J := Nat.div_lt_self (by omega) (by omega) have hq_ge1 : 1 ≤ q := by rcases q with _ | _ · simp at hdq; omega @@ -395,10 +437,10 @@ theorem prime_iff_not_dvd_shuniaProd {J : ℕ} (hJ : 2 ≤ J) : rw [h2] at hdq omega have hd_ge3 : 3 ≤ d := by omega - have h2d_lt : 2 * d < d * d := by nlinarith + have h2d_lt : 2 * d < d * d := Nat.mul_lt_mul_of_pos_right hd_ge3 (by omega) have h2d_le : 2 * d ≤ J - 1 := by omega have hmul := mul_dvd_factorial_of_lt (a := d) (b := 2 * d) (by omega) (by omega) h2d_le - have h2J : d * (2 * d) = 2 * J := by nlinarith + have h2J : d * (2 * d) = 2 * J := by rw [← hdq, Nat.mul_left_comm] rw [h2J] at hmul exact dvd_trans (dvd_mul_left J 2) hmul · rcases lt_or_gt_of_ne heq_dq with hlt | hgt @@ -408,9 +450,10 @@ theorem prime_iff_not_dvd_shuniaProd {J : ℕ} (hJ : 2 ≤ J) : mul_dvd_factorial_of_lt hq_ge1 hgt (by omega : d ≤ J - 1) rwa [mul_comm, hdq] at hmul exact dvd_mul_of_dvd_left hfac_dvd (primorial (J - 1)) + · rfl theorem primorial_step {J : ℕ} (hJ : 2 ≤ J) : - primorial J = if J.Prime then J * primorial (J - 1) else primorial (J - 1) := by + primorial J = if isPrimeBool J then J * primorial (J - 1) else primorial (J - 1) := by rcases J with _ | n · omega · rfl @@ -427,14 +470,14 @@ theorem shuniaProd_step {J : ℕ} (hJ : 2 ≤ J) : | succ J' => simp [Nat.factorial_succ] have hp_iff := prime_iff_not_dvd_shuniaProd hJ by_cases hdvd : J ∣ shuniaProd (J - 1) - · have hnotp : ¬ J.Prime := fun hp => (hp_iff.mp hp) hdvd + · have hnotp : ¬ isPrimeBool J = true := fun hp => (hp_iff.mp hp) hdvd simp only [hdvd, ↓reduceIte] - simp only [shuniaProd, hfac, primorial_step hJ, hnotp, ↓reduceIte] - ring - · have hp : J.Prime := hp_iff.mpr hdvd + simp only [shuniaProd, hfac, primorial_step hJ, hnotp] + exact Nat.mul_assoc _ _ _ + · have hp : isPrimeBool J = true := hp_iff.mpr hdvd simp only [hdvd, ↓reduceIte] simp only [shuniaProd, hfac, primorial_step hJ, hp, ↓reduceIte] - ring + rw [Nat.pow_two, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_left_comm (J - 1).factorial J] /-! ## Section 5: Subroutine Specification (`SubEval`) & Combinators -/ @@ -455,7 +498,7 @@ theorem popContinueRev_zero_eq_dropLeadingZeros (rev : List (Fin 2)) : induction rev with | nil => rfl | cons b rest ih => - fin_cases b + rcases ConjectureMachines.Semantics.Riemann.Layer1.fin2_cases b with rfl | rfl · simp [popContinueRev, dropLeadingZeros, ih] · rfl @@ -1050,14 +1093,23 @@ theorem subEval_seed_deficit : regs.getD 3 0 + regs.getD 1 0, regs.getD 4 0 + regs.getD 1 0]) (fun _ _ => by simp) (fun regs hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hj; subst hj; simp) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ] at hj + subst hj + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.add_zero]) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp [leafReg] at hj ⊢; omega) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 70 = 4 from rfl, show leafReg 36 = 3 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + subst hj + simp only [Nat.add_assoc, Nat.add_comm 1 k]) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp [leafReg] at hj ⊢) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 70 = 4 from rfl, show leafReg 36 = 3 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + omega) /-- `dec_f` (State `96`): saturating decrement of register `f` (`regs[3]`). -/ theorem subEval_dec_f : @@ -1105,14 +1157,24 @@ theorem subEval_fold_loop : regs.getD 3 0, regs.getD 4 0 + regs.getD 1 0]) (fun _ _ => by simp) (fun regs hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hj; subst hj; simp) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ] at hj + subst hj + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.add_zero]) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hj ⊢; omega) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + subst hj + congr 1; congr 1 + · congr 1 + · omega + · congr 1; congr 1; omega) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hj ⊢) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + omega) /-- `fold` (State `102`): `(m, j, x, f, v) ↦ (m, j + v, x + j, f, 0)`. -/ theorem subEval_fold : @@ -1169,7 +1231,8 @@ theorem subEval_transform_loop : obtain ⟨sk, hsk, hsteps_k⟩ := ih (j + v) (x + j + 1) f 0 have h1 : j + v + 0 = j + v := by omega have h2 : x + j + 1 + k * (j + v + 0 + 1) + (j + v) = - x + (k + 1) * (j + v + 1) + j := by ring + x + (k + 1) * (j + v + 1) + j := by + rw [h1, Nat.succ_mul]; omega rw [h1] at h2 hsteps_k rw [h2] at hsteps_k have tail := step_rhRegNSteps hs_m (step_rhRegNSteps hs_x (step_rhRegNSteps hs_c hsteps_k)) @@ -1276,14 +1339,15 @@ theorem subEval_divide_loop : rcases v with _ | v' · simp only [List.set, List.getD_cons_zero, List.getD_cons_succ, ↓reduceIte, Nat.zero_add, Nat.add_zero] - have hN : (x + 1) * (j + 1) + k = x * (j + 1) + j + (k + 1) := by ring + have hN : (x + 1) * (j + 1) + k = x * (j + 1) + j + (k + 1) := by + rw [Nat.succ_mul]; omega rw [hN] · simp only [List.set, List.getD_cons_zero, List.getD_cons_succ, Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel] have hJ : j + 1 + v' + 1 = j + (v' + 1) + 1 := by omega have hJ2 : j + 1 + v' = j + (v' + 1) := by omega have hN : x * (j + (v' + 1) + 1) + (j + 1) + k = - x * (j + (v' + 1) + 1) + j + (k + 1) := by ring + x * (j + (v' + 1) + 1) + j + (k + 1) := by omega rw [hJ, hJ2, hN]) (fun regs k hlen hm => by rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> @@ -1305,7 +1369,7 @@ theorem subEval_divide : intro regs hlen rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.zero_add, Nat.add_zero] - have h1 : m + x = x + m := by ring + have h1 : m + x = x + m := Nat.add_comm m x have h2 : j + v + 1 - 1 = j + v := by omega have h3 : v + j = j + v := by omega simp [h1, h2, h3] @@ -1384,16 +1448,22 @@ theorem product_step_shuniaProd {K : ℕ} (hK : 2 ≤ K) (f : ℕ) : obtain ⟨m, hm⟩ := hdvd rcases m with _ | m' · simp at hm; omega - · have hB_eq : B = (K - 1) + m' * K := by nlinarith [hK1] + · have hm' : B + 1 = m' * K + K := by rw [hBA, hm, Nat.mul_succ, Nat.mul_comm] + have hB_eq : B = (K - 1) + m' * K := by omega have hdiv : B / K = m' := by rw [hB_eq, Nat.add_mul_div_right _ _ (by omega), Nat.div_eq_of_lt (by omega : K - 1 < K), Nat.zero_add] - have hK_mul_div : B / K * K + (K - 1) = B := by rw [hdiv]; nlinarith [hK1] - have hr_eq : B % K = K - 1 := by nlinarith [hK1] + have hK_mul_div : B / K * K + (K - 1) = B := by rw [hdiv, hB_eq, Nat.add_comm] + have hr_eq : B % K = K - 1 := by + rw [hB_eq, Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt (by omega)] have hv0 : K - 1 - B % K = 0 := by omega rw [ite_eq_left hv0, hK_mul_div] have hfin : B * K + (K - 1) = K * A - 1 := by - have h1 : B * K + (K - 1) + 1 = K * A := by nlinarith [hK1] + have h1 : B * K + (K - 1) + 1 = K * A := by + calc B * K + (K - 1) + 1 + _ = B * K + K := by omega + _ = (B + 1) * K := (Nat.succ_mul B K).symm + _ = K * A := by rw [hBA, Nat.mul_comm] omega rw [hfin] · rw [ite_eq_right hdvd] @@ -1402,11 +1472,20 @@ theorem product_step_shuniaProd {K : ℕ} (hK : 2 ≤ K) (f : ℕ) : have hr_eq : B % K = K - 1 := by omega apply hdvd refine ⟨B / K + 1, ?_⟩ - nlinarith [hK1] - have hqK : B / K * K + B % K = B := by nlinarith [hK1] + calc A = B + 1 := hBA.symm + _ = K * (B / K) + B % K + 1 := by rw [hdiv_mod] + _ = K * (B / K) + K := by omega + _ = K * (B / K + 1) := (Nat.mul_succ K (B / K)).symm + have hqK : B / K * K + B % K = B := by rw [Nat.mul_comm]; exact hdiv_mod rw [ite_eq_right hv_ne, hqK] have hfin : (B * K + (K - 1)) * K + (K - 1) = K ^ 2 * A - 1 := by - have h1 : (B * K + (K - 1)) * K + (K - 1) + 1 = K ^ 2 * A := by nlinarith [hK1] + have h1 : (B * K + (K - 1)) * K + (K - 1) + 1 = K ^ 2 * A := by + calc (B * K + (K - 1)) * K + (K - 1) + 1 + _ = (B * K + (K - 1)) * K + K := by omega + _ = (B * K + (K - 1) + 1) * K := (Nat.succ_mul _ K).symm + _ = (B * K + K) * K := by rw [Nat.add_assoc, hK1] + _ = (B + 1) * K * K := by rw [← Nat.succ_mul B K] + _ = K ^ 2 * A := by rw [hBA, Nat.pow_two, Nat.mul_assoc, Nat.mul_comm A (K * K)] omega rw [hfin] @@ -1546,23 +1625,41 @@ theorem subEval_halve_j : 0, regs.getD 2 0, regs.getD 3 0, regs.getD 4 0 + regs.getD 1 0 / 2]) (fun _ _ => by simp) (fun regs hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hj; subst hj; simp) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ] at hj + subst hj + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.add_zero, + Nat.zero_add, Nat.div_eq_of_lt (by decide : 1 < 2)]) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp only [leafReg, List.set, List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 4 = 0 from rfl, show leafReg 47 = 1 from rfl, + show leafReg 70 = 4 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ subst hj - rcases k with _ | _ <;> (simp; try omega)) + rcases k with _ | k' + · simp only [↓reduceIte, List.getD_cons_zero, List.getD_cons_succ] + · simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel, + List.getD_cons_zero, List.getD_cons_succ] + have h1 : m + 1 + (k' + 1) / 2 = m + (k' + 1 + 1 + 1) / 2 := by omega + have h2 : v + 1 + k' / 2 = v + (k' + 1 + 1) / 2 := by omega + rw [h1, h2]) (fun regs k hlen hj => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp only [leafReg, List.set, List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 4 = 0 from rfl, show leafReg 47 = 1 from rfl, + show leafReg 70 = 4 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hj ⊢ subst hj - rcases k with _ | _ <;> simp) + rcases k with _ | k' <;> + (simp only [↓reduceIte, Nat.succ_ne_zero, Nat.add_sub_cancel, + List.getD_cons_zero, List.getD_cons_succ] + omega)) refine (subEval_seq (q := 104) (q₀ := 110) (q₁ := 60) rfl rfl rfl rfl h110 subEval_move_v_j).congr ?_ intro regs hlen - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> - (simp at hlen ⊢; try omega) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.zero_add] /-- `halve(f)` (State `111`): `(m, j, x, f, v) ↦ (m, j, x, v + f/2, 0)`. -/ theorem subEval_halve_f : @@ -1576,23 +1673,37 @@ theorem subEval_halve_f : 0, regs.getD 4 0 + regs.getD 3 0 / 2]) (fun _ _ => by simp) (fun regs hlen hf => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hf; subst hf; simp) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ] at hf + subst hf + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.zero_div, Nat.add_zero]) (fun regs k hlen hf => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp only [leafReg, List.set, List.getD_cons_zero, List.getD_cons_succ] at hf ⊢ + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 46 = 3 from rfl, show leafReg 70 = 4 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hf ⊢ subst hf - rcases k with _ | _ <;> (simp; try omega)) + rcases k with _ | k' + · simp only [↓reduceIte, List.getD_cons_zero, List.getD_cons_succ] + · simp only [Nat.succ_ne_zero, ↓reduceIte, Nat.add_sub_cancel, + List.getD_cons_zero, List.getD_cons_succ] + have h1 : v + 1 + k' / 2 = v + (k' + 1 + 1) / 2 := by omega + rw [h1]) (fun regs k hlen hf => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp only [leafReg, List.set, List.getD_cons_zero, List.getD_cons_succ] at hf ⊢ + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + rw [show leafReg 46 = 3 from rfl, show leafReg 70 = 4 from rfl] + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hf ⊢ subst hf - rcases k with _ | _ <;> simp) + rcases k with _ | k' <;> + (simp only [↓reduceIte, Nat.succ_ne_zero, Nat.add_sub_cancel, + List.getD_cons_zero, List.getD_cons_succ] + omega)) refine (subEval_seq (q := 111) (q₀ := 115) (q₁ := 116) rfl rfl rfl rfl h115 subEval_move_v_f).congr ?_ intro regs hlen - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> - (simp at hlen ⊢; try omega) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.zero_add] /-- Scaling loop inside `width` (State `61`): when `v = 0`, scales `j` by 4 each tick, conserving `m + j`, counting `q = quarterClock j` in `x`, and dividing `f` by $2^q$. -/ @@ -1672,14 +1783,21 @@ theorem subEval_compare_sub : regs.getD 3 0 - regs.getD 2 0, regs.getD 4 0]) (fun _ _ => by simp) (fun regs hlen hx => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hx; subst hx; simp) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.getD_cons_zero, List.getD_cons_succ] at hx + subst hx + simp only [List.getD_cons_zero, List.getD_cons_succ, Nat.sub_zero]) (fun regs k hlen hx => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hx ⊢; omega) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hx ⊢ + subst hx + congr 1; congr 1; congr 1; congr 1; omega) (fun regs k hlen hx => by - rcases regs with _ | ⟨m, _ | ⟨j, _ | ⟨x, _ | ⟨f, _ | ⟨v, _ | _⟩⟩⟩⟩⟩ <;> try simp at hlen - simp at hx ⊢) + obtain ⟨m, j, x, f, v, rfl⟩ := list_length_five regs hlen + simp only [List.set_cons_zero, List.set_cons_succ, + List.getD_cons_zero, List.getD_cons_succ] at hx ⊢ + omega) theorem shuniaCounterexample_iff_sub_pos (n : ℕ) : ShuniaCounterexample n ↔ @@ -1688,7 +1806,7 @@ theorem shuniaCounterexample_iff_sub_pos (n : ℕ) : set q := quarterClock (n - 1) have hpow : 0 < 2 ^ q := Nat.pow_pos (by decide) rw [← Nat.le_div_iff_mul_le hpow] - omega + constructor <;> intro h <;> omega /-- Full `compare` subroutine at State `62` (`[1, 1, 1, 1, 1]`): subtracts `x` from `f`, then returns to `[]` if `f - x = 0`, or halts at State `77` (`[1^7]`) if `0 < f - x`. -/ diff --git a/Cryptids/Zf380.lean b/Cryptids/Zf380.lean index 77e9fa83..3779d377 100644 --- a/Cryptids/Zf380.lean +++ b/Cryptids/Zf380.lean @@ -1347,10 +1347,8 @@ theorem mkL_cons_eq_mk'_cons (l : Fin 2) (L R : ListBlank (Fin 2)) : simp [Tape.mkL, Tape.mk'] theorem default_cons_zero : - (default : ListBlank (Fin 2)).cons 0 = default := by - change ListBlank.cons 0 (ListBlank.mk []) = ListBlank.mk [] - rw [ListBlank.cons_mk] - exact Quot.sound (Or.inr ⟨1, rfl⟩) + (default : ListBlank (Fin 2)).cons 0 = default := + ListBlank.cons_default_default theorem step_mk'_none {N : ℕ} [NeZero N] {M : Machine N 2} {q : Fin N} {a : Fin 2} (h : M.transition q a = none) (L R : ListBlank (Fin 2)) : diff --git a/README.md b/README.md index 56f1b2db..fc0cc1d0 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ This repository contains two Lean 4 (`v4.35.0-rc4`) formalization libraries for | [`Cryptids/`](Cryptids/) | `(Q, 2)` Turing machines for Goldbach, ZF consistency, the Riemann Hypothesis, Erdős's ternary conjecture, and Brocard's problem | Certified state reductions (`25 → 21`, `393 → 380`, `120 → 104 → 95`, `15 → 14`), a new 28-state Brocard machine, and end-to-end halting equivalences (`Halts M ↔ ¬ GoldbachConjecture`, `ZFInconsistent`, `¬ RiemannHypothesis`, `¬ ErdosTernaryConjecture`, `¬ BrocardConjecture`) | [`Cryptids/README.md`](Cryptids/README.md), [`Cryptids/Semantics/README.md`](Cryptids/Semantics/README.md) | | [`BusyBeaver/`](BusyBeaver/) | `BB(6)` `(6, 2)` and `BB(3, 3)` `(3, 3)` holdout Turing machines (some are potential Cryptids, subject to community acceptance) | Shared execution semantics (`BusyBeaver/Defs.lean`), foundational lemmas (`BusyBeaver/Basic.lean`), RLE loader and `ConjectureMachines` bridge (`BusyBeaver/Bridge.lean`), and certified behavioral proofs in [`BusyBeaver/BB6/`](BusyBeaver/BB6/README.md) (55 closed-pattern/reflective holdouts + 56 [`Accelerations/`](BusyBeaver/BB6/Accelerations/README.md) + 191 resolved [`Halt/`](BusyBeaver/BB6/Halt/) and [`NonHalt/`](BusyBeaver/BB6/NonHalt/) proofs, plus halting equivalences and hardness evidence) and [`BusyBeaver/BB33/`](BusyBeaver/BB33/README.md) (6 machines) | [`BusyBeaver/README.md`](BusyBeaver/README.md), [`BusyBeaver/BB6/README.md`](BusyBeaver/BB6/README.md), [`BusyBeaver/BB6/Accelerations/README.md`](BusyBeaver/BB6/Accelerations/README.md), [`BusyBeaver/BB33/README.md`](BusyBeaver/BB33/README.md) | -All Lean 4 proofs are checked by the kernel without `sorry` and depend only on standard Lean axioms: -- **Constructive (`["propext", "Quot.sound"]`, no `Classical.choice`):** All ZF machine-to-proof-search equivalences (`halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, `halts_zf432_iff_wadeZFInconsistent`), first-order Peano Arithmetic (`PAProvable`) consistency and $\Sigma_1^0$ standard-model adequacy (`not_paProvable_false`, `paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent` in [`Cryptids/Semantics/PA/`](Cryptids/Semantics/PA/)), the direct simulation state reductions ([`Goldbach21.lean`](Cryptids/Goldbach21.lean), [`Zf380.lean`](Cryptids/Zf380.lean), [`Riemann104.lean`](Cryptids/Riemann104.lean)), the `erdos_ternary_14` reduction ([`ErdosTernary14.lean`](Cryptids/ErdosTernary14.lean)), the `brocard_28` equivalence `Halts brocard28 ↔ ∃ n, 7 < n ∧ IsSquare (n! + 1)` ([`Brocard28.lean`](Cryptids/Brocard28.lean), [`Semantics/Brocard28.lean`](Cryptids/Semantics/Brocard28.lean)), and all five `candidate_fewer_states` theorems, audited in CI via [`comparator/constructive.json`](comparator/constructive.json). Because classical Lean (`ZFSet.{0}` in [`Soundness.lean`](Cryptids/Semantics/Zf/Soundness.lean)) proves `¬ ZFInconsistent`—so any non-halting machine would vacuously satisfy `Halts M ↔ ZFInconsistent` under `Classical.choice`—excluding `Classical.choice` blocks classical `Con(ZF)` shortcuts, while deeply embedded `PAProvable` provides a weak first-order metatheory strictly below `ZF` (see [Foundational Note on `Con(ZF)` and Constructive Equivalence](Cryptids/Semantics/README.md#foundational-note-conzf-in-lean-and-constructive-equivalence)). -- **Classical (`["propext", "Classical.choice", "Quot.sound"]`):** First-order `PA` standard-model soundness and object-level `PAProvable` proofs that `zf_380` and `zf_393` halt iff `ZF` is inconsistent (`paProvable_sound_nat`, `paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, `paProvable_halts_zf380_iff_zfInconsistent`; proved semantically in arbitrary `PAModel`s via first-order induction and reflected to `PAProvable` via internal Gödel–Henkin completeness `paProvable_iff_holdsIn_all_models`, which uses `Classical.choice`), set-theoretic soundness and non-halting in `ZFSet.{0}` (`zfProvable_sound_zfSet`, `not_zfInconsistent`, `not_halts_zf393`, `not_halts_candidate`), negated-$\Pi_1^0$ Goldbach equivalence (`¬ GoldbachConjecture`, which uses Markov's Principle), the arithmetic-stage `riemann_95` reduction (`Nat.Prime`), complex-analytic `RiemannHypothesis` equivalences, the `erdos_ternary_15` and `erdos_ternary_14` equivalences with `ErdosTernaryConjecture` (`Nat.digits`, and Markov's Principle for `¬ ErdosTernaryConjecture`), the `brocard_28` equivalence with `¬ BrocardConjecture` (Markov's Principle), and the `BB(6)` and `BB(3, 3)` holdout reductions, audited via [`comparator/all.json`](comparator/all.json), [`comparator/pa_semantics.json`](comparator/pa_semantics.json), and [`comparator/busy_beaver.json`](comparator/busy_beaver.json). +All Lean 4 proofs are checked by the kernel without `sorry` and audited in CI across three axiom tiers: +- **Zero-Axiom (`[]` — pure `CIC`, no axioms whatsoever):** Specification definitions (`ListBlank`, `Tape`, `Halts`, `Machine`, `BundledMachine`, `candidate`, `reference`, `PAProvable`) represent half-tapes concretely as canonical blank-trimmed lists rather than quotients, and all five `candidate_fewer_states` theorems together with syntactic first-order `PA` consistency (`not_paProvable_false`) depend on **zero axioms (`[]`)**, audited in CI via [`comparator/zero_axioms.json`](comparator/zero_axioms.json). +- **Constructive (`["propext", "Quot.sound"]`, no `Classical.choice`):** **All five** state reductions ([`Goldbach21.lean`](Cryptids/Goldbach21.lean), [`Zf380.lean`](Cryptids/Zf380.lean), [`Riemann104.lean`](Cryptids/Riemann104.lean), [`Riemann95.lean`](Cryptids/Riemann95.lean), [`ErdosTernary14.lean`](Cryptids/ErdosTernary14.lean)), all ZF machine-to-proof-search equivalences (`halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, `halts_zf432_iff_wadeZFInconsistent`), first-order Peano Arithmetic (`PAProvable`) consistency and $\Sigma_1^0$ standard-model adequacy (`not_paProvable_false`, `paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent` in [`Cryptids/Semantics/PA/`](Cryptids/Semantics/PA/)), and the `brocard_28` equivalence `Halts brocard28 ↔ ∃ n, 7 < n ∧ IsSquare (n! + 1)` ([`Brocard28.lean`](Cryptids/Brocard28.lean), [`Semantics/Brocard28.lean`](Cryptids/Semantics/Brocard28.lean)), audited in CI via [`comparator/constructive.json`](comparator/constructive.json). Because classical Lean (`ZFSet.{0}` in [`Soundness.lean`](Cryptids/Semantics/Zf/Soundness.lean)) proves `¬ ZFInconsistent`—so any non-halting machine would vacuously satisfy `Halts M ↔ ZFInconsistent` under `Classical.choice`—excluding `Classical.choice` blocks classical `Con(ZF)` shortcuts, while deeply embedded `PAProvable` provides a weak first-order metatheory strictly below `ZF` (see [Foundational Note on `Con(ZF)` and Constructive Equivalence](Cryptids/Semantics/README.md#foundational-note-conzf-in-lean-and-constructive-equivalence)). +- **Classical (`["propext", "Classical.choice", "Quot.sound"]`):** First-order `PA` standard-model soundness and object-level `PAProvable` proofs that `zf_380` and `zf_393` halt iff `ZF` is inconsistent (`paProvable_sound_nat`, `paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, `paProvable_halts_zf380_iff_zfInconsistent`; proved semantically in arbitrary `PAModel`s via first-order induction and reflected to `PAProvable` via internal Gödel–Henkin completeness `paProvable_iff_holdsIn_all_models`, which uses `Classical.choice`), set-theoretic soundness and non-halting in `ZFSet.{0}` (`zfProvable_sound_zfSet`, `not_zfInconsistent`, `not_halts_zf393`, `not_halts_candidate`), negated-$\Pi_1^0$ Goldbach equivalence (`¬ GoldbachConjecture`, which uses Markov's Principle), complex-analytic `RiemannHypothesis` equivalences, the `erdos_ternary_15` and `erdos_ternary_14` equivalences with `ErdosTernaryConjecture` (`Nat.digits`, and Markov's Principle for `¬ ErdosTernaryConjecture`), the `brocard_28` equivalence with `¬ BrocardConjecture` (Markov's Principle), and the `BB(6)` and `BB(3, 3)` holdout proofs, audited via [`comparator/all.json`](comparator/all.json), [`comparator/pa_semantics.json`](comparator/pa_semantics.json), [`comparator/busy_beaver.json`](comparator/busy_beaver.json), and [`comparator/a6.json`](comparator/a6.json). The [95-state Riemann machine](artifacts/riemann_95/README.md) has a kernel-checked blank-tape halting equivalence to the 104-state machine and to `¬ RiemannHypothesis`. @@ -32,6 +33,7 @@ Build the conjecture-checking library (`Cryptids` and `Challenge`, default targe ```bash lake build +lake comparator --config comparator/zero_axioms.json lake comparator --config comparator/constructive.json lake comparator --config comparator/all.json python3 verify.py diff --git a/artifacts/riemann_95/README.md b/artifacts/riemann_95/README.md index 3a2f40d5..7e6584cc 100644 --- a/artifacts/riemann_95/README.md +++ b/artifacts/riemann_95/README.md @@ -33,14 +33,19 @@ From the repository root: ```sh lake build +lake comparator --config comparator/riemann_95_reduction.json lake comparator --config comparator/riemann_95.json python3 verify.py ``` -The comparator checks the three public theorems against independent challenge -definitions loaded from [`machine.txt`](machine.txt), allowing only `propext`, -`Classical.choice`, and `Quot.sound`. The same targets are included in -`comparator/all.json` and the normal CI workflow. +`comparator/riemann_95_reduction.json` verifies the state-reduction theorems +(`candidate_fewer_states` and `candidate_equivalent`) without `Classical.choice` +(allowing only `propext` and `Quot.sound`), and is included in `comparator/constructive.json` +(`candidate_fewer_states` itself is also checked with zero axioms in `comparator/zero_axioms.json`). +`comparator/riemann_95.json` checks all three public theorems—including the analytic +`halts_candidate_iff_not_riemannHypothesis`—against independent challenge definitions loaded from +[`machine.txt`](machine.txt), allowing `propext`, `Classical.choice`, and `Quot.sound`; the same +targets are included in `comparator/all.json` and the normal CI workflow. The root Python verifier checks the table's SHA-256, compares all 190 cells loaded by the implementation and challenge, and replays the complete blank diff --git a/comparator/README.md b/comparator/README.md index 046e2d76..c905c6c3 100644 --- a/comparator/README.md +++ b/comparator/README.md @@ -35,23 +35,30 @@ that: 1. Every target theorem and all of its transitive definition dependencies match identically between the challenge module and the solution module. 2. Only the permitted axioms for that configuration are used: + - **`[]` (strictly zero axioms — pure CIC kernel terms):** enforced on + [`zero_axioms.json`](./zero_axioms.json), covering all five `candidate_fewer_states` theorems + (`Goldbach21`, `Zf380`, `Riemann104`, `Riemann95`, `ErdosTernary14`) and syntactic first-order + `PA` consistency (`Semantics.PA.not_paProvable_false`). Specification definitions (`ListBlank`, + `Tape`, `Halts`, `Machine`, `BundledMachine`, `candidate`, `reference`, `PAProvable`) represent + half-tapes as canonical blank-trimmed lists rather than quotients so they depend on zero + axioms. - **`["propext", "Quot.sound"]` (strictly constructive — no `Classical.choice`):** enforced on [`constructive.json`](./constructive.json), [`goldbach_21.json`](./goldbach_21.json), - [`zf_380.json`](./zf_380.json), and [`riemann_104.json`](./riemann_104.json), covering all - three ZF machine-to-proof-search equivalences (`halts_zf393_iff_zfInconsistent`, + [`zf_380.json`](./zf_380.json), [`riemann_104.json`](./riemann_104.json), and + [`riemann_95_reduction.json`](./riemann_95_reduction.json), covering **all five** state + reductions (`Goldbach21`, `Zf380`, `Riemann104`, `Riemann95`, `ErdosTernary14`), all three ZF + machine-to-proof-search equivalences (`halts_zf393_iff_zfInconsistent`, `Zf380.Semantics.halts_candidate_iff_zfInconsistent`, `halts_zf432_iff_wadeZFInconsistent`), first-order `PA` consistency and $\Sigma_1^0$ adequacy (`not_paProvable_false`, `paHalts_holds_iff_halts`, - `paZFInconsistent_holds_iff_zfInconsistent`), the direct simulation reductions (`Goldbach21`, - `Zf380`, `Riemann104`), the `ErdosTernary14` reduction, all five `candidate_fewer_states` - theorems, and the `brocard_28` equivalence `Brocard28.halts_brocard28_iff_exists_square` - (16 theorems total). - Disallowing `Classical.choice` blocks classical `Con(ZF)` shortcuts (`not_zfInconsistent` in - `ZFSet.{0}` or `Classical.em` + `digama0/ConZF`) for `Halts M ↔ ZFInconsistent`, while deeply - embedded `PAProvable` provides a weak first-order metatheory strictly below `ZF` (see + `paZFInconsistent_holds_iff_zfInconsistent`), and the `brocard_28` equivalence + `Brocard28.halts_brocard28_iff_exists_square` (17 theorems total). Disallowing + `Classical.choice` blocks classical `Con(ZF)` shortcuts (`not_zfInconsistent` in `ZFSet.{0}` or + `Classical.em` + `digama0/ConZF`) for `Halts M ↔ ZFInconsistent`, while deeply embedded + `PAProvable` provides a weak first-order metatheory strictly below `ZF` (see [`Cryptids/Semantics/README.md`](../Cryptids/Semantics/README.md#foundational-note-conzf-in-lean-and-constructive-equivalence)). - **`["propext", "Quot.sound", "Classical.choice"]`:** allowed in [`all.json`](./all.json), - [`busy_beaver.json`](./busy_beaver.json), and the classical model-theoretic / arithmetic-stage / + [`busy_beaver.json`](./busy_beaver.json), and the classical model-theoretic / analytic configs (`pa_semantics.json`, `zf_393.json`, `zf_semantics.json`, `goldbach_semantics.json`, `riemann_95.json`, `riemann_120.json`, `riemann_semantics.json`, `erdos_ternary_15.json`, `erdos_ternary_14.json`, `brocard_28.json`). @@ -61,7 +68,8 @@ that: | Config File | Challenge Module | Solution Module | Permitted Axioms | Verified Theorems | | :--- | :--- | :--- | :--- | :--- | -| [`constructive.json`](./constructive.json) | `Challenge` | `Cryptids` | `propext`, `Quot.sound` | All 16 constructive theorems: all 3 ZF proof-search equivalences (`zf_393`, `zf_380`, `zf_432`), first-order `PA` consistency & $\Sigma_1^0$ adequacy (`not_paProvable_false`, `paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`), direct state reductions (`Goldbach21`, `Zf380`, `Riemann104`), `Riemann95.candidate_fewer_states`, and the `ErdosTernary14` reduction, and `Brocard28.halts_brocard28_iff_exists_square` | +| [`zero_axioms.json`](./zero_axioms.json) | `Challenge` | `Cryptids` | *(none)* (`[]`) | All 6 zero-axiom theorems: all 5 `candidate_fewer_states` theorems (`Goldbach21`, `Zf380`, `Riemann104`, `Riemann95`, `ErdosTernary14`) and syntactic `PA` consistency (`not_paProvable_false`) | +| [`constructive.json`](./constructive.json) | `Challenge` | `Cryptids` | `propext`, `Quot.sound` | All 17 constructive theorems: all 5 state reductions (`Goldbach21`, `Zf380`, `Riemann104`, `Riemann95`, `ErdosTernary14`), all 3 ZF proof-search equivalences (`zf_393`, `zf_380`, `zf_432`), first-order `PA` consistency & $\Sigma_1^0$ adequacy (`not_paProvable_false`, `paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`), and `Brocard28.halts_brocard28_iff_exists_square` | | [`all.json`](./all.json) | `Challenge` | `Cryptids` | `propext`, `Quot.sound`, `Classical.choice` | All 36 conjecture-checking state-reduction, equivalence, `PA` metatheory & internalized `ZF` provability, and semantics theorems | | [`pa_semantics.json`](./pa_semantics.json) | `Challenge` | `Cryptids.Semantics.PA` | `propext`, `Quot.sound`, `Classical.choice` | `not_paProvable_false`, `paHalts_holds_iff_halts`, `paZFInconsistent_holds_iff_zfInconsistent`, `paProvable_sound_nat`, `paProvable_halts_zf380_iff_zf393`, `paProvable_halts_zf393_iff_zfInconsistent`, `paProvable_halts_zf380_iff_zfInconsistent` | | [`busy_beaver.json`](./busy_beaver.json) | `BusyBeaverChallenge` | `BusyBeaver` | `propext`, `Quot.sound`, `Classical.choice` | All 735 `BB(6)` and `BB(3, 3)` holdout Level A, Level B, equivalence, A6 `is_not_halt`, and hardness-evidence theorems (`is_closed_pattern_set`, `has_collatz_reduction`, `is_closed_stack_pattern_set`, `has_stacked_collatz_reduction`, `has_stack_reduction`, `has_odometer_reduction`, `has_transducer_reduction`, `is_closed_segmented_system`, `is_valid_acceleration`, `isHalt_iff_acceleration`, `is_valid_highLevel_acceleration`, `isHalt_iff_highLevel_acceleration`, `acceleration_iff_highLevel_acceleration`, `is_not_halt`, `isHalt_HHH1LC_iff_HHH0LA`, `HardnessEvidence.*`, `is_word_run_cryptid`, `is_segmented_cryptid`, `is_odometer_cryptid`, `is_stack_cryptid`, `is_cryptid`) | @@ -72,6 +80,7 @@ that: | [`zf_393.json`](./zf_393.json) | `Challenge` | `Cryptids.Semantics.Zf393` | `propext`, `Quot.sound`, `Classical.choice` | `halts_zf393_iff_zfInconsistent`, `not_halts_zf393`, `halts_candidate_iff_zfInconsistent`, `not_halts_candidate` | | [`zf_semantics.json`](./zf_semantics.json) | `Challenge` | `Cryptids.Semantics.Zf` | `propext`, `Quot.sound`, `Classical.choice` | `zfProvable_sound_zfSet`, `not_zfInconsistent`, `halts_zf432_iff_wadeZFInconsistent` | | [`riemann_104.json`](./riemann_104.json) | `Challenge` | `Cryptids.Riemann104` | `propext`, `Quot.sound` | `candidate_fewer_states`, `candidate_equivalent` | +| [`riemann_95_reduction.json`](./riemann_95_reduction.json) | `Challenge` | `Cryptids.Riemann95` | `propext`, `Quot.sound` | `candidate_fewer_states`, `candidate_equivalent` | | [`riemann_95.json`](./riemann_95.json) | `Challenge` | `Cryptids.Semantics.Riemann95` | `propext`, `Quot.sound`, `Classical.choice` | `candidate_fewer_states`, `candidate_equivalent`, `halts_candidate_iff_not_riemannHypothesis` | | [`riemann_120.json`](./riemann_120.json) | `Challenge` | `Cryptids.Semantics.Riemann120` | `propext`, `Quot.sound`, `Classical.choice` | `halts_riemann120_iff_not_riemannHypothesis`, `halts_candidate_iff_not_riemannHypothesis` | | [`riemann_semantics.json`](./riemann_semantics.json) | `Challenge` | `Cryptids.Semantics.Riemann` | `propext`, `Quot.sound`, `Classical.choice` | `halts_riemann744_iff_exists_counterexample`, `halts_riemann744_iff_not_riemannHypothesis` | @@ -90,6 +99,7 @@ From the repository root (with `bwrap` installed): ```bash lake exe cache get +lake comparator --config comparator/zero_axioms.json lake comparator --config comparator/constructive.json lake comparator --config comparator/all.json lake comparator --config comparator/busy_beaver.json diff --git a/comparator/constructive.json b/comparator/constructive.json index 2d917499..75e06d00 100644 --- a/comparator/constructive.json +++ b/comparator/constructive.json @@ -15,6 +15,7 @@ "ConjectureMachines.Riemann104.candidate_fewer_states", "ConjectureMachines.Riemann104.candidate_equivalent", "ConjectureMachines.Riemann95.candidate_fewer_states", + "ConjectureMachines.Riemann95.candidate_equivalent", "ConjectureMachines.ErdosTernary14.candidate_fewer_states", "ConjectureMachines.ErdosTernary14.candidate_equivalent", "ConjectureMachines.Brocard28.halts_brocard28_iff_exists_square" diff --git a/comparator/riemann_95_reduction.json b/comparator/riemann_95_reduction.json new file mode 100644 index 00000000..856bba6e --- /dev/null +++ b/comparator/riemann_95_reduction.json @@ -0,0 +1,12 @@ +{ + "challenge_module": "Challenge", + "solution_module": "Cryptids.Riemann95", + "theorem_names": [ + "ConjectureMachines.Riemann95.candidate_fewer_states", + "ConjectureMachines.Riemann95.candidate_equivalent" + ], + "permitted_axioms": [ + "propext", + "Quot.sound" + ] +} diff --git a/comparator/zero_axioms.json b/comparator/zero_axioms.json new file mode 100644 index 00000000..264dd1be --- /dev/null +++ b/comparator/zero_axioms.json @@ -0,0 +1,13 @@ +{ + "challenge_module": "Challenge", + "solution_module": "Cryptids", + "theorem_names": [ + "ConjectureMachines.Goldbach21.candidate_fewer_states", + "ConjectureMachines.Zf380.candidate_fewer_states", + "ConjectureMachines.Riemann104.candidate_fewer_states", + "ConjectureMachines.Riemann95.candidate_fewer_states", + "ConjectureMachines.ErdosTernary14.candidate_fewer_states", + "ConjectureMachines.Semantics.PA.not_paProvable_false" + ], + "permitted_axioms": [] +} diff --git a/formalization.yaml b/formalization.yaml index 3f8a0fd5..8e6c845b 100644 --- a/formalization.yaml +++ b/formalization.yaml @@ -233,24 +233,24 @@ related_formalizations: status: scope: >- - All three ZF machine-to-proof-search equivalences (zf_393, zf_380, zf_432) - and the state-reduction halting equivalences for goldbach_21, zf_380, - riemann_104, and erdos_ternary_14 (along with all five candidate_fewer_states - theorems, 12 theorems total) are proved constructively using only propext and Quot.sound - (zero Classical.choice, audited via comparator/constructive.json so - classical Con(ZF) shortcuts such as Soundness.lean's not_zfInconsistent are - excluded; this establishes a constructive meta-level correspondence in Lean - rather than internalizing the reduction inside PA/ZF). The classical - end-to-end - semantics—unconditional ZF non-halting via soundness in Mathlib's ZFSet.{0} - (Cryptids/Semantics/Zf/Soundness.lean), negated-Pi_1^0 Goldbach semantics - (Cryptids/Semantics/Goldbach.lean), and complex-analytic Riemann Hypothesis - semantics for riemann_744 (Cryptids/Semantics/Riemann.lean), Shunia's - 120-state machine riemann_120, riemann_104 - (Cryptids/Semantics/Riemann120.lean), and the 95-state arithmetic-stage - reduction riemann_95 (Cryptids/Riemann95.lean, - Cryptids/Semantics/Riemann95.lean)—are proved with zero sorrys. The - 15-state machine erdos_ternary_15 satisfies Halts erdosTernary15 <-> ∃ n, 8 < n ∧ 2 ∉ pw n + Specification definitions (ListBlank, Tape, Halts, Machine, BundledMachine, + PAProvable), all five candidate_fewer_states theorems, and syntactic + first-order Peano Arithmetic consistency (not_paProvable_false) depend on + zero axioms ([], audited via comparator/zero_axioms.json). All five + state-reduction halting equivalences (goldbach_21, zf_380, riemann_104, + riemann_95, erdos_ternary_14), all three ZF machine-to-proof-search + equivalences (zf_393, zf_380, zf_432), Sigma_1^0 PA standard-model + adequacy, and the brocard_28 square equivalence (17 theorems total) are + proved constructively using at most + propext and Quot.sound (zero Classical.choice, audited via + comparator/constructive.json). Object-level first-order PA provability of + the zf_380 and zf_393 halting equivalences (PAProvable, + Cryptids/Semantics/PA/), unconditional ZF non-halting in Mathlib's + ZFSet.{0} (Cryptids/Semantics/Zf/Soundness.lean), negated-Pi_1^0 Goldbach + semantics (Cryptids/Semantics/Goldbach.lean), and complex-analytic Riemann + Hypothesis semantics for riemann_744, riemann_120, riemann_104, and + riemann_95 are all proved with zero sorrys. The 15-state machine + erdos_ternary_15 satisfies Halts erdosTernary15 <-> ∃ n, 8 < n ∧ 2 ∉ pw n constructively (Cryptids/ErdosTernary15.lean, pw = base-3 digits of 2^n by repeated doubling) and Halts erdosTernary15 <-> ¬ ErdosTernaryConjecture via Mathlib's Nat.digits (Cryptids/Semantics/ErdosTernary15.lean). The 14-state @@ -272,8 +272,8 @@ status: - declaration: "ConjectureMachines.Goldbach21.candidate_fewer_states" file: "Cryptids/Goldbach21.lean" sorry_count: 0 - axioms: ["propext"] - comparator_config: "comparator/goldbach_21.json" + axioms: [] + comparator_config: "comparator/zero_axioms.json" - declaration: "ConjectureMachines.Goldbach21.candidate_equivalent" file: "Cryptids/Goldbach21.lean" sorry_count: 0 @@ -302,8 +302,8 @@ status: - declaration: "ConjectureMachines.Zf380.candidate_fewer_states" file: "Cryptids/Zf380.lean" sorry_count: 0 - axioms: ["propext"] - comparator_config: "comparator/zf_380.json" + axioms: [] + comparator_config: "comparator/zero_axioms.json" - declaration: "ConjectureMachines.Zf380.candidate_equivalent" file: "Cryptids/Zf380.lean" sorry_count: 0 @@ -334,6 +334,41 @@ status: sorry_count: 0 axioms: ["propext", "Quot.sound"] comparator_config: "comparator/constructive.json" + - declaration: "ConjectureMachines.Semantics.PA.not_paProvable_false" + file: "Cryptids/Semantics/PA/Syntax.lean" + sorry_count: 0 + axioms: [] + comparator_config: "comparator/zero_axioms.json" + - declaration: "ConjectureMachines.Semantics.PA.paHalts_holds_iff_halts" + file: "Cryptids/Semantics/PA/Adequacy.lean" + sorry_count: 0 + axioms: ["propext", "Quot.sound"] + comparator_config: "comparator/constructive.json" + - declaration: "ConjectureMachines.Semantics.PA.paZFInconsistent_holds_iff_zfInconsistent" + file: "Cryptids/Semantics/PA/Adequacy.lean" + sorry_count: 0 + axioms: ["propext", "Quot.sound"] + comparator_config: "comparator/constructive.json" + - declaration: "ConjectureMachines.Semantics.PA.paProvable_sound_nat" + file: "Cryptids/Semantics/PA/Syntax.lean" + sorry_count: 0 + axioms: ["propext", "Classical.choice", "Quot.sound"] + comparator_config: "comparator/pa_semantics.json" + - declaration: "ConjectureMachines.Semantics.PA.paProvable_halts_zf380_iff_zf393" + file: "Cryptids/Semantics/PA/Zf380.lean" + sorry_count: 0 + axioms: ["propext", "Classical.choice", "Quot.sound"] + comparator_config: "comparator/pa_semantics.json" + - declaration: "ConjectureMachines.Semantics.PA.paProvable_halts_zf393_iff_zfInconsistent" + file: "Cryptids/Semantics/PA/Zf393/Soundness.lean" + sorry_count: 0 + axioms: ["propext", "Classical.choice", "Quot.sound"] + comparator_config: "comparator/pa_semantics.json" + - declaration: "ConjectureMachines.Semantics.PA.paProvable_halts_zf380_iff_zfInconsistent" + file: "Cryptids/Semantics/PA/Zf393/Soundness.lean" + sorry_count: 0 + axioms: ["propext", "Classical.choice", "Quot.sound"] + comparator_config: "comparator/pa_semantics.json" - declaration: "ConjectureMachines.Semantics.Riemann.halts_riemann744_iff_exists_counterexample" file: "Cryptids/Semantics/Riemann.lean" sorry_count: 0 @@ -352,8 +387,8 @@ status: - declaration: "ConjectureMachines.Riemann104.candidate_fewer_states" file: "Cryptids/Riemann104.lean" sorry_count: 0 - axioms: ["propext"] - comparator_config: "comparator/riemann_104.json" + axioms: [] + comparator_config: "comparator/zero_axioms.json" - declaration: "ConjectureMachines.Riemann104.candidate_equivalent" file: "Cryptids/Riemann104.lean" sorry_count: 0 @@ -367,13 +402,13 @@ status: - declaration: "ConjectureMachines.Riemann95.candidate_fewer_states" file: "Cryptids/Riemann95.lean" sorry_count: 0 - axioms: ["propext"] - comparator_config: "comparator/constructive.json" + axioms: [] + comparator_config: "comparator/zero_axioms.json" - declaration: "ConjectureMachines.Riemann95.candidate_equivalent" file: "Cryptids/Riemann95.lean" sorry_count: 0 - axioms: ["propext", "Classical.choice", "Quot.sound"] - comparator_config: "comparator/riemann_95.json" + axioms: ["propext", "Quot.sound"] + comparator_config: "comparator/riemann_95_reduction.json" - declaration: "ConjectureMachines.Riemann95.Semantics.halts_candidate_iff_not_riemannHypothesis" file: "Cryptids/Semantics/Riemann95.lean" sorry_count: 0 @@ -392,8 +427,8 @@ status: - declaration: "ConjectureMachines.ErdosTernary14.candidate_fewer_states" file: "Cryptids/ErdosTernary14.lean" sorry_count: 0 - axioms: ["propext"] - comparator_config: "comparator/constructive.json" + axioms: [] + comparator_config: "comparator/zero_axioms.json" - declaration: "ConjectureMachines.ErdosTernary14.candidate_equivalent" file: "Cryptids/ErdosTernary14.lean" sorry_count: 0 @@ -522,6 +557,34 @@ alignment: lean: "ConjectureMachines.Semantics.Zf.halts_zf432_iff_wadeZFInconsistent" module: "Cryptids.Semantics.Zf" status: "proved" + - source: "Syntactic consistency of first-order PA (¬ PAProvable ⊥)" + lean: "ConjectureMachines.Semantics.PA.not_paProvable_false" + module: "Cryptids.Semantics.PA.Syntax" + status: "proved" + - source: "Sigma_1^0 adequacy of paHalts M on ℕ" + lean: "ConjectureMachines.Semantics.PA.paHalts_holds_iff_halts" + module: "Cryptids.Semantics.PA.Adequacy" + status: "proved" + - source: "Sigma_1^0 adequacy of paZFInconsistent on ℕ" + lean: "ConjectureMachines.Semantics.PA.paZFInconsistent_holds_iff_zfInconsistent" + module: "Cryptids.Semantics.PA.Adequacy" + status: "proved" + - source: "Standard-model soundness of PAProvable on ℕ" + lean: "ConjectureMachines.Semantics.PA.paProvable_sound_nat" + module: "Cryptids.Semantics.PA.Syntax" + status: "proved" + - source: "Object-level PA proof: PA |- Halts(zf_380) <-> Halts(zf_393)" + lean: "ConjectureMachines.Semantics.PA.paProvable_halts_zf380_iff_zf393" + module: "Cryptids.Semantics.PA.Zf380" + status: "proved" + - source: "Object-level PA proof: PA |- Halts(zf_393) <-> ~Con(ZF)" + lean: "ConjectureMachines.Semantics.PA.paProvable_halts_zf393_iff_zfInconsistent" + module: "Cryptids.Semantics.PA.Zf393.Soundness" + status: "proved" + - source: "Object-level PA proof: PA |- Halts(zf_380) <-> ~Con(ZF)" + lean: "ConjectureMachines.Semantics.PA.paProvable_halts_zf380_iff_zfInconsistent" + module: "Cryptids.Semantics.PA.Zf393.Soundness" + status: "proved" - source: "riemann_744 <-> ∃ x, MatiyasevichRiemannCounterexample x" lean: "ConjectureMachines.Semantics.Riemann.halts_riemann744_iff_exists_counterexample" module: "Cryptids.Semantics.Riemann"