@@ -109,7 +109,7 @@ theorem comp_general_halts_imp_gi_dom
109109 have hn_le_base : n ≤ base + 1 := by have := compositionBase_ge_n_sub_one m n pF pGs; omega
110110 have hsSave_value : sSave.read (base + 1 + r) = inputs ⟨r, hr_lt_n⟩ := by
111111 rw [hsSave_eq]; exact saveInputs_state base n hn_le_base inputs r hr_lt_n
112- have hSavePrefixChain := Steps.chain_concat hSave_steps ( by simp) rfl hPrefix_steps hPrefix_halted
112+ have hSavePrefixChain := Steps.chain_concat_sf hSaveInputs_sf hSave_steps hSave_halted' hPrefix_steps hPrefix_halted
113113 have hPrefix_state_match : cPrefix.state = sSavePrefix := by
114114 simp only [hsSavePrefix_eq hSavePrefix_halts, ← Steps.halts_unique hSavePrefixChain.1 hSavePrefixChain.2 hSavePrefix_halts.choose_spec.1 hSavePrefix_halts.choose_spec.2 ]
115115 have hPrefix_preserves := allGPhases_prefix_preserves_saved_inputs m n base pGs hGs_sf hpGs_max hn_le_base
@@ -251,23 +251,22 @@ theorem comp_general_dom_imp_halts
251251 have hGPhases_pc : cGPhases.pc = gPhases.length :=
252252 hGPhases_sf.pc_eq_length_of_halted hGPhases_steps (Nat.zero_le _) hGPhases_halted
253253 let sGPhases := cGPhases.state
254+ have hpc_eq : cGPhases.pc + saveInputs.length = (saveInputs.concat gPhases).length := by
255+ simp only [Program.concat_length, hGPhases_pc]; omega
254256 have hResults : ∀ j : ℕ, (hj : j < m) → sGPhases.read (base + n + 1 + j) = results ⟨j, hj⟩ := fun j hj => by
255257 have hSaveGPhases_halted' : ∃ c : Config,
256258 Steps (saveInputs.concat gPhases) ⟨0 , State.fromInputs (List.ofFn inputs)⟩ c ∧
257259 c.isHalted (saveInputs.concat gPhases) ∧ c.state = cGPhases.state :=
258- ⟨⟨(saveInputs.concat gPhases).length, sGPhases⟩,
259- by convert hSaveGPhases_steps using 2 ; simp [Program.concat_length, hGPhases_pc, add_comm],
260- by simp, rfl⟩
260+ ⟨⟨(saveInputs.concat gPhases).length, sGPhases⟩, hpc_eq ▸ hSaveGPhases_steps, by simp, rfl⟩
261261 exact allGPhases_saves_result (pF := pF) hGs_sf hGs_spec inputs hGs_dom ⟨j, hj⟩ _ hSaveGPhases_halted'
262262 have hpF_max : pF.maxRegister ≤ base := compositionBase_ge_pF_max m n pF pGs
263263 have hm_le_base : m ≤ base + 1 := compositionBase_ge_m m n pF pGs
264264 obtain ⟨cFinal, hFinal_steps, hFinal_halted⟩ :=
265265 finalPhase_halts_from_results hF_sf hpF_max hm_le_base hF_halts sGPhases hResults
266266 have hSaveGPhases_steps' : Steps (saveInputs.concat gPhases) ⟨0 , State.fromInputs (List.ofFn inputs)⟩
267- ⟨(saveInputs.concat gPhases).length, sGPhases⟩ := by
268- convert hSaveGPhases_steps using 2 ; simp only [Program.concat_length, hGPhases_pc]; omega
269- have ⟨hTotal_steps, hTotal_halted⟩ := Steps.chain_concat hSaveGPhases_steps' (by simp)
270- rfl hFinal_steps hFinal_halted
267+ ⟨(saveInputs.concat gPhases).length, sGPhases⟩ := hpc_eq ▸ hSaveGPhases_steps
268+ have hSaveGPhases_halted' : (⟨(saveInputs.concat gPhases).length, sGPhases⟩ : Config).isHalted (saveInputs.concat gPhases) := by simp
269+ have ⟨hTotal_steps, hTotal_halted⟩ := Steps.chain_concat hSaveGPhases_steps' hSaveGPhases_halted' rfl hFinal_steps hFinal_halted
271270 rw [hH_eq, ← concat_assoc]; exact ⟨_, hTotal_steps, hTotal_halted⟩
272271
273272/-- The result of the composition equals the composed function value. -/
@@ -314,6 +313,8 @@ theorem comp_general_result
314313 have hn_le_base : n ≤ base + 1 := compositionBase_ge_n m n pF pGs
315314 have hGi_halts : ∀ i, Halts (pGs i) (List.ofFn inputs) := fun i => (hGs_spec i inputs).1 .mpr (hGs_dom i)
316315 have hGPhases_sf := allGPhases_isStandardForm (n := n) (base := base) hGs_sf
316+ have hSaveInputs_sf := saveInputs_isStandardForm base n
317+ have hSaveGPhases_sf := hSaveInputs_sf.concat hGPhases_sf
317318 have hSave_sl := copyRegisterRange_isStraightLine 0 (base + 1 ) n
318319 obtain ⟨cSave, hSave_steps, hSave_halted, hSave_pc'⟩ := straightLine_halts_from_state hSave_sl (State.fromInputs (List.ofFn inputs))
319320 have hNoOverlap' : 0 + n ≤ base + 1 := by simp; exact compositionBase_ge_n m n pF pGs
@@ -332,6 +333,8 @@ theorem comp_general_result
332333 have hGPhases_pc : cGPhases.pc = gPhases.length :=
333334 hGPhases_sf.pc_eq_length_of_halted hGPhases_steps (Nat.zero_le _) hGPhases_halted
334335 let sGPhases := cGPhases.state
336+ have hpc_eq : cGPhases.pc + saveInputs.length = (saveInputs.concat gPhases).length := by
337+ simp only [Program.concat_length, hGPhases_pc]; omega
335338 have hResults : ∀ j : ℕ, (hj : j < m) → sGPhases.read (base + n + 1 + j) = results ⟨j, hj⟩ := fun j hj => by
336339 have hSaveGPhases_halted' : ∃ c : Config,
337340 Steps (saveInputs.concat gPhases) ⟨0 , State.fromInputs (List.ofFn inputs)⟩ c ∧
@@ -377,9 +380,9 @@ theorem comp_general_result
377380 have ⟨hTransferF_steps, hTransferF_halted⟩ := Steps.chain_concat hTransfer_steps hTransfer_halted rfl epF.steps epF.halted
378381 have ⟨hClearTransferF_steps, hClearTransferF_halted⟩ := Steps.chain_concat hClear_steps hClear_halted hClear_pc hTransferF_steps hTransferF_halted
379382 have hSaveGPhases_steps' : Steps (saveInputs.concat gPhases) ⟨0 , State.fromInputs (List.ofFn inputs)⟩
380- ⟨(saveInputs.concat gPhases).length, sGPhases⟩ := by
381- convert hSaveGPhases_steps using 2 ; simp only [Program.concat_length, hGPhases_pc]; omega
382- have ⟨hTotal_steps, hTotal_halted⟩ := Steps.chain_concat hSaveGPhases_steps' ( by simp) rfl hClearTransferF_steps hClearTransferF_halted
383+ ⟨(saveInputs.concat gPhases).length, sGPhases⟩ := hpc_eq ▸ hSaveGPhases_steps
384+ have hSaveGPhases_halted' : (⟨(saveInputs.concat gPhases).length, sGPhases⟩ : Config).isHalted (saveInputs.concat gPhases) := by simp
385+ have ⟨hTotal_steps, hTotal_halted⟩ := Steps.chain_concat hSaveGPhases_steps' hSaveGPhases_halted' rfl hClearTransferF_steps hClearTransferF_halted
383386 rw [hH_eq, ← concat_assoc] at hH_steps hH_halted
384387 let cH_built : Config := ⟨(saveInputs.concat gPhases).length + final.length + epF.config.pc - pF.length, epF.config.state⟩
385388 have hcH_built_halted : cH_built.isHalted ((saveInputs.concat gPhases).concat final) := by
0 commit comments