Mathlib v3 is deprecated. Go to Mathlib v4

Commit 2021-04-14 08:29 63801552

View on Github →

refactor(*): kill nat multiplication diamonds (#7084) An add_monoid has a natural -action, defined by n • a = a + ... + a, that we want to declare as an instance as it makes it possible to use the language of linear algebra. However, there are often other natural -actions. For instance, for any semiring R, the space of polynomials polynomial R has a natural R-action defined by multiplication on the coefficients. This means that polynomial ℕ has two natural -actions, which are equal but not defeq. The same goes for linear maps, tensor products, and so on (and even for itself). This is the case on current mathlib, with such non-defeq diamonds all over the place. To solve this issue, we embed an -action in the definition of an add_monoid (which is by default the naive action a + ... + a, but can be adjusted when needed -- it should always be equal to this one, but not necessarily definitionally), and declare a has_scalar ℕ α instance using this action. This is yet another example of the forgetful inheritance pattern that we use in metric spaces, embedding a topology and a uniform structure in it (except that here the functor from additive monoids to nat-modules is faithful instead of forgetful, but it doesn't make a difference). More precisely, we define

def nsmul_rec [has_add M] [has_zero M] : ℕ → M → M
| 0     a := 0
| (n+1) a := nsmul_rec n a + a
class add_monoid (M : Type u) extends add_semigroup M, add_zero_class M :=
(nsmul : ℕ → M → M := nsmul_rec)
(nsmul_zero' : ∀ x, nsmul 0 x = 0 . try_refl_tac)
(nsmul_succ' : ∀ (n : ℕ) x, nsmul n.succ x = nsmul n x + x . try_refl_tac)

For example, when we define polynomial R, then we declare the -action to be by multiplication on each coefficient (using the -action on R that comes from the fact that R is an add_monoid). In this way, the two natural has_scalar ℕ (polynomial ℕ) instances are defeq. The tactic to_additive transfers definitions and results from multiplicative monoids to additive monoids. To work, it has to map fields to fields. This means that we should also add corresponding fields to the multiplicative structure monoid, which could solve defeq problems for powers if needed. These problems do not come up in practice, so most of the time we will not need to adjust the npow field when defining multiplicative objects. With this refactor, all the diamonds are gone. Or rather, all the diamonds I noticed are gone, but if there are still some diamonds then they can be fixed, contrary to before. Also, the notation •ℕ is gone, just use .

Estimated changes

added theorem npow_add
added theorem npow_one
added def npow_rec
added theorem nsmul_one'
added def nsmul_rec
modified theorem add_monoid_hom.map_nsmul
modified theorem add_nsmul
modified theorem bit0_nsmul'
modified theorem bit0_nsmul
modified theorem bit1_nsmul'
modified theorem bit1_nsmul
modified theorem gpow_zero
modified theorem gsmul_coe_nat
modified theorem gsmul_neg_succ_of_nat
modified theorem gsmul_of_nat
deleted def monoid.pow
deleted theorem monoid.pow_eq_has_pow
modified theorem mul_nsmul'
modified theorem mul_nsmul
modified theorem neg_nsmul
added theorem npow_eq_pow
deleted def nsmul
modified theorem nsmul_add
modified theorem nsmul_add_comm'
modified theorem nsmul_add_comm
modified theorem nsmul_add_sub_nsmul
added theorem nsmul_eq_smul
modified theorem nsmul_le_nsmul
modified theorem nsmul_le_nsmul_of_le_right
modified theorem nsmul_neg_comm
modified theorem nsmul_nonneg
modified theorem nsmul_pos
modified theorem nsmul_sub
modified theorem nsmul_zero
modified theorem one_gsmul
modified theorem one_nsmul
modified theorem pow_one
modified theorem pow_succ
modified theorem pow_zero
modified theorem sub_nsmul_nsmul_add
modified theorem succ_nsmul'
modified theorem succ_nsmul
modified theorem two_nsmul
modified theorem zero_gsmul
modified theorem zero_nsmul
modified theorem list.sum_repeat
modified theorem mul_nsmul_assoc
modified theorem mul_nsmul_left
modified theorem nat.nsmul_eq_mul
modified theorem nsmul_eq_mul'
modified theorem nsmul_eq_mul
modified theorem nsmul_le_nsmul_iff
modified theorem nsmul_lt_nsmul_iff
modified theorem nsmul_one