Experimental computational algorithms for chip-firing #
This file contains an early executable implementation of several chip-firing algorithms, including greedy dollar-game play, Dhar's burning algorithm, and $q$-reduction routines.
The formal proof of Riemann-Roch in this repository does not rely on this file. Some of these definitions predate the current theorem-proving infrastructure and should be treated as exploratory code rather than certified implementations of the textbook algorithms. In particular, the core mathematical statements about $q$-reduced divisors, superstability, and Dhar's algorithm are proved elsewhere in the library.
Checks whether a divisor is effective, meaning that all vertex values are nonnegative.
Equations
- ChipFiring.CF.isEffective D = decide (∀ (v : G.V), D v ≥ 0)
Instances For
A small size measure used only to set conservative default loop fuel.
Equations
- ChipFiring.CF.divisorMagnitude G D = ∑ v : G.V, (D v).natAbs
Instances For
Default fuel for greedy routines, scaled by the actual chip counts in the input.
Equations
- ChipFiring.CF.greedyFuel G D = (Fintype.card G.V + 1) * (ChipFiring.CF.divisorMagnitude G D + 1) ^ 2 + 1
Instances For
Number of chips away from the source, used for the q-reduction loop budget.
Equations
- ChipFiring.CF.nonSourceChipCount G q D = ∑ v ∈ Finset.univ.erase q, (D v).toNat
Instances For
Fuel-bounded greedy borrowing loop, recording vertices visited and the accumulated firing script.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The greedy algorithm for the dollar game (Corry-Perkinson, Algorithm 1).
The algorithm repeatedly chooses an in-debt vertex $v$, performs a borrowing move
at $v$, and records in $M$ that $v$ has borrowed at least once. Vertices already
in $M$ may still need to borrow again.
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
Instances For
Finds a burnable vertex $v \in S$, meaning one satisfying $c(v) < \operatorname{outdeg}_S(v)$.
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 (Corry-Perkinson, Algorithm 2).
Given a configuration $c$ (represented here as a function $V(G) \to \mathbb{Z}$, with nonnegativity away from $q$ handled externally) and a sink $q$, this returns the set of unburnt vertices $S \subseteq V(G) \setminus \{q\}$. The set $S$ is empty if and only if the restriction of $c$ to $V(G) \setminus \{q\}$ is superstable relative to $q$.
The implementation uses well-founded recursion on the size of $S$.
Equations
- ChipFiring.CF.dharBurningSet G q c = ChipFiring.CF.dharBurningSetLoop G c (Finset.univ.erase q) (Fintype.card G.V + 1)
Instances For
Fires every vertex in $S$, starting from the divisor $D$.
Equations
- ChipFiring.CF.fireSet G D S = List.foldl (fun (current_D : ChipFiring.CFDiv G) (v : G.V) => ChipFiring.firingMove G current_D v) D S.toList
Instances For
Fuel-bounded borrowing loop that seeks nonnegative wealth away from the distinguished vertex.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The preprocessing step for findQReducedDivisor.
This borrows greedily at in-debt non-source vertices until $D(v) \ge 0$ for all
$v \ne q$ (Corry-Perkinson, Algorithm 4).
Requires sufficient fuel for the termination guard.
Returns none if fuel runs out, implying potential unwinnability or insufficient fuel.
Equations
- ChipFiring.CF.makeNonNegativeExceptQ G q D max_fuel = ChipFiring.CF.makeNonNegativeExceptQLoop G q D max_fuel
Instances For
Fuel-bounded reduction loop that fires the nonburning set.
Returns none if the fuel runs out before reduction completes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Finds the unique $q$-reduced divisor linearly equivalent to $D$ (Corry-Perkinson, Algorithm 3).
Starting from $D$, the algorithm first preprocesses by borrowing greedily at
in-debt non-source vertices until all vertices other than $q$ are nonnegative.
It then repeatedly finds the maximal legal firing set
$S \subseteq V(G) \setminus \{q\}$ using dharBurningSet, and fires $S$ until
dharBurningSet returns the empty set.
Returns none if preprocessing or reduction exhausts its fuel.
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(G) \setminus \{q\}$.
Equivalent to dharBurningSet.
Equations
- ChipFiring.CF.burn G q c = ChipFiring.CF.dharBurningSet G q c
Instances For
Finds the $v$-reduced divisor linearly equivalent to $D$.
This wraps findQReducedDivisor.
Returns none if the reduction process fails.
Equations
- ChipFiring.CF.dhar G D v = ChipFiring.CF.findQReducedDivisor G v D
Instances For
Attempts to determine winnability with a fuel-bounded reduction.
An already effective divisor returns some true, including on disconnected graphs.
Otherwise this seeks the $q$-reduced representative $D_q$ and returns
some (D_q(q) ≥ 0) (see Corry-Perkinson, preliminary version, Corollary 3.8).
If reduction exhausts its fuel, none records an inconclusive search, not unwinnability.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Calculates the incoming burning degree of a vertex $v$ from a set $B$.
This sums numEdges from each $u \in B$ to $v$.
Equations
- ChipFiring.CF.burningIndeg G B v = ∑ u ∈ B, ↑(ChipFiring.numEdges G u v)
Instances For
Fuel-bounded burning loop that records the orientations created as vertices burn.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The orientation-based version of Dhar's algorithm (Corry-Perkinson, Algorithm 5).
This takes a nonnegative configuration $c$ relative to $q$, and returns the final stable set $S \subseteq V(G) \setminus \{q\}$ (empty if and only if $c$ is superstable) together with a multiset $O$ of directed edges $(u,v)$ where fire spread from $u$ to $v$.
Note: this assumes $c$ is nonnegative on $V(G) \setminus \{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.