Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/lean_action_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 69 additions & 9 deletions BusyBeaver/Bridge.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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 Γ :=
Expand Down
24 changes: 23 additions & 1 deletion BusyBeaverChallenge.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading
Loading