CIS6700-Spring2025/cbpv.ott

792 lines
13 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

embed
{{ tex-preamble
\newcommand{\gap}{\:}
\newcommand{\kw}[1]{ \mathsf{#1} }
}}
metavar x, y, z ::=
{{ com term variables }}
{{ lex alphanum }}
grammar
v, w :: 'val_' ::= {{ com values }}
| x :: :: Var
| unit :: :: Unit
{{ tex \kw{unit} }}
| inl v :: :: Inl
{{ tex \kw{inl} \gap [[v]] }}
| inr v :: :: Inr
{{ tex \kw{inr} \gap [[v]] }}
| thunk m :: :: Thunk
{{ tex \kw{thunk} \gap [[m]] }}
| ( v ) :: S :: Parens
{{ com parentheses }}
{{ tex ([[v]]) }}
| v { s } :: S :: Subst
{{ tex [[v]][ [[s]] ]}}
m, n :: 'com_' ::= {{ com computations }}
| force v :: :: Force
{{ tex \kw{force} \gap [[v]] }}
| λ x . m :: :: Lam
(+ bind x in m +)
{{ tex \lambda [[x]] \mathpunct{.} [[m]] }}
| m v :: :: App
{{ tex [[m]] \gap [[v]] }}
| ret v :: :: Ret
{{ tex \kw{return} \gap [[v]] }}
| let x m n :: :: Let
(+ bind x in n +)
{{ tex \kw{let} \gap [[x]] \leftarrow [[m]] \gap \kw{in} \gap [[n]] }}
| case v | y . m | z . n :: :: Case
(+ bind y in m +)
(+ bind z in n +)
{{ tex \kw{case} \gap [[v]] \gap \kw{of} \gap \lbrace \kw{inl} \gap [[y]] \Rightarrow [[m]] \mathrel{;} \kw{inr} \gap [[z]] \Rightarrow [[n]] \rbrace }}
| ( m ) :: S :: Parens
{{ com parentheses }}
{{ tex ([[m]]) }}
| m { s } :: S :: Subst
{{ tex [[m]][ [[s]] ]}}
A :: 'valtype_' ::= {{ com value types }}
| Unit :: :: Unit
{{ tex \kw{Unit} }}
| A1 + A2 :: :: Sum
{{ tex [[A1]] + [[A2]] }}
| U B :: :: U
{{ tex \kw{U} \gap [[B]] }}
B :: 'comtype_' ::= {{ com computation types }}
| F A :: :: F
{{ tex \kw{F} \gap [[A]] }}
| A → B :: :: Arr
{{ tex [[A]] \rightarrow [[B]] }}
s {{ tex \sigma }} :: 'subst_' ::= {{ com substitutions }}
| • :: :: Nil
{{ com identity substitution }}
{{ tex \cdot }}
| s , x ↦ v :: :: Cons
{{ com substitution extension }}
{{ tex [[s]], [[x]] \mapsto [[v]] }}
| x ↦ v :: S :: Single
{{ com single substitution }}
{{ tex [[x]] \mapsto [[v]] }}
| ⇑ s :: :: Lift
{{ com lifting substitution }}
{{ tex \mathop{\Uparrow} [[s]] }}
G {{ tex \Gamma }}, D {{ tex \Delta }} :: 'ctxt_' ::= {{ com contexts }}
| • :: :: Nil
{{ com empty context }}
{{ tex \cdot }}
| G , x : A :: :: Cons
{{ com context extension }}
{{ tex [[G]], [[x]] \mathbin{:} [[A]] }}
P, Q :: 'set_' ::=
| { v | formula } :: :: valset
{{ tex \lbrace [[v]] \mid [[formula]] \rbrace }}
| { m | formula } :: :: comset
{{ tex \lbrace [[m]] \mid [[formula]] \rbrace }}
formula :: 'formula_' ::=
| judgement :: :: judgement
| formula1 ∧ formula2 :: :: and
{{ tex [[formula1]] \wedge [[formula2]] }}
| formula1 formula2 :: :: or
{{ tex [[formula1]] \vee [[formula2]] }}
| formula1 ⇒ formula2 :: :: implies
{{ tex [[formula1]] \Rightarrow [[formula2]] }}
| x : A ∈ G :: :: in
{{ tex [[x]] : [[A]] \in [[G]] }}
| v = w :: :: equals
{{ tex [[v]] = [[w]] }}
| v ∈ P :: :: valin
{{ tex [[v]] \in [[P]] }}
| m ∈ P :: :: comin
{{ tex [[m]] \in [[P]] }}
| ∀ v . formula :: :: valforall
{{ tex \forall [[v]] \mathpunct{.} [[formula]] }}
| ∀ m . formula :: :: comforall
{{ tex \forall [[m]] \mathpunct{.} [[formula]] }}
| ∃ v . formula :: :: valexists
{{ tex \exists [[v]] \mathpunct{.} [[formula]] }}
| ∃ m . formula :: :: comexists
{{ tex \exists [[m]] \mathpunct{.} [[formula]] }}
| ( formula ) :: :: parentheses
{{ tex ( [[formula ]] ) }}
| (# formula #) :: :: sparentheses
{{ tex [[formula]] }}
%% Inductive definition of strong normalization %%
defns
SN :: '' ::=
defn
v ∈ SNe :: :: SNeVal :: 'SNe_'
{{ tex [[v]] \in \kw{SNe} }}
by
------- :: Var
x ∈ SNe
defn
m ∈ SNe :: :: SNeCom :: 'SNe_'
{{ tex [[m]] \in \kw{SNe} }}
by
------------- :: Force
force x ∈ SNe
m ∈ SNe
v ∈ SN
--------- :: App
m v ∈ SNe
m ∈ SNe
n ∈ SN
--------------- :: Let
let x m n ∈ SNe
m ∈ SN
n ∈ SN
------------------------ :: Case
case x | y.m | z.n ∈ SNe
defn
v ∈ SN :: :: SNVal :: 'SN_'
{{ tex [[v]] \in \kw{SN} }}
by
------ :: Var
x ∈ SN
--------- :: Unit
unit ∈ SN
v ∈ SN
---------- :: Inl
inl v ∈ SN
v ∈ SN
---------- :: Inr
inr v ∈ SN
m ∈ SN
------------ :: Thunk
thunk m ∈ SN
% inversion
force v ∈ SN
------------ :: Force_inv
v ∈ SN
defn
m ∈ SN :: :: SNCom :: 'SN_'
{{ tex [[m]] \in \kw{SN} }}
by
m ∈ SN
---------- :: Lam
λx. m ∈ SN
v ∈ SN
---------- :: Ret
ret v ∈ SN
m ∈ SNe
------- :: SNe
m ∈ SN
m ⤳ n
n ∈ SN
------ :: Red
m ∈ SN
% backward closure
m ⤳* n
n ∈ SN
------- :: Reds
m ∈ SN
% extensionality
m x ∈ SN
-------- :: Ext
m ∈ SN
% lifting
G ⊧ s
G, x : A ⊧ m : B
---------------- :: Lift
m{⇑ s} ∈ SN
defn
m ⤳ n :: :: SR :: 'SR_'
{{ tex [[m]] \leadsto [[n]] }}
by
-------------------- :: Thunk
force (thunk m) ⤳ m
v ∈ SN
--------------------- :: Lam
(λx. m) v ⤳ m{x ↦ v}
v ∈ SN
--------------------------- :: Ret
let x (ret v) m ⤳ m{x ↦ v}
v ∈ SN
n ∈ SN
------------------------------------ :: Inl
case (inl v) | y.m | z.n ⤳ m{y ↦ v}
v ∈ SN
m ∈ SN
------------------------------------ :: Inr
case (inr v) | y.m | z.n ⤳ n{z ↦ v}
m ⤳ n
---------- :: App
m v ⤳ n v
m ⤳ m'
----------------------- :: Let
let x m n ⤳ let x m' n
defn
m ⤳* n :: :: SRs :: 'SRs_'
{{ tex [[m]] \leadsto^* [[n]] }}
by
------- :: Refl
m ⤳* m
m ⤳ m'
m' ⤳* n
-------- :: Trans
m ⤳* n
% admissible
m ⤳ n
------- :: Once
m ⤳* n
m ⤳* m'
m' ⤳* n
-------- :: Trans'
m ⤳* n
% congruence rules
m ⤳* n
----------- :: App
m v ⤳* n v
m ⤳* m'
------------------------ :: Let
let x m n ⤳* let x m' n
%% Logical relation and semantic typing %%
defns
LR :: '' ::=
defn
⟦ A ⟧ ↘ P :: :: ValType :: 'LR_'
{{ tex \mathopen{\llbracket} [[A]] \mathclose{\rrbracket} \searrow [[P]] }}
by
------------------------------------- :: Unit
⟦ Unit ⟧ ↘ { v | v ∈ SNe v = unit }
⟦ A1 ⟧ ↘ P
⟦ A2 ⟧ ↘ Q
----------------------------------------------------------------------------------------------------------- :: Sum
⟦ A1 + A2 ⟧ ↘ { v | v ∈ SNe (# (∃w. (# v = inl w ∧ w ∈ P #)) (∃w. (# v = inr w ∧ w ∈ Q #)) #) }
⟦ B ⟧ ↘ P
----------------------------- :: U
⟦ U B ⟧ ↘ { v | force v ∈ P }
defn
⟦ B ⟧ ↘ P :: :: ComType :: 'LR_'
{{ tex \mathopen{\llbracket} [[B]] \mathclose{\rrbracket} \searrow [[P]] }}
by
⟦ A ⟧ ↘ P
--------------------------------------------------------------------------------- :: F
⟦ F A ⟧ ↘ { m | (∃n. (# m ⤳* n ∧ n ∈ SNe #)) (∃v. (# m ⤳* ret v ∧ v ∈ P #)) }
⟦ A ⟧ ↘ P
⟦ B ⟧ ↘ Q
--------------------------------------------- :: Arr
⟦ A → B ⟧ ↘ { m | ∀v. (# v ∈ P ⇒ m v ∈ Q #) }
defns
LRs :: '' ::=
defn
v ∈ ⟦ A ⟧ :: :: ValTypes :: 'LR'_'
{{ tex [[v]] \in \mathopen{\llbracket} [[A]] \mathclose{\rrbracket} }}
by
------------ :: Unit_var
x ∈ ⟦ Unit ⟧
--------------- :: Unit_unit
unit ∈ ⟦ Unit ⟧
--------------- :: Sum_var
x ∈ ⟦ A1 + A2 ⟧
v ∈ ⟦ A1 ⟧
------------------- :: Sum_inl
inl v ∈ ⟦ A1 + A2 ⟧
v ∈ ⟦ A2 ⟧
------------------- :: Sum_inr
inr v ∈ ⟦ A1 + A2 ⟧
force v ∈ ⟦ B ⟧
--------------- :: Force
v ∈ ⟦ U B ⟧
defn
m ∈ ⟦ B ⟧ :: :: ComTypes :: 'LR'_'
{{ tex [[m]] \in \mathopen{\llbracket} [[B]] \mathclose{\rrbracket} }}
by
m ⤳* n
n ∈ SNe
----------- :: F_var
m ∈ ⟦ F A ⟧
m ⤳* ret v
v ∈ ⟦ A ⟧
----------- :: F_ret
m ∈ ⟦ F A ⟧
∀v. (# v ∈ ⟦ A ⟧ ⇒ m v ∈ ⟦ B ⟧ #)
--------------------------------- :: Arr
m ∈ ⟦ A → B ⟧
defns
Sem :: '' ::=
defn
G ⊧ s :: :: SemCtxt :: 'S_'
{{ tex [[G]] \vDash [[s]] }}
by
----- :: Nil
G ⊧ •
G ⊧ s
⟦ A ⟧ ↘ P
v ∈ P
------------------- :: Cons
G, x : A ⊧ s, x ↦ v
defn
G ⊧ v : A :: :: SemVal :: 'S_'
{{ tex [[G]] \vDash [[v]] : [[A]] }}
by
x : A ∈ G
--------- :: Var
G ⊧ x : A
--------------- :: Unit
G ⊧ unit : Unit
G ⊧ v : A1
------------------- :: Inl
G ⊧ inl v : A1 + A2
G ⊧ v : A2
------------------- :: Inr
G ⊧ inr v : A1 + A2
G ⊧ m : B
----------------- :: Thunk
G ⊧ thunk m : U B
defn
G ⊧ m : B :: :: SemCom :: 'S_'
{{ tex [[G]] \vDash [[m]] : [[B]] }}
by
G ⊧ v : U B
--------------- :: Force
G ⊧ force v : B
G, x : A ⊧ m : B
----------------- :: Arr
G ⊧ λx. m : A → B
G ⊧ m : A → B
G ⊧ v : A
-------------- :: App
G ⊧ m v : B
G ⊧ v : A
---------------- :: Ret
G ⊧ ret v : F A
G ⊧ m : F A
G, x : A ⊧ n : B
----------------- :: Let
G ⊧ let x m n : B
G ⊧ v : A1 + A2
G, y : A1 ⊧ m : B
G, z : A2 ⊧ n : B
-------------------------- :: Case
G ⊧ case v | y.m | z.n : B
%% Syntactic typing %%
defns
Typing :: '' ::=
defn
G ⊢ v : A :: :: ValWt :: 'T_'
{{ tex [[G]] \vdash [[v]] : [[A]] }}
by
x : A ∈ G
--------- :: Var
G ⊢ x : A
--------------- :: Unit
G ⊢ unit : Unit
G ⊢ v : A1
------------------- :: Inl
G ⊢ inl v : A1 + A2
G ⊢ v : A2
------------------- :: Inr
G ⊢ inr v : A1 + A2
G ⊢ m : B
----------------- :: Thunk
G ⊢ thunk m : U B
defn
G ⊢ m : B :: :: ComWt :: 'T_'
{{ tex [[G]] \vdash [[m]] : [[B]] }}
by
G ⊢ v : U B
--------------- :: Force
G ⊢ force v : B
G, x : A ⊢ m : B
----------------- :: Lam
G ⊢ λx. m : A → B
G ⊢ m : A → B
G ⊢ v : A
-------------- :: App
G ⊢ m v : B
G ⊢ v : A
---------------- :: Ret
G ⊢ ret v : F A
G ⊢ m : F A
G, x : A ⊢ n : B
----------------- :: Let
G ⊢ let x m n : B
G ⊢ v : A1 + A2
G, y : A1 ⊢ m : B
G, z : A2 ⊢ n : B
-------------------------- :: Case
G ⊢ case v | y.m | z.n : B
%% Reduction %%
defns
Red :: '' ::=
defn
v ⇝ w :: :: StepVal :: 'StepVal_'
{{ tex [[v]] \rightsquigarrow [[w]] }}
by
defn
m ⇝ n :: :: StepCom :: 'StepCom_'
{{ tex [[m]] \rightsquigarrow [[n]] }}
by
defn
v ⇝* w :: :: StepVals :: 'StepVals_'
{{ tex [[v]] \rightsquigarrow^* [[w]] }}
by
defn
m ⇝* n :: :: StepComs :: 'StepComs_'
{{ tex [[m]] \rightsquigarrow^* [[n]] }}
by
%% Accessibility definition of strong normalization %%
defns
sn :: '' ::=
defn
v ∈ sn :: :: snVal :: 'sn_'
{{ tex [[v]] \in \kw{sn} }}
by
∀w. (# v ⇝ w ⇒ w ∈ sn #)
------------------------ :: Val
v ∈ sn
% inversion
force v ∈ sn
------------ :: Force_inv
v ∈ sn
m v ∈ sn
-------- :: App_inv2
v ∈ sn
% congruence
------ :: Var
x ∈ sn
--------- :: Unit
unit ∈ sn
v ∈ sn
---------- :: Inl
inl v ∈ sn
v ∈ sn
---------- :: Inr
inr v ∈ sn
m ∈ sn
------------ :: Thunk
thunk m ∈ sn
defn
m ∈ sn :: :: snCom :: 'sn_'
{{ tex [[m]] \in \kw{sn} }}
by
∀n. (# m ⇝ n ⇒ n ∈ sn #)
------------------------ :: Com
m ∈ sn
% inversion
m v ∈ sn
-------- :: App_inv1
m ∈ sn
let x m n ∈ sn
-------------- :: Let_inv1
m ∈ sn
let x m n ∈ sn
-------------- :: Let_inv2
n ∈ sn
% antisubstitution
m{x ↦ v} ∈ sn
v ∈ sn
------------- :: antisubst
m ∈ sn
% expansion
m ∈ sn
-------------------- :: Force_Thunk
force (thunk m) ∈ sn
v ∈ sn
m{x ↦ v} ∈ sn
-------------- :: App_Lam
(λx. m) v ∈ sn
v ∈ sn
m{x ↦ v} ∈ sn
-------------------- :: Let_Ret
let x (ret v) m ∈ sn
v ∈ sn
m{y ↦ v} ∈ sn
n ∈ sn
----------------------------- :: Case_Inl
case (inl v) | y.m | z.n ∈ sn
v ∈ sn
m ∈ sn
n{z ↦ v} ∈ sn
----------------------------- :: Case_Inr
case (inr v) | y.m | z.n ∈ sn
% closure
m ⤳' n
v ∈ sn
n v ∈ sn
-------- :: App_bwd
m v ∈ sn
m ⤳' m'
n ∈ sn
let x m' n ∈ sn
--------------- :: Let_bwd
let x m n ∈ sn
m ⤳' n
n ∈ sn
------- :: closure
m ∈ sn
% congruence
v ∈ sn
------------ :: Force
force v ∈ sn
m ∈ sn
---------- :: Lam
λx. m ∈ sn
v ∈ sn
---------- :: Ret
ret v ∈ sn
m ∈ sne
v ∈ sn
-------- :: App
m v ∈ sn
m ∈ sne
n ∈ sn
-------------- :: Let
let x m n ∈ sn
v ∈ sne
m ∈ sn
n ∈ sn
----------------------- :: Case
case v | y.m | z.n ∈ sn
defn
m ⤳' n :: :: sr :: 'sr_'
{{ tex [[m]] \leadsto_{ \kw{sn} } [[n]] }}
by
--------------------- :: Thunk
force (thunk m) ⤳' m
v ∈ sn
---------------------- :: Lam
(λx. m) v ⤳' m{x ↦ v}
v ∈ sn
---------------------------- :: Ret
let x (ret v) m ⤳' m{x ↦ v}
v ∈ sn
n ∈ sn
------------------------------------- :: Inl
case (inl v) | y.m | z.n ⤳' m{y ↦ v}
v ∈ sn
m ∈ sn
------------------------------------- :: Inr
case (inr v) | y.m | z.n ⤳' n{z ↦ v}
m ⤳' n
----------- :: App
m v ⤳' n v
m ⤳' m'
------------------------ :: Let
let x m n ⤳' let x m' n
defn
v ∈ ne :: :: neVal :: 'ne_'
{{ tex [[v]] \in \kw{ne} }}
by
------ :: Var
x ∈ ne
% preservation
v ⇝ w
v ∈ ne
------ :: StepVal
w ∈ ne
defn
m ∈ ne :: :: neCom :: 'ne_'
{{ tex [[m]] \in \kw{ne} }}
by
------------ :: Force
force x ∈ ne
m ∈ ne
-------- :: App
m v ∈ ne
m ∈ ne
-------------- :: Let
let x m n ∈ ne
------------------ :: Case
case x | y.m | z.n ∈ ne
% preservation
m ⇝ n
n ∈ ne
------ :: StepCom
m ∈ ne
% embedding
m ∈ SNe
------- :: SNe
m ∈ ne
defn
v ∈ sne :: :: sneVal :: 'sneval_'
{{ tex [[v]] \in \kw{sne} }}
by
------- :: sne
x ∈ sne
defn
m ∈ sne :: :: sneCom :: 'snecom_'
{{ tex [[m]] \in \kw{sne} }}
by
m ∈ ne
m ∈ sn
------- :: sne
m ∈ sne