{"id":4090,"library":"logical-unification","title":"Logical Unification","description":"Logical Unification is a Python library that provides capabilities for logical unification, a core concept in logic programming and automated reasoning. It enables solving equations between symbolic expressions by finding substitutions for variables. The library is a fork of the original 'unification' project, designed with a generator-based approach to handle deeply nested structures efficiently and avoid Python's recursion limits. It is currently at version 0.4.7 and receives periodic updates focusing on features and maintenance.","status":"active","version":"0.4.7","language":"en","source_language":"en","source_url":"https://github.com/pythological/unification","tags":["logic","unification","logic programming","declarative programming","solver","pattern matching"],"install":[{"cmd":"pip install logical-unification","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"symbol":"unify","correct":"from unification import unify"},{"symbol":"var","correct":"from unification import var"},{"symbol":"reify","correct":"from unification import reify"},{"symbol":"unifiable","correct":"from unification.core import unifiable"}],"quickstart":{"code":"from unification import unify, var, reify\n\nx = var()\ny = var()\n\n# Unify constants\nprint(f\"Unify(1, 1): {unify(1, 1)}\")\nprint(f\"Unify(1, 2): {unify(1, 2)}\")\n\n# Unify with a variable\nprint(f\"Unify((1, x), (1, 2)): {unify((1, x), (1, 2))}\")\n\n# Unify multiple variables where they must be the same\nprint(f\"Unify((x, x), (1, 2)): {unify((x, x), (1, 2))}\")\n\n# Reify a term with a substitution\nsubstitution = unify((1, x), (1, 2))\nif substitution:\n    print(f\"Reify((1, x), {substitution}): {reify((1, x), substitution)}\")\n\n# Unify dictionaries\nprint(f\"Unify({{\\\"a\\\": 1, \\\"b\\\": 2}}, {{\\\"a\\\": x, \\\"b\\\": 2}}): {unify({\"a\": 1, \"b\": 2}, {\"a\": x, \"b\": 2})}\")","lang":"python","description":"This quickstart demonstrates the core `unify` and `reify` functions, along with creating logic variables using `var()`. It shows how to unify basic Python types like integers and tuples, and how to apply the resulting substitutions to reify terms. Dictionaries are also supported for unification."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"This library requires Python 3.9 or newer. Users on older Python versions will encounter installation errors or runtime incompatibilities.","severity":"breaking","affected_versions":"<0.4.5 (if upgrading from very old versions), all versions >=0.4.5"},{"fix":"Verify that your `pip install` command is `pip install logical-unification` and your imports use `from unification import ...`.","message":"The `logical-unification` library is a fork of the original `unification` project. While aiming for similar functionality, be aware that API or behavioral differences may exist. Ensure you are importing from `unification` (the installed package name for `logical-unification`) and not the original `unification` package if you intended to use this fork's features.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly import the symbols you need: `from unification import unify, var, reify`.","message":"Using `from unification import *` (wildcard import) as seen in some quickstart examples can pollute your namespace. For clarity and to avoid naming conflicts, it's generally recommended to import specific functions (e.g., `from unification import unify, var`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"When performing complex unifications, especially with recursive data structures, be mindful of potential self-referential loops. Test thoroughly to understand the library's behavior in such edge cases.","message":"Unification algorithms, by default or design choice, may or may not include an 'occurs check'. Omitting this check can lead to infinite terms (e.g., unifying `x` with `f(x)`), potentially causing infinite loops or memory exhaustion if not handled. While `logical-unification` uses a generator-based design to manage recursion, complex self-referential unifications might still behave unexpectedly if an explicit occurs check is not performed.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}