Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lengyijun committed Oct 16, 2024
1 parent e024761 commit 5a9514d
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 0 deletions.
4 changes: 4 additions & 0 deletions GoldbachTm.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import GoldbachTm.Basic
import GoldbachTm.Format
import GoldbachTm.ListBlank
import GoldbachTm.Tm27.TuringMachine27
import GoldbachTm.Tm27.Search0
import GoldbachTm.Tm27.Prime
import GoldbachTm.Tm27.Content

import GoldbachTm.Tm31.TuringMachine31
import GoldbachTm.Tm31.Search0
import GoldbachTm.Tm31.Content
Expand Down
3 changes: 3 additions & 0 deletions GoldbachTm/Tm27/Content.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import GoldbachTm.Tm27.TuringMachine27
import GoldbachTm.Tm27.Search0
import Mathlib.Data.Nat.Prime.Defs
77 changes: 77 additions & 0 deletions GoldbachTm/Tm27/Prime.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import GoldbachTm.Tm27.TuringMachine27

namespace Tm27

-- not sure
theorem prime_21 (i r1: ℕ) (l r : List Γ)
(g :
nth_cfg i = some ⟨⟨0, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (Γ.zero :: l), Turing.ListBlank.mk (List.replicate r1 Γ.one ++ List.cons Γ.zero r)⟩⟩)
(p : Nat.Prime (r1+1)) :
∃ j, nth_cfg (i+j) = some ⟨⟨21, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (r1+1) Γ.one ++ List.cons Γ.zero r)⟩⟩ :=
match h : r1 with
| Nat.zero => by subst r1
exfalso
apply Nat.not_prime_one p
| Nat.succ Nat.zero => by
subst r1
forward g g i
forward g g (1+i)
forward g g (2+i)
forward g g (3+i)
forward g g (4+i)
use 5
ring_nf at *
simp [g]
| Nat.succ (Nat.succ Nat.zero) => by
subst r1
forward g g i
forward g g (1+i)
forward g g (2+i)
forward g g (3+i)
forward g g (4+i)
forward g g (5+i)
forward g g (6+i)
use 7
ring_nf at *
simp [g]
| Nat.succ (Nat.succ (Nat.succ r1)) => by sorry


-- not sure
theorem n_prime_17 (i r1: ℕ) (l r : List Γ)
(g :
nth_cfg i = some ⟨⟨0, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (Γ.zero :: l), Turing.ListBlank.mk (List.replicate r1 Γ.one ++ List.cons Γ.zero r)⟩⟩)
(hp : ¬ Nat.Prime (r1+1)) :
∃ j, nth_cfg (i+j) = some ⟨⟨17, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (r1+1) Γ.one ++ List.cons Γ.zero r)⟩⟩ :=
match r1 with
| Nat.zero => by simp_all
forward g g i
forward g g (1+i)
forward g g (2+i)
use 3
rw [← g]
ring_nf
| Nat.succ Nat.zero => by exfalso
apply hp
decide
| Nat.succ (Nat.succ Nat.zero) => by exfalso
apply hp
decide
| Nat.succ (Nat.succ (Nat.succ r1)) => by
forward g g i
forward g g (1+i)
forward g g (2+i)
forward g g (3+i)
forward g g (4+i)
forward g g (5+i)
forward g g (6+i)
forward g g (7+i)
forward g g (8+i)
forward g g (9+i)
forward g g (10+i)
forward g g (11+i)
forward g g (12+i)
forward g g (13+i)
sorry

end Tm27
105 changes: 105 additions & 0 deletions GoldbachTm/Tm27/Search0.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
-- theorem of recursive states
-- all these states' usage is to search 0
import GoldbachTm.Tm27.TuringMachine27

namespace Tm27

-- left
theorem rec17 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨17, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero l), Turing.ListBlank.mk r⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨17, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ r)⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) l (List.cons Γ.one r)
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec19 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨19, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero l), Turing.ListBlank.mk r⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨19, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ r)⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) l (List.cons Γ.one r)
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec21 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨21, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero l), Turing.ListBlank.mk r⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨21, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ r)⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) l (List.cons Γ.one r)
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec24 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨24, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero l), Turing.ListBlank.mk r⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨24, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ r)⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) l (List.cons Γ.one r)
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

--right
theorem rec11 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨11, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero r) ⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨11, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ l), Turing.ListBlank.mk r⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) (List.cons Γ.one l) r
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec20 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨20, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero r) ⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨20, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ l), Turing.ListBlank.mk r⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) (List.cons Γ.one l) r
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec23 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨23, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero r) ⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨23, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ l), Turing.ListBlank.mk r⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) (List.cons Γ.one l) r
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

theorem rec26 (k : ℕ): ∀ (i : ℕ) (l r : List Γ),
nth_cfg i = some ⟨⟨26, by omega⟩, ⟨Γ.one, Turing.ListBlank.mk l, Turing.ListBlank.mk (List.replicate k Γ.one ++ List.cons Γ.zero r) ⟩⟩ →
nth_cfg (i + k + 1) = some ⟨⟨26, by omega⟩, ⟨Γ.zero, Turing.ListBlank.mk (List.replicate (k+1) Γ.one ++ l), Turing.ListBlank.mk r⟩⟩ := by
induction k with intros i l r h
| zero => simp [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]
| succ k => rename_i induction_step
specialize induction_step (i+1) (List.cons Γ.one l) r
have g : i + (k+1) +1 = i + 1 + k + 1 := by omega
rw [g, induction_step]
. simp [List.replicate_succ' (k+1)]
. simp! [nth_cfg, h, step, machine, Turing.Tape.write, Turing.Tape.move]

end Tm27
19 changes: 19 additions & 0 deletions GoldbachTm/Tm27/TuringMachine27.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- inspired by https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Computability/TuringMachine.lean
import Mathlib.Computability.TuringMachine
import Mathlib.Data.Real.Sqrt
import GoldbachTm.Basic
import GoldbachTm.Format
import GoldbachTm.ListBlank
Expand Down Expand Up @@ -91,4 +92,22 @@ def machine : Machine
| ⟨26, _⟩, Γ.one => some ⟨⟨26, by omega⟩, ⟨Turing.Dir.right, Γ.one⟩⟩
| ⟨_+27, _⟩, _ => by omega -- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Pattern.20matching.20on.20Fin.20isn't.20exhaustive.20for.20large.20matches/near/428048252

def nth_cfg : (n : Nat) -> Option Cfg
| 0 => init []
| Nat.succ n => match (nth_cfg n) with
| none => none
| some cfg => step machine cfg


-- g1 = g2
macro "forward" g1:ident g2:Lean.binderIdent i:term: tactic => `(tactic| (
have h : nth_cfg ($i + 1) = nth_cfg ($i + 1) := rfl
nth_rewrite 2 [nth_cfg] at h
simp [*, step, Option.map, machine, Turing.Tape.write, Turing.Tape.move] at h
try simp! [*, -nth_cfg] at h
try ring_nf at h
clear $g1
rename_i $g2
))

end Tm27

0 comments on commit 5a9514d

Please sign in to comment.