refactor(Combinatorics/SimpleGraph/Copy): rename copy counts, align variable names, clean up docstring#38745
Conversation
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 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. |
PR summary 4a320e882cImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
Labeled with |
d4abe3f to
498eb74
Compare
Sub subtype
d30310b to
33a7a17
Compare
Sub subtype|
Updated the PR per discussion on zulip, also aligned the variable names to follow Ready to be reviewed again. Use this link for the diff over #39307. |
mitchell-horner
left a comment
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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
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. 😅
There was a problem hiding this comment.
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:
- What letters do we use for
SimpleGraphvariables (G,H,IorA,B,C)? - Do we (try to) use consistent letters to highlight the "small" in relation to the "large" graphs?
- 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.
3149dcc to
61742e2
Compare
|
This pull request has conflicts, please merge |
61742e2 to
e65532e
Compare
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.
e65532e to
d49d816
Compare
…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.
d49d816 to
3669ba6
Compare
|
This pull request has conflicts, please merge |
Renames
labelledCopyCounttocopyCountand reassigns the previouscopyCounttounlabeledCopyCount. Unifies graph-variable letters to the standardGuest /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/InducedCopyrefactor-feat stack.Originally motivated by a adiscussion in #38631 by @SnirBroshi that the British spelling of
labelledis deprecated; see also discussion on Zulip (#general > SimpleGraph.Copy is labeled but copyCount is not). The addition of the newUnlabeledCopytype 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 writeCopy G HbutcopyCount 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/TopwithEmptyGraph/CompleteGraphin 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.Copy A BCopy G HG.labelledCopyCount HH.copyCount GG.copyCount HH.unlabeledCopyCount GG.killCopies HH.killCopies GA B C/α β γandG H I/V W XG H I/V W X(+G'/H'onV'/W')UnlabeledCopycarrier subtype #39307Diff for the changes just in this PR over its predecessor: link