Skip to content

Commit a3efff6

Browse files
authored
Prove URMComputable1.rfind closure (#28) (#42)
1 parent 7244ebc commit a3efff6

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

Urm/Partrec.lean

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,43 @@ theorem URMComputable1.prec {f g : ℕ →. ℕ}
11771177
then apply URMComputable.min. -/
11781178
theorem URMComputable1.rfind {f : ℕ →. ℕ} (hf : URMComputable1 f) :
11791179
URMComputable1 (fun a => Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a n)) := by
1180-
-- f_adapted(a,n) = f(pair(a,n)) via composition with pair_computable
1181-
-- Then μFunction f_adapted equals the goal, apply URMComputable.min
1182-
sorry
1180+
unfold URMComputable1 at *
1181+
-- Step 1: Define f_adapted via composition with pair_computable
1182+
-- f_adapted(xy) = f(pair(xy 0, xy 1))
1183+
let pairGs : Fin 1 → (Fin 2 → ℕ) → Part ℕ :=
1184+
fun _ xy => Part.some (Nat.pair (xy 0) (xy 1))
1185+
have h_pair : ∀ i, URMComputable 2 (pairGs i) := fun _ => pair_computable
1186+
have h_adapted := URMComputable.comp_general (m := 1) (n := 2) hf h_pair
1187+
-- h_adapted : URMComputableSF 2 (compFunction 1 2 (fun x => f (x 0)) pairGs)
1188+
1189+
-- Step 2: Apply minimization
1190+
have h_min := URMComputable.min h_adapted.toComputable
1191+
-- h_min : URMComputableSF 1 (μFunction (compFunction ...))
1192+
1193+
-- Step 3: Convert to goal form
1194+
convert h_min.toComputable using 1
1195+
funext x
1196+
-- Goal: Nat.rfind (fun n => (· = 0) <$> f (pair (x 0) n))
1197+
-- = μFunction (compFunction 1 2 ...) x
1198+
-- Both sides compute Nat.rfind of the same predicate
1199+
simp only [μFunction, μ]
1200+
congr 1
1201+
funext n
1202+
-- Show checkZero predicates are equal
1203+
simp only [checkZero, extendInputs, compFunction, Part.sequence,
1204+
Part.bind_some, pairGs]
1205+
-- Both sides are Part.map (· = 0) (f (pair ... ...))
1206+
-- Simplify Fin.snoc to show equality
1207+
congr 2
1208+
simp only [Part.map_some, Part.bind_some, Fin.cons_zero]
1209+
-- Show: f (pair (x 0) n) = f (pair (snoc x n 0) (snoc x n 1))
1210+
-- Unfold Fin.snoc and simplify
1211+
simp only [Fin.snoc, Fin.val_zero, Fin.val_one, Nat.lt_irrefl, dite_false]
1212+
-- Remaining goal: simplify the conditional and casts
1213+
have h01 : (0 : ℕ) < 1 := by omega
1214+
simp only [h01, ↓reduceDIte]
1215+
-- The casts are identities on ℕ
1216+
rfl
11831217

11841218
end URMComputable1Closure
11851219

0 commit comments

Comments
 (0)