Abella logo (small)

poplmark-1a.thm

%% POPLmark 1a: Reflexivity and transitivity for Fsub Specification "poplmark-1a". % We use nominal constants to represent type variable names. This predicate % recognizes such nominal constants. Define name : ty -> prop by nabla x, name x. % ctx defines the context in which subtyping judgements are made Define ctx : olist -> prop by ctx nil ; ctx (bound X U :: L) := name X /\ ctx L. % cty defines valid closed types (used for reflexivity) Define cty : olist -> ty -> prop by cty L top ; cty L X := exists U, member (bound X U) L ; cty L (arrow T1 T2) := cty L T1 /\ cty L T2 ; cty L (all T1 T2) := cty L T1 /\ nabla x, cty (bound x T1 :: L) (T2 x). % ty defines valid open types (used for transitivity) Define ty : ty -> prop by ty top ; nabla x, ty x ; ty (arrow T1 T2) := ty T1 /\ ty T2 ; ty (all T1 T2) := ty T1 /\ nabla x, ty (T2 x). Theorem sub_refl : forall L T, cty L T -> {L |- sub T T}. IH : induction on 1. intros Hcty. case Hcty. - search. - search. - HctyT1 HctyT2 => apply IH to *HctyT1. apply IH to *HctyT2. search. - HctyT1 HctyBody => apply IH to *HctyT1. apply IH to *HctyBody. search. Theorem ctx_member : forall E L, ctx L -> member E L -> exists X U, E = bound X U /\ name X. IH : induction on 2. intros Hctx Hmem. case Hmem. - case Hctx. search. - HmemTail => _ HctxTail : case Hctx. apply IH to *HctxTail *HmemTail. search. Theorem bound_name : forall L X U, ctx L -> {L |- bound X U} -> name X. intros Hctx Hbound. HboundHyp Hmem : case Hbound. apply ctx_member to *Hctx *Hmem. case HboundHyp. search. Theorem sub_top : forall L T, ctx L -> {L |- sub top T} -> T = top. intros Hctx Hsub. case Hsub. - search. - search. - Hbound => Hname : apply bound_name to *Hctx *Hbound. case Hname. - HsubHyp Hmem => apply ctx_member to *Hctx *Hmem. case HsubHyp. Theorem dual_theorem : forall Q, ty Q -> (forall L S T, ctx L -> {L |- sub S Q} -> {L |- sub Q T} -> {L |- sub S T}) /\ (forall L P X TM TN, ctx (bound X Q :: L) -> {L |- sub P Q} -> {L, bound X Q |- sub TM TN} -> {L, bound X P |- sub TM TN}). % The proof is by induction on the type Q. % For transitivity there is a nested induction on {L |- sub S Q} % For narrowing there is a nested induction on {L, bound X Q |- sub TM TN} IH : induction on 1. intros !Q Hty. split*. - IHtrans : induction on 2. intros Hctx HsubSQ HsubQT. case HsubSQ. + apply sub_top to Hctx HsubQT. search. + search. + Hbound HsubUQ => apply IHtrans to *Hctx *HsubUQ *HsubQT. search. + HsubT1S1 HsubS2T2 => case HsubQT. * search. * Hbound => Hname : apply bound_name to *Hctx *Hbound. case Hname. * Hbound => Hname : apply bound_name to *Hctx *Hbound. case Hname. * HsubT4T1 HsubT2T3 => HtyT1 HtyT2 : case Hty. HtransT1 : apply IH to *HtyT1. HtransT2 : apply IH to *HtyT2. apply HtransT1 to Hctx *HsubT4T1 *HsubT1S1. apply HtransT2 to *Hctx *HsubS2T2 *HsubT2T3. search. * HsubHyp Hmem => apply ctx_member to *Hctx *Hmem. case HsubHyp. + HsubT1S1 HsubBody => case HsubQT. * search. * Hbound => Hname : apply bound_name to *Hctx *Hbound. case Hname. * Hbound => Hname : apply bound_name to *Hctx *Hbound. case Hname. * HsubT4T1 HsubBT => HtyT1 HtyBody : case Hty. HtransT1 HnarrowT1 : apply IH to *HtyT1. HtransB : apply IH to *HtyBody. apply HtransT1 to Hctx HsubT4T1 HsubT1S1. HsubMid : apply HnarrowT1 to _ HsubT4T1 HsubBody with X = n1. apply HtransB to _ HsubMid HsubBT. search. * HsubHyp Hmem => apply ctx_member to *Hctx *Hmem. case HsubHyp. + HsubHyp Hmem => apply ctx_member to *Hctx *Hmem. case HsubHyp. - Htrans => IHnarrow : induction on 3. intros !L !_ !X HctxExt HsubPQ HsubTM. case HsubTM (keep). + search. + Hbound => HboundHyp HmemExt : case Hbound. case HmemExt. * case HboundHyp. search. * Hmem => _ HctxBase : case HctxExt. apply ctx_member to HctxBase Hmem. case HboundHyp. search. + HboundTM HsubUTN => HboundHyp HmemExt : case HboundTM. case HmemExt. case HboundHyp. * HsubMid : apply IHnarrow to HctxExt HsubPQ *HsubUTN. case HctxExt. apply Htrans to _ HsubPQ HsubMid. search. * Hmem => apply IHnarrow to HctxExt HsubPQ *HsubUTN. _ HctxBase : case HctxExt. apply ctx_member to HctxBase Hmem. case HboundHyp. search. + HsubT1S1 HsubS2T2 => apply IHnarrow to HctxExt HsubPQ HsubT1S1. apply IHnarrow to *HctxExt *HsubPQ *HsubS2T2. search. + !_ !_ !T1 HsubT1S1 HsubBody => apply IHnarrow to HctxExt HsubPQ HsubT1S1. HctxMid : assert ctx (bound X Q :: bound n1 T1 :: L). * case HctxExt. search. * apply IHnarrow to *HctxMid *HsubPQ *HsubBody. search. + HsubHyp Hmem => apply ctx_member to *HctxExt *Hmem. case HsubHyp. % We can extract the transitivity result from the generalized theorem Theorem transitivity : forall L Q S T, ctx L -> ty Q -> {L |- sub S Q} -> {L |- sub Q T} -> {L |- sub S T}. intros Hctx Hty HsubSQ HsubQT. Htrans : apply dual_theorem to *Hty. apply Htrans to *Hctx *HsubSQ *HsubQT. search.