@@ -85,15 +85,21 @@ theorem allGPhases_halts_from_saved_inputs {m n base : ℕ} {pGs : Fin m → Pro
8585 (hSaved : ∀ j : ℕ, (hj : j < n) → s.read (base + 1 + j) = inputs ⟨j, hj⟩) :
8686 ∃ c, Steps (allGPhases m n base pGs) ⟨0 , s⟩ c ∧ c.isHalted (allGPhases m n base pGs) := by
8787 induction m with
88- | zero => simp only [allGPhases, List.finRange_zero, List.foldl_nil]
89- exact ⟨⟨0 , s⟩, Relation.ReflTransGen.refl, by simp⟩
88+ | zero =>
89+ have hAllGPhases_zero : allGPhases 0 n base pGs = [] := by
90+ simp only [allGPhases, gPhaseList, List.finRange_zero, List.map_nil, List.prod_nil]; rfl
91+ simp only [hAllGPhases_zero]
92+ exact ⟨⟨0 , s⟩, Relation.ReflTransGen.refl, by simp⟩
9093 | succ m' ih =>
91- simp only [allGPhases]
92- rw [List.finRange_succ_last, List.foldl_append, List.foldl_map, List.foldl_cons, List.foldl_nil]
9394 let pGs' : Fin m' → Program := fun i => pGs i.castSucc
94- have hPrefix_eq : List.foldl (fun x y => Program.concat x (gPhase base n (pGs y.castSucc) ↑y.castSucc))
95- [] (List.finRange m') = allGPhases m' n base pGs' := rfl
96- rw [hPrefix_eq]
95+ have hAllGPhases_succ : allGPhases (m' + 1 ) n base pGs =
96+ (allGPhases m' n base pGs').concat (gPhase base n (pGs (Fin.last m')) m') := by
97+ simp only [allGPhases, gPhaseList]
98+ rw [List.finRange_succ_last, List.map_append, List.map_singleton, List.prod_append, List.prod_singleton]
99+ show (Program.concat _ _) = (Program.concat _ _)
100+ simp only [List.map_map, Fin.val_last, Function.comp_def]
101+ rfl
102+ rw [hAllGPhases_succ]
97103 obtain ⟨cPrefix, hPrefix_steps, hPrefix_halted⟩ := ih (fun i => hpGs_sf i.castSucc)
98104 (fun i => hpGs_max i.castSucc) (fun i => hpGs_halts i.castSucc)
99105 have hPrefix_sf := allGPhases_isStandardForm (n := n) (base := base) (fun i => hpGs_sf i.castSucc)
@@ -144,20 +150,23 @@ theorem allGPhases_suffix_preserves_earlier_results {m n base : ℕ} {pGs : Fin
144150 (hhalted : c'.isHalted (allGPhases_suffix m n base pGs start)) :
145151 c'.state.read (base + n + 1 + k) = s.read (base + n + 1 + k) := by
146152 match m with
147- | 0 => simp only [allGPhases_suffix, List.finRange_zero, List.drop_nil, List.foldl_nil] at hsteps hhalted
148- rw [Steps.halts_unique hsteps hhalted Relation.ReflTransGen.refl (by simp)]
153+ | 0 =>
154+ have hSuffix_zero : allGPhases_suffix 0 n base pGs start = [] := by
155+ simp only [allGPhases_suffix, gPhaseList, List.finRange_zero, List.drop_nil, List.map_nil, List.prod_nil]; rfl
156+ simp only [hSuffix_zero] at hsteps hhalted
157+ rw [Steps.halts_unique hsteps hhalted Relation.ReflTransGen.refl (by simp)]
149158 | Nat.succ m' =>
150159 by_cases hEmpty : start ≥ m' + 1
151160 · have hSuffix_empty : allGPhases_suffix (m' + 1 ) n base pGs start = [] := by
152- simp only [allGPhases_suffix]; rw [List.drop_eq_nil_of_le (by simp; omega)]; rfl
161+ simp only [allGPhases_suffix, gPhaseList]
162+ rw [List.drop_eq_nil_of_le (by simp; omega)]
163+ rfl
153164 rw [hSuffix_empty] at hsteps hhalted
154165 rw [Steps.halts_unique hsteps hhalted Relation.ReflTransGen.refl (by simp)]
155166 · push_neg at hEmpty
156167 have hSuffix_decomp : allGPhases_suffix (m' + 1 ) n base pGs start =
157- (gPhase base n (pGs ⟨start, hEmpty⟩) start).concat (allGPhases_suffix (m' + 1 ) n base pGs (start + 1 )) := by
158- simp only [allGPhases_suffix]
159- rw [List.drop_eq_getElem_cons (by simp; exact hEmpty), List.foldl_cons, foldl_concat_eq_acc_concat]
160- simp only [concat_nil_left, List.getElem_finRange]; congr 2
168+ (gPhase base n (pGs ⟨start, hEmpty⟩) start).concat (allGPhases_suffix (m' + 1 ) n base pGs (start + 1 )) :=
169+ allGPhases_suffix_cons pGs start hEmpty
161170 rw [hSuffix_decomp] at hsteps hhalted
162171 let dFirst := decompose_concat hsteps hhalted (gPhase_isStandardForm (hpGs_sf ⟨start, hEmpty⟩))
163172 obtain ⟨cRest, hRest_steps, hRest_halted⟩ := dFirst.halts_right
@@ -198,11 +207,8 @@ theorem allGPhases_saves_result {m n : ℕ} [NeZero m] {pF : Program} {pGs : Fin
198207 obtain ⟨sSavePrefix, hSavePrefix_steps, cSuffix, hSuffix_steps, hSuffix_halted⟩ :=
199208 suffix_of_concat_from_zero hsteps hhalted hSavePrefix_sf
200209 have hPrefixDecomp : allGPhases_prefix m n base pGs (i.val + 1 ) =
201- (allGPhases_prefix m n base pGs i.val).concat (gPhase base n (pGs i) i.val) := by
202- simp only [allGPhases_prefix]
203- rw [List.take_succ_eq_append_getElem (by simp : i.val < (List.finRange m).length),
204- List.foldl_append, List.foldl_cons, List.foldl_nil, foldl_concat_eq_acc_concat]
205- simp only [List.getElem_finRange]; congr 1
210+ (allGPhases_prefix m n base pGs i.val).concat (gPhase base n (pGs i) i.val) :=
211+ allGPhases_prefix_succ pGs i.val i.isLt
206212 have hSavePrefixI_sf := hSave_sf.concat (allGPhases_prefix_isStandardForm (n := n) (base := base) hGs_sf i.val)
207213 have hSavePrefix_eq : saveInputs.concat (allGPhases_prefix m n base pGs (i.val + 1 )) =
208214 (saveInputs.concat (allGPhases_prefix m n base pGs i.val)).concat (gPhase base n (pGs i) i.val) := by
@@ -229,7 +235,9 @@ theorem allGPhases_saves_result {m n : ℕ} [NeZero m] {pF : Program} {pGs : Fin
229235 have hSaved_i : ∀ k : ℕ, (hk : k < n) → sSavePrefixI.read (base + 1 + k) = inputs ⟨k, hk⟩ := by
230236 intro k hk
231237 by_cases hi_zero : i.val = 0
232- · simp only [hi_zero, allGPhases_prefix, List.take_zero, List.foldl_nil, concat_nil_right] at hSavePrefixI_steps
238+ · have hPrefix_zero : allGPhases_prefix m n base pGs 0 = [] := by
239+ simp only [allGPhases_prefix, gPhaseList, List.take_zero, List.map_nil, List.prod_nil]; rfl
240+ simp only [hi_zero, hPrefix_zero, concat_nil_right] at hSavePrefixI_steps
233241 rw [show sSavePrefixI = cSave.state from
234242 congrArg Config.state (Steps.halts_unique hSavePrefixI_steps (by simp) hSave_steps' hSave_halted'),
235243 hSave_state_sSave, hAfterSave k hk]
0 commit comments