prolog-unification

Unify logical terms with variables and compound structures using the Martelli–Montanari algorithm.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill prolog-unification
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prolog-unification
Source: https://github.com/hafley66/claude-research/tree/main/skills/prolog-unification
Command: npx skills add https://github.com/hafley66/claude-research --skill prolog-unification

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Unification is the single operation that drives all of Prolog's computation. Given two terms, unification finds a substitution -- a set of variable bindings -- that makes the two terms syntactically identical. If no such substitution exists, unification fails.

Core Features & Use Cases

  • Bidirectional variable binding and aliasing, enabling both sides to carry unbound variables that resolve during solving.
  • Handling constants, variables, and compound terms (including lists) with recursive, structural matching and backtracking support.
  • Occurs check discussion and practical tradeoffs used to prevent infinite terms, with guidance on when to enable a full occurs check.
  • Substitution environment semantics: write-once bindings, transitive resolution, and backtracking rollback.

Quick Start

Demonstrate unifying f(X, g(Y, a)) with f(h(Z), g(b, Z)) and display the final substitution.

Frequently Asked Questions about prolog-unification

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does Prolog unification work when matching compound terms?

Unification in Prolog finds a substitution set of variable bindings that makes two terms syntactically identical. It structurally decomposes constants, variables, and compound terms, binding variables bidirectionally until the terms match or fail.

How do I unify terms with unbound variables on both sides in logic programming?

Bidirectional variable binding allows both terms to carry unbound variables that resolve during solving. The unification process creates write-once aliases and transitively resolves substitutions until both terms become identical.

What is the occurs check in Prolog and when should I enable it?

The occurs check prevents infinite terms by verifying a variable does not appear within the term it binds to. Enable it during constraint solving when logically sound substitutions are required, accepting the performance tradeoff.

How do I unify f(X, g(Y, a)) with f(h(Z), g(b, Z)) step by step?

Unifying f(X, g(Y, a)) with f(h(Z), g(b, Z)) matches compound structures recursively. The resulting substitution binds X to h(Z) and Y to b, resolving Z transitively to produce a consistent binding environment.

Does the Martelli-Montanari algorithm support backtracking for unification?

The Martelli-Montanari algorithm provides backtracking-ready solutions through write-once substitution environments with rollback semantics. If unification fails, the environment rolls back previous bindings to explore alternative matching paths.