Skip to content

feat(Combinatorics/Quiver/Path): simple paths, cycles and acyclic quivers - #45034

Open
mkaratarakis wants to merge 3 commits into
leanprover-community:masterfrom
mkaratarakis:quiver-path-cycle
Open

mkaratarakis wants to merge 3 commits into
leanprover-community:masterfrom
mkaratarakis:quiver-path-cycle

Conversation

@mkaratarakis

@mkaratarakis mkaratarakis commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Quiver.Path.IsSimple and Quiver.Path.IsCycle, plus Quiver.IsAcyclic, modelled on what we already have for SimpleGraph.Walk.

The main result is that a path revisiting a vertex can be shortened by cutting out the loop. In particular, a shortest nontrivial loop is a cycle.


Split from #39916.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

PR summary cbd682d415

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.Quiver.Path.Cycle (new file) 524

Declarations diff (regex)

+ IsAcyclic
+ IsAcyclic.eq_nil
+ IsAcyclic.not_isCycle
+ IsCycle
+ IsCycle.of_minimal_length
+ IsSimple
+ IsSimple.nil
+ exists_length_add_eq_of_getElem_eq
+ exists_length_lt_of_not_isCycle
+ exists_length_lt_of_not_isSimple
+ isCycle_def
+ isSimple_cons
+ isSimple_def

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

  • +24 new declarations
  • −0 removed declarations
+Quiver.IsAcyclic
+Quiver.IsAcyclic.eq_nil
+Quiver.IsAcyclic.not_isCycle
+Quiver.Path.IsCycle
+Quiver.Path.IsCycle.casesOn
+Quiver.Path.IsCycle.length_ne_zero
+Quiver.Path.IsCycle.mk
+Quiver.Path.IsCycle.of_minimal_length
+Quiver.Path.IsCycle.rec
+Quiver.Path.IsCycle.recOn
+Quiver.Path.IsCycle.vertices_dropLast_nodup
+Quiver.Path.IsSimple
+Quiver.Path.IsSimple.casesOn
+Quiver.Path.IsSimple.mk
+Quiver.Path.IsSimple.nil
+Quiver.Path.IsSimple.rec
+Quiver.Path.IsSimple.recOn
+Quiver.Path.IsSimple.vertices_nodup
+Quiver.Path.exists_length_add_eq_of_getElem_eq
+Quiver.Path.exists_length_lt_of_not_isCycle
+Quiver.Path.exists_length_lt_of_not_isSimple
+Quiver.Path.isCycle_def
+Quiver.Path.isSimple_cons
+Quiver.Path.isSimple_def

No changes to strong technical debt.

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

Current commit cbd682d415
Reference commit bdece672cb

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

@github-actions github-actions Bot added the t-combinatorics Combinatorics label Oct 19, 2026
@mkaratarakis
mkaratarakis force-pushed the quiver-path-cycle branch 2 times, most recently from 2fe3010 to d667636 Compare October 19, 2026 13:25

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Jun2M, would your work cover quivers by any chance? Does that mean we don't need the content of this PR?

`Quiver.cycleLengths` (in `Mathlib/Combinatorics/Quiver/Cyclic.lean`) records lengths of positive
loops without a simplicity hypothesis.

For cardinality bounds use `p.vertices.toFinset` (see `List.toFinset_card_of_nodup`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
For cardinality bounds use `p.vertices.toFinset` (see `List.toFinset_card_of_nodup`).
For cardinality bounds, use `p.vertices.toFinset` (see `List.toFinset_card_of_nodup`).

variable {V : Type*} [Quiver V]

/-- A path with no repeated vertices (cf. `SimpleGraph.Walk.IsPath`). -/
@[reducible] def IsPath {a b : V} (p : Path a b) : Prop :=

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
@[reducible] def IsPath {a b : V} (p : Path a b) : Prop :=
abbrev IsPath {a b : V} (p : Path a b) : Prop :=

? Same below

@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 19, 2026
@YaelDillies YaelDillies self-assigned this Oct 19, 2026
@mkaratarakis

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 19, 2026
@Jun2M

Jun2M commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

@YaelDillies, HypergraphLike should be able to cover Quiver. There is a bit of an inconvience due to the fact that Quiver hides the edge type(s) inside the field so until you have the Quiver instance, you don't know what edge type you are working with. HypergraphLike expects you to know the edge type before you know what graph you are working with.

Here is a Lean formalization. The Quiver.Path def is equivalent to my walk def on HypergraphLike. If something like this is fine, then HypergraphLike can handle Quiver.:

/- The edge type of a quiver. Only known after the quiver instance is available. -/
abbrev Arrow (V : Type*) [Quiver V] := Σ a b : V, a ⟶ b

/- Associate each instance of `Quiver V` with a singlton type. -/
structure AsGraphLike (V : Type*) [Quiver V] : Type where

instance {V : Type*} [Quiver V] : HyperGraphLike V (Arrow V × Bool) (Arrow V) (AsGraphLike V) where
  verts _ := Set.univ
  edges _ := Set.univ
  incs _ := Set.univ
  edgeMap' _ i := ⟨i.val.1, Set.mem_univ _⟩
  attach' _ i := ⟨if i.val.2 then i.val.1.2.1 else i.val.1.1, Set.mem_univ _⟩
  IsSource _ i := i.2 = false
  IsTarget _ i := i.2 = true
  mem_incs_iff := by simp

/-- The canonical graph-like object attached to a quiver. -/
def graphOf (V : Type*) [Quiver V] : AsGraphLike V := ⟨⟩

def pathEquivWalk {V : Type*} [Quiver V] (a b : V) : Path a b ≃ Walk (graphOf V) a b := by
  sorry

@YaelDillies

Copy link
Copy Markdown
Contributor

IMO Quiver is somewhat misdesigned as it tries to both be a combinatorial object and the basis for category theory. These two goals are at odds with each other and I expect usability would improve if we were to separate them. Could I interest you both in investigating whether making Quiver a structure and making it follow the HypergraphLike` design improves usability (outside of category theory, of course, which will want its own version)?

This branch has not been deployed

No deployments
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.

4 participants