AML Wiki Review copy, version 1.1, 12 November 2026
algebraic.ai

Examples

Hamiltonian cycles and Sudoku

Stub

This page is a stub: a first draft that has not yet been reviewed.

Algebraic Machine Learning (AML) can be given a problem with no data at all. The axioms then describe the problem itself: its constraints and its goal. This is called learning without data. Two problems illustrate it: finding Hamiltonian cycles in graphs, which is the worked case, and Sudoku.

Why it can work

As with data, learning here consists of discovering discriminative atoms of the freest model of the axioms, and with Sparse Crossing this typically occurs gradually, over several batches that each contain the complete set of axioms. A result from Semantic embeddings in semilattices is relevant here: for a type of embedding called an explicit embedding, each solution of the problem has a model atomized by a subset of the non-redundant atoms of the freest model of the axioms. Most atoms are redundant, so the property severely restricts the part of the atom space that contains the solutions. Since Sparse Crossing is designed to be effective at finding non-redundant atoms, the authors suggest that this may explain its effectiveness on these problems.1

Hamiltonian cycles

The Hamiltonian cycle problem is this: given a graph, find a closed path that visits every node exactly once. The axioms say what the graph looks like and what such a path is. They do not say how to find one. The model is trained on the same axioms in every batch, and after each batch it is read to see which edges it places on the path. Each reading is an attempt.

Constants

For a graph with \(v\) nodes and \(e\) edges the embedding uses a constant \(V_i\) for each node; a constant \(E_k\) for each edge; a constant \(P\) for the path to be computed; a constant \(W\) used to encode constraints and to train with results obtained along the way; a constant \(nE_k\) for the absence of each edge; one auxiliary constant \(Z_k\) and two context constants \(g_k\) and \(h_k\) per edge; and, to specify a connected path, a constant \(id_i\) per node. This gives \(2v + 5e + 2\) constants.

Some of the axioms

The topology of the graph is expressed by the positive axioms

\[V_{r(k)} \odot V_{s(k)} \leq E_k ,\]

where \(r(k)\) and \(s(k)\) index the two nodes of edge \(E_k\). To describe a path, for each node \(i\) and each pair of its edges \(E_y\) and \(E_z\),

\[P \odot \Big( \bigodot_{x \notin \{y, z\}} nE_x \Big) = E_y \odot E_z \odot P ,\]

where the idempotent summation runs over every edge of node \(i\) except \(y\) and \(z\). The axiom says that, in the context of a path, having two edges of a node present is equivalent to having every other edge of that node absent. In all there are \(2v + 1\) negative axioms and approximately \(2(e^2/v) + 7e + 2v + 2\) positive axioms. The complete set of axioms is given in the Methods of the paper cited.2

Reading a model

Given a model \(M\) of the axioms, the path \(P\) has edge \(E_k\) if and only if \(E_k \leq P\) holds in \(M\). The model produced after each sparse-crossing batch is read in this way, which gives one attempt per batch.

Learning from failed attempts

Optionally, a path that cannot be completed can be added to the axioms as \(W \leq \bigodot_u E_u\), where the summation runs over the edges of the unwanted path, together with the axiom \(W \not\leq P\).

Soft constraints

The constraints of the embedding are soft, “more an invitation than a hard constraint”: there are models of the axioms in which \(P\) contains every node without having the edges to justify it. In experiments, good models are nevertheless produced, and produced early; the authors suggest that good models are a simpler interpretation of the constraints and so more likely to be found.

Results

Sparse Crossing has been applied to graphs 1 to 10 of the FHCP challenge set, with 10 independent runs per graph. “First” is the number of attempts needed to obtain the first Hamiltonian cycle in any of the runs; “Median”, the number needed for 5 of the 10 runs to find one; “All”, the number needed for all 10 runs to find one. “SLH transforms” is the number of graph transformations needed to find a first path with the Snakes and Ladders Heuristic, a state-of-the-art algorithm for Hamiltonian cycles.

GraphFirstMedianAllSLH transforms
G19773365113356
G2121244715078
G3808679846419172316
G41110083379266
G51818104926401381571
G628437887370
G7356028202292521412275
G820718385823666801
G98282130717472180
G104347682907285

Cycles have also been found in randomly generated graphs of variable edge density, modified Flower Snarks, Sheehan graphs of various sizes and generalized Petersen graphs. For Sheehan graphs, which have a single Hamiltonian cycle, the embedding always produces that cycle at the first attempt, and excluding the cycle with a \(W\) axiom makes the embedding inconsistent.3

Speed

Although the method can find paths in very few attempts, each attempt is time-consuming: a batch takes about 0.5 to 5 seconds, depending on the graph, on a regular desktop computer. This makes the method “much slower than state of the art algorithms such as the Snakes and Ladders Heuristic algorithm”. The axioms describe only the graph and the goal of the task, and do not encode any method for finding the solution.

Settings

For Sudoku and Hamiltonian cycles all the positive and negative duples are presented in every batch, the simplification threshold is \(\gamma = 1.1\), and no model reduction is applied: each solution is extracted from the master model and not from the union model. For Hamiltonian cycles better results were observed with larger values of the fractioning parameter, such as \(\kappa = 0.5\).4

Sudoku

An algebra can be trained to solve Sudoku puzzles, or to form complete Sudoku boards starting from an empty grid, with axioms that describe the constraints of a correct board and the goal of the game, and without any examples.1 An embedding for Sudoku is set out in Semantic embeddings in semilattices, section “Sudoku”. The Open-AML-Engine includes the files example02_Sudoku.py and embedding_Sudoku.py.5

References

  • Martin-Maroto, Abderrahaman, Méndez and de Polavieja (2025), Algebraic Machine Learning: Learning as computing an algebraic decomposition of a task, arXiv:2502.19944.
  • Martin-Maroto and de Polavieja (2022), Semantic embeddings in semilattices, arXiv:2205.12618.

See also

Try it

The Hamiltonian Graph tutorial embeds a graph and the notion of a Hamiltonian cycle, and finds cycles in graphs that have very few of them.

Footnotes

  1. Martin-Maroto et al. (2025), section “Learning without data”. ↩ ↩2

  2. Martin-Maroto et al. (2025), section “Learning without data”; Methods, “Embedding for Hamiltonian cycles”. ↩

  3. Martin-Maroto et al. (2025), section “Learning without data”, Figure 5. ↩

  4. Martin-Maroto et al. (2025), Methods, “AML models”. ↩

  5. Martin-Maroto et al. (2025), Methods, “Embedding for Sudoku”. ↩