Skip to content

[Merged by Bors] - feat(Data/Set/Card): Fintype.card s = s.ncard#38426

Closed
SnirBroshi wants to merge 10 commits into
leanprover-community:masterfrom
SnirBroshi:feature/data/set/fintype-card-eq-ncard
Closed

[Merged by Bors] - feat(Data/Set/Card): Fintype.card s = s.ncard#38426
SnirBroshi wants to merge 10 commits into
leanprover-community:masterfrom
SnirBroshi:feature/data/set/fintype-card-eq-ncard

Conversation

@SnirBroshi

@SnirBroshi SnirBroshi commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

We have ↑(Fintype.card s) = s.encard but we don't yet have a theorem relating Fintype.card and Set.ncard.

This adds Fintype.card s = s.ncard for Fintype s, and also s.ncard = s.encard for Finite s.


(tagging simp is problematic since the aforementioned theorem (Set.coe_fintypeCard) is simp, and I'm not sure we should untag it)

Open in Gitpod

@SnirBroshi SnirBroshi added the easy < 20s of review time. See the lifecycle page for guidelines. label Apr 23, 2026
@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

PR summary e120fe83a7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ coe_ncard_eq_encard
+ fintypeCard_eq_ncard

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

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

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/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 23, 2026

@Vierkantor Vierkantor left a comment

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 agree with adding the lemma. This should probably be a @[simp] lemma, though. We can fix the simpNF linter by adding the following theorem:

variable (s) in
@[simp]
/-- `simpNF` form of `coe_fintypeCard`. -/
theorem ncard_eq_encard [Finite s] : s.ncard = s.encard := by
  have := Fintype.ofFinite s
  rw [← fintypeCard_eq_ncard, coe_fintypeCard]

and then removing the @[simp] from coe_fintypeCard.

(Note: this was the first proof I came up with, it might be simplifiable)

@Vierkantor Vierkantor added awaiting-author A reviewer has asked the author a question or requested changes. and removed easy < 20s of review time. See the lifecycle page for guidelines. labels Apr 27, 2026
@Vierkantor Vierkantor self-assigned this Apr 27, 2026
@SnirBroshi SnirBroshi removed the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 28, 2026
@b-mehta

b-mehta commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Tagging this simp may be a good idea, but it is a pretty big change, since it's declaring that Fintype.card ↑s is "bad". And that means that the lemmas here https://leanprover-community.github.io/mathlib4_docs/Mathlib/Data/Set/Finite/Basic.html#Cardinality should be viewed as deprecated (and the linter will yell at you until you un-simp them).
I'm 60% sure this is the right thing to do, but I think it could be wiser to make the simp change in a different PR, and keep this one as just adding the new lemma (which I'm 100% sure is the right thing to do).

@SnirBroshi

Copy link
Copy Markdown
Collaborator Author

With +31/-28 the linter is not angry anymore, though arguably we do want to add Set.ncard versions of the simp-lemmas that were untagged, and deprecate the old versions. Should the split be ("add the small lemma" + "change simpNF") + "add new Set.ncard simp lemmas" or should we postpone the simpNF changes to a new PR?

@Vierkantor

Copy link
Copy Markdown
Contributor

I would say: this PR can add the lemma but not tag it as @[simp], and then we change simp-NF in the next PR.

@SnirBroshi
SnirBroshi requested a review from Vierkantor April 29, 2026 22:30

@Vierkantor Vierkantor left a comment

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.

Thanks!

bors r+

@mathlib-triage mathlib-triage Bot added the ready-to-merge This PR has been sent to bors. label May 15, 2026
mathlib-bors Bot pushed a commit that referenced this pull request May 15, 2026
We have `↑(Fintype.card s) = s.encard` but we don't yet have a theorem relating `Fintype.card` and `Set.ncard`.

This adds `Fintype.card s = s.ncard` for `Fintype s`, and also `s.ncard = s.encard` for `Finite s`.
@mathlib-bors

mathlib-bors Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat(Data/Set/Card): Fintype.card s = s.ncard [Merged by Bors] - feat(Data/Set/Card): Fintype.card s = s.ncard May 15, 2026
@mathlib-bors mathlib-bors Bot closed this May 15, 2026
@SnirBroshi

Copy link
Copy Markdown
Collaborator Author

this PR can add the lemma but not tag it as @[simp], and then we change simp-NF in the next PR.

simpNF PR: #39414

Bergschaf pushed a commit to Bergschaf/mathlib4 that referenced this pull request Jun 3, 2026
…#38426)

We have `↑(Fintype.card s) = s.encard` but we don't yet have a theorem relating `Fintype.card` and `Set.ncard`.

This adds `Fintype.card s = s.ncard` for `Fintype s`, and also `s.ncard = s.encard` for `Finite s`.
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.

3 participants