Conversation
…atCast` Reduce the diff of #11203
These lemmas are needed to define the semifield structure on `NNRat`, hence I am repurposing `Algebra.Order.Field.Defs` from avoiding a timeout (which I believe was solved long ago) to avoiding to import random stuff in the definition of the semifield structure on `NNRat` (although this PR doesn't actually reduce imports there, it will be in a later PR). Reduce the diff of #11203
by declaring them all in `where` style with implicit type assumptions and `inst` prefix Here to reduce the diff from #11203
Among other things, change the `nsmul`, `zsmul`, `qsmul` fields to have `n`/`q` come before `x`, because this matches the lemmas we want to write about them. It would be preferrable to perform the same changes to the `AddMonoid`/`AddGroup`-like typeclasses, but this is impossible with the current `to_additive` framework, so instead I have inserted some `Function.swap` at the interface between `AddMonoid`/`AddGroup` and `Ring`/`Field`. Reduce the diff of #11203
Soon, there will be `NNRat` analogs of the `Rat` fields in the definition of `Field`. `NNRat` is less nicely a structure than `Rat`, hence there is a need to reduce the dependency of `Field` on the internals of `Rat`. This PR achieves this by restating `Field.ratCast_mk'` in terms of `Rat.num`, `Rat.den`. This requires fixing a few downstream instances. Reduce the diff of #11203. Co-authored-by: Floris van Doorn <fpvdoorn@gmail.com>
`Rat` has a long history in (and before) mathlib and as such its development is full of cruft. Now that `NNRat` is a thing, there is a need for the theory of `Rat` to be mimickable to yield the theory of `NNRat`, which is not currently the case. Broadly, this PR aims at mirroring the `Rat` and `NNRat` declarations. It achieves this by: * Relying more on `Rat.num` and `Rat.den`, and less on the structure representation of `Rat` * Abandoning the vestigial `Rat.Nonneg` (which was replaced in Std by a new development of the order on `Rat`) * Renaming many `Rat` lemmas with dubious names. This creates quite a lot of conflicts with Std lemmas, whose names are themselves dubious. I am priming the relevant new mathlib names and leaving TODOs to fix the Std names. * Handling most of the `Rat` porting notes Reduce the diff of #11203
| ## Huge warning | ||
|
|
||
| Whenever you state a lemma about the coercion `ℚ≥0 → ℚ`, check that Lean inserts `NNRat.cast`, not | ||
| `Subtype.val`. Else your lemma will never apply. |
There was a problem hiding this comment.
Ouch, this is rather unfortunate.
There was a problem hiding this comment.
Yeah... The precise issue is that ⟨q, hq⟩ notation creates a term of type {q : ℚ // 0 ≤ q}, not ℚ≥0, so it finds Subtype.val as the coercion, not NNRat.cast
There was a problem hiding this comment.
This suggests we might want an NNRat.mk that has the correct return type?
But if so, that can wait until a later PR
bors merge
There was a problem hiding this comment.
Maybe, but it won't have the constructor notation. To properly solve it we should either:
- make
NNRatreducible - make
NNRata one-field structure - make
NNRata fully fledged structure withnum den : Natetc
Define the canonical coercion from the nonnegative rationals to any division semiring. From LeanAPAP
|
!bench |
|
Here are the benchmark results for commit f76c7be. Benchmark Metric Change
========================================================================
- ~Mathlib.FieldTheory.Subfield instructions 15.8%
- ~Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup instructions 7.7% |
|
The bench is very good: I was afraid of a global slowdown, but there is nothing in sight. I don't think the slowdown in two specific files has any importance (although if you can understand what is going on this would be even better). |
|
Yes, I already removed the problematic instances like For |
Ruben-VandeVelde
left a comment
There was a problem hiding this comment.
Code looks fine, assuming this is a change we want.
maintainer merge
|
🚀 Pull request has been placed on the maintainer queue by Ruben-VandeVelde. |
|
Pull request successfully merged into master. Build succeeded: |
Define the canonical coercion from the nonnegative rationals to any division semiring.
From LeanAPAP
GroupWithZero#11202MulOpposite/AddOpposite#11485nat_cast/int_cast/rat_casttonatCast/intCast/ratCast#11486coe_nat/coe_int/coe_rattonatCast/intCast/ratCast#11499pow_lt_pow_succtoAlgebra.Order.WithZero#11507Field's fields docstrings #11508Ratinternals in the definition ofField#11639NNRat.cast#12360