-
Notifications
You must be signed in to change notification settings - Fork 1
/
attributes.html
6478 lines (5852 loc) · 327 KB
/
attributes.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>
<html lang="en">
<head>
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/style.css">
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/pygments.css">
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/pygments-dark.css">
<link rel="shortcut icon" href="https://pygae.github.io/lean-ga-docs/favicon.ico">
<title>Attributes - mathlib3 docs</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Attributes are a tool for associating information with declarations. In the simplest case, an attribute is a tag that can be applied to a declaration. simp is a common example of this." />
<link rel="canonical" href="https://leanprover-community.github.io/mathlib_docs/attributes.html" />
<meta property="og:title" content="Attributes - mathlib3 docs">
<meta property="og:site_name" content="mathlib for Lean 3 - API documentation">
<meta property="og:description" content="Attributes are a tool for associating information with declarations. In the simplest case, an attribute is a tag that can be applied to a declaration. simp is a common example of this.">
<meta property="og:image" content="https://pygae.github.io/lean-ga-docs/meta-og.png">
<meta name="twitter:card" content="summary">
<script src="https://pygae.github.io/lean-ga-docs/color_scheme.js"></script>
</head>
<body>
<input id="nav_toggle" type="checkbox">
<header>
<h1><label for="nav_toggle"></label><a href="https://leanprover-community.github.io/lean3">mathlib3</a>
<span>documentation</span></h1>
<p class="header_filename break_within">Attributes</p>
<form action="https://google.com/search" method="get" id="search_form">
<input type="hidden" name="sitesearch" value="https://leanprover-community.github.io/mathlib_docs">
<input type="text" name="q" autocomplete="off">
<button>Google site search</button>
</form>
</header>
<nav class="internal_nav">
<h3><a href="#top">Attributes</a></h3>
<details class="tagfilter-div">
<summary>Filter by tag</summary>
<label><input type="checkbox" id="tagfilter-selectall" name="tagfilter-selectall">Select/deselect all</label>
<br><hr>
<label><input type="checkbox" class="tagfilter" name="arithmetic" value="arithmetic">arithmetic</label>
<br>
<label><input type="checkbox" class="tagfilter" name="category-theory" value="category-theory">category theory</label>
<br>
<label><input type="checkbox" class="tagfilter" name="coercions" value="coercions">coercions</label>
<br>
<label><input type="checkbox" class="tagfilter" name="decision_procedure" value="decision_procedure">decision_procedure</label>
<br>
<label><input type="checkbox" class="tagfilter" name="environment" value="environment">environment</label>
<br>
<label><input type="checkbox" class="tagfilter" name="lemma-derivation" value="lemma-derivation">lemma derivation</label>
<br>
<label><input type="checkbox" class="tagfilter" name="linting" value="linting">linting</label>
<br>
<label><input type="checkbox" class="tagfilter" name="logic" value="logic">logic</label>
<br>
<label><input type="checkbox" class="tagfilter" name="parsing" value="parsing">parsing</label>
<br>
<label><input type="checkbox" class="tagfilter" name="rewrite" value="rewrite">rewrite</label>
<br>
<label><input type="checkbox" class="tagfilter" name="search" value="search">search</label>
<br>
<label><input type="checkbox" class="tagfilter" name="simplification" value="simplification">simplification</label>
<br>
<label><input type="checkbox" class="tagfilter" name="structures" value="structures">structures</label>
<br>
<label><input type="checkbox" class="tagfilter" name="transport" value="transport">transport</label>
<br>
</details>
<div class="taclink transport environment"><a href="#ancestor">ancestor</a></div>
<div class="taclink category-theory"><a href="#elementwise">elementwise</a></div>
<div class="taclink lemma-derivation environment"><a href="#expand_exists">expand_exists</a></div>
<div class="taclink rewrite logic"><a href="#ext">ext</a></div>
<div class="taclink lemma-derivation"><a href="#higher_order">higher_order</a></div>
<div class="taclink rewrite search"><a href="#hint_tactic">hint_tactic</a></div>
<div class="taclink environment"><a href="#interactive">interactive</a></div>
<div class="taclink linting"><a href="#linter">linter</a></div>
<div class="taclink logic environment"><a href="#mk_iff">mk_iff</a></div>
<div class="taclink linting"><a href="#nolint">nolint</a></div>
<div class="taclink coercions simplification"><a href="#norm_cast attributes">norm_cast attributes</a></div>
<div class="taclink arithmetic decision_procedure"><a href="#norm_num">norm_num</a></div>
<div class="taclink parsing environment structures"><a href="#protect_proj">protect_proj</a></div>
<div class="taclink parsing environment"><a href="#protected">protected</a></div>
<div class="taclink category-theory"><a href="#reassoc">reassoc</a></div>
<div class="taclink simplification"><a href="#simps">simps</a></div>
<div class="taclink search"><a href="#tidy">tidy</a></div>
<div class="taclink transport environment lemma-derivation"><a href="#to_additive">to_additive</a></div>
<div class="taclink coercions transport"><a href="#zify">zify</a></div>
</nav>
<main>
<a id="top"></a>
<div class="docfile">
<h1>Attributes</h1>
<p><em>Attributes</em> are a tool for associating information with declarations.</p>
<p>In the simplest case, an attribute is a tag that can be applied to a declaration.
<code>simp</code> is a common example of this. A lemma</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo</span> <span class="o">:</span> <span class="bp">...</span>
</code></pre></div>
<p>has been tagged with the <code>simp</code> attribute.
When the simplifier runs, it will collect all lemmas that have been tagged with this attribute.</p>
<p>More complicated attributes take <em>parameters</em>. An example of this is the <code>nolint</code> attribute.
It takes a list of linter names when it is applied, and for each declaration tagged with <code>@[nolint linter_1 linter_2]</code>,
this list can be accessed by a metaprogram.</p>
<p>Attributes can also be applied to declarations with the syntax:</p>
<div class="codehilite"><pre><span></span><code><span class="kn">attribute</span> <span class="o">[</span><span class="n">attr_name</span><span class="o">]</span> <span class="n">decl_name_1</span> <span class="n">decl_name_2</span> <span class="n">decl_name</span> <span class="mi">3</span>
</code></pre></div>
<p>The core API for creating and using attributes can be found in
<a href="init/meta/attribute.html">init.meta.attribute</a>.</p>
<div class="tactic transport environment">
<h2 id="ancestor"><a href="#ancestor">ancestor</a></h2>
<p>The <code>ancestor</code> attributes is used to record the names of structures which appear in the
extends clause of a <code>structure</code> or <code>class</code> declared with <code>old_structure_cmd</code> set to true.</p>
<p>As an example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">set_option</span> <span class="n">old_structure_cmd</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span>
<span class="kd">structure</span> <span class="n">base_one</span> <span class="o">:=</span> <span class="o">(</span><span class="n">one</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span>
<span class="kd">structure</span> <span class="n">base_two</span> <span class="o">(</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">)</span> <span class="o">:=</span> <span class="o">(</span><span class="n">two</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span>
<span class="kd">@[ancestor base_one base_two]</span>
<span class="kd">structure</span> <span class="n">bar</span> <span class="kd">extends</span> <span class="n">base_one</span><span class="o">,</span> <span class="n">base_two</span> <span class="n">α</span>
</code></pre></div>
<p>The list of ancestors should be in the order they appear in the <code>extends</code> clause, and should
contain only the names of the ancestor structures, without any arguments.</p>
<div class="tags">Tags:
<ul>
<li>transport</li>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/algebra.html#tactic.ancestor_attr">tactic.ancestor_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.algebra</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic category-theory">
<h2 id="elementwise"><a href="#elementwise">elementwise</a></h2>
<p>The <code>elementwise</code> attribute can be applied to a lemma</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[elementwise]</span>
<span class="kd">lemma</span> <span class="n">some_lemma</span> <span class="o">{</span><span class="n">C</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">}</span> <span class="o">[</span><span class="n">category</span> <span class="n">C</span><span class="o">]</span>
<span class="o">{</span><span class="n">X</span> <span class="n">Y</span> <span class="n">Z</span> <span class="o">:</span> <span class="n">C</span><span class="o">}</span> <span class="o">(</span><span class="n">f</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">⟶</span> <span class="n">Y</span><span class="o">)</span> <span class="o">(</span><span class="n">g</span> <span class="o">:</span> <span class="n">Y</span> <span class="bp">⟶</span> <span class="n">Z</span><span class="o">)</span> <span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">⟶</span> <span class="n">Z</span><span class="o">)</span> <span class="o">(</span><span class="n">w</span> <span class="o">:</span> <span class="bp">...</span><span class="o">)</span> <span class="o">:</span> <span class="n">f</span> <span class="bp">≫</span> <span class="n">g</span> <span class="bp">=</span> <span class="n">h</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>and will produce</p>
<div class="codehilite"><pre><span></span><code><span class="kd">lemma</span> <span class="n">some_lemma_apply</span> <span class="o">{</span><span class="n">C</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">}</span> <span class="o">[</span><span class="n">category</span> <span class="n">C</span><span class="o">]</span> <span class="o">[</span><span class="n">concrete_category</span> <span class="n">C</span><span class="o">]</span>
<span class="o">{</span><span class="n">X</span> <span class="n">Y</span> <span class="n">Z</span> <span class="o">:</span> <span class="n">C</span><span class="o">}</span> <span class="o">(</span><span class="n">f</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">⟶</span> <span class="n">Y</span><span class="o">)</span> <span class="o">(</span><span class="n">g</span> <span class="o">:</span> <span class="n">Y</span> <span class="bp">⟶</span> <span class="n">Z</span><span class="o">)</span> <span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">⟶</span> <span class="n">Z</span><span class="o">)</span> <span class="o">(</span><span class="n">w</span> <span class="o">:</span> <span class="bp">...</span><span class="o">)</span> <span class="o">(</span><span class="n">x</span> <span class="o">:</span> <span class="n">X</span><span class="o">)</span> <span class="o">:</span> <span class="n">g</span> <span class="o">(</span><span class="n">f</span> <span class="n">x</span><span class="o">)</span> <span class="bp">=</span> <span class="n">h</span> <span class="n">x</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>Here <code>X</code> is being coerced to a type via <code>concrete_category.has_coe_to_sort</code> and
<code>f</code>, <code>g</code>, and <code>h</code> are being coerced to functions via <code>concrete_category.has_coe_to_fun</code>.
Further, we simplify the type using <code>concrete_category.coe_id : ((𝟙 X) : X → X) x = x</code> and
<code>concrete_category.coe_comp : (f ≫ g) x = g (f x)</code>,
replacing morphism composition with function composition.</p>
<p>The <code>[concrete_category C]</code> argument will be omitted if it is possible to synthesize an instance.</p>
<p>The name of the produced lemma can be specified with <code>@[elementwise other_lemma_name]</code>.
If <code>simp</code> is added first, the generated lemma will also have the <code>simp</code> attribute.</p>
<div class="tags">Tags:
<ul>
<li>category theory</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/elementwise.html#tactic.elementwise_attr">tactic.elementwise_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.elementwise</li></ul></details>
</div>
<div class="tactic lemma-derivation environment">
<h2 id="expand_exists"><a href="#expand_exists">expand_exists</a></h2>
<p>From a proof that (a) value(s) exist(s) with certain properties, constructs (an) instance(s)
satisfying those properties. For instance:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[expand_exists nat_greater nat_greater_spec]</span>
<span class="kd">lemma</span> <span class="n">nat_greater_exists</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="bp">∃</span> <span class="n">m</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">,</span> <span class="n">n</span> <span class="bp"><</span> <span class="n">m</span> <span class="o">:=</span> <span class="bp">...</span>
<span class="k">#check</span> <span class="n">nat_greater</span> <span class="c1">-- nat_greater : ℕ → ℕ</span>
<span class="k">#check</span> <span class="n">nat_greater_spec</span> <span class="c1">-- nat_greater_spec : ∀ (n : ℕ), n < nat_greater n</span>
</code></pre></div>
<p>It supports multiple witnesses:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[expand_exists nat_greater_m nat_greater_l nat_greater_spec]</span>
<span class="kd">lemma</span> <span class="n">nat_greater_exists</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="bp">∃</span> <span class="o">(</span><span class="n">m</span> <span class="n">l</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">),</span> <span class="n">n</span> <span class="bp"><</span> <span class="n">m</span> <span class="bp">∧</span> <span class="n">m</span> <span class="bp"><</span> <span class="n">l</span> <span class="o">:=</span> <span class="bp">...</span>
<span class="k">#check</span> <span class="n">nat_greater_m</span> <span class="c1">-- nat_greater : ℕ → ℕ</span>
<span class="k">#check</span> <span class="n">nat_greater_l</span> <span class="c1">-- nat_greater : ℕ → ℕ</span>
<span class="k">#check</span> <span class="n">nat_greater_spec</span><span class="c1">-- nat_greater_spec : ∀ (n : ℕ),</span>
<span class="n">n</span> <span class="bp"><</span> <span class="n">nat_greater_m</span> <span class="n">n</span> <span class="bp">∧</span> <span class="n">nat_greater_m</span> <span class="n">n</span> <span class="bp"><</span> <span class="n">nat_greater_l</span> <span class="n">n</span>
</code></pre></div>
<p>It also supports logical conjunctions:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[expand_exists nat_greater nat_greater_lt nat_greater_nonzero]</span>
<span class="kd">lemma</span> <span class="n">nat_greater_exists</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="bp">∃</span> <span class="n">m</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">,</span> <span class="n">n</span> <span class="bp"><</span> <span class="n">m</span> <span class="bp">∧</span> <span class="n">m</span> <span class="bp">≠</span> <span class="mi">0</span> <span class="o">:=</span> <span class="bp">...</span>
<span class="k">#check</span> <span class="n">nat_greater</span> <span class="c1">-- nat_greater : ℕ → ℕ</span>
<span class="k">#check</span> <span class="n">nat_greater_lt</span> <span class="c1">-- nat_greater_lt : ∀ (n : ℕ), n < nat_greater n</span>
<span class="k">#check</span> <span class="n">nat_greater_nonzero</span> <span class="c1">-- nat_greater_nonzero : ∀ (n : ℕ), nat_greater n ≠ 0</span>
</code></pre></div>
<p>Note that without the last argument <code>nat_greater_nonzero</code>, <code>nat_greater_lt</code> would be:</p>
<div class="codehilite"><pre><span></span><code><span class="k">#check</span> <span class="n">nat_greater_lt</span> <span class="c1">-- nat_greater_lt : ∀ (n : ℕ), n < nat_greater n ∧ nat_greater n ≠ 0</span>
<span class="bp">```</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>lemma derivation</li>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/expand_exists.html#tactic.expand_exists_attr">tactic.expand_exists_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.expand_exists</li>
<li>import tactic</li></ul></details>
</div>
<div class="tactic rewrite logic">
<h2 id="ext"><a href="#ext">ext</a></h2>
<p>Tag lemmas of the form:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext]</span>
<span class="kd">lemma</span> <span class="n">my_collection.ext</span> <span class="o">(</span><span class="n">a</span> <span class="n">b</span> <span class="o">:</span> <span class="n">my_collection</span><span class="o">)</span>
<span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">x</span><span class="o">,</span> <span class="n">a.lookup</span> <span class="n">x</span> <span class="bp">=</span> <span class="n">b.lookup</span> <span class="n">y</span><span class="o">)</span> <span class="o">:</span>
<span class="n">a</span> <span class="bp">=</span> <span class="n">b</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>The attribute indexes extensionality lemma using the type of the
objects (i.e. <code>my_collection</code>) which it gets from the statement of
the lemma. In some cases, the same lemma can be used to state the
extensionality of multiple types that are definitionally equivalent.</p>
<div class="codehilite"><pre><span></span><code><span class="kn">attribute</span> <span class="o">[</span><span class="n">ext</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#thunk">thunk</a></span><span class="o">,</span> <span class="n">ext</span> <span class="n">stream</span><span class="o">]</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/funext.html#funext">funext</a></span>
</code></pre></div>
<p>Also, the following:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext]</span>
<span class="kd">lemma</span> <span class="n">my_collection.ext</span> <span class="o">(</span><span class="n">a</span> <span class="n">b</span> <span class="o">:</span> <span class="n">my_collection</span><span class="o">)</span>
<span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">x</span><span class="o">,</span> <span class="n">a.lookup</span> <span class="n">x</span> <span class="bp">=</span> <span class="n">b.lookup</span> <span class="n">y</span><span class="o">)</span> <span class="o">:</span>
<span class="n">a</span> <span class="bp">=</span> <span class="n">b</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>is equivalent to</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext my_collection]</span>
<span class="kd">lemma</span> <span class="n">my_collection.ext</span> <span class="o">(</span><span class="n">a</span> <span class="n">b</span> <span class="o">:</span> <span class="n">my_collection</span><span class="o">)</span>
<span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">x</span><span class="o">,</span> <span class="n">a.lookup</span> <span class="n">x</span> <span class="bp">=</span> <span class="n">b.lookup</span> <span class="n">y</span><span class="o">)</span> <span class="o">:</span>
<span class="n">a</span> <span class="bp">=</span> <span class="n">b</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>This allows us specify type synonyms along with the type
that is referred to in the lemma statement.</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext, ext my_type_synonym]</span>
<span class="kd">lemma</span> <span class="n">my_collection.ext</span> <span class="o">(</span><span class="n">a</span> <span class="n">b</span> <span class="o">:</span> <span class="n">my_collection</span><span class="o">)</span>
<span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">x</span><span class="o">,</span> <span class="n">a.lookup</span> <span class="n">x</span> <span class="bp">=</span> <span class="n">b.lookup</span> <span class="n">y</span><span class="o">)</span> <span class="o">:</span>
<span class="n">a</span> <span class="bp">=</span> <span class="n">b</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>The <code>ext</code> attribute can be applied to a structure to generate its extensionality lemmas:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext]</span>
<span class="kd">structure</span> <span class="n">foo</span> <span class="o">(</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">)</span> <span class="o">:=</span>
<span class="o">(</span><span class="n">x</span> <span class="n">y</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span>
<span class="o">(</span><span class="n">z</span> <span class="o">:</span> <span class="o">{</span><span class="n">z</span> <span class="bp">//</span> <span class="n">z</span> <span class="bp"><</span> <span class="n">x</span><span class="o">})</span>
<span class="o">(</span><span class="n">k</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span>
<span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="n">x</span> <span class="bp"><</span> <span class="n">y</span><span class="o">)</span>
</code></pre></div>
<p>will generate:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[ext]</span> <span class="kd">lemma</span> <span class="n">foo.ext</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Type</span> <span class="n">u_1</span><span class="o">}</span> <span class="o">(</span><span class="n">x</span> <span class="n">y</span> <span class="o">:</span> <span class="n">foo</span> <span class="n">α</span><span class="o">),</span>
<span class="n">x.x</span> <span class="bp">=</span> <span class="n">y.x</span> <span class="bp">→</span> <span class="n">x.y</span> <span class="bp">=</span> <span class="n">y.y</span> <span class="bp">→</span> <span class="n">x.z</span> <span class="bp">==</span> <span class="n">y.z</span> <span class="bp">→</span> <span class="n">x.k</span> <span class="bp">=</span> <span class="n">y.k</span> <span class="bp">→</span> <span class="n">x</span> <span class="bp">=</span> <span class="n">y</span>
<span class="kd">lemma</span> <span class="n">foo.ext_iff</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Type</span> <span class="n">u_1</span><span class="o">}</span> <span class="o">(</span><span class="n">x</span> <span class="n">y</span> <span class="o">:</span> <span class="n">foo</span> <span class="n">α</span><span class="o">),</span>
<span class="n">x</span> <span class="bp">=</span> <span class="n">y</span> <span class="bp">↔</span> <span class="n">x.x</span> <span class="bp">=</span> <span class="n">y.x</span> <span class="bp">∧</span> <span class="n">x.y</span> <span class="bp">=</span> <span class="n">y.y</span> <span class="bp">∧</span> <span class="n">x.z</span> <span class="bp">==</span> <span class="n">y.z</span> <span class="bp">∧</span> <span class="n">x.k</span> <span class="bp">=</span> <span class="n">y.k</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>rewrite</li>
<li>logic</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/ext.html#extensional_attribute">extensional_attribute</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.ext</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic lemma-derivation">
<h2 id="higher_order"><a href="#higher_order">higher_order</a></h2>
<p>A user attribute that applies to lemmas of the shape <code>∀ x, f (g x) = h x</code>.
It derives an auxiliary lemma of the form <code>f ∘ g = h</code> for reasoning about higher-order functions.</p>
<div class="tags">Tags:
<ul>
<li>lemma derivation</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/core.html#tactic.higher_order_attr">tactic.higher_order_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.core</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic rewrite search">
<h2 id="hint_tactic"><a href="#hint_tactic">hint_tactic</a></h2>
<p>An attribute marking a <code><a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a></code> or <code><a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/data/string/basic.html#string">string</a></code> which should be used by the <code>hint</code>
tactic.</p>
<div class="tags">Tags:
<ul>
<li>rewrite</li>
<li>search</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/hint.html#tactic.hint.hint_tactic_attribute">tactic.hint.hint_tactic_attribute</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.hint</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic environment">
<h2 id="interactive"><a href="#interactive">interactive</a></h2>
<p>Copies a definition into the <code>tactic.interactive</code> namespace to make it usable
in proof scripts. It allows one to write</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[interactive]</span>
<span class="kd">meta</span> <span class="kd">def</span> <span class="n">my_tactic</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>instead of</p>
<div class="codehilite"><pre><span></span><code><span class="kd">meta</span> <span class="kd">def</span> <span class="n">my_tactic</span> <span class="o">:=</span> <span class="bp">...</span>
<span class="kd">run_cmd</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/meta/interactive.html#add_interactive">add_interactive</a></span> <span class="o">[</span><span class="bp">``</span><span class="n">my_tactic</span><span class="o">]</span>
<span class="bp">```</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/core.html#tactic.interactive_attr">tactic.interactive_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.core</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic linting">
<h2 id="linter"><a href="#linter">linter</a></h2>
<p>Defines the user attribute <code><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/basic.html#linter">linter</a></code> for adding a linter to the default set.
Linters should be defined in the <code><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/basic.html#linter">linter</a></code> namespace.
A linter <code>linter.my_new_linter</code> is referred to as <code>my_new_linter</code> (without the <code><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/basic.html#linter">linter</a></code> namespace)
when used in <code>#lint</code>.</p>
<div class="tags">Tags:
<ul>
<li>linting</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/basic.html#linter_attr">linter_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.lint.basic</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic logic environment">
<h2 id="mk_iff"><a href="#mk_iff">mk_iff</a></h2>
<p>Applying the <code>mk_iff</code> attribute to an inductively-defined proposition <code>mk_iff</code> makes an <code><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#iff">iff</a></code> rule
<code>r</code> with the shape <code>∀ps is, i as ↔ ⋁_j, ∃cs, is = cs</code>, where <code>ps</code> are the type parameters, <code>is</code> are
the indices, <code>j</code> ranges over all possible constructors, the <code>cs</code> are the parameters for each of the
constructors, and the equalities <code>is = cs</code> are the instantiations for each constructor for each of
the indices to the inductive type <code>i</code>.</p>
<p>In each case, we remove constructor parameters (i.e. <code>cs</code>) when the corresponding equality would
be just <code>c = i</code> for some index <code>i</code>.</p>
<p>For example, if we try the following:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[mk_iff]</span> <span class="kd">structure</span> <span class="n">foo</span> <span class="o">(</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="kt">Prop</span> <span class="o">:=</span>
<span class="o">(</span><span class="n">equal</span> <span class="o">:</span> <span class="n">m</span> <span class="bp">=</span> <span class="n">n</span><span class="o">)</span>
<span class="o">(</span><span class="n">sum_eq_two</span> <span class="o">:</span> <span class="n">m</span> <span class="bp">+</span> <span class="n">n</span> <span class="bp">=</span> <span class="mi">2</span><span class="o">)</span>
</code></pre></div>
<p>Then <code>#check foo_iff</code> returns:</p>
<div class="codehilite"><pre><span></span><code><span class="n">foo_iff</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">(</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">),</span> <span class="n">foo</span> <span class="n">m</span> <span class="n">n</span> <span class="bp">↔</span> <span class="n">m</span> <span class="bp">=</span> <span class="n">n</span> <span class="bp">∧</span> <span class="n">m</span> <span class="bp">+</span> <span class="n">n</span> <span class="bp">=</span> <span class="mi">2</span>
</code></pre></div>
<p>You can add an optional string after <code>mk_iff</code> to change the name of the generated lemma.
For example, if we try the following:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[mk_iff bar]</span> <span class="kd">structure</span> <span class="n">foo</span> <span class="o">(</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="kt">Prop</span> <span class="o">:=</span>
<span class="o">(</span><span class="n">equal</span> <span class="o">:</span> <span class="n">m</span> <span class="bp">=</span> <span class="n">n</span><span class="o">)</span>
<span class="o">(</span><span class="n">sum_eq_two</span> <span class="o">:</span> <span class="n">m</span> <span class="bp">+</span> <span class="n">n</span> <span class="bp">=</span> <span class="mi">2</span><span class="o">)</span>
</code></pre></div>
<p>Then <code>#check bar</code> returns:</p>
<div class="codehilite"><pre><span></span><code><span class="n">bar</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">(</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">),</span> <span class="n">foo</span> <span class="n">m</span> <span class="n">n</span> <span class="bp">↔</span> <span class="n">m</span> <span class="bp">=</span> <span class="n">n</span> <span class="bp">∧</span> <span class="n">m</span> <span class="bp">+</span> <span class="n">n</span> <span class="bp">=</span> <span class="mi">2</span>
</code></pre></div>
<p>See also the user command <code>mk_iff_of_inductive_prop</code>.</p>
<div class="tags">Tags:
<ul>
<li>logic</li>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/mk_iff_of_inductive_prop.html#mk_iff_attr">mk_iff_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.mk_iff_of_inductive_prop</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic linting">
<h2 id="nolint"><a href="#nolint">nolint</a></h2>
<p>Defines the user attribute <code>nolint</code> for skipping <code>#lint</code></p>
<div class="tags">Tags:
<ul>
<li>linting</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/basic.html#nolint_attr">nolint_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.lint.basic</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic coercions simplification">
<h2 id="norm_cast attributes"><a href="#norm_cast attributes">norm_cast attributes</a></h2>
<p>The <code>norm_cast</code> attribute should be given to lemmas that describe the
behaviour of a coercion in regard to an operator, a relation, or a particular
function.</p>
<p>It only concerns equality or iff lemmas involving <code>↑</code>, <code>⇑</code> and <code>↥</code>, describing the behavior of
the coercion functions.
It does not apply to the explicit functions that define the coercions.</p>
<p>Examples:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">coe_nat_inj'</span> <span class="o">{</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">}</span> <span class="o">:</span> <span class="o">(</span><span class="bp">↑</span><span class="n">m</span> <span class="o">:</span> <span class="n">ℤ</span><span class="o">)</span> <span class="bp">=</span> <span class="bp">↑</span><span class="n">n</span> <span class="bp">↔</span> <span class="n">m</span> <span class="bp">=</span> <span class="n">n</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">coe_int_denom</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℤ</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℚ</span><span class="o">)</span><span class="bp">.</span><span class="n">denom</span> <span class="bp">=</span> <span class="mi">1</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">cast_id</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℚ</span><span class="o">,</span> <span class="bp">↑</span><span class="n">n</span> <span class="bp">=</span> <span class="n">n</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">coe_nat_add</span> <span class="o">(</span><span class="n">m</span> <span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="bp">↑</span><span class="o">(</span><span class="n">m</span> <span class="bp">+</span> <span class="n">n</span><span class="o">)</span> <span class="o">:</span> <span class="n">ℤ</span><span class="o">)</span> <span class="bp">=</span> <span class="bp">↑</span><span class="n">m</span> <span class="bp">+</span> <span class="bp">↑</span><span class="n">n</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">cast_sub</span> <span class="o">[</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a></span> <span class="n">α</span><span class="o">]</span> <span class="o">[</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_one">has_one</a></span> <span class="n">α</span><span class="o">]</span> <span class="o">{</span><span class="n">m</span> <span class="n">n</span><span class="o">}</span> <span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="n">m</span> <span class="bp">≤</span> <span class="n">n</span><span class="o">)</span> <span class="o">:</span>
<span class="o">((</span><span class="n">n</span> <span class="bp">-</span> <span class="n">m</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span> <span class="bp">=</span> <span class="n">n</span> <span class="bp">-</span> <span class="n">m</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">coe_nat_bit0</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="bp">↑</span><span class="o">(</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#bit0">bit0</a></span> <span class="n">n</span><span class="o">)</span> <span class="o">:</span> <span class="n">ℤ</span><span class="o">)</span> <span class="bp">=</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#bit0">bit0</a></span> <span class="bp">↑</span><span class="n">n</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">cast_coe_nat</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="o">((</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℤ</span><span class="o">)</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span> <span class="bp">=</span> <span class="n">n</span>
<span class="kd">@[norm_cast]</span> <span class="kd">theorem</span> <span class="n">cast_one</span> <span class="o">:</span> <span class="o">((</span><span class="mi">1</span> <span class="o">:</span> <span class="n">ℚ</span><span class="o">)</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span> <span class="bp">=</span> <span class="mi">1</span>
</code></pre></div>
<p>Lemmas tagged with <code>@[norm_cast]</code> are classified into three categories: <code>move</code>, <code>elim</code>, and
<code>squash</code>. They are classified roughly as follows:</p>
<ul>
<li>elim lemma: LHS has 0 head coes and ≥ 1 internal coe</li>
<li>move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes</li>
<li>squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes</li>
</ul>
<p><code>norm_cast</code> uses <code>move</code> and <code>elim</code> lemmas to factor coercions toward the root of an expression
and to cancel them from both sides of an equation or relation. It uses <code>squash</code> lemmas to clean
up the result.</p>
<p>Occasionally you may want to override the automatic classification.
You can do this by giving an optional <code>elim</code>, <code>move</code>, or <code>squash</code> parameter to the attribute.</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp, norm_cast elim]</span> <span class="kd">lemma</span> <span class="n">nat_cast_re</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="n">n</span> <span class="o">:</span> <span class="n">ℂ</span><span class="o">)</span><span class="bp">.</span><span class="n">re</span> <span class="bp">=</span> <span class="n">n</span> <span class="o">:=</span>
<span class="kd">by</span> <span class="n">rw</span> <span class="o">[</span><span class="bp">←</span> <span class="n">of_real_nat_cast</span><span class="o">,</span> <span class="n">of_real_re</span><span class="o">]</span>
</code></pre></div>
<p>Don't do this unless you understand what you are doing.</p>
<p>A full description of the tactic, and the use of each lemma category, can be found at
<a href="https://lean-forward.github.io/norm_cast/norm_cast.pdf">https://lean-forward.github.io/norm_cast/norm_cast.pdf</a>.</p>
<div class="tags">Tags:
<ul>
<li>coercions</li>
<li>simplification</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/norm_cast.html#norm_cast.norm_cast_attr">norm_cast.norm_cast_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.norm_cast</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic arithmetic decision_procedure">
<h2 id="norm_num"><a href="#norm_num">norm_num</a></h2>
<p>An attribute for adding additional extensions to <code>norm_num</code>. To use this attribute, put
<code>@[norm_num]</code> on a tactic of type <code><a href="https://pygae.github.io/lean-ga-docs/init/meta/expr.html#expr">expr</a> → <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> (<a href="https://pygae.github.io/lean-ga-docs/init/meta/expr.html#expr">expr</a> × <a href="https://pygae.github.io/lean-ga-docs/init/meta/expr.html#expr">expr</a>)</code>; the tactic will be called on
subterms by <code>norm_num</code>, and it is responsible for identifying that the expression is a numerical
function applied to numerals, for example <code>nat.fib 17</code>, and should return the reduced numerical
expression (which must be in <code>norm_num</code>-normal form: a natural or rational numeral, i.e. <code>37</code>,
<code>12 / 7</code> or <code>-(2 / 3)</code>, although this can be an expression in any type), and the proof that the
original expression is equal to the rewritten expression.</p>
<p>Failure is used to indicate that this tactic does not apply to the term. For performance reasons,
it is best to detect non-applicability as soon as possible so that the next tactic can have a go,
so generally it will start with a pattern match and then checking that the arguments to the term
are numerals or of the appropriate form, followed by proof construction, which should not fail.</p>
<p>Propositions are treated like any other term. The normal form for propositions is <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></code> or
<code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#false">false</a></code>, so it should produce a proof of the form <code>p = <a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></code> or <code>p = <a href="https://pygae.github.io/lean-ga-docs/init/core.html#false">false</a></code>. <code><a href="https://pygae.github.io/lean-ga-docs/init/propext.html#eq_true_intro">eq_true_intro</a></code> can be
used to help here.</p>
<div class="tags">Tags:
<ul>
<li>arithmetic</li>
<li>decision_procedure</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/norm_num.html#norm_num.attr">norm_num.attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.norm_num</li>
<li>import tactic</li></ul></details>
</div>
<div class="tactic parsing environment structures">
<h2 id="protect_proj"><a href="#protect_proj">protect_proj</a></h2>
<p>Attribute to protect the projections of a structure.
If a structure <code>foo</code> is marked with the <code>protect_proj</code> user attribute, then
all of the projections become protected, meaning they must always be referred to by
their full name <code>foo.bar</code>, even when the <code>foo</code> namespace is open.</p>
<p><code>protect_proj without bar baz</code> will protect all projections except for <code>bar</code> and <code>baz</code>.</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[protect_proj without baz bar]</span> <span class="kd">structure</span> <span class="n">foo</span> <span class="o">:</span> <span class="kt">Type</span> <span class="o">:=</span>
<span class="o">(</span><span class="n">bar</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a></span><span class="o">)</span> <span class="o">(</span><span class="n">baz</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a></span><span class="o">)</span> <span class="o">(</span><span class="n">qux</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a></span><span class="o">)</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>parsing</li>
<li>environment</li>
<li>structures</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/protected.html#tactic.protect_proj_attr">tactic.protect_proj_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.protected</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic parsing environment">
<h2 id="protected"><a href="#protected">protected</a></h2>
<p>Attribute to protect a declaration.
If a declaration <code>foo.bar</code> is marked protected, then it must be referred to
by its full name <code>foo.bar</code>, even when the <code>foo</code> namespace is open.</p>
<p>Protectedness is a built in parser feature that is independent of this attribute.
A declaration may be protected even if it does not have the <code>@[protected]</code> attribute.
This provides a convenient way to protect many declarations at once.</p>
<div class="tags">Tags:
<ul>
<li>parsing</li>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/protected.html#tactic.protected_attr">tactic.protected_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.protected</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic category-theory">
<h2 id="reassoc"><a href="#reassoc">reassoc</a></h2>
<p>The <code>reassoc</code> attribute can be applied to a lemma</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[reassoc]</span>
<span class="kd">lemma</span> <span class="n">some_lemma</span> <span class="o">:</span> <span class="n">foo</span> <span class="bp">≫</span> <span class="n">bar</span> <span class="bp">=</span> <span class="n">baz</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>to produce</p>
<div class="codehilite"><pre><span></span><code><span class="kd">lemma</span> <span class="n">some_lemma_assoc</span> <span class="o">{</span><span class="n">Y</span> <span class="o">:</span> <span class="n">C</span><span class="o">}</span> <span class="o">(</span><span class="n">f</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">⟶</span> <span class="n">Y</span><span class="o">)</span> <span class="o">:</span> <span class="n">foo</span> <span class="bp">≫</span> <span class="n">bar</span> <span class="bp">≫</span> <span class="n">f</span> <span class="bp">=</span> <span class="n">baz</span> <span class="bp">≫</span> <span class="n">f</span> <span class="o">:=</span> <span class="bp">...</span>
</code></pre></div>
<p>The name of the produced lemma can be specified with <code>@[reassoc other_lemma_name]</code>. If
<code>simp</code> is added first, the generated lemma will also have the <code>simp</code> attribute.</p>
<div class="tags">Tags:
<ul>
<li>category theory</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/reassoc_axiom.html#tactic.reassoc_attr">tactic.reassoc_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.reassoc_axiom</li>
<li>import tactic</li></ul></details>
</div>
<div class="tactic simplification">
<h2 id="simps"><a href="#simps">simps</a></h2>
<p>The <code>@[simps]</code> attribute automatically derives lemmas specifying the projections of this
declaration.</p>
<p>Example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simps]</span> <span class="kd">def</span> <span class="n">foo</span> <span class="o">:</span> <span class="n">ℕ</span> <span class="bp">×</span> <span class="n">ℤ</span> <span class="o">:=</span> <span class="o">(</span><span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="o">)</span>
</code></pre></div>
<p>derives two <code>simp</code> lemmas:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_fst</span> <span class="o">:</span> <span class="n">foo.fst</span> <span class="bp">=</span> <span class="mi">1</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_snd</span> <span class="o">:</span> <span class="n">foo.snd</span> <span class="bp">=</span> <span class="mi">2</span>
</code></pre></div>
<ul>
<li>
<p>It does not derive <code>simp</code> lemmas for the prop-valued projections.</p>
</li>
<li>
<p>It will automatically reduce newly created beta-redexes, but will not unfold any definitions.</p>
</li>
<li>
<p>If the structure has a coercion to either sorts or functions, and this is defined to be one
of the projections, then this coercion will be used instead of the projection.</p>
</li>
<li>
<p>If the structure is a class that has an instance to a notation class, like <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_mul">has_mul</a></code>, then this
notation is used instead of the corresponding projection.</p>
</li>
<li>
<p>You can specify custom projections, by giving a declaration with name
<code>{structure_name}.simps.{projection_name}</code>. See <a id="noteref1" href="https://pygae.github.io/lean-ga-docs/notes.html#custom simps projection">Note [custom simps projection]</a>.</p>
<p>Example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">def</span> <span class="n">equiv.simps.inv_fun</span> <span class="o">(</span><span class="n">e</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">≃</span> <span class="n">β</span><span class="o">)</span> <span class="o">:</span> <span class="n">β</span> <span class="bp">→</span> <span class="n">α</span> <span class="o">:=</span> <span class="n">e.symm</span>
<span class="kd">@[simps]</span> <span class="kd">def</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv.trans">equiv.trans</a></span> <span class="o">(</span><span class="n">e₁</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">≃</span> <span class="n">β</span><span class="o">)</span> <span class="o">(</span><span class="n">e₂</span> <span class="o">:</span> <span class="n">β</span> <span class="bp">≃</span> <span class="n">γ</span><span class="o">)</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">≃</span> <span class="n">γ</span> <span class="o">:=</span>
<span class="o">⟨</span><span class="n">e₂</span> <span class="bp">∘</span> <span class="n">e₁</span><span class="o">,</span> <span class="n">e₁.symm</span> <span class="bp">∘</span> <span class="n">e₂.symm</span><span class="o">⟩</span>
</code></pre></div>
<p>generates</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">equiv.trans_to_fun</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="n">β</span> <span class="n">γ</span><span class="o">}</span> <span class="o">(</span><span class="n">e₁</span> <span class="n">e₂</span><span class="o">)</span> <span class="o">(</span><span class="n">a</span> <span class="o">:</span> <span class="n">α</span><span class="o">),</span> <span class="bp">⇑</span><span class="o">(</span><span class="n">e₁.trans</span> <span class="n">e₂</span><span class="o">)</span> <span class="n">a</span> <span class="bp">=</span> <span class="o">(</span><span class="bp">⇑</span><span class="n">e₂</span> <span class="bp">∘</span> <span class="bp">⇑</span><span class="n">e₁</span><span class="o">)</span> <span class="n">a</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">equiv.trans_inv_fun</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="n">β</span> <span class="n">γ</span><span class="o">}</span> <span class="o">(</span><span class="n">e₁</span> <span class="n">e₂</span><span class="o">)</span> <span class="o">(</span><span class="n">a</span> <span class="o">:</span> <span class="n">γ</span><span class="o">),</span>
<span class="bp">⇑</span><span class="o">((</span><span class="n">e₁.trans</span> <span class="n">e₂</span><span class="o">)</span><span class="bp">.</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/algebra/classes.html#symm">symm</a></span><span class="o">)</span> <span class="n">a</span> <span class="bp">=</span> <span class="o">(</span><span class="bp">⇑</span><span class="o">(</span><span class="n">e₁.symm</span><span class="o">)</span> <span class="bp">∘</span> <span class="bp">⇑</span><span class="o">(</span><span class="n">e₂.symm</span><span class="o">))</span> <span class="n">a</span>
</code></pre></div>
</li>
<li>
<p>You can specify custom projection names, by specifying the new projection names using
<code>initialize_simps_projections</code>.
Example: <code>initialize_simps_projections <a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a> (to_fun → apply, inv_fun → symm_apply)</code>.
See <code><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#initialize_simps_projections_cmd">initialize_simps_projections_cmd</a></code> for more information.</p>
</li>
<li>
<p>If one of the fields itself is a structure, this command will recursively create
<code>simp</code> lemmas for all fields in that structure.</p>
<ul>
<li>Exception: by default it will not recursively create <code>simp</code> lemmas for fields in the structures
<code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#prod">prod</a></code> and <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#pprod">pprod</a></code>. You can give explicit projection names or change the value of
<code><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#simps_cfg.not_recursive">simps_cfg.not_recursive</a></code> to override this behavior.</li>
</ul>
<p>Example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">structure</span> <span class="n">my_prod</span> <span class="o">(</span><span class="n">α</span> <span class="n">β</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">)</span> <span class="o">:=</span> <span class="o">(</span><span class="n">fst</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span> <span class="o">(</span><span class="n">snd</span> <span class="o">:</span> <span class="n">β</span><span class="o">)</span>
<span class="kd">@[simps]</span> <span class="kd">def</span> <span class="n">foo</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#prod">prod</a></span> <span class="n">ℕ</span> <span class="n">ℕ</span> <span class="bp">×</span> <span class="n">my_prod</span> <span class="n">ℕ</span> <span class="n">ℕ</span> <span class="o">:=</span> <span class="o">⟨⟨</span><span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="o">⟩,</span> <span class="mi">3</span><span class="o">,</span> <span class="mi">4</span><span class="o">⟩</span>
</code></pre></div>
<p>generates</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_fst</span> <span class="o">:</span> <span class="n">foo.fst</span> <span class="bp">=</span> <span class="o">(</span><span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="o">)</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_snd_fst</span> <span class="o">:</span> <span class="n">foo.snd.fst</span> <span class="bp">=</span> <span class="mi">3</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_snd_snd</span> <span class="o">:</span> <span class="n">foo.snd.snd</span> <span class="bp">=</span> <span class="mi">4</span>
</code></pre></div>
</li>
<li>
<p>You can use <code>@[simps proj1 proj2 ...]</code> to only generate the projection lemmas for the specified
projections.</p>
</li>
<li>
<p>Recursive projection names can be specified using <code>proj1_proj2_proj3</code>.
This will create a lemma of the form <code>foo.proj1.proj2.proj3 = ...</code>.</p>
<p>Example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">structure</span> <span class="n">my_prod</span> <span class="o">(</span><span class="n">α</span> <span class="n">β</span> <span class="o">:</span> <span class="kt">Type</span><span class="bp">*</span><span class="o">)</span> <span class="o">:=</span> <span class="o">(</span><span class="n">fst</span> <span class="o">:</span> <span class="n">α</span><span class="o">)</span> <span class="o">(</span><span class="n">snd</span> <span class="o">:</span> <span class="n">β</span><span class="o">)</span>
<span class="kd">@[simps fst fst_fst snd]</span> <span class="kd">def</span> <span class="n">foo</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#prod">prod</a></span> <span class="n">ℕ</span> <span class="n">ℕ</span> <span class="bp">×</span> <span class="n">my_prod</span> <span class="n">ℕ</span> <span class="n">ℕ</span> <span class="o">:=</span> <span class="o">⟨⟨</span><span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="o">⟩,</span> <span class="mi">3</span><span class="o">,</span> <span class="mi">4</span><span class="o">⟩</span>
</code></pre></div>
<p>generates</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_fst</span> <span class="o">:</span> <span class="n">foo.fst</span> <span class="bp">=</span> <span class="o">(</span><span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="o">)</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_fst_fst</span> <span class="o">:</span> <span class="n">foo.fst.fst</span> <span class="bp">=</span> <span class="mi">1</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">foo_snd</span> <span class="o">:</span> <span class="n">foo.snd</span> <span class="bp">=</span> <span class="o">{</span><span class="n">fst</span> <span class="o">:=</span> <span class="mi">3</span><span class="o">,</span> <span class="n">snd</span> <span class="o">:=</span> <span class="mi">4</span><span class="o">}</span>
</code></pre></div>
</li>
<li>
<p>If one of the values is an eta-expanded structure, we will eta-reduce this structure.</p>
<p>Example:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">structure</span> <span class="n">equiv_plus_data</span> <span class="o">(</span><span class="n">α</span> <span class="n">β</span><span class="o">)</span> <span class="kd">extends</span> <span class="n">α</span> <span class="bp">≃</span> <span class="n">β</span> <span class="o">:=</span> <span class="o">(</span><span class="n">data</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#bool">bool</a></span><span class="o">)</span>
<span class="kd">@[simps]</span> <span class="kd">def</span> <span class="n">bar</span> <span class="o">{</span><span class="n">α</span><span class="o">}</span> <span class="o">:</span> <span class="n">equiv_plus_data</span> <span class="n">α</span> <span class="n">α</span> <span class="o">:=</span> <span class="o">{</span> <span class="n">data</span> <span class="o">:=</span> <span class="n">tt</span><span class="o">,</span> <span class="bp">..</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv.refl">equiv.refl</a></span> <span class="n">α</span> <span class="o">}</span>
</code></pre></div>
<p>generates the following:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">bar_to_equiv</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Sort</span><span class="bp">*</span><span class="o">},</span> <span class="n">bar.to_equiv</span> <span class="bp">=</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv.refl">equiv.refl</a></span> <span class="n">α</span>
<span class="kd">@[simp]</span> <span class="kd">lemma</span> <span class="n">bar_data</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">α</span> <span class="o">:</span> <span class="kt">Sort</span><span class="bp">*</span><span class="o">},</span> <span class="n">bar.data</span> <span class="bp">=</span> <span class="n">tt</span>
</code></pre></div>
<p>This is true, even though Lean inserts an eta-expanded version of <code><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv.refl">equiv.refl</a> α</code> in the
definition of <code>bar</code>.</p>
</li>
<li>
<p>For configuration options, see the doc string of <code><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#simps_cfg">simps_cfg</a></code>.</p>
</li>
<li>
<p>The precise syntax is <code>('simps' ident* e)</code>, where <code>e</code> is an expression of type <code><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#simps_cfg">simps_cfg</a></code>.</p>
</li>
<li>
<p><code>@[simps]</code> reduces let-expressions where necessary.</p>
</li>
<li>
<p>When option <code>trace.simps.verbose</code> is true, <code>simps</code> will print the projections it finds and the
lemmas it generates. The same can be achieved by using <code>@[simps?]</code>, except that in this case it
will not print projection information.</p>
</li>
<li>
<p>Use <code>@[to_additive, simps]</code> to apply both <code>to_additive</code> and <code>simps</code> to a definition, making sure
that <code>simps</code> comes after <code>to_additive</code>. This will also generate the additive versions of all
<code>simp</code> lemmas.</p>
</li>
</ul>
<div class="tags">Tags:
<ul>
<li>simplification</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#simps_attr">simps_attr</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.simps</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic search">
<h2 id="tidy"><a href="#tidy">tidy</a></h2>
<p>Tag interactive tactics (locally) with <code>[tidy]</code> to add them to the list of default tactics
called by <code>tidy</code>.</p>
<div class="tags">Tags:
<ul>
<li>search</li>
</ul>
</div>