-
Notifications
You must be signed in to change notification settings - Fork 1
/
Auto.html
819 lines (670 loc) · 81.9 KB
/
Auto.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
<!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="coqdoc.css" rel="stylesheet" type="text/css"/>
<title>Auto: More Automation</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<div id="page">
<div id="header">
</div>
<div id="main">
<h1 class="libtitle">Auto<span class="subtitle">More Automation</span></h1>
<div class="code code-tight">
</div>
<div class="doc">
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Export</span> <span class="id" type="var">Imp</span>.<br/>
<br/>
</div>
<div class="doc">
Up to now, we've continued to use a quite restricted set of
Coq's tactic facilities. In this chapter, we'll learn more about
two very powerful features of Coq's tactic language:
proof search via the <span class="inlinecode"><span class="id" type="tactic">auto</span></span> and <span class="inlinecode"><span class="id" type="tactic">eauto</span></span> tactics, and
automated forward reasoning via the <span class="inlinecode"><span class="id" type="keyword">Ltac</span></span> hypothesis matching
machinery. Using these features together with Ltac's scripting facilities
will enable us to make our proofs startlingly short! Used properly,
they can also make proofs more maintainable and robust in the face
of incremental changes to underlying definitions.
<div class="paragraph"> </div>
There's a third major source of automation we haven't
fully studied yet, namely built-in decision procedures for specific
kinds of problems: <span class="inlinecode"><span class="id" type="tactic">omega</span></span> is one example, but there are others.
This topic will be defered for a while longer.
<div class="paragraph"> </div>
<div class="paragraph"> </div>
Our motivating example will be this proof, repeated with
just a few small changes from <span class="inlinecode"><span class="id" type="var">Imp</span></span>. We will try to simplify
this proof in several stages.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Ltac</span> <span class="id" type="var">inv</span> <span class="id" type="var">H</span> := <span class="id" type="tactic">inversion</span> <span class="id" type="var">H</span>; <span class="id" type="tactic">subst</span>; <span class="id" type="tactic">clear</span> <span class="id" type="var">H</span>.<br/>
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>.<br/>
<span class="id" type="var">Case</span> "E_Skip". <span class="id" type="tactic">reflexivity</span>.<br/>
<span class="id" type="var">Case</span> "E_Ass". <span class="id" type="tactic">reflexivity</span>.<br/>
<span class="id" type="var">Case</span> "E_Seq".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SCase</span> "Proof of assertion". <span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1_1</span>; <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1_2</span>. <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="var">Case</span> "E_IfTrue".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1</span>. <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H5</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">Case</span> "E_IfFalse".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H5</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to false".<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1</span>. <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileEnd".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false".<br/>
<span class="id" type="tactic">reflexivity</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H2</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H2</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H4</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H4</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SSCase</span> "Proof of assertion". <span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1_1</span>; <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">IHE1_2</span>. <span class="id" type="tactic">assumption</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab624"></a><h1 class="section">The <span class="inlinecode"><span class="id" type="tactic">auto</span></span> and <span class="inlinecode"><span class="id" type="tactic">eauto</span></span> tactics</h1>
<div class="paragraph"> </div>
Thus far, we have (nearly) always written proof scripts that
apply relevant hypothoses or lemmas by name. In particular, when
a chain of hypothesis applications is needed, we have specified
them explicitly. (The only exceptions introduced so far are using
<span class="inlinecode"><span class="id" type="tactic">assumption</span></span> to find a matching unqualified hypothesis
or <span class="inlinecode">(<span class="id" type="var">e</span>)<span class="id" type="var">constructor</span></span> to find a matching constructor.)
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_1</span> : <span style="font-family: arial;">∀</span>(<span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span>: <span class="id" type="keyword">Prop</span>), (<span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">Q</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">Q</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span> <span class="id" type="var">H1</span> <span class="id" type="var">H2</span> <span class="id" type="var">H3</span>.<br/>
<span class="id" type="tactic">apply</span> <span class="id" type="var">H2</span>. <span class="id" type="tactic">apply</span> <span class="id" type="var">H1</span>. <span class="id" type="tactic">assumption</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
The <span class="inlinecode"><span class="id" type="tactic">auto</span></span> tactic frees us from this drudgery by <i>searching</i>
for a sequence of applications that will prove the goal
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_1'</span> : <span style="font-family: arial;">∀</span>(<span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span>: <span class="id" type="keyword">Prop</span>), (<span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">Q</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">Q</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span> <span class="id" type="var">H1</span> <span class="id" type="var">H2</span> <span class="id" type="var">H3</span>.<br/>
<span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
The <span class="inlinecode"><span class="id" type="tactic">auto</span></span> tactic solves goals that are solvable by any combination of
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" type="tactic">intros</span></span>,
</li>
<li> <span class="inlinecode"><span class="id" type="tactic">apply</span></span> (with a local hypothesis, by default).
</li>
</ul>
<div class="paragraph"> </div>
The <span class="inlinecode"><span class="id" type="tactic">eauto</span></span> tactic works just like <span class="inlinecode"><span class="id" type="tactic">auto</span></span>, except that it uses
<span class="inlinecode"><span class="id" type="tactic">eapply</span></span> instead of <span class="inlinecode"><span class="id" type="tactic">apply</span></span>.
<div class="paragraph"> </div>
Using <span class="inlinecode"><span class="id" type="tactic">auto</span></span> is always "safe" in the sense that it will never fail
and will never change the proof state: either it completely solves
the current goal, or it does nothing.
<div class="paragraph"> </div>
A more complicated example:
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_2</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span> <span class="id" type="var">S</span> <span class="id" type="var">T</span> <span class="id" type="var">U</span> : <span class="id" type="keyword">Prop</span>,<br/>
(<span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">Q</span>) <span style="font-family: arial;">→</span><br/>
(<span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span><br/>
(<span class="id" type="var">T</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span><br/>
(<span class="id" type="var">S</span> <span style="font-family: arial;">→</span> <span class="id" type="var">T</span> <span style="font-family: arial;">→</span> <span class="id" type="var">U</span>) <span style="font-family: arial;">→</span><br/>
((<span class="id" type="var">P</span><span style="font-family: arial;">→</span><span class="id" type="var">Q</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">P</span><span style="font-family: arial;">→</span><span class="id" type="var">S</span>)) <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">T</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">P</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">U</span>.<br/>
<span class="id" type="keyword">Proof</span>. <span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
Search can take an arbitrarily long time, so there are limits to
how far <span class="inlinecode"><span class="id" type="tactic">auto</span></span> will search by default
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_3</span> : <span style="font-family: arial;">∀</span>(<span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span> <span class="id" type="var">S</span> <span class="id" type="var">T</span> <span class="id" type="var">U</span>: <span class="id" type="keyword">Prop</span>), <br/>
(<span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">Q</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">Q</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">R</span> <span style="font-family: arial;">→</span> <span class="id" type="var">S</span>) <span style="font-family: arial;">→</span> <br/>
(<span class="id" type="var">S</span> <span style="font-family: arial;">→</span> <span class="id" type="var">T</span>) <span style="font-family: arial;">→</span> (<span class="id" type="var">T</span> <span style="font-family: arial;">→</span> <span class="id" type="var">U</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">P</span> <span style="font-family: arial;">→</span> <span class="id" type="var">U</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="comment">(* When it cannot solve the goal, does nothing! *)</span><br/>
<span class="id" type="tactic">auto</span> 6. <span class="comment">(* Optional argument says how deep to search (default depth is 5) *)</span><br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
When searching for potential proofs of the current goal, <span class="inlinecode"><span class="id" type="tactic">auto</span></span>
and <span class="inlinecode"><span class="id" type="tactic">eauto</span></span> consider the hypotheses in the current context
together with a <i>hint database</i> of other lemmas and constructors.
Some of the lemmas and constructors we've already seen — e.g.,
<span class="inlinecode"><span class="id" type="var">eq_refl</span></span>, <span class="inlinecode"><span class="id" type="var">conj</span></span>, <span class="inlinecode"><span class="id" type="var">or_introl</span></span>, and <span class="inlinecode"><span class="id" type="var">or_intror</span></span> — are installed in this hint
database by default.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_4</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">P</span> <span class="id" type="var">Q</span> <span class="id" type="var">R</span> : <span class="id" type="keyword">Prop</span>,<br/>
<span class="id" type="var">Q</span> <span style="font-family: arial;">→</span><br/>
(<span class="id" type="var">Q</span> <span style="font-family: arial;">→</span> <span class="id" type="var">R</span>) <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">P</span> <span style="font-family: arial;">∨</span> (<span class="id" type="var">Q</span> <span style="font-family: arial;">∧</span> <span class="id" type="var">R</span>).<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
If we want to see which facts <span class="inlinecode"><span class="id" type="tactic">auto</span></span> is using, we can use <span class="inlinecode"><span class="id" type="var">info_auto</span></span> instead.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_5</span>: 2 = 2.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="var">info_auto</span>. <span class="comment">(* subsumes reflexivity because eq_refl is in hint database *)</span><br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
We can extend the hint database just for the purposes of one
application of <span class="inlinecode"><span class="id" type="tactic">auto</span></span> or <span class="inlinecode"><span class="id" type="tactic">eauto</span></span> by writing <span class="inlinecode"><span class="id" type="tactic">auto</span></span> <span class="inlinecode"><span class="id" type="keyword">using</span></span> <span class="inlinecode">...</span>.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Lemma</span> <span class="id" type="var">le_antisym</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">n</span> <span class="id" type="var">m</span>: <span class="id" type="var">nat</span>, (<span class="id" type="var">n</span> ≤ <span class="id" type="var">m</span> <span style="font-family: arial;">∧</span> <span class="id" type="var">m</span> ≤ <span class="id" type="var">n</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">n</span> = <span class="id" type="var">m</span>.<br/>
<span class="id" type="keyword">Proof</span>. <span class="id" type="tactic">intros</span>. <span class="id" type="tactic">omega</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_6</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">n</span> <span class="id" type="var">m</span> <span class="id" type="var">p</span> : <span class="id" type="var">nat</span>,<br/>
(<span class="id" type="var">n</span>≤ <span class="id" type="var">p</span> <span style="font-family: arial;">→</span> (<span class="id" type="var">n</span> ≤ <span class="id" type="var">m</span> <span style="font-family: arial;">∧</span> <span class="id" type="var">m</span> ≤ <span class="id" type="var">n</span>)) <span style="font-family: arial;">→</span> <br/>
<span class="id" type="var">n</span> ≤ <span class="id" type="var">p</span> <span style="font-family: arial;">→</span> <br/>
<span class="id" type="var">n</span> = <span class="id" type="var">m</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="comment">(* does nothing: auto doesn't destruct hypotheses! *)</span><br/>
<span class="id" type="tactic">auto</span> <span class="id" type="keyword">using</span> <span class="id" type="var">le_antisym</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
Of course, in any given development there will also be some of our
own specific constructors and lemmas that are used very often in
proofs. We can add these to the global hint database by writing
<div class="paragraph"> </div>
<div class="code code-tight">
<span class="id" type="keyword">Hint</span> <span class="id" type="keyword">Resolve</span> <span class="id" type="var">T</span>.
<div class="paragraph"> </div>
</div>
at the top level, where <span class="inlinecode"><span class="id" type="var">T</span></span> is a top-level theorem or a
constructor of an inductively defined proposition (i.e., anything
whose type is an implication). As a shorthand, we can write
<div class="paragraph"> </div>
<div class="code code-tight">
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <span class="id" type="var">c</span>.
<div class="paragraph"> </div>
</div>
to tell Coq to do a <span class="inlinecode"><span class="id" type="keyword">Hint</span></span> <span class="inlinecode"><span class="id" type="keyword">Resolve</span></span> for <i>all</i> of the constructors
from the inductive definition of <span class="inlinecode"><span class="id" type="var">c</span></span>.
<div class="paragraph"> </div>
It is also sometimes necessary to add
<div class="paragraph"> </div>
<div class="code code-tight">
<span class="id" type="keyword">Hint</span> <span class="id" type="keyword">Unfold</span> <span class="id" type="var">d</span>.
<div class="paragraph"> </div>
</div>
where <span class="inlinecode"><span class="id" type="var">d</span></span> is a defined symbol, so that <span class="inlinecode"><span class="id" type="tactic">auto</span></span> knows to expand
uses of <span class="inlinecode"><span class="id" type="var">d</span></span> and enable further possibilities for applying
lemmas that it knows about.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="keyword">Resolve</span> <span class="id" type="var">le_antisym</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_6'</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">n</span> <span class="id" type="var">m</span> <span class="id" type="var">p</span> : <span class="id" type="var">nat</span>,<br/>
(<span class="id" type="var">n</span>≤ <span class="id" type="var">p</span> <span style="font-family: arial;">→</span> (<span class="id" type="var">n</span> ≤ <span class="id" type="var">m</span> <span style="font-family: arial;">∧</span> <span class="id" type="var">m</span> ≤ <span class="id" type="var">n</span>)) <span style="font-family: arial;">→</span> <br/>
<span class="id" type="var">n</span> ≤ <span class="id" type="var">p</span> <span style="font-family: arial;">→</span> <br/>
<span class="id" type="var">n</span> = <span class="id" type="var">m</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="comment">(* picks up hint from database *)</span><br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">is_fortytwo</span> <span class="id" type="var">x</span> := <span class="id" type="var">x</span> = 42.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_7</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">x</span>, (<span class="id" type="var">x</span> ≤ 42 <span style="font-family: arial;">∧</span> 42 ≤ <span class="id" type="var">x</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">is_fortytwo</span> <span class="id" type="var">x</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="comment">(* does nothing *)</span><br/>
<span class="id" type="keyword">Abort</span>.<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="keyword">Unfold</span> <span class="id" type="var">is_fortytwo</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_7'</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span>, (<span class="id" type="var">x</span> ≤ 42 <span style="font-family: arial;">∧</span> 42 ≤ <span class="id" type="var">x</span>) <span style="font-family: arial;">→</span> <span class="id" type="var">is_fortytwo</span> <span class="id" type="var">x</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="var">info_auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <span class="id" type="var">ceval</span>.<br/>
<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">st12</span> := <span class="id" type="var">update</span> (<span class="id" type="var">update</span> <span class="id" type="var">empty_state</span> <span class="id" type="var">X</span> 1) <span class="id" type="var">Y</span> 2.<br/>
<span class="id" type="keyword">Definition</span> <span class="id" type="var">st21</span> := <span class="id" type="var">update</span> (<span class="id" type="var">update</span> <span class="id" type="var">empty_state</span> <span class="id" type="var">X</span> 2) <span class="id" type="var">Y</span> 1.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_8</span> : <span style="font-family: arial;">∃</span><span class="id" type="var">s'</span>,<br/>
(<span class="id" type="var">IFB</span> (<span class="id" type="var">BLe</span> (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">Y</span>))<br/>
<span class="id" type="var">THEN</span> (<span class="id" type="var">Z</span> ::= <span class="id" type="var">AMinus</span> (<span class="id" type="var">AId</span> <span class="id" type="var">Y</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>))<br/>
<span class="id" type="var">ELSE</span> (<span class="id" type="var">Y</span> ::= <span class="id" type="var">APlus</span> (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">Z</span>))<br/>
<span class="id" type="var">FI</span>) / <span class="id" type="var">st21</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">s'</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="var">eexists</span>. <span class="id" type="var">info_auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <span class="id" type="var">auto_example_8'</span> : <span style="font-family: arial;">∃</span><span class="id" type="var">s'</span>,<br/>
(<span class="id" type="var">IFB</span> (<span class="id" type="var">BLe</span> (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">Y</span>))<br/>
<span class="id" type="var">THEN</span> (<span class="id" type="var">Z</span> ::= <span class="id" type="var">AMinus</span> (<span class="id" type="var">AId</span> <span class="id" type="var">Y</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>))<br/>
<span class="id" type="var">ELSE</span> (<span class="id" type="var">Y</span> ::= <span class="id" type="var">APlus</span> (<span class="id" type="var">AId</span> <span class="id" type="var">X</span>) (<span class="id" type="var">AId</span> <span class="id" type="var">Z</span>))<br/>
<span class="id" type="var">FI</span>) / <span class="id" type="var">st12</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">s'</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="var">eexists</span>. <span class="id" type="var">info_auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
Now let's take a pass over <span class="inlinecode"><span class="id" type="var">ceval_deterministic</span></span> using <span class="inlinecode"><span class="id" type="tactic">auto</span></span>
to simplify the proof script. We see that all simple sequences of hypothesis
applications and all uses of <span class="inlinecode"><span class="id" type="tactic">reflexivity</span></span> can be replaced by <span class="inlinecode"><span class="id" type="tactic">auto</span></span>,
which we add to the default tactic to be applied to each case.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic'</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_Seq".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_IfTrue".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H5</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">Case</span> "E_IfFalse".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H5</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileEnd".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H2</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H2</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="tactic">rewrite</span> <span class="id" type="var">H</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H4</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">H4</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SSCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab625"></a><h1 class="section">Searching Hypotheses</h1>
<div class="paragraph"> </div>
The proof has become simpler, but there is still an annoying amount
of repetition. Let's start by tackling the contradiction cases. Each
of them occurs in a situation where we have both
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" type="var">H1</span>:</span> <span class="inlinecode"><span class="id" type="var">beval</span></span> <span class="inlinecode"><span class="id" type="var">st</span></span> <span class="inlinecode"><span class="id" type="var">b</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">false</span></span>
<div class="paragraph"> </div>
and
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" type="var">H2</span>:</span> <span class="inlinecode"><span class="id" type="var">beval</span></span> <span class="inlinecode"><span class="id" type="var">st</span></span> <span class="inlinecode"><span class="id" type="var">b</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">true</span></span>
<div class="paragraph"> </div>
as hypotheses. The contradiction is evident, but demonstrating it
is a little complicated: we have to locate the two hypotheses <span class="inlinecode"><span class="id" type="var">H1</span></span> and <span class="inlinecode"><span class="id" type="var">H2</span></span>
and do a <span class="inlinecode"><span class="id" type="tactic">rewrite</span></span> following by an <span class="inlinecode"><span class="id" type="tactic">inversion</span></span>. We'd like to automate
this process.
<div class="paragraph"> </div>
Note: In fact, Coq has a built-in tactic <span class="inlinecode"><span class="id" type="tactic">congruence</span></span> that will do the
job. But we'll ignore the existence of this tactic for now, in order
to demonstrate how to build forward search tactics by hand.
<div class="paragraph"> </div>
<div class="paragraph"> </div>
As a first step, we can abstract out the piece of script in question by
writing a small amount of paramerized Ltac.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Ltac</span> <span class="id" type="var">rwinv</span> <span class="id" type="var">H1</span> <span class="id" type="var">H2</span> := <span class="id" type="tactic">rewrite</span> <span class="id" type="var">H1</span> <span class="id" type="keyword">in</span> <span class="id" type="var">H2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">H2</span>.<br/>
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic''</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_Seq".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_IfTrue".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="var">rwinv</span> <span class="id" type="var">H</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">Case</span> "E_IfFalse".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="var">rwinv</span> <span class="id" type="var">H</span> <span class="id" type="var">H5</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileEnd".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="var">rwinv</span> <span class="id" type="var">H</span> <span class="id" type="var">H2</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="var">rwinv</span> <span class="id" type="var">H</span> <span class="id" type="var">H4</span>.<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SSCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
But this is not much better. We really want Coq to discover
the relevant hypotheses for us. We can do this by using the
<span class="inlinecode"><span class="id" type="keyword">match</span></span> <span class="inlinecode"><span class="id" type="var">goal</span></span> <span class="inlinecode"><span class="id" type="keyword">with</span></span> <span class="inlinecode">...</span> <span class="inlinecode"><span class="id" type="keyword">end</span></span> facility of Ltac.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Ltac</span> <span class="id" type="var">find_rwinv</span> :=<br/>
<span class="id" type="keyword">match</span> <span class="id" type="var">goal</span> <span class="id" type="keyword">with</span><br/>
<span class="id" type="var">H1</span>: ?<span class="id" type="var">E</span> = <span class="id" type="var">true</span>, <span class="id" type="var">H2</span>: ?<span class="id" type="var">E</span> = <span class="id" type="var">false</span> <span style="font-family: arial;">⊢</span> <span class="id" type="var">_</span> ⇒ <span class="id" type="var">rwinv</span> <span class="id" type="var">H1</span> <span class="id" type="var">H2</span><br/>
<span class="id" type="keyword">end</span>.<br/>
<br/>
</div>
<div class="doc">
In words, this <span class="inlinecode"><span class="id" type="keyword">match</span></span> <span class="inlinecode"><span class="id" type="var">goal</span></span> looks for two (distinct) hypotheses that have
the form of equalities with the same arbitrary expression <span class="inlinecode"><span class="id" type="var">E</span></span> on the
left and conflicting boolean values on the right; if such hypotheses are
found, it binds <span class="inlinecode"><span class="id" type="var">H1</span></span> and <span class="inlinecode"><span class="id" type="var">H2</span></span> to their names, and applies the tactic
after the <span class="inlinecode">⇒</span>.
<div class="paragraph"> </div>
Adding this tactic to our default string handles all the contradiction cases.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic'''</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">find_rwinv</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_Seq".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">assert</span> (<span class="id" type="var">st'</span> = <span class="id" type="var">st'0</span>) <span class="id" type="keyword">as</span> <span class="id" type="var">EQ1</span>.<br/>
<span class="id" type="var">SSCase</span> "Proof of assertion". <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="tactic">subst</span> <span class="id" type="var">st'0</span>.<br/>
<span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
Finally, let's see about the remaining cases. Each of them involves
applying a conditional hypothesis to extract an equality. Currently
we have phrased these as assertions, so that we have to predict what
the resulting equality will be (although we can then use <span class="inlinecode"><span class="id" type="tactic">auto</span></span>
to prove it.) An alternative is to pick the relevant
hypotheses to use, and then rewrite with them, as follows:
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic''''</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">find_rwinv</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_Seq".<br/>
<span class="id" type="tactic">rewrite</span> (<span class="id" type="var">IHE1_1</span> <span class="id" type="var">st'0</span> <span class="id" type="var">H1</span>) <span class="id" type="keyword">in</span> ×. <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_WhileLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true".<br/>
<span class="id" type="tactic">rewrite</span> (<span class="id" type="var">IHE1_1</span> <span class="id" type="var">st'0</span> <span class="id" type="var">H3</span>) <span class="id" type="keyword">in</span> ×. <span class="id" type="tactic">auto</span>. <span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
Now we can automate the task of finding the relevant hypotheses to
rewrite with.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Ltac</span> <span class="id" type="var">find_eqn</span> :=<br/>
<span class="id" type="keyword">match</span> <span class="id" type="var">goal</span> <span class="id" type="keyword">with</span><br/>
<span class="id" type="var">H1</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">x</span>, ?<span class="id" type="var">P</span> <span class="id" type="var">x</span> <span style="font-family: arial;">→</span> ?<span class="id" type="var">L</span> = ?<span class="id" type="var">R</span>, <span class="id" type="var">H2</span>: ?<span class="id" type="var">P</span> ?<span class="id" type="var">X</span> <span style="font-family: arial;">⊢</span> <span class="id" type="var">_</span> ⇒ <br/>
<span class="id" type="tactic">rewrite</span> (<span class="id" type="var">H1</span> <span class="id" type="var">X</span> <span class="id" type="var">H2</span>) <span class="id" type="keyword">in</span> × <br/>
<span class="id" type="keyword">end</span>.<br/>
<br/>
</div>
<div class="doc">
But there are several pairs of hypotheses that have the right
general form, and it seems tricky to pick out the ones we actually need.
A key trick is to realize that we can <i>try them all</i>!
Here's how this works:
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" type="tactic">rewrite</span></span> will fail given a trivial equation of the form <span class="inlinecode"><span class="id" type="var">X</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">X</span></span>.
</li>
<li> each execution of <span class="inlinecode"><span class="id" type="keyword">match</span></span> <span class="inlinecode"><span class="id" type="var">goal</span></span> will keep trying to find a valid pair of
hypotheses until the tactic on the RHS of the match succeeds;
if there are no such pairs, it fails.
</li>
<li> we can wrap the whole thing in a <span class="inlinecode"><span class="id" type="tactic">repeat</span></span> which will keep
doing useful rewrites until only trivial ones are left.
</li>
</ul>
</div>
<div class="code code-tight">
<br/>
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic'''''</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">find_rwinv</span>; <span class="id" type="tactic">repeat</span> <span class="id" type="var">find_eqn</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
</div>
<div class="doc">
The big pay-off in this approach is that our proof script
should be robust in the face of modest changes to our language.
For example, we can add a <span class="inlinecode"><span class="id" type="var">REPEAT</span></span> command to the language.
(This was an exercise in <span class="inlinecode"><span class="id" type="var">Hoare.v</span></span>.)
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Module</span> <span class="id" type="var">Repeat</span>.<br/>
<br/>
<span class="id" type="keyword">Inductive</span> <span class="id" type="var">com</span> : <span class="id" type="keyword">Type</span> :=<br/>
| <span class="id" type="var">CSkip</span> : <span class="id" type="var">com</span><br/>
| <span class="id" type="var">CAsgn</span> : <span class="id" type="var">id</span> <span style="font-family: arial;">→</span> <span class="id" type="var">aexp</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span><br/>
| <span class="id" type="var">CSeq</span> : <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span><br/>
| <span class="id" type="var">CIf</span> : <span class="id" type="var">bexp</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span><br/>
| <span class="id" type="var">CWhile</span> : <span class="id" type="var">bexp</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span><br/>
| <span class="id" type="var">CRepeat</span> : <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">bexp</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span>.<br/>
<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" type="var">REPEAT</span></span> behaves like <span class="inlinecode"><span class="id" type="var">WHILE</span></span>, except that the loop guard is
checked <i>after</i> each execution of the body, with the loop
repeating as long as the guard stays <i>false</i>. Because of this,
the body will always execute at least once.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Tactic Notation</span> "com_cases" <span class="id" type="var">tactic</span>(<span class="id" type="var">first</span>) <span class="id" type="var">ident</span>(<span class="id" type="var">c</span>) :=<br/>
<span class="id" type="var">first</span>;<br/>
[ <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "SKIP" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "::=" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> ";"<br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "IFB" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "WHILE"<br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "CRepeat" ].<br/>
<br/>
<span class="id" type="keyword">Notation</span> "'SKIP'" := <br/>
<span class="id" type="var">CSkip</span>.<br/>
<span class="id" type="keyword">Notation</span> "c1 ; c2" := <br/>
(<span class="id" type="var">CSeq</span> <span class="id" type="var">c1</span> <span class="id" type="var">c2</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 80, <span class="id" type="var">right</span> <span class="id" type="var">associativity</span>).<br/>
<span class="id" type="keyword">Notation</span> "X '::=' a" := <br/>
(<span class="id" type="var">CAsgn</span> <span class="id" type="var">X</span> <span class="id" type="var">a</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 60).<br/>
<span class="id" type="keyword">Notation</span> "'WHILE' b 'DO' c 'END'" := <br/>
(<span class="id" type="var">CWhile</span> <span class="id" type="var">b</span> <span class="id" type="var">c</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 80, <span class="id" type="var">right</span> <span class="id" type="var">associativity</span>).<br/>
<span class="id" type="keyword">Notation</span> "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := <br/>
(<span class="id" type="var">CIf</span> <span class="id" type="var">e1</span> <span class="id" type="var">e2</span> <span class="id" type="var">e3</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 80, <span class="id" type="var">right</span> <span class="id" type="var">associativity</span>).<br/>
<span class="id" type="keyword">Notation</span> "'REPEAT' e1 'UNTIL' b2 'END'" := <br/>
(<span class="id" type="var">CRepeat</span> <span class="id" type="var">e1</span> <span class="id" type="var">b2</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 80, <span class="id" type="var">right</span> <span class="id" type="var">associativity</span>).<br/>
<br/>
<span class="id" type="keyword">Inductive</span> <span class="id" type="var">ceval</span> : <span class="id" type="var">state</span> <span style="font-family: arial;">→</span> <span class="id" type="var">com</span> <span style="font-family: arial;">→</span> <span class="id" type="var">state</span> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <span class="id" type="var">E_Skip</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span>,<br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">SKIP</span> <span class="id" type="var">st</span><br/>
| <span class="id" type="var">E_Ass</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">a1</span> <span class="id" type="var">n</span> <span class="id" type="var">X</span>,<br/>
<span class="id" type="var">aeval</span> <span class="id" type="var">st</span> <span class="id" type="var">a1</span> = <span class="id" type="var">n</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">X</span> ::= <span class="id" type="var">a1</span>) (<span class="id" type="var">update</span> <span class="id" type="var">st</span> <span class="id" type="var">X</span> <span class="id" type="var">n</span>)<br/>
| <span class="id" type="var">E_Seq</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">c1</span> <span class="id" type="var">c2</span> <span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">st''</span>,<br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st'</span> <span class="id" type="var">c2</span> <span class="id" type="var">st''</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">c1</span> ; <span class="id" type="var">c2</span>) <span class="id" type="var">st''</span><br/>
| <span class="id" type="var">E_IfTrue</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">b1</span> <span class="id" type="var">c1</span> <span class="id" type="var">c2</span>,<br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st</span> <span class="id" type="var">b1</span> = <span class="id" type="var">true</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">IFB</span> <span class="id" type="var">b1</span> <span class="id" type="var">THEN</span> <span class="id" type="var">c1</span> <span class="id" type="var">ELSE</span> <span class="id" type="var">c2</span> <span class="id" type="var">FI</span>) <span class="id" type="var">st'</span><br/>
| <span class="id" type="var">E_IfFalse</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">b1</span> <span class="id" type="var">c1</span> <span class="id" type="var">c2</span>,<br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st</span> <span class="id" type="var">b1</span> = <span class="id" type="var">false</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c2</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">IFB</span> <span class="id" type="var">b1</span> <span class="id" type="var">THEN</span> <span class="id" type="var">c1</span> <span class="id" type="var">ELSE</span> <span class="id" type="var">c2</span> <span class="id" type="var">FI</span>) <span class="id" type="var">st'</span><br/>
| <span class="id" type="var">E_WhileEnd</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">b1</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span>,<br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st</span> <span class="id" type="var">b1</span> = <span class="id" type="var">false</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">WHILE</span> <span class="id" type="var">b1</span> <span class="id" type="var">DO</span> <span class="id" type="var">c1</span> <span class="id" type="var">END</span>) <span class="id" type="var">st</span><br/>
| <span class="id" type="var">E_WhileLoop</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">st''</span> <span class="id" type="var">b1</span> <span class="id" type="var">c1</span>,<br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st</span> <span class="id" type="var">b1</span> = <span class="id" type="var">true</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st'</span> (<span class="id" type="var">WHILE</span> <span class="id" type="var">b1</span> <span class="id" type="var">DO</span> <span class="id" type="var">c1</span> <span class="id" type="var">END</span>) <span class="id" type="var">st''</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">WHILE</span> <span class="id" type="var">b1</span> <span class="id" type="var">DO</span> <span class="id" type="var">c1</span> <span class="id" type="var">END</span>) <span class="id" type="var">st''</span><br/>
| <span class="id" type="var">E_RepeatEnd</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">b1</span> <span class="id" type="var">c1</span>,<br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st'</span> <span class="id" type="var">b1</span> = <span class="id" type="var">true</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">CRepeat</span> <span class="id" type="var">c1</span> <span class="id" type="var">b1</span>) <span class="id" type="var">st'</span><br/>
| <span class="id" type="var">E_RepeatLoop</span> : <span style="font-family: arial;">∀</span><span class="id" type="var">st</span> <span class="id" type="var">st'</span> <span class="id" type="var">st''</span> <span class="id" type="var">b1</span> <span class="id" type="var">c1</span>,<br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">beval</span> <span class="id" type="var">st'</span> <span class="id" type="var">b1</span> = <span class="id" type="var">false</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st'</span> (<span class="id" type="var">CRepeat</span> <span class="id" type="var">c1</span> <span class="id" type="var">b1</span>) <span class="id" type="var">st''</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> (<span class="id" type="var">CRepeat</span> <span class="id" type="var">c1</span> <span class="id" type="var">b1</span>) <span class="id" type="var">st''</span><br/>
.<br/>
<br/>
<span class="id" type="keyword">Tactic Notation</span> "ceval_cases" <span class="id" type="var">tactic</span>(<span class="id" type="var">first</span>) <span class="id" type="var">ident</span>(<span class="id" type="var">c</span>) :=<br/>
<span class="id" type="var">first</span>;<br/>
[ <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_Skip" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_Ass"<br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_Seq"<br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_IfTrue" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_IfFalse"<br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_WhileEnd" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_WhileLoop" <br/>
| <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_RepeatEnd" | <span class="id" type="var">Case_aux</span> <span class="id" type="var">c</span> "E_RepeatLoop" <br/>
].<br/>
<br/>
<span class="id" type="keyword">Notation</span> "c1 '/' st '<span style="font-family: arial;">⇓</span>' st'" := (<span class="id" type="var">ceval</span> <span class="id" type="var">st</span> <span class="id" type="var">c1</span> <span class="id" type="var">st'</span>) <br/>
(<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 40, <span class="id" type="var">st</span> <span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 39).<br/>
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">find_rwinv</span>; <span class="id" type="tactic">repeat</span> <span class="id" type="var">find_eqn</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="var">Case</span> "E_RepeatEnd".<br/>
<span class="id" type="var">SCase</span> "b evaluates to false (contradiction)".<br/>
<span class="id" type="var">find_rwinv</span>.<br/>
<span class="comment">(* oops: why didn't <span class="inlinecode"><span class="id" type="var">find_rwinv</span></span> solve this for us already? <br/>
answer: we did things in the wrong order. *)</span><br/>
<span class="id" type="tactic">case</span> "E_RepeatLoop".<br/>
<span class="id" type="var">SCase</span> "b evaluates to true (contradiction)".<br/>
<span class="id" type="var">find_rwinv</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">Theorem</span> <span class="id" type="var">ceval_deterministic'</span>: <span style="font-family: arial;">∀</span><span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span>,<br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st1</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">c</span> / <span class="id" type="var">st</span> <span style="font-family: arial;">⇓</span> <span class="id" type="var">st2</span> <span style="font-family: arial;">→</span><br/>
<span class="id" type="var">st1</span> = <span class="id" type="var">st2</span>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">c</span> <span class="id" type="var">st</span> <span class="id" type="var">st1</span> <span class="id" type="var">st2</span> <span class="id" type="var">E1</span> <span class="id" type="var">E2</span>;<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">st2</span>;<br/>
<span class="id" type="var">ceval_cases</span> (<span class="id" type="tactic">induction</span> <span class="id" type="var">E1</span>) <span class="id" type="var">Case</span>;<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">st2</span> <span class="id" type="var">E2</span>; <span class="id" type="var">inv</span> <span class="id" type="var">E2</span>; <span class="id" type="tactic">repeat</span> <span class="id" type="var">find_eqn</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">find_rwinv</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
<br/>
<span class="id" type="keyword">End</span> <span class="id" type="var">Repeat</span>.<br/>
<br/>
</div>
<div class="doc">
These examples just give a flavor of what "hyper-automation" can do...
<div class="paragraph"> </div>
The details of using <span class="inlinecode"><span class="id" type="keyword">match</span></span> <span class="inlinecode"><span class="id" type="var">goal</span></span> are tricky, and debugging is
not pleasant at all. But it is well worth adding at least simple
uses to your proofs to avoid tedium and "future proof" your scripts.
<div class="paragraph"> </div>
</div>
<div class="code code-tight">
<br/>
<span class="comment">(* $Date: 2013-07-30 12:24:33 -0400 (Tue, 30 Jul 2013) $ *)</span><br/>
</div>
</div>
<div id="footer">
<hr/><a href="coqindex.html">Index</a><hr/>This page has been generated by <a href="http://www.lix.polytechnique.fr/coq/">coqdoc</a>
</div>
</div>
</body>
</html>