Computational algorithms for chip-firing #
This file implements the main computational algorithms for chip-firing on graphs:
greedyWinnable: Greedy dollar game solver (Algorithm 1).dharBurningSet: Dhar's burning algorithm, returning the set of unburnt vertices (Algorithm 2).findQReducedDivisor: Finds the unique $q$-reduced divisor linearly equivalent to a given divisor (Algorithm 3).isWinnable: Winnability check via $q$-reduction (Algorithm 4).dharBurningSetWithOrientation: Dhar's burning algorithm with orientation tracking (Algorithm 5).
Check if a divisor is effective (all vertices non-negative). From Basic.lean
Equations
- CF.is_effective D = decide (∀ (v : V), D v ≥ 0)
Instances For
Greedy Algorithm for the dollar game (Algorithm 1).
Repeatedly chooses an in-debt vertex v that hasn't borrowed yet (v ∉ M)
and performs a borrowing move at v, adding v to M.
Returns (winnable, script) where winnable is true if an effective divisor is reached,
and script is the net borrowing count for each vertex if winnable.
Equations
- CF.greedyWinnable G D = CF.greedyWinnable.loop G D ∅ 0 (Fintype.card V * Fintype.card V)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Calculates the out-degree of a vertex v with respect to a set S.
This counts the number of edges from v to vertices outside S (including q).
outdeg G S v = |{ w | ∃ edge (v, w) in G.edges and w ∉ S }|
Equations
- CF.dhar_outdeg G S v = ∑ w : V with w ∉ S, ↑(num_edges G v w)
Instances For
Find a vertex v in S such that c(v) < dhar_outdeg G S v (a "burnable" vertex).
Returns some v if found, none otherwise.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The core iterative burning process of Dhar's algorithm (Algorithm 2).
Given a configuration c (represented as V → ℤ for simplicity here, assuming non-negativity outside q is handled externally)
and a sink q, it finds the set of unburnt vertices S ⊆ V \ {q} which forms a legal firing set.
The set S is empty if and only if c restricted to V \ {q} is superstable relative to q.
Implementation uses well-founded recursion on the size of the set S.
Equations
- CF.dharBurningSet G q c = CF.dharBurningSet.loop G c (Finset.univ.erase q) (Fintype.card V + 1)
Instances For
Helper function to fire a set of vertices S on a divisor D.
Equations
- CF.fireSet G D S = List.foldl (fun (current_D : CFDiv V) (v : V) => firing_move G current_D v) D S.toList
Instances For
Preprocessing Step for Algorithm 3/4: Fires q repeatedly until D(v) ≥ 0 for all v ≠ q.
Requires sufficient total degree in the graph. Uses fuel for termination guarantee.
Returns none if fuel runs out, implying potential unwinnability or insufficient fuel.
Equations
- CF.makeNonNegativeExceptQ G q D max_fuel = CF.makeNonNegativeExceptQ.loop G q D max_fuel
Instances For
Finds the unique q-reduced divisor linearly equivalent to D (Algorithm 3).
Starts from divisor D, performs preprocessing (firing q until others non-negative),
then repeatedly finds the maximal legal firing set S ⊆ V \ {q}
using dharBurningSet and fires S until dharBurningSet returns an empty set.
Returns none if preprocessing fails (fuel exhaustion or insufficient degree).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simulates the fire spread from q in Dhar's algorithm on a configuration c.
Returns the set of unburnt vertices $S \subseteq V \setminus \{q\}$.
Equivalent to dharBurningSet.
Equations
- CF.burn G q c = CF.dharBurningSet G q c
Instances For
Finds the v-reduced divisor linearly equivalent to D. Wraps findQReducedDivisor.
Returns none if the reduction process fails.
Equations
- CF.dhar G D v = CF.findQReducedDivisor G v D
Instances For
Efficient Winnability Determination Algorithm (Algorithm 4).
Checks if the divisor D is winnable by finding the q-reduced equivalent Dq
and checking if Dq(q) ≥ 0.
Requires selection of a source vertex q. Returns false if reduction process fails.
Equations
- CF.isWinnable G q D = match CF.findQReducedDivisor G q D with | none => false | some D_q => decide (D_q q ≥ 0)
Instances For
Helper to calculate incoming "burning" degree for vertex v from set B.
Sums num_edges from u in B to v.
Equations
- CF.burning_indeg G B v = ∑ u ∈ B, ↑(num_edges G u v)
Instances For
Orientation-based Dhar's Algorithm (Algorithm 5).
Takes a nonnegative configuration c relative to q.
Returns the final stable set S ⊆ V \ {q} (empty iff c is superstable)
and a multiset O of directed edges (u, v) where fire spread from u to v.
Note: Assumes c is non-negative on V \ {q}.
The returned multiset O represents the edges oriented by the burning process.
It may not form a complete CFOrientation structure directly if not all edges are involved.
Equations
- CF.dharBurningSetWithOrientation G q c = CF.dharBurningSetWithOrientation.loop G c (Finset.univ.erase q) {q} ∅ (Fintype.card V + 1)
Instances For
Equations
- One or more equations did not get rendered due to their size.