Elm Exactly

TheoremtaskRed_none

StandardElmMech/Eff/Task.lean:259, The redex of a task · tactic proof

A well-formed task that is not an outcome has no reduction only when the application of r:e-task-andthen-succeed or r:e-task-onerror-fail at its redex has no result.

Statement

theorem taskRed_none {tk : Val} (hw : WFTask tk) (ho : tk.isOutcome = false)
    (hn : ∀ a t, ¬ TaskRed tk a t) :
    ∃ fs f v, (focus tk = some (fs, .andThen f (.succeed v)) ∨ focus tk = some (fs, .onError f (.fail v)))
      ∧ ¬ ∃ t, AppVal f v t

Proof

by
  induction hw with
  | succeed => simp [Val.isOutcome] at ho
  | fail => simp [Val.isOutcome] at ho
  | andThen f t ht ih =>
    cases hto : t.isOutcome
    · obtain ⟨fs, g, v, hf, hna⟩ := ih hto (fun a t' d => hn a _ (.r_e_task_andthen_inner _ _ _ _ d))
      refine ⟨.andThen f :: fs, g, v, ?_, hna⟩
      rcases hf with hf | hf
      · exact Or.inl (by simp [focus, hto, hf])
      · exact Or.inr (by simp [focus, hto, hf])
    · cases ht with
      | succeed v =>
        refine ⟨[], f, v, Or.inl (by simp [focus, Val.isOutcome]), ?_⟩
        rintro ⟨t', h⟩
        exact hn none t' (.r_e_task_andthen_succeed _ _ _ h)
      | fail v => exact absurd (.r_e_task_andthen_fail f v) (hn none _)
      | _ => simp [Val.isOutcome] at hto
  | onError f t ht ih =>
    cases hto : t.isOutcome
    · obtain ⟨fs, g, v, hf, hna⟩ := ih hto (fun a t' d => hn a _ (.r_e_task_onerror_inner _ _ _ _ d))
      refine ⟨.onError f :: fs, g, v, ?_, hna⟩
      rcases hf with hf | hf
      · exact Or.inl (by simp [focus, hto, hf])
      · exact Or.inr (by simp [focus, hto, hf])
    · cases ht with
      | fail v =>
        refine ⟨[], f, v, Or.inr (by simp [focus, Val.isOutcome]), ?_⟩
        rintro ⟨t', h⟩
        exact hn none t' (.r_e_task_onerror_fail _ _ _ h)
      | succeed v => exact absurd (.r_e_task_onerror_succeed f v) (hn none _)
      | _ => simp [Val.isOutcome] at hto
  | sleep v => exact absurd (.r_e_task_prim _ _ _ (.sleep v)) (hn _ _)
  | spawn t => exact absurd (.r_e_task_prim _ _ _ (.spawn t 0)) (hn _ _)
  | kill n => exact absurd (.r_e_task_prim _ _ _ (.kill n)) (hn _ _)

Proved with tactics, which Lean expands into a proof term that its kernel checks.

Rules of the book it uses

In StandardElmMech/Eff/Task.lean: Task reduction (TaskRed, 7 rules, r_e_task_*) and its logged twin, focus and plug, the property of task reduction (taskRed_iff, taskRed_outcome, taskRed_kind, taskRed_silent_same, taskRed_none), and the executable step stepTaskL, sound, complete and unique.

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.