Skip to content

feat(Combinatorics/SimpleGraph/Acyclic): a graph is a tree iff it's acyclic and has exactly n - 1 edges#34910

Open
SnirBroshi wants to merge 53 commits into
leanprover-community:masterfrom
SnirBroshi:feature/simple-graph/tree-iff-acyclic-and-n-minus-one
Open

feat(Combinatorics/SimpleGraph/Acyclic): a graph is a tree iff it's acyclic and has exactly n - 1 edges#34910
SnirBroshi wants to merge 53 commits into
leanprover-community:masterfrom
SnirBroshi:feature/simple-graph/tree-iff-acyclic-and-n-minus-one

Conversation

@SnirBroshi

@SnirBroshi SnirBroshi commented Feb 6, 2026

Copy link
Copy Markdown
Collaborator

@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

PR summary 8379122c70

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ IsAcyclic.ncard_edgeSet_add_card_connectedComponent
+ IsAcyclic.ncard_edgeSet_add_one_le_card
+ IsTree.ncard_edgeSet_add_one
+ connected_iff_card_connectedComponent_eq_one
+ edgeSetEquivSigmaConnectedComponent
+ exists_isCycle_of_card_le
+ isTree_iff_isAcyclic_and_ncard_edgeSet_add_one_eq_card
+ ofLE
+ sum_connectedComponent_ncard_edgeSet
+ sum_connectedComponent_ncard_supp
+ verticesEquivSigmaConnectedComponent

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

  • +17 new declarations
  • −0 removed declarations
+RelHom.ofLE
+RelHom.ofLE_apply
+SimpleGraph.IsAcyclic.ncard_edgeSet_add_card_connectedComponent
+SimpleGraph.IsAcyclic.ncard_edgeSet_add_one_le_card
+SimpleGraph.IsTree.ncard_edgeSet_add_one
+SimpleGraph.connected_iff_card_connectedComponent_eq_one
+SimpleGraph.edgeSetEquivSigmaConnectedComponent
+SimpleGraph.edgeSetEquivSigmaConnectedComponent_apply
+SimpleGraph.edgeSetEquivSigmaConnectedComponent_symm_apply_coe
+SimpleGraph.exists_isCycle_of_card_le
+SimpleGraph.isTree_iff_isAcyclic_and_ncard_edgeSet_add_one_eq_card
+SimpleGraph.sum_connectedComponent_ncard_edgeSet
+SimpleGraph.sum_connectedComponent_ncard_supp
+SimpleGraph.verticesEquivSigmaConnectedComponent
+SimpleGraph.verticesEquivSigmaConnectedComponent_apply_fst
+SimpleGraph.verticesEquivSigmaConnectedComponent_apply_snd_coe
+SimpleGraph.verticesEquivSigmaConnectedComponent_symm_apply

No changes to strong technical debt.

No changes to weak technical debt.

Current commit 8379122c70
Reference commit 4efb186f10

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 Feb 6, 2026
@SnirBroshi SnirBroshi added the t-combinatorics Combinatorics label Feb 6, 2026
@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 Mar 20, 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 Mar 20, 2026
@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 Jun 10, 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 Jun 11, 2026
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
@mathlib-dependent-issues mathlib-dependent-issues Bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jun 16, 2026
@mathlib-dependent-issues

Copy link
Copy Markdown

@amellendijk amellendijk 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.

Thanks!

Just some minor comments, but this all seems reasonable.

Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Connectivity/Connected.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
obtain ⟨F, hF⟩ := G.exists_isAcyclic_reachable_eq_le_of_le_of_isAcyclic bot_le isAcyclic_bot
grind [IsTree, Connected, preconnected_iff_reachable_eq_top]

theorem connected_iff_card_connectedComponent_eq_one :

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.

Is it possible to move this to Connectivity/Connected.lean?

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.

Not without import changes as it doesn't import Nat.card. It is imported in Connectivity/Subgraph.lean and Connectivity/EdgeConnectivity.lean, but they also seem weird.

#40624 will fix the import issues, but no one commented on it yet.

Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Comment thread Mathlib/Order/RelIso/Basic.lean Outdated
exact Finset.card_lt_card <| by simpa [deleteEdges, edgeFinset]

/-- An acyclic graph on `n` vertices with `c` connected components has exactly `n - c` edges -/
theorem IsAcyclic.ncard_edgeSet_add_card_connectedComponent [Finite V] (h : G.IsAcyclic) :

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 the naming is fine, but sometimes while naming we are using the plural connectedComponents such as colorable_iff_forall_connectedComponents, and sometimes not, what do you think is best?

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.

The only uses of the plural seem to be what you mentioned and homOfConnectedComponents. I think colorable_iff_forall_connectedComponents is a typo, and homOfConnectedComponents is probably fine since it's a def.

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.

Good point, fixed in #41648.

Comment thread Mathlib/Combinatorics/SimpleGraph/Acyclic.lean Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants