{"id":4111,"library":"minikanren","title":"minikanren","description":"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]","status":"active","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/pythological/kanren","tags":["relational programming","logic programming","DSL","constraint programming","AI","symbolic computation"],"install":[{"cmd":"pip install minikanren","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used internally for supporting pattern matching on user-defined types. [2]","package":"multipledispatch","optional":false},{"reason":"Used internally for supporting pattern matching on user-defined types. [2]","package":"logical-unification","optional":false}],"imports":[{"note":"The PyPI package name is `minikanren`, but the Python importable package is `kanren`.","wrong":"from minikanren import ...","symbol":"run, eq, membero, var, lall","correct":"from kanren import run, eq, membero, var, lall"}],"quickstart":{"code":"from kanren import run, eq, var\n\nx = var()\nresults = run(1, x, eq(x, 5))\nprint(results)\n\ny, z = var(), var()\nresults_multi = run(1, (y, z), eq(y, z), eq(z, 3))\nprint(results_multi)\n\n# Example with unification of structures\nresults_struct = run(1, x, eq((1, 2), (1, x)))\nprint(results_struct)","lang":"python","description":"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]"},"warnings":[{"fix":"Always use `from kanren import ...` for imports.","message":"The PyPI package is `minikanren`, but the Python module to import is `kanren`. Importing from `minikanren` directly will result in an `ImportError`. [2, 3]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully design goals to constrain the search space or be aware of potential non-termination for certain queries.","message":"Like other logic programming languages, `minikanren` queries may enter an infinite loop if no solution exists within an infinite search tree. The interleaved search strategy guarantees finding solutions if they exist, but cannot guarantee termination if no solution is found and the search space is unbounded. [16]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Experiment with different goal orderings, prioritizing more restrictive goals earlier in conjunctions (`lall`) to prune the search space faster.","message":"While `minikanren`'s interleaving search provides completeness, the order of goals can still impact performance, especially in complex scenarios. Inefficient goal ordering might lead to longer execution times or seemingly non-terminating searches if favorable branches are explored later. [18, 20]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult `minikanren` documentation and examples when migrating from `logpy` to understand the differences in core implementation and available features.","message":"The `kanren` project is a fork of `logpy` and while aiming for syntactic parity, it deviates significantly in 'core mechanics and offerings'. Users migrating from `logpy` should be aware that internal behaviors and potential extensions might differ substantially. [2]","severity":"breaking","affected_versions":"From 1.0.0 onwards, compared to `logpy`"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}