Skip to content

feat(Combinatorics/SimpleGraph/Coloring/EdgeColoring): create a basic edge-coloring API#33313

Open
SnirBroshi wants to merge 12 commits intoleanprover-community:masterfrom
SnirBroshi:feature/simple-graph/edge-coloring
Open

feat(Combinatorics/SimpleGraph/Coloring/EdgeColoring): create a basic edge-coloring API#33313
SnirBroshi wants to merge 12 commits intoleanprover-community:masterfrom
SnirBroshi:feature/simple-graph/edge-coloring

Conversation

@SnirBroshi
Copy link
Copy Markdown
Collaborator

@SnirBroshi SnirBroshi commented Dec 26, 2025


Future work (which I'm working on):

  • Relating degrees to edge-colorability (G.maxDegree ≤ G.chromaticIndex)
  • Vizing's theorem (G.chromaticIndex ≤ G.maxDegree + 1)
  • chromaticIndex ⊤ = (if Even #V then #V - 1 else #V)
  • [Infinite α] → chromaticIndex ⊤ = ⊤

Open in Gitpod

@github-actions github-actions bot added the large-import Automatically added label for PRs with a significant increase in transitive imports label Dec 26, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 26, 2025

PR summary b31b601893

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.SimpleGraph.Coloring.EdgeColoring (new file) 1041

Declarations diff

+ EdgeColorable
+ EdgeColorable.anti
+ EdgeColorable.chromaticIndex_le
+ EdgeColorable.chromaticIndex_of_finite
+ EdgeColorable.chromaticIndex_pos
+ EdgeColorable.mono
+ EdgeColorable.of_bot
+ EdgeColorable.of_fintype
+ EdgeColorable.of_isContained
+ EdgeColorable.of_iso
+ EdgeColorable.of_lineGraph_hom
+ EdgeColorable.of_lineGraph_iso
+ EdgeColorableWith
+ EdgeColorableWith.anti
+ EdgeColorableWith.mono
+ EdgeColorableWith.of_bot
+ EdgeColorableWith.of_isContained
+ EdgeColorableWith.of_iso
+ EdgeColorableWith.of_lineGraph_hom
+ EdgeColorableWith.of_lineGraph_iso
+ EdgeColoring
+ EdgeColoring.apply_eq_iff_of_adj
+ EdgeColoring.colorClassSubgraph
+ EdgeColoring.edgeColorable
+ EdgeColoring.id
+ EdgeColoring.isMatching_colorClassSubgraph
+ EdgeColoring.ne_of_adj_lineGraph
+ EdgeColoring.ofBot
+ EdgeColoring.ofColorEmbedding
+ EdgeColoring.ofColorIso
+ EdgeColoring.ofCopy
+ EdgeColoring.ofIsSubgraph
+ EdgeColoring.ofIso
+ EdgeColoring.ofLineGraphHom
+ EdgeColoring.ofLineGraphIso
+ IsContained.chromaticIndex_le
+ Iso.chromaticIndex_eq
+ chromaticIndex
+ chromaticIndex_bot
+ chromaticIndex_eq_iff_edgeColorable_not_edgeColorable
+ chromaticIndex_eq_of_lineGraph_iso
+ chromaticIndex_le_iff_edgeColorable
+ chromaticIndex_le_of_lineGraph_hom
+ chromaticIndex_le_one_of_subsingleton
+ chromaticIndex_mono
+ chromaticIndex_ne_top_iff_exists
+ edgeColorableWith_iff_of_isEmpty
+ edgeColorable_chromaticIndex_iff
+ edgeColorable_zero_iff
+ eq_bot_of_chromaticIndex_eq_zero
+ instance : Coe (G.EdgeColoring α) (G.EdgeLabeling α)
+ two_le_chromaticIndex_of_adj

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

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

@SnirBroshi SnirBroshi added the t-combinatorics Combinatorics label Dec 26, 2025
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Dec 26, 2025
@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 Mar 22, 2026
@mathlib-dependent-issues
Copy link
Copy Markdown

@SnirBroshi SnirBroshi force-pushed the feature/simple-graph/edge-coloring branch from 151cba8 to 115da59 Compare March 22, 2026 14:46
@SnirBroshi SnirBroshi changed the title feat(Combinatorics/SimpleGraph/EdgeColoring): create a basic edge-coloring API feat(Combinatorics/SimpleGraph/Coloring/Edges): create a basic edge-coloring API Mar 22, 2026
@github-actions github-actions bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label Mar 22, 2026
@SnirBroshi SnirBroshi force-pushed the feature/simple-graph/edge-coloring branch from 115da59 to e40eb80 Compare March 22, 2026 14:47
Copy link
Copy Markdown
Collaborator

@ooovi ooovi left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! :)

Please put periods at the end of your docstrings.

Also consider moving the Coloring.lean file in the parent directory to the Coloring folder and renaming it to Basic.lean.

@SnirBroshi
Copy link
Copy Markdown
Collaborator Author

Thanks for your PR! :)

Thank you for reviewing!

Please put periods at the end of your docstrings.

I really prefer them without periods, unless there's more than one sentence.
By my count ~15% of docstrings in Mathlib don't end with a period, and the style guide shows period-less docstrings as valid.
So I think this is currently author's choice, until the maintainers decide to change the style guide.

Also consider moving the Coloring.lean file in the parent directory to the Coloring folder and renaming it to Basic.lean.

Should I do in this PR or a separate one? Also, my plan was to have something like:

  • Coloring/Vertices.lean
  • Coloring/Edges.lean
  • Coloring/ListVertices.lean
  • Coloring/ListEdges.lean
  • Coloring/ChromaticPolynomial.lean

or (if that sounds weird)

  • Coloring/VertexColoring.lean
  • Coloring/EdgeColoring.lean
  • Coloring/VertexListColoring.lean
  • Coloring/EdgeListColoring.lean
  • Coloring/ChromaticPolynomial.lean

wdyt? I agree that vertex coloring is the simplest one, but making it Basic.lean seems wrong.

@ooovi
Copy link
Copy Markdown
Collaborator

ooovi commented Apr 1, 2026

I really prefer them without periods, unless there's more than one sentence. By my count ~15% of docstrings in Mathlib don't end with a period, and the style guide shows period-less docstrings as valid. So I think this is currently author's choice, until the maintainers decide to change the style guide.

I'm afraid the documentation style guide indeed recommends that "If a doc string is a complete sentence, then it should end in a period.". Then again, many of yours are not complete sentences :)

Should I do in this PR or a separate one?

It should be a separate PR just moving the file, and then another one that deprecates the module, since those are easy to approve. This PR can then depend on them.

wdyt? I agree that vertex coloring is the simplest one, but making it Basic.lean seems wrong.

I also feel its wrong. I even remember being disappointed to find that SimpleGraph.Coloring was not the flavour I was looking for. It might even make sense to rename SimpleGraph.Coloring to SimpleGraph.VertexColoring in a separate PR, since afaict the literature just calls a graph coloring whatever it is currently interested in.

How about SimpleGraph/Labeling/VertexColoring.lean, so Labeling.lean can also live there?

@SnirBroshi
Copy link
Copy Markdown
Collaborator Author

I think coloring is a major part of graph-theory so we should have a Coloring/ folder.
EdgeLabeling is only for Ramsey's theorem. Maybe it can just live in Coloring/? Ramsey's theorem is also about colors, they just don't have any restrictions like actual coloring.

mathlib-bors bot pushed a commit that referenced this pull request Apr 2, 2026
…oloring/VertexColoring.lean` (#37525)

This is in preparation of #33313 and other material to come, here's how I imagine the folder to look like:
- `Coloring/VertexColoring.lean` (currently `Coloring.lean`)
- `Coloring/EdgeColoring.lean`
- `Coloring/VertexListColoring.lean`
- `Coloring/EdgeListColoring.lean`
- `Coloring/ChromaticPolynomial.lean`
- `Coloring/EdgeLabeling.lean` (currently `./EdgeLabeling.lean`)
- `Coloring/ConcreteColorings.lean` (currently `./ConcreteColorings.lean`)
@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 Apr 2, 2026
@mathlib-merge-conflicts
Copy link
Copy Markdown

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

@SnirBroshi SnirBroshi changed the title feat(Combinatorics/SimpleGraph/Coloring/Edges): create a basic edge-coloring API feat(Combinatorics/SimpleGraph/Coloring/EdgeColoring): create a basic edge-coloring API Apr 2, 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 Apr 2, 2026
simpa using isEmpty_of_chromaticNumber_eq_zero h

/-- Lift an embedding of colors to an embedding of edge colorings. -/
def EdgeColoring.ofColorEmbedding (f : α ↪ β) : G.EdgeColoring α ↪ G.EdgeColoring β :=
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.

Suggested change
def EdgeColoring.ofColorEmbedding (f : α ↪ β) : G.EdgeColoring α ↪ G.EdgeColoring β :=
def EdgeColoring.ofEmbedding (f : α ↪ β) : G.EdgeColoring α ↪ G.EdgeColoring β :=

recolorOfEmbedding _ f

/-- Lift an isomorphism of colors to an isomorphism of edge colorings. -/
def EdgeColoring.ofColorIso (f : α ≃ β) : G.EdgeColoring α ≃ G.EdgeColoring β :=
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.

Suggested change
def EdgeColoring.ofColorIso (f : α ≃ β) : G.EdgeColoring α ≃ G.EdgeColoring β :=
def EdgeColoring.congr (f : α ≃ β) : G.EdgeColoring α ≃ G.EdgeColoring β :=

maybe? or maybe edgeColoringEquivOfEquiv outside of the EdgeLabelling namespace? The current name is probably not suitable.

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.

edgeColoringEquivOfEquiv and edgeColoringEquivOfIso would then be separated by a slight technicality in naming. Are you sure?
I agree on un-namespacing this one, since it would allow for dot-notation on graphs.


variable (α) in
/-- Edge-colorings of graphs with isomorphic line-graphs are equivalent. -/
def EdgeColoring.ofLineGraphIso (f : G.lineGraph ≃g G'.lineGraph) :
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.

Suggested change
def EdgeColoring.ofLineGraphIso (f : G.lineGraph ≃g G'.lineGraph) :
def edgeColoringEquivOfLineGraphIso (f : G.lineGraph ≃g G'.lineGraph) :


variable (α) in
/-- Edge-colorings of isomorphic graphs are equivalent. -/
def EdgeColoring.ofIso (f : G ≃g G') : G.EdgeColoring α ≃ G'.EdgeColoring α :=
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.

Suggested change
def EdgeColoring.ofIso (f : G ≃g G') : G.EdgeColoring α ≃ G'.EdgeColoring α :=
def edgeColoringEquivOfIso (f : G ≃g G') : G.EdgeColoring α ≃ G'.EdgeColoring α :=

Copy link
Copy Markdown
Collaborator Author

@SnirBroshi SnirBroshi Apr 2, 2026

Choose a reason for hiding this comment

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

What's wrong with namespacing? (ditto for EdgeColoring.ofLineGraphIso)

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.

Actually how about Iso.edgeColoringEquiv for dot notation on Iso?

xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request Apr 3, 2026
…oloring/VertexColoring.lean` (leanprover-community#37525)

This is in preparation of leanprover-community#33313 and other material to come, here's how I imagine the folder to look like:
- `Coloring/VertexColoring.lean` (currently `Coloring.lean`)
- `Coloring/EdgeColoring.lean`
- `Coloring/VertexListColoring.lean`
- `Coloring/EdgeListColoring.lean`
- `Coloring/ChromaticPolynomial.lean`
- `Coloring/EdgeLabeling.lean` (currently `./EdgeLabeling.lean`)
- `Coloring/ConcreteColorings.lean` (currently `./ConcreteColorings.lean`)
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.

3 participants