Skip to content

feat: introduce NthRoot notation class#7907

Closed
urkud wants to merge 25 commits intomasterfrom
YK-nth-root
Closed

feat: introduce NthRoot notation class#7907
urkud wants to merge 25 commits intomasterfrom
YK-nth-root

Conversation

@urkud
Copy link
Copy Markdown
Member

@urkud urkud commented Oct 25, 2023

Also use it for Real.sqrt, and replace the few occurrences of sqrt that do not already use the notation.


Zulip

Open in Gitpod

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 30, 2023
@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 13, 2024
@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 14, 2024
@fpvandoorn fpvandoorn added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 5, 2024
@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 10, 2024
mathlib-bors bot pushed a commit that referenced this pull request Apr 11, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
mathlib-bors bot pushed a commit that referenced this pull request Apr 13, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 13, 2024
@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 13, 2024
@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 14, 2024
xgenereux pushed a commit that referenced this pull request Apr 15, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
atarnoam pushed a commit that referenced this pull request Apr 16, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
uniwuni pushed a commit that referenced this pull request Apr 19, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
callesonne pushed a commit that referenced this pull request Apr 22, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
Jun2M pushed a commit that referenced this pull request Apr 24, 2024
This adds the notation `√r` for `Real.sqrt r`. The precedence is such that `√x⁻¹` is parsed as `√(x⁻¹)`; not because this is particularly desirable, but because it's the default and the choice doesn't really matter.

This is extracted from #7907, which adds a more general nth root typeclass.
The idea is to perform all the boring substitutions downstream quickly, so that we can play around with custom elaborators with a much slower rate of code-rot.
This PR also won't rot as quickly, as it does not forbid writing `x.sqrt` as that PR does.

While perhaps claiming `√` for `Real.sqrt` is greedy; it:
* Is far more common thatn `NNReal.sqrt` and `Nat.sqrt`
* Is far more interesting to mathlib than `sqrt` on `Float`
* Can be overloaded anyway, so this does not prevent downstream code using the notation on their own types.
* Will be replaced by a more general typeclass in a future PR.

[Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60Sqrt.60.20notation.20typeclass/near/400086502)



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 25, 2024
@eric-wieser eric-wieser added awaiting-review awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. and removed awaiting-author A reviewer has asked the author a question or requested changes. labels May 25, 2024
@eric-wieser eric-wieser requested a review from kmill May 25, 2024 21:47
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some more changes, this now looks great.

@kmill, could you check the unexpander / use of default_instance is reasonable?

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 6, 2024
@github-actions
Copy link
Copy Markdown

PR summary 8f948ff6a7

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Data.Real.Sqrt 1073 1075 +2 (+0.19%)
Mathlib.Data.Complex.Abs 1075 1077 +2 (+0.19%)
Mathlib.Analysis.RCLike.Basic 1218 1220 +2 (+0.16%)
Mathlib.Topology.ContinuousFunction.StarOrdered 1253 1255 +2 (+0.16%)
Mathlib.Analysis.Complex.AbelLimit 1264 1266 +2 (+0.16%)
Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic 1266 1268 +2 (+0.16%)
Mathlib.Analysis.SpecialFunctions.Pow.Real 1346 1348 +2 (+0.15%)
Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics 1348 1350 +2 (+0.15%)
Mathlib.Data.Real.GoldenRatio 1382 1384 +2 (+0.14%)
Mathlib.Analysis.InnerProductSpace.Basic 1467 1469 +2 (+0.14%)
Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds 1628 1630 +2 (+0.12%)
Mathlib.LinearAlgebra.Matrix.PosDef 1675 1677 +2 (+0.12%)
Mathlib.Analysis.SpecialFunctions.Stirling 1803 1805 +2 (+0.11%)
Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls 1865 1867 +2 (+0.11%)
Mathlib.Probability.Distributions.Gaussian 1867 1869 +2 (+0.11%)
Mathlib.NumberTheory.Harmonic.GammaDeriv 1899 1901 +2 (+0.11%)
Mathlib.Analysis.CstarAlgebra.ContinuousFunctionalCalculus.Instances 1938 1940 +2 (+0.10%)
Mathlib.NumberTheory.NumberField.CanonicalEmbedding.ConvexBody 2169 2171 +2 (+0.09%)
Mathlib.NumberTheory.NumberField.Discriminant 2172 2174 +2 (+0.09%)
Mathlib.NumberTheory.NumberField.ClassNumber 2180 2182 +2 (+0.09%)
Import changes for all files
Files Import difference
There are 693 files with changed transitive imports: this is too many to display!

Declarations diff

+ NthRoot
+ NthRoot.unexpander
+ instance : NthRoot ℝ 2 := ⟨fun x ↦ NNReal.sqrt (Real.toNNReal x)⟩
+ sqrt_def
- sqrt

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

@ghost ghost added merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) and removed merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) labels Jul 28, 2024
@grunweg grunweg added t-analysis Analysis (normed *, calculus) t-algebra Algebra (groups, rings, fields, etc) labels Aug 27, 2024
urkud and others added 2 commits May 7, 2025 21:20
@urkud urkud closed this Feb 8, 2026
@urkud urkud deleted the YK-nth-root branch February 8, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) t-algebra Algebra (groups, rings, fields, etc) t-analysis Analysis (normed *, calculus)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants