Skip to content

Commit 4bf376b

Browse files
committed
Extract const_one_n_computable helper in Partrec
Create generalized const_one_n_computable that works for any arity, replacing duplicate ~20-line proofs for the 2-ary and 1-ary cases with one-liners that reference the shared helper. Net reduction: 14 lines.
1 parent ca6dc22 commit 4bf376b

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

Urm/Partrec.lean

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,10 @@ private def leOuterGs : Fin 2 → (Fin 2 → ℕ) → Part ℕ :=
334334
@[simp] private theorem leOuterGs_zero : leOuterGs 0 = fun _ => Part.some 1 := rfl
335335
@[simp] private theorem leOuterGs_one : leOuterGs 1 = leSignXY := rfl
336336

337-
/-- Constant 1 is URMComputable 2 (program: Z 0, S 0). -/
338-
private theorem const_one_computable : URMComputable 2 (fun _ : Fin 2 → ℕ => Part.some 1) := by
337+
/-- Constant 1 is URMComputable n for any arity (program: Z 0, S 0). -/
338+
private theorem const_one_n_computable (n : ℕ) : URMComputable n (fun _ : Fin n → ℕ => Part.some 1) := by
339339
use [Instr.Z 0, Instr.S 0]
340340
intro inputs
341-
-- Build the execution: Z 0 clears R0, S 0 increments to 1, then halt at pc=2
342341
let s0 := State.fromInputs (List.ofFn inputs)
343342
let s1 := s0.write 0 0
344343
let s2 := s1.write 0 (s1.read 0 + 1)
@@ -356,6 +355,10 @@ private theorem const_one_computable : URMComputable 2 (fun _ : Fin 2 → ℕ =>
356355
simp only [Result, heq, State.output, s2, s1, s0, State.write, State.read,
357356
Function.update_self, Part.get_some]
358357

358+
/-- Constant 1 is URMComputable 2. -/
359+
private theorem const_one_computable : URMComputable 2 (fun _ : Fin 2 → ℕ => Part.some 1) :=
360+
const_one_n_computable 2
361+
359362
/-- Helper: Composing sub with (const 1, sign(x-y)) computes 1 - sign(x-y). -/
360363
private theorem le_comp_eq (xy : Fin 2 → ℕ) :
361364
compFunction 2 2 (fun ab => Part.some (ab 0 - ab 1)) leOuterGs xy =
@@ -869,25 +872,8 @@ private theorem unpairLtDS_computable :
869872
Fin.val_zero, ↓reduceIte, Fin.cons_zero, Fin.cons_one, Fin.val_succ, Nat.add_one_ne_zero]
870873

871874
-- Helper: constant 1 as a 1-ary function
872-
private theorem const_one_1_computable : URMComputable 1 (fun _ : Fin 1 → ℕ => Part.some 1) := by
873-
use [Instr.Z 0, Instr.S 0]
874-
intro inputs
875-
let s0 := State.fromInputs (List.ofFn inputs)
876-
let s1 := s0.write 0 0
877-
let s2 := s1.write 0 (s1.read 0 + 1)
878-
have hstep1 : Step [Instr.Z 0, Instr.S 0] ⟨0, s0⟩ ⟨1, s1⟩ := Step.zero rfl
879-
have hstep2 : Step [Instr.Z 0, Instr.S 0] ⟨1, s1⟩ ⟨2, s2⟩ := Step.succ rfl
880-
have hhalted : (⟨2, s2⟩ : Config).isHalted [Instr.Z 0, Instr.S 0] := by simp
881-
have hsteps : Steps [Instr.Z 0, Instr.S 0] (Config.init (List.ofFn inputs)) ⟨2, s2⟩ :=
882-
Steps.trans (Steps.single hstep1) (Steps.single hstep2)
883-
constructor
884-
· simp only [Part.some_dom, iff_true]
885-
exact ⟨⟨2, s2⟩, hsteps, hhalted⟩
886-
· intro hHalts _
887-
obtain ⟨hsteps', hhalted'⟩ := Classical.choose_spec hHalts
888-
have heq := Steps.halts_unique hsteps' hhalted' hsteps hhalted
889-
simp only [Result, heq, State.output, s2, s1, s0, State.write, State.read,
890-
Function.update_self, Part.get_some]
875+
private theorem const_one_1_computable : URMComputable 1 (fun _ : Fin 1 → ℕ => Part.some 1) :=
876+
const_one_n_computable 1
891877

892878
-- Helper: 1 - lt(d, s) is computable (ge indicator)
893879
private def unpairGeDSGs : Fin 2 → (Fin 1 → ℕ) → Part ℕ :=

0 commit comments

Comments
 (0)