@@ -25,12 +25,25 @@ When adding new definitions that transfer type-classes across an equivalence, pl
2525
2626assert_not_exists MonoidWithZero MulAction
2727
28+ library_note «instance transfer via equivalence » /--
29+ For many type classes, we have a definition that lets us transfer instances from one type to another
30+ using an equivalence, such as `Equiv.mul` for `Mul`.
31+ Constructing data instances in this way is discouraged because the resulting data is inefficient
32+ to unfold. To somewhat mitigate this problem, in these definitions we don't write the
33+ projections on `Equiv` in the usual way using `Equiv.symm` and `DFunLike.coe`, and instead use
34+ `Equiv.toFun` and `Equiv.invFun` directly. As a result, unification has to do less unfolding.
35+
36+ Note also that when constructing data instances in this way, it usually helps to use
37+ `fast_instance%` to get a faster instance.
38+ -/
39+
2840namespace Equiv
2941variable {M α β : Type *} (e : α ≃ β)
3042
43+ -- See note [instance transfer via equivalence]
3144/-- Transfer `One` across an `Equiv` -/
3245@ [to_additive /-- Transfer `Zero` across an `Equiv` -/ ]
33- protected abbrev one [One β] : One α where one := e.symm 1
46+ protected abbrev one [One β] : One α where one := e.invFun 1
3447
3548@[to_additive]
3649lemma one_def [One β] :
@@ -39,7 +52,7 @@ lemma one_def [One β] :
3952
4053/-- Transfer `Mul` across an `Equiv` -/
4154@ [to_additive /-- Transfer `Add` across an `Equiv` -/ ]
42- protected abbrev mul [Mul β] : Mul α where mul x y := e.symm (e x * e y)
55+ protected abbrev mul [Mul β] : Mul α where mul x y := e.invFun (e.toFun x * e.toFun y)
4356
4457@[to_additive]
4558lemma mul_def [Mul β] (x y : α) :
@@ -49,7 +62,7 @@ lemma mul_def [Mul β] (x y : α) :
4962/-- Transfer `Div` across an `Equiv` -/
5063@ [to_additive /-- Transfer `Sub` across an `Equiv` -/ ]
5164protected abbrev div [Div β] : Div α :=
52- ⟨fun x y => e.symm (e x / e y)⟩
65+ ⟨fun x y => e.invFun (e.toFun x / e.toFun y)⟩
5366
5467@[to_additive]
5568lemma div_def [Div β] (x y : α) :
@@ -60,7 +73,7 @@ lemma div_def [Div β] (x y : α) :
6073-- but we already have an `Equiv.inv` (which perhaps should move to `Perm.inv`?)
6174/-- Transfer `Inv` across an `Equiv` -/
6275@ [to_additive /-- Transfer `Neg` across an `Equiv` -/ ]
63- protected abbrev Inv [Inv β] : Inv α where inv x := e.symm (e x)⁻¹
76+ protected abbrev Inv [Inv β] : Inv α where inv x := e.invFun (e.toFun x)⁻¹
6477
6578@[to_additive]
6679lemma inv_def [Inv β] (x : α) :
@@ -71,7 +84,7 @@ variable (M) in
7184/-- Transfer `Pow` across an `Equiv` -/
7285@ [to_additive (attr := to_additive /-- Transfer `VAdd` across an `Equiv` -/ ) smul
7386/-- Transfer `SMul` across an `Equiv` -/ ]
74- protected abbrev pow [Pow β M] : Pow α M where pow x n := e.symm (e x ^ n)
87+ protected abbrev pow [Pow β M] : Pow α M where pow x n := e.invFun (e.toFun x ^ n)
7588
7689@ [to_additive (attr := to_additive) smul_def]
7790lemma pow_def [Pow β M] (n : M) (x : α) :
0 commit comments