Mercurial > cpdt > repo
comparison src/Universes.v @ 302:7b38729be069
Tweak mark-up to support coqdoc 8.3
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Mon, 17 Jan 2011 15:12:30 -0500 |
parents | be571572c088 |
children | d5787b70cf48 |
comparison
equal
deleted
inserted
replaced
301:f4768d5a75eb | 302:7b38729be069 |
---|---|
67 | 67 |
68 Check nat. | 68 Check nat. |
69 (** %\vspace{-.15in}% [[ | 69 (** %\vspace{-.15in}% [[ |
70 nat | 70 nat |
71 : Set | 71 : Set |
72 ]] *) | 72 ]] |
73 *) | |
73 | 74 |
74 (** printing $ %({}*% #(<a/>*# *) | 75 (** printing $ %({}*% #(<a/>*# *) |
75 (** printing ^ %*{})% #*<a/>)# *) | 76 (** printing ^ %*{})% #*<a/>)# *) |
76 | 77 |
77 Check Set. | 78 Check Set. |
78 (** %\vspace{-.15in}% [[ | 79 (** %\vspace{-.15in}% [[ |
79 Set | 80 Set |
80 : Type $ (0)+1 ^ | 81 : Type $ (0)+1 ^ |
81 | 82 |
82 ]] *) | 83 ]] |
84 *) | |
83 | 85 |
84 Check Type. | 86 Check Type. |
85 (** %\vspace{-.15in}% [[ | 87 (** %\vspace{-.15in}% [[ |
86 Type $ Top.3 ^ | 88 Type $ Top.3 ^ |
87 : Type $ (Top.3)+1 ^ | 89 : Type $ (Top.3)+1 ^ |
98 | 100 |
99 Check forall T : nat, fin T. | 101 Check forall T : nat, fin T. |
100 (** %\vspace{-.15in}% [[ | 102 (** %\vspace{-.15in}% [[ |
101 forall T : nat, fin T | 103 forall T : nat, fin T |
102 : Set | 104 : Set |
103 ]] *) | 105 ]] |
106 *) | |
104 | 107 |
105 Check forall T : Set, T. | 108 Check forall T : Set, T. |
106 (** %\vspace{-.15in}% [[ | 109 (** %\vspace{-.15in}% [[ |
107 forall T : Set, T | 110 forall T : Set, T |
108 : Type $ max(0, (0)+1) ^ | 111 : Type $ max(0, (0)+1) ^ |
109 ]] *) | 112 ]] |
113 *) | |
110 | 114 |
111 Check forall T : Type, T. | 115 Check forall T : Type, T. |
112 (** %\vspace{-.15in}% [[ | 116 (** %\vspace{-.15in}% [[ |
113 forall T : Type $ Top.9 ^ , T | 117 forall T : Type $ Top.9 ^ , T |
114 : Type $ max(Top.9, (Top.9)+1) ^ | 118 : Type $ max(Top.9, (Top.9)+1) ^ |
140 Definition id (T : Type) (x : T) : T := x. | 144 Definition id (T : Type) (x : T) : T := x. |
141 Check id 0. | 145 Check id 0. |
142 (** %\vspace{-.15in}% [[ | 146 (** %\vspace{-.15in}% [[ |
143 id 0 | 147 id 0 |
144 : nat | 148 : nat |
145 ]] *) | 149 ]] |
150 *) | |
146 | 151 |
147 Check id Set. | 152 Check id Set. |
148 (** %\vspace{-.15in}% [[ | 153 (** %\vspace{-.15in}% [[ |
149 id Set | 154 id Set |
150 : Type $ Top.17 ^ | 155 : Type $ Top.17 ^ |
151 ]] *) | 156 ]] |
157 *) | |
152 | 158 |
153 Check id Type. | 159 Check id Type. |
154 (** %\vspace{-.15in}% [[ | 160 (** %\vspace{-.15in}% [[ |
155 id Type $ Top.18 ^ | 161 id Type $ Top.18 ^ |
156 : Type $ Top.19 ^ | 162 : Type $ Top.19 ^ |
157 ]] *) | 163 ]] |
164 *) | |
158 | 165 |
159 (** So far so good. As we apply [id] to different [T] values, the inferred index for [T]'s [Type] occurrence automatically moves higher up the type hierarchy. | 166 (** So far so good. As we apply [id] to different [T] values, the inferred index for [T]'s [Type] occurrence automatically moves higher up the type hierarchy. |
160 | 167 |
161 [[ | 168 [[ |
162 Check id id. | 169 Check id id. |
195 | 202 |
196 Check Const 0. | 203 Check Const 0. |
197 (** %\vspace{-.15in}% [[ | 204 (** %\vspace{-.15in}% [[ |
198 Const 0 | 205 Const 0 |
199 : exp nat | 206 : exp nat |
200 ]] *) | 207 ]] |
208 *) | |
201 | 209 |
202 Check Pair (Const 0) (Const tt). | 210 Check Pair (Const 0) (Const tt). |
203 (** %\vspace{-.15in}% [[ | 211 (** %\vspace{-.15in}% [[ |
204 Pair (Const 0) (Const tt) | 212 Pair (Const 0) (Const tt) |
205 : exp (nat * unit) | 213 : exp (nat * unit) |
206 ]] *) | 214 ]] |
215 *) | |
207 | 216 |
208 Check Eq (Const Set) (Const Type). | 217 Check Eq (Const Set) (Const Type). |
209 (** %\vspace{-.15in}% [[ | 218 (** %\vspace{-.15in}% [[ |
210 Eq (Const Set) (Const Type $ Top.59 ^ ) | 219 Eq (Const Set) (Const Type $ Top.59 ^ ) |
211 : exp bool | 220 : exp bool |
304 | 313 |
305 Check foo nat. | 314 Check foo nat. |
306 (** %\vspace{-.15in}% [[ | 315 (** %\vspace{-.15in}% [[ |
307 foo nat | 316 foo nat |
308 : Set | 317 : Set |
309 ]] *) | 318 ]] |
319 *) | |
310 | 320 |
311 Check foo Set. | 321 Check foo Set. |
312 (** %\vspace{-.15in}% [[ | 322 (** %\vspace{-.15in}% [[ |
313 foo Set | 323 foo Set |
314 : Type | 324 : Type |
315 ]] *) | 325 ]] |
326 *) | |
316 | 327 |
317 Check foo True. | 328 Check foo True. |
318 (** %\vspace{-.15in}% [[ | 329 (** %\vspace{-.15in}% [[ |
319 foo True | 330 foo True |
320 : Prop | 331 : Prop |
345 | 356 |
346 Print sig. | 357 Print sig. |
347 (** %\vspace{-.15in}% [[ | 358 (** %\vspace{-.15in}% [[ |
348 Inductive sig (A : Type) (P : A -> Prop) : Type := | 359 Inductive sig (A : Type) (P : A -> Prop) : Type := |
349 exist : forall x : A, P x -> sig P | 360 exist : forall x : A, P x -> sig P |
350 ]] *) | 361 ]] |
362 *) | |
351 | 363 |
352 Print ex. | 364 Print ex. |
353 (** %\vspace{-.15in}% [[ | 365 (** %\vspace{-.15in}% [[ |
354 Inductive ex (A : Type) (P : A -> Prop) : Prop := | 366 Inductive ex (A : Type) (P : A -> Prop) : Prop := |
355 ex_intro : forall x : A, P x -> ex P | 367 ex_intro : forall x : A, P x -> ex P |
410 (** val sym_ex : __ **) | 422 (** val sym_ex : __ **) |
411 | 423 |
412 let sym_ex = __ | 424 let sym_ex = __ |
413 >> | 425 >> |
414 | 426 |
415 In this example, the [ex] type itself is in [Prop], so whole [ex] packages are erased. Coq extracts every proposition as the (Coq-specific) type %\texttt{%#<tt>#__#</tt>#%}%, whose single constructor is %\texttt{%#<tt>#__#</tt>#%}%. Not only are proofs replaced by [__], but proof arguments to functions are also removed completely, as we see here. | 427 In this example, the [ex] type itself is in [Prop], so whole [ex] packages are erased. Coq extracts every proposition as the (Coq-specific) type %\texttt{\_\_}%#<tt>__</tt>#, whose single constructor is %\texttt{\_\_}%#<tt>__</tt>#. Not only are proofs replaced by [__], but proof arguments to functions are also removed completely, as we see here. |
416 | 428 |
417 Extraction is very helpful as an optimization over programs that contain proofs. In languages like Haskell, advanced features make it possible to program with proofs, as a way of convincing the type checker to accept particular definitions. Unfortunately, when proofs are encoded as values in GADTs, these proofs exist at runtime and consume resources. In contrast, with Coq, as long as you keep all of your proofs within [Prop], extraction is guaranteed to erase them. | 429 Extraction is very helpful as an optimization over programs that contain proofs. In languages like Haskell, advanced features make it possible to program with proofs, as a way of convincing the type checker to accept particular definitions. Unfortunately, when proofs are encoded as values in GADTs, these proofs exist at runtime and consume resources. In contrast, with Coq, as long as you keep all of your proofs within [Prop], extraction is guaranteed to erase them. |
418 | 430 |
419 Many fans of the Curry-Howard correspondence support the idea of %\textit{%#<i>#extracting programs from proofs#</i>#%}%. In reality, few users of Coq and related tools do any such thing. Instead, extraction is better thought of as an optimization that reduces the runtime costs of expressive typing. | 431 Many fans of the Curry-Howard correspondence support the idea of %\textit{%#<i>#extracting programs from proofs#</i>#%}%. In reality, few users of Coq and related tools do any such thing. Instead, extraction is better thought of as an optimization that reduces the runtime costs of expressive typing. |
420 | 432 |
440 | 452 |
441 Check ConstP 0. | 453 Check ConstP 0. |
442 (** %\vspace{-.15in}% [[ | 454 (** %\vspace{-.15in}% [[ |
443 ConstP 0 | 455 ConstP 0 |
444 : expP nat | 456 : expP nat |
445 ]] *) | 457 ]] |
458 *) | |
446 | 459 |
447 Check PairP (ConstP 0) (ConstP tt). | 460 Check PairP (ConstP 0) (ConstP tt). |
448 (** %\vspace{-.15in}% [[ | 461 (** %\vspace{-.15in}% [[ |
449 PairP (ConstP 0) (ConstP tt) | 462 PairP (ConstP 0) (ConstP tt) |
450 : expP (nat * unit) | 463 : expP (nat * unit) |
451 ]] *) | 464 ]] |
465 *) | |
452 | 466 |
453 Check EqP (ConstP Set) (ConstP Type). | 467 Check EqP (ConstP Set) (ConstP Type). |
454 (** %\vspace{-.15in}% [[ | 468 (** %\vspace{-.15in}% [[ |
455 EqP (ConstP Set) (ConstP Type) | 469 EqP (ConstP Set) (ConstP Type) |
456 : expP bool | 470 : expP bool |
457 ]] *) | 471 ]] |
472 *) | |
458 | 473 |
459 Check ConstP (ConstP O). | 474 Check ConstP (ConstP O). |
460 (** %\vspace{-.15in}% [[ | 475 (** %\vspace{-.15in}% [[ |
461 ConstP (ConstP 0) | 476 ConstP (ConstP 0) |
462 : expP (expP nat) | 477 : expP (expP nat) |
473 | 488 |
474 Check (Base 0). | 489 Check (Base 0). |
475 (** %\vspace{-.15in}% [[ | 490 (** %\vspace{-.15in}% [[ |
476 Base 0 | 491 Base 0 |
477 : eqPlus 0 0 | 492 : eqPlus 0 0 |
478 ]] *) | 493 ]] |
494 *) | |
479 | 495 |
480 Check (Func (fun n => n) (fun n => 0 + n) (fun n => Base n)). | 496 Check (Func (fun n => n) (fun n => 0 + n) (fun n => Base n)). |
481 (** %\vspace{-.15in}% [[ | 497 (** %\vspace{-.15in}% [[ |
482 Func (fun n : nat => n) (fun n : nat => 0 + n) (fun n : nat => Base n) | 498 Func (fun n : nat => n) (fun n : nat => 0 + n) (fun n : nat => Base n) |
483 : eqPlus (fun n : nat => n) (fun n : nat => 0 + n) | 499 : eqPlus (fun n : nat => n) (fun n : nat => 0 + n) |
484 ]] *) | 500 ]] |
501 *) | |
485 | 502 |
486 Check (Base (Base 1)). | 503 Check (Base (Base 1)). |
487 (** %\vspace{-.15in}% [[ | 504 (** %\vspace{-.15in}% [[ |
488 Base (Base 1) | 505 Base (Base 1) |
489 : eqPlus (Base 1) (Base 1) | 506 : eqPlus (Base 1) (Base 1) |
490 ]] *) | 507 ]] |
508 *) | |
491 | 509 |
492 | 510 |
493 (** * Axioms *) | 511 (** * Axioms *) |
494 | 512 |
495 (** While the specific logic Gallina is hardcoded into Coq's implementation, it is possible to add certain logical rules in a controlled way. In other words, Coq may be used to reason about many different refinements of Gallina where strictly more theorems are provable. We achieve this by asserting %\textit{%#<i>#axioms#</i>#%}% without proof. | 513 (** While the specific logic Gallina is hardcoded into Coq's implementation, it is possible to add certain logical rules in a controlled way. In other words, Coq may be used to reason about many different refinements of Gallina where strictly more theorems are provable. We achieve this by asserting %\textit{%#<i>#axioms#</i>#%}% without proof. |
546 Qed. | 564 Qed. |
547 | 565 |
548 Print Assumptions t1. | 566 Print Assumptions t1. |
549 (** %\vspace{-.15in}% [[ | 567 (** %\vspace{-.15in}% [[ |
550 Closed under the global context | 568 Closed under the global context |
551 ]] *) | 569 ]] |
570 *) | |
552 | 571 |
553 Theorem t2 : forall P : Prop, ~ ~ P -> P. | 572 Theorem t2 : forall P : Prop, ~ ~ P -> P. |
554 (** [[ | 573 (** [[ |
555 tauto. | 574 tauto. |
556 | 575 |
557 Error: tauto failed. | 576 Error: tauto failed. |
558 | 577 |
559 ]] *) | 578 ]] |
579 *) | |
560 | 580 |
561 intro P; destruct (classic P); tauto. | 581 intro P; destruct (classic P); tauto. |
562 Qed. | 582 Qed. |
563 | 583 |
564 Print Assumptions t2. | 584 Print Assumptions t2. |
694 : forall (A : Set) (f : A -> nat) (g : nat -> A), | 714 : forall (A : Set) (f : A -> nat) (g : nat -> A), |
695 (forall x : A, g (f x) = x) -> | 715 (forall x : A, g (f x) = x) -> |
696 forall P : A -> Prop, | 716 forall P : A -> Prop, |
697 (forall x : A, {P x} + {~ P x}) -> | 717 (forall x : A, {P x} + {~ P x}) -> |
698 (exists! x : A, P x) -> {x : A | P x} | 718 (exists! x : A, P x) -> {x : A | P x} |
699 ]] *) | 719 ]] |
720 *) | |
700 | 721 |
701 Print Assumptions constructive_definite_description. | 722 Print Assumptions constructive_definite_description. |
702 (** %\vspace{-.15in}% [[ | 723 (** %\vspace{-.15in}% [[ |
703 Closed under the global context | 724 Closed under the global context |
704 | 725 |
762 | 783 |
763 Eval compute in (cast (refl_equal (nat -> nat)) (fun n => S n)) 12. | 784 Eval compute in (cast (refl_equal (nat -> nat)) (fun n => S n)) 12. |
764 (** [[ | 785 (** [[ |
765 = 13 | 786 = 13 |
766 : nat | 787 : nat |
767 ]] *) | 788 ]] |
789 *) | |
768 | 790 |
769 (** Things do not go as smoothly when we use [cast] with proofs that rely on axioms. *) | 791 (** Things do not go as smoothly when we use [cast] with proofs that rely on axioms. *) |
770 | 792 |
771 Theorem t3 : (forall n : nat, fin (S n)) = (forall n : nat, fin (n + 1)). | 793 Theorem t3 : (forall n : nat, fin (S n)) = (forall n : nat, fin (n + 1)). |
772 change ((forall n : nat, (fun n => fin (S n)) n) = (forall n : nat, (fun n => fin (n + 1)) n)); | 794 change ((forall n : nat, (fun n => fin (S n)) n) = (forall n : nat, (fun n => fin (n + 1)) n)); |
815 | 837 |
816 Eval compute in cast (t4 13) First. | 838 Eval compute in cast (t4 13) First. |
817 (** %\vspace{-.15in}% [[ | 839 (** %\vspace{-.15in}% [[ |
818 = First | 840 = First |
819 : fin (13 + 1) | 841 : fin (13 + 1) |
820 ]] *) | 842 ]] |
843 *) |