Skip to content

feat(Combinatorics/Quiver): periodicity and aperiodicity - #39913

Open
mkaratarakis wants to merge 14 commits into
leanprover-community:masterfrom
mkaratarakis:pf/port/quiver-cyclic
Open

mkaratarakis wants to merge 14 commits into
leanprover-community:masterfrom
mkaratarakis:pf/port/quiver-cyclic

Conversation

@mkaratarakis

@mkaratarakis mkaratarakis commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

cycle lengths, index of imprimitivity, and cyclic partitions for strongly connected quivers.

Part of the Perron–Frobenius formalization (with @or4nge19).


Open in Gitpod

cc @or4nge19 for review

@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown

PR summary ba6e7eebc7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.Quiver.Cyclic (new file) 1579

Declarations diff (regex)

+ IsAperiodic
+ IsCyclicPartition
+ add_mem_cycleLengths
+ const_mul_mem_cycleLengths
+ cycleLengths
+ dvd_period
+ dvd_period_iff
+ exists_forall_ge_mem_cycleLengths
+ exists_isCyclicPartition
+ imprimitivityIndex
+ imprimitivityIndex_dvd
+ imprimitivityIndex_pos
+ le_period
+ length_comp_mem_cycleLengths
+ mem_cycleLengths_iff
+ mem_cycleLengths_of_mem_closure
+ mul_const_mem_cycleLengths
+ period
+ period_dvd_of_mem_cycleLengths
+ period_dvd_of_round_trip
+ period_eq_of_isSStronglyConnected
+ period_eq_zero
+ period_pos
+ zero_mem_cycleLengths

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

  • +23 new declarations
  • −0 removed declarations
+Quiver.IsAperiodic
+Quiver.IsCyclicPartition
+Quiver.add_mem_cycleLengths
+Quiver.const_mul_mem_cycleLengths
+Quiver.cycleLengths
+Quiver.dvd_period
+Quiver.dvd_period_iff
+Quiver.exists_forall_ge_mem_cycleLengths
+Quiver.exists_isCyclicPartition
+Quiver.imprimitivityIndex
+Quiver.imprimitivityIndex_dvd
+Quiver.imprimitivityIndex_pos
+Quiver.le_period
+Quiver.length_comp_mem_cycleLengths
+Quiver.mem_cycleLengths_iff
+Quiver.mem_cycleLengths_of_mem_closure
+Quiver.mul_const_mem_cycleLengths
+Quiver.period
+Quiver.period_dvd_of_mem_cycleLengths
+Quiver.period_eq_of_isSStronglyConnected
+Quiver.period_eq_zero
+Quiver.period_pos
+Quiver.zero_mem_cycleLengths

No changes to strong technical debt.

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

Current commit ba6e7eebc7
Reference commit 74e558e2f8

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 May 27, 2026
@mkaratarakis
mkaratarakis force-pushed the pf/port/quiver-cyclic branch 5 times, most recently from 81aeef9 to 519d92e Compare May 27, 2026 19:34
@or4nge19

or4nge19 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks! I think I have shared/committed several refactor suggestions and improvements to this file (which was the latest developed among the Perron-Frobenius prerequisites); in particular an improvement to the definition of an aperiodic Quiver.

mkaratarakis and others added 2 commits July 5, 2026 01:03
The master merge (toolchain v4.32.0-rc1) changed simp's handling of
let-bound locals: `simpa [indexOfImprimitivity, i0]` no longer unfolds
the let-variable `h` in the goal, so the divisibility bridge failed with
a type mismatch. The two `have`s are definitionally true (`h` is a let
of `indexOfImprimitivity`, which is a plain def of `period`), so provide
the terms directly and let defeq do the work.
mkaratarakis and others added 4 commits August 21, 2026 19:09
…mmon divisor

`period` was `Nat.find` over the set of common divisors of the cycle
lengths at a vertex. Since `1` is always such a divisor, that returned
`1` as soon as any cycle exists, so `IsAperiodic` held for every quiver
with a cycle and the notion carried no content.

Define it instead as the least positive element of the additive subgroup
of `ℤ` generated by the cycle lengths, which is their gcd, and record the
universal property: every common divisor of the cycle lengths divides the
period (`dvd_period`).

`period_min` and `period_le_of_commonDivisor`, which asserted
minimality, are replaced by `dvd_period` and `commonDivisor_le_period`.
Every other statement is unchanged, and
`period_constant_of_strongly_connected` now concludes with
`Nat.dvd_antisymm` instead of `le_antisymm`.
If the period at a vertex is `1`, every sufficiently large natural number
is the length of a cycle there
(`exists_forall_ge_mem_CycleLengths_of_period_eq_one`).

The proof needs no general theory of numerical semigroups: from
`1 ∈ cycleSubgroup i` one extracts two cycle lengths differing by `1`
(`exists_consecutive_of_period_eq_one`), and for consecutive `q`, `q + 1`
every `n ≥ q * q` is a nonnegative combination, obtained by splitting
`n = (n / q - n % q) * q + n % q * (q + 1)`.

Supporting lemmas: `add_mem_CycleLengths` (concatenation of cycles),
`nsmul_mem_CycleLengths`, and `exists_sub_repr_of_mem_cycleSubgroup`,
which writes every element of the generated subgroup as a difference of
two cycle lengths.
@mkaratarakis

Copy link
Copy Markdown
Contributor Author

WIP

@github-actions github-actions Bot added the WIP Work in progress label Aug 25, 2026
@mkaratarakis

Copy link
Copy Markdown
Contributor Author

-WIP

@github-actions github-actions Bot removed the WIP Work in progress label Aug 25, 2026

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

Do you have a reference for this material? I have never of the "period of a quiver" before

@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 17, 2026
Add references section to Cyclic.lean
@mkaratarakis

Copy link
Copy Markdown
Contributor Author

Hey Yael! it's from Seneta, Non-negative matrices and Markov chains

@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 Sep 18, 2026
@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 29, 2026
@mkaratarakis

mkaratarakis commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All addressed

-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 17, 2026
@mkaratarakis
mkaratarakis force-pushed the pf/port/quiver-cyclic branch from 344ee29 to e67f4ee Compare October 17, 2026 23:44
/-! ### Cycle lengths -/

/-- The lengths of the positive-length cycles at a vertex `i`. -/
def cycleLengths (i : V) : Set ℕ := {k | 0 < k ∧ ∃ p : Path i i, p.length = k}

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.

Would it not make sense to allow 0 to be a cycle length? All the statements below seemingly more with this more permissive definition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, 0 is now included. Most statements got simpler. period_eq_zero and period_pos now talk about {0} and nonzero cycle lengths instead of emptiness.

Comment on lines +197 to +198
def IsCyclicPartition {h : ℕ} (f : V → Fin h) : Prop :=
∀ ⦃i j : V⦄, (i ⟶ j) → (f j : ℕ) = ((f i : ℕ) + 1) % h

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.

Shouldn't you be using ZMod here instead?

Suggested change
def IsCyclicPartition {h : ℕ} (f : V → Fin h) : Prop :=
∀ ⦃i j : V⦄, (i ⟶ j) → (f j : ℕ) = ((f i : ℕ) + 1) % h
def IsCyclicPartition {h : ℕ} (f : V → ZMod h) : Prop :=
∀ ⦃i j : V⦄, (i ⟶ j) → f j = f i + 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, switched to ZMod.

@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
@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
exact ⟨by lia, p.comp q, by simp [Path.length_comp]⟩
obtain ⟨p, rfl⟩ := ha
obtain ⟨q, rfl⟩ := hb
exact ⟨p.comp q, by simp [Path.length_comp]⟩

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.

This is already a simp lemma

Suggested change
exact ⟨p.comp q, by simp [Path.length_comp]⟩
exact ⟨p.comp q, by simp⟩

/-- The lengths of the positive-length cycles at a vertex `i`. -/
def cycleLengths (i : V) : Set ℕ := {k | 0 < k ∧ ∃ p : Path i i, p.length = k}
/-- The lengths of the cycles at a vertex `i`, including the trivial cycle of length `0`. -/
def cycleLengths (i : V) : Set ℕ := {k | ∃ p : Path i i, p.length = k}

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 define this as

Suggested change
def cycleLengths (i : V) : Set ℕ := {k | ∃ p : Path i i, p.length = k}
def cycleLengths (i : V) : AddSubmonoid ℕ where
carrier := {k | ∃ p : Path i i, p.length = k}
...

right away? An even nicer way to define it would be as the range of length as an AddChar (Path i i) ℕ, but I don't think Path i i currently has a monoid structure. I suspect we should add it anyway, as it would make #45033 redundant (in another way than described there).

| zero => simp
| succ k ih => simpa [Nat.succ_mul] using add_mem_cycleLengths ih ha

lemma mul_const_mem_cycleLengths (ha : a ∈ cycleLengths i) (m : ℕ) : a * m ∈ cycleLengths i :=

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
lemma mul_const_mem_cycleLengths (ha : a ∈ cycleLengths i) (m : ℕ) : a * m ∈ cycleLengths i :=
lemma mul_mem_cycleLengths_of_left (ha : a ∈ cycleLengths i) (m : ℕ) : a * m ∈ cycleLengths i :=

Similarly below

Comment on lines +129 to +130
theorem exists_forall_ge_mem_cycleLengths (h : period i = 1) :
∃ N, ∀ n, N ≤ n → n ∈ cycleLengths i := by

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
theorem exists_forall_ge_mem_cycleLengths (h : period i = 1) :
∃ N, ∀ n, N ≤ n → n ∈ cycleLengths i := by
theorem eventually_mem_cycleLengths (h : period i = 1) :
∀\^f n in atTop, n ∈ cycleLengths i := by

and can you upgrade this to an iff?

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

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

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants