game sudoku petri-net ode go-pflow

Sudoku Petri-Net Model

Overview

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.

Encoding Sudoku as a Petri Net

Sudoku rules can be expressed entirely as token flow constraints: cells fill, constraints validate, and only valid configurations enable the final solved state.

Cell Places

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.

Digit-Write Transitions

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).

Constraint Collectors

Sudoku uniqueness rules (one digit per row/column/box) become collector transitions:

These transitions only fire when all contributing places are consistent.

"Solved" Transition

All collectors feed a final transition:

all_constraints_satisfied

This marks the solved place only when every Sudoku rule is satisfied.

The ODE-Compatible Model

Continuous-Time Interpretation

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.

Why Sudoku Works Well with ODEs

This transforms Sudoku from a search problem into a constraint-energy landscape.

Running the Model

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:

Visualizations

(Placeholder for SVG/plots/heatmaps)

Future Work

Advanced Constraint Patterns

Extend the model with:

Parameter Sweeps & Energy Landscapes

Using continuous simulation, we can:

ODE Simulation with go-pflow

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.

Conclusion

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.