Algorithms

From a factorial to an expert system

Axioma is a Turing-complete general-purpose language — and a symbolic-AI one, where rules and inference are native. Here is the algorithm canon, from sorting and search to dynamic programming and a forward-chaining expert system. Every example runs right here in the page.

▶ Edit any example and press Run — or /Ctrl+Enter. Same WebAssembly interpreter as the playground; nothing leaves your browser. interpreter: loading…
FUNDAMENTALS

Fundamentals

The everyday canon — recursion, a sort, a search, primes, the functional triad, a little set theory. Edit and run any of them; this is the same WebAssembly interpreter as the playground.

Factorial

Recursion — base case plus recursive step.

factorial.axOpen in Playground ↗

Euclid's GCD

The oldest algorithm still in daily use (c. 300 BCE).

Quicksort

Divide and conquer with set-builder partitions around a pivot.

quicksort.axOpen in Playground ↗

Binary search

Halve the interval each step — O(log n) over a sorted array.

bsearch.axOpen in Playground ↗

Primes

Trial division as a set comprehension — prime iff it has no divisor.

primes.axOpen in Playground ↗

Map / filter / reduce

The functional triad — sum the squares of the evens.

mapreduce.axOpen in Playground ↗

FizzBuzz

The classic warm-up — multiples of 3, 5 and 15.

fizzbuzz.axOpen in Playground ↗

Palindrome

Fold a string's characters in reverse, then compare.

palindrome.axOpen in Playground ↗

Powerset

Set theory is first-class — every subset of {1, 2, 3}.

powerset.axOpen in Playground ↗
SEARCH & GRAPH

Search & graph

Traversal and ordering over graphs — including the Datalog one-liner where a single recursive rule computes the entire transitive closure.

Reachability (Datalog)

A recursive Horn rule computes a graph's whole transitive closure.

reachability.axOpen in Playground ↗

Depth-first search

Recurse into each neighbour, tracking a visited set.

Breadth-first search

A hand-rolled queue (array + head index) explores level by level.

Dijkstra's shortest path

Weighted shortest paths from a source over a small graph.

dijkstra.axOpen in Playground ↗

Topological sort

DFS post-order, reversed — a valid dependency ordering.

toposort.axOpen in Playground ↗
RECURSION & BACKTRACKING

Recursion & backtracking

Problems solved by trying and undoing — the shape of classical search.

Towers of Hanoi

Relocate a stack of disks, three pegs, recursively.

hanoi.axOpen in Playground ↗

N-Queens

Backtracking: count non-attacking placements on a 6×6 board.

nqueens.axOpen in Playground ↗

Permutations

Every ordering of a list, built recursively.

perms.axOpen in Playground ↗
DYNAMIC PROGRAMMING

Dynamic programming

Overlapping subproblems solved once and cached — by array tabulation, or a dict memo keyed by the subproblem's state.

Fibonacci (memoized)

Top-down memoization — a dict caches each result, so every value is computed once.

Edit distance

Top-down, with a dict memo keyed by a compound "i,j" state — the idiom a flat array can't express directly.

editdist.axOpen in Playground ↗

Longest common subsequence

The longest order-preserving shared subsequence (length).

0/1 Knapsack

Maximum value within a weight budget, each item at most once.

knapsack.axOpen in Playground ↗

Coin change

Fewest coins that make an amount, from given denominations.

coinchange.axOpen in Playground ↗
SYMBOLIC AI

Symbolic AI

Axioma's home ground: facts, rules, inference and defeasible reasoning — the classic GOFAI toolkit expressed directly. (Axioma is Datalog-flat, so these are forward-chaining and query-driven, not backtracking search.)

Forward-chaining expert system

Facts plus strict rules chain to a classification; the result is a theorem.

expert.axOpen in Playground ↗

Family-tree inference

Parent facts; recursive ancestor, grandparent and sibling rules.

family.axOpen in Playground ↗

Unification by join

A shared variable bound across two relations does what unification does.

Defeasible reasoning

A strict law (theorem) survives; a default (conjecture) can be cancelled.

defeasible.axOpen in Playground ↗

Rule-based NLP

Ordered morphological rules turn a noun into its English plural.

pluralize.axOpen in Playground ↗

State-space reachability

States and moves as facts; a recursive rule finds every reachable state.

planner.axOpen in Playground ↗

Turing-complete, and then some.

Recursion, loops, search, dynamic programming and a full inference engine — and every block above is editable and one click from the playground. The philosophical side lives next door in Symbolization.