WF.v 8.39 KB
Newer Older
Gaspard Ferey's avatar
WIP.  
Gaspard Ferey committed
1 2 3 4 5 6

Require Import PeanoNat.
Require Import List.
Require Import LPTerm.


Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
Theorem types_WF : forall Γ t u, Γ  t : u -> Γ .
Proof. intros. induction H; easy. Qed.

Theorem vardecl_WF : forall Γ x A, Γ, x : A  -> Γ .
Proof.
  intros.
  remember (Γ, x : A) as Γ2.
  induction H; inversion HeqΓ2; subst; eapply types_WF; apply H0.
Qed.

Theorem ruldecl_WF : forall Γ t u, Γ, t  u  -> Γ .
Proof.
  intros.
  remember (Γ, t  u) as Γ2.
  induction H; inversion HeqΓ2; subst; eapply types_WF; apply H0.
Qed.



Inductive weaker : context -> context -> Prop :=
| WeakRefl        : forall Γ       , weaker Γ Γ
| WeakVarDecl     : forall Γ    x A, weaker Γ (Γ, x : A)
| WeakRulDecl     : forall Γ    t u, weaker Γ (Γ, t  u)
| WeakNextVarDecl : forall Γ Γ' x A, weaker Γ Γ' -> weaker (Γ, x : A) (Γ', x : A)
| WeakNextRulDecl : forall Γ Γ' t u, weaker Γ Γ' -> weaker (Γ, t  u) (Γ', t  u).


Theorem subset_var_decl : forall Γ Γ' x A, weaker Γ Γ' -> x : A  Γ -> x : A  Γ'.
Proof.
  intros.
  induction H.
  - easy.
  - apply IAfterV. easy.
  - apply IAfterR. easy.
  - remember (Γ, x0 : A0) as Γ2. induction H0.
    + inversion HeqΓ2. subst. apply INow.
    + inversion HeqΓ2. subst. apply IAfterV. apply IHweaker. easy.
    + inversion HeqΓ2.
  - remember (Γ, t  u) as Γ2. induction H0 ; inversion HeqΓ2.
    subst. apply IAfterR. apply IHweaker. easy.
Qed.

Theorem subset_rul_decl : forall Γ Γ' t u, weaker Γ Γ' -> t  u  Γ -> t  u  Γ'.
Proof.
  intros.
  induction H.
  - easy.
  - apply IRAfterV. easy.
  - apply IRAfterR. easy.
  - remember (Γ, x : A) as Γ2. induction H0.
    + inversion HeqΓ2.
    + inversion HeqΓ2. subst. apply IRAfterV. apply IHweaker. easy.
    + inversion HeqΓ2.
  - remember (Γ, t0  u0) as Γ2. induction H0; inversion HeqΓ2.
    + subst. econstructor.
    + inversion HeqΓ2. subst. apply IRAfterR. apply IHweaker. easy.
Qed.

Theorem fresh_vars_weaker : forall Γ Γ' x, weaker Γ Γ' -> Fresh_var Γ' x -> Fresh_var Γ x.
Proof.
67
  intros. intro. apply H0. destruct H1. exists x0. eapply subset_var_decl. apply H. easy.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
68 69 70 71 72 73 74 75 76 77 78 79 80
Qed.


Theorem weak : forall Γ Γ' t u, Γ  t : u -> weaker Γ Γ' -> Γ'  -> Γ'  t : u.
Proof.
  intros.
  generalize dependent Γ'.
  induction H; intros.
  - apply TyAxiom. easy. eapply subset_var_decl. apply H1. easy.
  - apply TyType. easy.
  - eapply TyPi.
    + apply IHtyping. easy. easy.
    + intro. intro. apply H1. apply H4. apply WeakNextVarDecl. easy. econstructor.
81
      Admitted.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
82 83
      

84 85 86
Theorem not_in_not_eq {A:Type} : forall (x v : A) l, ~ (In x (v::l)) -> x <> v.
Proof. intros. intro. apply H. now left. Qed.

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
Theorem FV_close : forall x y t, In x (FV t) -> x <> y -> forall n, In x (FV (close_k t n y)).
Proof.
  intros x y t H x_neq_y.
  induction t ; try inversion H ; subst ; intros n.
  - unfold close ; simpl. destruct (var_dec x y).
    + contradiction.
    + assumption.
  - inversion H0.
  - simpl ; apply in_or_app.
    simpl in H ; apply in_app_or in H ; destruct H.
    + left ; now apply IHt1.
    + right. now apply IHt2.
  - simpl ; apply in_or_app.
    simpl in H ; apply in_app_or in H ; destruct H.
    + left ; now apply IHt1.
    + right. now apply IHt2.
  - simpl ; apply in_or_app.
    simpl in H ; apply in_app_or in H ; destruct H.
    + left ; now apply IHt1.
    + right. now apply IHt2.
Qed.

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
Theorem left_arr_type : forall Γ t u AB, Γ  t ~> u : AB -> exists A, Γ  t : A.
Proof.
  intros.
  remember (t ~> u) as w.
  induction H ; try inversion Heqw.
  - subst. exists type ; easy.
  - subst. clear H2.
    pose proof (IHtyping1 (eq_refl _)).
    assumption.
Qed.

Theorem right_arr_type : forall Γ t u AB, Γ  t ~> u : AB ->
                                                  exists A L, forall x, ~In x L -> Γ, x : A  close u x : type \/ u = type .
Proof.
Admitted.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
124 125


Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
126 127
Theorem FV_decl1 : forall Γ t u, Γ  t : u -> forall v, In v (FV t) -> Defined_var Γ v.
Proof.
128
  intros Γ t ; revert Γ ;  induction t; intros ; try inversion H0.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
129 130 131
  - subst. induction H.
    +  inversion H0. subst. exists A ; easy. inversion H2.
    +  inversion H0.
132
    + destruct (in_app_or (FV A) (FV B) v0 H0).
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
133
      * apply IHtyping. easy.
134
      * destruct (var_inf (v0 :: L)). assert (Defined_var (Γ, x : A) v0).
135
        -- apply H2. intro. apply H4. simpl. right. easy.
136 137
           assert (x <> v0) by (apply (not_in_not_eq _ _ _ H4)).
           apply FV_close ; [assumption | now apply not_eq_sym].
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
138 139 140
        -- induction H5. inversion H5 ; subst.
           ++ contradict H4. simpl. auto.
           ++ econstructor. apply H11.
141
    + destruct (in_app_or (FV A) (FV t) v0 H0).
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
142
      * apply IHtyping. easy.
143 144 145 146
      * destruct (var_inf (v0 :: L)). assert (Defined_var (Γ, x : A) v0).
        -- apply H4. intro. apply H6. simpl. right. easy.
           assert (x <> v0) by (apply (not_in_not_eq _ _ _ H6)).
           apply FV_close ; [assumption | now apply not_eq_sym].
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
147 148
        -- induction H7. inversion H7; subst.
           ++ contradict H6. simpl. auto.
149 150
           ++ econstructor. apply H13.
    + destruct (in_app_or (FV t) (FV u) v0 H0).
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
151 152 153 154
      * apply IHtyping1. easy.
      * apply IHtyping2. easy.
    +  apply IHtyping1. easy.
  - contradict H1.
155 156 157 158 159 160 161 162
  - simpl in H0.
    pose proof (left_arr_type Γ t1 t2 u H).
    destruct H1.
    apply in_app_or in H0 ;  destruct H0.
    + eapply IHt1 ; eassumption.
    + admit.
  - admit.
  - admit.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
163
Qed.
Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

Theorem FV_decl1 : forall Γ x A t u, Γ, x : A  -> ~ In x (FV t) -> ~ In x (FV u) -> Γ  t : u -> Γ, x: A  t : u.
Proof.
  do 5 intro.
  generalize Γ.
  induction t.
  - intros. remember TKind as t'. induction H2 ; inversion Heqt'.
    subst. econstructor. apply IHtyping1. easy. easy. easy.
  - apply TyAxiom. easy. econstructor. easy.
  - apply TyType. easy.
  - apply (TyPi ((FV B) ++ (FV s) ++ L)).
    + apply IHtyping. easy. intro. apply H0. simpl. apply in_or_app. auto. simpl. easy.
    + intros.
Qed.


Theorem FV_decl1 : forall Γ x A y B,
    ~ In x (FV B) -> ~ In y (FV A) -> Γ, x : A, y : B  -> Γ, y : B, x : A .
Proof.
  intros.
  remember (Γ, x : A) as Γ0.
  remember (Γ0, y : B) as Γ1.
  induction H1.
  - inversion HeqΓ1.
188 189 190
    -


Gaspard Ferey's avatar
WIP  
Gaspard Ferey committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204

Theorem FV_decl1 : forall Γ x A y B t u, Γ, x : A, y : B  -> ~ In x (FV t) -> ~ In x (FV u) -> Γ  t : u -> Γ, x: A  t : u.

Theorem FV_decl1 : forall Γ x A t u, Γ, x : A  -> ~ In x (FV t) -> ~ In x (FV u) -> Γ  t : u -> Γ, x: A  t : u.
Proof.
  intros.
  induction H2.
  - apply TyAxiom. easy. econstructor. easy.
  - apply TyType. easy.
  - apply (TyPi ((FV B) ++ (FV s) ++ L)).
    + apply IHtyping. easy. intro. apply H0. simpl. apply in_or_app. auto. simpl. easy.
    + intros.
Qed.

Gaspard Ferey's avatar
WIP.  
Gaspard Ferey committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
Theorem WF_var_decl : forall Γ x A, Γ, x : A  -> Γ .
Proof.
  intros.
  remember (Γ, x : A) as Γ0.
  induction H.
  - inversion HeqΓ0.
  - inversion HeqΓ0. subst. induction H.
    + easy.
    + easy.
    + apply IHtyping. easy.
    + apply IHtyping. easy.
    + apply IHtyping1. easy.
    + apply IHtyping1. easy.
  - inversion HeqΓ0. subst. induction H.
    + easy.
    + easy.
    + apply IHtyping. easy.
    + apply IHtyping. easy.
    + apply IHtyping1. easy.
    + apply IHtyping1. easy.
  - inversion HeqΓ0.
Qed.

Theorem WF_rul_decl : forall Γ t u, Γ, t  u  -> Γ .
Proof.
  intros.
  remember (Γ, t  u) as Γ0.
  induction H.
  - inversion HeqΓ0.
  - inversion HeqΓ0.
  - inversion HeqΓ0.
  - subst. inversion HeqΓ0. subst. easy.
Qed.

Theorem TyPreserv_var_decl : forall Γ x A c d, Γ   c : d -> Γ, x : A  -> Γ, x : A  c : d.
Proof.
  intros.
  induction H.
  - apply TyAxiom. easy. constructor. easy.
  - apply TyType. easy.
  -  apply (TyPi (x :: L)).
    + apply IHtyping. easy.
    + intros.
      assert (Γ, x0 : A0  B : s). apply (H1 x0). intro. apply H3. right. easy.
249

Gaspard Ferey's avatar
WIP.  
Gaspard Ferey committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
      remember (Γ, x0 : A0) as Γ0.
      induction H4.
      * subst.
        inversion H5.
        -- subst. apply TyAxiom. constructor.
Qed.

Theorem TyPreserv_rul_decl : forall Γ t u c d, Γ   c : d -> Γ, t  u  c : d.
Proof.
Admitted.


Theorem TyPi2 : forall Γ A B s, Γ  A : type -> Γ  B : s -> Γ  Π A ~ B : s.
Proof.
  intros.
  apply (TyPi nil).
  - easy.
267
  - intros. apply TyPreserv_var_decl. easy.
Gaspard Ferey's avatar
WIP.  
Gaspard Ferey committed
268 269 270 271 272 273 274 275 276 277
Qed.

Theorem TyAbs2 : forall Γ A B s t, Γ  A : type -> Γ  B : s -> Γ  t : B -> Γ  λ A ~ t : Π A ~ B.
Proof.
  intros.
  eapply (TyAbs nil).
  - easy.
  - intros. apply TyPreserv_var_decl. apply H0.
  - intros. apply TyPreserv_var_decl. apply H1.
Qed.