Directed walks in a list, ends, and counting vertices in a set
DefinitionRhoMin_DirThree notions about a finite sequence of vertices of a type and a relation on , read as the arc relation of a digraph.
- is a walk of if every consecutive pair is an arc: for all . The empty sequence and one-vertex sequences are walks.
- A vertex is an end of if it is the first or the last element of .
- For a finite set , the count of in is the number of entries of that lie in .
A directed path, in the sense used for the upper bound, is a walk without repeated vertices; these notions are used to state how a path meets the pieces of a chain.
Formalization Note Sequences are lists; the empty list has no end.
import Mathlib.Data.Finset.Card
import Mathlib.Data.List.Count
namespace RhoMin
variable {V : Type*} [DecidableEq V]
set_option linter.unusedSectionVars false
def Walk (A : V → V → Prop) : List V → Prop
| [] => True
| [_] => True
| x :: y :: l => A x y ∧ Walk A (y :: l)
def IsEnd (x : V) (l : List V) : Prop := l.head? = some x ∨ l.getLast? = some x
def cnt (S : Finset V) (l : List V) : ℕ := l.countP (fun x => decide (x ∈ S))
end RhoMin
Read-back
What the Lean code literally says, in plain math · claude-fable-5-2
Throughout, is an arbitrary type (in any universe; it may be empty or infinite), declared together with the assumption that equality on is algorithmically decidable. This assumption is the only standing assumption of the file; it is needed for the third definition (to test membership in a finite set) and has no effect on the meaning of the first two. "List" means a finite sequence of elements of , possibly empty and possibly with repeated entries.
Definition Walk (predicate ). For an arbitrary binary relation on (no symmetry, irreflexivity, or other property is assumed) and a list of elements of , the proposition is defined by recursion on :
- if is empty, it is true;
- if has exactly one element, it is true;
- if has at least two elements, it holds if and only if holds and holds, where is with its first element removed.
Unfolded: for ,
The relation is applied in the order of the list (from each entry to the next one), so the notion is directed. The entries are not required to be distinct.
Definition IsEnd (predicate ). For an element and a list of elements of , the proposition holds if and only if
For the empty list it is false for every . For a one-element list it holds exactly when . It concerns only the first and last positions of ; may also occur elsewhere in .
Definition cnt (). For a finite subset and a list of elements of , is the natural number
the number of positions of whose entry belongs to . Repeated entries are counted with multiplicity. For the empty list, or for , the value is .