This model explores how a full 9×9 Sudoku puzzle can be represented as a Petri net, and how that structural model can be analyzed using continuous ordinary differential equations (ODEs).
Instead of hard-coding Sudoku rules or writing a custom solver, we encode the puzzle as a network of places and transitions:
Once encoded, the net behaves like an executable structure. Using go-pflow, we can:
This provides insight into Sudoku's constraint flow, solution stability, and energy-like dynamics.
Sudoku rules can be expressed entirely as token flow constraints: cells fill, constraints validate, and only valid configurations enable the final solved state.
Each cell (r, c) in the 9×9 grid becomes a place:
cell_r3_c7
cell_r8_c2
...
Prefilled ("given") cells contain an initial token; empty cells start at zero.
For each cell and each digit 1–9, we define one transition:
write_r3_c7_d5
write_r1_c9_d9
...
Firing this transition "writes" digit d into cell (r, c).
Sudoku uniqueness rules (one digit per row/column/box) become collector transitions:
row_r4_d7_okcol_c2_d1_okbox_r3_c3_d9_okThese transitions only fire when all contributing places are consistent.
All collectors feed a final transition:
all_constraints_satisfied
This marks the solved place only when every Sudoku rule is satisfied.
Once exported using go-pflow's JSON-LD format (sudoku-9x9-ode.jsonld),
the net can be interpreted as a continuous-time system:
dX/dt = M · v(X)
Where:
The discrete Sudoku rules become a smooth dynamical system where constraint satisfaction emerges progressively.
This transforms Sudoku from a search problem into a constraint-energy landscape.
cd examples/sudoku
# Generate or view the 9x9 ODE model
cat sudoku-9x9-ode.jsonld
# Analyze using go-pflow
go-pflow analyze sudoku-9x9-ode.jsonld
# Run ODE simulation
go-pflow simulate sudoku-9x9-ode.jsonld --tspan 0,50
We can then visualize:
(Placeholder for SVG/plots/heatmaps)
Extend the model with:
Using continuous simulation, we can:
go-pflow provides built-in ODE simulation using the Tsit5 solver:
net := petri.NewPetriNet()
// ... define places and transitions ...
problem := solver.NewProblem(net)
result := solver.Solve(problem, solver.Tsit5(), solver.DefaultOptions())
// Access place trajectories
for i, t := range result.T {
fmt.Printf("Time %.1f: %v\n", t, result.U[i])
}
We can also use pflow.xyz to run ODE analysis directly in the browser.
By modeling Sudoku as a Petri net, we capture the entire logic of the puzzle using structural primitives. By converting that net into an ODE system, we explore Sudoku as a continuous dynamical process, revealing its hidden constraint geometry.
This demonstrates not just a novel Sudoku solver, but a general modeling pattern: encode discrete systems structurally, then analyze them with continuous mathematics.
More examples and interactive visualizations are available at pflow.xyz.