-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTactics.html
1863 lines (1471 loc) · 260 KB
/
Tactics.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>Tactics: More Basic Tactics</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">Tactics<span class="subtitle">More Basic Tactics</span></h1>
<div class="doc">
<div class="paragraph"> </div>
This chapter introduces several additional proof strategies
and tactics that allow us to begin proving more interesting
properties of functional programs.
<div class="paragraph"> </div>
We will see:
<ul class="doclist">
<li> how to use auxiliary lemmas in both "forward-" and
"backward-style" proofs;
</li>
<li> how to reason about data constructors -- in particular, how to
use the fact that they are injective and disjoint;
</li>
<li> how to strengthen an induction hypothesis, and when such
strengthening is required; and
</li>
<li> more details on how to reason by case analysis.
</li>
</ul>
</div>
<div class="code">
<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="Poly.html#"><span class="id" title="library">Poly</span></a>.<br/>
</div>
<div class="doc">
<a id="lab157"></a><h1 class="section">The <span class="inlinecode"><span class="id" title="tactic">apply</span></span> Tactic</h1>
<div class="paragraph"> </div>
We often encounter situations where the goal to be proved is
<i>exactly</i> the same as some hypothesis in the context or some
previously proved lemma.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly1" class="idref" href="#silly1"><span class="id" title="lemma">silly1</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:1" class="idref" href="#n:1"><span class="id" title="binder">n</span></a> <a id="m:2" class="idref" href="#m:2"><span class="id" title="binder">m</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/>
<a class="idref" href="Tactics.html#n:1"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:2"><span class="id" title="variable">m</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="Tactics.html#n:1"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:2"><span class="id" title="variable">m</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">m</span> <span class="id" title="var">eq</span>.<br/>
</div>
<div class="doc">
Here, we could finish with "<span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">eq</span>.</span> <span class="inlinecode"><span class="id" title="tactic">reflexivity</span>.</span>" as we
have done several times before. Or we can finish in a single step
by using <span class="inlinecode"><span class="id" title="tactic">apply</span></span>:
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The <span class="inlinecode"><span class="id" title="tactic">apply</span></span> tactic also works with <i>conditional</i> hypotheses
and lemmas: if the statement being applied is an implication, then
the premises of this implication will be added to the list of
subgoals needing to be proved. <span class="inlinecode"><span class="id" title="tactic">apply</span></span> also works with <i>conditional</i> hypotheses:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly2" class="idref" href="#silly2"><span class="id" title="lemma">silly2</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:3" class="idref" href="#n:3"><span class="id" title="binder">n</span></a> <a id="m:4" class="idref" href="#m:4"><span class="id" title="binder">m</span></a> <a id="o:5" class="idref" href="#o:5"><span class="id" title="binder">o</span></a> <a id="p:6" class="idref" href="#p:6"><span class="id" title="binder">p</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/>
<a class="idref" href="Tactics.html#n:3"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:4"><span class="id" title="variable">m</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="Tactics.html#n:3"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:4"><span class="id" title="variable">m</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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#n:3"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#o:5"><span class="id" title="variable">o</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:4"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#p:6"><span class="id" title="variable">p</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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><br/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#n:3"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#o:5"><span class="id" title="variable">o</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:4"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#p:6"><span class="id" title="variable">p</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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</span> <span class="id" title="var">m</span> <span class="id" title="var">o</span> <span class="id" title="var">p</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Typically, when we use <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span>, the statement <span class="inlinecode"><span class="id" title="var">H</span></span> will
begin with a <span class="inlinecode"><span class="id" title="keyword">∀</span></span> that introduces some <i>universally quantified
variables</i>.
<div class="paragraph"> </div>
When Coq matches the current goal against the conclusion of <span class="inlinecode"><span class="id" title="var">H</span></span>,
it will try to find appropriate values for these variables. For
example, when we do <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">eq<sub>2</sub></span></span> in the following proof, the
universal variable <span class="inlinecode"><span class="id" title="var">q</span></span> in <span class="inlinecode"><span class="id" title="var">eq<sub>2</sub></span></span> gets instantiated with <span class="inlinecode"><span class="id" title="var">n</span></span>, and
<span class="inlinecode"><span class="id" title="var">r</span></span> gets instantiated with <span class="inlinecode"><span class="id" title="var">m</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly2a" class="idref" href="#silly2a"><span class="id" title="lemma">silly2a</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 id="m:8" class="idref" href="#m:8"><span class="id" title="binder">m</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/>
<a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#n:7"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">,</span></a><a class="idref" href="Tactics.html#n:7"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#m:8"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">,</span></a><a class="idref" href="Tactics.html#m:8"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><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><span class="id" title="keyword">∀</span> (<a id="q:9" class="idref" href="#q:9"><span class="id" title="binder">q</span></a> <a id="r:10" class="idref" href="#r:10"><span class="id" title="binder">r</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="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#q:9"><span class="id" title="variable">q</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">,</span></a><a class="idref" href="Tactics.html#q:9"><span class="id" title="variable">q</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#r:10"><span class="id" title="variable">r</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><span class="id" title="notation">,</span></a><a class="idref" href="Tactics.html#r:10"><span class="id" title="variable">r</span></a><a class="idref" href="Poly.html#62264328926d76449e4f268ee9289ca<sub>9</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#q:9"><span class="id" title="variable">q</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#r:10"><span class="id" title="variable">r</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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><br/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#n:7"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:8"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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</span> <span class="id" title="var">m</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab158"></a><h4 class="section">Exercise: 2 stars, standard, optional (silly_ex)</h4>
Complete the following proof using only <span class="inlinecode"><span class="id" title="tactic">intros</span></span> and <span class="inlinecode"><span class="id" title="tactic">apply</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly_ex" class="idref" href="#silly_ex"><span class="id" title="lemma">silly_ex</span></a> : <span class="id" title="keyword">∀</span> <a id="p:11" class="idref" href="#p:11"><span class="id" title="binder">p</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="n:12" class="idref" href="#n:12"><span class="id" title="binder">n</span></a>, <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> <a class="idref" href="Tactics.html#n:12"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Basics.html#even"><span class="id" title="definition">even</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="Tactics.html#n:12"><span class="id" title="variable">n</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">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="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><span class="id" title="keyword">∀</span> <a id="n:13" class="idref" href="#n:13"><span class="id" title="binder">n</span></a>, <a class="idref" href="Basics.html#even"><span class="id" title="definition">even</span></a> <a class="idref" href="Tactics.html#n:13"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#false"><span class="id" title="constructor">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="Basics.html#odd"><span class="id" title="definition">odd</span></a> <a class="idref" href="Tactics.html#n:13"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Basics.html#even"><span class="id" title="definition">even</span></a> <a class="idref" href="Tactics.html#p:11"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Basics.html#odd"><span class="id" title="definition">odd</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="Tactics.html#p:11"><span class="id" title="variable">p</span></a>) <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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>
To use the <span class="inlinecode"><span class="id" title="tactic">apply</span></span> tactic, the (conclusion of the) fact
being applied must match the goal exactly (perhaps after
simplification) -- for example, <span class="inlinecode"><span class="id" title="tactic">apply</span></span> will not work if the left
and right sides of the equality are swapped.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly3" class="idref" href="#silly3"><span class="id" title="lemma">silly3</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:14" class="idref" href="#n:14"><span class="id" title="binder">n</span></a> <a id="m:15" class="idref" href="#m:15"><span class="id" title="binder">m</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/>
<a class="idref" href="Tactics.html#n:14"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:15"><span class="id" title="variable">m</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="Tactics.html#m:15"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#n:14"><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">m</span> <span class="id" title="var">H</span>.<br/>
</div>
<div class="doc">
Here we cannot use <span class="inlinecode"><span class="id" title="tactic">apply</span></span> directly...
</div>
<div class="code">
<span class="id" title="var">Fail</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
</div>
<div class="doc">
but we can use the <span class="inlinecode"><span class="id" title="tactic">symmetry</span></span> tactic, which switches the left
and right sides of an equality in the goal.
</div>
<div class="code">
<span class="id" title="tactic">symmetry</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab159"></a><h4 class="section">Exercise: 2 stars, standard (apply_exercise1)</h4>
You can use <span class="inlinecode"><span class="id" title="tactic">apply</span></span> with previously defined theorems, not
just hypotheses in the context. Use <span class="inlinecode"><span class="id" title="keyword">Search</span></span> to find a
previously-defined theorem about <span class="inlinecode"><span class="id" title="var">rev</span></span> from <a href="Lists.html"><span class="inlineref">Lists</span></a>. Use
that theorem as part of your (relatively short) solution to this
exercise. You do not need <span class="inlinecode"><span class="id" title="tactic">induction</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="rev_exercise1" class="idref" href="#rev_exercise1"><span class="id" title="lemma">rev_exercise1</span></a> : <span class="id" title="keyword">∀</span> (<a id="l:16" class="idref" href="#l:16"><span class="id" title="binder">l</span></a> <a id="l':17" class="idref" href="#l':17"><span class="id" title="binder">l'</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</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/>
<a class="idref" href="Tactics.html#l:16"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Poly.html#rev"><span class="id" title="definition">rev</span></a> <a class="idref" href="Tactics.html#l':17"><span class="id" title="variable">l'</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="Tactics.html#l':17"><span class="id" title="variable">l'</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Poly.html#rev"><span class="id" title="definition">rev</span></a> <a class="idref" href="Tactics.html#l:16"><span class="id" title="variable">l</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="lab160"></a><h4 class="section">Exercise: 1 star, standard, optional (apply_rewrite)</h4>
Briefly explain the difference between the tactics <span class="inlinecode"><span class="id" title="tactic">apply</span></span> and
<span class="inlinecode"><span class="id" title="tactic">rewrite</span></span>. What are the situations where both can usefully be
applied?
</div>
<div class="code">
<span class="comment">(* FILL IN HERE *)</span><br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<a id="lab161"></a><h1 class="section">The <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="keyword">with</span></span> Tactic</h1>
<div class="paragraph"> </div>
The following silly example uses two rewrites in a row to
get from <span class="inlinecode">[<span class="id" title="var">a</span>;<span class="id" title="var">b</span>]</span> to <span class="inlinecode">[<span class="id" title="var">e</span>;<span class="id" title="var">f</span>]</span>.
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="trans_eq_example" class="idref" href="#trans_eq_example"><span class="id" title="definition">trans_eq_example</span></a> : <span class="id" title="keyword">∀</span> (<a id="a:18" class="idref" href="#a:18"><span class="id" title="binder">a</span></a> <a id="b:19" class="idref" href="#b:19"><span class="id" title="binder">b</span></a> <a id="c:20" class="idref" href="#c:20"><span class="id" title="binder">c</span></a> <a id="d:21" class="idref" href="#d:21"><span class="id" title="binder">d</span></a> <a id="e:22" class="idref" href="#e:22"><span class="id" title="binder">e</span></a> <a id="f:23" class="idref" href="#f:23"><span class="id" title="binder">f</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/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:18"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:19"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#c:20"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:21"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#c:20"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:21"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:22"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:23"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:18"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:19"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:22"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:23"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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">a</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> <span class="id" title="var">d</span> <span class="id" title="var">e</span> <span class="id" title="var">f</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">rewrite</span> → <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="tactic">rewrite</span> → <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Since this is a common pattern, we might like to pull it out as a
lemma that records, once and for all, the fact that equality is
transitive.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="trans_eq" class="idref" href="#trans_eq"><span class="id" title="lemma">trans_eq</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:24" class="idref" href="#X:24"><span class="id" title="binder">X</span></a>:<span class="id" title="keyword">Type</span>) (<a id="n:25" class="idref" href="#n:25"><span class="id" title="binder">n</span></a> <a id="m:26" class="idref" href="#m:26"><span class="id" title="binder">m</span></a> <a id="o:27" class="idref" href="#o:27"><span class="id" title="binder">o</span></a> : <a class="idref" href="Tactics.html#X:24"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="Tactics.html#n:25"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:26"><span class="id" title="variable">m</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="Tactics.html#m:26"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#o:27"><span class="id" title="variable">o</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="Tactics.html#n:25"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#o:27"><span class="id" title="variable">o</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">X</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">o</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> → <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="tactic">rewrite</span> → <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Now, we should be able to use <span class="inlinecode"><span class="id" title="var">trans_eq</span></span> to prove the above
example. However, to do this we need a slight refinement of the
<span class="inlinecode"><span class="id" title="tactic">apply</span></span> tactic.
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="trans_eq_example'" class="idref" href="#trans_eq_example'"><span class="id" title="definition">trans_eq_example'</span></a> : <span class="id" title="keyword">∀</span> (<a id="a:28" class="idref" href="#a:28"><span class="id" title="binder">a</span></a> <a id="b:29" class="idref" href="#b:29"><span class="id" title="binder">b</span></a> <a id="c:30" class="idref" href="#c:30"><span class="id" title="binder">c</span></a> <a id="d:31" class="idref" href="#d:31"><span class="id" title="binder">d</span></a> <a id="e:32" class="idref" href="#e:32"><span class="id" title="binder">e</span></a> <a id="f:33" class="idref" href="#f:33"><span class="id" title="binder">f</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/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:28"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:29"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#c:30"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:31"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#c:30"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:31"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:32"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:33"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:28"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:29"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:32"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:33"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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">a</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> <span class="id" title="var">d</span> <span class="id" title="var">e</span> <span class="id" title="var">f</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
</div>
<div class="doc">
If we simply tell Coq <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">trans_eq</span></span> at this point, it can
tell (by matching the goal against the conclusion of the lemma)
that it should instantiate <span class="inlinecode"><span class="id" title="var">X</span></span> with <span class="inlinecode">[<span class="id" title="var">nat</span>]</span>, <span class="inlinecode"><span class="id" title="var">n</span></span> with <span class="inlinecode">[<span class="id" title="var">a</span>,<span class="id" title="var">b</span>]</span>, and
<span class="inlinecode"><span class="id" title="var">o</span></span> with <span class="inlinecode">[<span class="id" title="var">e</span>,<span class="id" title="var">f</span>]</span>. However, the matching process doesn't determine
an instantiation for <span class="inlinecode"><span class="id" title="var">m</span></span>: we have to supply one explicitly by
adding "<span class="inlinecode"><span class="id" title="keyword">with</span></span> <span class="inlinecode">(<span class="id" title="var">m</span>:=[<span class="id" title="var">c</span>,<span class="id" title="var">d</span>])</span>" to the invocation of <span class="inlinecode"><span class="id" title="tactic">apply</span></span>.
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <a class="idref" href="Tactics.html#trans_eq"><span class="id" title="lemma">trans_eq</span></a> <span class="id" title="keyword">with</span> (<span class="id" title="var">m</span>:=<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><span class="id" title="var">c</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><span class="id" title="var">d</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a>).<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Actually, the name <span class="inlinecode"><span class="id" title="var">m</span></span> in the <span class="inlinecode"><span class="id" title="keyword">with</span></span> clause is not required,
since Coq is often smart enough to figure out which variable we
are instantiating. We could instead simply write <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">trans_eq</span></span>
<span class="inlinecode"><span class="id" title="keyword">with</span></span> <span class="inlinecode">[<span class="id" title="var">c</span>;<span class="id" title="var">d</span>]</span>.
<div class="paragraph"> </div>
Coq also has a built-in tactic <span class="inlinecode"><span class="id" title="tactic">transitivity</span></span> that
accomplishes the same purpose as applying <span class="inlinecode"><span class="id" title="var">trans_eq</span></span>. The tactic
requires us to state the instantiation we want, just like <span class="inlinecode"><span class="id" title="tactic">apply</span></span>
<span class="inlinecode"><span class="id" title="keyword">with</span></span> does.
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="trans_eq_example''" class="idref" href="#trans_eq_example''"><span class="id" title="definition">trans_eq_example''</span></a> : <span class="id" title="keyword">∀</span> (<a id="a:34" class="idref" href="#a:34"><span class="id" title="binder">a</span></a> <a id="b:35" class="idref" href="#b:35"><span class="id" title="binder">b</span></a> <a id="c:36" class="idref" href="#c:36"><span class="id" title="binder">c</span></a> <a id="d:37" class="idref" href="#d:37"><span class="id" title="binder">d</span></a> <a id="e:38" class="idref" href="#e:38"><span class="id" title="binder">e</span></a> <a id="f:39" class="idref" href="#f:39"><span class="id" title="binder">f</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/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:34"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:35"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#c:36"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:37"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#c:36"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:37"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:38"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:39"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:34"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:35"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:38"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:39"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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">a</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> <span class="id" title="var">d</span> <span class="id" title="var">e</span> <span class="id" title="var">f</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">transitivity</span> <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><span class="id" title="var">c</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><span class="id" title="var">d</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>1</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab162"></a><h4 class="section">Exercise: 3 stars, standard, optional (trans_eq_exercise)</h4>
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="trans_eq_exercise" class="idref" href="#trans_eq_exercise"><span class="id" title="definition">trans_eq_exercise</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:40" class="idref" href="#n:40"><span class="id" title="binder">n</span></a> <a id="m:41" class="idref" href="#m:41"><span class="id" title="binder">m</span></a> <a id="o:42" class="idref" href="#o:42"><span class="id" title="binder">o</span></a> <a id="p:43" class="idref" href="#p:43"><span class="id" title="binder">p</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/>
<a class="idref" href="Tactics.html#m:41"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#minustwo"><span class="id" title="definition">minustwo</span></a> <a class="idref" href="Tactics.html#o:42"><span class="id" title="variable">o</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#n:40"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Tactics.html#p:43"><span class="id" title="variable">p</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:41"><span class="id" title="variable">m</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#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#n:40"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Tactics.html#p:43"><span class="id" title="variable">p</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#minustwo"><span class="id" title="definition">minustwo</span></a> <a class="idref" href="Tactics.html#o:42"><span class="id" title="variable">o</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</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">
<a id="lab163"></a><h1 class="section">The <span class="inlinecode"><span class="id" title="tactic">injection</span></span> and <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> Tactics</h1>
<div class="paragraph"> </div>
Recall the definition of natural numbers:
<br/>
<span class="inlinecode"> <span class="id" title="keyword">Inductive</span> <span class="id" title="var">nat</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> (<span class="id" title="var">n</span> : <span class="id" title="var">nat</span>).
</span> It is obvious from this definition that every number has one of
two forms: either it is the constructor <span class="inlinecode"><span class="id" title="var">O</span></span> or it is built by
applying the constructor <span class="inlinecode"><span class="id" title="var">S</span></span> to another number. But there is more
here than meets the eye: implicit in the definition are two
additional facts:
<div class="paragraph"> </div>
<ul class="doclist">
<li> The constructor <span class="inlinecode"><span class="id" title="var">S</span></span> is <i>injective</i> (or <i>one-to-one</i>). That is,
if <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">m</span></span>, it must also be that <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>.
<div class="paragraph"> </div>
</li>
<li> The constructors <span class="inlinecode"><span class="id" title="var">O</span></span> and <span class="inlinecode"><span class="id" title="var">S</span></span> are <i>disjoint</i>. That is, <span class="inlinecode"><span class="id" title="var">O</span></span> is not
equal to <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> for any <span class="inlinecode"><span class="id" title="var">n</span></span>.
</li>
</ul>
<div class="paragraph"> </div>
Similar principles apply to every inductively defined type:
all constructors are injective, and the values built from distinct
constructors are never equal. For lists, the <span class="inlinecode"><span class="id" title="var">cons</span></span> constructor
is injective and the empty list <span class="inlinecode"><span class="id" title="var">nil</span></span> is different from every
non-empty list. For booleans, <span class="inlinecode"><span class="id" title="var">true</span></span> and <span class="inlinecode"><span class="id" title="var">false</span></span> are different.
(Since <span class="inlinecode"><span class="id" title="var">true</span></span> and <span class="inlinecode"><span class="id" title="var">false</span></span> take no arguments, their injectivity is
neither here nor there.) And so on.
<div class="paragraph"> </div>
We can <i>prove</i> the injectivity of <span class="inlinecode"><span class="id" title="var">S</span></span> by using the <span class="inlinecode"><span class="id" title="var">pred</span></span> function
defined in <span class="inlinecode"><span class="id" title="var">Basics.v</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="S_injective" class="idref" href="#S_injective"><span class="id" title="lemma">S_injective</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:44" class="idref" href="#n:44"><span class="id" title="binder">n</span></a> <a id="m:45" class="idref" href="#m:45"><span class="id" title="binder">m</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/>
<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="Tactics.html#n:44"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:45"><span class="id" title="variable">m</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="Tactics.html#n:44"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:45"><span class="id" title="variable">m</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">m</span> <span class="id" title="var">H<sub>1</sub></span>.<br/>
<span class="id" title="tactic">assert</span> (<span class="id" title="var">H<sub>2</sub></span>: <span class="id" title="var">n</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Peano.html#pred"><span class="id" title="abbreviation">pred</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>)). { <span class="id" title="tactic">reflexivity</span>. }<br/>
<span class="id" title="tactic">rewrite</span> <span class="id" title="var">H<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H<sub>1</sub></span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
This technique can be generalized to any constructor by
writing the equivalent of <span class="inlinecode"><span class="id" title="var">pred</span></span> -- i.e., writing a function that
"undoes" one application of the constructor.
<div class="paragraph"> </div>
As a more convenient alternative, Coq provides a tactic called
<span class="inlinecode"><span class="id" title="tactic">injection</span></span> that allows us to exploit the injectivity of any
constructor. Here is an alternate proof of the above theorem
using <span class="inlinecode"><span class="id" title="tactic">injection</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="S_injective'" class="idref" href="#S_injective'"><span class="id" title="lemma">S_injective'</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:46" class="idref" href="#n:46"><span class="id" title="binder">n</span></a> <a id="m:47" class="idref" href="#m:47"><span class="id" title="binder">m</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/>
<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="Tactics.html#n:46"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:47"><span class="id" title="variable">m</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="Tactics.html#n:46"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:47"><span class="id" title="variable">m</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">m</span> <span class="id" title="var">H</span>.<br/>
</div>
<div class="doc">
By writing <span class="inlinecode"><span class="id" title="tactic">injection</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode"><span class="id" title="var">Hmn</span></span> at this point, we are asking Coq
to generate all equations that it can infer from <span class="inlinecode"><span class="id" title="var">H</span></span> using the
injectivity of constructors (in the present example, the equation
<span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>). Each such equation is added as a hypothesis (called
<span class="inlinecode"><span class="id" title="var">Hmn</span></span> in this case) into the context.
</div>
<div class="code">
<span class="id" title="tactic">injection</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> <span class="id" title="var">Hnm</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">Hnm</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Here's a more interesting example that shows how <span class="inlinecode"><span class="id" title="tactic">injection</span></span> can
derive multiple equations at once.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="injection_ex<sub>1</sub>" class="idref" href="#injection_ex<sub>1</sub>"><span class="id" title="lemma">injection_ex<sub>1</sub></span></a> : <span class="id" title="keyword">∀</span> (<a id="n:48" class="idref" href="#n:48"><span class="id" title="binder">n</span></a> <a id="m:49" class="idref" href="#m:49"><span class="id" title="binder">m</span></a> <a id="o:50" class="idref" href="#o:50"><span class="id" title="binder">o</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/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#n:48"><span class="id" title="variable">n</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#m:49"><span class="id" title="variable">m</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#o:50"><span class="id" title="variable">o</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#o:50"><span class="id" title="variable">o</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Tactics.html#n:48"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:49"><span class="id" title="variable">m</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">m</span> <span class="id" title="var">o</span> <span class="id" title="var">H</span>.<br/>
<span class="comment">(* WORKED IN CLASS *)</span><br/>
<span class="id" title="tactic">injection</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> <span class="id" title="var">H<sub>1</sub></span> <span class="id" title="var">H<sub>2</sub></span>.<br/>
<span class="id" title="tactic">rewrite</span> <span class="id" title="var">H<sub>1</sub></span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">H<sub>2</sub></span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab164"></a><h4 class="section">Exercise: 3 stars, standard (injection_ex<sub>3</sub>)</h4>
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="injection_ex<sub>3</sub>" class="idref" href="#injection_ex<sub>3</sub>"><span class="id" title="definition">injection_ex<sub>3</sub></span></a> : <span class="id" title="keyword">∀</span> (<a id="X:51" class="idref" href="#X:51"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="x:52" class="idref" href="#x:52"><span class="id" title="binder">x</span></a> <a id="y:53" class="idref" href="#y:53"><span class="id" title="binder">y</span></a> <a id="z:54" class="idref" href="#z:54"><span class="id" title="binder">z</span></a> : <a class="idref" href="Tactics.html#X:51"><span class="id" title="variable">X</span></a>) (<a id="l:55" class="idref" href="#l:55"><span class="id" title="binder">l</span></a> <a id="j:56" class="idref" href="#j:56"><span class="id" title="binder">j</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Tactics.html#X:51"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="Tactics.html#x:52"><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="Tactics.html#y:53"><span class="id" title="variable">y</span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="Tactics.html#l:55"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#z:54"><span class="id" title="variable">z</span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="Tactics.html#j:56"><span class="id" title="variable">j</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="Tactics.html#j:56"><span class="id" title="variable">j</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#z:54"><span class="id" title="variable">z</span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="Tactics.html#l:55"><span class="id" title="variable">l</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="Tactics.html#x:52"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#y:53"><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>
So much for injectivity of constructors. What about disjointness?
<div class="paragraph"> </div>
The principle of disjointness says that two terms beginning
with different constructors (like <span class="inlinecode"><span class="id" title="var">O</span></span> and <span class="inlinecode"><span class="id" title="var">S</span></span>, or <span class="inlinecode"><span class="id" title="var">true</span></span> and <span class="inlinecode"><span class="id" title="var">false</span></span>)
can never be equal. This means that, any time we find ourselves
in a context where we've <i>assumed</i> that two such terms are equal,
we are justified in concluding anything we want, since the
assumption is nonsensical.
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> tactic embodies this principle: It is used
on a hypothesis involving an equality between different
constructors (e.g., <span class="inlinecode"><span class="id" title="var">false</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">true</span></span>), and it solves the current
goal immediately. Some examples:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="discriminate_ex<sub>1</sub>" class="idref" href="#discriminate_ex<sub>1</sub>"><span class="id" title="lemma">discriminate_ex<sub>1</sub></span></a> : <span class="id" title="keyword">∀</span> (<a id="n:57" class="idref" href="#n:57"><span class="id" title="binder">n</span></a> <a id="m:58" class="idref" href="#m:58"><span class="id" title="binder">m</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/>
<a class="idref" href="Basics.html#false"><span class="id" title="constructor">false</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Tactics.html#n:57"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:58"><span class="id" title="variable">m</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">m</span> <span class="id" title="var">contra</span>. <span class="id" title="tactic">discriminate</span> <span class="id" title="var">contra</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="discriminate_ex<sub>2</sub>" class="idref" href="#discriminate_ex<sub>2</sub>"><span class="id" title="lemma">discriminate_ex<sub>2</sub></span></a> : <span class="id" title="keyword">∀</span> (<a id="n:59" class="idref" href="#n:59"><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>),<br/>
<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="Tactics.html#n:59"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#O"><span class="id" title="constructor">O</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/>
2 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 2 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 5.<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">contra</span>. <span class="id" title="tactic">discriminate</span> <span class="id" title="var">contra</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
These examples are instances of a logical principle known as the
<i>principle of explosion</i>, which asserts that a contradictory
hypothesis entails anything (even manifestly false things!).
<div class="paragraph"> </div>
If you find the principle of explosion confusing, remember
that these proofs are <i>not</i> showing that the conclusion of the
statement holds. Rather, they are showing that, <i>if</i> the
nonsensical situation described by the premise did somehow hold,
<i>then</i> the nonsensical conclusion would also follow, because we'd
be living in an inconsistent universe where every statement is
true.
<div class="paragraph"> </div>
We'll explore the principle of explosion in more detail in the
next chapter.
<div class="paragraph"> </div>
<a id="lab165"></a><h4 class="section">Exercise: 1 star, standard (discriminate_ex<sub>3</sub>)</h4>
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="discriminate_ex<sub>3</sub>" class="idref" href="#discriminate_ex<sub>3</sub>"><span class="id" title="definition">discriminate_ex<sub>3</sub></span></a> :<br/>
<span class="id" title="keyword">∀</span> (<a id="X:60" class="idref" href="#X:60"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="x:61" class="idref" href="#x:61"><span class="id" title="binder">x</span></a> <a id="y:62" class="idref" href="#y:62"><span class="id" title="binder">y</span></a> <a id="z:63" class="idref" href="#z:63"><span class="id" title="binder">z</span></a> : <a class="idref" href="Tactics.html#X:60"><span class="id" title="variable">X</span></a>) (<a id="l:64" class="idref" href="#l:64"><span class="id" title="binder">l</span></a> <a id="j:65" class="idref" href="#j:65"><span class="id" title="binder">j</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="Tactics.html#X:60"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="Tactics.html#x:61"><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="Tactics.html#y:62"><span class="id" title="variable">y</span></a> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="Tactics.html#l:64"><span class="id" title="variable">l</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><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="Tactics.html#x:61"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#z:63"><span class="id" title="variable">z</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>
For a more useful example, we can use <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> to make a
connection between the two different notions of equality (<span class="inlinecode">=</span> and
<span class="inlinecode">=?</span>) that we have seen for natural numbers.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="eqb_0_l" class="idref" href="#eqb_0_l"><span class="id" title="lemma">eqb_0_l</span></a> : <span class="id" title="keyword">∀</span> <a id="n:66" class="idref" href="#n:66"><span class="id" title="binder">n</span></a>,<br/>
0 <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Tactics.html#n:66"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Tactics.html#n:66"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>.<br/>
</div>
<div class="doc">
We can proceed by case analysis on <span class="inlinecode"><span class="id" title="var">n</span></span>. The first case is
trivial.
</div>
<div class="code">
<span class="id" title="tactic">destruct</span> <span class="id" title="var">n</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">n'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
- <span class="comment">(* n = 0 *)</span><br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
</div>
<div class="doc">
However, the second one doesn't look so simple: assuming <span class="inlinecode">0</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> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">true</span></span>, we must show <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">0</span>! The way forward is to
observe that the assumption itself is nonsensical:
</div>
<div class="code">
- <span class="comment">(* n = S n' *)</span><br/>
<span class="id" title="tactic">simpl</span>.<br/>
</div>
<div class="doc">
If we use <span class="inlinecode"><span class="id" title="tactic">discriminate</span></span> on this hypothesis, Coq confirms
that the subgoal we are working on is impossible and removes it
from further consideration.
</div>
<div class="code">
<span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">discriminate</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The injectivity of constructors allows us to reason that
<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">m</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="var">nat</span>),</span> <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">m</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>. The converse of this
implication is an instance of a more general fact about both
constructors and functions, which we will find convenient
below:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="f_equal" class="idref" href="#f_equal"><span class="id" title="lemma">f_equal</span></a> : <span class="id" title="keyword">∀</span> (<a id="A:67" class="idref" href="#A:67"><span class="id" title="binder">A</span></a> <a id="B:68" class="idref" href="#B:68"><span class="id" title="binder">B</span></a> : <span class="id" title="keyword">Type</span>) (<a id="f:69" class="idref" href="#f:69"><span class="id" title="binder">f</span></a>: <a class="idref" href="Tactics.html#A:67"><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> <a class="idref" href="Tactics.html#B:68"><span class="id" title="variable">B</span></a>) (<a id="x:70" class="idref" href="#x:70"><span class="id" title="binder">x</span></a> <a id="y:71" class="idref" href="#y:71"><span class="id" title="binder">y</span></a>: <a class="idref" href="Tactics.html#A:67"><span class="id" title="variable">A</span></a>),<br/>
<a class="idref" href="Tactics.html#x:70"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#y:71"><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="Tactics.html#f:69"><span class="id" title="variable">f</span></a> <a class="idref" href="Tactics.html#x:70"><span class="id" title="variable">x</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#f:69"><span class="id" title="variable">f</span></a> <a class="idref" href="Tactics.html#y:71"><span class="id" title="variable">y</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">A</span> <span class="id" title="var">B</span> <span class="id" title="var">f</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="eq_implies_succ_equal" class="idref" href="#eq_implies_succ_equal"><span class="id" title="lemma">eq_implies_succ_equal</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:72" class="idref" href="#n:72"><span class="id" title="binder">n</span></a> <a id="m:73" class="idref" href="#m:73"><span class="id" title="binder">m</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/>
<a class="idref" href="Tactics.html#n:72"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:73"><span class="id" title="variable">m</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#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="Tactics.html#n:72"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:73"><span class="id" title="variable">m</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="Tactics.html#f_equal"><span class="id" title="lemma">f_equal</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Indeed, there is also a tactic named `f_equal` that can
prove such theorems directly. Given a goal of the form <span class="inlinecode"><span class="id" title="var">f</span></span> <span class="inlinecode"><span class="id" title="var">a<sub>1</sub></span></span>
<span class="inlinecode">...</span> <span class="inlinecode"><span class="id" title="var">an</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">g</span></span> <span class="inlinecode"><span class="id" title="var">b<sub>1</sub></span></span> <span class="inlinecode">...</span> <span class="inlinecode"><span class="id" title="var">bn</span></span>, the tactic <span class="inlinecode"><span class="id" title="tactic">f_equal</span></span> will produce subgoals
of the form <span class="inlinecode"><span class="id" title="var">f</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">g</span></span>, <span class="inlinecode"><span class="id" title="var">a<sub>1</sub></span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">b<sub>1</sub></span></span>, ..., <span class="inlinecode"><span class="id" title="var">an</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">bn</span></span>. At the same time,
any of these subgoals that are simple enough (e.g., immediately
provable by <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span>) will be automatically discharged by
<span class="inlinecode"><span class="id" title="tactic">f_equal</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="eq_implies_succ_equal'" class="idref" href="#eq_implies_succ_equal'"><span class="id" title="lemma">eq_implies_succ_equal'</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:74" class="idref" href="#n:74"><span class="id" title="binder">n</span></a> <a id="m:75" class="idref" href="#m:75"><span class="id" title="binder">m</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/>
<a class="idref" href="Tactics.html#n:74"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:75"><span class="id" title="variable">m</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#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="Tactics.html#n:74"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#m:75"><span class="id" title="variable">m</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">f_equal</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab166"></a><h1 class="section">Using Tactics on Hypotheses</h1>
<div class="paragraph"> </div>
By default, most tactics work on the goal formula and leave
the context unchanged. However, most tactics also have a variant
that performs a similar operation on a statement in the context.
<div class="paragraph"> </div>
For example, the tactic "<span class="inlinecode"><span class="id" title="tactic">simpl</span></span> <span class="inlinecode"><span class="id" title="keyword">in</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span>" performs simplification on
the hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span> in the context.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="S_inj" class="idref" href="#S_inj"><span class="id" title="lemma">S_inj</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:76" class="idref" href="#n:76"><span class="id" title="binder">n</span></a> <a id="m:77" class="idref" href="#m:77"><span class="id" title="binder">m</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="b:78" class="idref" href="#b:78"><span class="id" title="binder">b</span></a> : <a class="idref" href="Basics.html#bool"><span class="id" title="inductive">bool</span></a>),<br/>
<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><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="Tactics.html#n:76"><span class="id" title="variable">n</span></a><a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><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="Tactics.html#m:77"><span class="id" title="variable">m</span></a><a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">)</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#b:78"><span class="id" title="variable">b</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#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="Tactics.html#n:76"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Tactics.html#m:77"><span class="id" title="variable">m</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#b:78"><span class="id" title="variable">b</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">m</span> <span class="id" title="var">b</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Similarly, <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">L</span></span> <span class="inlinecode"><span class="id" title="keyword">in</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> matches some conditional statement
<span class="inlinecode"><span class="id" title="var">L</span></span> (of the form <span class="inlinecode"><span class="id" title="var">X</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Y</span></span>, say) against a hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span> in the
context. However, unlike ordinary <span class="inlinecode"><span class="id" title="tactic">apply</span></span> (which rewrites a goal
matching <span class="inlinecode"><span class="id" title="var">Y</span></span> into a subgoal <span class="inlinecode"><span class="id" title="var">X</span></span>), <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">L</span></span> <span class="inlinecode"><span class="id" title="keyword">in</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> matches <span class="inlinecode"><span class="id" title="var">H</span></span>
against <span class="inlinecode"><span class="id" title="var">X</span></span> and, if successful, replaces it with <span class="inlinecode"><span class="id" title="var">Y</span></span>.
<div class="paragraph"> </div>
In other words, <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">L</span></span> <span class="inlinecode"><span class="id" title="keyword">in</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> gives us a form of "forward
reasoning": given <span class="inlinecode"><span class="id" title="var">X</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Y</span></span> and a hypothesis matching <span class="inlinecode"><span class="id" title="var">X</span></span>, it
produces a hypothesis matching <span class="inlinecode"><span class="id" title="var">Y</span></span>.
<div class="paragraph"> </div>
By contrast, <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">L</span></span> is "backward reasoning": it says that if we
know <span class="inlinecode"><span class="id" title="var">X</span></span> <span class="inlinecode">→</span> <span class="inlinecode"><span class="id" title="var">Y</span></span> and we are trying to prove <span class="inlinecode"><span class="id" title="var">Y</span></span>, it suffices to prove
<span class="inlinecode"><span class="id" title="var">X</span></span>.
<div class="paragraph"> </div>
Here is a variant of a proof from above, using forward reasoning
throughout instead of backward reasoning.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="silly4" class="idref" href="#silly4"><span class="id" title="lemma">silly4</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:79" class="idref" href="#n:79"><span class="id" title="binder">n</span></a> <a id="m:80" class="idref" href="#m:80"><span class="id" title="binder">m</span></a> <a id="p:81" class="idref" href="#p:81"><span class="id" title="binder">p</span></a> <a id="q:82" class="idref" href="#q:82"><span class="id" title="binder">q</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/>
<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="Tactics.html#n:79"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:80"><span class="id" title="variable">m</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="Tactics.html#p:81"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#q:82"><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><br/>
<a class="idref" href="Tactics.html#m:80"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#n:79"><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="Tactics.html#q:82"><span class="id" title="variable">q</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#p:81"><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">n</span> <span class="id" title="var">m</span> <span class="id" title="var">p</span> <span class="id" title="var">q</span> <span class="id" title="var">EQ</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">symmetry</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">EQ</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">symmetry</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Forward reasoning starts from what is <i>given</i> (premises,
previously proven theorems) and iteratively draws conclusions from
them until the goal is reached. Backward reasoning starts from
the <i>goal</i> and iteratively reasons about what would imply the
goal, until premises or previously proven theorems are reached.
<div class="paragraph"> </div>
The informal proofs seen in math or computer science classes tend
to use forward reasoning. By contrast, idiomatic use of Coq
generally favors backward reasoning, though in some situations the
forward style can be easier to think about.
</div>
<div class="doc">
<a id="lab167"></a><h1 class="section">Specializing Hypotheses</h1>
<div class="paragraph"> </div>
Another handy tactic for fiddling with hypotheses is <span class="inlinecode"><span class="id" title="tactic">specialize</span></span>.
It is essentially just a combination of <span class="inlinecode"><span class="id" title="tactic">assert</span></span> and <span class="inlinecode"><span class="id" title="tactic">apply</span></span>, but
it often provides a pleasingly smooth way to nail down overly
general assumptions. It works like this:
<div class="paragraph"> </div>
If <span class="inlinecode"><span class="id" title="var">H</span></span> is a quantified hypothesis in the current context -- i.e.,
<span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" title="keyword">∀</span></span> <span class="inlinecode">(<span class="id" title="var">x</span>:<span class="id" title="var">T</span>),</span> <span class="inlinecode"><span class="id" title="var">P</span></span> -- then <span class="inlinecode"><span class="id" title="tactic">specialize</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">with</span></span> <span class="inlinecode">(<span class="id" title="var">x</span></span> <span class="inlinecode">:=</span> <span class="inlinecode"><span class="id" title="var">e</span>)</span> will
change <span class="inlinecode"><span class="id" title="var">H</span></span> so that it looks like <span class="inlinecode">[<span class="id" title="var">x</span>:=<span class="id" title="var">e</span>]<span class="id" title="var">P</span></span>, that is, <span class="inlinecode"><span class="id" title="var">P</span></span> with <span class="inlinecode"><span class="id" title="var">x</span></span>
replaced by <span class="inlinecode"><span class="id" title="var">e</span></span>.
<div class="paragraph"> </div>
For example:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="specialize_example" class="idref" href="#specialize_example"><span class="id" title="lemma">specialize_example</span></a>: <span class="id" title="keyword">∀</span> <a id="n:83" class="idref" href="#n:83"><span class="id" title="binder">n</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="m:84" class="idref" href="#m:84"><span class="id" title="binder">m</span></a>, <a class="idref" href="Tactics.html#m:84"><span class="id" title="variable">m</span></a><a class="idref" href="Basics.html#ea2ff3d561159081cea6fb2e8113cc<sub>54</sub>"><span class="id" title="notation">×</span></a><a class="idref" href="Tactics.html#n:83"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0<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="Tactics.html#n:83"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 0.<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>.<br/>
<span class="id" title="tactic">specialize</span> <span class="id" title="var">H</span> <span class="id" title="keyword">with</span> (<span class="id" title="var">m</span> := 1).<br/>
<span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">rewrite</span> <a class="idref" href="Induction.html#add_comm"><span class="id" title="axiom">add_comm</span></a> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Using <span class="inlinecode"><span class="id" title="tactic">specialize</span></span> before <span class="inlinecode"><span class="id" title="tactic">apply</span></span> gives us yet another way to
control where <span class="inlinecode"><span class="id" title="tactic">apply</span></span> does its work.
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <a id="trans_eq_example'''" class="idref" href="#trans_eq_example'''"><span class="id" title="definition">trans_eq_example'''</span></a> : <span class="id" title="keyword">∀</span> (<a id="a:85" class="idref" href="#a:85"><span class="id" title="binder">a</span></a> <a id="b:86" class="idref" href="#b:86"><span class="id" title="binder">b</span></a> <a id="c:87" class="idref" href="#c:87"><span class="id" title="binder">c</span></a> <a id="d:88" class="idref" href="#d:88"><span class="id" title="binder">d</span></a> <a id="e:89" class="idref" href="#e:89"><span class="id" title="binder">e</span></a> <a id="f:90" class="idref" href="#f:90"><span class="id" title="binder">f</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/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:85"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:86"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#c:87"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:88"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#c:87"><span class="id" title="variable">c</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#d:88"><span class="id" title="variable">d</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:89"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:90"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="Tactics.html#a:85"><span class="id" title="variable">a</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#b:86"><span class="id" title="variable">b</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><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="Tactics.html#e:89"><span class="id" title="variable">e</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><a class="idref" href="Tactics.html#f:90"><span class="id" title="variable">f</span></a><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><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">a</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> <span class="id" title="var">d</span> <span class="id" title="var">e</span> <span class="id" title="var">f</span> <span class="id" title="var">eq<sub>1</sub></span> <span class="id" title="var">eq<sub>2</sub></span>.<br/>
<span class="id" title="tactic">specialize</span> <a class="idref" href="Tactics.html#trans_eq"><span class="id" title="lemma">trans_eq</span></a> <span class="id" title="keyword">with</span> (<span class="id" title="var">m</span>:=<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><span class="id" title="var">c</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a><span class="id" title="var">d</span><a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">]</span></a>) <span class="id" title="keyword">as</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>1</sub></span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">eq<sub>2</sub></span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Note:
<ul class="doclist">
<li> We can <span class="inlinecode"><span class="id" title="tactic">specialize</span></span> facts in the global context, not just
local hypotheses.
</li>
<li> The <span class="inlinecode"><span class="id" title="keyword">as</span>...</span> clause at the end tells <span class="inlinecode"><span class="id" title="tactic">specialize</span></span> how to name
the new hypothesis in this case.
</li>
</ul>
</div>
<div class="doc">
<a id="lab168"></a><h1 class="section">Varying the Induction Hypothesis</h1>
<div class="paragraph"> </div>
Sometimes it is important to control the exact form of the
induction hypothesis when carrying out inductive proofs in Coq.
In particular, we may need to be careful about which of the
assumptions we move (using <span class="inlinecode"><span class="id" title="tactic">intros</span></span>) from the goal to the context
before invoking the <span class="inlinecode"><span class="id" title="tactic">induction</span></span> tactic.
<div class="paragraph"> </div>
For example, suppose we want to show that <span class="inlinecode"><span class="id" title="var">double</span></span> is injective --
i.e., that it maps different arguments to different results:
<br/>
<span class="inlinecode"> <span class="id" title="keyword">Theorem</span> <span class="id" title="var">double_injective</span>: <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span>,<br/>
<span class="id" title="var">double</span> <span class="id" title="var">n</span> = <span class="id" title="var">double</span> <span class="id" title="var">m</span> →<br/>
<span class="id" title="var">n</span> = <span class="id" title="var">m</span>.
</span> The way we start this proof is a bit delicate: if we begin it with
<br/>
<span class="inlinecode"> <span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">induction</span> <span class="id" title="var">n</span>.
</span> then all is well. But if we begin it with introducing both
variables
<br/>
<span class="inlinecode"> <span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span>. <span class="id" title="tactic">induction</span> <span class="id" title="var">n</span>.
</span> we get stuck in the middle of the inductive case...
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="double_injective_FAILED" class="idref" href="#double_injective_FAILED"><span class="id" title="lemma">double_injective_FAILED</span></a> : <span class="id" title="keyword">∀</span> <a id="n:91" class="idref" href="#n:91"><span class="id" title="binder">n</span></a> <a id="m:92" class="idref" href="#m:92"><span class="id" title="binder">m</span></a>,<br/>
<a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Tactics.html#n:91"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Tactics.html#m:92"><span class="id" title="variable">m</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="Tactics.html#n:91"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:92"><span class="id" title="variable">m</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">m</span>. <span class="id" title="tactic">induction</span> <span class="id" title="var">n</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">n'</span> <span class="id" title="var">IHn'</span>].<br/>
- <span class="comment">(* n = O *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">m</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">m'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
+ <span class="comment">(* m = O *)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
+ <span class="comment">(* m = S m' *)</span> <span class="id" title="tactic">discriminate</span> <span class="id" title="var">eq</span>.<br/>
- <span class="comment">(* n = S n' *)</span> <span class="id" title="tactic">intros</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">m</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">m'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
+ <span class="comment">(* m = O *)</span> <span class="id" title="tactic">discriminate</span> <span class="id" title="var">eq</span>.<br/>
+ <span class="comment">(* m = S m' *)</span> <span class="id" title="tactic">f_equal</span>.<br/>
</div>
<div class="doc">
At this point, the induction hypothesis (<span class="inlinecode"><span class="id" title="var">IHn'</span></span>) does <i>not</i> give us
<span class="inlinecode"><span class="id" title="var">n'</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m'</span></span> -- there is an extra <span class="inlinecode"><span class="id" title="var">S</span></span> in the way -- so the goal is
not provable.
</div>
<div class="code">
<span class="id" title="keyword">Abort</span>.<br/>
</div>
<div class="doc">
What went wrong?
<div class="paragraph"> </div>
The problem is that, at the point where we invoke the
induction hypothesis, we have already introduced <span class="inlinecode"><span class="id" title="var">m</span></span> into the
context -- intuitively, we have told Coq, "Let's consider some
particular <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span>..." and we now have to prove that, if
<span class="inlinecode"><span class="id" title="var">double</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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> for <i>these particular</i> <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span>, then
<span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>.
<div class="paragraph"> </div>
The next tactic, <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> says to Coq: We are going to show
the goal by induction on <span class="inlinecode"><span class="id" title="var">n</span></span>. That is, we are going to prove, for
<i>all</i> <span class="inlinecode"><span class="id" title="var">n</span></span>, that the proposition
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> = "if <span class="inlinecode"><span class="id" title="var">double</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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span>, then <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>"
</li>
</ul>
<div class="paragraph"> </div>
holds, by showing
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="var">P</span></span> <span class="inlinecode"><span class="id" title="var">O</span></span>
<div class="paragraph"> </div>
(i.e., "if <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">O</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> then <span class="inlinecode"><span class="id" title="var">O</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>") and
<div class="paragraph"> </div>
</li>
<li> <span class="inlinecode"><span class="id" title="var">P</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">P</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>
(i.e., "if <span class="inlinecode"><span class="id" title="var">double</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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> then <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>" implies "if
<span class="inlinecode"><span class="id" title="var">double</span></span> <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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> then <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">m</span></span>").
</li>
</ul>
<div class="paragraph"> </div>
If we look closely at the second statement, it is saying something
rather strange: that, for a <i>particular</i> <span class="inlinecode"><span class="id" title="var">m</span></span>, if we know
<div class="paragraph"> </div>
<ul class="doclist">
<li> "if <span class="inlinecode"><span class="id" title="var">double</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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> then <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">m</span></span>"
</li>
</ul>
<div class="paragraph"> </div>
then we can prove
<div class="paragraph"> </div>
<ul class="doclist">
<li> "if <span class="inlinecode"><span class="id" title="var">double</span></span> <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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span> then <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">m</span></span>".
</li>
</ul>
<div class="paragraph"> </div>
To see why this is strange, let's think of a particular <span class="inlinecode"><span class="id" title="var">m</span></span> --
say, <span class="inlinecode">5</span>. The statement is then saying that, if we know
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="var">Q</span></span> = "if <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">10</span> then <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode">=</span> <span class="inlinecode">5</span>"
</li>
</ul>
<div class="paragraph"> </div>
then we can prove
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="var">R</span></span> = "if <span class="inlinecode"><span class="id" title="var">double</span></span> <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">10</span> then <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">5</span>".
</li>
</ul>
<div class="paragraph"> </div>
But knowing <span class="inlinecode"><span class="id" title="var">Q</span></span> doesn't give us any help at all with proving <span class="inlinecode"><span class="id" title="var">R</span></span>!
If we tried to prove <span class="inlinecode"><span class="id" title="var">R</span></span> from <span class="inlinecode"><span class="id" title="var">Q</span></span>, we would start with something
like "Suppose <span class="inlinecode"><span class="id" title="var">double</span></span> <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">10</span>..." but then we'd be stuck:
knowing that <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span>)</span> is <span class="inlinecode">10</span> tells us nothing helpful about
whether <span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> is <span class="inlinecode">10</span> (indeed, it strongly suggests that
<span class="inlinecode"><span class="id" title="var">double</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> is <i>not</i> <span class="inlinecode">10</span>!!), so <span class="inlinecode"><span class="id" title="var">Q</span></span> is useless.
<div class="paragraph"> </div>
Trying to carry out this proof by induction on <span class="inlinecode"><span class="id" title="var">n</span></span> when <span class="inlinecode"><span class="id" title="var">m</span></span> is
already in the context doesn't work because we are then trying to
prove a statement involving <i>every</i> <span class="inlinecode"><span class="id" title="var">n</span></span> but just a <i>particular</i>
<span class="inlinecode"><span class="id" title="var">m</span></span>.
<div class="paragraph"> </div>
A successful proof of <span class="inlinecode"><span class="id" title="var">double_injective</span></span> leaves <span class="inlinecode"><span class="id" title="var">m</span></span> universally
quantified in the goal statement at the point where the
<span class="inlinecode"><span class="id" title="tactic">induction</span></span> tactic is invoked on <span class="inlinecode"><span class="id" title="var">n</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="double_injective" class="idref" href="#double_injective"><span class="id" title="lemma">double_injective</span></a> : <span class="id" title="keyword">∀</span> <a id="n:93" class="idref" href="#n:93"><span class="id" title="binder">n</span></a> <a id="m:94" class="idref" href="#m:94"><span class="id" title="binder">m</span></a>,<br/>
<a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Tactics.html#n:93"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Induction.html#double"><span class="id" title="definition">double</span></a> <a class="idref" href="Tactics.html#m:94"><span class="id" title="variable">m</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="Tactics.html#n:93"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:94"><span class="id" title="variable">m</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="tactic">induction</span> <span class="id" title="var">n</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">n'</span> <span class="id" title="var">IHn'</span>].<br/>
- <span class="comment">(* n = O *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">intros</span> <span class="id" title="var">m</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">m</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">m'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
+ <span class="comment">(* m = O *)</span> <span class="id" title="tactic">reflexivity</span>.<br/>
+ <span class="comment">(* m = S m' *)</span> <span class="id" title="tactic">discriminate</span> <span class="id" title="var">eq</span>.<br/><hr class='doublespaceincode'/>
- <span class="comment">(* n = S n' *)</span><br/>
<br/>
</div>
<div class="doc">
Notice that both the goal and the induction hypothesis are
different this time: the goal asks us to prove something more
general (i.e., we must prove the statement for <i>every</i> <span class="inlinecode"><span class="id" title="var">m</span></span>), but
the induction hypothesis <span class="inlinecode"><span class="id" title="var">IH'</span></span> is correspondingly more flexible,
allowing us to choose any <span class="inlinecode"><span class="id" title="var">m</span></span> we like when we apply it.
</div>
<div class="code">
<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">m</span> <span class="id" title="var">eq</span>.<br/>
</div>
<div class="doc">
Now we've chosen a particular <span class="inlinecode"><span class="id" title="var">m</span></span> and introduced the assumption
that <span class="inlinecode"><span class="id" title="var">double</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">double</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span>. Since we are doing a case analysis on
<span class="inlinecode"><span class="id" title="var">n</span></span>, we also need a case analysis on <span class="inlinecode"><span class="id" title="var">m</span></span> to keep the two "in sync."
</div>
<div class="code">
<span class="id" title="tactic">destruct</span> <span class="id" title="var">m</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">m'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
+ <span class="comment">(* m = O *)</span><br/>
<br/>
</div>
<div class="doc">
The 0 case is trivial:
</div>
<div class="code">
<br/>
<span class="id" title="tactic">discriminate</span> <span class="id" title="var">eq</span>.<br/>
+ <span class="comment">(* m = S m' *)</span><br/>
<span class="id" title="tactic">f_equal</span>.<br/>
</div>
<div class="doc">
Since we are now in the second branch of the <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> <span class="inlinecode"><span class="id" title="var">m</span></span>, the
<span class="inlinecode"><span class="id" title="var">m'</span></span> mentioned in the context is the predecessor of the <span class="inlinecode"><span class="id" title="var">m</span></span> we
started out talking about. Since we are also in the <span class="inlinecode"><span class="id" title="var">S</span></span> branch of
the induction, this is perfect: if we instantiate the generic <span class="inlinecode"><span class="id" title="var">m</span></span>
in the IH with the current <span class="inlinecode"><span class="id" title="var">m'</span></span> (this instantiation is performed
automatically by the <span class="inlinecode"><span class="id" title="tactic">apply</span></span> in the next step), then <span class="inlinecode"><span class="id" title="var">IHn'</span></span> gives
us exactly what we need to finish the proof.
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <span class="id" title="var">IHn'</span>. <span class="id" title="tactic">simpl</span> <span class="id" title="keyword">in</span> <span class="id" title="var">eq</span>. <span class="id" title="tactic">injection</span> <span class="id" title="var">eq</span> <span class="id" title="keyword">as</span> <span class="id" title="keyword">goal</span>. <span class="id" title="tactic">apply</span> <span class="id" title="keyword">goal</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The thing to take away from all this is that you need to be
careful, when using induction, that you are not trying to prove
something too specific: When proving a property quantified over
variables <span class="inlinecode"><span class="id" title="var">n</span></span> and <span class="inlinecode"><span class="id" title="var">m</span></span> by induction on <span class="inlinecode"><span class="id" title="var">n</span></span>, it is sometimes crucial
to leave <span class="inlinecode"><span class="id" title="var">m</span></span> generic.
<div class="paragraph"> </div>
The following exercise, which further strengthens the link between
<span class="inlinecode">=?</span> and <span class="inlinecode">=</span>, follows the same pattern. <a id="lab169"></a><h4 class="section">Exercise: 2 stars, standard (eqb_true)</h4>
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="eqb_true" class="idref" href="#eqb_true"><span class="id" title="lemma">eqb_true</span></a> : <span class="id" title="keyword">∀</span> <a id="n:95" class="idref" href="#n:95"><span class="id" title="binder">n</span></a> <a id="m:96" class="idref" href="#m:96"><span class="id" title="binder">m</span></a>,<br/>
<a class="idref" href="Tactics.html#n:95"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> <a class="idref" href="Tactics.html#m:96"><span class="id" title="variable">m</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Basics.html#true"><span class="id" title="constructor">true</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="Tactics.html#n:95"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> <a class="idref" href="Tactics.html#m:96"><span class="id" title="variable">m</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="lab170"></a><h4 class="section">Exercise: 2 stars, advanced (eqb_true_informal)</h4>
Give a careful informal proof of <span class="inlinecode"><span class="id" title="var">eqb_true</span></span>, stating the induction
hypothesis explicitly and being as explicit as possible about
quantifiers, everywhere.
</div>
<div class="code">
<span class="comment">(* FILL IN HERE *)</span><br/><hr class='doublespaceincode'/>
<span class="comment">(* Do not modify the following line: *)</span><br/>
<span class="id" title="keyword">Definition</span> <a id="manual_grade_for_informal_proof" class="idref" href="#manual_grade_for_informal_proof"><span class="id" title="definition">manual_grade_for_informal_proof</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#option"><span class="id" title="inductive">option</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="Poly.html#11c698c8685bb8ab1cf725545c085ac<sub>4</sub>"><span class="id" title="notation">×</span></a><a class="idref" href="http://coq.inria.fr/library//Coq.Strings.String.html#string"><span class="id" title="inductive">string</span></a>) := <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#None"><span class="id" title="constructor">None</span></a>.<br/>
<font size=-2>☐</font>
</div>