-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.html
6399 lines (5782 loc) · 334 KB
/
notes.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>notes - mathlib3 docs</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Various implementation details are noted in the mathlib source, and referenced later on. We collect these notes here." />
<link rel="canonical" href="https://leanprover-community.github.io/mathlib_docs/notes.html" />
<meta property="og:title" content="notes - mathlib3 docs">
<meta property="og:site_name" content="mathlib for Lean 3 - API documentation">
<meta property="og:description" content="Various implementation details are noted in the mathlib source, and referenced later on. We collect these notes here.">
<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">notes</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">Library notes</a></h3>
<div class="nav_link"><a href="#addition on function coercions">addition on function coercions</a></div>
<div class="nav_link"><a href="#bundled maps over different rings">bundled maps over different rings</a></div>
<div class="nav_link"><a href="#category_theory universes">category_theory universes</a></div>
<div class="nav_link"><a href="#coercion into rings">coercion into rings</a></div>
<div class="nav_link"><a href="#comp_of_eq lemmas">comp_of_eq lemmas</a></div>
<div class="nav_link"><a href="#continuity lemma statement">continuity lemma statement</a></div>
<div class="nav_link"><a href="#custom simps projection">custom simps projection</a></div>
<div class="nav_link"><a href="#decidable arguments">decidable arguments</a></div>
<div class="nav_link"><a href="#decidable namespace">decidable namespace</a></div>
<div class="nav_link"><a href="#dsimp, simp">dsimp, simp</a></div>
<div class="nav_link"><a href="#fact non-instances">fact non-instances</a></div>
<div class="nav_link"><a href="#forgetful inheritance">forgetful inheritance</a></div>
<div class="nav_link"><a href="#function coercion">function coercion</a></div>
<div class="nav_link"><a href="#implicit instance arguments">implicit instance arguments</a></div>
<div class="nav_link"><a href="#likely generated binder names">likely generated binder names</a></div>
<div class="nav_link"><a href="#lower instance priority">lower instance priority</a></div>
<div class="nav_link"><a href="#nolint_ge">nolint_ge</a></div>
<div class="nav_link"><a href="#open expressions">open expressions</a></div>
<div class="nav_link"><a href="#operator precedence of big operators">operator precedence of big operators</a></div>
<div class="nav_link"><a href="#out-param inheritance">out-param inheritance</a></div>
<div class="nav_link"><a href="#partially-applied ext lemmas">partially-applied ext lemmas</a></div>
<div class="nav_link"><a href="#pointwise nat action">pointwise nat action</a></div>
<div class="nav_link"><a href="#range copy pattern">range copy pattern</a></div>
<div class="nav_link"><a href="#simp-normal form">simp-normal form</a></div>
<div class="nav_link"><a href="#slow-failing instance priority">slow-failing instance priority</a></div>
<div class="nav_link"><a href="#use has_coe_t">use has_coe_t</a></div>
<div class="nav_link"><a href="#user attribute parameters">user attribute parameters</a></div>
</nav>
<main>
<a id="top"></a>
<div class="docfile">
<h1>Lean mathlib notes</h1>
<p>Various implementation details are noted in the mathlib source, and referenced later on.
We collect these notes here.</p>
<div class="note">
<h2 id="addition on function coercions"><a href="#addition on function coercions">addition on function coercions</a></h2>
<p>Terms containing <code>@has_add.add (has_coe_to_fun.F ...) <a href="https://pygae.github.io/lean-ga-docs/data/pi/algebra.html#pi.has_add">pi.has_add</a></code>
seem to cause leanchecker to <a href="https://github.com/leanprover-community/lean/issues/543">crash due to an out-of-memory
condition</a>.
As a workaround, we add a type annotation: <code>(f + g : V₁ → V₂)</code></p>
</div>
<div class="note">
<h2 id="bundled maps over different rings"><a href="#bundled maps over different rings">bundled maps over different rings</a></h2>
<p>Frequently, we find ourselves wanting to express a bilinear map <code>M →ₗ[R] N →ₗ[R] P</code> or an
equivalence between maps <code>(M →ₗ[R] N) ≃ₗ[R] (M' →ₗ[R] N')</code> where the maps have an associated ring
<code>R</code>. Unfortunately, using definitions like these requires that <code>R</code> satisfy <code><a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#comm_semiring">comm_semiring</a> R</code>, and
not just <code><a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> R</code>. Using <code>M →ₗ[R] N →+ P</code> and <code>(M →ₗ[R] N) ≃+ (M' →ₗ[R] N')</code> avoids this
problem, but throws away structure that is useful for when we <em>do</em> have a commutative (semi)ring.</p>
<p>To avoid making this compromise, we instead state these definitions as <code>M →ₗ[R] N →ₗ[S] P</code> or
<code>(M →ₗ[R] N) ≃ₗ[S] (M' →ₗ[R] N')</code> and require <code><a href="https://pygae.github.io/lean-ga-docs/group_theory/group_action/defs.html#smul_comm_class">smul_comm_class</a> S R</code> on the appropriate modules. When
the caller has <code><a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#comm_semiring">comm_semiring</a> R</code>, they can set <code>S = R</code> and <code><a href="https://pygae.github.io/lean-ga-docs/group_theory/group_action/defs.html#smul_comm_class_self">smul_comm_class_self</a></code> will populate the
instance. If the caller only has <code><a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> R</code> they can still set either <code>R = ℕ</code> or <code>S = ℕ</code>, and
<code>add_comm_monoid.nat_smul_comm_class</code> or <code>add_comm_monoid.nat_smul_comm_class'</code> will populate
the typeclass, which is still sufficient to recover a <code>≃+</code> or <code>→+</code> structure.</p>
<p>An example of where this is used is <code><a href="https://pygae.github.io/lean-ga-docs/linear_algebra/prod.html#linear_map.prod_equiv">linear_map.prod_equiv</a></code>.</p>
referenced by: <small>
<a href="linear_algebra/basic.html#noteref1" title="mathlib: linear_algebra.basic">[1]</a>
<a href="linear_algebra/pi.html#noteref1" title="mathlib: linear_algebra.pi">[2]</a>
<a href="linear_algebra/pi.html#noteref3" title="mathlib: linear_algebra.pi">[3]</a>
<a href="linear_algebra/finsupp.html#noteref1" title="mathlib: linear_algebra.finsupp">[4]</a>
<a href="linear_algebra/finsupp.html#noteref2" title="mathlib: linear_algebra.finsupp">[5]</a>
<a href="linear_algebra/affine_space/affine_map.html#noteref1" title="mathlib: linear_algebra.affine_space.affine_map">[6]</a>
<a href="linear_algebra/prod.html#noteref1" title="mathlib: linear_algebra.prod">[7]</a>
<a href="linear_algebra/prod.html#noteref2" title="mathlib: linear_algebra.prod">[8]</a>
<a href="linear_algebra/basis.html#noteref1" title="mathlib: linear_algebra.basis">[9]</a>
<a href="linear_algebra/dfinsupp.html#noteref2" title="mathlib: linear_algebra.dfinsupp">[10]</a>
<a href="linear_algebra/free_module/basic.html#noteref1" title="mathlib: linear_algebra.free_module.basic">[11]</a>
</small>
</div>
<div class="note">
<h2 id="category_theory universes"><a href="#category_theory universes">category_theory universes</a></h2>
<p>The typeclass <code>category C</code> describes morphisms associated to objects of type <code>C : Type u</code>.</p>
<p>The universe levels of the objects and morphisms are independent, and will often need to be
specified explicitly, as <code>category.{v} C</code>.</p>
<p>Typically any concrete example will either be a <code>small_category</code>, where <code>v = u</code>,
which can be introduced as</p>
<div class="codehilite"><pre><span></span><code><span class="kd">universes</span> <span class="n">u</span>
<span class="kd">variables</span> <span class="o">{</span><span class="n">C</span> <span class="o">:</span> <span class="kt">Type</span> <span class="n">u</span><span class="o">}</span> <span class="o">[</span><span class="n">small_category</span> <span class="n">C</span><span class="o">]</span>
</code></pre></div>
<p>or a <code>large_category</code>, where <code>u = v+1</code>, which can be introduced as</p>
<div class="codehilite"><pre><span></span><code><span class="kd">universes</span> <span class="n">u</span>
<span class="kd">variables</span> <span class="o">{</span><span class="n">C</span> <span class="o">:</span> <span class="kt">Type</span> <span class="o">(</span><span class="n">u</span><span class="bp">+</span><span class="mi">1</span><span class="o">)}</span> <span class="o">[</span><span class="n">large_category</span> <span class="n">C</span><span class="o">]</span>
</code></pre></div>
<p>In order for the library to handle these cases uniformly,
we generally work with the unconstrained <code>category.{v u}</code>,
for which objects live in <code>Type u</code> and morphisms live in <code>Type v</code>.</p>
<p>Because the universe parameter <code>u</code> for the objects can be inferred from <code>C</code>
when we write <code>category C</code>, while the universe parameter <code>v</code> for the morphisms
can not be automatically inferred, through the category theory library
we introduce universe parameters with morphism levels listed first,
as in</p>
<div class="codehilite"><pre><span></span><code><span class="kd">universes</span> <span class="n">v</span> <span class="n">u</span>
</code></pre></div>
<p>or</p>
<div class="codehilite"><pre><span></span><code><span class="kd">universes</span> <span class="n">v₁</span> <span class="n">v₂</span> <span class="n">u₁</span> <span class="n">u₂</span>
</code></pre></div>
<p>when multiple independent universes are needed.</p>
<p>This has the effect that we can simply write <code>category.{v} C</code>
(that is, only specifying a single parameter) while <code>u</code> will be inferred.</p>
<p>Often, however, it's not even necessary to include the <code>.{v}</code>.
(Although it was in earlier versions of Lean.)
If it is omitted a "free" universe will be used.</p>
</div>
<div class="note">
<h2 id="coercion into rings"><a href="#coercion into rings">coercion into rings</a></h2>
<p>Coercions such as <code><a href="https://pygae.github.io/lean-ga-docs/data/nat/cast/defs.html#nat.cast_coe">nat.cast_coe</a></code> that go from a concrete structure such as
<code>ℕ</code> to an arbitrary ring <code>R</code> should be set up as follows:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[priority 900]</span> <span class="kd">instance</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a></span> <span class="n">ℕ</span> <span class="n">R</span> <span class="o">:=</span> <span class="o">⟨</span><span class="bp">...</span><span class="o">⟩</span>
</code></pre></div>
<p>It needs to be <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a></code> instead of <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe">has_coe</a></code> because otherwise type-class
inference would loop when constructing the transitive coercion <code>ℕ → ℕ → ℕ → ...</code>.
The reduced priority is necessary so that it doesn't conflict with instances
such as <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a> R (<a href="https://pygae.github.io/lean-ga-docs/init/core.html#option">option</a> R)</code>.</p>
<p>For this to work, we reduce the priority of the <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_base">coe_base</a></code> and <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_trans">coe_trans</a></code>
instances because we want the instances for <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a></code> to be tried in the
following order:</p>
<ol>
<li><code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a></code> instances declared in mathlib (such as <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a> R (<a href="https://pygae.github.io/lean-ga-docs/order/with_bot.html#with_top">with_top</a> R)</code>, etc.)</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_base">coe_base</a></code>, which contains instances such as <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe">has_coe</a> (<a href="https://pygae.github.io/lean-ga-docs/init/data/fin/basic.html#fin">fin</a> n) n</code></li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/data/nat/cast/defs.html#nat.cast_coe">nat.cast_coe</a> : <a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_t">has_coe_t</a> ℕ R</code> etc.</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_trans">coe_trans</a></code></li>
</ol>
<p>If <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_trans">coe_trans</a></code> is tried first, then <code><a href="https://pygae.github.io/lean-ga-docs/data/nat/cast/defs.html#nat.cast_coe">nat.cast_coe</a></code> doesn't get a chance to apply.</p>
referenced by: <small>
<a href="data/is_R_or_C/basic.html#noteref1" title="mathlib: data.is_R_or_C.basic">[1]</a>
</small>
</div>
<div class="note">
<h2 id="comp_of_eq lemmas"><a href="#comp_of_eq lemmas">comp_of_eq lemmas</a></h2>
<p>Lean's elaborator has trouble elaborating applications of lemmas that state that the composition of
two functions satisfy some property at a point, like <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at.comp">continuous_at.comp</a></code> / <code>cont_diff_at.comp</code> and
<code>cont_mdiff_within_at.comp</code>. The reason is that a lemma like this looks like
<code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> g (f x) → <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> f x → <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> (g ∘ f) x</code>.
Since Lean's elaborator elaborates the arguments from left-to-right, when you write <code>hg.comp hf</code>,
the elaborator will try to figure out <em>both</em> <code>f</code> and <code>g</code> from the type of <code>hg</code>. It tries to figure
out <code>f</code> just from the point where <code>g</code> is continuous. For example, if <code>hg : <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> g (a, x)</code>
then the elaborator will assign <code>f</code> to the function <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#prod.mk">prod.mk</a> a</code>, since in that case <code>f x = (a, x)</code>.
This is undesirable in most cases where <code>f</code> is not a variable. There are some ways to work around
this, for example by giving <code>f</code> explicitly, or to force Lean to elaborate <code>hf</code> before elaborating
<code>hg</code>, but this is annoying.
Another better solution is to reformulate composition lemmas to have the following shape
<code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> g y → <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> f x → f x = y → <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a> (g ∘ f) x</code>.
This is even useful if the proof of <code>f x = y</code> is <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#rfl">rfl</a></code>.
The reason that this works better is because the type of <code>hg</code> doesn't mention <code>f</code>.
Only after elaborating the two <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a></code> arguments, Lean will try to unify <code>f x</code> with <code>y</code>,
which is often easy after having chosen the correct functions for <code>f</code> and <code>g</code>.
Here is an example that shows the difference:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">example</span> <span class="o">{</span><span class="n">x₀</span> <span class="o">:</span> <span class="n">α</span><span class="o">}</span> <span class="o">(</span><span class="n">f</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">→</span> <span class="n">α</span> <span class="bp">→</span> <span class="n">β</span><span class="o">)</span> <span class="o">(</span><span class="n">hf</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a></span> <span class="o">(</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/function.html#function.uncurry">function.uncurry</a></span> <span class="n">f</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"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span> <span class="bp">=></span> <span class="n">f</span> <span class="n">x</span> <span class="n">x</span><span class="o">)</span> <span class="n">x₀</span> <span class="o">:=</span>
<span class="c1">-- hf.comp x (continuous_at_id.prod continuous_at_id) -- type mismatch</span>
<span class="c1">-- hf.comp_of_eq (continuous_at_id.prod continuous_at_id) rfl -- works</span>
</code></pre></div>
referenced by: <small>
<a href="topology/basic.html#noteref1" title="mathlib: topology.basic">[1]</a>
</small>
</div>
<div class="note">
<h2 id="continuity lemma statement"><a href="#continuity lemma statement">continuity lemma statement</a></h2>
<p>The library contains many lemmas stating that functions/operations are continuous. There are many
ways to formulate the continuity of operations. Some are more convenient than others.
Note: for the most part this note also applies to other properties
(<code>measurable</code>, <code>differentiable</code>, <code><a href="https://pygae.github.io/lean-ga-docs/topology/continuous_on.html#continuous_on">continuous_on</a></code>, ...).</p>
<h3 id="the-traditional-way" class="markdown-heading">The traditional way <a class="hover-link" href="#the-traditional-way">#</a></h3>
<p>As an example, let's look at addition <code>(+) : M → M → M</code>. We can state that this is continuous
in different definitionally equal ways (omitting some typing information)</p>
<ul>
<li><code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a> (λ p, p.1 + p.2)</code>;</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a> (<a href="https://pygae.github.io/lean-ga-docs/init/function.html#function.uncurry">function.uncurry</a> (+))</code>;</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a> ↿(+)</code>. (<code>↿</code> is notation for recursively uncurrying a function)</li>
</ul>
<p>However, lemmas with this conclusion are not nice to use in practice because</p>
<ol>
<li>They confuse the elaborator. The following two examples fail, because of limitations in the
elaboration process.</li>
</ol>
<div class="codehilite"><pre><span></span><code><span class="kd">variables</span> <span class="o">{</span><span class="n">M</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"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_add">has_add</a></span> <span class="n">M</span><span class="o">]</span> <span class="o">[</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></span> <span class="n">M</span><span class="o">]</span> <span class="o">[</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/monoid.html#has_continuous_add">has_continuous_add</a></span> <span class="n">M</span><span class="o">]</span>
<span class="kd">example</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span> <span class="o">:</span> <span class="n">M</span><span class="o">,</span> <span class="n">x</span> <span class="bp">+</span> <span class="n">x</span><span class="o">)</span> <span class="o">:=</span>
<span class="n">continuous_add.comp</span> <span class="n">_</span>
<span class="kd">example</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span> <span class="o">:</span> <span class="n">M</span><span class="o">,</span> <span class="n">x</span> <span class="bp">+</span> <span class="n">x</span><span class="o">)</span> <span class="o">:=</span>
<span class="n">continuous_add.comp</span> <span class="o">(</span><span class="n">continuous_id.prod_mk</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_id">continuous_id</a></span><span class="o">)</span>
</code></pre></div>
<p>The second is a valid proof, which is accepted if you write it as
<code>continuous_add.comp (continuous_id.prod_mk <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_id">continuous_id</a> : _)</code></p>
<ol start="2">
<li>If the operation has more than 2 arguments, they are impractical to use, because in your
application the arguments in the domain might be in a different order or associated differently.</li>
</ol>
<h3 id="the-convenient-way" class="markdown-heading">The convenient way <a class="hover-link" href="#the-convenient-way">#</a></h3>
<p>A much more convenient way to write continuity lemmas is like <code><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/monoid.html#continuous.add">continuous.add</a></code>:</p>
<div class="codehilite"><pre><span></span><code><span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/monoid.html#continuous.add">continuous.add</a></span> <span class="o">{</span><span class="n">f</span> <span class="n">g</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">→</span> <span class="n">M</span><span class="o">}</span> <span class="o">(</span><span class="n">hf</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">f</span><span class="o">)</span> <span class="o">(</span><span class="n">hg</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">g</span><span class="o">)</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span><span class="o">,</span> <span class="n">f</span> <span class="n">x</span> <span class="bp">+</span> <span class="n">g</span> <span class="n">x</span><span class="o">)</span>
</code></pre></div>
<p>The conclusion can be <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a> (f + g)</code>, which is definitionally equal.
This has the following advantages</p>
<ul>
<li>It supports projection notation, so is shorter to write.</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/monoid.html#continuous.add">continuous.add</a> _ _</code> is recognized correctly by the elaborator and gives useful new goals.</li>
<li>It works generally, since the domain is a variable.</li>
</ul>
<p>As an example for an unary operation, we have <code><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/group/basic.html#continuous.neg">continuous.neg</a></code>.</p>
<div class="codehilite"><pre><span></span><code><span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/group/basic.html#continuous.neg">continuous.neg</a></span> <span class="o">{</span><span class="n">f</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">→</span> <span class="n">G</span><span class="o">}</span> <span class="o">(</span><span class="n">hf</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">f</span><span class="o">)</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span><span class="o">,</span> <span class="bp">-</span><span class="n">f</span> <span class="n">x</span><span class="o">)</span>
</code></pre></div>
<p>For unary functions, the elaborator is not confused when applying the traditional lemma
(like <code>continuous_neg</code>), but it's still convenient to have the short version available (compare
<code>hf.neg.neg.neg</code> with <code>continuous_neg.comp $ continuous_neg.comp $ continuous_neg.comp hf</code>).</p>
<p>As a harder example, consider an operation of the following type:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">def</span> <span class="n">strans</span> <span class="o">{</span><span class="n">x</span> <span class="o">:</span> <span class="n">F</span><span class="o">}</span> <span class="o">(</span><span class="n">γ</span> <span class="n">γ'</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/path_connected.html#path">path</a></span> <span class="n">x</span> <span class="n">x</span><span class="o">)</span> <span class="o">(</span><span class="n">t₀</span> <span class="o">:</span> <span class="n">I</span><span class="o">)</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/path_connected.html#path">path</a></span> <span class="n">x</span> <span class="n">x</span>
</code></pre></div>
<p>The precise definition is not important, only its type.
The correct continuity principle for this operation is something like this:</p>
<div class="codehilite"><pre><span></span><code><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">F</span><span class="o">}</span> <span class="o">{</span><span class="n">γ</span> <span class="n">γ'</span> <span class="o">:</span> <span class="bp">∀</span> <span class="n">x</span><span class="o">,</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/path_connected.html#path">path</a></span> <span class="o">(</span><span class="n">f</span> <span class="n">x</span><span class="o">)</span> <span class="o">(</span><span class="n">f</span> <span class="n">x</span><span class="o">)}</span> <span class="o">{</span><span class="n">t₀</span> <span class="n">s</span> <span class="o">:</span> <span class="n">X</span> <span class="bp">→</span> <span class="n">I</span><span class="o">}</span>
<span class="o">(</span><span class="n">hγ</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="bp">↿</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"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="bp">↿</span><span class="n">γ'</span><span class="o">)</span>
<span class="o">(</span><span class="n">ht</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">t₀</span><span class="o">)</span> <span class="o">(</span><span class="n">hs</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">s</span><span class="o">)</span> <span class="o">:</span>
<span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span><span class="o">,</span> <span class="n">strans</span> <span class="o">(</span><span class="n">γ</span> <span class="n">x</span><span class="o">)</span> <span class="o">(</span><span class="n">γ'</span> <span class="n">x</span><span class="o">)</span> <span class="o">(</span><span class="n">t</span> <span class="n">x</span><span class="o">)</span> <span class="o">(</span><span class="n">s</span> <span class="n">x</span><span class="o">))</span>
</code></pre></div>
<p>Note that <em>all</em> arguments of <code>strans</code> are indexed over <code>X</code>, even the basepoint <code>x</code>, and the last
argument <code>s</code> that arises since <code><a href="https://pygae.github.io/lean-ga-docs/topology/path_connected.html#path">path</a> x x</code> has a coercion to <code>I → F</code>. The paths <code>γ</code> and <code>γ'</code> (which
are unary functions from <code>I</code>) become binary functions in the continuity lemma.</p>
<h3 id="summary" class="markdown-heading">Summary <a class="hover-link" href="#summary">#</a></h3>
<ul>
<li>Make sure that your continuity lemmas are stated in the most general way, and in a convenient
form. That means that:
<ul>
<li>The conclusion has a variable <code>X</code> as domain (not something like <code>Y × Z</code>);</li>
<li>Wherever possible, all point arguments <code>c : Y</code> are replaced by functions <code>c : X → Y</code>;</li>
<li>All <code>n</code>-ary function arguments are replaced by <code>n+1</code>-ary functions
(<code>f : Y → Z</code> becomes <code>f : X → Y → Z</code>);</li>
<li>All (relevant) arguments have continuity assumptions, and perhaps there are additional
assumptions needed to make the operation continuous;</li>
<li>The function in the conclusion is fully applied.</li>
</ul>
</li>
<li>These remarks are mostly about the format of the <em>conclusion</em> of a continuity lemma.
In assumptions it's fine to state that a function with more than 1 argument is continuous using
<code>↿</code> or <code><a href="https://pygae.github.io/lean-ga-docs/init/function.html#function.uncurry">function.uncurry</a></code>.</li>
</ul>
<h3 id="functions-with-discontinuities" class="markdown-heading">Functions with discontinuities <a class="hover-link" href="#functions-with-discontinuities">#</a></h3>
<p>In some cases, you want to work with discontinuous functions, and in certain expressions they are
still continuous. For example, consider the fractional part of a number, <code>fract : ℝ → ℝ</code>.
In this case, you want to add conditions to when a function involving <code>fract</code> is continuous, so you
get something like this: (assumption <code>hf</code> could be weakened, but the important thing is the shape
of the conclusion)</p>
<div class="codehilite"><pre><span></span><code><span class="kd">lemma</span> <span class="n">continuous_on.comp_fract</span> <span class="o">{</span><span class="n">X</span> <span class="n">Y</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"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></span> <span class="n">X</span><span class="o">]</span> <span class="o">[</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></span> <span class="n">Y</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">ℝ</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">X</span> <span class="bp">→</span> <span class="n">ℝ</span><span class="o">}</span> <span class="o">(</span><span class="n">hf</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="bp">↿</span><span class="n">f</span><span class="o">)</span> <span class="o">(</span><span class="n">hg</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="n">g</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">s</span><span class="o">,</span> <span class="n">f</span> <span class="n">s</span> <span class="mi">0</span> <span class="bp">=</span> <span class="n">f</span> <span class="n">s</span> <span class="mi">1</span><span class="o">)</span> <span class="o">:</span>
<span class="n"><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous">continuous</a></span> <span class="o">(</span><span class="bp">λ</span> <span class="n">x</span><span class="o">,</span> <span class="n">f</span> <span class="n">x</span> <span class="o">(</span><span class="n">fract</span> <span class="o">(</span><span class="n">g</span> <span class="n">x</span><span class="o">)))</span>
</code></pre></div>
<p>With <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#continuous_at">continuous_at</a></code> you can be even more precise about what to prove in case of discontinuities,
see e.g. <code><a href="https://pygae.github.io/lean-ga-docs/topology/algebra/group_with_zero.html#continuous_at.comp_div_cases">continuous_at.comp_div_cases</a></code>.</p>
referenced by: <small>
<a href="topology/path_connected.html#noteref2" title="mathlib: topology.path_connected">[1]</a>
<a href="topology/algebra/order/proj_Icc.html#noteref1" title="mathlib: topology.algebra.order.proj_Icc">[2]</a>
</small>
</div>
<div class="note">
<h2 id="custom simps projection"><a href="#custom simps projection">custom simps projection</a></h2>
<p>You can specify custom projections for the <code>@[simps]</code> attribute.
To do this for the projection <code>my_structure.original_projection</code> by adding a declaration
<code>my_structure.simps.my_projection</code> that is definitionally equal to
<code>my_structure.original_projection</code> but has the projection in the desired (simp-normal) form.
Then you can call</p>
<div class="codehilite"><pre><span></span><code><span class="n">initialize_simps_projections</span> <span class="o">(</span><span class="n">original_projection</span> <span class="bp">→</span> <span class="n">my_projection</span><span class="o">,</span> <span class="bp">...</span><span class="o">)</span>
</code></pre></div>
<p>to register this projection. 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>
<p>You can also specify custom projections that are definitionally equal to a composite of multiple
projections. This is often desirable when extending structures (without <code>old_structure_cmd</code>).</p>
<p><code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> and notation class (like <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_mul">has_mul</a></code>) instances will be automatically used, if they
are definitionally equal to a projection of the structure (but not when they are equal to the
composite of multiple projections).</p>
referenced by: <small>
<a href="commands.html#noteref1" title="docs: commands">[1]</a>
<a href="attributes.html#noteref1" title="docs: attributes">[2]</a>
<a href="algebra/group/units.html#noteref1" title="mathlib: algebra.group.units">[3]</a>
<a href="algebra/group/units.html#noteref2" title="mathlib: algebra.group.units">[4]</a>
<a href="algebra/group/units.html#noteref3" title="mathlib: algebra.group.units">[5]</a>
<a href="algebra/group/units.html#noteref4" title="mathlib: algebra.group.units">[6]</a>
<a href="logic/equiv/defs.html#noteref1" title="mathlib: logic.equiv.defs">[7]</a>
<a href="algebra/hom/equiv/basic.html#noteref1" title="mathlib: algebra.hom.equiv.basic">[8]</a>
<a href="linear_algebra/affine_space/affine_equiv.html#noteref1" title="mathlib: linear_algebra.affine_space.affine_equiv">[9]</a>
<a href="linear_algebra/affine_space/affine_equiv.html#noteref2" title="mathlib: linear_algebra.affine_space.affine_equiv">[10]</a>
<a href="topology/local_homeomorph.html#noteref1" title="mathlib: topology.local_homeomorph">[11]</a>
<a href="topology/local_homeomorph.html#noteref2" title="mathlib: topology.local_homeomorph">[12]</a>
<a href="topology/algebra/module/basic.html#noteref1" title="mathlib: topology.algebra.module.basic">[13]</a>
<a href="topology/algebra/module/basic.html#noteref2" title="mathlib: topology.algebra.module.basic">[14]</a>
<a href="topology/algebra/module/basic.html#noteref3" title="mathlib: topology.algebra.module.basic">[15]</a>
<a href="topology/algebra/module/basic.html#noteref4" title="mathlib: topology.algebra.module.basic">[16]</a>
<a href="algebra/ring/equiv.html#noteref1" title="mathlib: algebra.ring.equiv">[17]</a>
<a href="group_theory/subgroup/basic.html#noteref1" title="mathlib: group_theory.subgroup.basic">[18]</a>
<a href="group_theory/subgroup/basic.html#noteref2" title="mathlib: group_theory.subgroup.basic">[19]</a>
<a href="topology/homeomorph.html#noteref1" title="mathlib: topology.homeomorph">[20]</a>
<a href="topology/homeomorph.html#noteref2" title="mathlib: topology.homeomorph">[21]</a>
<a href="algebra/module/equiv.html#noteref1" title="mathlib: algebra.module.equiv">[22]</a>
<a href="group_theory/submonoid/basic.html#noteref1" title="mathlib: group_theory.submonoid.basic">[23]</a>
<a href="group_theory/submonoid/basic.html#noteref2" title="mathlib: group_theory.submonoid.basic">[24]</a>
<a href="algebra/algebra/equiv.html#noteref1" title="mathlib: algebra.algebra.equiv">[25]</a>
<a href="analysis/normed_space/linear_isometry.html#noteref1" title="mathlib: analysis.normed_space.linear_isometry">[26]</a>
<a href="analysis/normed_space/linear_isometry.html#noteref2" title="mathlib: analysis.normed_space.linear_isometry">[27]</a>
<a href="analysis/normed_space/linear_isometry.html#noteref3" title="mathlib: analysis.normed_space.linear_isometry">[28]</a>
<a href="logic/equiv/local_equiv.html#noteref1" title="mathlib: logic.equiv.local_equiv">[29]</a>
<a href="for_mathlib/linear_algebra/quadratic_form/isometric_map.html#noteref1" title="lean-ga: for_mathlib.linear_algebra.quadratic_form.isometric_map">[30]</a>
<a href="topology/sets/opens.html#noteref1" title="mathlib: topology.sets.opens">[31]</a>
<a href="topology/metric_space/isometry.html#noteref1" title="mathlib: topology.metric_space.isometry">[32]</a>
<a href="topology/metric_space/isometry.html#noteref2" title="mathlib: topology.metric_space.isometry">[33]</a>
<a href="order/closure.html#noteref1" title="mathlib: order.closure">[34]</a>
<a href="order/closure.html#noteref2" title="mathlib: order.closure">[35]</a>
<a href="algebra/order/absolute_value.html#noteref1" title="mathlib: algebra.order.absolute_value">[36]</a>
<a href="topology/path_connected.html#noteref1" title="mathlib: topology.path_connected">[37]</a>
<a href="topology/uniform_space/equiv.html#noteref1" title="mathlib: topology.uniform_space.equiv">[38]</a>
<a href="topology/uniform_space/equiv.html#noteref2" title="mathlib: topology.uniform_space.equiv">[39]</a>
<a href="group_theory/subsemigroup/basic.html#noteref1" title="mathlib: group_theory.subsemigroup.basic">[40]</a>
<a href="group_theory/subsemigroup/basic.html#noteref2" title="mathlib: group_theory.subsemigroup.basic">[41]</a>
<a href="algebra/star/star_alg_hom.html#noteref1" title="mathlib: algebra.star.star_alg_hom">[42]</a>
<a href="algebra/module/linear_map.html#noteref1" title="mathlib: algebra.module.linear_map">[43]</a>
<a href="topology/algebra/module/multilinear.html#noteref1" title="mathlib: topology.algebra.module.multilinear">[44]</a>
<a href="order/rel_iso/basic.html#noteref1" title="mathlib: order.rel_iso.basic">[45]</a>
<a href="order/rel_iso/basic.html#noteref2" title="mathlib: order.rel_iso.basic">[46]</a>
<a href="order/rel_iso/basic.html#noteref3" title="mathlib: order.rel_iso.basic">[47]</a>
<a href="order/omega_complete_partial_order.html#noteref1" title="mathlib: order.omega_complete_partial_order">[48]</a>
<a href="data/subtype.html#noteref1" title="mathlib: data.subtype">[49]</a>
<a href="tactic/simps.html#noteref1" title="mathlib: tactic.simps">[50]</a>
<a href="tactic/simps.html#noteref2" title="mathlib: tactic.simps">[51]</a>
<a href="tactic/simps.html#noteref3" title="mathlib: tactic.simps">[52]</a>
<a href="tactic/simps.html#noteref5" title="mathlib: tactic.simps">[53]</a>
<a href="tactic/simps.html#noteref6" title="mathlib: tactic.simps">[54]</a>
</small>
</div>
<div class="note">
<h2 id="decidable arguments"><a href="#decidable arguments">decidable arguments</a></h2>
<p>As mathlib is primarily classical,
if the type signature of a <code>def</code> or <code>lemma</code> does not require any <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> instances to state,
it is preferable not to introduce any <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> instances that are needed in the proof
as arguments, but rather to use the <code>classical</code> tactic as needed.</p>
<p>In the other direction, when <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> instances do appear in the type signature,
it is better to use explicitly introduced ones rather than allowing Lean to automatically infer
classical ones, as these may cause instance mismatch errors later.</p>
</div>
<div class="note">
<h2 id="decidable namespace"><a href="#decidable namespace">decidable namespace</a></h2>
<p>In most of mathlib, we use the law of excluded middle (LEM) and the axiom of choice (AC) freely.
The <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> namespace contains versions of lemmas from the root namespace that explicitly
attempt to avoid the axiom of choice, usually by adding decidability assumptions on the inputs.</p>
<p>You can check if a lemma uses the axiom of choice by using <code>#print axioms foo</code> and seeing if
<code><a href="https://pygae.github.io/lean-ga-docs/init/classical.html#classical.choice">classical.choice</a></code> appears in the list.</p>
</div>
<div class="note">
<h2 id="dsimp, simp"><a href="#dsimp, simp">dsimp, simp</a></h2>
<p>Many proofs in the category theory library use the <code>dsimp, simp</code> pattern,
which typically isn't necessary elsewhere.</p>
<p>One would usually hope that the same effect could be achieved simply with <code>simp</code>.</p>
<p>The essential issue is that composition of morphisms involves dependent types.
When you have a chain of morphisms being composed, say <code>f : X ⟶ Y</code> and <code>g : Y ⟶ Z</code>,
then <code>simp</code> can operate succesfully on the morphisms
(e.g. if <code>f</code> is the identity it can strip that off).</p>
<p>However if we have an equality of objects, say <code>Y = Y'</code>,
then <code>simp</code> can't operate because it would break the typing of the composition operations.
We rarely have interesting equalities of objects
(because that would be "evil" --- anything interesting should be expressed as an isomorphism
and tracked explicitly),
except of course that we have plenty of definitional equalities of objects.</p>
<p><code>dsimp</code> can apply these safely, even inside a composition.</p>
<p>After <code>dsimp</code> has cleared up the object level, <code>simp</code> can resume work on the morphism level ---
but without the <code>dsimp</code> step, because <code>simp</code> looks at expressions syntactically,
the relevant lemmas might not fire.</p>
<p>There's no bound on how many times you potentially could have to switch back and forth,
if the <code>simp</code> introduced new objects we again need to <code>dsimp</code>.
In practice this does occur, but only rarely, because <code>simp</code> tends to shorten chains of compositions
(i.e. not introduce new objects at all).</p>
referenced by: <small>
<a href="tactic/simps.html#noteref4" title="mathlib: tactic.simps">[1]</a>
</small>
</div>
<div class="note">
<h2 id="fact non-instances"><a href="#fact non-instances">fact non-instances</a></h2>
<p>In most cases, we should not have global instances of <code><a href="https://pygae.github.io/lean-ga-docs/logic/basic.html#fact">fact</a></code>; typeclass search only reads the head
symbol and then tries any instances, which means that adding any such instance will cause slowdowns
everywhere. We instead make them as lemmata and make them local instances as required.</p>
</div>
<div class="note">
<h2 id="forgetful inheritance"><a href="#forgetful inheritance">forgetful inheritance</a></h2>
<p>Suppose that one can put two mathematical structures on a type, a rich one <code>R</code> and a poor one
<code>P</code>, and that one can deduce the poor structure from the rich structure through a map <code>F</code> (called a
forgetful functor) (think <code>R = <a href="https://pygae.github.io/lean-ga-docs/topology/metric_space/basic.html#metric_space">metric_space</a></code> and <code>P = <a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></code>). A possible
implementation would be to have a type class <code>rich</code> containing a field <code>R</code>, a type class <code>poor</code>
containing a field <code>P</code>, and an instance from <code>rich</code> to <code>poor</code>. However, this creates diamond
problems, and a better approach is to let <code>rich</code> extend <code>poor</code> and have a field saying that
<code>F R = P</code>.</p>
<p>To illustrate this, consider the pair <code><a href="https://pygae.github.io/lean-ga-docs/topology/metric_space/basic.html#metric_space">metric_space</a></code> / <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></code>. Consider the topology
on a product of two metric spaces. With the first approach, it could be obtained by going first from
each metric space to its topology, and then taking the product topology. But it could also be
obtained by considering the product metric space (with its sup distance) and then the topology
coming from this distance. These would be the same topology, but not definitionally, which means
that from the point of view of Lean's kernel, there would be two different <code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></code>
instances on the product. This is not compatible with the way instances are designed and used:
there should be at most one instance of a kind on each type. This approach has created an instance
diamond that does not commute definitionally.</p>
<p>The second approach solves this issue. Now, a metric space contains both a distance, a topology, and
a proof that the topology coincides with the one coming from the distance. When one defines the
product of two metric spaces, one uses the sup distance and the product topology, and one has to
give the proof that the sup distance induces the product topology. Following both sides of the
instance diamond then gives rise (definitionally) to the product topology on the product space.</p>
<p>Another approach would be to have the rich type class take the poor type class as an instance
parameter. It would solve the diamond problem, but it would lead to a blow up of the number
of type classes one would need to declare to work with complicated classes, say a real inner
product space, and would create exponential complexity when working with products of
such complicated spaces, that are avoided by bundling things carefully as above.</p>
<p>Note that this description of this specific case of the product of metric spaces is oversimplified
compared to mathlib, as there is an intermediate typeclass between <code><a href="https://pygae.github.io/lean-ga-docs/topology/metric_space/basic.html#metric_space">metric_space</a></code> and
<code><a href="https://pygae.github.io/lean-ga-docs/topology/basic.html#topological_space">topological_space</a></code> called <code><a href="https://pygae.github.io/lean-ga-docs/topology/uniform_space/basic.html#uniform_space">uniform_space</a></code>. The above scheme is used at both levels, embedding a
topology in the uniform space structure, and a uniform structure in the metric space structure.</p>
<p>Note also that, when <code>P</code> is a proposition, there is no such issue as any two proofs of <code>P</code> are
definitionally equivalent in Lean.</p>
<p>To avoid boilerplate, there are some designs that can automatically fill the poor fields when
creating a rich structure if one doesn't want to do something special about them. For instance,
in the definition of metric spaces, default tactics fill the uniform space fields if they are
not given explicitly. One can also have a helper function creating the rich structure from a
structure with fewer fields, where the helper function fills the remaining fields. See for instance
<code><a href="https://pygae.github.io/lean-ga-docs/topology/uniform_space/basic.html#uniform_space.of_core">uniform_space.of_core</a></code> or <code>real_inner_product.of_core</code>.</p>
<p>For more details on this question, called the forgetful inheritance pattern, see <a href="https://hal.inria.fr/hal-02463336">Competing
inheritance paths in dependent type theory: a case study in functional
analysis</a>.</p>
referenced by: <small>
<a href="topology/uniform_space/basic.html#noteref1" title="mathlib: topology.uniform_space.basic">[1]</a>
<a href="topology/metric_space/basic.html#noteref1" title="mathlib: topology.metric_space.basic">[2]</a>
<a href="topology/metric_space/basic.html#noteref2" title="mathlib: topology.metric_space.basic">[3]</a>
<a href="topology/metric_space/basic.html#noteref3" title="mathlib: topology.metric_space.basic">[4]</a>
<a href="topology/metric_space/basic.html#noteref4" title="mathlib: topology.metric_space.basic">[5]</a>
<a href="topology/metric_space/basic.html#noteref5" title="mathlib: topology.metric_space.basic">[6]</a>
<a href="topology/metric_space/basic.html#noteref6" title="mathlib: topology.metric_space.basic">[7]</a>
<a href="analysis/normed_space/operator_norm.html#noteref1" title="mathlib: analysis.normed_space.operator_norm">[8]</a>
<a href="analysis/normed_space/operator_norm.html#noteref2" title="mathlib: analysis.normed_space.operator_norm">[9]</a>
<a href="analysis/normed_space/operator_norm.html#noteref3" title="mathlib: analysis.normed_space.operator_norm">[10]</a>
<a href="analysis/normed_space/operator_norm.html#noteref4" title="mathlib: analysis.normed_space.operator_norm">[11]</a>
<a href="algebra/group/defs.html#noteref1" title="mathlib: algebra.group.defs">[12]</a>
<a href="algebra/group/defs.html#noteref2" title="mathlib: algebra.group.defs">[13]</a>
<a href="algebra/group/defs.html#noteref3" title="mathlib: algebra.group.defs">[14]</a>
<a href="algebra/field/defs.html#noteref1" title="mathlib: algebra.field.defs">[15]</a>
<a href="algebra/field/defs.html#noteref2" title="mathlib: algebra.field.defs">[16]</a>
<a href="topology/metric_space/emetric_space.html#noteref1" title="mathlib: topology.metric_space.emetric_space">[17]</a>
<a href="topology/metric_space/emetric_space.html#noteref2" title="mathlib: topology.metric_space.emetric_space">[18]</a>
</small>
</div>
<div class="note">
<h2 id="function coercion"><a href="#function coercion">function coercion</a></h2>
<p>Many structures such as bundled morphisms coerce to functions so that you can
transparently apply them to arguments. For example, if <code>e : α ≃ β</code> and <code>a : α</code>
then you can write <code>e a</code> and this is elaborated as <code>⇑e a</code>. This type of
coercion is implemented using the <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> type class. There is one
important consideration:</p>
<p>If a type coerces to another type which in turn coerces to a function,
then it <strong>must</strong> implement <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> directly:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">structure</span> <span class="n">sparkling_equiv</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="c1">-- if we add a `has_coe` instance,</span>
<span class="kd">instance</span> <span class="o">{</span><span class="n">α</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/coe.html#has_coe">has_coe</a></span> <span class="o">(</span><span class="n">sparkling_equiv</span> <span class="n">α</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="o">⟨</span><span class="n">sparkling_equiv.to_equiv</span><span class="o">⟩</span>
<span class="c1">-- then a `has_coe_to_fun` instance **must** be added as well:</span>
<span class="kd">instance</span> <span class="o">{</span><span class="n">α</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/coe.html#has_coe_to_fun">has_coe_to_fun</a></span> <span class="o">(</span><span class="n">sparkling_equiv</span> <span class="n">α</span> <span class="n">β</span><span class="o">)</span> <span class="o">:=</span>
<span class="o">⟨</span><span class="bp">λ</span> <span class="n">_</span><span class="o">,</span> <span class="n">α</span> <span class="bp">→</span> <span class="n">β</span><span class="o">,</span> <span class="bp">λ</span> <span class="n">f</span><span class="o">,</span> <span class="n">f.to_equiv.to_fun</span><span class="o">⟩</span>
</code></pre></div>
<p>(Rationale: if we do not declare the direct coercion, then <code>⇑e a</code> is not in
simp-normal form. The lemma <code><a href="https://pygae.github.io/lean-ga-docs/logic/basic.html#coe_fn_coe_base">coe_fn_coe_base</a></code> will unfold it to <code>⇑↑e a</code>. This
often causes loops in the simplifier.)</p>
referenced by: <small>
<a href="tactic/lint/type_classes.html#noteref1" title="mathlib: tactic.lint.type_classes">[1]</a>
<a href="algebra/hom/non_unital_alg.html#noteref1" title="mathlib: algebra.hom.non_unital_alg">[2]</a>
</small>
</div>
<div class="note">
<h2 id="implicit instance arguments"><a href="#implicit instance arguments">implicit instance arguments</a></h2>
<p>There are places where typeclass arguments are specified with implicit <code>{}</code> brackets instead of
the usual <code>[]</code> brackets. This is done when the instances can be inferred because they are implicit
arguments to the type of one of the other arguments. When they can be inferred from these other
arguments, it is faster to use this method than to use type class inference.</p>
<p>For example, when writing lemmas about <code>(f : α →+* β)</code>, it is faster to specify the fact that <code>α</code>
and <code>β</code> are <code><a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a></code>s as <code>{rα : <a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> α} {rβ : <a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> β}</code> rather than the usual
<code>[<a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> α] [<a href="https://pygae.github.io/lean-ga-docs/algebra/ring/defs.html#semiring">semiring</a> β]</code>.</p>
referenced by: <small>
<a href="analysis/normed/field/basic.html#noteref1" title="mathlib: analysis.normed.field.basic">[1]</a>
<a href="analysis/normed/field/basic.html#noteref2" title="mathlib: analysis.normed.field.basic">[2]</a>
<a href="algebra/hom/ring.html#noteref1" title="mathlib: algebra.hom.ring">[3]</a>
<a href="algebra/hom/ring.html#noteref2" title="mathlib: algebra.hom.ring">[4]</a>
<a href="data/finsupp/basic.html#noteref1" title="mathlib: data.finsupp.basic">[5]</a>
</small>
</div>
<div class="note">
<h2 id="likely generated binder names"><a href="#likely generated binder names">likely generated binder names</a></h2>
<p>In surface Lean, we can write anonymous Π binders (i.e. binders where the
argument is not named) using the function arrow notation:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">inductive</span> <span class="n">test</span> <span class="o">:</span> <span class="kt">Type</span>
<span class="bp">|</span> <span class="n">intro</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="bp">→</span> <span class="n">test</span>
</code></pre></div>
<p>After elaboration, however, every binder must have a name, so Lean generates
one. In the example, the binder in the type of <code>intro</code> is anonymous, so Lean
gives it the name <code>ᾰ</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="n">test.intro</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">(</span><span class="n">ᾰ</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="n">test</span>
</code></pre></div>
<p>When there are multiple anonymous binders, they are named <code>ᾰ_1</code>, <code>ᾰ_2</code> etc.</p>
<p>Thus, when we want to know whether the user named a binder, we can check whether
the name follows this scheme. Note, however, that this is not reliable. When the
user writes (for whatever reason)</p>
<div class="codehilite"><pre><span></span><code><span class="kd">inductive</span> <span class="n">test</span> <span class="o">:</span> <span class="kt">Type</span>
<span class="bp">|</span> <span class="n">intro</span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">(</span><span class="n">ᾰ</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="n">test</span>
</code></pre></div>
<p>we cannot tell that the binder was, in fact, named.</p>
<p>The function <code><a href="https://pygae.github.io/lean-ga-docs/meta/expr.html#name.is_likely_generated_binder_name">name.is_likely_generated_binder_name</a></code> checks if
a name is of the form <code>ᾰ</code>, <code>ᾰ_1</code>, etc.</p>
referenced by: <small>
<a href="meta/expr.html#noteref1" title="mathlib: meta.expr">[1]</a>
<a href="meta/expr.html#noteref2" title="mathlib: meta.expr">[2]</a>
</small>
</div>
<div class="note">
<h2 id="lower instance priority"><a href="#lower instance priority">lower instance priority</a></h2>
<p>Certain instances always apply during type-class resolution. For example, the instance
<code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_comm_group.to_add_group">add_comm_group.to_add_group</a> {α} [<a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_comm_group">add_comm_group</a> α] : <a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> α</code> applies to all type-class
resolution problems of the form <code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> _</code>, and type-class inference will then do an
exhaustive search to find a commutative group. These instances take a long time to fail.
Other instances will only apply if the goal has a certain shape. For example
<code><a href="https://pygae.github.io/lean-ga-docs/data/int/basic.html#int.add_group">int.add_group</a> : <a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> ℤ</code> or
<code>add_group.prod {α β} [<a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> α] [<a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> β] : <a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_group">add_group</a> (α × β)</code>. Usually these instances
will fail quickly, and when they apply, they are almost always the desired instance.
For this reason, we want the instances of the second type (that only apply in specific cases) to
always have higher priority than the instances of the first type (that always apply).
See also #1561.</p>
<p>Therefore, if we create an instance that always applies, we set the priority of these instances to
100 (or something similar, which is below the default value of 1000).</p>
referenced by: <small>
<a href="analysis/normed/field/basic.html#noteref3" title="mathlib: analysis.normed.field.basic">[1]</a>
<a href="data/set/finite.html#noteref1" title="mathlib: data.set.finite">[2]</a>
<a href="algebra/group/conj.html#noteref1" title="mathlib: algebra.group.conj">[3]</a>
<a href="logic/nontrivial.html#noteref1" title="mathlib: logic.nontrivial">[4]</a>
</small>
</div>
<div class="note">
<h2 id="nolint_ge"><a href="#nolint_ge">nolint_ge</a></h2>
<p>Currently, the linter forbids the use of <code>></code> and <code>≥</code> in definitions and
statements, as they cause problems in rewrites.
They are still allowed in statements such as <code>bounded (≥)</code> or <code>∀ ε > 0</code> or <code>⨆ n ≥ m</code>,
and the linter allows that.
If you write a pattern where you bind two or more variables, like <code>∃ n m > 0</code>, the linter will
flag this as illegal, but it is also allowed. In this case, add the line</p>
<div class="codehilite"><pre><span></span><code><span class="kd">@[nolint ge_or_gt]</span> <span class="c1">-- see <a id="noteref1" href="https://pygae.github.io/lean-ga-docs/notes.html#nolint_ge">Note [nolint_ge]</a></span>
</code></pre></div>
referenced by: <small>
<a href="order/basic.html#noteref1" title="mathlib: order.basic">[1]</a>
<a href="tactic/lint/misc.html#noteref1" title="mathlib: tactic.lint.misc">[2]</a>
<a href="notes.html#noteref1" title="docs: notes">[3]</a>
</small>
</div>
<div class="note">
<h2 id="open expressions"><a href="#open expressions">open expressions</a></h2>
<p>Some declarations work with open expressions, i.e. an expr that has free variables.
Terms will free variables are not well-typed, and one should not use them in tactics like
<code>infer_type</code> or <code>unify</code>. You can still do syntactic analysis/manipulation on them.
The reason for working with open types is for performance: instantiating variables requires
iterating through the expression. In one performance test <code>pi_binders</code> was more than 6x
quicker than <code>mk_local_pis</code> (when applied to the type of all imported declarations 100x).</p>
referenced by: <small>
<a href="commands.html#noteref2" title="docs: commands">[1]</a>
<a href="tactic/doc_commands.html#noteref1" title="mathlib: tactic.doc_commands">[2]</a>
<a href="meta/expr.html#noteref3" title="mathlib: meta.expr">[3]</a>
<a href="meta/expr.html#noteref4" title="mathlib: meta.expr">[4]</a>
<a href="meta/expr.html#noteref5" title="mathlib: meta.expr">[5]</a>
<a href="meta/expr.html#noteref6" title="mathlib: meta.expr">[6]</a>
<a href="init/meta/expr.html#noteref1" title="core: init.meta.expr">[7]</a>
<a href="init/meta/expr.html#noteref2" title="core: init.meta.expr">[8]</a>
</small>
</div>
<div class="note">
<h2 id="operator precedence of big operators"><a href="#operator precedence of big operators">operator precedence of big operators</a></h2>
<p>There is no established mathematical convention
for the operator precedence of big operators like <code>∏</code> and <code>∑</code>.
We will have to make a choice.</p>
<p>Online discussions, such as <a href="https://math.stackexchange.com/q/185538/30839">https://math.stackexchange.com/q/185538/30839</a>
seem to suggest that <code>∏</code> and <code>∑</code> should have the same precedence,
and that this should be somewhere between <code>*</code> and <code>+</code>.
The latter have precedence levels <code>70</code> and <code>65</code> respectively,
and we therefore choose the level <code>67</code>.</p>
<p>In practice, this means that parentheses should be placed as follows:</p>
<div class="codehilite"><pre><span></span><code><span class="bp">∑</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="o">(</span><span class="n">a</span> <span class="n">k</span> <span class="bp">+</span> <span class="n">b</span> <span class="n">k</span><span class="o">)</span> <span class="bp">=</span> <span class="bp">∑</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="n">a</span> <span class="n">k</span> <span class="bp">+</span> <span class="bp">∑</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="n">b</span> <span class="n">k</span> <span class="bp">→</span>
<span class="bp">∏</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="n">a</span> <span class="n">k</span> <span class="bp">*</span> <span class="n">b</span> <span class="n">k</span> <span class="bp">=</span> <span class="o">(</span><span class="bp">∏</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="n">a</span> <span class="n">k</span><span class="o">)</span> <span class="bp">*</span> <span class="o">(</span><span class="bp">∏</span> <span class="n">k</span> <span class="k">in</span> <span class="n">K</span><span class="o">,</span> <span class="n">b</span> <span class="n">k</span><span class="o">)</span>
</code></pre></div>
<p>(Example taken from page 490 of Knuth's <em>Concrete Mathematics</em>.)</p>
</div>
<div class="note">
<h2 id="out-param inheritance"><a href="#out-param inheritance">out-param inheritance</a></h2>
<p>Diamond inheritance cannot depend on <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#out_param">out_param</a></code>s in the following circumstances:</p>
<ul>
<li>there are three classes <code>top</code>, <code>middle</code>, <code>bottom</code></li>
<li>all of these classes have a parameter <code>(α : <a href="https://pygae.github.io/lean-ga-docs/init/core.html#out_param">out_param</a> _)</code></li>
<li>all of these classes have an instance parameter <code>[root α]</code> that depends on this <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#out_param">out_param</a></code></li>
<li>the <code>root</code> class has two child classes: <code>left</code> and <code>right</code>, these are siblings in the hierarchy</li>
<li>the instance <code>bottom.to_middle</code> takes a <code>[left α]</code> parameter</li>
<li>the instance <code>middle.to_top</code> takes a <code>[right α]</code> parameter</li>
<li>there is a <code>leaf</code> class that inherits from both <code>left</code> and <code>right</code>.
In that case, given instances <code>bottom α</code> and <code>leaf α</code>, Lean cannot synthesize a <code>top α</code> instance,
even though the hypotheses of the instances <code>bottom.to_middle</code> and <code>middle.to_top</code> are satisfied.</li>
</ul>
<p>There are two workarounds:</p>
<ul>
<li>You could replace the bundled inheritance implemented by the instance <code>middle.to_top</code> with
unbundled inheritance implemented by adding a <code>[top α]</code> parameter to the <code>middle</code> class. This is
the preferred option since it is also more compatible with Lean 4, at the cost of being more work
to implement and more verbose to use.</li>
<li>You could weaken the <code>bottom.to_middle</code> instance by making it depend on a subclass of
<code>middle.to_top</code>'s parameter, in this example replacing <code>[left α]</code> with <code>[leaf α]</code>.</li>
</ul>
</div>
<div class="note">
<h2 id="partially-applied ext lemmas"><a href="#partially-applied ext lemmas">partially-applied ext lemmas</a></h2>
<p>When possible, <code>ext</code> lemmas are stated without a full set of arguments. As an example, for bundled
homs <code>f</code>, <code>g</code>, and <code>of</code>, <code>f.comp of = g.comp of → f = g</code> is a better <code>ext</code> lemma than
<code>(∀ x, f (of x) = g (of x)) → f = g</code>, as the former allows a second type-specific extensionality
lemmas to be applied to <code>f.comp of = g.comp of</code>.
If the domain of <code>of</code> is <code>ℕ</code> or <code>ℤ</code> and <code>of</code> is a <code><a href="https://pygae.github.io/lean-ga-docs/algebra/hom/ring.html#ring_hom">ring_hom</a></code>, such a lemma could then make the goal
<code>f (of 1) = g (of 1)</code>.</p>
<p>For bundled morphisms, there is a <code>ext</code> lemma that always applies of the form
<code>(∀ x, ⇑f x = ⇑g x) → f = g</code>. When adding type-specific <code>ext</code> lemmas like the one above, we want
these to be tried first. This happens automatically since the type-specific lemmas are inevitably
defined later.</p>
referenced by: <small>
<a href="group_theory/quotient_group.html#noteref1" title="mathlib: group_theory.quotient_group">[1]</a>
<a href="group_theory/quotient_group.html#noteref2" title="mathlib: group_theory.quotient_group">[2]</a>
<a href="data/mv_polynomial/basic.html#noteref1" title="mathlib: data.mv_polynomial.basic">[3]</a>
<a href="ring_theory/localization/basic.html#noteref1" title="mathlib: ring_theory.localization.basic">[4]</a>
<a href="ring_theory/localization/basic.html#noteref2" title="mathlib: ring_theory.localization.basic">[5]</a>
<a href="linear_algebra/clifford_algebra/even.html#noteref1" title="mathlib: linear_algebra.clifford_algebra.even">[6]</a>
<a href="algebra/direct_sum/module.html#noteref1" title="mathlib: algebra.direct_sum.module">[7]</a>
<a href="linear_algebra/tensor_algebra/basic.html#noteref1" title="mathlib: linear_algebra.tensor_algebra.basic">[8]</a>
<a href="algebra/algebra/tower.html#noteref1" title="mathlib: algebra.algebra.tower">[9]</a>
<a href="algebra/direct_sum/ring.html#noteref1" title="mathlib: algebra.direct_sum.ring">[10]</a>
<a href="data/dfinsupp/basic.html#noteref1" title="mathlib: data.dfinsupp.basic">[11]</a>
<a href="ring_theory/tensor_product.html#noteref1" title="mathlib: ring_theory.tensor_product">[12]</a>
<a href="linear_algebra/pi.html#noteref2" title="mathlib: linear_algebra.pi">[13]</a>
<a href="algebra/big_operators/pi.html#noteref1" title="mathlib: algebra.big_operators.pi">[14]</a>
<a href="algebra/big_operators/pi.html#noteref2" title="mathlib: algebra.big_operators.pi">[15]</a>
<a href="linear_algebra/prod.html#noteref3" title="mathlib: linear_algebra.prod">[16]</a>
<a href="linear_algebra/tensor_product.html#noteref1" title="mathlib: linear_algebra.tensor_product">[17]</a>
<a href="algebra/monoid_algebra/basic.html#noteref1" title="mathlib: algebra.monoid_algebra.basic">[18]</a>
<a href="algebra/monoid_algebra/basic.html#noteref2" title="mathlib: algebra.monoid_algebra.basic">[19]</a>
<a href="algebra/monoid_algebra/basic.html#noteref3" title="mathlib: algebra.monoid_algebra.basic">[20]</a>
<a href="algebra/monoid_algebra/basic.html#noteref4" title="mathlib: algebra.monoid_algebra.basic">[21]</a>
<a href="algebra/monoid_algebra/basic.html#noteref5" title="mathlib: algebra.monoid_algebra.basic">[22]</a>
<a href="algebra/monoid_algebra/basic.html#noteref6" title="mathlib: algebra.monoid_algebra.basic">[23]</a>
<a href="data/finsupp/basic.html#noteref2" title="mathlib: data.finsupp.basic">[24]</a>
<a href="data/rat/cast.html#noteref1" title="mathlib: data.rat.cast">[25]</a>
<a href="algebra/free_algebra.html#noteref1" title="mathlib: algebra.free_algebra">[26]</a>
<a href="linear_algebra/clifford_algebra/basic.html#noteref1" title="mathlib: linear_algebra.clifford_algebra.basic">[27]</a>
<a href="linear_algebra/dfinsupp.html#noteref1" title="mathlib: linear_algebra.dfinsupp">[28]</a>
<a href="algebra/direct_sum/algebra.html#noteref1" title="mathlib: algebra.direct_sum.algebra">[29]</a>
<a href="algebra/direct_sum/basic.html#noteref1" title="mathlib: algebra.direct_sum.basic">[30]</a>
<a href="linear_algebra/exterior_algebra/basic.html#noteref1" title="mathlib: linear_algebra.exterior_algebra.basic">[31]</a>
<a href="linear_algebra/quotient.html#noteref1" title="mathlib: linear_algebra.quotient">[32]</a>
</small>
</div>
<div class="note">
<h2 id="pointwise nat action"><a href="#pointwise nat action">pointwise nat action</a></h2>
<p>Pointwise monoids (<code><a href="https://pygae.github.io/lean-ga-docs/init/data/set.html#set">set</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/data/finset/basic.html#finset">finset</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/order/filter/basic.html#filter">filter</a></code>) have derived pointwise actions of the form
<code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#has_smul">has_smul</a> α β → <a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#has_smul">has_smul</a> α (<a href="https://pygae.github.io/lean-ga-docs/init/data/set.html#set">set</a> β)</code>. When <code>α</code> is <code>ℕ</code> or <code>ℤ</code>, this action conflicts with the
nat or int action coming from <code><a href="https://pygae.github.io/lean-ga-docs/init/data/set.html#set">set</a> β</code> being a <code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#monoid">monoid</a></code> or <code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#div_inv_monoid">div_inv_monoid</a></code>. For example,
<code>2 • {a, b}</code> can both be <code>{2 • a, 2 • b}</code> (pointwise action, pointwise repeated addition,
<code><a href="https://pygae.github.io/lean-ga-docs/data/set/pointwise/smul.html#set.has_smul_set">set.has_smul_set</a></code>) and <code>{a + a, a + b, b + a, b + b}</code> (nat or int action, repeated pointwise
addition, <code><a href="https://pygae.github.io/lean-ga-docs/data/set/pointwise/basic.html#set.has_nsmul">set.has_nsmul</a></code>).</p>
<p>Because the pointwise action can easily be spelled out in such cases, we give higher priority to the
nat and int actions.</p>
referenced by: <small>
<a href="data/set/pointwise/basic.html#noteref1" title="mathlib: data.set.pointwise.basic">[1]</a>
<a href="data/set/pointwise/basic.html#noteref2" title="mathlib: data.set.pointwise.basic">[2]</a>
<a href="data/set/pointwise/basic.html#noteref3" title="mathlib: data.set.pointwise.basic">[3]</a>
<a href="data/set/pointwise/basic.html#noteref4" title="mathlib: data.set.pointwise.basic">[4]</a>
<a href="data/set/pointwise/basic.html#noteref5" title="mathlib: data.set.pointwise.basic">[5]</a>
<a href="data/finset/pointwise.html#noteref1" title="mathlib: data.finset.pointwise">[6]</a>