| 1 |
(** Occur-check for Meta (up to delta) *) |
| 2 |
|
| 3 |
(** LNMItPredShort.v Version 2.0 July 2008 *) |
| 4 |
(** does not need impredicative Set, runs under V8.2, tested with SVN 11296 *) |
| 5 |
|
| 6 |
(** Copyright Ralph Matthes, I.R.I.T., C.N.R.S. & University of Toulouse*) |
| 7 |
|
| 8 |
|
| 9 |
Set Implicit Arguments. |
| 10 |
|
| 11 |
(** the universe of all monotypes *) |
| 12 |
Definition k0 := Set. |
| 13 |
|
| 14 |
(** the type of all type transformations *) |
| 15 |
Definition k1 := k0 -> k0. |
| 16 |
|
| 17 |
(** the type of all rank-2 type transformations *) |
| 18 |
Definition k2 := k1 -> k1. |
| 19 |
|
| 20 |
(** polymorphic identity *) |
| 21 |
Definition id : forall (A:Set), A -> A := fun A x => x. |
| 22 |
|
| 23 |
(** composition *) |
| 24 |
Definition comp (A B C:Set)(g:B->C)(f:A->B) : A->C := fun x => g (f x). |
| 25 |
|
| 26 |
Infix "o" := comp (at level 90). |
| 27 |
|
| 28 |
Definition sub_k1 (X Y:k1) : Type := |
| 29 |
forall A:Set, X A -> Y A. |
| 30 |
|
| 31 |
Infix "c_k1" := sub_k1 (at level 60). |
| 32 |
|
| 33 |
(** monotonicity *) |
| 34 |
Definition mon (X:k1) : Type := forall (A B:Set), (A -> B) -> X A -> X B. |
| 35 |
|
| 36 |
(** extensionality *) |
| 37 |
Definition ext (X:k1)(h: mon X): Prop := |
| 38 |
forall (A B:Set)(f g:A -> B), |
| 39 |
(forall a, f a = g a) -> forall r, h _ _ f r = h _ _ g r. |
| 40 |
|
| 41 |
(** first functor law *) |
| 42 |
Definition fct1 (X:k1)(m: mon X) : Prop := |
| 43 |
forall (A:Set)(x:X A), m _ _ (id(A:=A)) x = x. |
| 44 |
|
| 45 |
(** second functor law *) |
| 46 |
Definition fct2 (X:k1)(m: mon X) : Prop := |
| 47 |
forall (A B C:Set)(f:A -> B)(g:B -> C)(x:X A), |
| 48 |
m _ _ (g o f) x = m _ _ g (m _ _ f x). |
| 49 |
|
| 50 |
(** pack up the good properties of the approximation into |
| 51 |
the notion of an extensional functor *) |
| 52 |
Record EFct (X:k1) : Type := mkEFct |
| 53 |
{ m : mon X; |
| 54 |
e : ext m; |
| 55 |
f1 : fct1 m; |
| 56 |
f2 : fct2 m }. |
| 57 |
|
| 58 |
(** preservation of extensional functors *) |
| 59 |
Definition pEFct (F:k2) : Type := |
| 60 |
forall (X:k1), EFct X -> EFct (F X). |
| 61 |
|
| 62 |
|
| 63 |
(** we show some closure properties of pEFct, depending on such properties |
| 64 |
for EFct *) |
| 65 |
|
| 66 |
Definition moncomp (X Y:k1)(mX:mon X)(mY:mon Y): mon (fun A => X(Y A)). |
| 67 |
Proof. |
| 68 |
red. |
| 69 |
intros A B f x. |
| 70 |
exact (mX (Y A)(Y B) (mY A B f) x). |
| 71 |
Defined. |
| 72 |
|
| 73 |
(** closure under composition *) |
| 74 |
Lemma compEFct (X Y:k1): EFct X -> EFct Y -> EFct (fun A => X(Y A)). |
| 75 |
Proof. |
| 76 |
intros ef1 ef2. |
| 77 |
apply (mkEFct(m:=moncomp (m ef1) (m ef2))); red; intros; unfold moncomp. |
| 78 |
(* prove ext *) |
| 79 |
apply (e ef1). |
| 80 |
intro. |
| 81 |
apply (e ef2); trivial. |
| 82 |
(* prove fct1 *) |
| 83 |
rewrite (e ef1 (m ef2 (id (A:=A))) (id(A:=Y A))). |
| 84 |
apply (f1 ef1). |
| 85 |
intro. |
| 86 |
apply (f1 ef2). |
| 87 |
(* prove fct2 *) |
| 88 |
rewrite (e ef1 (m ef2 (g o f))((m ef2 g)o(m ef2 f))). |
| 89 |
apply (f2 ef1). |
| 90 |
intro. |
| 91 |
unfold comp at 2. |
| 92 |
apply (f2 ef2). |
| 93 |
Defined. |
| 94 |
|
| 95 |
Corollary comppEFct (F G:k2): pEFct F -> pEFct G -> |
| 96 |
pEFct (fun X A => F X (G X A)). |
| 97 |
Proof. |
| 98 |
red. |
| 99 |
intros. |
| 100 |
apply compEFct; auto. |
| 101 |
Defined. |
| 102 |
|
| 103 |
(** closure under sums *) |
| 104 |
Lemma sumEFct (X Y:k1): EFct X -> EFct Y -> EFct (fun A => X A + Y A)%type. |
| 105 |
Proof. |
| 106 |
intros ef1 ef2. |
| 107 |
set (m12:=fun (A B:Set)(f:A->B) x => match x with |
| 108 |
| inl y => inl _ (m ef1 f y) |
| 109 |
| inr y => inr _ (m ef2 f y) |
| 110 |
end). |
| 111 |
apply (mkEFct(m:=m12)); red; intros. |
| 112 |
(* prove ext *) |
| 113 |
destruct r. |
| 114 |
simpl. |
| 115 |
apply (f_equal (fun x=>inl (A:=X B) (Y B) x)). |
| 116 |
apply (e ef1); trivial. |
| 117 |
simpl. |
| 118 |
apply (f_equal (fun x=>inr (X B) (B:=Y B) x)). |
| 119 |
apply (e ef2); trivial. |
| 120 |
(* prove fct1 *) |
| 121 |
destruct x. |
| 122 |
simpl. |
| 123 |
apply (f_equal (fun x=>inl (A:=X A) (Y A) x)). |
| 124 |
apply (f1 ef1). |
| 125 |
simpl. |
| 126 |
apply (f_equal (fun x=>inr (X A) (B:=Y A) x)). |
| 127 |
apply (f1 ef2). |
| 128 |
(* prove fct2 *) |
| 129 |
destruct x. |
| 130 |
simpl. |
| 131 |
rewrite (f2 ef1); reflexivity. |
| 132 |
simpl. |
| 133 |
rewrite (f2 ef2); reflexivity. |
| 134 |
Defined. |
| 135 |
|
| 136 |
Corollary sumpEFct (F G:k2): pEFct F -> pEFct G -> |
| 137 |
pEFct (fun X A => F X A + G X A)%type. |
| 138 |
Proof. |
| 139 |
red. |
| 140 |
intros. |
| 141 |
apply sumEFct; auto. |
| 142 |
Defined. |
| 143 |
|
| 144 |
(** closure under products *) |
| 145 |
Lemma prodEFct (X Y:k1): EFct X -> EFct Y -> EFct (fun A => X A * Y A)%type. |
| 146 |
Proof. |
| 147 |
intros ef1 ef2. |
| 148 |
set (m12:=fun (A B:Set)(f:A->B) x => match x with |
| 149 |
(x1,x2) => (m ef1 f x1, m ef2 f x2) end). |
| 150 |
apply (mkEFct(m:=m12)); red; intros. |
| 151 |
(* prove ext *) |
| 152 |
destruct r as [x1 x2]. |
| 153 |
simpl. |
| 154 |
apply injective_projections; simpl. |
| 155 |
apply (e ef1); trivial. |
| 156 |
apply (e ef2); trivial. |
| 157 |
(* prove fct1 *) |
| 158 |
destruct x as [x1 x2]. |
| 159 |
simpl. |
| 160 |
apply injective_projections; simpl. |
| 161 |
apply (f1 ef1). |
| 162 |
apply (f1 ef2). |
| 163 |
(* prove fct2 *) |
| 164 |
destruct x as [x1 x2]. |
| 165 |
simpl. |
| 166 |
apply injective_projections; simpl. |
| 167 |
apply (f2 ef1). |
| 168 |
apply (f2 ef2). |
| 169 |
Defined. |
| 170 |
|
| 171 |
Corollary prodpEFct (F G:k2): pEFct F -> pEFct G -> |
| 172 |
pEFct (fun X A => F X A * G X A)%type. |
| 173 |
Proof. |
| 174 |
red. |
| 175 |
intros. |
| 176 |
apply prodEFct; auto. |
| 177 |
Defined. |
| 178 |
|
| 179 |
(** the identity in k2 preserves extensional functors *) |
| 180 |
Lemma idpEFct: pEFct (fun X => X). |
| 181 |
Proof. |
| 182 |
red. |
| 183 |
intros. |
| 184 |
assumption. |
| 185 |
Defined. |
| 186 |
|
| 187 |
(** a variant for the eta-expanded identity *) |
| 188 |
Lemma idpEFct_eta: pEFct (fun X A => X A). |
| 189 |
Proof. |
| 190 |
red. |
| 191 |
intros X ef. |
| 192 |
destruct ef as [m0 e0 f01 f02]. |
| 193 |
change (mon X) with (mon (fun A => X A)) in m0. |
| 194 |
apply (mkEFct (m:=m0) e0 f01 f02). |
| 195 |
Defined. |
| 196 |
|
| 197 |
(** the identity in k1 "is" an extensional functor *) |
| 198 |
Lemma idEFct: EFct (fun A => A). |
| 199 |
Proof. |
| 200 |
set (mId:=fun A B (f:A->B)(x:A) => f x). |
| 201 |
apply (mkEFct(m:=mId)). |
| 202 |
red. |
| 203 |
intros. |
| 204 |
unfold mId. |
| 205 |
apply H. |
| 206 |
red. |
| 207 |
reflexivity. |
| 208 |
red. |
| 209 |
reflexivity. |
| 210 |
Defined. |
| 211 |
|
| 212 |
(** constants in k2 *) |
| 213 |
Lemma constpEFct (X:k1): EFct X -> pEFct (fun _ => X). |
| 214 |
Proof. |
| 215 |
red. |
| 216 |
intros. |
| 217 |
assumption. |
| 218 |
Defined. |
| 219 |
|
| 220 |
(** constants in k1 *) |
| 221 |
Lemma constEFct (C:Set): EFct (fun _ => C). |
| 222 |
Proof. |
| 223 |
set (mC:=fun A B (f:A->B)(x:C) => x). |
| 224 |
apply (mkEFct(m:=mC)); red; intros; unfold mC; reflexivity. |
| 225 |
Defined. |
| 226 |
|
| 227 |
|
| 228 |
(** the option type *) |
| 229 |
Lemma optionEFct: EFct (fun (A:Set) => option A). |
| 230 |
apply (mkEFct (X:=fun (A:Set) => option A)(m:=option_map)); red; intros. |
| 231 |
destruct r. |
| 232 |
simpl. |
| 233 |
rewrite H. |
| 234 |
reflexivity. |
| 235 |
reflexivity. |
| 236 |
destruct x; reflexivity. |
| 237 |
destruct x; reflexivity. |
| 238 |
Defined. |
| 239 |
|
| 240 |
|
| 241 |
(** natural transformations from (X,mX) to (Y,mY) *) |
| 242 |
Definition NAT(X Y:k1)(j:X c_k1 Y)(mX:mon X)(mY:mon Y) : Prop := |
| 243 |
forall (A B:Set)(f:A->B)(t:X A), j B (mX A B f t) = mY _ _ f (j A t). |
| 244 |
|
| 245 |
|
| 246 |
Module Type LNMIt_Type. |
| 247 |
|
| 248 |
Parameter F:k2. |
| 249 |
Parameter FpEFct: pEFct F. |
| 250 |
Parameter mu20: k1. |
| 251 |
Definition mu2: k1:= fun A => mu20 A. |
| 252 |
Parameter mapmu2: mon mu2. |
| 253 |
Definition MItType: Type := |
| 254 |
forall G : k1, (forall X : k1, X c_k1 G -> F X c_k1 G) -> mu2 c_k1 G. |
| 255 |
Parameter MIt0 : MItType. |
| 256 |
Definition MIt : MItType:= fun G s A t => MIt0 s t. |
| 257 |
Definition InType : Type := |
| 258 |
forall (X:k1)(ef:EFct X)(j: X c_k1 mu2), |
| 259 |
NAT j (m ef) mapmu2 -> F X c_k1 mu2. |
| 260 |
Parameter In : InType. |
| 261 |
Axiom mapmu2Red : forall (A:Set)(X:k1)(ef:EFct X)(j: X c_k1 mu2) |
| 262 |
(n: NAT j (m ef) mapmu2)(t: F X A)(B:Set)(f:A->B), |
| 263 |
mapmu2 f (In ef n t) = In ef n (m (FpEFct ef) f t). |
| 264 |
Axiom MItRed : forall (G : k1) |
| 265 |
(s : forall X : k1, X c_k1 G -> F X c_k1 G)(X : k1)(ef:EFct X)(j: X c_k1 mu2) |
| 266 |
(n: NAT j (m ef) mapmu2)(A:Set)(t:F X A), |
| 267 |
MIt s (In ef n t) = s X (fun A => (MIt s (A:=A)) o (j A)) A t. |
| 268 |
Definition mu2IndType : Prop := |
| 269 |
forall (P : (forall A : Set, mu2 A -> Prop)), |
| 270 |
(forall (X : k1)(ef:EFct X)(j : X c_k1 mu2)(n: NAT j (m ef) mapmu2), |
| 271 |
(forall (A : Set) (x : X A), P A (j A x)) -> |
| 272 |
forall (A:Set)(t : F X A), P A (In ef n t)) -> |
| 273 |
forall (A : Set) (r : mu2 A), P A r. |
| 274 |
Axiom mu2Ind : mu2IndType. |
| 275 |
|
| 276 |
End LNMIt_Type. |
| 277 |
|
| 278 |
(** BushDepPredShort.v Version 0.2 July 2008 *) |
| 279 |
(** does not need impredicative Set, produces stack overflow under V8.2, tested |
| 280 |
with SVN 11296 *) |
| 281 |
|
| 282 |
(** Copyright Ralph Matthes, I.R.I.T., C.N.R.S. & University of Toulouse *) |
| 283 |
|
| 284 |
Set Implicit Arguments. |
| 285 |
|
| 286 |
Require Import TestSuite.list. |
| 287 |
|
| 288 |
Definition listk1 (A:Set) : Set := list A. |
| 289 |
Open Scope type_scope. |
| 290 |
|
| 291 |
Definition BushF(X:k1)(A:Set) := unit + A * X (X A). |
| 292 |
|
| 293 |
Definition bushpEFct : pEFct BushF. |
| 294 |
Proof. |
| 295 |
unfold BushF. |
| 296 |
apply sumpEFct. |
| 297 |
apply constpEFct. |
| 298 |
apply constEFct. |
| 299 |
apply prodpEFct. |
| 300 |
apply constpEFct. |
| 301 |
apply idEFct. |
| 302 |
apply comppEFct. |
| 303 |
apply idpEFct. |
| 304 |
apply idpEFct_eta. |
| 305 |
Defined. |
| 306 |
|
| 307 |
Module Type BUSH := LNMIt_Type with Definition F:=BushF |
| 308 |
with Definition FpEFct := |
| 309 |
bushpEFct. |
| 310 |
|
| 311 |
Module Bush (BushBase:BUSH). |
| 312 |
|
| 313 |
Definition Bush : k1 := BushBase.mu2. |
| 314 |
|
| 315 |
Definition bush : mon Bush := BushBase.mapmu2. |
| 316 |
|
| 317 |
End Bush. |
| 318 |
|
| 319 |
|
| 320 |
Definition Id : k1 := fun X => X. |
| 321 |
|
| 322 |
Fixpoint Pow (X:k1)(k:nat){struct k}:k1:= |
| 323 |
match k with 0 => Id |
| 324 |
| S k' => fun A => X (Pow X k' A) |
| 325 |
end. |
| 326 |
|
| 327 |
Fixpoint POW (k:nat)(X:k1)(m:mon X){struct k} : mon (Pow X k) := |
| 328 |
match k return mon (Pow X k) |
| 329 |
with 0 => fun _ _ f => f |
| 330 |
| S k' => fun _ _ f => m _ _ (POW k' m f) |
| 331 |
end. |
| 332 |
|
| 333 |
Module Type BushkToList_Type. |
| 334 |
|
| 335 |
Declare Module Import BP: BUSH. |
| 336 |
Definition F:=BushF. |
| 337 |
Definition FpEFct:= bushpEFct. |
| 338 |
Definition mu20 := mu20. |
| 339 |
Definition mu2 := mu2. |
| 340 |
Definition mapmu2 := mapmu2. |
| 341 |
Definition MItType:= MItType. |
| 342 |
Definition MIt0 := MIt0. |
| 343 |
Definition MIt := MIt. |
| 344 |
Definition InType := InType. |
| 345 |
Definition In := In. |
| 346 |
Definition mapmu2Red:=mapmu2Red. |
| 347 |
Definition MItRed:=MItRed. |
| 348 |
Definition mu2IndType:=mu2IndType. |
| 349 |
Definition mu2Ind:=mu2Ind. |
| 350 |
|
| 351 |
Definition Bush:= mu2. |
| 352 |
Module BushM := Bush BP. |
| 353 |
|
| 354 |
Parameter BushkToList: forall(k:nat)(A:k0)(t:Pow Bush k A), list A. |
| 355 |
Axiom BushkToList0: forall(A:k0)(t:Pow Bush 0 A), BushkToList 0 A t = cons t nil. |
| 356 |
|
| 357 |
End BushkToList_Type. |
| 358 |
|
| 359 |
Module BushDep (BushkToListM:BushkToList_Type). |
| 360 |
|
| 361 |
Module Bush := Bush BushkToListM. |
| 362 |
|
| 363 |
Import Bush. |
| 364 |
Import BushkToListM. |
| 365 |
|
| 366 |
|
| 367 |
Lemma BushkToList0NAT: NAT(Y:=listk1) (BushkToList 0) (POW 0 bush) map. |
| 368 |
Proof. |
| 369 |
red. |
| 370 |
intros. |
| 371 |
simpl. |
| 372 |
rewrite BushkToList0. |
| 373 |
(* stack overflow for coqc and coqtop *) |
| 374 |
|
| 375 |
|
| 376 |
Abort. |
| 377 |
End BushDep. |