11
2- (**
2+ (**
33 We were able to mechanize the first three steps of Exercise 23.6.3 of Types and Programming Languages (page 356)
44 Autosubst was a great help because it lowers the burden of starting to work on an exercise.
5- If I didn't have Autosubst available, I would not have attempted to mechanize the exercise
5+ If I didn't have Autosubst available, I would not have attempted to mechanize the exercise
66 because the substitution boilerplate is so tedious.
77
8- Andrej told me that the rest of the steps (3-7) are probably very hard to prove in Coq
8+ Andrej told me that the rest of the steps (3-7) are probably very hard to prove in Coq
99 because they are always talking about "forms" which is hard to control in Coq.
10-
10+
1111 I tried around a little bit, defining more well-formed predicates.
12- It went nowehere, though, because writing proofs with them is hard.
12+ It went nowehere, though, because writing proofs with them is hard.
1313 But this is not a failing of Autosubst.
1414 *)
15- Require Import Arith.
15+ From Stdlib Require Import Arith.
1616Require Import sysf.
1717Require Import core unscoped.
18- Require List.
18+ From Stdlib Require List.
1919Import List.ListNotations.
2020Open Scope list.
2121
@@ -84,9 +84,9 @@ Lemma nth_error_map {X Y:Type} : forall (l:list X) (f: X -> Y) y n,
8484 List.nth_error (List.map f l) n = Some y ->
8585 exists x, List.nth_error l n = Some x /\ y = f x.
8686Proof .
87- intros * H.
87+ intros * H.
8888 destruct (List.nth_error l n) as [x'|] eqn:E.
89- - exists x'. split. reflexivity.
89+ - exists x'. split. reflexivity.
9090 specialize (List.map_nth_error f _ _ E) as H'.
9191 rewrite H' in H. injection H. intros ->. reflexivity.
9292 - exfalso.
9595 eapply Nat.le_ngt.
9696 1: eassumption.
9797 rewrite <- (List.map_length f).
98- apply List.nth_error_Some.
98+ apply List.nth_error_Some.
9999 intros H'. rewrite H' in H. discriminate H.
100100Qed .
101101
@@ -216,7 +216,7 @@ Proof.
216216 intros x T Hx.
217217 apply H, Hx.
218218Qed .
219-
219+
220220Lemma context_morphism_lemma :
221221 forall Gamma Gamma' s T sigma tau,
222222 (forall x T, List.nth_error Gamma x = Some T -> has_type Gamma' (tau x) (subst_ty sigma T)) ->
@@ -236,7 +236,7 @@ Proof.
236236 intros [|x] T Hx.
237237 + cbn. constructor. cbn.
238238 injection Hx. intros ->. reflexivity.
239- + cbn.
239+ + cbn.
240240 rewrite <- rinstId'_ty.
241241 eapply context_renaming_lemma.
242242 2: apply H, Hx.
@@ -296,7 +296,7 @@ Proof.
296296Qed .
297297
298298(* it was pleasantly simple to prove preservation which I can then use to prove some part of the TAPL exercise.
299- It is a bit strange that I have to sometime `rewrite <- idSubst` to be able to
299+ It is a bit strange that I have to sometime `rewrite <- idSubst` to be able to
300300 apply the context_renaming_lemma/context_morphism_lemma *)
301301Lemma sysf_preservation :
302302 forall Gamma s s' T, has_type Gamma s T -> eval s s' -> has_type Gamma s' T.
@@ -361,10 +361,10 @@ Fixpoint erase (s: tm) : utlc :=
361361(* This should be a correct formalization of exercise 23.6.3 1) *)
362362Lemma lemma_23_6_3_1:
363363 forall Gamma t T m, has_type Gamma t T -> erase t = m ->
364- exists Gamma' s T', has_type Gamma' s T' /\ erase s = m.
364+ exists Gamma' s T', has_type Gamma' s T' /\ erase s = m.
365365Proof .
366366 (* intros Gamma t. revert Gamma. *)
367- intros * Htype Herase.
367+ intros * Htype Herase.
368368 induction t in Gamma, T, Htype, Herase |- *.
369369 - exists Gamma, (var_tm n), T. now split.
370370 - exists Gamma, (app t1 t2), T. now split.
@@ -402,7 +402,7 @@ Proof.
402402Qed .
403403
404404Print Assumptions erase_subst.
405-
405+
406406Lemma wf_subst: forall s n l sigma_ty,
407407 wf s n l -> wf (subst_tm sigma_ty var_tm s) n l.
408408Proof .
@@ -433,7 +433,7 @@ Proof.
433433 1, 2: assumption. constructor. constructor.
434434 - exists (app t1 t2), 0, 0. repeat split.
435435 1, 2: assumption. constructor. constructor.
436- - inversion Htype. subst T s T2.
436+ - inversion Htype. subst T s T2.
437437 specialize (IHt Gamma (all T1) m H2 Herase) as (s & n & l & IH0 & IH1 & IH2).
438438 destruct n as [|n'].
439439 + exists (tapp s t0), 0, (S l). repeat split.
@@ -454,7 +454,7 @@ Proof.
454454 apply wf_subst. apply H1.
455455 - exists (lam t t0), 0, 0. repeat split.
456456 1, 2: assumption. constructor. constructor.
457- - inversion Htype. subst T s.
457+ - inversion Htype. subst T s.
458458 specialize (IHt (List.map (ren_ty S) Gamma) T0 m H0 Herase) as (s & n & l & IH0 & IH1 & IH2).
459459 exists (tlam s), (S n), l. repeat split.
460460 + constructor. assumption.
464464
465465Print Assumptions lemma_23_6_3_2.
466466
467- Require Import Lia.
467+ From Stdlib Require Import Lia.
468468Lemma bin_size_ind (f : nat -> nat -> nat) (P : nat -> nat -> Type ) :
469469 (forall x y, (forall x' y', f x' y' < f x y -> P x' y') -> P x y) -> forall x y, P x y.
470470Proof .
@@ -518,15 +518,15 @@ Qed.
518518
519519Lemma lemma_23_6_3_3 :
520520 forall Gamma t m n T, exposed t -> has_type Gamma t T -> erase t = app_utlc m n ->
521- exists s u U, has_type Gamma s (arr U T) /\ erase s = m /\
522- has_type Gamma u U /\ erase u = n /\
521+ exists s u U, has_type Gamma s (arr U T) /\ erase s = m /\
522+ has_type Gamma u U /\ erase u = n /\
523523 t = app s u.
524- Proof .
524+ Proof .
525525 intros Gamma t. revert Gamma.
526- destruct t; intros * Hext HTt Hert;
526+ destruct t; intros * Hext HTt Hert;
527527 try discriminate Hert. (* takes care of cases where erase does not change the constructor. *)
528528 - inversion HTt; subst.
529- inversion Hert; subst.
529+ inversion Hert; subst.
530530 exists t1, t2, T1; repeat split; assumption.
531531 - inversion Hext. (* tapp is thrown away by erase but cannot be exposed. *)
532532 - inversion Hext. (* tlam is thrown away by erase but cannot be exposed. *)
0 commit comments