minikanren

1.0.5 · active · verified Sat Apr 11

minikanren is a Python library that provides a Domain Specific Language (DSL) for relational (logic) programming. It enables users to express sophisticated relations—in the form of goals—and generate values that satisfy these relations. The library is often used as an algorithmic core for Computer Algebra Systems and for the automated generation and optimization of numeric software. The current version is 1.0.5, with ongoing development and participation in miniKanren workshops across various language implementations. [2, 3]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic relational programming with `minikanren`. It shows how to declare logic variables (`var`), express equality relations (`eq`), and run a query to find solutions. The first example finds `x` such that `x` equals 5. The second finds `y` and `z` such that both are 3. The third shows unification of a structure. [2, 3]

from kanren import run, eq, var

x = var()
results = run(1, x, eq(x, 5))
print(results)

y, z = var(), var()
results_multi = run(1, (y, z), eq(y, z), eq(z, 3))
print(results_multi)

# Example with unification of structures
results_struct = run(1, x, eq((1, 2), (1, x)))
print(results_struct)

view raw JSON →