-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAltAuto.html
2424 lines (2008 loc) · 369 KB
/
AltAuto.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>AltAuto: A Streamlined Treatment of Automation</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">AltAuto<span class="subtitle">A Streamlined Treatment of Automation</span></h1>
<div class="doc">
<div class="paragraph"> </div>
So far, we've been doing all our proofs using just a small
handful of Coq's tactics and completely ignoring its powerful
facilities for constructing parts of proofs automatically. Getting
used to them will take some work -- Coq's automation is a power
tool -- but it will allow us to scale up our efforts to more
complex definitions and more interesting properties without
becoming overwhelmed by boring, repetitive, low-level details.
<div class="paragraph"> </div>
In this chapter, we'll learn about
<div class="paragraph"> </div>
<ul class="doclist">
<li> <i>tacticals</i>, which allow tactics to be combined;
<div class="paragraph"> </div>
</li>
<li> new tactics that make dealing with hypothesis names less fussy
and more maintainable;
<div class="paragraph"> </div>
</li>
<li> <i>automatic solvers</i> that can prove limited classes of theorems
without any human assistance;
<div class="paragraph"> </div>
</li>
<li> <i>proof search</i> with the <span class="inlinecode"><span class="id" title="tactic">auto</span></span> tactic; and
<div class="paragraph"> </div>
</li>
<li> the <i>Ltac</i> language for writing tactics.
</li>
</ul>
<div class="paragraph"> </div>
These features enable startlingly short proofs. Used properly,
they can also make proofs more maintainable and robust to changes
in underlying definitions.
<div class="paragraph"> </div>
This chapter is an alternative to the combination of <a href="Imp.html"><span class="inlineref">Imp</span></a>
and <a href="Auto.html"><span class="inlineref">Auto</span></a>, which cover roughly the same material about
automation, but in the context of programming language metatheory.
A deeper treatment of <span class="inlinecode"><span class="id" title="tactic">auto</span></span> can be found in the <a href="https://softwarefoundations.cis.upenn.edu/plf-current/UseAuto.html"><span class="inlineref">UseAuto</span></a>
chapter in <i>Programming Language Foundations</i>.
</div>
<div class="code">
<span class="id" title="keyword">Set</span> <span class="id" title="var">Warnings</span> "-notation-overridden,-parsing,-deprecated-hint-without-locality,-deprecated-syntactic-definition,-deprecated]".<br/>
<span class="id" title="keyword">From</span> <span class="id" title="var">Coq</span> <span class="id" title="keyword">Require</span> <span class="id" title="keyword">Import</span> <a class="idref" href="http://coq.inria.fr/library//Coq.Arith.Arith.html#"><span class="id" title="library">Arith</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Lists.List.html#"><span class="id" title="library">List</span></a>.<br/>
<span class="id" title="keyword">From</span> <span class="id" title="var">LF</span> <span class="id" title="keyword">Require</span> <span class="id" title="keyword">Import</span> <a class="idref" href="IndProp.html#"><span class="id" title="library">IndProp</span></a>.<br/>
</div>
<div class="doc">
As a simple illustration of the benefits of automation,
let's consider another problem on regular expressions, which we
formalized in <a href="IndProp.html"><span class="inlineref">IndProp</span></a>. A given set of strings can be
denoted by many different regular expressions. For example, <span class="inlinecode"><span class="id" title="var">App</span></span>
<span class="inlinecode"><span class="id" title="var">EmptyString</span></span> <span class="inlinecode"><span class="id" title="var">re</span></span> matches exactly the same strings as <span class="inlinecode"><span class="id" title="var">re</span></span>. We can
write a function that "optimizes" any regular expression into a
potentially simpler one by applying this fact throughout the r.e.
(Note that, for simplicity, the function does not optimize
expressions that arise as the result of other optimizations.)
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <a id="re_opt_e" class="idref" href="#re_opt_e"><span class="id" title="definition">re_opt_e</span></a> {<a id="T:1" class="idref" href="#T:1"><span class="id" title="binder">T</span></a>:<span class="id" title="keyword">Type</span>} (<a id="re:2" class="idref" href="#re:2"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:1"><span class="id" title="variable">T</span></a>) : <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:1"><span class="id" title="variable">T</span></a> :=<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="AltAuto.html#re:2"><span class="id" title="variable">re</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <span class="id" title="var">re<sub>2</sub></span><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> (<a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <span class="id" title="var">re<sub>1</sub></span>) (<a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <span class="id" title="var">re<sub>2</sub></span>)<br/>
| <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> (<a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <span class="id" title="var">re<sub>1</sub></span>) (<a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <span class="id" title="var">re<sub>2</sub></span>)<br/>
| <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> <span class="id" title="var">re</span> ⇒ <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> (<a class="idref" href="AltAuto.html#re_opt_e:3"><span class="id" title="definition">re_opt_e</span></a> <a class="idref" href="AltAuto.html#re:2"><span class="id" title="variable">re</span></a>)<br/>
| <span class="id" title="var">_</span> ⇒ <a class="idref" href="AltAuto.html#re:2"><span class="id" title="variable">re</span></a><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
We would like to show the equivalence of re's with their
"optimized" form. One direction of this equivalence looks like
this (the other is similar).
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="re_opt_e_match" class="idref" href="#re_opt_e_match"><span class="id" title="lemma">re_opt_e_match</span></a> : <span class="id" title="keyword">∀</span> <a id="T:5" class="idref" href="#T:5"><span class="id" title="binder">T</span></a> (<a id="re:6" class="idref" href="#re:6"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:5"><span class="id" title="variable">T</span></a>) <a id="s:7" class="idref" href="#s:7"><span class="id" title="binder">s</span></a>,<br/>
<a class="idref" href="AltAuto.html#s:7"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re:6"><span class="id" title="variable">re</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="AltAuto.html#s:7"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re_opt_e"><span class="id" title="definition">re_opt_e</span></a> <a class="idref" href="AltAuto.html#re:6"><span class="id" title="variable">re</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">T</span> <span class="id" title="var">re</span> <span class="id" title="var">s</span> <span class="id" title="var">M</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">M</span><br/>
<span class="id" title="keyword">as</span> [| <span class="id" title="var">x'</span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span> | <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span><br/>
| <span class="id" title="var">re</span> | <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re</span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span>].<br/>
- <span class="comment">(* MEmpty *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
- <span class="comment">(* MChar *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MChar"><span class="id" title="constructor">MChar</span></a>.<br/>
- <span class="comment">(* MApp *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">Hmatch1</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
- <span class="comment">(* MUnionL *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MUnionR *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MStar0 *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
- <span class="comment">(* MStarApp *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStarApp"><span class="id" title="constructor">MStarApp</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The amount of repetition in that proof is annoying. And if
we wanted to extend the optimization function to handle other,
similar, rewriting opportunities, it would start to be a real
problem. We can streamline the proof with <i>tacticals</i>, which we
turn to, next.
</div>
<div class="doc">
<a id="lab445"></a><h1 class="section">Tacticals</h1>
<div class="paragraph"> </div>
<i>Tacticals</i> are tactics that take other tactics as arguments --
"higher-order tactics," if you will.
</div>
<div class="doc">
<a id="lab446"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="tactic">try</span></span> Tactical</h2>
<div class="paragraph"> </div>
If <span class="inlinecode"><span class="id" title="var">T</span></span> is a tactic, then <span class="inlinecode"><span class="id" title="tactic">try</span></span> <span class="inlinecode"><span class="id" title="var">T</span></span> is a tactic that is just like <span class="inlinecode"><span class="id" title="var">T</span></span>
except that, if <span class="inlinecode"><span class="id" title="var">T</span></span> fails, <span class="inlinecode"><span class="id" title="tactic">try</span></span> <span class="inlinecode"><span class="id" title="var">T</span></span> <i>successfully</i> does nothing at
all instead of failing.
</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:8" class="idref" href="#n:8"><span class="id" title="binder">n</span></a>, 1 <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#n:8"><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="AltAuto.html#n:8"><span class="id" title="variable">n</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">try</span> <span class="id" title="tactic">reflexivity</span>. <span class="comment">(* this just does <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span> *)</span> <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<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="P:9" class="idref" href="#P:9"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="AltAuto.html#P:9"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="AltAuto.html#P:9"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="var">Fail</span> <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="tactic">try</span> <span class="id" title="tactic">reflexivity</span>. <span class="comment">(* proof state is unchanged *)</span><br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
There is no real reason to use <span class="inlinecode"><span class="id" title="tactic">try</span></span> in completely manual
proofs like these, but it is very useful for doing automated
proofs in conjunction with the <span class="inlinecode">;</span> tactical, which we show
next.
</div>
<div class="doc">
<a id="lab447"></a><h2 class="section">The Sequence Tactical <span class="inlinecode">;</span> (Simple Form)</h2>
<div class="paragraph"> </div>
In its most common form, the sequence tactical, written with
semicolon <span class="inlinecode">;</span>, takes two tactics as arguments. The compound
tactic <span class="inlinecode"><span class="id" title="var">T</span>;</span> <span class="inlinecode"><span class="id" title="var">T'</span></span> first performs <span class="inlinecode"><span class="id" title="var">T</span></span> and then performs <span class="inlinecode"><span class="id" title="var">T'</span></span> on <i>each
subgoal</i> generated by <span class="inlinecode"><span class="id" title="var">T</span></span>.
<div class="paragraph"> </div>
For example, consider the following trivial lemma:
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="simple_semi" class="idref" href="#simple_semi"><span class="id" title="lemma">simple_semi</span></a> : <span class="id" title="keyword">∀</span> <a id="n:10" class="idref" href="#n:10"><span class="id" title="binder">n</span></a>, <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#n:10"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 1 <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> 0<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <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>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>.<br/>
<span class="id" title="tactic">destruct</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">(* Leaves two subgoals, which are discharged identically... *)</span><br/>
- <span class="comment">(* n=0 *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
- <span class="comment">(* n=Sn' *)</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">
We can simplify this proof using the <span class="inlinecode">;</span> tactical:
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="simple_semi'" class="idref" href="#simple_semi'"><span class="id" title="lemma">simple_semi'</span></a> : <span class="id" title="keyword">∀</span> <a id="n:11" class="idref" href="#n:11"><span class="id" title="binder">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="AltAuto.html#n:11"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 1 <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> 0<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <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>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>.<br/>
<span class="comment">(* <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> the current goal *)</span><br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">n</span>;<br/>
<span class="comment">(* then <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> each resulting subgoal *)</span><br/>
<span class="id" title="tactic">simpl</span>;<br/>
<span class="comment">(* and do <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span> on each resulting subgoal *)</span><br/>
<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Or even more tersely, <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> can do the <span class="inlinecode"><span class="id" title="tactic">intro</span></span>, and <span class="inlinecode"><span class="id" title="tactic">simpl</span></span>
can be omitted:
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="simple_semi''" class="idref" href="#simple_semi''"><span class="id" title="lemma">simple_semi''</span></a> : <span class="id" title="keyword">∀</span> <a id="n:12" class="idref" href="#n:12"><span class="id" title="binder">n</span></a>, <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#n:12"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> 1 <a class="idref" href="Basics.html#ad2ec4e405f68c46c0a176e3e94ae2e<sub>3</sub>"><span class="id" title="notation">=?</span></a> 0<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">)</span></a> <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>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">n</span>; <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab448"></a><h4 class="section">Exercise: 3 stars, standard (try_sequence)</h4>
<div class="paragraph"> </div>
Prove the following theorems using <span class="inlinecode"><span class="id" title="tactic">try</span></span> and <span class="inlinecode">;</span>. Like
<span class="inlinecode"><span class="id" title="var">simple_semi''</span></span> above, each proof script should be a sequence <span class="inlinecode"><span class="id" title="var">t<sub>1</sub></span>;</span>
<span class="inlinecode">...;</span> <span class="inlinecode"><span class="id" title="var">tn</span>.</span> of tactics, and there should be only one period in
between <span class="inlinecode"><span class="id" title="keyword">Proof</span>.</span> and <span class="inlinecode"><span class="id" title="keyword">Qed</span>.</span>. Let's call that a "one shot"
proof.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="andb_eq_orb" class="idref" href="#andb_eq_orb"><span class="id" title="lemma">andb_eq_orb</span></a> :<br/>
<span class="id" title="keyword">∀</span> (<a id="b:13" class="idref" href="#b:13"><span class="id" title="binder">b</span></a> <a id="c:14" class="idref" href="#c:14"><span class="id" title="binder">c</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#::type_scope:x_'->'_x"><span class="id" title="notation">(</span></a><a class="idref" href="Basics.html#andb"><span class="id" title="definition">andb</span></a> <a class="idref" href="AltAuto.html#b:13"><span class="id" title="variable">b</span></a> <a class="idref" href="AltAuto.html#c:14"><span class="id" title="variable">c</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#orb"><span class="id" title="definition">orb</span></a> <a class="idref" href="AltAuto.html#b:13"><span class="id" title="variable">b</span></a> <a class="idref" href="AltAuto.html#c:14"><span class="id" title="variable">c</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="AltAuto.html#b:13"><span class="id" title="variable">b</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="AltAuto.html#c:14"><span class="id" title="variable">c</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="comment">(* FILL IN HERE *)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="add_assoc" class="idref" href="#add_assoc"><span class="id" title="lemma">add_assoc</span></a> : <span class="id" title="keyword">∀</span> <a id="n:15" class="idref" href="#n:15"><span class="id" title="binder">n</span></a> <a id="m:16" class="idref" href="#m:16"><span class="id" title="binder">m</span></a> <a id="p:17" class="idref" href="#p:17"><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="AltAuto.html#n:15"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#m:16"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#p:17"><span class="id" title="variable">p</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><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#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#n:15"><span class="id" title="variable">n</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#m:16"><span class="id" title="variable">m</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#p:17"><span class="id" title="variable">p</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="comment">(* FILL IN HERE *)</span> <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Fixpoint</span> <a id="nonzeros" class="idref" href="#nonzeros"><span class="id" title="definition">nonzeros</span></a> (<a id="lst:18" class="idref" href="#lst:18"><span class="id" title="binder">lst</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/>
<span class="id" title="keyword">match</span> <a class="idref" href="AltAuto.html#lst:18"><span class="id" title="variable">lst</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a> ⇒ <a class="idref" href="Poly.html#2c60282cbb04e070c60ae01e76f3865a"><span class="id" title="notation">[]</span></a><br/>
| 0 <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <span class="id" title="var">t</span> ⇒ <a class="idref" href="AltAuto.html#nonzeros:19"><span class="id" title="definition">nonzeros</span></a> <span class="id" title="var">t</span><br/>
| <span class="id" title="var">h</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <span class="id" title="var">t</span> ⇒ <span class="id" title="var">h</span> <a class="idref" href="Poly.html#:::x_'::'_x"><span class="id" title="notation">::</span></a> <a class="idref" href="AltAuto.html#nonzeros:19"><span class="id" title="definition">nonzeros</span></a> <span class="id" title="var">t</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="nonzeros_app" class="idref" href="#nonzeros_app"><span class="id" title="lemma">nonzeros_app</span></a> : <span class="id" title="keyword">∀</span> <a id="lst1:21" class="idref" href="#lst1:21"><span class="id" title="binder">lst1</span></a> <a id="lst2:22" class="idref" href="#lst2:22"><span class="id" title="binder">lst2</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="AltAuto.html#nonzeros"><span class="id" title="definition">nonzeros</span></a> (<a class="idref" href="AltAuto.html#lst1:21"><span class="id" title="variable">lst1</span></a> <a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a> <a class="idref" href="AltAuto.html#lst2:22"><span class="id" title="variable">lst2</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#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#nonzeros"><span class="id" title="definition">nonzeros</span></a> <a class="idref" href="AltAuto.html#lst1:21"><span class="id" title="variable">lst1</span></a><a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">)</span></a> <a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a> <a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#nonzeros"><span class="id" title="definition">nonzeros</span></a> <a class="idref" href="AltAuto.html#lst2:22"><span class="id" title="variable">lst2</span></a><a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">)</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <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>
Using <span class="inlinecode"><span class="id" title="tactic">try</span></span> and <span class="inlinecode">;</span> together, we can improve the proof about
regular expression optimization.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="re_opt_e_match'" class="idref" href="#re_opt_e_match'"><span class="id" title="lemma">re_opt_e_match'</span></a> : <span class="id" title="keyword">∀</span> <a id="T:23" class="idref" href="#T:23"><span class="id" title="binder">T</span></a> (<a id="re:24" class="idref" href="#re:24"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:23"><span class="id" title="variable">T</span></a>) <a id="s:25" class="idref" href="#s:25"><span class="id" title="binder">s</span></a>,<br/>
<a class="idref" href="AltAuto.html#s:25"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re:24"><span class="id" title="variable">re</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="AltAuto.html#s:25"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re_opt_e"><span class="id" title="definition">re_opt_e</span></a> <a class="idref" href="AltAuto.html#re:24"><span class="id" title="variable">re</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">T</span> <span class="id" title="var">re</span> <span class="id" title="var">s</span> <span class="id" title="var">M</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">M</span><br/>
<span class="id" title="keyword">as</span> [| <span class="id" title="var">x'</span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span> | <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span><br/>
| <span class="id" title="var">re</span> | <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re</span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span>];<br/>
<span class="comment">(* Do the <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> for every case here: *)</span><br/>
<span class="id" title="tactic">simpl</span>.<br/>
- <span class="comment">(* MEmpty *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
- <span class="comment">(* MChar *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MChar"><span class="id" title="constructor">MChar</span></a>.<br/>
- <span class="comment">(* MApp *)</span><br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>;<br/>
<span class="comment">(* Most cases follow by the same formula. Notice that <span class="inlinecode"><span class="id" title="tactic">apply</span></span>
<span class="inlinecode"><span class="id" title="var">MApp</span></span> gives two subgoals: <span class="inlinecode"><span class="id" title="tactic">try</span></span> <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">IH<sub>1</sub></span></span> is run on _both_ of<br/>
them and succeeds on the first but not the second; <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">IH<sub>2</sub></span></span><br/>
is then run on this remaining goal. *)</span><br/>
<span class="id" title="tactic">try</span> (<span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>; <span class="id" title="tactic">try</span> <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>; <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>).<br/>
<span class="comment">(* The interesting case, on which <span class="inlinecode"><span class="id" title="tactic">try</span>...</span> does nothing, is when<br/>
<span class="inlinecode"><span class="id" title="var">re<sub>1</sub></span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">EmptyStr</span></span>. In this case, we have to appeal to the fact<br/>
that <span class="inlinecode"><span class="id" title="var">re<sub>1</sub></span></span> matches only the empty string: *)</span><br/>
<span class="id" title="tactic">inversion</span> <span class="id" title="var">Hmatch1</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
- <span class="comment">(* MUnionL *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MUnionR *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MStar0 *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
- <span class="comment">(* MStarApp *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStarApp"><span class="id" title="constructor">MStarApp</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab449"></a><h2 class="section">The Sequence Tactical <span class="inlinecode">;</span> (Local Form)</h2>
<div class="paragraph"> </div>
The sequence tactical <span class="inlinecode">;</span> also has a more general form than the
simple <span class="inlinecode"><span class="id" title="var">T</span>;</span> <span class="inlinecode"><span class="id" title="var">T'</span></span> we saw above. If <span class="inlinecode"><span class="id" title="var">T</span></span>, <span class="inlinecode"><span class="id" title="var">T<sub>1</sub></span></span>, ..., <span class="inlinecode"><span class="id" title="var">Tn</span></span> are tactics,
then
<div class="paragraph"> </div>
<span class="inlinecode">[</span> <span class="inlinecode"><span class="id" title="var">T</span>;</span> <span class="inlinecode">[<span class="id" title="var">T<sub>1</sub></span></span> <span class="inlinecode">|</span> <span class="inlinecode"><span class="id" title="var">T<sub>2</sub></span></span> <span class="inlinecode">|</span> <span class="inlinecode">...</span> <span class="inlinecode">|</span> <span class="inlinecode"><span class="id" title="var">Tn</span>]</span> <span class="inlinecode">]</span>
<div class="paragraph"> </div>
is a tactic that first performs <span class="inlinecode"><span class="id" title="var">T</span></span> and then locally performs <span class="inlinecode"><span class="id" title="var">T<sub>1</sub></span></span>
on the first subgoal generated by <span class="inlinecode"><span class="id" title="var">T</span></span>, locally performs <span class="inlinecode"><span class="id" title="var">T<sub>2</sub></span></span> on
the second subgoal, etc.
<div class="paragraph"> </div>
So <span class="inlinecode"><span class="id" title="var">T</span>;</span> <span class="inlinecode"><span class="id" title="var">T'</span></span> is just special notation for the case when all of the
<span class="inlinecode"><span class="id" title="var">Ti</span></span>'s are the same tactic; i.e., <span class="inlinecode"><span class="id" title="var">T</span>;</span> <span class="inlinecode"><span class="id" title="var">T'</span></span> is shorthand for:
<div class="paragraph"> </div>
<br/>
<span class="inlinecode"> <span class="id" title="var">T</span>; [<span class="id" title="var">T'</span> | <span class="id" title="var">T'</span> | ... | <span class="id" title="var">T'</span>]
</span>
<div class="paragraph"> </div>
For example, the following proof makes it clear which tactics are
used to solve the base case vs. the inductive case.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="app_length" class="idref" href="#app_length"><span class="id" title="lemma">app_length</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:26" class="idref" href="#X:26"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="lst1:27" class="idref" href="#lst1:27"><span class="id" title="binder">lst1</span></a> <a id="lst2:28" class="idref" href="#lst2:28"><span class="id" title="binder">lst2</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="AltAuto.html#X:26"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> (<a class="idref" href="AltAuto.html#lst1:27"><span class="id" title="variable">lst1</span></a> <a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a> <a class="idref" href="AltAuto.html#lst2:28"><span class="id" title="variable">lst2</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#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> <a class="idref" href="AltAuto.html#lst1:27"><span class="id" title="variable">lst1</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> <a class="idref" href="AltAuto.html#lst2:28"><span class="id" title="variable">lst2</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><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="tactic">induction</span> <span class="id" title="var">lst1</span>;<br/>
[<span class="id" title="tactic">reflexivity</span> | <span class="id" title="tactic">simpl</span>; <span class="id" title="tactic">rewrite</span> <span class="id" title="var">IHlst1</span>; <span class="id" title="tactic">reflexivity</span>].<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The identity tactic <span class="inlinecode"><span class="id" title="tactic">idtac</span></span> always succeeds without changing the
proof state. We can use it to factor out <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span> in the
previous proof.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="app_length'" class="idref" href="#app_length'"><span class="id" title="lemma">app_length'</span></a> : <span class="id" title="keyword">∀</span> (<a id="X:29" class="idref" href="#X:29"><span class="id" title="binder">X</span></a> : <span class="id" title="keyword">Type</span>) (<a id="lst1:30" class="idref" href="#lst1:30"><span class="id" title="binder">lst1</span></a> <a id="lst2:31" class="idref" href="#lst2:31"><span class="id" title="binder">lst2</span></a> : <a class="idref" href="Poly.html#list"><span class="id" title="inductive">list</span></a> <a class="idref" href="AltAuto.html#X:29"><span class="id" title="variable">X</span></a>),<br/>
<a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> (<a class="idref" href="AltAuto.html#lst1:30"><span class="id" title="variable">lst1</span></a> <a class="idref" href="Poly.html#f03f7a04ef75ff3ac66ca5c23554e52e"><span class="id" title="notation">++</span></a> <a class="idref" href="AltAuto.html#lst2:31"><span class="id" title="variable">lst2</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#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> <a class="idref" href="AltAuto.html#lst1:30"><span class="id" title="variable">lst1</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="Poly.html#length"><span class="id" title="definition">length</span></a> <a class="idref" href="AltAuto.html#lst2:31"><span class="id" title="variable">lst2</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><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="tactic">induction</span> <span class="id" title="var">lst1</span>;<br/>
[<span class="id" title="tactic">idtac</span> | <span class="id" title="tactic">simpl</span>; <span class="id" title="tactic">rewrite</span> <span class="id" title="var">IHlst1</span>];<br/>
<span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab450"></a><h4 class="section">Exercise: 1 star, standard (notry_sequence)</h4>
<div class="paragraph"> </div>
Prove the following theorem with a one-shot proof, but this
time, do not use <span class="inlinecode"><span class="id" title="tactic">try</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="add_assoc'" class="idref" href="#add_assoc'"><span class="id" title="lemma">add_assoc'</span></a> : <span class="id" title="keyword">∀</span> <a id="n:32" class="idref" href="#n:32"><span class="id" title="binder">n</span></a> <a id="m:33" class="idref" href="#m:33"><span class="id" title="binder">m</span></a> <a id="p:34" class="idref" href="#p:34"><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="AltAuto.html#n:32"><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="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#m:33"><span class="id" title="variable">m</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#p:34"><span class="id" title="variable">p</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><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#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">(</span></a><a class="idref" href="AltAuto.html#n:32"><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="AltAuto.html#m:33"><span class="id" title="variable">m</span></a><a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">)</span></a> <a class="idref" href="Basics.html#0dacc1786c5ba797d47dd85006231633"><span class="id" title="notation">+</span></a> <a class="idref" href="AltAuto.html#p:34"><span class="id" title="variable">p</span></a>.<br/>
<span class="id" title="keyword">Proof</span>. <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>
We can use the local form of the sequence tactical to give a
slightly neater version of our optimization proof. Two lines
change, as shown below with <span class="inlinecode"><===</span>.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="re_opt_e_match''" class="idref" href="#re_opt_e_match''"><span class="id" title="lemma">re_opt_e_match''</span></a> : <span class="id" title="keyword">∀</span> <a id="T:35" class="idref" href="#T:35"><span class="id" title="binder">T</span></a> (<a id="re:36" class="idref" href="#re:36"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:35"><span class="id" title="variable">T</span></a>) <a id="s:37" class="idref" href="#s:37"><span class="id" title="binder">s</span></a>,<br/>
<a class="idref" href="AltAuto.html#s:37"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re:36"><span class="id" title="variable">re</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="AltAuto.html#s:37"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re_opt_e"><span class="id" title="definition">re_opt_e</span></a> <a class="idref" href="AltAuto.html#re:36"><span class="id" title="variable">re</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">T</span> <span class="id" title="var">re</span> <span class="id" title="var">s</span> <span class="id" title="var">M</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">M</span><br/>
<span class="id" title="keyword">as</span> [| <span class="id" title="var">x'</span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span> | <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span><br/>
| <span class="id" title="var">re</span> | <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re</span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span>];<br/>
<span class="comment">(* Do the <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> for every case here: *)</span><br/>
<span class="id" title="tactic">simpl</span>.<br/>
- <span class="comment">(* MEmpty *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
- <span class="comment">(* MChar *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MChar"><span class="id" title="constructor">MChar</span></a>.<br/>
- <span class="comment">(* MApp *)</span><br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>;<br/>
<span class="id" title="tactic">try</span> (<span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>; [<span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span> | <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>]). <span class="comment">(* <=== *)</span><br/>
<span class="id" title="tactic">inversion</span> <span class="id" title="var">Hmatch1</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
- <span class="comment">(* MUnionL *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MUnionR *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MStar0 *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
- <span class="comment">(* MStarApp *)</span> <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStarApp"><span class="id" title="constructor">MStarApp</span></a>; [<span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span> | <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>]. <span class="comment">(* <=== *)</span><br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab451"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> Tactical</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> tactical takes another tactic and keeps
applying this tactic until it fails or stops making progress. Here
is an example showing that <span class="inlinecode">10</span> is in a long list:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="In<sub>10</sub>" class="idref" href="#In<sub>10</sub>"><span class="id" title="lemma">In<sub>10</sub></span></a> : <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 10 <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a>1<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>2<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>3<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>4<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>5<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>6<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>7<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>8<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>9<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>10<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">repeat</span> (<span class="id" title="tactic">try</span> (<span class="id" title="tactic">left</span>; <span class="id" title="tactic">reflexivity</span>); <span class="id" title="tactic">right</span>).<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The tactic <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> <span class="inlinecode"><span class="id" title="var">T</span></span> never fails: if the tactic <span class="inlinecode"><span class="id" title="var">T</span></span> doesn't apply
to the original goal, then <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> still succeeds without
changing the original goal (i.e., it repeats zero times).
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="In<sub>10</sub>'" class="idref" href="#In<sub>10</sub>'"><span class="id" title="lemma">In<sub>10</sub>'</span></a> : <a class="idref" href="Logic.html#In"><span class="id" title="definition">In</span></a> 10 <a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a>1<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>2<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>3<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>4<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>5<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>6<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>7<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>8<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>9<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">;</span></a>10<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">repeat</span> (<span class="id" title="tactic">left</span>; <span class="id" title="tactic">reflexivity</span>).<br/>
<span class="id" title="tactic">repeat</span> (<span class="id" title="tactic">right</span>; <span class="id" title="tactic">try</span> (<span class="id" title="tactic">left</span>; <span class="id" title="tactic">reflexivity</span>)).<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
The tactic <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> <span class="inlinecode"><span class="id" title="var">T</span></span> also does not have any upper bound on the
number of times it applies <span class="inlinecode"><span class="id" title="var">T</span></span>. If <span class="inlinecode"><span class="id" title="var">T</span></span> is a tactic that always
succeeds, then repeat <span class="inlinecode"><span class="id" title="var">T</span></span> will loop forever (e.g., <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> <span class="inlinecode"><span class="id" title="tactic">simpl</span></span>
loops, since <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> always succeeds). Evaluation in Coq's term
language, Gallina, is guaranteed to terminate, but tactic
evaluation is not. This does not affect Coq's logical consistency,
however, since the job of <span class="inlinecode"><span class="id" title="tactic">repeat</span></span> and other tactics is to guide
Coq in constructing proofs. If the construction process diverges,
it simply means that we have failed to construct a proof, not that
we have constructed an incorrect proof.
<div class="paragraph"> </div>
<a id="lab452"></a><h4 class="section">Exercise: 1 star, standard (ev100)</h4>
Prove that 100 is even. Your proof script should be quite short.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="ev100" class="idref" href="#ev100"><span class="id" title="lemma">ev100</span></a>: <a class="idref" href="IndProp.html#ev"><span class="id" title="inductive">ev</span></a> 100.<br/>
<span class="id" title="keyword">Proof</span>. <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="lab453"></a><h2 class="section">An Optimization Exercise</h2>
<a id="lab454"></a><h4 class="section">Exercise: 4 stars, standard (re_opt)</h4>
<div class="paragraph"> </div>
Consider this more powerful version of the regular expression
optimizer.
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <a id="re_opt" class="idref" href="#re_opt"><span class="id" title="definition">re_opt</span></a> {<a id="T:38" class="idref" href="#T:38"><span class="id" title="binder">T</span></a>:<span class="id" title="keyword">Type</span>} (<a id="re:39" class="idref" href="#re:39"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:38"><span class="id" title="variable">T</span></a>) : <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:38"><span class="id" title="variable">T</span></a> :=<br/>
<span class="id" title="keyword">match</span> <a class="idref" href="AltAuto.html#re:39"><span class="id" title="variable">re</span></a> <span class="id" title="keyword">with</span><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <span class="id" title="var">_</span> <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a> ⇒ <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>2</sub></span><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <span class="id" title="var">re<sub>1</sub></span> <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a> ⇒ <a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>1</sub></span><br/>
| <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="IndProp.html#App"><span class="id" title="constructor">App</span></a> (<a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>1</sub></span>) (<a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>2</sub></span>)<br/>
| <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>2</sub></span><br/>
| <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> <span class="id" title="var">re<sub>1</sub></span> <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a> ⇒ <a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>1</sub></span><br/>
| <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> ⇒ <a class="idref" href="IndProp.html#Union"><span class="id" title="constructor">Union</span></a> (<a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>1</sub></span>) (<a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <span class="id" title="var">re<sub>2</sub></span>)<br/>
| <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a> ⇒ <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a><br/>
| <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a> ⇒ <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a><br/>
| <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> <span class="id" title="var">re</span> ⇒ <a class="idref" href="IndProp.html#Star"><span class="id" title="constructor">Star</span></a> (<a class="idref" href="AltAuto.html#re_opt:40"><span class="id" title="definition">re_opt</span></a> <a class="idref" href="AltAuto.html#re:39"><span class="id" title="variable">re</span></a>)<br/>
| <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a> ⇒ <a class="idref" href="IndProp.html#EmptySet"><span class="id" title="constructor">EmptySet</span></a><br/>
| <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a> ⇒ <a class="idref" href="IndProp.html#EmptyStr"><span class="id" title="constructor">EmptyStr</span></a><br/>
| <a class="idref" href="IndProp.html#Char"><span class="id" title="constructor">Char</span></a> <span class="id" title="var">x</span> ⇒ <a class="idref" href="IndProp.html#Char"><span class="id" title="constructor">Char</span></a> <span class="id" title="var">x</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="comment">(* Here is an incredibly tedious manual proof of (one direction of)<br/>
its correctness: *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="re_opt_match" class="idref" href="#re_opt_match"><span class="id" title="lemma">re_opt_match</span></a> : <span class="id" title="keyword">∀</span> <a id="T:42" class="idref" href="#T:42"><span class="id" title="binder">T</span></a> (<a id="re:43" class="idref" href="#re:43"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:42"><span class="id" title="variable">T</span></a>) <a id="s:44" class="idref" href="#s:44"><span class="id" title="binder">s</span></a>,<br/>
<a class="idref" href="AltAuto.html#s:44"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re:43"><span class="id" title="variable">re</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="AltAuto.html#s:44"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re_opt"><span class="id" title="definition">re_opt</span></a> <a class="idref" href="AltAuto.html#re:43"><span class="id" title="variable">re</span></a>.<br/>
<div class="togglescript" id="proofcontrol1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')"><span class="show"></span></div>
<div class="proofscript" id="proof1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')">
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">T</span> <span class="id" title="var">re</span> <span class="id" title="var">s</span> <span class="id" title="var">M</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">M</span><br/>
<span class="id" title="keyword">as</span> [| <span class="id" title="var">x'</span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span><br/>
| <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span> | <span class="id" title="var">re<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re<sub>2</sub></span> <span class="id" title="var">Hmatch</span> <span class="id" title="var">IH</span><br/>
| <span class="id" title="var">re</span> | <span class="id" title="var">s<sub>1</sub></span> <span class="id" title="var">s<sub>2</sub></span> <span class="id" title="var">re</span> <span class="id" title="var">Hmatch1</span> <span class="id" title="var">IH<sub>1</sub></span> <span class="id" title="var">Hmatch2</span> <span class="id" title="var">IH<sub>2</sub></span>].<br/>
- <span class="comment">(* MEmpty *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
- <span class="comment">(* MChar *)</span> <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MChar"><span class="id" title="constructor">MChar</span></a>.<br/>
- <span class="comment">(* MApp *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>1</sub></span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Poly.html#app_nil_r"><span class="id" title="axiom">app_nil_r</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Poly.html#app_nil_r"><span class="id" title="axiom">app_nil_r</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Poly.html#app_nil_r"><span class="id" title="axiom">app_nil_r</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>. <span class="id" title="tactic">rewrite</span> <a class="idref" href="Poly.html#app_nil_r"><span class="id" title="axiom">app_nil_r</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MApp"><span class="id" title="constructor">MApp</span></a>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
-- <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
- <span class="comment">(* MUnionL *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionL"><span class="id" title="constructor">MUnionL</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MUnionR *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
+ <span class="id" title="tactic">destruct</span> <span class="id" title="var">re<sub>2</sub></span>.<br/>
× <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MUnionR"><span class="id" title="constructor">MUnionR</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH</span>.<br/>
- <span class="comment">(* MStar0 *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re</span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
+ <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re</span>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar0"><span class="id" title="constructor">MStar0</span></a>.<br/>
- <span class="comment">(* MStarApp *)</span> <span class="id" title="tactic">simpl</span>.<br/>
<span class="id" title="tactic">destruct</span> <span class="id" title="var">re</span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
+ <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>1</sub></span>. <span class="id" title="tactic">inversion</span> <span class="id" title="var">IH<sub>2</sub></span>. <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MEmpty"><span class="id" title="constructor">MEmpty</span></a>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#star_app"><span class="id" title="lemma">star_app</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar1"><span class="id" title="lemma">MStar1</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#star_app"><span class="id" title="lemma">star_app</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar1"><span class="id" title="lemma">MStar1</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#star_app"><span class="id" title="lemma">star_app</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar1"><span class="id" title="lemma">MStar1</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
+ <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#star_app"><span class="id" title="lemma">star_app</span></a>.<br/>
× <span class="id" title="tactic">apply</span> <a class="idref" href="IndProp.html#MStar1"><span class="id" title="lemma">MStar1</span></a>. <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>1</sub></span>.<br/>
× <span class="id" title="tactic">apply</span> <span class="id" title="var">IH<sub>2</sub></span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<br/>
<span class="comment">(* Use the tacticals described so far to shorten the proof. The proof<br/>
above is about 200 lines. Reduce it to 50 or fewer lines of similar<br/>
density. Solve each of the seven top-level bullets with a one-shot<br/>
proof.<br/>
<br/>
Hint: use a bottom-up approach. First copy-paste the entire proof<br/>
below. Then automate the innermost bullets first, proceeding<br/>
outwards. Frequently double-check that the entire proof still<br/>
compiles. If it doesn't, undo the most recent changes you made<br/>
until you get back to a compiling proof. *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Lemma</span> <a id="re_opt_match'" class="idref" href="#re_opt_match'"><span class="id" title="lemma">re_opt_match'</span></a> : <span class="id" title="keyword">∀</span> <a id="T:45" class="idref" href="#T:45"><span class="id" title="binder">T</span></a> (<a id="re:46" class="idref" href="#re:46"><span class="id" title="binder">re</span></a>: <a class="idref" href="IndProp.html#reg_exp"><span class="id" title="inductive">reg_exp</span></a> <a class="idref" href="AltAuto.html#T:45"><span class="id" title="variable">T</span></a>) <a id="s:47" class="idref" href="#s:47"><span class="id" title="binder">s</span></a>,<br/>
<a class="idref" href="AltAuto.html#s:47"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re:46"><span class="id" title="variable">re</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="AltAuto.html#s:47"><span class="id" title="variable">s</span></a> <a class="idref" href="IndProp.html#70ea788eca33f3ac1bb7ed2e8169c791"><span class="id" title="notation">=~</span></a> <a class="idref" href="AltAuto.html#re_opt"><span class="id" title="definition">re_opt</span></a> <a class="idref" href="AltAuto.html#re:46"><span class="id" title="variable">re</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/>
<span class="comment">(* Do not modify the following line: *)</span><br/>
<span class="id" title="keyword">Definition</span> <a id="manual_grade_for_re_opt" class="idref" href="#manual_grade_for_re_opt"><span class="id" title="definition">manual_grade_for_re_opt</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="IndProp.html#string"><span class="id" title="definition">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>
<div class="doc">
<a id="lab455"></a><h1 class="section">Tactics that Make Mentioning Names Unnecessary</h1>
<div class="paragraph"> </div>
So far we have been dependent on knowing the names of
hypotheses. For example, to prove the following simple theorem,
we hardcode the name <span class="inlinecode"><span class="id" title="var">HP</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="hyp_name" class="idref" href="#hyp_name"><span class="id" title="lemma">hyp_name</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:48" class="idref" href="#P:48"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="AltAuto.html#P:48"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="AltAuto.html#P:48"><span class="id" title="variable">P</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">HP</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
We took the trouble to invent a name for <span class="inlinecode"><span class="id" title="var">HP</span></span>, then we had
to remember that name. If we later change the name in one place,
we have to change it everywhere. Likewise, if we were to add new
arguments to the theorem, we would have to adjust the <span class="inlinecode"><span class="id" title="tactic">intros</span></span>
list. That makes it challenging to maintain large proofs. So, Coq
provides several tactics that make it possible to write proof
scripts that do not hardcode names.
</div>
<div class="doc">
<a id="lab456"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="tactic">assumption</span></span> tactic</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="tactic">assumption</span></span> tactic is useful to streamline the proof
above. It looks through the hypotheses and, if it finds the goal
as one them, it uses that to finish the proof.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="no_hyp_name" class="idref" href="#no_hyp_name"><span class="id" title="lemma">no_hyp_name</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:49" class="idref" href="#P:49"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="AltAuto.html#P:49"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="AltAuto.html#P:49"><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="tactic">assumption</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Some might argue to the contrary that hypothesis names
improve self-documention of proof scripts. Maybe they do,
sometimes. But in the case of the two proofs above, the first
mentions unnecessary detail, whereas the second could be
paraphrased simply as "the conclusion follows from the
assumptions."
<div class="paragraph"> </div>
Anyway, unlike informal (good) mathematical proofs, Coq proof
scripts are generally not that illuminating to readers. Worries
about rich, self-documenting names for hypotheses might be
misplaced.
</div>
<div class="doc">
<a id="lab457"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="var">contradiction</span></span> tactic</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="var">contradiction</span></span> tactic handles some ad hoc situations where a
hypothesis contains <span class="inlinecode"><span class="id" title="var">False</span></span>, or two hypotheses derive <span class="inlinecode"><span class="id" title="var">False</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="false_assumed" class="idref" href="#false_assumed"><span class="id" title="lemma">false_assumed</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 1.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">H</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="false_assumed'" class="idref" href="#false_assumed'"><span class="id" title="lemma">false_assumed'</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#False"><span class="id" title="inductive">False</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 1.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span>. <span class="id" title="var">contradiction</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="contras" class="idref" href="#contras"><span class="id" title="lemma">contras</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:50" class="idref" href="#P:50"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="AltAuto.html#P:50"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="AltAuto.html#P:50"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 1.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">P</span> <span class="id" title="var">HP</span> <span class="id" title="var">HNP</span>. <span class="id" title="var">exfalso</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HNP</span>. <span class="id" title="tactic">apply</span> <span class="id" title="var">HP</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="contras'" class="idref" href="#contras'"><span class="id" title="lemma">contras'</span></a> : <span class="id" title="keyword">∀</span> (<a id="P:51" class="idref" href="#P:51"><span class="id" title="binder">P</span></a> : <span class="id" title="keyword">Prop</span>), <a class="idref" href="AltAuto.html#P:51"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#63a68285c81db8f9bc456233bb9ed181"><span class="id" title="notation">¬</span></a><a class="idref" href="AltAuto.html#P:51"><span class="id" title="variable">P</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> 0 <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#6cd0f7b28b6092304087c7049437bb1a"><span class="id" title="notation">=</span></a> 1.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span>. <span class="id" title="var">contradiction</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab458"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="tactic">subst</span></span> tactic</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="tactic">subst</span></span> tactic substitutes away an identifier, replacing
it everywhere and eliminating it from the context. That helps
us to avoid naming hypotheses in <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span>s.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <a id="many_eq" class="idref" href="#many_eq"><span class="id" title="lemma">many_eq</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:52" class="idref" href="#n:52"><span class="id" title="binder">n</span></a> <a id="m:53" class="idref" href="#m:53"><span class="id" title="binder">m</span></a> <a id="o:54" class="idref" href="#o:54"><span class="id" title="binder">o</span></a> <a id="p:55" class="idref" href="#p:55"><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="AltAuto.html#n:52"><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="AltAuto.html#m:53"><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="AltAuto.html#o:54"><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="AltAuto.html#p:55"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a><br/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="AltAuto.html#n:52"><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="AltAuto.html#o:54"><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="AltAuto.html#m:53"><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="AltAuto.html#p:55"><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">Hnm</span> <span class="id" title="var">Hop</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hnm</span>. <span class="id" title="tactic">rewrite</span> <span class="id" title="var">Hop</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <a id="many_eq'" class="idref" href="#many_eq'"><span class="id" title="lemma">many_eq'</span></a> : <span class="id" title="keyword">∀</span> (<a id="n:56" class="idref" href="#n:56"><span class="id" title="binder">n</span></a> <a id="m:57" class="idref" href="#m:57"><span class="id" title="binder">m</span></a> <a id="o:58" class="idref" href="#o:58"><span class="id" title="binder">o</span></a> <a id="p:59" class="idref" href="#p:59"><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="AltAuto.html#n:56"><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="AltAuto.html#m:57"><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="AltAuto.html#o:58"><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="AltAuto.html#p:59"><span class="id" title="variable">p</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a><br/>
<a class="idref" href="Poly.html#fa57d319973f6d58544a8887d0d48ea<sub>6</sub>"><span class="id" title="notation">[</span></a><a class="idref" href="AltAuto.html#n:56"><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="AltAuto.html#o:58"><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="AltAuto.html#m:57"><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="AltAuto.html#p:59"><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="tactic">subst</span>. <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Actually there are two forms of this tactic.
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="tactic">subst</span></span> <span class="inlinecode"><span class="id" title="var">x</span></span> finds an assumption <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> or <span class="inlinecode"><span class="id" title="var">e</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">x</span></span> in the
context, replaces <span class="inlinecode"><span class="id" title="var">x</span></span> with <span class="inlinecode"><span class="id" title="var">e</span></span> throughout the context and
current goal, and removes the assumption from the context.
<div class="paragraph"> </div>
</li>
<li> <span class="inlinecode"><span class="id" title="tactic">subst</span></span> substitutes away <i>all</i> assumptions 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">e</span></span>
or <span class="inlinecode"><span class="id" title="var">e</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">x</span></span>.
</li>
</ul>
</div>
<div class="doc">
<a id="lab459"></a><h2 class="section">The <span class="inlinecode"><span class="id" title="tactic">constructor</span></span> tactic</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="tactic">constructor</span></span> tactic tries to find a constructor <span class="inlinecode"><span class="id" title="var">c</span></span> (from the
appropriate <span class="inlinecode"><span class="id" title="keyword">Inductive</span></span> definition in the current environment)
that can be applied to solve the current goal.
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <a class="idref" href="IndProp.html#ev_0"><span class="id" title="constructor">ev_0</span></a> : <a class="idref" href="IndProp.html#ev"><span class="id" title="inductive">ev</span></a> 0.<br/>
<span class="id" title="keyword">Check</span> <a class="idref" href="IndProp.html#ev_SS"><span class="id" title="constructor">ev_SS</span></a> : <span class="id" title="keyword">∀</span> <a id="n:60" class="idref" href="#n:60"><span class="id" title="binder">n</span></a> : <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>, <a class="idref" href="IndProp.html#ev"><span class="id" title="inductive">ev</span></a> <a class="idref" href="AltAuto.html#n:60"><span class="id" title="variable">n</span></a> <a class="idref" href="http://coq.inria.fr/library//Coq.Init.Logic.html#::type_scope:x_'->'_x"><span class="id" title="notation">→</span></a> <a class="idref" href="IndProp.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> (<a class="idref" href="http://coq.inria.fr/library//Coq.Init.Datatypes.html#S"><span class="id" title="constructor">S</span></a> <a class="idref" href="AltAuto.html#n:60"><span class="id" title="variable">n</span></a>)).<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <a id="constructor_example" class="idref" href="#constructor_example"><span class="id" title="definition">constructor_example</span></a>: <span class="id" title="keyword">∀</span> (<a id="n:61" class="idref" href="#n:61"><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="IndProp.html#ev"><span class="id" title="inductive">ev</span></a> (<a class="idref" href="AltAuto.html#n:61"><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="AltAuto.html#n:61"><span class="id" title="variable">n</span></a>).<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">n</span>; <span class="id" title="tactic">simpl</span>.<br/>
- <span class="id" title="tactic">constructor</span>. <span class="comment">(* applies ev_0 *)</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="tactic">simpl</span>. <span class="id" title="tactic">constructor</span>. <span class="comment">(* applies ev_SS *)</span><br/>
<span class="id" title="tactic">assumption</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Warning: if more than one constructor can apply,
<span class="inlinecode"><span class="id" title="tactic">constructor</span></span> picks the first one, in the order in which they were
defined in the <span class="inlinecode"><span class="id" title="keyword">Inductive</span></span> definition. That might not be the one
you want.
</div>
<div class="doc">
<a id="lab460"></a><h1 class="section">Automatic Solvers</h1>
<div class="paragraph"> </div>
Coq has several special-purpose tactics that can solve
certain kinds of goals in a completely automated way. These
tactics are based on sophisticated algorithms developed for
verification in specific mathematical or logical domains.
<div class="paragraph"> </div>
Some automatic solvers are <i>decision procedures</i>, which are
algorithms that always terminate, and always give a correct
answer. Here, that means that they always find a correct proof, or
correctly determine that the goal is invalid. Other automatic
solvers are <i>incomplete</i>: they might fail to find a proof of a
valid goal.
</div>
<div class="doc">
<a id="lab461"></a><h2 class="section">Linear Integer Arithmetic: The <span class="inlinecode"><span class="id" title="var">lia</span></span> Tactic</h2>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" title="var">lia</span></span> tactic implements a decision procedure for integer
linear arithmetic, a subset of propositional logic and arithmetic.
As input it accepts goals constructed as follows:
<div class="paragraph"> </div>
<ul class="doclist">
<li> variables and constants of type <span class="inlinecode"><span class="id" title="var">nat</span></span>, <span class="inlinecode"><span class="id" title="var">Z</span></span>, and other integer
types;
<div class="paragraph"> </div>
</li>
<li> arithmetic operators <span class="inlinecode">+</span>, <span class="inlinecode">-</span>, <span class="inlinecode">×</span>, and <span class="inlinecode">^</span>;
<div class="paragraph"> </div>
</li>
<li> equality <span class="inlinecode">=</span> and ordering <span class="inlinecode"><</span>, <span class="inlinecode">></span>, <span class="inlinecode">≤</span>, <span class="inlinecode">≥</span>; and
<div class="paragraph"> </div>
</li>
<li> the logical connectives <span class="inlinecode">∧</span>, <span class="inlinecode">∨</span>, <span class="inlinecode">¬</span>, <span class="inlinecode">→</span>, and <span class="inlinecode">↔</span>; and
constants <span class="inlinecode"><span class="id" title="var">True</span></span> and <span class="inlinecode"><span class="id" title="var">False</span></span>.
</li>
</ul>
<div class="paragraph"> </div>
<i>Linear</i> goals involve (in)equalities over expressions of the form
<span class="inlinecode"><span class="id" title="var">c<sub>1</sub></span></span> <span class="inlinecode">×</span> <span class="inlinecode"><span class="id" title="var">x<sub>1</sub></span></span> <span class="inlinecode">+</span> <span class="inlinecode">...</span> <span class="inlinecode">+</span> <span class="inlinecode"><span class="id" title="var">cn</span></span> <span class="inlinecode">×</span> <span class="inlinecode"><span class="id" title="var">xn</span></span>, where <span class="inlinecode"><span class="id" title="var">ci</span></span> are constants and <span class="inlinecode"><span class="id" title="var">xi</span></span> are
variables.
<div class="paragraph"> </div>
<ul class="doclist">
<li> For linear goals, <span class="inlinecode"><span class="id" title="var">lia</span></span> will either solve the goal or fail,
meaning that the goal is actually invalid.
<div class="paragraph"> </div>
</li>
<li> For non-linear goals, <span class="inlinecode"><span class="id" title="var">lia</span></span> will also either solve the goal or
fail. But in this case, the failure does not necessarily mean
that the goal is invalid -- it might just be beyond <span class="inlinecode"><span class="id" title="var">lia</span></span>'s
reach to prove because of non-linearity.
</li>
</ul>