486486End strong_normalization_proof_kripke.
487487
488488(*******************************************************************************
489- Strong normalization proof with the typed version of reducibility (incomplete)
489+ Strong normalization proof with the typed version of reducibility
490490****************************************************************************** *)
491491Module strong_normalization_proof_typed.
492492
@@ -495,6 +495,40 @@ Import subject_reduction_proof.
495495Fixpoint list_hyp ty : seq typ :=
496496 if ty is tyl :->: tyr then tyl :: list_hyp tyl ++ list_hyp tyr else [::].
497497
498+ Fixpoint list_hyp' (ctx : context typ) t : seq typ :=
499+ oapp list_hyp [::] (typing ctx t) ++
500+ match t with
501+ | var n => [::]
502+ | app tl tr => list_hyp' ctx tl ++ list_hyp' ctx tr
503+ | abs ty t => list_hyp' (Some ty :: ctx) t
504+ end .
505+
506+ Lemma list_hyp'E ctx t :
507+ list_hyp' ctx t =
508+ oapp list_hyp [::] (typing ctx t) ++
509+ match t with
510+ | var n => [::]
511+ | app tl tr => list_hyp' ctx tl ++ list_hyp' ctx tr
512+ | abs ty t => list_hyp' (Some ty :: ctx) t
513+ end .
514+ Proof . by case: t. Qed .
515+
516+ Lemma ctxleq_list_hyp' ctx ctx' t ty :
517+ ctx <=c ctx' -> ctx \|- t \: ty -> list_hyp' ctx' t = list_hyp' ctx t.
518+ Proof .
519+ elim: t ty ctx ctx' => //=.
520+ - move => n ty ctx ctx' H H0.
521+ by rewrite -(eqP (ctxleq_preserves_typing H H0)) -(eqP H0).
522+ - move => tl IHtl tr IHtr tyr ctx ctx' H H0.
523+ rewrite -(eqP (ctxleq_preserves_typing H H0)) -(eqP H0) /=; congr cat.
524+ case/typing_appP: H0 => tyl H0 H1.
525+ by rewrite (IHtl (tyl :->: tyr) ctx ctx') // (IHtr tyl ctx ctx').
526+ - move => tyl t IHt ty ctx ctx' H H0.
527+ rewrite -(eqP (ctxleq_preserves_typing H H0)) -(eqP H0) /=; congr cat.
528+ case/typing_absP: H0 => tyr _ H0.
529+ by rewrite (IHt tyr (Some tyl :: ctx) (Some tyl :: ctx')) // ctxleqE eqxx.
530+ Qed .
531+
498532Fixpoint reducible (ctx : context typ) (ty : typ) (t : term) : Prop :=
499533 match ty with
500534 | tyvar n => SN t
@@ -565,4 +599,51 @@ Proof.
565599 by apply (CR2 (subst_betared1 0 [:: t''] H11)), H4.
566600Qed .
567601
602+ Lemma reduce_lemma ctx (ctx' : seq (term * typ)) t ty :
603+ [seq Some p.2 | p <- ctx'] ++ ctx \|- t \: ty ->
604+ all (fun ty => Some ty \in ctx)
605+ (list_hyp' ([seq Some p.2 | p <- ctx'] ++ ctx) t) ->
606+ all (fun p => ctx \|- p.1 \: p.2) ctx' ->
607+ Forall (fun p => reducible ctx p.2 p.1) ctx' ->
608+ reducible ctx ty (substitute 0 [seq p.1 | p <- ctx'] t).
609+ Proof .
610+ elim: t ty ctx ctx'.
611+ - move => /= n ty ctx ctx' H.
612+ rewrite -(eqP H) cats0 subn0 size_map shiftzero /=.
613+ elim: ctx' n H => [| c' ctx' IH []] /=.
614+ + move => n H H0 _ _; rewrite nth_nil subn0.
615+ apply CR3 => // t' H1; inversion H1.
616+ + case/eqP => ->; tauto.
617+ + by move => n H H0 /andP [_ H1] [_]; apply IH.
618+ - move => /= tl IHtl tr IHtr tyr ctx ctx' H.
619+ rewrite -(eqP H) /=; case/typing_appP: H => tyl H H0.
620+ rewrite !all_cat; case/and3P => H1 H2 H3 H4 H5.
621+ move: (IHtl (tyl :->: tyr) ctx ctx') => /=; apply; auto.
622+ by apply subject_subst0.
623+ - move => /= tyl t IHt ty ctx ctx' H.
624+ rewrite -(eqP H) /=; case/typing_absP: H => tyr -> H.
625+ rewrite all_cat; case/andP => H0 H1 H2 H3.
626+ simpl substitute; apply abstraction_lemma => //;
627+ first by apply (@subject_subst0 (abs tyl t)) => //; rewrite typing_absE.
628+ move => /= t2 H4 H5.
629+ rewrite subst_app /=.
630+ apply (IHt tyr ctx ((t2, tyl) :: ctx')) => //=.
631+ by rewrite H4.
632+ Qed .
633+
634+ Theorem typed_term_is_sn ctx t ty : ctx \|- t \: ty -> SN t.
635+ Proof .
636+ move => H.
637+ have H0: ctx ++ map some (list_hyp' ([::] ++ ctx) t) \|- t \: ty by
638+ move: H; apply ctxleq_preserves_typing, ctxleq_appr.
639+ move: (@reduce_lemma _ [::] _ _ H0) => /=.
640+ rewrite (ctxleq_list_hyp' (ctxleq_appr ctx _) H).
641+ have ->: forall xs ys, all (fun x => Some x \in xs ++ map some ys) ys by
642+ move => A xs ys; apply/allP => x H1;
643+ rewrite mem_cat; apply/orP/or_intror/map_f.
644+ move/(_ erefl erefl I); rewrite subst_nil; apply CR1 => //.
645+ by apply/allP => /= ty' H1; rewrite list_hyp'E mem_cat;
646+ apply/orP/or_intror/map_f; rewrite mem_cat -(eqP H) H1.
647+ Qed .
648+
568649End strong_normalization_proof_typed.
0 commit comments