Skip to content

refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, align variable names, clean up docstring#38745

Open
FordUniver wants to merge 12 commits into
leanprover-community:masterfrom
FordUniver:chore/copy-spelling
Open

refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, align variable names, clean up docstring#38745
FordUniver wants to merge 12 commits into
leanprover-community:masterfrom
FordUniver:chore/copy-spelling

Conversation

@FordUniver

@FordUniver FordUniver commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Renames labelledCopyCount to copyCount and reassigns the previous copyCount to unlabeledCopyCount. Unifies graph-variable letters to the standard Guest / Host convention. Restructures and cleans up the module docstring.

Co-authored-by: Malte Jackisch 45597826+MaltyBlanket@users.noreply.github.com


Step 2/5 of the Copy / InducedCopy refactor-feat stack.

Originally motivated by a adiscussion in #38631 by @SnirBroshi that the British spelling of labelled is deprecated; see also discussion on Zulip (#general > SimpleGraph.Copy is labeled but copyCount is not). The addition of the new UnlabeledCopy type was separated into #39307 as a requirement to keep the diff somewhat readable.

On top of the Zulip discussion I also unified the argument naming to always follow the Guest / Host convention. This highlighted a discrepancy where we write Copy G H but copyCount H G. I left this untouched since small-first-big-later seems to be the type and big-first-small-later the ops norm in mathlib. I am happy to align them if someone has a strong opinion either way.

I also adjusted a ton of docstrings since the rename was already touching them, so it seemed sensible to use this opportunity for cleanup. Open to suggestions for what should be done differently.

I also considered replacing Bot/Top with EmptyGraph/CompleteGraph in args and statement names (@SnirBroshi that was the now-closed #39303 ) because I thought that was established with #23838 but it seems controversial, so I have reverted it.

notion before after
labelled copy / injective hom / monomorphism Copy A B Copy G H
count of labelled copies G.labelledCopyCount H H.copyCount G
count of unlabelled copies G.copyCount H H.unlabeledCopyCount G
killing operation G.killCopies H H.killCopies G
graph variables mixed A B C / α β γ and G H I / V W X uniform G H I / V W X (+ G'/H' on V'/W')

Diff for the changes just in this PR over its predecessor: link

@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 29, 2026
@github-actions

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 29, 2026

Copy link
Copy Markdown

PR summary 4a320e882c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ UnlabeledCopy
+ instance : FunLike (Copy G H) V W
+ instance : IsPreorder (SimpleGraph V) IsContained
+ instance : IsPreorder (SimpleGraph V) IsIndContained
+ le_card_edgeFinset_killCopies_add_unlabeledCopyCount
+ uniqueUnlabeledCopyBot
+ unlabeledCopyCount
+ unlabeledCopyCount_bot
+ unlabeledCopyCount_eq_card_image_copyToSubgraph
+ unlabeledCopyCount_eq_zero
+ unlabeledCopyCount_le_copyCount
+ unlabeledCopyCount_of_isEmpty
+ unlabeledCopyCount_pos
- copyCount_bot
- copyCount_le_labelledCopyCount
- instance : FunLike (Copy A B) α β
- instance : IsPreorder (SimpleGraph α) IsContained
- instance : IsPreorder (SimpleGraph α) IsIndContained
- le_card_edgeFinset_killCopies_add_copyCount

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 4a320e8).

  • +10 new declarations
  • −3 removed declarations
+SimpleGraph.UnlabeledCopy
-SimpleGraph.copyCount_bot
-SimpleGraph.copyCount_le_labelledCopyCount
-SimpleGraph.le_card_edgeFinset_killCopies_add_copyCount
+SimpleGraph.le_card_edgeFinset_killCopies_add_unlabeledCopyCount
+SimpleGraph.uniqueUnlabeledCopyBot
+SimpleGraph.unlabeledCopyCount
+SimpleGraph.unlabeledCopyCount_bot
+SimpleGraph.unlabeledCopyCount_eq_card_image_copyToSubgraph
+SimpleGraph.unlabeledCopyCount_eq_zero
+SimpleGraph.unlabeledCopyCount_le_copyCount
+SimpleGraph.unlabeledCopyCount_of_isEmpty
+SimpleGraph.unlabeledCopyCount_pos

No changes to strong technical debt.

No changes to weak technical debt.

Current commit 4a320e882c
Reference commit 47550252e7

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

Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
@plp127 plp127 added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 29, 2026
@FordUniver FordUniver removed the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 30, 2026
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Copy.lean Outdated
@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 30, 2026
@FordUniver FordUniver removed the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 30, 2026
@FordUniver FordUniver changed the title chore(Combinatorics/SimpleGraph/Copy): rename labelledCopyCount, add @[no_expose] chore(Combinatorics/SimpleGraph/Copy): rename labelledCopyCount Apr 30, 2026
@FordUniver FordUniver added the awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there label May 11, 2026
@FordUniver

FordUniver commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Labeled with awaiting-zulip based on #general>SimpleGraph.Copy is labeled but copyCount is not. The question is whether to enforce both labeled and unlabeled as a prefix for copyCount and deprecate the un-prefixed version. If so, this PR would probably be a natural place to do so.

@FordUniver
FordUniver force-pushed the chore/copy-spelling branch from d4abe3f to 498eb74 Compare May 12, 2026 12:58
@FordUniver FordUniver removed the awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there label May 12, 2026
@FordUniver FordUniver changed the title chore(Combinatorics/SimpleGraph/Copy): rename labelledCopyCount refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, introduce Sub subtype May 12, 2026
@mathlib-dependent-issues mathlib-dependent-issues Bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label May 12, 2026
@FordUniver
FordUniver force-pushed the chore/copy-spelling branch 7 times, most recently from d30310b to 33a7a17 Compare May 12, 2026 17:42
@FordUniver FordUniver changed the title refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, introduce Sub subtype refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, align variable names, clean up docstring May 13, 2026
@FordUniver

Copy link
Copy Markdown
Collaborator Author

Updated the PR per discussion on zulip, also aligned the variable names to follow Guest / Host convention after checking with @YaelDillies and cleaned up docstrings. Also split up the abbrev Sub into a prerequisite PR (#39307).

Ready to be reviewed again. Use this link for the diff over #39307.

@mitchell-horner mitchell-horner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is a good idea. I sense Sub will be unpopular as a name (I personally don't mind it), but I agree with the shape of everything.

graph embedding, as we do not require the subgraph to be induced).

If there exists an induced copy of `G` in `H`, we say that `H` *inducingly contains* `G`. This is
equivalent to saying that there is a graph embedding `G ↪ H`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I actually would rather this the other way around. That H is the smaller contained graph and G is the larger graph.

The idea being that H.Free G looks like a predicate "is $G$ a $H$-free graph".

I understand this is purely cosmetic, but that is how it is written in extremal/*.lean and it would be nice to be consistent if we are going through rewriting variables, etc.

That is, H < G < I should be the order.

I had originally used A, B, C to be generic but that was a poor choice in retrospect. 😅

@FordUniver FordUniver May 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am not quite sure I follow what convention you are suggesting? To use different variable letters or different variable order? There is three different things overall:

  1. What letters do we use for SimpleGraph variables (G, H, I or A, B, C)?
  2. Do we (try to) use consistent letters to highlight the "small" in relation to the "large" graphs?
  3. In which order do "small" and "large" graph appear as arguments of any particular definition or statement.

I believe the file was previously inconsistent with respect to all three. Now it is only (somewhat) inconsistent with respect to (3): types (Copy) are big-first while ops (copyCount) are small first. This is somewhat in line with mathlib practices though I couldn't find any other examples where type and op are so closely linked in name as Copy and copyCount.

W.r.t. the order I don't have any particularly strong opinion, i.e., I can swap the order of both / either Copy and copyCount. If we wanted to avoid any confusion, we could have more verbose names FreeOf, FreeFrom, copyCountOf, copyCountIn, ...

But what I would find very confusing is to use G for the big graph and H for the smaller one or to just have an "alphabetic by argument order" convention, i.e., we would have copy G H and copyCount G H but the variable names do not align. I am not sure how common this convention is, but I have always liked the Guest / Host mnemonic.

@FordUniver
FordUniver force-pushed the chore/copy-spelling branch 2 times, most recently from 3149dcc to 61742e2 Compare May 17, 2026 16:38
@mathlib-merge-conflicts mathlib-merge-conflicts 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 23, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@FordUniver
FordUniver force-pushed the chore/copy-spelling branch from 61742e2 to e65532e Compare May 25, 2026 07:10
@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 25, 2026
Adds `abbrev Sub A B := {B' : B.Subgraph // Nonempty (A ≃g B'.coe)}`, the
subtype of `SimpleGraph.Subgraph`s of `B` isomorphic to `A`. Redefines
`copyCount G H` via `Fintype.card (H.Sub G)`, replacing the previous inline
filter-set body, and rewrites the affected proofs (`copyCount_eq_zero`,
`copyCount_pos`, `copyCount_le_labelledCopyCount`, `copyCount_bot`,
`le_card_edgeFinset_killCopies`) to use `Sub` directly.

The singleton-empty-subgraph reasoning previously inlined in `copyCount_bot`'s
proof is factored out as `instance uniqueSubBot (G : SimpleGraph V) :
Unique ((⊥ : SimpleGraph V).Sub G)`, making `copyCount_bot` a one-liner via
`Fintype.card_unique`. The cardinality proof inside the instance stays inline
to keep the introduction minimal — extraction to a separate private helper
and the rename to `_emptyGraph` per the convention from leanprover-community#23838 (and adopted
in `AdjMatrix.lean`) happen in the next PR.

Drops `copyCount_eq_card_image_copyToSubgraph` (the legacy bridge between the
filter-set and Finset.image-of-Copy.toSubgraph forms) — unused after the
type-form refactor.
@FordUniver
FordUniver force-pushed the chore/copy-spelling branch from e65532e to d49d816 Compare June 13, 2026 19:55
@YaelDillies
YaelDillies removed their request for review July 1, 2026 06:12
FordUniver and others added 4 commits July 8, 2026 17:24
…copyToSubgraph as deprecated

Restores the exact statement of the legacy bridge lemma dropped when copyCount
was redefined via UnlabeledCopy, now carrying @[deprecated] (since 2026-07-12)
per review, with a proof against the new Fintype.card (H.UnlabeledCopy G) body.
…y graph variables

Aligns the labelled/unlabelled naming in `Copy.lean` so that the type `Copy G H`
(labelled, injective hom from `G` into `H`) is paired with the count
`H.copyCount G` (labelled count, host-first per mathlib op convention) and the
`UnlabeledCopy G H` carrier (introduced in the previous PR) is paired with the
count `H.unlabeledCopyCount G`. Also unifies the graph-variable letters: the
`A B C` set that was local to `Copy.lean` is dropped in favour of mathlib's
wider `G H I` convention, with `α β γ` → `V W X` correspondingly. Within the
new convention `G` is the guest (pattern, contained side) and `H` is the host
(container), matching `G ⊑ H` and the hom direction `G →g H`.

Types are guest-first (`Copy G H`, `UnlabeledCopy G H`); operations are
host-first via dot notation (`H.copyCount G`, `H.unlabeledCopyCount G`,
`H.killCopies G`). This matches the existing mathlib convention split (hom
types use source-first, host-side operations use the host as the dot-notation
receiver).

Changes:

* Rename `labelledCopyCount → copyCount` (with British `@[deprecated]` alias
  `labelledCopyCount`). The previous `copyCount → unlabeledCopyCount` rename
  has no alias — `copyCount` is reassigned to mean the labelled count. Same
  for the `_of_isEmpty` / `_eq_zero` / `_pos` lemma families.
* Rename `copyCount_bot → unlabeledCopyCount_bot` (count name rename only;
  `_bot` spelling preserved per @SnirBroshi).
* Unify `A B C / α β γ` to `G H I / V W X` throughout. Variable block follows
  the mathlib convention (cf. `SimpleGraph/Maps.lean`): subscripted names
  (`G₁ G₂ G₃`) for same-vertex-type variants used in `≤` chains and `ofLE`;
  primed names (`G'`, `H'`) on independent universes (`V'`, `W'`) for the
  cross-universe variants used in `isContained_congr` / `free_congr` (and
  their `_left` / `_right` partial-iso forms). This preserves the universe
  polymorphism the old `A B C / α β γ` block provided implicitly and that
  `Extremal/Basic.lean` (line 96, `← free_congr .refl (.map e G)`) relies on.
* Fix the docstring direction on `IsContained.trans` and `.trans'`: the
  previous wording ("`G` contains `H`") read the relation backwards relative
  to the lemma signature (`G ⊑ H` means `G` is contained in `H`).
* Update module docstring (`UnlabeledCopy` / `unlabeledCopyCount` bullets,
  logical-flow ordering, `SimpleGraph.Subgraph` cross-references); add TODOs
  for `homCount` and the three densities.
@FordUniver
FordUniver force-pushed the chore/copy-spelling branch from d49d816 to 3669ba6 Compare July 12, 2026 02:21
@mathlib-merge-conflicts mathlib-merge-conflicts 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 Jul 17, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@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 Jul 17, 2026
@FordUniver FordUniver removed the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants