AbstractUnificator

abstract class AbstractUnificator(val context: Substitution) : Unificator

Skeletal Unificator implementation, providing a complete, equation-based unification algorithm (in the style of Martelli & Montanari's): both mgu and merge repeatedly decompose their operands into Equations and simplify them (structurally comparing Terms, applying resulting variable assignments to the remaining equations) until either a contradiction is found (failure) or no equation can be simplified further (success).

The only decision left to subclasses is checkTermsEquality, namely how two non-variable Terms are compared while building equations — this is exactly what distinguishes Unificator.strict from Unificator.naive. Subclasses that additionally need to observe or alter the equation-solving process itself (e.g. to reject some equations based on custom criteria, or to inspect the final result) may also override handleEquation and/or handleResult; both default to the identity function and thus have no effect unless overridden.

val caseInsensitive =
object : AbstractUnificator() {
override fun checkTermsEquality(first: Term, second: Term): Boolean = when {
first.isAtom && second.isAtom ->
first.castToAtom().value.equals(second.castToAtom().value, ignoreCase = true)
else -> first == second
}
}
caseInsensitive.match(Atom.of("Foo"), Atom.of("foo")) // true

Parameters

context

the starting bindings assumed by this Unificator; see Unificator.context

Constructors

Link copied to clipboard
constructor(context: Substitution)
constructor()

Creates an AbstractUnificator with an empty starting context.

Properties

Link copied to clipboard
open override val context: Substitution

Functions

Link copied to clipboard
open fun match(term1: Term, term2: Term): Boolean

Tells whether term1 and term2 match each other, that is, whether mgu would succeed for them. Performs unification with occurs-check enabled.

open fun match(term1: Term, term2: Term, occurCheckEnabled: Boolean): Boolean

Tells whether term1 and term2 match each other, that is, whether mgu would succeed for them, optionally enabling occurs-check.

Link copied to clipboard
open override fun merge(substitution1: Substitution, substitution2: Substitution, occurCheckEnabled: Boolean): Substitution

When occurCheckEnabled is false, this first attempts a quick Substitution.plus-based union of context, substitution1 and substitution2; only if that union is contradictory does it fall back to the full, equation-based merge (which also re-unifies, rather than merely composes, bindings shared by both operands).

open fun merge(substitution1: Substitution, substitution2: Substitution): Substitution

Merges substitution1 and substitution2, with occurs-check enabled.

Link copied to clipboard
open override fun mgu(term1: Term, term2: Term, occurCheckEnabled: Boolean = true): Substitution

Calculates the Most General Unifier of term1 and term2, optionally enabling occurs-check.

open fun mgu(term1: Term, term2: Term): Substitution

Calculates the Most General Unifier of term1 and term2, with occurs-check enabled.

Link copied to clipboard
open fun unify(term1: Term, term2: Term): Term?

Unifies term1 and term2 if possible, with occurs-check enabled.

open fun unify(term1: Term, term2: Term, occurCheckEnabled: Boolean): Term?

Unifies term1 and term2 if possible, optionally enabling occurs-check.