Skip to content
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] - chore(PartENat): golf and improve ofNat support #8002

Closed
wants to merge 11 commits into from

Conversation

timotree3
Copy link
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 The author would like community review of the PR awaiting-CI labels Oct 28, 2023
@eric-wieser
Copy link
Member

!bench

@leanprover-bot
Copy link
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 which is still in the queue. label Nov 2, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the blocked-by-other-PR This PR depends on another PR which is still in the queue. label Nov 2, 2023
@leanprover-community-mathlib4-bot
Copy link
Collaborator

This PR/issue depends on:

@eric-wieser
Copy link
Member

bors d+

Pleaes merge once CI passes.

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

@mathlib-bors
Copy link

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 and removed awaiting-review The author would like community review of the PR labels Nov 8, 2023
@eric-wieser
Copy link
Member

bors merge

@eric-wieser
Copy link
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
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

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>
Louddy 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 ready-to-merge This PR has been sent to bors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants