Registry / ai-ml / logical-unification

logical-unification

JSON →
library0.4.7pypypi✓ verified 23d ago

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.

pip install logical-unification
INSTALL
IMPORT
SIG · LOGICAL-UNIFICATIO
L
logical-unification
ai-mlpythonv0.4.7
Install
1.9s avg
Import
120ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.122s · 18.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.118s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unify
from unification import unify
var
from unification import var
reify
from unification import reify
unifiable
from unification.core import unifiable

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.

from unification import unify, var, reify x = var() y = var() # Unify constants print(f"Unify(1, 1): {unify(1, 1)}") print(f"Unify(1, 2): {unify(1, 2)}") # Unify with a variable print(f"Unify((1, x), (1, 2)): {unify((1, x), (1, 2))}") # Unify multiple variables where they must be the same print(f"Unify((x, x), (1, 2)): {unify((x, x), (1, 2))}") # Reify a term with a substitution substitution = unify((1, x), (1, 2)) if substitution: print(f"Reify((1, x), {substitution}): {reify((1, x), substitution)}") # Unify dictionaries print(f"Unify({{\"a\": 1, \"b\": 2}}, {{\"a\": x, \"b\": 2}}): {unify({"a": 1, "b": 2}, {"a": x, "b": 2})}")
Debug
Known issues
breakingThis library requires Python 3.9 or newer. Users on older Python versions will encounter installation errors or runtime incompatibilities.
fix
Upgrade your Python environment to 3.9 or newer.
affects: <0.4.5 (if upgrading from very old versions), all versions >=0.4.5
gotchaThe `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.
fix
Verify that your `pip install` command is `pip install logical-unification` and your imports use `from unification import ...`.
affects: All versions
gotchaUsing `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`).
fix
Explicitly import the symbols you need: `from unification import unify, var, reify`.
affects: All versions
gotchaUnification 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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'logical_unification'
The package is installed as `logical-unification` (with a hyphen) but its primary module to import is named `unification` (without the `logical_` prefix and with an underscore instead of a hyphen if `logical-unification` were used directly).
fix
After installing with `pip install logical-unification`, import the library using `from unification import *` or `import unification`.
NameError: name 'unify' is not defined
This typically occurs when a user imports the module using `import unification` but then tries to call `unify()` or `var()` directly without the module prefix.
fix
Either use `from unification import unify, var` (or `from unification import *`) to bring `unify` and `var` into the global namespace, or call the functions with the module prefix, e.g., `unification.unify(term1, term2)` and `unification.var()`.
TypeError: 'bool' object is not callable
The `unify` function returns `False` when unification fails, rather than raising an exception. If a user expects a dictionary (substitution) and attempts to access it or call methods on the `False` return value, this `TypeError` can occur.
fix
Always check the return value of `unify`. It returns a dictionary (the substitution) on success and `False` on failure. Handle the `False` case explicitly: `result = unify(term1, term2); if result is not False: # Process substitution else: # Handle unification failure`.
Upgrade
Version history
0.4.7latest on PyPI · released Oct 20, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.9 or newer.
Agent activity
3 hits · last 30 days
node
2
Resources
logical-unification — pip install logical-unification · libregistry