agda style

This commit is contained in:
Jeremy Siek 2019-08-20 15:37:15 -04:00
parent b88cd2478b
commit 69da80df93

View file

@ -32,12 +32,13 @@ open import Data.Product using (_×_; Σ; Σ-syntax; ∃; ∃-syntax; proj₁; p
open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit using (; tt) open import Data.Unit using (; tt)
open import plfa.part2.Untyped open import plfa.part2.Untyped
using (Context; _,_; ★; _∋_; _⊢_; `_; ƛ_; _·_) using (Context; _,_; ★; _∋_; _⊢_; `_; ƛ_; _·_)
open import plfa.part3.Denotational open import plfa.part3.Denotational
using (Value; _↦_; _`,_; _⊔_; ⊥; _⊑_; _⊢_↓_; using (Value; _↦_; _`,_; _⊔_; ⊥; _⊑_; _⊢_↓_;
⊑-bot; ⊑-fun; ⊑-conj-L; ⊑-conj-R1; ⊑-conj-R2; ⊑-dist; ⊑-refl; ⊑-trans; ⊔↦⊔-dist; ⊑-bot; ⊑-fun; ⊑-conj-L; ⊑-conj-R1; ⊑-conj-R2;
var; ↦-intro; ↦-elim; ⊔-intro; ⊥-intro; sub; ⊑-dist; ⊑-refl; ⊑-trans; ⊔↦⊔-dist;
up-env; ; _≃_; ≃-sym; Denotation; Env) var; ↦-intro; ↦-elim; ⊔-intro; ⊥-intro; sub;
up-env; ; _≃_; ≃-sym; Denotation; Env)
open plfa.part3.Denotational.≃-Reasoning open plfa.part3.Denotational.≃-Reasoning
``` ```
@ -80,10 +81,10 @@ derivation of `u ⊑ v`, using the `up-env` lemma in the case for the
``` ```
sub- : ∀{Γ}{N : Γ , ★ ⊢ ★}{γ v u} sub- : ∀{Γ}{N : Γ , ★ ⊢ ★}{γ v u}
( N) γ v ( N) γ v
→ u ⊑ v → u ⊑ v
------------ ------------
( N) γ u ( N) γ u
sub- d ⊑-bot = tt sub- d ⊑-bot = tt
sub- d (⊑-fun lt lt) = sub (up-env d lt) lt sub- d (⊑-fun lt lt) = sub (up-env d lt) lt
sub- d (⊑-conj-L lt lt₁) = ⟨ sub- d lt , sub- d lt₁ ⟩ sub- d (⊑-conj-L lt lt₁) = ⟨ sub- d lt , sub- d lt₁ ⟩
@ -108,9 +109,9 @@ rule.
``` ```
ℰƛ→ℱℰ : ∀{Γ}{γ : Env Γ}{N : Γ , ★ ⊢ ★}{v : Value} ℰƛ→ℱℰ : ∀{Γ}{γ : Env Γ}{N : Γ , ★ ⊢ ★}{v : Value}
(ƛ N) γ v (ƛ N) γ v
------------ ------------
( N) γ v ( N) γ v
ℰƛ→ℱℰ (↦-intro d) = d ℰƛ→ℱℰ (↦-intro d) = d
ℰƛ→ℱℰ ⊥-intro = tt ℰƛ→ℱℰ ⊥-intro = tt
ℰƛ→ℱℰ (⊔-intro d₁ d₂) = ⟨ ℰƛ→ℱℰ d₁ , ℰƛ→ℱℰ d₂ ⟩ ℰƛ→ℱℰ (⊔-intro d₁ d₂) = ⟨ ℰƛ→ℱℰ d₁ , ℰƛ→ℱℰ d₂ ⟩
@ -135,9 +136,9 @@ the value v.
``` ```
ℱℰ→ℰƛ : ∀{Γ}{γ : Env Γ}{N : Γ , ★ ⊢ ★}{v : Value} ℱℰ→ℰƛ : ∀{Γ}{γ : Env Γ}{N : Γ , ★ ⊢ ★}{v : Value}
( N) γ v ( N) γ v
------------ ------------
(ƛ N) γ v (ƛ N) γ v
ℱℰ→ℰƛ {v = ⊥} d = ⊥-intro ℱℰ→ℰƛ {v = ⊥} d = ⊥-intro
ℱℰ→ℰƛ {v = v₁ ↦ v₂} d = ↦-intro d ℱℰ→ℰƛ {v = v₁ ↦ v₂} d = ↦-intro d
ℱℰ→ℰƛ {v = v₁ ⊔ v₂} ⟨ d1 , d2 ⟩ = ⊔-intro (ℱℰ→ℰƛ d1) (ℱℰ→ℰƛ d2) ℱℰ→ℰƛ {v = v₁ ⊔ v₂} ⟨ d1 , d2 ⟩ = ⊔-intro (ℱℰ→ℰƛ d1) (ℱℰ→ℰƛ d2)
@ -148,7 +149,7 @@ to lambda abstraction, as witnessed by the function ``.
``` ```
lam-equiv : ∀{Γ}{N : Γ , ★ ⊢ ★} lam-equiv : ∀{Γ}{N : Γ , ★ ⊢ ★}
(ƛ N) ≃ ( N) (ƛ N) ≃ ( N)
lam-equiv γ v = ⟨ ℰƛ→ℱℰ , ℱℰ→ℰƛ ⟩ lam-equiv γ v = ⟨ ℰƛ→ℱℰ , ℱℰ→ℰƛ ⟩
``` ```
@ -193,9 +194,9 @@ describe the proof below.
``` ```
ℰ·→●ℰ : ∀{Γ}{γ : Env Γ}{L M : Γ ⊢ ★}{v : Value} ℰ·→●ℰ : ∀{Γ}{γ : Env Γ}{L M : Γ ⊢ ★}{v : Value}
(L · M) γ v (L · M) γ v
---------------- ----------------
→ ( L ● M) γ v → ( L ● M) γ v
ℰ·→●ℰ (↦-elim{v = v} d₁ d₂) = inj₂ ⟨ v , ⟨ d₁ , d₂ ⟩ ⟩ ℰ·→●ℰ (↦-elim{v = v} d₁ d₂) = inj₂ ⟨ v , ⟨ d₁ , d₂ ⟩ ⟩
ℰ·→●ℰ {v = ⊥} ⊥-intro = inj₁ ⊑-bot ℰ·→●ℰ {v = ⊥} ⊥-intro = inj₁ ⊑-bot
ℰ·→●ℰ {Γ}{γ}{L}{M}{v} (⊔-intro{v = v₁}{w = v₂} d₁ d₂) ℰ·→●ℰ {Γ}{γ}{L}{M}{v} (⊔-intro{v = v₁}{w = v₂} d₁ d₂)
@ -273,9 +274,9 @@ Otherwise, we conclude immediately by rule `↦-elim`.
``` ```
●ℰ→ℰ· : ∀{Γ}{γ : Env Γ}{L M : Γ ⊢ ★}{v} ●ℰ→ℰ· : ∀{Γ}{γ : Env Γ}{L M : Γ ⊢ ★}{v}
→ ( L ● M) γ v → ( L ● M) γ v
---------------- ----------------
(L · M) γ v (L · M) γ v
●ℰ→ℰ· {γ}{v} (inj₁ lt) = sub ⊥-intro lt ●ℰ→ℰ· {γ}{v} (inj₁ lt) = sub ⊥-intro lt
●ℰ→ℰ· {γ}{v} (inj₂ ⟨ v₁ , ⟨ d1 , d2 ⟩ ⟩) = ↦-elim d1 d2 ●ℰ→ℰ· {γ}{v} (inj₂ ⟨ v₁ , ⟨ d1 , d2 ⟩ ⟩) = ↦-elim d1 d2
``` ```
@ -285,7 +286,7 @@ function application, as witnessed by the `●` function.
``` ```
app-equiv : ∀{Γ}{L M : Γ ⊢ ★} app-equiv : ∀{Γ}{L M : Γ ⊢ ★}
(L · M) ≃ ( L) ● ( M) (L · M) ≃ ( L) ● ( M)
app-equiv γ v = ⟨ ℰ·→●ℰ , ●ℰ→ℰ· ⟩ app-equiv γ v = ⟨ ℰ·→●ℰ , ●ℰ→ℰ· ⟩
``` ```
@ -308,8 +309,7 @@ To round-out the semantic equations, we establish the following one
for variables. for variables.
``` ```
var-equiv : ∀{Γ}{x : Γ ∋ ★} var-equiv : ∀{Γ}{x : Γ ∋ ★} → (` x) ≃ (λ γ v → v ⊑ γ x)
(` x) ≃ (λ γ v → v ⊑ γ x)
var-equiv γ v = ⟨ var-inv , (λ lt → sub var lt) ⟩ var-equiv γ v = ⟨ var-inv , (λ lt → sub var lt) ⟩
``` ```
@ -332,17 +332,17 @@ whether `` is a congruence.
``` ```
-cong : ∀{Γ}{D D : Denotation (Γ , ★)} -cong : ∀{Γ}{D D : Denotation (Γ , ★)}
→ D ≃ D → D ≃ D
----------- -----------
D ≃ D D ≃ D
-cong{Γ} D≃D γ v = -cong{Γ} D≃D γ v =
⟨ (λ x → ℱ≃{γ}{v} x D≃D) , (λ x → ℱ≃{γ}{v} x (≃-sym D≃D)) ⟩ ⟨ (λ x → ℱ≃{γ}{v} x D≃D) , (λ x → ℱ≃{γ}{v} x (≃-sym D≃D)) ⟩
where where
ℱ≃ : ∀{γ : Env Γ}{v}{D D : Denotation (Γ , ★)} ℱ≃ : ∀{γ : Env Γ}{v}{D D : Denotation (Γ , ★)}
D γ v → D ≃ D D γ v D γ v → D ≃ D D γ v
ℱ≃ {v = ⊥} fd dd = tt ℱ≃ {v = ⊥} fd dd = tt
ℱ≃ {γ}{v ↦ w} fd dd = proj₁ (dd (γ `, v) w) fd ℱ≃ {γ}{v ↦ w} fd dd = proj₁ (dd (γ `, v) w) fd
ℱ≃ {γ}{u ⊔ w} fd dd = ⟨ ℱ≃{γ}{u} (proj₁ fd) dd , ℱ≃{γ}{w} (proj₂ fd) dd ℱ≃ {γ}{u ⊔ w} fd dd = ⟨ ℱ≃{γ}{u} (proj₁ fd) dd , ℱ≃{γ}{w} (proj₂ fd) dd
``` ```
The proof of `-cong` uses the lemma `ℱ≃` to handle both directions of The proof of `-cong` uses the lemma `ℱ≃` to handle both directions of
@ -354,9 +354,9 @@ equational reasoning.
``` ```
lam-cong : ∀{Γ}{N N : Γ , ★ ⊢ ★} lam-cong : ∀{Γ}{N N : Γ , ★ ⊢ ★}
N ≃ N N ≃ N
----------------- -----------------
(ƛ N) ≃ (ƛ N) (ƛ N) ≃ (ƛ N)
lam-cong {Γ}{N}{N} N≃N = lam-cong {Γ}{N}{N} N≃N =
start start
(ƛ N) (ƛ N)
@ -377,17 +377,17 @@ is a congruence.
``` ```
●-cong : ∀{Γ}{D₁ D₁ D₂ D₂ : Denotation Γ} ●-cong : ∀{Γ}{D₁ D₁ D₂ D₂ : Denotation Γ}
→ D₁ ≃ D₁ → D₂ ≃ D₂ → D₁ ≃ D₁ → D₂ ≃ D₂
→ (D₁ ● D₂) ≃ (D₁ ● D₂) → (D₁ ● D₂) ≃ (D₁ ● D₂)
●-cong {Γ} d1 d2 γ v = ⟨ (λ x → ●≃ x d1 d2) , ●-cong {Γ} d1 d2 γ v = ⟨ (λ x → ●≃ x d1 d2) ,
(λ x → ●≃ x (≃-sym d1) (≃-sym d2)) ⟩ (λ x → ●≃ x (≃-sym d1) (≃-sym d2)) ⟩
where where
●≃ : ∀{γ : Env Γ}{v}{D₁ D₁ D₂ D₂ : Denotation Γ} ●≃ : ∀{γ : Env Γ}{v}{D₁ D₁ D₂ D₂ : Denotation Γ}
→ (D₁ ● D₂) γ v → D₁ ≃ D₁ → D₂ ≃ D₂ → (D₁ ● D₂) γ v → D₁ ≃ D₁ → D₂ ≃ D₂
→ (D₁ ● D₂) γ v → (D₁ ● D₂) γ v
●≃ (inj₁ v⊑⊥) eq₁ eq₂ = inj₁ v⊑⊥ ●≃ (inj₁ v⊑⊥) eq₁ eq₂ = inj₁ v⊑⊥
●≃ {γ} {w} (inj₂ ⟨ v , ⟨ Dv↦w , Dv ⟩ ⟩) eq₁ eq₂ = ●≃ {γ} {w} (inj₂ ⟨ v , ⟨ Dv↦w , Dv ⟩ ⟩) eq₁ eq₂ =
inj₂ ⟨ v , ⟨ proj₁ (eq₁ γ (v ↦ w)) Dv↦w , proj₁ (eq₂ γ v) Dv ⟩ ⟩ inj₂ ⟨ v , ⟨ proj₁ (eq₁ γ (v ↦ w)) Dv↦w , proj₁ (eq₂ γ v) Dv ⟩ ⟩
``` ```
Again, both directions of the if-and-only-if are proved via a lemma. Again, both directions of the if-and-only-if are proved via a lemma.
@ -398,10 +398,10 @@ congruence by direct equational reasoning.
``` ```
app-cong : ∀{Γ}{L L M M : Γ ⊢ ★} app-cong : ∀{Γ}{L L M M : Γ ⊢ ★}
L ≃ L L ≃ L
M ≃ M M ≃ M
------------------------- -------------------------
(L · M) ≃ (L · M) (L · M) ≃ (L · M)
app-cong {Γ}{L}{L}{M}{M} L≅L M≅M = app-cong {Γ}{L}{L}{M}{M} L≅L M≅M =
start start
(L · M) (L · M)
@ -468,9 +468,9 @@ denotationally equal.
``` ```
compositionality : ∀{Γ Δ}{C : Ctx Γ Δ} {M N : Γ ⊢ ★} compositionality : ∀{Γ Δ}{C : Ctx Γ Δ} {M N : Γ ⊢ ★}
M ≃ N M ≃ N
--------------------------- ---------------------------
(plug C M) ≃ (plug C N) (plug C M) ≃ (plug C N)
compositionality {C = ctx-hole} M≃N = compositionality {C = ctx-hole} M≃N =
M≃N M≃N
compositionality {C = ctx-lam C} M≃N = compositionality {C = ctx-lam C} M≃N =
@ -507,28 +507,27 @@ straightforward induction, using the three equations
with the congruence lemmas for `` and `●`. with the congruence lemmas for `` and `●`.
``` ```
ℰ≃⟦⟧ : ∀ {Γ} {M : Γ ⊢ ★} ℰ≃⟦⟧ : ∀ {Γ} {M : Γ ⊢ ★} → M ≃ ⟦ M ⟧
M ≃ ⟦ M ⟧
ℰ≃⟦⟧ {Γ} {` x} = var-equiv ℰ≃⟦⟧ {Γ} {` x} = var-equiv
ℰ≃⟦⟧ {Γ} {ƛ N} = ℰ≃⟦⟧ {Γ} {ƛ N} =
let ih = ℰ≃⟦⟧ {M = N} in let ih = ℰ≃⟦⟧ {M = N} in
(ƛ N) (ƛ N)
≃⟨ lam-equiv ⟩ ≃⟨ lam-equiv ⟩
( N) ( N)
≃⟨ -cong (ℰ≃⟦⟧ {M = N}) ⟩ ≃⟨ -cong (ℰ≃⟦⟧ {M = N}) ⟩
⟦ N ⟧ ⟦ N ⟧
≃⟨⟩ ≃⟨⟩
⟦ ƛ N ⟧ ⟦ ƛ N ⟧
ℰ≃⟦⟧ {Γ} {L · M} = ℰ≃⟦⟧ {Γ} {L · M} =
(L · M) (L · M)
≃⟨ app-equiv ⟩ ≃⟨ app-equiv ⟩
L ● M L ● M
≃⟨ ●-cong (ℰ≃⟦⟧ {M = L}) (ℰ≃⟦⟧ {M = M}) ⟩ ≃⟨ ●-cong (ℰ≃⟦⟧ {M = L}) (ℰ≃⟦⟧ {M = M}) ⟩
⟦ L ⟧ ● ⟦ M ⟧ ⟦ L ⟧ ● ⟦ M ⟧
≃⟨⟩ ≃⟨⟩
⟦ L · M ⟧ ⟦ L · M ⟧
``` ```