AFTD Auto-Formalizing Theoretical Domains

perm_cycle_count

def

The number of cycles of a permutation σ of {0, ..., n-1}, counting fixed points as cycles of length 1, is the number of nontrivial cycles plus n minus the sum of the lengths of the nontrivial cycles.

Statement

def perm_cycle_count {n : ℕ} (σ : Equiv.Perm (Fin n)) : ℕ
Defined in
arXiv:2611.33575 Section 1 and Section 8
Verified
27 Nov 2026
Axioms
none listed

Read back from the Lean

Given a natural number $n$ and a permutation $\sigma$ of $\mathrm{Fin}(n)$, perm_cycle_count σ is defined as the natural number equal to the cardinality of the multiset of cycle lengths of $\sigma$ (Equiv.Perm.cycleType σ) plus $n$ minus the sum of the cycle lengths of $\sigma$ (Multiset.sum (Equiv.Perm.cycleType σ)). (In Mathlib, cycleType only includes cycles of length $\ge 2$, so this counts the number of non-trivial cycles plus the number of fixed points, i.e., the total number of cycles of $\sigma$ including 1-cycles.)

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- Total number of disjoint cycles of a permutation on Fin n, including fixed points. -/
def perm_cycle_count {n : ℕ} (σ : Equiv.Perm (Fin n)) : ℕ := Multiset.card (Equiv.Perm.cycleType σ) + (n - Multiset.sum (Equiv.Perm.cycleType σ))
See it in the graphDiscuss this resultChallenge it