Abella logo (small)

poplmark-2a.thm

%% POPLmark 2a: Progress and preservation for Fsub %% %% Most of this is derived from the Twelf solution by CMU Specification "poplmark-2a". %% Subtyping inversions Theorem sub_top : forall T, {sub top T} -> T = top. IH : induction on 1. intros Hsub. case Hsub. - search. - search. - HsubTop HsubT => apply IH to HsubTop. apply IH to HsubT. search. Theorem sub_arrow : forall S T1 T2, {sub S (arrow T1 T2)} -> exists S1 S2, S = arrow S1 S2. IH : induction on 1. intros Hsub. case Hsub. - search. - HsubS HsubArrow => apply IH to HsubArrow. apply IH to HsubS. search. - search. Theorem sub_forall : forall S T1 T2, {sub S (all T1 T2)} -> exists S1 S2, S = all S1 S2. IH : induction on 1. intros Hsub. case Hsub. - search. - HsubS HsubAll => apply IH to HsubAll. apply IH to HsubS. search. - search. Theorem invert_sub_arrow : forall S1 S2 T1 T2, {sub (arrow S1 S2) (arrow T1 T2)} -> {sub T1 S1} /\ {sub S2 T2}. IH : induction on 1. intros Hsub. case Hsub. - search. - HsubArrow1 HsubArrow2 => apply sub_arrow to HsubArrow2. apply IH to HsubArrow1. apply IH to HsubArrow2. search. - search. Theorem invert_sub_forall : forall S1 S2 T1 T2, {sub (all S1 S2) (all T1 T2)} -> {sub T1 S1} /\ nabla x, {sub x T1 |- sub (S2 x) (T2 x)}. IH : induction on 1. intros !S1 !S2 !T1 !T2 Hsub. case Hsub. - search. - HsubAll1 HsubAll2 => !S3 !S4 : apply sub_forall to HsubAll2. _ HsubPrune : apply IH to HsubAll1. apply IH to HsubAll2. HsubRefl : assert {sub n1 T1 |- sub n1 S3}. cut HsubPrune with HsubRefl. search. - search. %% Typing inversions Theorem absurd_ota : forall E T1 T2 T3, {of (tabs T1 E) (arrow T2 T3)} -> false. IH : induction on 1. intros !E !T1 !T2 !T3 Hof. HofSub HsubArrow : case Hof. apply sub_arrow to HsubArrow. apply IH to HofSub. Theorem absurd_oaf : forall E T1 T2 T3, {of (abs T1 E) (all T2 T3)} -> false. IH : induction on 1. intros !E !T1 !T2 !T3 Hof. HofSub HsubAll : case Hof. apply sub_forall to HsubAll. apply IH to HofSub. Theorem invert_of_abs : forall S1 E T1 T2, {of (abs S1 E) (arrow T1 T2)} -> exists S2, nabla x, {of x S1 |- of (E x) S2} /\ {sub T1 S1} /\ {sub S2 T2}. IH : induction on 1. intros Hof. case Hof. - search. - HofAbs HsubArrow => apply sub_arrow to HsubArrow. apply invert_sub_arrow to HsubArrow. apply IH to HofAbs. search. Theorem invert_of_tabs : forall S1 E T1 T2, {of (tabs S1 E) (all T1 T2)} -> exists S2, nabla x, {sub x S1 |- of (E x) (S2 x)} /\ {sub T1 S1} /\ {sub x T1 |- sub (S2 x) (T2 x)}. IH : induction on 1. intros !S1 !E !T1 !T2 Hof. case Hof. - search. - HofTabs HsubAll => !S2 !S3 : apply sub_forall to HsubAll. apply invert_sub_forall to HsubAll. _ _ HsubPrune : apply IH to HofTabs. HsubRefl : assert {sub n1 T1 |- sub n1 S2}. cut HsubPrune with HsubRefl. search. %% Progress Define progresses : tm -> prop by progresses E := {value E} ; progresses E := exists E', {step E E'}. Theorem app_progresses : forall E1 E2 T, {of (app E1 E2) T} -> progresses E1 -> progresses E2 -> progresses (app E1 E2). IH : induction on 1. intros !E1 !E2 !T Hof HprogE1 HprogE2. case Hof. - HofApp1 HofApp2 => case HprogE1. + HvalE1 => case HprogE2. * HvalE2 => case HvalE1. ** search. ** apply absurd_ota to HofApp1. * search. + search. - HofSub Hsub => HprogApp : apply IH to HofSub HprogE1 HprogE2. search. Theorem tapp_progresses : forall E T T', {of (tapp E T) T'} -> progresses E -> progresses (tapp E T). IH : induction on 1. intros !E !T !T' Hof HprogE. case Hof. - HofTapp HsubT => case HprogE. + HvalE => case HvalE. * apply absurd_oaf to HofTapp. * search. + search. - HofSub Hsub => HprogTapp : apply IH to HofSub HprogE. search. Theorem progress : forall E T, {of E T} -> progresses E. IH : induction on 1. intros !E !T Hof. case Hof (keep). - search. - HofApp1 HofApp2 => HprogE1 : apply IH to HofApp1. HprogE2 : apply IH to HofApp2. apply app_progresses to Hof HprogE1 HprogE2. search. - search. - HofTapp => HprogE : apply IH to HofTapp. apply tapp_progresses to Hof HprogE. search. - HofSub => Hprog : apply IH to HofSub. search. %% Preservation Theorem preservation : forall E E' T, {of E T} -> {step E E'} -> {of E' T}. IH : induction on 1. intros !E !E' !T Hof Hstep. case Hof. - case Hstep. - !T11 !E2 !E1 HofApp1 HofApp2 => case Hstep. + !_ !T1 HvalE2 => HofAbsBody : apply invert_of_abs to HofApp1. HofInst : inst HofAbsBody with n1 = E2. HofE2 : assert {of E2 T1}. cut HofInst with HofE2. search. + HstepApp1 => HofStep : apply IH to HofApp1 HstepApp1. search. + _ HstepApp2 => HofStep : apply IH to HofApp2 HstepApp2. search. - case Hstep. - !T11 !T2 !T12 !E1 HofTapp HsubT => case Hstep. + !_ !T3 => HofTabsBody _ HsubBody : apply invert_of_tabs to HofTapp. HsubRefl : assert {sub T2 T3}. HofInstBody : inst HofTabsBody with n1 = T2. cut HofInstBody with HsubRefl. HsubInst : inst HsubBody with n1 = T2. cut HsubInst with HsubT. search. + HstepTapp => HofStep : apply IH to HofTapp HstepTapp. search. - HofSub Hsub => HofStep : apply IH to HofSub Hstep. search.