Skip to content

feat(*/Fin/*): add lemmas#21112

Closed
urkud wants to merge 7 commits intomasterfrom
YK-fin-lemmas
Closed

feat(*/Fin/*): add lemmas#21112
urkud wants to merge 7 commits intomasterfrom
YK-fin-lemmas

Conversation

@urkud
Copy link
Copy Markdown
Member

@urkud urkud commented Jan 27, 2025

@urkud urkud added t-order Order theory t-data Data (lists, quotients, numbers, etc) labels Jan 27, 2025
@urkud urkud requested a review from grunweg January 27, 2025 03:39
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 27, 2025

PR summary 224861affc

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ cast_top
+ mk_zero'

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>

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


No changes to technical debt.

You can run this locally as

./scripts/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).

Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

I have one comment, about possible simplifications. Otherwise, the changes look good to me; I haven't checked yet if the simp tagging is fine etc.

@grunweg grunweg added the awaiting-author A reviewer has asked the author a question or requested changes. label Jan 27, 2025
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem mk_zero' (n : ℕ) (hn : 0 < n) : (⟨0, hn⟩ : Fin n) = haveI : NeZero n := .of_pos hn; 0 := rfl
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure whether we want this @[simp] lemma to apply to any (⟨0, hn⟩ : Fin n) (as it is written now) or only if [NeZero n] is in the context. In the former case (as it's written now), it forces us to write LHS of other simp lemmas as haveI : NeZero expr := _; ... (0 : Fin expr) instead of (⟨0, _⟩ : Fin expr).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kim-em WDYT? This lemma (in this form or in the (n : Nat) [NeZero n] form) is an obvious candidate for replacing Fin.mk_zero in the Lean core. Which form has more chances to get accepted?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer the NeZero version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both versions have NeZero, just at different places. In one case, simp can lead to expressions that use NeZero instances that aren't in the context. In another case, adding a local NeZero instance may break simp calls.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I went through git grep 'haveI.*NeZero', and found that Fin.cast_zero and PNat.mk_ofNat are the only lemmas that introduce an inline NeZero instance to state the lemma.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've created #21229 which assumes [NeZero _] instead of adding inline instances. CC: @kim-em

@urkud urkud removed the awaiting-author A reviewer has asked the author a question or requested changes. label Jan 27, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 27, 2025
mathlib-bors bot pushed a commit that referenced this pull request Jan 27, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 27, 2025
urkud added a commit that referenced this pull request Jan 28, 2025
Cherry-picked parts of #21112 that don't rely on a decision
about inline `haveI : NeZero n := _`
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 28, 2025
mathlib-bors bot pushed a commit that referenced this pull request Jan 28, 2025
Cherry-picked parts of #21112 that don't rely on a decision
about inline `haveI : NeZero n := _`
@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 28, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 28, 2025
@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 28, 2025
@urkud urkud marked this pull request as draft January 28, 2025 19:00
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 29, 2025
mathlib-bors bot pushed a commit that referenced this pull request Jan 29, 2025
... adding `[NeZero n]` as needed.

Cherry-picked from #21112
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 29, 2025
@mathlib4-dependent-issues-bot
Copy link
Copy Markdown
Collaborator

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 29, 2025
@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 29, 2025
@urkud urkud closed this Jan 29, 2025
@urkud urkud deleted the YK-fin-lemmas branch January 29, 2025 18:59
mathlib-bors bot pushed a commit that referenced this pull request Jan 29, 2025
This is a version of #21112 that doesn't use inline `NeZero` instances, thus doesn't break `simp` normal forms all over the place.
jt496 pushed a commit that referenced this pull request Feb 3, 2025
This is a version of #21112 that doesn't use inline `NeZero` instances, thus doesn't break `simp` normal forms all over the place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-data Data (lists, quotients, numbers, etc) t-order Order theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants