Skip to content

[Merged by Bors] - feat: use a constructor for NNReal#37609

Closed
sgouezel wants to merge 20 commits intoleanprover-community:masterfrom
sgouezel:SG_betterNNRealMk
Closed

[Merged by Bors] - feat: use a constructor for NNReal#37609
sgouezel wants to merge 20 commits intoleanprover-community:masterfrom
sgouezel:SG_betterNNRealMk

Conversation

@sgouezel
Copy link
Copy Markdown
Contributor

@sgouezel sgouezel commented Apr 3, 2026

Currently, many elements of NNReal are constructed as pair (x, hx), i.e., as elements of the subtype of nonnegative real numbers. The two types are defeq, but not reducibly, so this creates many defeq abuses. This PR introduces a constructor NNReal.mk and uses it instead of the bare constructor, to avoid these defeq abuses.


Open in Gitpod

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

PR summary cd8272a9d5

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ Measurable.nnreal_mk
+ instance {M : Type*} [SMul ℝ M] : SMul ℝ≥0 M
+ inv_mk
+ mk
+-+--+ nnnorm_nnratCast

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

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

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


Decrease in tech debt: (relative, absolute) = (8.00, 0.00)
Current number Change Type
6893 -8 backward.isDefEq.respectTransparency

Current commit 5954d3878f
Reference commit cd8272a9d5

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-data Data (lists, quotients, numbers, etc) label Apr 3, 2026
@sgouezel
Copy link
Copy Markdown
Contributor Author

sgouezel commented Apr 4, 2026

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 4, 2026

Benchmark results for 23488c7 against cd8272a are in. There are no significant changes. @sgouezel

  • 🟥 build//instructions: +7.9G (+0.00%)

Medium changes (2🟥)

  • 🟥 build/module/Mathlib.Analysis.Analytic.Composition//instructions: +19.2G (+16.57%)
  • 🟥 build/module/Mathlib.Geometry.Manifold.Riemannian.Basic//instructions: +4.0G (+5.71%)

Comment thread Mathlib/NumberTheory/NumberField/CanonicalEmbedding/Basic.lean Outdated
Comment thread Mathlib/NumberTheory/NumberField/CanonicalEmbedding/Basic.lean Outdated
@riccardobrasca
Copy link
Copy Markdown
Member

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 4, 2026

Benchmark results for 21b9539 against cd8272a are in. Significant changes detected! @riccardobrasca

  • 🟥 build//instructions: +109.5G (+0.06%)

Medium changes (8🟥)

  • 🟥 build/module/Mathlib.Analysis.Analytic.Composition//instructions: +19.0G (+16.40%)
  • 🟥 build/module/Mathlib.Geometry.Euclidean.Volume.Measure//instructions: +2.0G (+6.31%)
  • 🟥 build/module/Mathlib.Geometry.Manifold.Riemannian.Basic//instructions: +4.0G (+5.77%)
  • 🟥 build/module/Mathlib.InformationTheory.KullbackLeibler.Basic//instructions: +5.0G (+20.43%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Decomposition.Lebesgue//instructions: +12.4G (+24.95%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.FiniteMeasure//instructions: +13.8G (+28.19%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Haar.Unique//instructions: +11.2G (+16.63%)
  • 🟥 build/module/Mathlib.Probability.Distributions.SetBernoulli//instructions: +1.8G (+12.90%)

Small changes (8🟥)

  • 🟥 build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique//instructions: +1.4G (+1.98%)
  • 🟥 build/module/Mathlib.Analysis.Convex.SpecificFunctions.Pow//instructions: +1.3G (+12.52%)
  • 🟥 build/module/Mathlib.MeasureTheory.Covering.Differentiation//instructions: +4.4G (+9.66%)
  • 🟥 build/module/Mathlib.MeasureTheory.Group.MeasurableEquiv//instructions: +971.8M (+3.86%)
  • 🟥 build/module/Mathlib.MeasureTheory.Group.ModularCharacter//instructions: +992.8M (+6.67%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Hausdorff//instructions: +2.1G (+3.11%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.ProbabilityMeasure//instructions: +4.1G (+11.23%)
  • 🟥 build/module/Mathlib.MeasureTheory.VectorMeasure.Decomposition.Jordan//instructions: +794.2M (+3.66%)

@sgouezel
Copy link
Copy Markdown
Contributor Author

sgouezel commented Apr 4, 2026

The bad radar comes from the fact that I add an instance

instance {M : Type*} [SMul ℝ M] : SMul ℝ≥0 M :=
  ⟨fun c m ↦ (c : ℝ) • m⟩

while before we only had it for a MulAction, expressed in terms of toRealHom.toMonoidHom (so, with bad defeq behavior at instance transparency). This change is useful to remove several backward.isDefEq.respectTransparency , so I think it's a good change even if it has a small performance impact.

@riccardobrasca
Copy link
Copy Markdown
Member

I agree it is worth. Let's just see how is now.

!redar

@riccardobrasca
Copy link
Copy Markdown
Member

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 4, 2026

Benchmark results for 5954d38 against cd8272a are in. Significant changes detected! @riccardobrasca

  • 🟥 build//instructions: +95.6G (+0.05%)

Medium changes (8🟥)

  • 🟥 build/module/Mathlib.Analysis.Analytic.Composition//instructions: +19.1G (+16.49%)
  • 🟥 build/module/Mathlib.Geometry.Euclidean.Volume.Measure//instructions: +2.0G (+6.43%)
  • 🟥 build/module/Mathlib.Geometry.Manifold.Riemannian.Basic//instructions: +4.0G (+5.75%)
  • 🟥 build/module/Mathlib.InformationTheory.KullbackLeibler.Basic//instructions: +5.0G (+20.44%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Decomposition.Lebesgue//instructions: +12.1G (+24.51%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.FiniteMeasure//instructions: +13.7G (+27.97%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Haar.Unique//instructions: +11.2G (+16.58%)
  • 🟥 build/module/Mathlib.Probability.Distributions.SetBernoulli//instructions: +1.8G (+12.86%)

Small changes (8🟥)

  • 🟥 build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique//instructions: +1.4G (+1.93%)
  • 🟥 build/module/Mathlib.Analysis.Convex.SpecificFunctions.Pow//instructions: +1.3G (+12.43%)
  • 🟥 build/module/Mathlib.MeasureTheory.Covering.Differentiation//instructions: +4.5G (+9.70%)
  • 🟥 build/module/Mathlib.MeasureTheory.Group.MeasurableEquiv//instructions: +911.2M (+3.62%)
  • 🟥 build/module/Mathlib.MeasureTheory.Group.ModularCharacter//instructions: +1.1G (+7.38%)
  • 🟥 build/module/Mathlib.MeasureTheory.Integral.RieszMarkovKakutani.Basic//instructions: +893.0M (+3.34%)
  • 🟥 build/module/Mathlib.MeasureTheory.Measure.Hausdorff//instructions: +2.1G (+3.09%)
  • 🟥 build/module/Mathlib.MeasureTheory.VectorMeasure.Decomposition.Jordan//instructions: +828.4M (+3.81%)

@riccardobrasca
Copy link
Copy Markdown
Member

I think we can live with this slow down. Thanks!

bors merge

mathlib-bors bot pushed a commit that referenced this pull request Apr 4, 2026
Currently, many elements of NNReal are constructed as pair (x, hx), i.e., as elements of the subtype of nonnegative real numbers. The two types are defeq, but not reducibly, so this creates many defeq abuses. This PR introduces a constructor `NNReal.mk` and uses it instead of the bare constructor, to avoid these defeq abuses.

Co-authored-by: sgouezel <[email protected]>
@mathlib-triage mathlib-triage bot added the ready-to-merge This PR has been sent to bors. label Apr 4, 2026
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Apr 4, 2026

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: use a constructor for NNReal [Merged by Bors] - feat: use a constructor for NNReal Apr 4, 2026
@mathlib-bors mathlib-bors bot closed this Apr 4, 2026
@JovanGerb
Copy link
Copy Markdown
Contributor

I see a lot of simp; rfl. Are we missing some simp lemma?

riccardobrasca pushed a commit to riccardobrasca/mathlib4 that referenced this pull request Apr 6, 2026
Currently, many elements of NNReal are constructed as pair (x, hx), i.e., as elements of the subtype of nonnegative real numbers. The two types are defeq, but not reducibly, so this creates many defeq abuses. This PR introduces a constructor `NNReal.mk` and uses it instead of the bare constructor, to avoid these defeq abuses.

Co-authored-by: sgouezel <[email protected]>
YellPika pushed a commit to YellPika/mathlib4 that referenced this pull request Apr 6, 2026
Currently, many elements of NNReal are constructed as pair (x, hx), i.e., as elements of the subtype of nonnegative real numbers. The two types are defeq, but not reducibly, so this creates many defeq abuses. This PR introduces a constructor `NNReal.mk` and uses it instead of the bare constructor, to avoid these defeq abuses.

Co-authored-by: sgouezel <[email protected]>
@sgouezel sgouezel deleted the SG_betterNNRealMk branch April 10, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors. t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants