Finite folding of labelled inverse multigraphs #
This module implements the quotient step at the heart of Stallings folding. The implementation is deliberately finite and exhaustive: it intersects all equivalence relations that make the labelled multigraph deterministic. This is a simple reference algorithm; a union-find implementation can later replace it without changing the correctness interface.
An inverse-labelled multigraph with finite sets of outgoing targets. Multiple edges with the same source and label are allowed before folding.
The finite collection of targets with a given source and label.
Instances For
A Boolean relation is a fold congruence if it is an equivalence relation and equivalent vertices have equivalent targets along equally-labelled edges.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Vertices are equivalent after all possible folds have been performed.
For a finite vertex type, the quantification is over a finite type of Boolean relations, so this relation is decidable and executable.
Equations
- Stallings.foldRel G v w = ∀ (r : V → V → Bool), Stallings.IsFoldCongruence G r → r v w = true
Instances For
Equations
The least representative of a fold-equivalence class.
Equations
- Stallings.foldRep G v = {w : V | Stallings.foldRel G w v}.min' ⋯
Instances For
All original targets reachable from any vertex in the current fold class.
Equations
- Stallings.foldTargets G v x = {t : V | ∃ (u : V), Stallings.foldRel G u v ∧ t ∈ G.edges u x}
Instances For
Two targets of the same labelled edge out of a fold class are themselves fold-equivalent.
A deterministic representative transition before restricting to canonical representatives.
Equations
- Stallings.foldedNextCore G v x = if h : (Stallings.foldTargets G v x).Nonempty then some (Stallings.foldRep G ((Stallings.foldTargets G v x).min' h)) else none
Instances For
The deterministic transition produced by folding.
Equations
- Stallings.foldedNext G v x = if v = Stallings.foldRep G v then Stallings.foldedNextCore G v x else none
Instances For
The deterministic inverse automaton obtained by quotienting the multigraph.
Equations
- Stallings.foldAutomaton G base = { base := Stallings.foldRep G base, next := Stallings.foldedNext G, inverse_next := ⋯ }
Instances For
A path in a multigraph records one chosen edge for each letter.
- nil {V : Type u_1} {G : InverseMultigraph V} (v : V) : G.Walk v [] v
- cons {V : Type u_1} {G : InverseMultigraph V} {v u z : V} {x : Letter} {w : Word} (edge : u ∈ G.edges v x) (tail : G.Walk u w z) : G.Walk v (x :: w) z
Instances For
The subgroup generated by labels of based loops in the multigraph.
Equations
- G.loopSubgroup base = Subgroup.closure {g : Stallings.Free | ∃ (w : Stallings.Word), Stallings.wordEval w = g ∧ G.Walk base w base}
Instances For
Every original edge induces the corresponding transition between fold representatives.
Folding preserves every path in the original multigraph, after mapping its endpoints to their canonical representatives.
A potential assigns a free-group value to each vertex, consistently up to
left multiplication by H along every labelled edge.
Equations
- Stallings.HasCosetPotential G H potential = ∀ {v : V} {x : Stallings.Letter} {w : V}, w ∈ G.edges v x → Stallings.CosetEquivalent H (potential w) (potential v * Stallings.letterEval x)
Instances For
Along any path, a coset potential changes by the value of the path label.
A fold never identifies vertices with different subgroup cosets, whenever the input graph has a compatible coset potential.
Each transition made by the folded automaton respects the subgroup potential.
A successful folded traversal transports the potential by the value of its label word.
Folding preserves the subgroup generated by based loop labels, provided the original graph carries the canonical coset potential.