Skip to content

feat(Data/Fintype/Card): existsUnique_notMem_image_of_injective_of_card_succ#37720

Open
cjrl wants to merge 13 commits into
leanprover-community:masterfrom
cjrl:existsUnique_not_mem_image_of_card_succ
Open

feat(Data/Fintype/Card): existsUnique_notMem_image_of_injective_of_card_succ#37720
cjrl wants to merge 13 commits into
leanprover-community:masterfrom
cjrl:existsUnique_not_mem_image_of_card_succ

Conversation

@cjrl

@cjrl cjrl commented Apr 7, 2026

Copy link
Copy Markdown

This pull requests adds a small theorem existsUnique_notMem_image_of_injective_of_card_succ to Mathlib/Data/Fintype/Card that says given an injective map f : α → β such that β has cardinality one more than α, there exists a unique element of β not in the image of f.

This can be viewed as going in the opposite direction of card_lt_of_injective_of_notMem.

This little fact is needed for our Latin Square PR #36698.


Open in Gitpod

Co-authored-by: Christopher J. R. Lloyd <cjl8zf@virginia.edu>
Co-authored-by: George H. Seelinger <ghseeli@gmail.com>
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Apr 7, 2026
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

PR summary 03d14ad0b5

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ card_eq_one_iff_existsUnique
+ existsUnique_mem_codomain_notMem_image_of_injective_of_card_eq_add_one
+ existsUnique_notMem_image_of_injective_of_card_eq_add_one

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.

Declarations diff (Lean)

Lean-aware diff — post-build, computed from the Lean environment (commit 03d14ad).

  • +3 new declarations
  • −0 removed declarations
+Finset.card_eq_one_iff_existsUnique
+Finset.existsUnique_mem_codomain_notMem_image_of_injective_of_card_eq_add_one
+Fintype.existsUnique_notMem_image_of_injective_of_card_eq_add_one

No changes to strong technical debt.

No changes to weak technical debt.

Current commit 03d14ad0b5
Reference commit 859caf703c

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 7, 2026
@cjrl cjrl marked this pull request as ready for review April 7, 2026 01:41
ghseeli added a commit to cjrl/mathlib4 that referenced this pull request Apr 8, 2026
Co-authored-by: Christopher J. R. Lloyd <cjl8zf@virginia.edu>
Co-authored-by: George H. Seelinger <ghseeli@gmail.com>
@cjrl

cjrl commented Apr 8, 2026

Copy link
Copy Markdown
Author

+t-set-theory

@github-actions github-actions Bot added the t-set-theory Set theory label Apr 8, 2026
Comment thread Mathlib/Data/Fintype/Card.lean Outdated
Comment thread Mathlib/Data/Fintype/Card.lean Outdated
cjrl and others added 3 commits April 12, 2026 11:33
Co-authored-by: Iván Renison <85908989+IvanRenison@users.noreply.github.com>
Thanks for this!

Co-authored-by: Iván Renison <85908989+IvanRenison@users.noreply.github.com>
Comment thread Mathlib/Data/Fintype/Card.lean Outdated
@dagurtomas dagurtomas added the awaiting-author A reviewer has asked the author a question or requested changes. label May 13, 2026
Co-authored-by: Dagur Asgeirsson <dagurtomas@gmail.com>
@ghseeli

ghseeli commented May 13, 2026

Copy link
Copy Markdown

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label May 13, 2026
@dagurtomas

Copy link
Copy Markdown
Contributor

Here is a slightly better approach, that results in more usable lemmas:

theorem card_image_compl_of_injective [DecidableEq β]
    (f : α → β) (hf : f.Injective) : #(univ \ univ.image f) = card β - card α := by
  simp [card_sdiff, card_image_of_injective _ hf]

/-- Given an injective map `f : α → β` such that `β` has cardinality one more
than `α`, there exists a unique element of `β` not in the image of `f`. -/
theorem existsUnique_notMem_image_of_injective_of_card_eq_add_one [DecidableEq β]
    (f : α → β) (hf : f.Injective) (h : card β = card α + 1) : ∃! x, x ∉ univ.image f := by
  have : #(univ \ univ.image f) = 1 := by grind [card_image_compl_of_injective]
  suffices ∃! x, x ∈ univ \ univ.image f by convert this; grind
  sorry -- prove a lemma saying `#s = 1 ↔ ∃! x, x ∈ s` for finsets in general (add it in the same place as `card_eq_one`)

@dagurtomas dagurtomas added the awaiting-author A reviewer has asked the author a question or requested changes. label May 14, 2026
@github-actions github-actions Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 14, 2026
@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 May 14, 2026
@cjrl

cjrl commented May 17, 2026

Copy link
Copy Markdown
Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label May 17, 2026
Comment thread Mathlib/Data/Fintype/Card.lean Outdated
Comment thread Mathlib/Data/Finset/Card.lean Outdated
Comment thread Mathlib/Data/Fintype/Card.lean
@b-mehta b-mehta added the awaiting-author A reviewer has asked the author a question or requested changes. label Jun 4, 2026
Co-authored-by: Christopher J. R. Lloyd <cjl8zf@virginia.edu>
Co-authored-by: George H. Seelinger <ghseeli@gmail.com>
@ghseeli

ghseeli commented Jun 5, 2026

Copy link
Copy Markdown

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Jun 5, 2026
@ghseeli ghseeli temporarily deployed to cache-upload-forks June 5, 2026 01:17 — with GitHub Actions Inactive
Comment thread Mathlib/Data/Fintype/Card.lean Outdated
Comment on lines +256 to +264
/-- Given an injective map `f : α → β` for finite sets `s ⊂ α` and `t ⊂ β` such that `t` has
cardinality one more than `s`, there exists a unique element of `t` not in `f(s)`. -/
theorem existsUnique_mem_codomain_notMem_image_of_injective_of_card_eq_add_one {α β : Type*}
{s : Finset α} {t : Finset β} [DecidableEq β]
(f : α → β) (hf : f.Injective) (hf' : Set.MapsTo f s t) (h : #t = #s + 1) :
∃! x, x ∈ t ∧ x ∉ s.image f := by
have : #(t \ s.image f) = 1 := by
grind [card_sdiff_of_subset hf'.finsetImage_subset, card_image_of_injective _ hf]
simpa [card_eq_one_iff_existsUnique] using this

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.

Oops - I should've mentioned this before, but this one should go in Data/Finset/Card, rather than being here. You can also likely avoid some of the variables, because they'll be in the local context already.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We went ahead and moved it to the Finset/Card file as you suggested, but we were not quite sure where to put it. It had to go pretty far down in the file, though, since the proof used other lemmas that were down there!

@ghseeli ghseeli temporarily deployed to cache-upload-forks June 5, 2026 02:55 — with GitHub Actions Inactive
ghseeli and others added 2 commits June 6, 2026 20:06
Placed it lower in the file so it can use dependent lemmas in proof.

Co-authored-by: Christopher J. R. Lloyd <cjl8zf@virginia.edu>
Co-authored-by: George H. Seelinger <ghseeli@gmail.com>
Co-authored-by: Christopher J. R. Lloyd <cjl8zf@virginia.edu>
Co-authored-by: George H. Seelinger <ghseeli@gmail.com>
@ghseeli ghseeli temporarily deployed to cache-upload-forks June 7, 2026 01:01 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-data Data (lists, quotients, numbers, etc) t-set-theory Set theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants