-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProofObjects.html
1349 lines (1082 loc) · 174 KB
/
ProofObjects.html
1
2
3
4
5
6
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="common/css/sf.css" rel="stylesheet" type="text/css" />
<title>ProofObjects: The Curry-Howard Correspondence</title>
<link href="common/jquery-ui/jquery-ui.css" rel="stylesheet">
<script src="common/jquery-ui/external/jquery/jquery.js"></script>
<script src="common/jquery-ui/jquery-ui.js"></script>
<script src="common/toggleproofs.js"></script>
<link href="common/css/lf.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page">
<div id="header">
<div id='logoinheader'><a href='https://softwarefoundations.cis.upenn.edu'>
<img src='common/media/image/sf_logo_sm.png' alt='Software Foundations Logo'></a></div>
<div class='booktitleinheader'><a href='index.html'>Volume 1: Logical Foundations</a></div>
<ul id='menu'>
<li class='section_name'><a href='toc.html'>Table of Contents</a></li>
<li class='section_name'><a href='coqindex.html'>Index</a></li>
<li class='section_name'><a href='deps.html'>Roadmap</a></li>
</ul>
</div>
<div id="main">
<h1 class="libtitle">ProofObjects<span class="subtitle">The Curry-Howard Correspondence</span></h1>
<div class="code">
<span class="id" title="keyword">Set</span> <span class="id" title="var">Warnings</span> "-notation-overridden,-parsing,-deprecated-hint-without-locality".<br/>
<span class="id" title="keyword">From</span> <span class="id" title="var">LF</span> <span class="id" title="keyword">Require</span> <span class="id" title="keyword">Export</span> <a class="idref" href="IndProp.html#"><span class="id" title="library">IndProp</span></a>.<br/>
</div>
<div class="doc">
<div class="quote">"Algorithms are the computational content of proofs."
(Robert Harper)</div>
<div class="paragraph"> </div>
We have seen that Coq has mechanisms both for <i>programming</i>,
using inductive data types like <span class="inlinecode"><span class="id" title="var">nat</span></span> or <span class="inlinecode"><span class="id" title="var">list</span></span> and functions over
these types, and for <i>proving</i> properties of these programs, using
inductive propositions (like <span class="inlinecode"><span class="id" title="var">ev</span></span>), implication, universal
quantification, and the like. So far, we have mostly treated
these mechanisms as if they were quite separate, and for many
purposes this is a good way to think. But we have also seen hints
that Coq's programming and proving facilities are closely related.
For example, the keyword <span class="inlinecode"><span class="id" title="keyword">Inductive</span></span> is used to declare both data
types and propositions, and <span class="inlinecode">→</span> is used both to describe the type
of functions on data and logical implication. This is not just a
syntactic accident! In fact, programs and proofs in Coq are
almost the same thing. In this chapter we will study how this
works.
<div class="paragraph"> </div>
We have already seen the fundamental idea: provability in Coq is
represented by concrete <i>evidence</i>. When we construct the proof
of a basic proposition, we are actually building a tree of
evidence, which can be thought of as a data structure.
<div class="paragraph"> </div>
If the proposition is an implication like <span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">B</span></span>, then its proof
will be an evidence <i>transformer</i>: a recipe for converting
evidence for A into evidence for B. So at a fundamental level,
proofs are simply programs that manipulate evidence.
<div class="paragraph"> </div>
Question: If evidence is data, what are propositions themselves?
<div class="paragraph"> </div>
Answer: They are types!
<div class="paragraph"> </div>
Look again at the formal definition of the <span class="inlinecode"><span class="id" title="var">ev</span></span> property.
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <a id="ev" class="idref" href="#ev"><span class="id" title="definition, inductive"><span id="ev_ind" class="id"><span id="ev_sind" class="id">ev</span></span></span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="ev_0" class="idref" href="#ev_0"><span class="id" title="constructor">ev_0</span></a> : <a class="idref" href="ProofObjects.html#ev:1"><span class="id" title="inductive">ev</span></a> 0<br/>
| <a id="ev_SS" class="idref" href="#ev_SS"><span class="id" title="constructor">ev_SS</span></a> (<a id="n:3" class="idref" href="#n:3"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>) (<a id="H:4" class="idref" href="#H:4"><span class="id" title="binder">H</span></a> : <a class="idref" href="ProofObjects.html#ev:1"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:3"><span class="id" title="variable">n</span></a>) : <a class="idref" href="ProofObjects.html#ev:1"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n:3"><span class="id" title="variable">n</span></a>)).<br/>
</div>
<div class="doc">
Suppose we introduce an alternative pronunciation of "<span class="inlinecode">:</span>".
Instead of "has type," we can say "is a proof of." For example,
the second line in the definition of <span class="inlinecode"><span class="id" title="var">ev</span></span> declares that <span class="inlinecode"><span class="id" title="var">ev_0</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">ev</span></span>
<span class="inlinecode">0</span>. Instead of "<span class="inlinecode"><span class="id" title="var">ev_0</span></span> has type <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">0</span>," we can say that "<span class="inlinecode"><span class="id" title="var">ev_0</span></span>
is a proof of <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">0</span>."
<div class="paragraph"> </div>
This pun between types and propositions -- between <span class="inlinecode">:</span> as "has type"
and <span class="inlinecode">:</span> as "is a proof of" or "is evidence for" -- is called the
<i>Curry-Howard correspondence</i>. It proposes a deep connection
between the world of logic and the world of computation:
<pre>
propositions ~ types
proofs ~ programs
</pre>
See <a href="Bib.html#Wadler-2015"><span class="inlineref">[Wadler 2015]</span></a> for a brief history and up-to-date
exposition.
<div class="paragraph"> </div>
Many useful insights follow from this connection. To begin with,
it gives us a natural interpretation of the type of the <span class="inlinecode"><span class="id" title="var">ev_SS</span></span>
constructor:
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a><br/>
: <span class="id" title="keyword">∀</span> <a id="n:5" class="idref" href="#n:5"><span class="id" title="binder">n</span></a>,<br/>
<a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:5"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a><br/>
<a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n:5"><span class="id" title="variable">n</span></a>)).<br/>
</div>
<div class="doc">
This can be read "<span class="inlinecode"><span class="id" title="var">ev_SS</span></span> is a constructor that takes two
arguments -- a number <span class="inlinecode"><span class="id" title="var">n</span></span> and evidence for the proposition <span class="inlinecode"><span class="id" title="var">ev</span></span>
<span class="inlinecode"><span class="id" title="var">n</span></span> -- and yields evidence for the proposition <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>))</span>."
<div class="paragraph"> </div>
Now let's look again at a previous proof involving <span class="inlinecode"><span class="id" title="var">ev</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev_4" class="idref" href="#ev_4"><span class="id" title="lemma">ev_4</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>. <span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>. <span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
As with ordinary data values and functions, we can use the <span class="inlinecode"><span class="id" title="keyword">Print</span></span>
command to see the <i>proof object</i> that results from this proof
script.
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="var">ev_4</span>.<br/>
<span class="comment">(* ===> ev_4 = ev_SS 2 (ev_SS 0 ev_0)<br/>
: ev 4 *)</span><br/>
</div>
<div class="doc">
Indeed, we can also write down this proof object directly,
without the need for a separate proof script:
</div>
<div class="code">
<span class="id" title="keyword">Check</span> (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 2 (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 0 <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>))<br/>
: <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4.<br/>
</div>
<div class="doc">
The expression <span class="inlinecode"><span class="id" title="var">ev_SS</span></span> <span class="inlinecode">2</span> <span class="inlinecode">(<span class="id" title="var">ev_SS</span></span> <span class="inlinecode">0</span> <span class="inlinecode"><span class="id" title="var">ev_0</span>)</span> can be thought of as
instantiating the parameterized constructor <span class="inlinecode"><span class="id" title="var">ev_SS</span></span> with the
specific arguments <span class="inlinecode">2</span> and <span class="inlinecode">0</span> plus the corresponding proof
objects for its premises <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">2</span> and <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">0</span>. Alternatively, we can
think of <span class="inlinecode"><span class="id" title="var">ev_SS</span></span> as a primitive "evidence constructor" that, when
applied to a particular number, wants to be further applied to
evidence that this number is even; its type,
<br/>
<span class="inlinecode"> <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span>, <span class="id" title="var">ev</span> <span class="id" title="var">n</span> → <span class="id" title="var">ev</span> (<span class="id" title="var">S</span> (<span class="id" title="var">S</span> <span class="id" title="var">n</span>)),
</span> expresses this functionality, in the same way that the polymorphic
type <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">X</span>,</span> <span class="inlinecode"><span class="id" title="var">list</span></span> <span class="inlinecode"><span class="id" title="var">X</span></span> expresses the fact that the constructor
<span class="inlinecode"><span class="id" title="var">nil</span></span> can be thought of as a function from types to empty lists
with elements of that type.
<div class="paragraph"> </div>
We saw in the <a href="Logic.html"><span class="inlineref">Logic</span></a> chapter that we can use function
application syntax to instantiate universally quantified variables
in lemmas, as well as to supply evidence for assumptions that
these lemmas impose. For instance:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev_4'" class="idref" href="#ev_4'"><span class="id" title="lemma">ev_4'</span></a>: <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 2 (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 0 <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>)).<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab303"></a><h1 class="section">Proof Scripts</h1>
<div class="paragraph"> </div>
The <i>proof objects</i> we've been discussing lie at the core of how
Coq operates. When Coq is following a proof script, what is
happening internally is that it is gradually constructing a proof
object -- a term whose type is the proposition being proved. The
tactics between <span class="inlinecode"><span class="id" title="keyword">Proof</span></span> and <span class="inlinecode"><span class="id" title="keyword">Qed</span></span> tell it how to build up a term
of the required type. To see this process in action, let's use
the <span class="inlinecode"><span class="id" title="keyword">Show</span></span> <span class="inlinecode"><span class="id" title="keyword">Proof</span></span> command to display the current state of the proof
tree at various points in the following tactic proof.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev_4''" class="idref" href="#ev_4''"><span class="id" title="lemma">ev_4''</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
At any given moment, Coq has constructed a term with a
"hole" (indicated by <span class="inlinecode">?<span class="id" title="keyword">Goal</span></span> here, and so on), and it knows what
type of evidence is needed to fill this hole.
<div class="paragraph"> </div>
Each hole corresponds to a subgoal, and the proof is
finished when there are no more subgoals. At this point, the
evidence we've built is stored in the global context under the name
given in the <span class="inlinecode"><span class="id" title="keyword">Theorem</span></span> command.
<div class="paragraph"> </div>
Tactic proofs are convenient, but they are not essential in Coq:
in principle, we can always just construct the required evidence
by hand. Then we can use <span class="inlinecode"><span class="id" title="keyword">Definition</span></span> (rather than <span class="inlinecode"><span class="id" title="keyword">Theorem</span></span>) to
introduce a global name for this evidence.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_4'''" class="idref" href="#ev_4'''"><span class="id" title="definition">ev_4'''</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4 :=<br/>
<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 2 (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 0 <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>).<br/>
</div>
<div class="doc">
All these different ways of building the proof lead to exactly the
same evidence being saved in the global environment.
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="var">ev_4</span>.<br/>
<span class="comment">(* ===> ev_4 = ev_SS 2 (ev_SS 0 ev_0) : ev 4 *)</span><br/>
<span class="id" title="keyword">Print</span> <span class="id" title="var">ev_4'</span>.<br/>
<span class="comment">(* ===> ev_4' = ev_SS 2 (ev_SS 0 ev_0) : ev 4 *)</span><br/>
<span class="id" title="keyword">Print</span> <span class="id" title="var">ev_4''</span>.<br/>
<span class="comment">(* ===> ev_4'' = ev_SS 2 (ev_SS 0 ev_0) : ev 4 *)</span><br/>
<span class="id" title="keyword">Print</span> <span class="id" title="var">ev_4'''</span>.<br/>
<span class="comment">(* ===> ev_4''' = ev_SS 2 (ev_SS 0 ev_0) : ev 4 *)</span><br/>
</div>
<div class="doc">
<a id="lab304"></a><h4 class="section">Exercise: 2 stars, standard (eight_is_even)</h4>
Give a tactic proof and a proof object showing that <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">8</span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev_8" class="idref" href="#ev_8"><span class="id" title="lemma">ev_8</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 8.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="ev_8'" class="idref" href="#ev_8'"><span class="id" title="definition">ev_8'</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 8<br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<a id="lab305"></a><h1 class="section">Quantifiers, Implications, Functions</h1>
<div class="paragraph"> </div>
In Coq's computational universe (where data structures and
programs live), there are two sorts of values that have arrows in
their types: <i>constructors</i> introduced by <span class="inlinecode"><span class="id" title="keyword">Inductive</span></span>ly defined
data types, and <i>functions</i>.
<div class="paragraph"> </div>
Similarly, in Coq's logical universe (where we carry out proofs),
there are two ways of giving evidence for an implication:
constructors introduced by <span class="inlinecode"><span class="id" title="keyword">Inductive</span></span>ly defined propositions,
and... functions!
<div class="paragraph"> </div>
For example, consider this statement:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev_plus4" class="idref" href="#ev_plus4"><span class="id" title="lemma">ev_plus4</span></a> : <span class="id" title="keyword">∀</span> <a id="n:6" class="idref" href="#n:6"><span class="id" title="binder">n</span></a>, <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:6"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (4 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="ProofObjects.html#n:6"><span class="id" title="variable">n</span></a>).<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
What is the proof object corresponding to <span class="inlinecode"><span class="id" title="var">ev_plus4</span></span>?
<div class="paragraph"> </div>
We're looking for an expression whose <i>type</i> is <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode"><span class="id" title="var">n</span>,</span> <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">→</span>
<span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode">(4</span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">n</span>)</span> -- that is, a <i>function</i> that takes two arguments (one
number and a piece of evidence) and returns a piece of evidence!
<div class="paragraph"> </div>
Here it is:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_plus4'" class="idref" href="#ev_plus4'"><span class="id" title="definition">ev_plus4'</span></a> : <span class="id" title="keyword">∀</span> <a id="n:7" class="idref" href="#n:7"><span class="id" title="binder">n</span></a>, <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:7"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (4 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="ProofObjects.html#n:7"><span class="id" title="variable">n</span></a>) :=<br/>
<span class="id" title="keyword">fun</span> (<a id="n:8" class="idref" href="#n:8"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>) ⇒ <span class="id" title="keyword">fun</span> (<a id="H:9" class="idref" href="#H:9"><span class="id" title="binder">H</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:8"><span class="id" title="variable">n</span></a>) ⇒<br/>
<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n:8"><span class="id" title="variable">n</span></a>)) (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> <a class="idref" href="ProofObjects.html#n:8"><span class="id" title="variable">n</span></a> <a class="idref" href="ProofObjects.html#H:9"><span class="id" title="variable">H</span></a>).<br/>
</div>
<div class="doc">
Recall that <span class="inlinecode"><span class="id" title="keyword">fun</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">⇒</span> <span class="inlinecode"><span class="id" title="var">blah</span></span> means "the function that, given <span class="inlinecode"><span class="id" title="var">n</span></span>,
yields <span class="inlinecode"><span class="id" title="var">blah</span></span>," and that Coq treats <span class="inlinecode">4</span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>)))</span>
as synonyms. Another equivalent way to write this definition is:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_plus4''" class="idref" href="#ev_plus4''"><span class="id" title="definition">ev_plus4''</span></a> (<a id="n:10" class="idref" href="#n:10"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>) (<a id="H:11" class="idref" href="#H:11"><span class="id" title="binder">H</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:10"><span class="id" title="variable">n</span></a>)<br/>
: <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (4 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="ProofObjects.html#n:10"><span class="id" title="variable">n</span></a>) :=<br/>
<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n:10"><span class="id" title="variable">n</span></a>)) (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> <a class="idref" href="ProofObjects.html#n:10"><span class="id" title="variable">n</span></a> <a class="idref" href="ProofObjects.html#H:11"><span class="id" title="variable">H</span></a>).<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> <a class="idref" href="ProofObjects.html#ev_plus4''"><span class="id" title="definition">ev_plus4''</span></a> : <span class="id" title="keyword">∀</span> <a id="n:12" class="idref" href="#n:12"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:12"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (4 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="ProofObjects.html#n:12"><span class="id" title="variable">n</span></a>).<br/>
</div>
<div class="doc">
When we view the proposition being proved by <span class="inlinecode"><span class="id" title="var">ev_plus4</span></span> as a
function type, one interesting point becomes apparent: The second
argument's type, <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span>, mentions the <i>value</i> of the first
argument, <span class="inlinecode"><span class="id" title="var">n</span></span>.
<div class="paragraph"> </div>
While such <i>dependent types</i> are not found in most mainstream
programming languages, they can be quite useful in programming
too, as the flurry of activity in the functional programming
community over the past couple of decades demonstrates.
<div class="paragraph"> </div>
Notice that both implication (<span class="inlinecode">→</span>) and quantification (<span class="inlinecode"><span class="id" title="keyword">∀</span></span>)
correspond to functions on evidence. In fact, they are really the
same thing: <span class="inlinecode">→</span> is just a shorthand for a degenerate use of
<span class="inlinecode"><span class="id" title="keyword">∀</span></span> where there is no dependency, i.e., no need to give a
name to the type on the left-hand side of the arrow:
<br/>
<span class="inlinecode"> <span class="id" title="keyword">∀</span> (<span class="id" title="var">x</span>:<span class="id" title="var">nat</span>), <span class="id" title="var">nat</span><br/>
= <span class="id" title="keyword">∀</span> (<span class="id" title="var">_</span>:<span class="id" title="var">nat</span>), <span class="id" title="var">nat</span><br/>
= <span class="id" title="var">nat</span> → <span class="id" title="var">nat</span>
</span>
<div class="paragraph"> </div>
For example, consider this proposition:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_plus2" class="idref" href="#ev_plus2"><span class="id" title="definition">ev_plus2</span></a> : <span class="id" title="keyword">Prop</span> :=<br/>
<span class="id" title="keyword">∀</span> <a id="n:13" class="idref" href="#n:13"><span class="id" title="binder">n</span></a>, <span class="id" title="keyword">∀</span> (<a id="E:14" class="idref" href="#E:14"><span class="id" title="binder">E</span></a> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:13"><span class="id" title="variable">n</span></a>), <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="ProofObjects.html#n:13"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2).<br/>
</div>
<div class="doc">
A proof term inhabiting this proposition would be a function
with two arguments: a number <span class="inlinecode"><span class="id" title="var">n</span></span> and some evidence <span class="inlinecode"><span class="id" title="var">E</span></span> that <span class="inlinecode"><span class="id" title="var">n</span></span> is
even. But the name <span class="inlinecode"><span class="id" title="var">E</span></span> for this evidence is not used in the rest
of the statement of <span class="inlinecode"><span class="id" title="var">ev_plus2</span></span>, so it's a bit silly to bother
making up a name for it. We could write it like this instead,
using the dummy identifier <span class="inlinecode"><span class="id" title="var">_</span></span> in place of a real name:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_plus2'" class="idref" href="#ev_plus2'"><span class="id" title="definition">ev_plus2'</span></a> : <span class="id" title="keyword">Prop</span> :=<br/>
<span class="id" title="keyword">∀</span> <a id="n:15" class="idref" href="#n:15"><span class="id" title="binder">n</span></a>, <span class="id" title="keyword">∀</span> (<span class="id" title="var">_</span> : <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:15"><span class="id" title="variable">n</span></a>), <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="ProofObjects.html#n:15"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2).<br/>
</div>
<div class="doc">
Or, equivalently, we can write it in a more familiar way:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="ev_plus2''" class="idref" href="#ev_plus2''"><span class="id" title="definition">ev_plus2''</span></a> : <span class="id" title="keyword">Prop</span> :=<br/>
<span class="id" title="keyword">∀</span> <a id="n:16" class="idref" href="#n:16"><span class="id" title="binder">n</span></a>, <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:16"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="ProofObjects.html#n:16"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2).<br/>
</div>
<div class="doc">
In general, "<span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>" is just syntactic sugar for
"<span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode">(<span class="id" title="var">_</span>:<span class="id" title="var">P</span>),</span> <span class="inlinecode"><span class="id" title="var">Q</span></span>".
</div>
<div class="doc">
<a id="lab306"></a><h1 class="section">Programming with Tactics</h1>
<div class="paragraph"> </div>
If we can build proofs by giving explicit terms rather than
executing tactic scripts, you may be wondering whether we can
build <i>programs</i> using tactics rather than by writing down
explicit terms.
<div class="paragraph"> </div>
Naturally, the answer is yes!
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="add1" class="idref" href="#add1"><span class="id" title="definition">add1</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>.<br/>
<span class="id" title="tactic">intro</span> <span class="id" title="var">n</span>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">n</span>. <span class="id" title="keyword">Defined</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Print</span> <span class="id" title="var">add1</span>.<br/>
<span class="comment">(* ==><br/>
add1 = fun n : nat => S n<br/>
: nat <span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>></span></span> nat<br/>
*)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> <a class="idref" href="ProofObjects.html#add1"><span class="id" title="definition">add1</span></a> 2.<br/>
<span class="comment">(* ==> 3 : nat *)</span><br/>
</div>
<div class="doc">
Notice that we terminated the <span class="inlinecode"><span class="id" title="keyword">Definition</span></span> with a <span class="inlinecode">.</span> rather than
with <span class="inlinecode">:=</span> followed by a term. This tells Coq to enter <i>proof
scripting mode</i> to build an object of type <span class="inlinecode"><span class="id" title="var">nat</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">nat</span></span>. Also, we
terminate the proof with <span class="inlinecode"><span class="id" title="keyword">Defined</span></span> rather than <span class="inlinecode"><span class="id" title="keyword">Qed</span></span>; this makes
the definition <i>transparent</i> so that it can be used in computation
like a normally-defined function. (<span class="inlinecode"><span class="id" title="keyword">Qed</span></span>-defined objects are
opaque during computation.)
<div class="paragraph"> </div>
This feature is mainly useful for writing functions with dependent
types, which we won't explore much further in this book. But it
does illustrate the uniformity and orthogonality of the basic
ideas in Coq.
</div>
<div class="doc">
<a id="lab307"></a><h1 class="section">Logical Connectives as Inductive Types</h1>
<div class="paragraph"> </div>
Inductive definitions are powerful enough to express most of the
logical connectives we have seen so far. Indeed, only universal
quantification (with implication as a special case) is built into
Coq; all the others are defined inductively.
<div class="paragraph"> </div>
Let's see how.
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <a id="Props" class="idref" href="#Props"><span class="id" title="module">Props</span></a>.<br/>
</div>
<div class="doc">
<a id="lab308"></a><h2 class="section">Conjunction</h2>
<div class="paragraph"> </div>
To prove that <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">Q</span></span> holds, we must present evidence for both
<span class="inlinecode"><span class="id" title="var">P</span></span> and <span class="inlinecode"><span class="id" title="var">Q</span></span>. Thus, it makes sense to define a proof object for
<span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">Q</span></span> to consist of a pair of two proofs: one for <span class="inlinecode"><span class="id" title="var">P</span></span> and
another one for <span class="inlinecode"><span class="id" title="var">Q</span></span>. This leads to the following definition.
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <a id="Props.And" class="idref" href="#Props.And"><span class="id" title="module">And</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <a id="Props.And.and" class="idref" href="#Props.And.and"><span class="id" title="definition, inductive"><span id="Props.And.and_rect" class="id"><span id="Props.And.and_ind" class="id"><span id="Props.And.and_rec" class="id"><span id="Props.And.and_sind" class="id">and</span></span></span></span></span></a> (<a id="P:17" class="idref" href="#P:17"><span class="id" title="binder">P</span></a> <a id="Q:18" class="idref" href="#Q:18"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>) : <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="Props.And.conj" class="idref" href="#Props.And.conj"><span class="id" title="constructor">conj</span></a> : <a class="idref" href="ProofObjects.html#P:17"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#Q:18"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#and:19"><span class="id" title="inductive">and</span></a> <a class="idref" href="ProofObjects.html#P:17"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#Q:18"><span class="id" title="variable">Q</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Arguments</span> <a class="idref" href="ProofObjects.html#Props.And.conj"><span class="id" title="constructor">conj</span></a> [<span class="id" title="var">P</span>] [<span class="id" title="var">Q</span>].<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="6ab856ff40ad580509907a32018670d<sub>8</sub>" class="idref" href="#6ab856ff40ad580509907a32018670d<sub>8</sub>"><span class="id" title="notation">"</span></a>P /\ Q" := (<a class="idref" href="ProofObjects.html#Props.And.and"><span class="id" title="inductive">and</span></a> <span class="id" title="var">P</span> <span class="id" title="var">Q</span>) : <span class="id" title="var">type_scope</span>.<br/>
</div>
<div class="doc">
Notice the similarity with the definition of the <span class="inlinecode"><span class="id" title="var">prod</span></span> type,
given in chapter <a href="Poly.html"><span class="inlineref">Poly</span></a>; the only difference is that <span class="inlinecode"><span class="id" title="var">prod</span></span> takes
<span class="inlinecode"><span class="id" title="keyword">Type</span></span> arguments, whereas <span class="inlinecode"><span class="id" title="var">and</span></span> takes <span class="inlinecode"><span class="id" title="keyword">Prop</span></span> arguments.
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="var">prod</span>.<br/>
<span class="comment">(* ===><br/>
Inductive prod (X Y : Type) : Type :=<br/>
| pair : X <span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>></span></span> Y <span class="nowrap"><span style='font-size:85%;'><span style='vertical-align:5%;'><span style='letter-spacing:-.2em;'>-</span></span>></span></span> X * Y. *)</span><br/>
</div>
<div class="doc">
This similarity should clarify why <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> and <span class="inlinecode"><span class="id" title="tactic">intros</span></span>
patterns can be used on a conjunctive hypothesis. Case analysis
allows us to consider all possible ways in which <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode">∧</span> <span class="inlinecode"><span class="id" title="var">Q</span></span> was
proved -- here just one (the <span class="inlinecode"><span class="id" title="var">conj</span></span> constructor).
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="Props.And.proj1'" class="idref" href="#Props.And.proj1'"><span class="id" title="lemma">proj1'</span></a> : <span class="id" title="keyword">∀</span> <a id="P:21" class="idref" href="#P:21"><span class="id" title="binder">P</span></a> <a id="Q:22" class="idref" href="#Q:22"><span class="id" title="binder">Q</span></a>,<br/>
<a class="idref" href="ProofObjects.html#P:21"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#6ab856ff40ad580509907a32018670d<sub>8</sub>"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:22"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:21"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">HPQ</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">HPQ</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">HP</span> <span class="id" title="var">HQ</span>]. <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Similarly, the <span class="inlinecode"><span class="id" title="tactic">split</span></span> tactic actually works for any inductively
defined proposition with exactly one constructor. In particular,
it works for <span class="inlinecode"><span class="id" title="var">and</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="Props.And.and_comm" class="idref" href="#Props.And.and_comm"><span class="id" title="lemma">and_comm</span></a> : <span class="id" title="keyword">∀</span> <a id="P:23" class="idref" href="#P:23"><span class="id" title="binder">P</span></a> <a id="Q:24" class="idref" href="#Q:24"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>, <a class="idref" href="ProofObjects.html#P:23"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#6ab856ff40ad580509907a32018670d<sub>8</sub>"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:24"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'<->'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="ProofObjects.html#Q:24"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#6ab856ff40ad580509907a32018670d<sub>8</sub>"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#P:23"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span>. <span class="id" title="tactic">split</span>.<br/>
- <span class="id" title="tactic">intros</span> [<span class="id" title="var">HP</span> <span class="id" title="var">HQ</span>]. <span class="id" title="tactic">split</span>.<br/>
+ <span class="id" title="tactic">apply</span> <span class="id" title="var">HQ</span>.<br/>
+ <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
- <span class="id" title="tactic">intros</span> [<span class="id" title="var">HQ</span> <span class="id" title="var">HP</span>]. <span class="id" title="tactic">split</span>.<br/>
+ <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
+ <span class="id" title="tactic">apply</span> <span class="id" title="var">HQ</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <a class="idref" href="ProofObjects.html#Props.And"><span class="id" title="module">And</span></a>.<br/>
</div>
<div class="doc">
This shows why the inductive definition of <span class="inlinecode"><span class="id" title="var">and</span></span> can be
manipulated by tactics as we've been doing. We can also use it to
build proofs directly, using pattern-matching. For instance:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.proj1''" class="idref" href="#Props.proj1''"><span class="id" title="definition">proj1''</span></a> <a id="P:25" class="idref" href="#P:25"><span class="id" title="binder">P</span></a> <a id="Q:26" class="idref" href="#Q:26"><span class="id" title="binder">Q</span></a> (<a id="HPQ:27" class="idref" href="#HPQ:27"><span class="id" title="binder">HPQ</span></a> : <a class="idref" href="ProofObjects.html#P:25"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:26"><span class="id" title="variable">Q</span></a>) : <a class="idref" href="ProofObjects.html#P:25"><span class="id" title="variable">P</span></a> :=<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#HPQ:27"><span class="id" title="variable">HPQ</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#conj"><span class="id" title="constructor">conj</span></a> <span class="id" title="var">HP</span> <span class="id" title="var">HQ</span> ⇒ <span class="id" title="var">HP</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="Props.and_comm'_aux" class="idref" href="#Props.and_comm'_aux"><span class="id" title="definition">and_comm'_aux</span></a> <a id="P:29" class="idref" href="#P:29"><span class="id" title="binder">P</span></a> <a id="Q:30" class="idref" href="#Q:30"><span class="id" title="binder">Q</span></a> (<a id="H:31" class="idref" href="#H:31"><span class="id" title="binder">H</span></a> : <a class="idref" href="ProofObjects.html#P:29"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:30"><span class="id" title="variable">Q</span></a>) : <a class="idref" href="ProofObjects.html#Q:30"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#P:29"><span class="id" title="variable">P</span></a> :=<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#H:31"><span class="id" title="variable">H</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#conj"><span class="id" title="constructor">conj</span></a> <span class="id" title="var">HP</span> <span class="id" title="var">HQ</span> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#conj"><span class="id" title="constructor">conj</span></a> <span class="id" title="var">HQ</span> <span class="id" title="var">HP</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="Props.and_comm'" class="idref" href="#Props.and_comm'"><span class="id" title="definition">and_comm'</span></a> <a id="P:33" class="idref" href="#P:33"><span class="id" title="binder">P</span></a> <a id="Q:34" class="idref" href="#Q:34"><span class="id" title="binder">Q</span></a> : <a class="idref" href="ProofObjects.html#P:33"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:34"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'<->'_x"><span class="id" title="notation">↔</span></a> <a class="idref" href="ProofObjects.html#Q:34"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#P:33"><span class="id" title="variable">P</span></a> :=<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#conj"><span class="id" title="constructor">conj</span></a> (<a class="idref" href="ProofObjects.html#Props.and_comm'_aux"><span class="id" title="definition">and_comm'_aux</span></a> <a class="idref" href="ProofObjects.html#P:33"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#Q:34"><span class="id" title="variable">Q</span></a>) (<a class="idref" href="ProofObjects.html#Props.and_comm'_aux"><span class="id" title="definition">and_comm'_aux</span></a> <a class="idref" href="ProofObjects.html#Q:34"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#P:33"><span class="id" title="variable">P</span></a>).<br/>
</div>
<div class="doc">
<a id="lab309"></a><h4 class="section">Exercise: 2 stars, standard (conj_fact)</h4>
Construct a proof object for the following proposition.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.conj_fact" class="idref" href="#Props.conj_fact"><span class="id" title="definition">conj_fact</span></a> : <span class="id" title="keyword">∀</span> <a id="P:35" class="idref" href="#P:35"><span class="id" title="binder">P</span></a> <a id="Q:36" class="idref" href="#Q:36"><span class="id" title="binder">Q</span></a> <a id="R:37" class="idref" href="#R:37"><span class="id" title="binder">R</span></a>, <a class="idref" href="ProofObjects.html#P:35"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#Q:36"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#Q:36"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#R:37"><span class="id" title="variable">R</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:35"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ba2b0e492d2b4675a0acf3ea92aabadd"><span class="id" title="notation">∧</span></a> <a class="idref" href="ProofObjects.html#R:37"><span class="id" title="variable">R</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab310"></a><h2 class="section">Disjunction</h2>
<div class="paragraph"> </div>
The inductive definition of disjunction uses two constructors, one
for each side of the disjunct:
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <a id="Props.Or" class="idref" href="#Props.Or"><span class="id" title="module">Or</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <a id="Props.Or.or" class="idref" href="#Props.Or.or"><span class="id" title="definition, inductive"><span id="Props.Or.or_ind" class="id"><span id="Props.Or.or_sind" class="id">or</span></span></span></a> (<a id="P:38" class="idref" href="#P:38"><span class="id" title="binder">P</span></a> <a id="Q:39" class="idref" href="#Q:39"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>) : <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="Props.Or.or_introl" class="idref" href="#Props.Or.or_introl"><span class="id" title="constructor">or_introl</span></a> : <a class="idref" href="ProofObjects.html#P:38"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#or:40"><span class="id" title="inductive">or</span></a> <a class="idref" href="ProofObjects.html#P:38"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#Q:39"><span class="id" title="variable">Q</span></a><br/>
| <a id="Props.Or.or_intror" class="idref" href="#Props.Or.or_intror"><span class="id" title="constructor">or_intror</span></a> : <a class="idref" href="ProofObjects.html#Q:39"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#or:40"><span class="id" title="inductive">or</span></a> <a class="idref" href="ProofObjects.html#P:38"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#Q:39"><span class="id" title="variable">Q</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Arguments</span> <a class="idref" href="ProofObjects.html#Props.Or.or_introl"><span class="id" title="constructor">or_introl</span></a> [<span class="id" title="var">P</span>] [<span class="id" title="var">Q</span>].<br/>
<span class="id" title="keyword">Arguments</span> <a class="idref" href="ProofObjects.html#Props.Or.or_intror"><span class="id" title="constructor">or_intror</span></a> [<span class="id" title="var">P</span>] [<span class="id" title="var">Q</span>].<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>" class="idref" href="#74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>"><span class="id" title="notation">"</span></a>P \/ Q" := (<a class="idref" href="ProofObjects.html#Props.Or.or"><span class="id" title="inductive">or</span></a> <span class="id" title="var">P</span> <span class="id" title="var">Q</span>) : <span class="id" title="var">type_scope</span>.<br/>
</div>
<div class="doc">
This declaration explains the behavior of the <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> tactic on
a disjunctive hypothesis, since the generated subgoals match the
shape of the <span class="inlinecode"><span class="id" title="var">or_introl</span></span> and <span class="inlinecode"><span class="id" title="var">or_intror</span></span> constructors.
<div class="paragraph"> </div>
Once again, we can also directly write proof objects for theorems
involving <span class="inlinecode"><span class="id" title="var">or</span></span>, without resorting to tactics.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.Or.inj_l" class="idref" href="#Props.Or.inj_l"><span class="id" title="definition">inj_l</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:42" class="idref" href="#P:42"><span class="id" title="binder">P</span></a> <a id="Q:43" class="idref" href="#Q:43"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="ProofObjects.html#P:42"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:42"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:43"><span class="id" title="variable">Q</span></a> :=<br/>
<span class="id" title="keyword">fun</span> <a id="P:44" class="idref" href="#P:44"><span class="id" title="binder">P</span></a> <a id="Q:45" class="idref" href="#Q:45"><span class="id" title="binder">Q</span></a> <a id="HP:46" class="idref" href="#HP:46"><span class="id" title="binder">HP</span></a> ⇒ <a class="idref" href="ProofObjects.html#Props.Or.or_introl"><span class="id" title="constructor">or_introl</span></a> <a class="idref" href="ProofObjects.html#HP:46"><span class="id" title="variable">HP</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="Props.Or.inj_l'" class="idref" href="#Props.Or.inj_l'"><span class="id" title="lemma">inj_l'</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:47" class="idref" href="#P:47"><span class="id" title="binder">P</span></a> <a id="Q:48" class="idref" href="#Q:48"><span class="id" title="binder">Q</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="ProofObjects.html#P:47"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:47"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:48"><span class="id" title="variable">Q</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">HP</span>. <span class="id" title="tactic">left</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="keyword">Show</span> <span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="Props.Or.or_elim" class="idref" href="#Props.Or.or_elim"><span class="id" title="definition">or_elim</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:49" class="idref" href="#P:49"><span class="id" title="binder">P</span></a> <a id="Q:50" class="idref" href="#Q:50"><span class="id" title="binder">Q</span></a> <a id="R:51" class="idref" href="#R:51"><span class="id" title="binder">R</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#P:49"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:50"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#P:49"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:51"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#Q:50"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:51"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:51"><span class="id" title="variable">R</span></a> :=<br/>
<span class="id" title="keyword">fun</span> <a id="P:52" class="idref" href="#P:52"><span class="id" title="binder">P</span></a> <a id="Q:53" class="idref" href="#Q:53"><span class="id" title="binder">Q</span></a> <a id="R:54" class="idref" href="#R:54"><span class="id" title="binder">R</span></a> <a id="HPQ:55" class="idref" href="#HPQ:55"><span class="id" title="binder">HPQ</span></a> <a id="HPR:56" class="idref" href="#HPR:56"><span class="id" title="binder">HPR</span></a> <a id="HQR:57" class="idref" href="#HQR:57"><span class="id" title="binder">HQR</span></a> ⇒<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#HPQ:55"><span class="id" title="variable">HPQ</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="ProofObjects.html#Props.Or.or_introl"><span class="id" title="constructor">or_introl</span></a> <span class="id" title="var">HP</span> ⇒ <a class="idref" href="ProofObjects.html#HPR:56"><span class="id" title="variable">HPR</span></a> <span class="id" title="var">HP</span><br/>
| <a class="idref" href="ProofObjects.html#Props.Or.or_intror"><span class="id" title="constructor">or_intror</span></a> <span class="id" title="var">HQ</span> ⇒ <a class="idref" href="ProofObjects.html#HQR:57"><span class="id" title="variable">HQR</span></a> <span class="id" title="var">HQ</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="Props.Or.or_elim'" class="idref" href="#Props.Or.or_elim'"><span class="id" title="lemma">or_elim'</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:59" class="idref" href="#P:59"><span class="id" title="binder">P</span></a> <a id="Q:60" class="idref" href="#Q:60"><span class="id" title="binder">Q</span></a> <a id="R:61" class="idref" href="#R:61"><span class="id" title="binder">R</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#P:59"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#74311468d5b9a788b8073b6cfc8e0ac<sub>4</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:60"><span class="id" title="variable">Q</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#P:59"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:61"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="ProofObjects.html#Q:60"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:61"><span class="id" title="variable">R</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#R:61"><span class="id" title="variable">R</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">Q</span> <span class="id" title="var">R</span> <span class="id" title="var">HPQ</span> <span class="id" title="var">HPR</span> <span class="id" title="var">HQR</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">HPQ</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">HP</span> | <span class="id" title="var">HQ</span>].<br/>
- <span class="id" title="tactic">apply</span> <span class="id" title="var">HPR</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
- <span class="id" title="tactic">apply</span> <span class="id" title="var">HQR</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HQ</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <a class="idref" href="ProofObjects.html#Props.Or"><span class="id" title="module">Or</span></a>.<br/>
</div>
<div class="doc">
<a id="lab311"></a><h4 class="section">Exercise: 2 stars, standard (or_commut')</h4>
Construct a proof object for the following proposition.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.or_commut'" class="idref" href="#Props.or_commut'"><span class="id" title="definition">or_commut'</span></a> : <span class="id" title="keyword">∀</span> <a id="P:62" class="idref" href="#P:62"><span class="id" title="binder">P</span></a> <a id="Q:63" class="idref" href="#Q:63"><span class="id" title="binder">Q</span></a>, <a class="idref" href="ProofObjects.html#P:62"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:63"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#Q:63"><span class="id" title="variable">Q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#P:62"><span class="id" title="variable">P</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab312"></a><h2 class="section">Existential Quantification</h2>
<div class="paragraph"> </div>
To give evidence for an existential quantifier, we package a
witness <span class="inlinecode"><span class="id" title="var">x</span></span> together with a proof that <span class="inlinecode"><span class="id" title="var">x</span></span> satisfies the property
<span class="inlinecode"><span class="id" title="var">P</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <a id="Props.Ex" class="idref" href="#Props.Ex"><span class="id" title="module">Ex</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <a id="Props.Ex.ex" class="idref" href="#Props.Ex.ex"><span class="id" title="definition, inductive"><span id="Props.Ex.ex_ind" class="id"><span id="Props.Ex.ex_sind" class="id">ex</span></span></span></a> {<a id="A:64" class="idref" href="#A:64"><span class="id" title="binder">A</span></a> : <span class="id" title="keyword">Type</span>} (<a id="P:65" class="idref" href="#P:65"><span class="id" title="binder">P</span></a> : <a class="idref" href="ProofObjects.html#A:64"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) : <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="Props.Ex.ex_intro" class="idref" href="#Props.Ex.ex_intro"><span class="id" title="constructor">ex_intro</span></a> : <span class="id" title="keyword">∀</span> <a id="x:68" class="idref" href="#x:68"><span class="id" title="binder">x</span></a> : <a class="idref" href="ProofObjects.html#A:64"><span class="id" title="variable">A</span></a>, <a class="idref" href="ProofObjects.html#P:65"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:68"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#ex:66"><span class="id" title="inductive">ex</span></a> <a class="idref" href="ProofObjects.html#P:65"><span class="id" title="variable">P</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="ea9d7df266f3dd6dbf5f6c0e65bc25af" class="idref" href="#ea9d7df266f3dd6dbf5f6c0e65bc25af"><span class="id" title="notation">"</span></a>'exists' x , p" :=<br/>
(<a class="idref" href="ProofObjects.html#Props.Ex.ex"><span class="id" title="inductive">ex</span></a> (<span class="id" title="keyword">fun</span> <a id="x:69" class="idref" href="#x:69"><span class="id" title="binder">x</span></a> ⇒ <span class="id" title="var">p</span>))<br/>
(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 200, <span class="id" title="tactic">right</span> <span class="id" title="keyword">associativity</span>) : <span class="id" title="var">type_scope</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <a class="idref" href="ProofObjects.html#Props.Ex"><span class="id" title="module">Ex</span></a>.<br/>
</div>
<div class="doc">
This probably needs a little unpacking. The core definition is
for a type former <span class="inlinecode"><span class="id" title="var">ex</span></span> that can be used to build propositions of
the form <span class="inlinecode"><span class="id" title="var">ex</span></span> <span class="inlinecode"><span class="id" title="var">P</span></span>, where <span class="inlinecode"><span class="id" title="var">P</span></span> itself is a <i>function</i> from witness
values in the type <span class="inlinecode"><span class="id" title="var">A</span></span> to propositions. The <span class="inlinecode"><span class="id" title="var">ex_intro</span></span>
constructor then offers a way of constructing evidence for <span class="inlinecode"><span class="id" title="var">ex</span></span> <span class="inlinecode"><span class="id" title="var">P</span></span>,
given a witness <span class="inlinecode"><span class="id" title="var">x</span></span> and a proof of <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span>.
<div class="paragraph"> </div>
The notation in the standard library is a slight extension of
the above, enabling syntactic forms such as <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode"><span class="id" title="var">y</span>,</span> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode"><span class="id" title="var">y</span></span>.
<div class="paragraph"> </div>
The more familiar form <span class="inlinecode"><span class="id" title="tactic">∃</span></span> <span class="inlinecode"><span class="id" title="var">x</span>,</span> <span class="inlinecode"><span class="id" title="var">ev</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> desugars to an expression
involving <span class="inlinecode"><span class="id" title="var">ex</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex"><span class="id" title="inductive">ex</span></a> (<span class="id" title="keyword">fun</span> <a id="n:70" class="idref" href="#n:70"><span class="id" title="binder">n</span></a> ⇒ <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:70"><span class="id" title="variable">n</span></a>) : <span class="id" title="keyword">Prop</span>.<br/>
</div>
<div class="doc">
Here's how to define an explicit proof object involving <span class="inlinecode"><span class="id" title="var">ex</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.some_nat_is_even" class="idref" href="#Props.some_nat_is_even"><span class="id" title="definition">some_nat_is_even</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="n:71" class="idref" href="#n:71"><span class="id" title="binder">n</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="ProofObjects.html#n:71"><span class="id" title="variable">n</span></a> :=<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex_intro"><span class="id" title="constructor">ex_intro</span></a> <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> 4 (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 2 (<a class="idref" href="ProofObjects.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> 0 <a class="idref" href="ProofObjects.html#ev_0"><span class="id" title="constructor">ev_0</span></a>)).<br/>
</div>
<div class="doc">
<a id="lab313"></a><h4 class="section">Exercise: 2 stars, standard (ex_ev_Sn)</h4>
Construct a proof object for the following proposition.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.ex_ev_Sn" class="idref" href="#Props.ex_ev_Sn"><span class="id" title="definition">ex_ev_Sn</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex"><span class="id" title="inductive">ex</span></a> (<span class="id" title="keyword">fun</span> <a id="n:72" class="idref" href="#n:72"><span class="id" title="binder">n</span></a> ⇒ <a class="idref" href="ProofObjects.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n:72"><span class="id" title="variable">n</span></a>))<br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
To destruct existentials in a proof term we simply use match:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.dist_exists_or_term" class="idref" href="#Props.dist_exists_or_term"><span class="id" title="definition">dist_exists_or_term</span></a> (<a id="X:73" class="idref" href="#X:73"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="P:74" class="idref" href="#P:74"><span class="id" title="binder">P</span></a> <a id="Q:75" class="idref" href="#Q:75"><span class="id" title="binder">Q</span></a> : <a class="idref" href="ProofObjects.html#X:73"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>) :<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:76" class="idref" href="#x:76"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#P:74"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:76"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="ProofObjects.html#Q:75"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#x:76"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:77" class="idref" href="#x:77"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#P:74"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:77"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">∨</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:78" class="idref" href="#x:78"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#Q:75"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#x:78"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#f031fe1957c4a4a8e217aa46af2b4e<sub>25</sub>"><span class="id" title="notation">)</span></a> :=<br/>
<span class="id" title="keyword">fun</span> <a id="H:79" class="idref" href="#H:79"><span class="id" title="binder">H</span></a> ⇒ <span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#H:79"><span class="id" title="variable">H</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex_intro"><span class="id" title="constructor">ex_intro</span></a> <span class="id" title="var">_</span> <span class="id" title="var">x</span> <span class="id" title="var">Hx</span> ⇒<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">Hx</span> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#or_introl"><span class="id" title="constructor">or_introl</span></a> <span class="id" title="var">HPx</span> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#or_introl"><span class="id" title="constructor">or_introl</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex_intro"><span class="id" title="constructor">ex_intro</span></a> <span class="id" title="var">_</span> <span class="id" title="var">x</span> <span class="id" title="var">HPx</span>)<br/>
| <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#or_intror"><span class="id" title="constructor">or_intror</span></a> <span class="id" title="var">HQx</span> ⇒ <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#or_intror"><span class="id" title="constructor">or_intror</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#ex_intro"><span class="id" title="constructor">ex_intro</span></a> <span class="id" title="var">_</span> <span class="id" title="var">x</span> <span class="id" title="var">HQx</span>)<br/>
<span class="id" title="keyword">end</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
<a id="lab314"></a><h4 class="section">Exercise: 2 stars, standard (ex_match)</h4>
Construct a proof object for the following proposition:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.ex_match" class="idref" href="#Props.ex_match"><span class="id" title="definition">ex_match</span></a> : <span class="id" title="keyword">∀</span> (<a id="A:82" class="idref" href="#A:82"><span class="id" title="binder">A</span></a> : <span class="id" title="keyword">Type</span>) (<a id="P:83" class="idref" href="#P:83"><span class="id" title="binder">P</span></a> <a id="Q:84" class="idref" href="#Q:84"><span class="id" title="binder">Q</span></a> : <a class="idref" href="ProofObjects.html#A:82"><span class="id" title="variable">A</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>),<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="x:85" class="idref" href="#x:85"><span class="id" title="binder">x</span></a>, <a class="idref" href="ProofObjects.html#P:83"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:85"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#Q:84"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#x:85"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a><br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:86" class="idref" href="#x:86"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#P:83"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:86"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">∃</span></a> <a id="x:87" class="idref" href="#x:87"><span class="id" title="binder">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#a883bdd010993579f99d60b3775bcf54"><span class="id" title="notation">,</span></a> <a class="idref" href="ProofObjects.html#Q:84"><span class="id" title="variable">Q</span></a> <a class="idref" href="ProofObjects.html#x:87"><span class="id" title="variable">x</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab315"></a><h2 class="section"><span class="inlinecode"><span class="id" title="var">True</span></span> and <span class="inlinecode"><span class="id" title="var">False</span></span></h2>
<div class="paragraph"> </div>
The inductive definition of the <span class="inlinecode"><span class="id" title="var">True</span></span> proposition is simple:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <a id="Props.True" class="idref" href="#Props.True"><span class="id" title="definition, inductive"><span id="Props.True_rect" class="id"><span id="Props.True_ind" class="id"><span id="Props.True_rec" class="id"><span id="Props.True_sind" class="id">True</span></span></span></span></span></a> : <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="Props.I" class="idref" href="#Props.I"><span class="id" title="constructor">I</span></a> : <a class="idref" href="ProofObjects.html#True:88"><span class="id" title="inductive">True</span></a>.<br/>
</div>
<div class="doc">
It has one constructor (so every proof of <span class="inlinecode"><span class="id" title="var">True</span></span> is the same, so
being given a proof of <span class="inlinecode"><span class="id" title="var">True</span></span> is not informative.)
<div class="paragraph"> </div>
<a id="lab316"></a><h4 class="section">Exercise: 1 star, standard (p_implies_true)</h4>
Construct a proof object for the following proposition.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.p_implies_true" class="idref" href="#Props.p_implies_true"><span class="id" title="definition">p_implies_true</span></a> : <span class="id" title="keyword">∀</span> <a id="P:90" class="idref" href="#P:90"><span class="id" title="binder">P</span></a>, <a class="idref" href="ProofObjects.html#P:90"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#Props.True"><span class="id" title="inductive">True</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">False</span></span> is equally simple -- indeed, so simple it may look
syntactically wrong at first glance!
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <a id="Props.False" class="idref" href="#Props.False"><span class="id" title="definition, inductive"><span id="Props.False_rect" class="id"><span id="Props.False_ind" class="id"><span id="Props.False_rec" class="id"><span id="Props.False_sind" class="id">False</span></span></span></span></span></a> : <span class="id" title="keyword">Prop</span> := .<br/>
</div>
<div class="doc">
That is, <span class="inlinecode"><span class="id" title="var">False</span></span> is an inductive type with <i>no</i> constructors --
i.e., no way to build evidence for it. For example, there is
no way to complete the following definition such that it
succeeds.
</div>
<div class="code">
<span class="id" title="var">Fail</span><br/>
<span class="id" title="keyword">Definition</span> <a id="Props.contra" class="idref" href="#Props.contra"><span class="id" title="definition">contra</span></a> : <a class="idref" href="ProofObjects.html#Props.False"><span class="id" title="inductive">False</span></a> :=<br/>
42.<br/>
</div>
<div class="doc">
But it is possible to destruct <span class="inlinecode"><span class="id" title="var">False</span></span> by pattern matching. There can
be no patterns that match it, since it has no constructors. So
the pattern match also is so simple it may look syntactically
wrong at first glance.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.false_implies_zero_eq_one" class="idref" href="#Props.false_implies_zero_eq_one"><span class="id" title="definition">false_implies_zero_eq_one</span></a> : <a class="idref" href="ProofObjects.html#Props.False"><span class="id" title="inductive">False</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 1 :=<br/>
<span class="id" title="keyword">fun</span> <a id="contra:93" class="idref" href="#contra:93"><span class="id" title="binder">contra</span></a> ⇒ <span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#contra:93"><span class="id" title="variable">contra</span></a> <span class="id" title="keyword">with</span> <span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
Since there are no branches to evaluate, the <span class="inlinecode"><span class="id" title="keyword">match</span></span> expression
can be considered to have any type we want, including <span class="inlinecode">0</span> <span class="inlinecode">=</span> <span class="inlinecode">1</span>.
Fortunately, it's impossible to ever cause the <span class="inlinecode"><span class="id" title="keyword">match</span></span> to be
evaluated, because we can never construct a value of type <span class="inlinecode"><span class="id" title="var">False</span></span>
to pass to the function.
<div class="paragraph"> </div>
<a id="lab317"></a><h4 class="section">Exercise: 1 star, standard (ex_falso_quodlibet')</h4>
Construct a proof object for the following proposition.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="Props.ex_falso_quodlibet'" class="idref" href="#Props.ex_falso_quodlibet'"><span class="id" title="definition">ex_falso_quodlibet'</span></a> : <span class="id" title="keyword">∀</span> <a id="P:95" class="idref" href="#P:95"><span class="id" title="binder">P</span></a>, <a class="idref" href="ProofObjects.html#Props.False"><span class="id" title="inductive">False</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:95"><span class="id" title="variable">P</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="code">
<span class="id" title="keyword">End</span> <a class="idref" href="ProofObjects.html#Props"><span class="id" title="module">Props</span></a>.<br/>
</div>
<div class="doc">
<a id="lab318"></a><h1 class="section">Equality</h1>
<div class="paragraph"> </div>
Even Coq's equality relation is not built in. We can define
it ourselves:
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <a id="EqualityPlayground" class="idref" href="#EqualityPlayground"><span class="id" title="module">EqualityPlayground</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <a id="EqualityPlayground.eq" class="idref" href="#EqualityPlayground.eq"><span class="id" title="definition, inductive"><span id="EqualityPlayground.eq_ind" class="id"><span id="EqualityPlayground.eq_sind" class="id">eq</span></span></span></a> {<a id="X:96" class="idref" href="#X:96"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>} : <span class="id" title="var">X</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="var">X</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span> :=<br/>
| <a id="EqualityPlayground.eq_refl" class="idref" href="#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a> : <span class="id" title="keyword">∀</span> <a id="x:99" class="idref" href="#x:99"><span class="id" title="binder">x</span></a>, <a class="idref" href="ProofObjects.html#eq:97"><span class="id" title="inductive">eq</span></a> <a class="idref" href="ProofObjects.html#x:99"><span class="id" title="variable">x</span></a> <a class="idref" href="ProofObjects.html#x:99"><span class="id" title="variable">x</span></a>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Notation</span> <a id="846025eeecd6fa223055d2a135ffab3a" class="idref" href="#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">"</span></a>x == y" := (<a class="idref" href="ProofObjects.html#EqualityPlayground.eq"><span class="id" title="inductive">eq</span></a> <span class="id" title="var">x</span> <span class="id" title="var">y</span>)<br/>
(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 70, <span class="id" title="keyword">no</span> <span class="id" title="keyword">associativity</span>)<br/>
: <span class="id" title="var">type_scope</span>.<br/>
</div>
<div class="doc">
The way to think about this definition (which is just a slight
variant of the standard library's) is that, given a set <span class="inlinecode"><span class="id" title="var">X</span></span>, it
defines a <i>family</i> of propositions "<span class="inlinecode"><span class="id" title="var">x</span></span> is equal to <span class="inlinecode"><span class="id" title="var">y</span></span>," indexed
by pairs of values (<span class="inlinecode"><span class="id" title="var">x</span></span> and <span class="inlinecode"><span class="id" title="var">y</span></span>) from <span class="inlinecode"><span class="id" title="var">X</span></span>. There is just one way
of constructing evidence for members of this family: applying the
constructor <span class="inlinecode"><span class="id" title="var">eq_refl</span></span> to a type <span class="inlinecode"><span class="id" title="var">X</span></span> and a single value <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">X</span></span>,
which yields evidence that <span class="inlinecode"><span class="id" title="var">x</span></span> is equal to <span class="inlinecode"><span class="id" title="var">x</span></span>.
<div class="paragraph"> </div>
Other types of the form <span class="inlinecode"><span class="id" title="var">eq</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> <span class="inlinecode"><span class="id" title="var">y</span></span> where <span class="inlinecode"><span class="id" title="var">x</span></span> and <span class="inlinecode"><span class="id" title="var">y</span></span> are not the
same are thus uninhabited.
<div class="paragraph"> </div>
We can use <span class="inlinecode"><span class="id" title="var">eq_refl</span></span> to construct evidence that, for example, <span class="inlinecode">2</span> <span class="inlinecode">=</span>
<span class="inlinecode">2</span>. Can we also use it to construct evidence that <span class="inlinecode">1</span> <span class="inlinecode">+</span> <span class="inlinecode">1</span> <span class="inlinecode">=</span> <span class="inlinecode">2</span>?
Yes, we can. Indeed, it is the very same piece of evidence!
<div class="paragraph"> </div>
The reason is that Coq treats as "the same" any two terms that are
<i>convertible</i> according to a simple set of computation rules.
<div class="paragraph"> </div>
These rules, which are similar to those used by <span class="inlinecode"><span class="id" title="keyword">Compute</span></span>, include
evaluation of function application, inlining of definitions, and
simplification of <span class="inlinecode"><span class="id" title="keyword">match</span></span>es.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="EqualityPlayground.four" class="idref" href="#EqualityPlayground.four"><span class="id" title="lemma">four</span></a>: 2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2 <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> 1 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 3.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span> tactic that we have used to prove
equalities up to now is essentially just shorthand for <span class="inlinecode"><span class="id" title="tactic">apply</span></span>
<span class="inlinecode"><span class="id" title="var">eq_refl</span></span>.
<div class="paragraph"> </div>
In tactic-based proofs of equality, the conversion rules are
normally hidden in uses of <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> (either explicit or implicit in
other tactics such as <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span>).
<div class="paragraph"> </div>
But you can see them directly at work in the following explicit
proof objects:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="EqualityPlayground.four'" class="idref" href="#EqualityPlayground.four'"><span class="id" title="definition">four'</span></a> : 2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2 <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> 1 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 3 :=<br/>
<a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a> 4.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <a id="EqualityPlayground.singleton" class="idref" href="#EqualityPlayground.singleton"><span class="id" title="definition">singleton</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:100" class="idref" href="#X:100"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="x:101" class="idref" href="#x:101"><span class="id" title="binder">x</span></a>:<a class="idref" href="ProofObjects.html#X:100"><span class="id" title="variable">X</span></a>), <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a><a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="ProofObjects.html#x:101"><span class="id" title="variable">x</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#x:101"><span class="id" title="variable">x</span></a><a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a><a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a> :=<br/>
<span class="id" title="keyword">fun</span> (<a id="X:102" class="idref" href="#X:102"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="x:103" class="idref" href="#x:103"><span class="id" title="binder">x</span></a>:<a class="idref" href="ProofObjects.html#X:102"><span class="id" title="variable">X</span></a>) ⇒ <a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a> <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="ProofObjects.html#x:103"><span class="id" title="variable">x</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a>.<br/>
</div>
<div class="doc">
We can also pattern-match on an equality proof:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="EqualityPlayground.eq_add" class="idref" href="#EqualityPlayground.eq_add"><span class="id" title="definition">eq_add</span></a> : <span class="id" title="keyword">∀</span> (<a id="n<sub>1</sub>:104" class="idref" href="#n<sub>1</sub>:104"><span class="id" title="binder">n<sub>1</sub></span></a> <a id="n<sub>2</sub>:105" class="idref" href="#n<sub>2</sub>:105"><span class="id" title="binder">n<sub>2</sub></span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>), <a class="idref" href="ProofObjects.html#n<sub>1</sub>:104"><span class="id" title="variable">n<sub>1</sub></span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#n<sub>2</sub>:105"><span class="id" title="variable">n<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n<sub>1</sub>:104"><span class="id" title="variable">n<sub>1</sub></span></a><a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">)</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n<sub>2</sub>:105"><span class="id" title="variable">n<sub>2</sub></span></a><a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">)</span></a> :=<br/>
<span class="id" title="keyword">fun</span> <a id="n<sub>1</sub>:106" class="idref" href="#n<sub>1</sub>:106"><span class="id" title="binder">n<sub>1</sub></span></a> <a id="n<sub>2</sub>:107" class="idref" href="#n<sub>2</sub>:107"><span class="id" title="binder">n<sub>2</sub></span></a> <a id="Heq:108" class="idref" href="#Heq:108"><span class="id" title="binder">Heq</span></a> ⇒<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="ProofObjects.html#Heq:108"><span class="id" title="variable">Heq</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a> <span class="id" title="var">n</span> ⇒ <a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <span class="id" title="var">n</span>)<br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
By pattern-matching against <span class="inlinecode"><span class="id" title="var">n<sub>1</sub></span></span> <span class="inlinecode">==</span> <span class="inlinecode"><span class="id" title="var">n<sub>2</sub></span></span>, we obtain a term <span class="inlinecode"><span class="id" title="var">n</span></span>
that replaces <span class="inlinecode"><span class="id" title="var">n<sub>1</sub></span></span> and <span class="inlinecode"><span class="id" title="var">n<sub>2</sub></span></span> in the type we have to produce, so
instead of <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n<sub>1</sub></span>)</span> <span class="inlinecode">==</span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n<sub>2</sub></span>)</span>, we now have to produce something
of type <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>)</span> <span class="inlinecode">==</span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>)</span>, which we establish by <span class="inlinecode"><span class="id" title="var">eq_refl</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>)</span>.
<div class="paragraph"> </div>
A tactic-based proof runs into some difficulties if we try to use
our usual repertoire of tactics, such as <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> and
<span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span>. Those work with *setoid* relations that Coq knows
about, such as <span class="inlinecode">=</span>, but not our <span class="inlinecode">==</span>. We could prove to Coq that
<span class="inlinecode">==</span> is a setoid, but a simpler way is to use <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> and
<span class="inlinecode"><span class="id" title="tactic">apply</span></span> instead.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="EqualityPlayground.eq_add'" class="idref" href="#EqualityPlayground.eq_add'"><span class="id" title="lemma">eq_add'</span></a> : <span class="id" title="keyword">∀</span> (<a id="n<sub>1</sub>:110" class="idref" href="#n<sub>1</sub>:110"><span class="id" title="binder">n<sub>1</sub></span></a> <a id="n<sub>2</sub>:111" class="idref" href="#n<sub>2</sub>:111"><span class="id" title="binder">n<sub>2</sub></span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>), <a class="idref" href="ProofObjects.html#n<sub>1</sub>:110"><span class="id" title="variable">n<sub>1</sub></span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#n<sub>2</sub>:111"><span class="id" title="variable">n<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n<sub>1</sub>:110"><span class="id" title="variable">n<sub>1</sub></span></a><a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">)</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">(</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="ProofObjects.html#n<sub>2</sub>:111"><span class="id" title="variable">n<sub>2</sub></span></a><a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n<sub>1</sub></span> <span class="id" title="var">n<sub>2</sub></span> <span class="id" title="var">Heq</span>.<br/>
<span class="id" title="var">Fail</span> <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Heq</span>. <span class="comment">(* doesn't work for _our_ == relation *)</span><br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">Heq</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">n</span>]. <span class="comment">(* n<sub>1</sub> and n<sub>2</sub> replaced by n in the goal! *)</span><br/>
<span class="id" title="var">Fail</span> <span class="id" title="tactic">reflexivity</span>. <span class="comment">(* doesn't work for _our_ == relation *)</span><br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="ProofObjects.html#EqualityPlayground.eq_refl"><span class="id" title="constructor">eq_refl</span></a>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab319"></a><h4 class="section">Exercise: 2 stars, standard (eq_cons)</h4>
Construct the proof object for the following theorem. Use pattern
matching on the equality hypotheses.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="EqualityPlayground.eq_cons" class="idref" href="#EqualityPlayground.eq_cons"><span class="id" title="definition">eq_cons</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:112" class="idref" href="#X:112"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="h<sub>1</sub>:113" class="idref" href="#h<sub>1</sub>:113"><span class="id" title="binder">h<sub>1</sub></span></a> <a id="h<sub>2</sub>:114" class="idref" href="#h<sub>2</sub>:114"><span class="id" title="binder">h<sub>2</sub></span></a> : <a class="idref" href="ProofObjects.html#X:112"><span class="id" title="variable">X</span></a>) (<a id="t<sub>1</sub>:115" class="idref" href="#t<sub>1</sub>:115"><span class="id" title="binder">t<sub>1</sub></span></a> <a id="t<sub>2</sub>:116" class="idref" href="#t<sub>2</sub>:116"><span class="id" title="binder">t<sub>2</sub></span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="ProofObjects.html#X:112"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="ProofObjects.html#h<sub>1</sub>:113"><span class="id" title="variable">h<sub>1</sub></span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#h<sub>2</sub>:114"><span class="id" title="variable">h<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#t<sub>1</sub>:115"><span class="id" title="variable">t<sub>1</sub></span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#t<sub>2</sub>:116"><span class="id" title="variable">t<sub>2</sub></span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#h<sub>1</sub>:113"><span class="id" title="variable">h<sub>1</sub></span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="ProofObjects.html#t<sub>1</sub>:115"><span class="id" title="variable">t<sub>1</sub></span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#h<sub>2</sub>:114"><span class="id" title="variable">h<sub>2</sub></span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="ProofObjects.html#t<sub>2</sub>:116"><span class="id" title="variable">t<sub>2</sub></span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab320"></a><h4 class="section">Exercise: 2 stars, standard (equality__leibniz_equality)</h4>
The inductive definition of equality implies <i>Leibniz equality</i>:
what we mean when we say "<span class="inlinecode"><span class="id" title="var">x</span></span> and <span class="inlinecode"><span class="id" title="var">y</span></span> are equal" is that every
property on <span class="inlinecode"><span class="id" title="var">P</span></span> that is true of <span class="inlinecode"><span class="id" title="var">x</span></span> is also true of <span class="inlinecode"><span class="id" title="var">y</span></span>. Prove
that.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="EqualityPlayground.equality__leibniz_equality" class="idref" href="#EqualityPlayground.equality__leibniz_equality"><span class="id" title="lemma">equality__leibniz_equality</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:117" class="idref" href="#X:117"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="x:118" class="idref" href="#x:118"><span class="id" title="binder">x</span></a> <a id="y:119" class="idref" href="#y:119"><span class="id" title="binder">y</span></a>: <a class="idref" href="ProofObjects.html#X:117"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="ProofObjects.html#x:118"><span class="id" title="variable">x</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#y:119"><span class="id" title="variable">y</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">∀</span> (<a id="P:120" class="idref" href="#P:120"><span class="id" title="binder">P</span></a> : <a class="idref" href="ProofObjects.html#X:117"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>), <a class="idref" href="ProofObjects.html#P:120"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:118"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:120"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#y:119"><span class="id" title="variable">y</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab321"></a><h4 class="section">Exercise: 2 stars, standard (equality__leibniz_equality_term)</h4>
Construct the proof object for the previous exercise. All it
requires is anonymous functions and pattern-matching; the large
proof term constructed by tactics in the previous exercise is
needessly complicated. Hint: pattern-match as soon as possible.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="EqualityPlayground.equality__leibniz_equality_term" class="idref" href="#EqualityPlayground.equality__leibniz_equality_term"><span class="id" title="definition">equality__leibniz_equality_term</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:121" class="idref" href="#X:121"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="x:122" class="idref" href="#x:122"><span class="id" title="binder">x</span></a> <a id="y:123" class="idref" href="#y:123"><span class="id" title="binder">y</span></a>: <a class="idref" href="ProofObjects.html#X:121"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="ProofObjects.html#x:122"><span class="id" title="variable">x</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#y:123"><span class="id" title="variable">y</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">∀</span> <a id="P:124" class="idref" href="#P:124"><span class="id" title="binder">P</span></a> : (<a class="idref" href="ProofObjects.html#X:121"><span class="id" title="variable">X</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <span class="id" title="keyword">Prop</span>), <a class="idref" href="ProofObjects.html#P:124"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:122"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:124"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#y:123"><span class="id" title="variable">y</span></a><br/>
<span class="comment">(* REPLACE THIS LINE WITH ":= _your_definition_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
<a id="lab322"></a><h4 class="section">Exercise: 3 stars, standard, optional (leibniz_equality__equality)</h4>
Show that, in fact, the inductive definition of equality is
<i>equivalent</i> to Leibniz equality. Hint: the proof is quite short;
about all you need to do is to invent a clever property <span class="inlinecode"><span class="id" title="var">P</span></span> to
instantiate the antecedent.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="EqualityPlayground.leibniz_equality__equality" class="idref" href="#EqualityPlayground.leibniz_equality__equality"><span class="id" title="lemma">leibniz_equality__equality</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:125" class="idref" href="#X:125"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="x:126" class="idref" href="#x:126"><span class="id" title="binder">x</span></a> <a id="y:127" class="idref" href="#y:127"><span class="id" title="binder">y</span></a>: <a class="idref" href="ProofObjects.html#X:125"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><span class="id" title="keyword">∀</span> <a id="P:128" class="idref" href="#P:128"><span class="id" title="binder">P</span></a>:<a class="idref" href="ProofObjects.html#X:125"><span class="id" title="variable">X</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a><span class="id" title="keyword">Prop</span>, <a class="idref" href="ProofObjects.html#P:128"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#x:126"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#P:128"><span class="id" title="variable">P</span></a> <a class="idref" href="ProofObjects.html#y:127"><span class="id" title="variable">y</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="ProofObjects.html#x:126"><span class="id" title="variable">x</span></a> <a class="idref" href="ProofObjects.html#846025eeecd6fa223055d2a135ffab3a"><span class="id" title="notation">==</span></a> <a class="idref" href="ProofObjects.html#y:127"><span class="id" title="variable">y</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="code">
<span class="id" title="keyword">End</span> <a class="idref" href="ProofObjects.html#EqualityPlayground"><span class="id" title="module">EqualityPlayground</span></a>.<br/>
</div>
<div class="doc">
<a id="lab323"></a><h2 class="section">Inversion, Again</h2>