-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - refactor(algebra/module): change module into an abbreviation for semimodule #2848
Conversation
The old behaviour caused `eq.mpr`'s in `pi_instance` output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good to me. Thanks for doing this 🎉
I've flagged places where the instance priority is changed. This is something that we might want to discuss a bit.
I've also flagged places where proofs "downgraded". (Many proofs have moved around, so I probably didn't catch all of these cases.) We might want to discuss/investigate.
@@ -138,6 +138,9 @@ open_locale classical | |||
|
|||
universes u v w | |||
|
|||
local attribute [instance, priority 1001] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment on whether this is a good setting. I don't understand the priorities well enough, so I would like a second pair of eyes here.
(⇑((@finset.univ _ hs.fintype).sum (λ x, (linear_map.proj x : (s → ℝ) →ₗ[ℝ] ℝ).smul_right x.1))) '' | ||
(@std_simplex _ hs.fintype) := | ||
(⇑((@finset.univ _ hs.fintype).sum | ||
(λ x, (@linear_map.proj ℝ s _ (λ i, ℝ) _ _ x).smul_right x.1))) '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unfortunate.
@@ -670,13 +670,15 @@ by rw [← rat.norm_cast_real, ← int.norm_cast_real]; congr' 1; norm_cast | |||
section normed_space | |||
|
|||
section prio | |||
set_option default_priority 100 -- see Note [default priority] | |||
-- see Note[vector space definition] for why we extend `module`. | |||
set_option default_priority 920 -- see Note [default priority]. Here, we set a rather high priority, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second pair of eyes please.
definitions are given in terms of semirings, but many applications use rings or fields. We increase | ||
a little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that | ||
more specific instances are tried first. -/ | ||
attribute [instance, priority 200] ring.to_semiring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. But flagging this so that other reviewers can easily find it.
@@ -57,6 +57,8 @@ noncomputable theory | |||
open_locale classical | |||
open finset | |||
|
|||
local attribute [instance, priority 1001] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second pair of eyes please.
begin | ||
show is_linear_map R ((lsubtype_domain s : (α →₀ M) →ₗ[R] (s →₀ M)).comp | ||
(submodule.subtype (supported M R s))), | ||
let F : (supported M R s) ≃ (s →₀ M) := restrict_support_equiv s M, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unfortunate.
@@ -366,8 +369,10 @@ theorem ext_threefold {g h : (M ⊗[R] N) ⊗[R] P →ₗ[R] Q} | |||
begin | |||
let e := linear_equiv.to_equiv (lift.equiv R (M ⊗[R] N) P Q), | |||
apply e.symm.injective, | |||
ext x y z, | |||
exact H x y z, | |||
refine ext _, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to tag something with @[ext]
to fix this?
@@ -171,6 +198,8 @@ theorem smul_eq_zero {R E : Type*} [division_ring R] [add_comm_group E] [module | |||
|
|||
end module | |||
|
|||
section | |||
set_option default_priority 910 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second pair of eyes please.
I had to fix some additional failures after merging master. One of them is the following, in
and I had to change it to
So, exactly the same proof, but without the dot notation. I already had to make several changes with the same flavor when fixing the library, for instance going from |
Thanks 🎉 bors merge |
Canceled. |
bors merge |
Merge conflict. |
🥺 bors merge |
Canceled. |
bors merge |
…module (#2848) The file `algebra/module.lean` contains the lines ``` There were several attempts to make `module` an abbreviation of `semimodule` but this makes class instance search too hard for Lean 3. ``` It turns out that this was too hard for Lean 3 until recently, but this is not too hard for Lean 3.14. This PR removes these two lines, and changes the files accordingly. This means that the basic objects of linear algebra are now semimodules over semiring, making it possible to talk about matrices with natural number coefficients or apply general results on multilinear maps to get the binomial or the multinomial formula. A linear map is now defined over semirings, between semimodules which are `add_comm_monoid`s. For some statements, you need to have an `add_comm_group`, and a `ring` or a `comm_semiring` or a `comm_ring`. I have not tried to lower the possible typeclass assumptions like this in all files, but I have done it carefully in the following files: * `algebra/module` * `linear_algebra/basic` * `linear_algebra/multilinear` * `topology/algebra/module` * `topology/algebra/multilinear` Other files can be optimised later in the same way when needed, but this PR is already big enough. I have also fixed the breakage in all the other files. It was sometimes completely mysterious (in tensor products, I had to replace several times `linear_map.id.flip` with `linear_map.flip linear_map.id`), but globally all right. I have tweaked a few instance priorities to make sure that things don't go too bad: there are often additional steps in typeclass inference, going from `ring` to `semiring` and from `add_comm_group` to `add_comm_monoid`, so I have increased their priority (putting it strictly between 100 and 1000), and adjusted some other priorities to get more canonical instance paths, fixing some preexisting weirdnesses (notably in multilinear maps). One place where I really had to help Lean is with normed spaces of continuous multilinear maps, where instance search is just too big. I am aware that this will be a nightmare to refer, but as often with big refactor it's an "all or nothing" PR, impossible to split in tiny pieces. Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
Pull request successfully merged into master. Build succeeded: |
…module (leanprover-community#2848) The file `algebra/module.lean` contains the lines ``` There were several attempts to make `module` an abbreviation of `semimodule` but this makes class instance search too hard for Lean 3. ``` It turns out that this was too hard for Lean 3 until recently, but this is not too hard for Lean 3.14. This PR removes these two lines, and changes the files accordingly. This means that the basic objects of linear algebra are now semimodules over semiring, making it possible to talk about matrices with natural number coefficients or apply general results on multilinear maps to get the binomial or the multinomial formula. A linear map is now defined over semirings, between semimodules which are `add_comm_monoid`s. For some statements, you need to have an `add_comm_group`, and a `ring` or a `comm_semiring` or a `comm_ring`. I have not tried to lower the possible typeclass assumptions like this in all files, but I have done it carefully in the following files: * `algebra/module` * `linear_algebra/basic` * `linear_algebra/multilinear` * `topology/algebra/module` * `topology/algebra/multilinear` Other files can be optimised later in the same way when needed, but this PR is already big enough. I have also fixed the breakage in all the other files. It was sometimes completely mysterious (in tensor products, I had to replace several times `linear_map.id.flip` with `linear_map.flip linear_map.id`), but globally all right. I have tweaked a few instance priorities to make sure that things don't go too bad: there are often additional steps in typeclass inference, going from `ring` to `semiring` and from `add_comm_group` to `add_comm_monoid`, so I have increased their priority (putting it strictly between 100 and 1000), and adjusted some other priorities to get more canonical instance paths, fixing some preexisting weirdnesses (notably in multilinear maps). One place where I really had to help Lean is with normed spaces of continuous multilinear maps, where instance search is just too big. I am aware that this will be a nightmare to refer, but as often with big refactor it's an "all or nothing" PR, impossible to split in tiny pieces. Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
The file
algebra/module.lean
contains the linesIt turns out that this was too hard for Lean 3 until recently, but this is not too hard for Lean 3.14. This PR removes these two lines, and changes the files accordingly.
This means that the basic objects of linear algebra are now semimodules over semiring, making it possible to talk about matrices with natural number coefficients or apply general results on multilinear maps to get the binomial or the multinomial formula.
A linear map is now defined over semirings, between semimodules which are
add_comm_monoid
s. For some statements, you need to have anadd_comm_group
, and aring
or acomm_semiring
or acomm_ring
. I have not tried to lower the possible typeclass assumptions like this in all files, but I have done it carefully in the following files:algebra/module
linear_algebra/basic
linear_algebra/multilinear
topology/algebra/module
topology/algebra/multilinear
Other files can be optimised later in the same way when needed, but this PR is already big enough.
I have also fixed the breakage in all the other files. It was sometimes completely mysterious (in tensor products, I had to replace several times
linear_map.id.flip
withlinear_map.flip linear_map.id
), but globally all right. I have tweaked a few instance priorities to make sure that things don't go too bad: there are often additional steps in typeclass inference, going fromring
tosemiring
and fromadd_comm_group
toadd_comm_monoid
, so I have increased their priority (putting it strictly between 100 and 1000), and adjusted some other priorities to get more canonical instance paths, fixing some preexisting weirdnesses (notably in multilinear maps). One place where I really had to help Lean is with normed spaces of continuous multilinear maps, where instance search is just too big.I am aware that this will be a nightmare to refer, but as often with big refactor it's an "all or nothing" PR, impossible to split in tiny pieces.