open Term
Env.lookup x (pre ++ l) = (Env.lookup x pre).or (Env.lookup x l) :=
Env.lookup x ((s, y) :: l) = if x = s then some y else Env.lookup x l := rfl
(h : Not (x = s) \/ Not (Env.lookup s pre = none)) :
Env.lookup x (pre ++ (s, y) :: post) = Env.lookup x (pre ++ (s, z) :: post) := by
. subst hx
cases hp : Env.lookup x pre with
| dat (n : Nat) : Sim (dat n) (dat n)
| sym (s : Nat) : Sim (sym s) (sym s)
| ign : Sim ign ign
| nil : Sim nil nil
| env {bs bs' : Env} :
(forall s, Env.lookup s bs = none <-> Env.lookup s bs' = none) ->
(forall s u u', Env.lookup s bs = some u -> Env.lookup s bs' = some u' -> Sim u u') ->
Sim (env bs) (env bs')
| oper {a a' b b' c c' d d' : Term} :
| comb {a a' b b' c c' : Term} :
(forall s, Env.lookup s bs = none <-> Env.lookup s bs' = none) /\
(forall s u u', Env.lookup s bs = some u -> Env.lookup s bs' = some u' -> Sim u u')
Sim.env h.1 h.2
theorem Sim.envSim {bs bs' : Env} (h : Sim (Term.env bs) (Term.env bs')) : EnvSim bs bs' := by¶ node
namespace Sim
exact reflLookup bs s u h1)
| .app t => .app (refl t)
| .capsule k v => .capsule k (refl v)
theorem reflLookup : forall (bs : Env) (s : Nat) (u : Term), Env.lookup s bs = some u -> Sim u u¶ node
| [], _, _, h => by simp [Env.lookup] at h
rw [lookup_cons] at h
exact refl t
exact reflLookup r s u h
exact reflLookup bs' s u h1)
Sim (VauE.evalList e ts) (VauE.evalList e' ts') := by
. rw [Env.lookup_join, Env.lookup_join]
cases h1 : Env.lookup s a with
cases h1' : Env.lookup s a' with
. rw [Env.lookup_join] at h1 h2
cases ha1 : Env.lookup s a with
cases ha1' : Env.lookup s a' with
Sim t t' -> exists m', VauE.ematch p' t' = some m' /\ EnvSim m m'
simp only [VauE.ematch] at hm; cases hm
(fun s u u' h1 _ => by simp [Env.lookup] at h1)))
cases t <;> simp [VauE.ematch] at hm
(fun s u u' h1 _ => by simp [Env.lookup] at h1)))
simp only [VauE.ematch] at hm; cases hm
. simp only [Env.lookup]
. simp only [Env.lookup] at h1 h2
simp only [VauE.ematch] at hm
Exists.intro (Env.join m1' m2') (And.intro
(by simp only [VauE.ematch, syms_eq ha, syms_eq hb, hdis, if_true, h1'.1, h2'.1])
(join h1'.2 h2'.2))
| _ => simp [VauE.ematch] at hm
| .dat _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .prim _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .env _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .oper _ _ _ _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .app _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .eval _ _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .comb _ _ _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
| .capsule _ _, _, _, _, _, hm, _, _ => by simp [VauE.ematch] at hm
exists r', VauE.buildListStar x' = some r' /\ Sim r r'
simp only [VauE.buildListStar] at hb; cases hb
simp only [VauE.buildListStar, Option.map_eq_some_iff] at hb
(buildListStar hr0.1 (.pair hc hd)).elim fun r1 hr1 => by
. simp only [VauE.buildListStar, hr1.1, Option.map_some]
| _ => simp [VauE.buildListStar] at hb
| .dat _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .prim _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .sym _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .ign, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .nil, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .env _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .oper _ _ _ _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .app _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .eval _ _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .comb _ _ _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
| .capsule _ _, _, _, hb, _ => by simp [VauE.buildListStar] at hb
theorem isCapsuleOf_eq {k : Nat} {x x' : Term} (h : Sim x x') : isCapsuleOf k x' = isCapsuleOf k x := by¶ node
theorem capsCheck : forall {k : Nat} {vs vs' : Term} {b : Bool}, VauE.capsCheck k vs = some b ->¶ node
Sim vs vs' -> VauE.capsCheck k vs' = some b
simp only [VauE.capsCheck, Option.map_eq_some_iff] at hc
simp only [VauE.capsCheck, capsCheck hb0.1 h2, Option.map_some, isCapsuleOf_eq h1]
| _, .dat _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .prim _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .sym _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .ign, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .env _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .oper _ _ _ _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .app _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .eval _ _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .comb _ _ _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
| _, .capsule _ _, _, _, hc, _ => by simp [VauE.capsCheck] at hc
end Sim
| (s', t) :: r => if s = s' then (s', v) :: r else (s', t) :: Env.update s v r
Env.lookup s bs = some u -> Env.lookup s (Env.update s v bs) = some v
| [], h => by simp [Env.lookup] at h
simp only [Env.update]
. rw [if_pos hs, lookup_cons, if_pos hs]
. rw [if_neg hs, lookup_cons, if_neg hs]
rw [lookup_cons, if_neg hs] at h
exact lookup_update_same h
Env.lookup x (Env.update s v bs) = Env.lookup x bs
simp only [Env.update]
. rw [if_pos hs, lookup_cons, lookup_cons]
subst hs
. rw [if_neg hs, lookup_cons, lookup_cons, lookup_update_other hx]
Env.lookup s bs = some u -> Steps (env bs) (env (Env.update s v bs))
| [], h => by simp [Env.lookup] at h
simp only [Env.update]
rw [lookup_cons, if_pos hs] at h
exact Steps.envCons hv (Steps.refl _)
rw [lookup_cons, if_neg hs] at h
exact Steps.envCons (Steps.refl t) (steps_update hv h)
exact Exists.intro _ (And.intro (Steps.top (.evalSelf _ (ha.selfEval hse))) ha)
cases hb : Env.lookup x bs' with
| some w => exact Exists.intro w (And.intro (Steps.top (.evalSym hb)) (hsm x _ _ hl hb))
exact Exists.intro _ (And.intro (Steps.top (.evalPair _ _ _))
exact Exists.intro _ (And.intro (Steps.top (.evalApp _ _)) (.app (.eval h1 (.env hn hsm))))
exact (Sim.ematch hm (.pair h1 h2) (.pair hx (.env hn2 hsm2))).elim fun m' hm' =>
(Steps.top (.beta (h1.isValue hv1) (h2.isValue hv2) (hx.isValue hv3) hm'.1))
(.eval h3 (Sim.ofEnvSim (Sim.join hm'.2 (And.intro hn1 hsm1)))))
exact Exists.intro _ (And.intro (Steps.top (.combApp _ _ (hx.isList hl)))
(.comb h1 (Sim.evalList (.env hn hsm) hx hl) (.env hn hsm)))
(Steps.top (.deltaVau _ (h1.isValue hv1) (h2.isValue hv2) (h3.isValue hv3)))
exact Exists.intro _ (And.intro (Steps.top (.deltaWrap _ (h1.isValue hv))) (.app h1))
exact Exists.intro _ (And.intro (Steps.top (.deltaUnwrap _ (h2.isValue hv))) h2)
exact Exists.intro _ (And.intro (Steps.top (.deltaEval _ _ (h1.isValue hv)))
exact (Sim.buildListStar hr hx).elim fun r' hr' =>
Exists.intro r' (And.intro (Steps.top (.deltaListStar _ (hx.isValue hv) hr'.1)) hr'.2)
exact Exists.intro _ (And.intro (Steps.top (.deltaEncap k _ (h1.isValue hv))) (.capsule k h1))
(Steps.top (.deltaIsEncap k _ (hx.isValue hv) (Sim.capsCheck hc hx))) (.dat _))
exact Exists.intro _ (And.intro (Steps.top (.deltaDecap k _)) h2)
(hs : Sim (env (pre ++ (s, a) :: post)) t') :
by_cases hv : Env.lookup s pre = none
. have hla : Env.lookup s (pre ++ (s, a) :: post) = some a := by
rw [lookup_append, hv, lookup_cons, if_pos rfl]; rfl
cases hb : Env.lookup s bs' with
refine Exists.intro (env (Env.update s a1' bs')) (And.intro (steps_update h1.1 hb) ?_)
refine Sim.env (fun x => ?_) (fun x u u' hu hu' => ?_)
. subst hx
rw [lookup_append, hv, lookup_cons, if_pos rfl, lookup_update_same hb]
. rw [lookup_replace (Or.inl hx) (z := a), lookup_update_other hx]
. subst hx
rw [lookup_append, hv, lookup_cons, if_pos rfl] at hu
rw [lookup_update_same hb] at hu'
. rw [lookup_replace (Or.inl hx) (z := a)] at hu
rw [lookup_update_other hx] at hu'
. refine Exists.intro (env bs') (And.intro (Steps.refl _) ?_)
refine Sim.env (fun x => ?_) (fun x u u' hu hu' => ?_)
. rw [lookup_replace (Or.inr hv) (z := a)]; exact hn x
. rw [lookup_replace (Or.inr hv) (z := a)] at hu; exact hsm x u u' hu hu'
refine And.intro (fun t' ht => sim_top h ht) (fun l l1 e1 _ => ?_)
subst e1
refine And.intro (fun t' ht => env_sim_step (pre := []) ih.1 ht) (fun l l1 e1 e2 => ?_)
refine And.intro (fun t' ht => env_sim_step (pre := b :: pre) ha1.2.2 ht)
(And.intro (Steps.oper h1.1 (Steps.refl _) (Steps.refl _) (Steps.refl _)) (.oper h1.2 hb hc hd))
(And.intro (Steps.oper (Steps.refl _) h1.1 (Steps.refl _) (Steps.refl _)) (.oper ha h1.2 hc hd))
(And.intro (Steps.oper (Steps.refl _) (Steps.refl _) h1.1 (Steps.refl _)) (.oper ha hb h1.2 hd))
(And.intro (Steps.oper (Steps.refl _) (Steps.refl _) (Steps.refl _) h1.1) (.oper ha hb hc h1.2))
(And.intro (Steps.pair h1.1 (Steps.refl _)) (.pair h1.2 hb))
(And.intro (Steps.pair (Steps.refl _) h1.1) (.pair ha h1.2))
exact (ih.1 _ ha).elim fun a1 h1 => Exists.intro _ (And.intro (Steps.app h1.1) (.app h1.2))
(And.intro (Steps.eval h1.1 (Steps.refl _)) (.eval h1.2 hb))
(And.intro (Steps.eval (Steps.refl _) h1.1) (.eval ha h1.2))
(And.intro (Steps.comb3 h1.1 (Steps.refl _) (Steps.refl _)) (.comb h1.2 hb hc))
(And.intro (Steps.comb3 (Steps.refl _) h1.1 (Steps.refl _)) (.comb ha h1.2 hc))
(And.intro (Steps.comb3 (Steps.refl _) (Steps.refl _) h1.1) (.comb ha hb h1.2))
(And.intro (Steps.capsule h1.1) (.capsule k h1.2))
| refl => exact Exists.intro t' (And.intro (Steps.refl _) hs)
exact ih.elim fun v' hv => ((sim_step hstep).1 v' hv.2).elim fun w' hw =>
| hole : Ctx
| .envAt pre s c post, t => Term.env (pre ++ (s, c.plug t) :: post)
| .oper1 c b c' d, t => Term.oper (c.plug t) b c' d
| .oper2 a c c' d, t => Term.oper a (c.plug t) c' d
| .oper3 a b c d, t => Term.oper a b (c.plug t) d
| .oper4 a b c' c, t => Term.oper a b c' (c.plug t)
| .pairL c b, t => Term.pair (c.plug t) b
| .pairR a c, t => Term.pair a (c.plug t)
| .app c, t => Term.app (c.plug t)
| .evalL c b, t => Term.eval (c.plug t) b
| .evalR a c, t => Term.eval a (c.plug t)
| .comb1 c b c', t => Term.comb (c.plug t) b c'
| .comb2 a c c', t => Term.comb a (c.plug t) c'
| .comb3 a b c, t => Term.comb a b (c.plug t)
| .capsule k c, t => Term.capsule k (c.plug t)
refine Sim.env (fun x => ?_) (fun x u u' hu hu' => ?_)
. rw [lookup_append, lookup_append, lookup_cons, lookup_cons]
cases Env.lookup x pre with
. rw [lookup_append, lookup_cons] at hu hu'
cases hp : Env.lookup x pre with
exact Sim.reflLookup pre x w hp
exact Sim.reflLookup post x u hu
| envAt pre s c post ih => exact Sim.envAt ih
| pairL c b ih => exact .pair ih (Sim.refl _)
| pairR a c ih => exact .pair (Sim.refl _) ih
| evalL c b ih => exact .eval ih (Sim.refl _)
| evalR a c ih => exact .eval (Sim.refl _) ih
(Sim.steps hs h).elim fun u' hu => by
theorem env_opacity {bs bs' : Env} (h : forall s, Env.lookup s bs = Env.lookup s bs') (c : Ctx)¶ plain English
Iff.intro (Sim.observe (Sim.plug c (Sim.of_lookup_eq h)))
(Sim.observe (Sim.plug c (Sim.of_lookup_eq (fun s => (h s).symm))))
Steps (c.plug (env ((s, a) :: (s, b) :: r))) (dat n) <-> Steps (c.plug (env ((s, a) :: r))) (dat n) :=
env_opacity (fun x => by by_cases hx : x = s <;> simp [lookup_cons, hx]) c n
refine env_opacity (fun x => ?_) c n
. subst h1; simp [lookup_cons, hne]
. subst h2; simp [lookup_cons, h1]
. simp [lookup_cons, h1, h2]
| ign => simp only [ematch] at h; cases h; exact Or.inl (And.intro rfl rfl)
| sym s => simp only [ematch] at h; cases h; exact Or.inr (Exists.intro s (And.intro rfl rfl))
| _ => simp [ematch] at h
refine And.intro (Steps.top (.evalSym rfl)) (fun h => ?_)
Steps.top (.evalSym rfl)
have := normal_unique h h6 (normal_dat 5) (normal_dat 6)
theorem ignore_hygiene {p v b : Term} {e1 e2 e3 m : Env} (hp : IsValue p) (hv : IsValue v)¶ plain English
(hm : ematch p v = some m) :
simp only [ematch, syms, disjoint_nil, hm, if_true]
have h2 := Top.beta (body := b) (e1 := e1) hp .ign hv (key e2)
have h3 := Top.beta (body := b) (e1 := e1) hp .ign hv (key e3)
rw [Env.join_emp] at h2 h3
theorem ignore_hygiene_conv {p v b : Term} {e1 e2 e3 m : Env} (hp : IsValue p) (hv : IsValue v)¶ node
(hm : ematch p v = some m) :
Conv (comb (oper p ign b (env e1)) v (env e2)) (comb (oper p ign b (env e1)) v (env e3)) :=
let h := ignore_hygiene (b := b) (e1 := e1) (e2 := e2) (e3 := e3) hp hv hm
Vau.EqvGen.trans h.1.toEqvGen (Vau.EqvGen.symm h.2.toEqvGen)