Skip to content

chore(Combinatorics/SimpleGraph/Copy): replace file-wide @[expose] with selective exposure#38843

Open
FordUniver wants to merge 14 commits into
leanprover-community:masterfrom
FordUniver:chore/copy-expose
Open

chore(Combinatorics/SimpleGraph/Copy): replace file-wide @[expose] with selective exposure#38843
FordUniver wants to merge 14 commits into
leanprover-community:masterfrom
FordUniver:chore/copy-expose

Conversation

@FordUniver

@FordUniver FordUniver commented May 2, 2026

Copy link
Copy Markdown
Collaborator

Removes the file-wide @[expose] public section and restores selective @[expose] only on the small constructive defs that need cross-module reduction: Copy.toEmbedding, Copy.id, Copy.ofLE, Copy.topEmbedding — each has an exported @[simp] lemma proved by rfl that needs the definition unfolded to typecheck. Replaces @[simps!] on topEmbedding with an explicit @[simp] topEmbedding_apply to avoid a private _proof_1 term leaking into generated lemma names; adds toEmbedding_apply to match the existing toHom_apply. Switches IsIndContained from def to abbrev so the structural alias Nonempty (G ↪g H) stays transparent, matching IsContained and Free.

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


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

The noncomputable counts copyCount and unlabeledCopyCount are deliberately not exposed (see @plp127's review on #38631 explaining that unfolding a classical-Fintype.card body is rarely what you want); the downstream consumers in #38631 bridge via public *_eq_nat_card lemmas introduced in #38931 instead.

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

github-actions Bot commented May 2, 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 May 2, 2026

Copy link
Copy Markdown

PR summary cb0352fd14

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
+ toEmbedding_apply
+ topEmbedding_apply
+ 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 cb0352f).

  • +11 new declarations
  • −3 removed declarations
+SimpleGraph.Copy.toEmbedding_apply
+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.

Decrease in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5012 -1 exposed public sections

Current commit cb0352fd14
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).

@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 2, 2026
@github-actions github-actions Bot added the t-combinatorics Combinatorics label May 2, 2026
@FordUniver
FordUniver requested review from YaelDillies and plp127 May 2, 2026 08:51
@FordUniver
FordUniver marked this pull request as ready for review May 2, 2026 08:53
@github-actions github-actions Bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label May 4, 2026
@FordUniver
FordUniver force-pushed the chore/copy-expose branch from ca537f2 to 6fc9d09 Compare May 4, 2026 09:52
@github-actions github-actions Bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label May 4, 2026
@YaelDillies YaelDillies changed the title chore(Combinatorics.SimpleGraph.Copy): replace file-wide @[expose] with selective exposure chore(Combinatorics/SimpleGraph/Copy): replace file-wide @[expose] with selective exposure May 4, 2026
@FordUniver
FordUniver force-pushed the chore/copy-expose branch from 6fc9d09 to b217bf7 Compare May 12, 2026 12:37
@FordUniver FordUniver removed 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-expose branch 2 times, most recently from 0be21dc to 18f1ef5 Compare May 13, 2026 09:43
@FordUniver FordUniver added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label May 13, 2026
@mathlib-dependent-issues

mathlib-dependent-issues Bot commented May 13, 2026

Copy link
Copy Markdown

@FordUniver
FordUniver force-pushed the chore/copy-expose branch 3 times, most recently from 8c8e5d6 to 3d36b12 Compare May 13, 2026 13:04
@FordUniver
FordUniver force-pushed the chore/copy-expose branch from 3d36b12 to 5833af8 Compare May 13, 2026 14:48
@FordUniver
FordUniver marked this pull request as draft May 13, 2026 15:00
@mathlib-bors

mathlib-bors Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in draft mode. No active bors state needed cleanup.

While this PR remains draft, bors will ignore commands on this PR. Mark it ready for review before using commands like bors r+ or bors try.

@FordUniver
FordUniver force-pushed the chore/copy-expose branch 2 times, most recently from 7c1a473 to 78d141d Compare May 13, 2026 16:06
@FordUniver
FordUniver force-pushed the chore/copy-expose branch from af04a3f to a937b24 Compare May 17, 2026 17:05
FordUniver added a commit to FordUniver/mathlib4 that referenced this pull request May 18, 2026
…se]`

Match the stack convention (cf. leanprover-community#38843): use `public section` rather than
`@[expose] public section`, since no `def` in this file has a `@[simp]`
companion lemma proved by `rfl` that needs cross-module reduction. The
`autCount_eq_nat_card` bridge is rewritten to use `by rw [autCount]`
instead of `rfl`, matching `copyCount_eq_nat_card` / `unlabeledCopyCount_eq_nat_card`.
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@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
@FordUniver
FordUniver force-pushed the chore/copy-expose branch from a937b24 to d1f889a 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
@FordUniver FordUniver changed the title chore(Combinatorics/SimpleGraph/Copy): replace file-wide @[expose] with selective exposure chore(Combinatorics/SimpleGraph/Copy): replace file-wide @[expose] with selective exposure May 28, 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.
@YaelDillies
YaelDillies removed their request for review July 1, 2026 06:12
FordUniver and others added 5 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.
…th selective exposure

Replace `@[expose] public section` with a plain `public section` and
restore selective `@[expose]` on only the declarations that need
cross-module reduction:

* `Copy.toEmbedding`, `Copy.id`, `Copy.ofLE`, `Copy.topEmbedding` — the
  small constructive copy `def`s, kept transparent so consumers can
  elaborate against them by reducing.
* `copyCount`, `subCount` — the noncomputable counts. These need to be
  exposed so downstream files (e.g. the upcoming `InducedCopy.lean` in
  feat/ind-copy-count) can prove bridging inequalities like
  `embCount_le_copyCount` and `indSubCount_le_subCount` directly via
  `Nat.card_le_card_of_injective`.

Also:

* Inline the `@[simps!]` projections of `Copy.topEmbedding` into a manual
  `@[simp] lemma topEmbedding_apply` (and similarly for `Copy.toEmbedding`).
  The auto-generated `simps` form attached to `@[simps!]` was opaque to
  cross-module simp; the manual form is small enough to ship as a one-line
  named lemma. The body of `topEmbedding` is also tightened from
  `fun {v w} ↦ ⟨fun h ↦ by simpa using h.ne, _⟩` to
  `fun {_ _} ↦ ⟨fun h ↦ f.injective.ne_iff.mp h.ne, _⟩`.
* `IsIndContained` switches from `def` to `abbrev`, since the body
  `Nonempty (G ↪g H)` is small and downstream Lean elaboration benefits
  from automatic unfolding here.
@github-actions github-actions Bot added the tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip label Jul 12, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@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
@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
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) new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-combinatorics Combinatorics tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant