Skip to content

[Merged by Bors] - chore(PartENat): golf and improve ofNat support#8002

Closed
timotree3 wants to merge 11 commits intomasterfrom
TCB/PartENat-cleanup
Closed

[Merged by Bors] - chore(PartENat): golf and improve ofNat support#8002
timotree3 wants to merge 11 commits intomasterfrom
TCB/PartENat-cleanup

Conversation

@timotree3
Copy link
Copy Markdown
Collaborator

@timotree3 timotree3 commented Oct 28, 2023

This PR adds simp lemmas for OfNat.ofNat n : PartENat, 0 : PartENat, and 1 : PartENat in every place where there was a simp lemma for ((n : ℕ) : PartENat). This is necessary for simp confluence in the presence of lemmas such as Nat.cast_ofNat. In addition, instances for CharZero and ZeroLEOneClass are provided so that the lemmas from Data/Nat/Cast/Order.lean will apply, golfing some proofs.


Open in Gitpod

@timotree3 timotree3 added awaiting-review awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. labels Oct 28, 2023
@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Oct 29, 2023
@eric-wieser
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit fb7f2f8.
There were significant changes against commit 7b6b2a9:

  Benchmark                                                  Metric         Change
  ================================================================================
+ ~Mathlib.Analysis.NormedSpace.Multilinear                  instructions    -2.5%
+ ~Mathlib.LinearAlgebra.FreeModule.PID                      instructions    -5.6%
+ ~Mathlib.RepresentationTheory.GroupCohomology.Resolution   instructions    -3.4%

timotree3 and others added 3 commits November 2, 2023 15:56
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
These can be inferred by `[StrictOrderedSemiring R]`.
@timotree3 timotree3 added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Nov 2, 2023
@ghost ghost removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Nov 2, 2023
@ghost
Copy link
Copy Markdown

ghost commented Nov 2, 2023

This PR/issue depends on:

@eric-wieser
Copy link
Copy Markdown
Member

bors d+

Pleaes merge once CI passes.

Thanks, and sorry for letting this sit for a little.

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Nov 8, 2023

✌️ timotree3 can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@github-actions github-actions bot added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed awaiting-review labels Nov 8, 2023
@eric-wieser
Copy link
Copy Markdown
Member

bors merge

@eric-wieser
Copy link
Copy Markdown
Member

!bench

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Nov 8, 2023
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 385cee0.
There were significant changes against commit 9efe273:

  Benchmark                                                  Metric         Change
  ================================================================================
+ ~Mathlib.LinearAlgebra.FreeModule.PID                      instructions    -9.5%
- ~Mathlib.RepresentationTheory.GroupCohomology.Resolution   instructions     1.9%

mathlib-bors bot pushed a commit that referenced this pull request Nov 8, 2023
This PR adds simp lemmas for `OfNat.ofNat n : PartENat`, `0 : PartENat`, and `1 : PartENat` in every place where there was a simp lemma for `((n : ℕ) : PartENat)`. This is necessary for simp confluence in the presence of lemmas such as `Nat.cast_ofNat`. In addition, instances for `CharZero` and `ZeroLEOneClass` are provided so that the lemmas from `Data/Nat/Cast/Order.lean` will apply, golfing some proofs.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Nov 8, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore(PartENat): golf and improve ofNat support [Merged by Bors] - chore(PartENat): golf and improve ofNat support Nov 8, 2023
@mathlib-bors mathlib-bors bot closed this Nov 8, 2023
@mathlib-bors mathlib-bors bot deleted the TCB/PartENat-cleanup branch November 8, 2023 17:06
grunweg pushed a commit that referenced this pull request Dec 15, 2023
This PR adds simp lemmas for `OfNat.ofNat n : PartENat`, `0 : PartENat`, and `1 : PartENat` in every place where there was a simp lemma for `((n : ℕ) : PartENat)`. This is necessary for simp confluence in the presence of lemmas such as `Nat.cast_ofNat`. In addition, instances for `CharZero` and `ZeroLEOneClass` are provided so that the lemmas from `Data/Nat/Cast/Order.lean` will apply, golfing some proofs.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
mathlib-bors bot pushed a commit that referenced this pull request Feb 26, 2024
…sts (#8006)

I loogled for every occurrence of `"cast", Nat` and `"natCast"` and where the casted nat was `n`, and made sure there were corresponding `@[simp]` lemmas for `0`, `1`, and `OfNat.ofNat n`. This is necessary in general for simp confluence. Example:

```lean
import Mathlib

variable {α : Type*} [LinearOrderedRing α] (m n : ℕ) [m.AtLeastTwo] [n.AtLeastTwo]

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp only [Nat.cast_le] -- this `@[simp]` lemma can apply

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) := by
  simp only [Nat.cast_ofNat] -- and so can this one

example : (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp -- fails! `simp` doesn't have a lemma to bridge their results. confluence issue.
```

As far as I know, the only file this PR leaves with `ofNat` gaps is `PartENat.lean`. #8002 is addressing that file in parallel.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
riccardobrasca pushed a commit that referenced this pull request Mar 1, 2024
…sts (#8006)

I loogled for every occurrence of `"cast", Nat` and `"natCast"` and where the casted nat was `n`, and made sure there were corresponding `@[simp]` lemmas for `0`, `1`, and `OfNat.ofNat n`. This is necessary in general for simp confluence. Example:

```lean
import Mathlib

variable {α : Type*} [LinearOrderedRing α] (m n : ℕ) [m.AtLeastTwo] [n.AtLeastTwo]

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp only [Nat.cast_le] -- this `@[simp]` lemma can apply

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) := by
  simp only [Nat.cast_ofNat] -- and so can this one

example : (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp -- fails! `simp` doesn't have a lemma to bridge their results. confluence issue.
```

As far as I know, the only file this PR leaves with `ofNat` gaps is `PartENat.lean`. #8002 is addressing that file in parallel.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
dagurtomas pushed a commit that referenced this pull request Mar 22, 2024
…sts (#8006)

I loogled for every occurrence of `"cast", Nat` and `"natCast"` and where the casted nat was `n`, and made sure there were corresponding `@[simp]` lemmas for `0`, `1`, and `OfNat.ofNat n`. This is necessary in general for simp confluence. Example:

```lean
import Mathlib

variable {α : Type*} [LinearOrderedRing α] (m n : ℕ) [m.AtLeastTwo] [n.AtLeastTwo]

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp only [Nat.cast_le] -- this `@[simp]` lemma can apply

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) := by
  simp only [Nat.cast_ofNat] -- and so can this one

example : (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp -- fails! `simp` doesn't have a lemma to bridge their results. confluence issue.
```

As far as I know, the only file this PR leaves with `ofNat` gaps is `PartENat.lean`. #8002 is addressing that file in parallel.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
xgenereux pushed a commit that referenced this pull request Apr 15, 2024
…sts (#8006)

I loogled for every occurrence of `"cast", Nat` and `"natCast"` and where the casted nat was `n`, and made sure there were corresponding `@[simp]` lemmas for `0`, `1`, and `OfNat.ofNat n`. This is necessary in general for simp confluence. Example:

```lean
import Mathlib

variable {α : Type*} [LinearOrderedRing α] (m n : ℕ) [m.AtLeastTwo] [n.AtLeastTwo]

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp only [Nat.cast_le] -- this `@[simp]` lemma can apply

example : ((OfNat.ofNat m : ℕ) : α) ≤ ((OfNat.ofNat n : ℕ) : α) ↔ (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) := by
  simp only [Nat.cast_ofNat] -- and so can this one

example : (OfNat.ofNat m : α) ≤ (OfNat.ofNat n : α) ↔ (OfNat.ofNat m : ℕ) ≤ (OfNat.ofNat n : ℕ) := by
  simp -- fails! `simp` doesn't have a lemma to bridge their results. confluence issue.
```

As far as I know, the only file this PR leaves with `ofNat` gaps is `PartENat.lean`. #8002 is addressing that file in parallel.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants