Elm Exactly

TheoremnoDeriv_scope2

StandardElmMech/Stat/RefuseScope.lean:1652, Two modules: the second module's imports, or its body, fail for every derivation of the first · tactic proof

Statement

theorem noDeriv_scope2 {B : SBasis} {m1 m2 : BModule} (h : scope2 B m1 m2 = true) :
    ∀ a1 B' E, a1.erase = m1 → checkModule B a1 = true → a1.result B = some (B', E) →
      NoDeriv (B.plus B') m2

Proof

by
  intro a1 B' E he1 _ hr
  obtain ⟨C, E', PE, I, hd, hI, hME⟩ := result_inv hr
  have hh : a1.header = m1.header := by rw [← he1]; rfl
  have hb : a1.body.map ATopDec.erase = m1.body := by rw [← he1]; rfl
  unfold scope2 at h
  cases hs : helperSk m1 with
  | none => rw [hs] at h; cases h
  | some s =>
    rw [hs] at h
    simp only at h
    -- the skeleton of the first module's interface
    have hsk : s = skI I := by
      rw [hh] at hI
      cases hx : m1.header.exposing with
      | all => simp only [helperSk, hx] at hs; cases hs
      | items is =>
        simp only [helperSk, hx] at hs
        rw [hx] at hI
        have hT := teSk_topOpt hd
        rw [hb] at hT
        have := exposeItems_sk hT is I hI
        rw [hs] at this
        exact (Option.some.inj this)
    have hme : (fun mid => (FMap.find? (B.plus B').ME mid).map skI) = meSk B m1.header.name s := by
      funext mid
      simp only [SBasis.plus, meSk, hME, FMap.find?_modify, FMap.find?, hh, hsk]
      by_cases e : m1.header.name = mid <;> simp [e]
    intro a2 he2
    have him : a2.imports = m2.imports := by rw [← he2]; rfl
    unfold checkModule AModule.result importCtx
    rw [elabImports_sk, hme, him]
    cases hπ : elabImportsSk (meSk B m1.header.name s) π0 (defaultImports ++ m2.imports) with
    | none => rfl
    | some π =>
      rw [hπ] at h
      simp only [Bool.not_eq_true'] at h
      simp only [Option.map_some]
      have hb2 : a2.body.map ATopDec.erase = m2.body := by rw [← he2]; rfl
      unfold AModule.resultIn
      cases hd2 : checkTopDecOpt (modCtx (B.plus B') π) a2.body with
      | none => rfl
      | some EP =>
        obtain ⟨E2, PE2⟩ := EP
        have := sc_topOpt (abs_piShape (B.plus B') π) hd2
        rw [hb2, h] at this
        cases this

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

Theorems it uses

In StandardElmMech/Stat/RefuseScope.lean: Refusals by scope, constructor arity and imports, for one module and for a module after a helper (scopeFailB).

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.