Abella logo (small)

sred.thm

%% Ralph Loader's proof of standardization %% (Notes on Simply Typed Lambda Calculus, ECS-LFCS-98-381) %% an adaption of Hongwei Xi's arithmetical proof %% (Upper bounds for standardizations and an application, JSL 1999) %% to Gordon Plotkin's inductive formulation of standard reduction. %% (Call-by-name, Call-by-value and the Lambda-Calculus, TCS 1975) %% %% Abella proof by Andreas Abel (October 2009) Specification "sred". %% Technical lemma about fresh variables. Theorem member_prune : forall E (L:olist), nabla (x:tm), member (E x) L -> exists F, E = y\F. IH : induction on 1. intros Hmem. case Hmem. - search. - HmemTail => apply *IH to *HmemTail. search. %% Matching contexts of term variables x and x -->s x. Define ctx : olist -> olist -> prop by ctx nil nil ; nabla x, ctx (tm x :: C) (sred x x :: D) := ctx C D. Theorem ctx_member1 : forall C D H, ctx C D -> member H C -> exists X, H = tm X /\ member (sred X X) D. IH : induction on 2. intros Hctx Hmem. case Hmem. - case Hctx. search. - HmemTail => HctxSub : case Hctx. apply *IH to *HctxSub *HmemTail. search. Theorem ctx_member2 : forall C D H, ctx C D -> member H D -> exists X, H = sred X X /\ member (tm X) C. IH : induction on 2. intros Hctx Hmem. case Hmem. - case Hctx. search. - HmemTail => HctxSub : case Hctx. apply *IH to *HctxSub *HmemTail. search. %% Technical lemma: weak head reduction is independent of context. Theorem wh_ctx : forall C D T T', ctx C D -> {D |- wh T T'} -> {wh T T'}. IH : induction on 2. intros Hctx Hwh. case Hwh. - search. - HwhTail => apply *IH to *Hctx *HwhTail. search. - HseqWh Hmem => apply ctx_member2 to *Hctx *Hmem. case HseqWh. %% Standard reduction is reflexive. Theorem srefl : forall C D T, ctx C D -> {C |- tm T} -> {D |- sred T T}. IH : induction on 2. intros Hctx Htm. case Htm. - HtmM HtmN => apply IH to Hctx *HtmM. apply *IH to *Hctx *HtmN. search. - HtmBody => apply *IH to _ *HtmBody. search. - HseqTm Hmem => apply ctx_member1 to *Hctx *Hmem. case HseqTm. search. %% Standard reduction is closed under substitution. Theorem ssubst : forall C D T T' S S', nabla x, ctx C D -> {D, sred x x |- sred (T x) (T' x)} -> {D |- sred S S'} -> {D |- sred (T S) (T' S')}. IH : induction on 2. intros !C !D !T !T' !S !S' !n1 Hctx HseqSred Hsred. case HseqSred. - %% case weak head step HwhTail HsredTail => apply *IH to Hctx *HsredTail *Hsred. Hwh : apply wh_ctx to _ *HwhTail. inst *Hwh with n1 = S. search. - %% case: application HsredM HsredN => apply IH to Hctx *HsredM Hsred. apply *IH to *Hctx *HsredN *Hsred. search. - %% case: abstraction HsredAbs => apply *IH to _ *HsredAbs *Hsred. search. - %% case hypothesis HseqVar HmemVar => case HmemVar. + case HseqVar. search. + HmemTail => apply ctx_member2 to Hctx HmemTail. case HseqVar. apply member_prune to HmemTail. search. %% Variables do not beta reduce. Theorem name_not_beta : forall T, nabla x, {beta x T} -> false. intros Hbeta. case Hbeta. Theorem var_not_beta : forall C D T T', ctx C D -> member (tm T) C -> {beta T T'} -> false. IH : induction on 2. intros Hctx Hmem Hbeta. case Hmem. - case Hctx. case Hbeta. - HmemTail => HctxSub : case Hctx. apply *IH to *HctxSub *HmemTail *Hbeta. %% Variables are not abstractions. Theorem var_not_abs : forall C D R, ctx C D -> member (tm (abs R)) C -> false. IH : induction on 2. intros Hctx Hmem. case Hmem. - case Hctx. - HmemTail => HctxSub : case Hctx. apply *IH to *HctxSub *HmemTail. %% Applying a sred which ends in a lambda, removing the resulting redex. Theorem sred_beta : forall C D M N N' R, ctx C D -> {D |- sred M (abs R)} -> {D |- sred N N'} -> {D |- sred (app M N) (R N')}. IH : induction on 2. intros Hctx HsredM HsredN. case HsredM. - % weak head reduction case _ HsredTail => apply *IH to *Hctx *HsredTail *HsredN. search. - % abstraction case HsredAbs => apply ssubst to *Hctx *HsredAbs *HsredN. search. - % variable case (impossible) HseqVar Hmem => HmemAbs : apply ctx_member2 to Hctx *Hmem. case HseqVar. apply var_not_abs to *Hctx *HmemAbs. %% Main Lemma: %% Standard reduction is closed under appending a beta step. Theorem sappend : forall C D T T' T'', ctx C D -> {D |- sred T T'} -> {beta T' T''} -> {D |- sred T T''}. IH : induction on 2. intros Hctx Hsred Hbeta. case Hsred. - % weak head step case _ HsredTail => apply *IH to *Hctx *HsredTail *Hbeta. search. - % application case HsredM HsredN => case Hbeta. + % subcase reduction in function part HbetaFun => apply *IH to *Hctx *HsredM *HbetaFun. search. + % subcase reduction in argument part HbetaArg => apply *IH to *Hctx *HsredN *HbetaArg. search. + % subcase beta-contraction apply sred_beta to *Hctx *HsredM *HsredN. search. - % abstraction case HsredAbs => HbetaAbs : case Hbeta. apply *IH to _ *HsredAbs *HbetaAbs. search. - % variable case HseqVar Hmem => HmemTm : apply ctx_member2 to Hctx *Hmem. case HseqVar. apply var_not_beta to *Hctx *HmemTm *Hbeta. %% QED ! %% Theorem: Each beta reduction sequence can be standardized. Theorem standardization: forall T T', {tm T} -> {betas T T'} -> {sred T T'}. IH : induction on 2. intros Htm Hbetas. case Hbetas. - apply srefl to _ *Htm. search. - HbetasTail HbetaTail => HsredMid : apply *IH to *Htm *HbetasTail. apply sappend to _ *HsredMid *HbetaTail. search.