%{ 15-317 Constructive Logic November 19th & 23rd Twelf Metatheory }% %% Syntax %% tp : type. %name tp T. o : tp. arrow : tp -> tp -> tp. term : type. b : term. app : term -> term -> term. lam : tp -> (term -> term) -> term. %% Static Semantics %% of : term -> tp -> type. %name term E x. of/b : of b o. of/app : of (app E1 E2) T' <- of E1 (arrow T T') <- of E2 T. of/lam : of (lam T ([x] E x)) (arrow T T') <- ({x} of x T -> of (E x) T'). %% Dynamic Semantics %% step : term -> term -> type. step/app : step (app E1 E2) (app E1' E2) <- step E1 E1'. step/beta : step (app (lam T ([x] E1 x)) E2) (E1 E2). %% Example of a metajudgment: size of a derivation %% nat : type. 0 : nat. s : nat -> nat. plus : nat -> nat -> nat -> type. %mode plus +X1 +X2 -X3. plus/0 : plus 0 N N. plus/s : plus (s N) M (s P) <- plus N M P. %worlds () (plus _ _ _). %total N (plus N _ _ ). size : of E T -> nat -> type. %mode size +X1 -X2. size/of/b : size of/b 0. size/of/app : size (of/app D2 D1) (s M+N) <- size D1 M <- size D2 N <- plus M N M+N. size/of/lam : size (of/lam ([x:term] [d:of x T] D x d)) (s N) <- ({x:term} {d:of x T} size d 0 -> size (D x d) N). %block size-block : some {T:tp} block {x:term} {d:of x T} {_:size d 0}. %worlds (size-block) (size _ _). %total D (size D _). %% Metatheory %% preservation : of E T -> step E E' %% -> of E' T -> type. %mode preservation +X1 +X2 -X3. %{pres/step/beta : preservation of/b ??? %% No cases! }% %% Same for lam. %% Case: app E1 E2 steps to app E1' E2 because E1 steps to E1'. pres/step/app : preservation (of/app (Dof2 : of E2 T) (Dof1 : of E1 (arrow T T'))) (step/app (Dstep1 : step E1 E1') : step (app E1 E2) (app E1' E2)) %% NTS: app E1' E2 : T (of/app Dof2 Dof1') %% Inductive call <- preservation Dof1 Dstep1 (Dof1' : of E1' (arrow T T')). pres/step/beta : preservation (of/app (Dof2 : of E2 T) (of/lam ([x] [d:of x T] Dof1 x d : of (E1 x) T') : of (lam T E1) (arrow T T'))) step/beta (Dof1 E2 Dof2). %{ Bogus case: fails termination pres/bogus : preservation Dof Dstep Dof' <- preservation Dof Dstep Dof'. }% %worlds () (preservation _ _ _). %total D (preservation _ D _). %% Incomplete: progress value : term -> type. value/b : value b. value/lam : value (lam _ _). unstuck : term -> type. unstuck/value : unstuck E <- value E. unstuck/value : unstuck E <- step E E'. progress : of E T %% -> unstuck E -> type. %mode progress +X1 -X2.