Class Unifier
- Direct Known Subclasses:
MartelliUnifier,RobinsonUnifier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCalled by the unifier when a Term's type becomes known.static final classConstraint arising from a call to an overloaded function.static classControl flow exception, thrown byUnifier.Term.checkCycle(Map, Map)if it finds a cycle in a substitution map.private static classAn action that, when executed, marks two terms as equivalent.static interfaceResult indicating that unification was not possible.static interfaceResult of attempting unification.static interfaceResult indicating that unification may be possible if we adjust some initial parameters.static final classA sequence of terms.static classMap from variables to terms.static final classThe results of a successful unification.static interfaceTerm (variable, symbol or node).static final classA pair of terms.static interfaceVisitor for terms.static interfaceCalled on various events during unification.static final classA variable that represents a symbol or a sequence; unification's task is to find the substitutions for such variables. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String, Unifier.Sequence> private final Map<String, AtomicInteger> Assists with the generation of unique names by recording the lowest ordinal, for a given prefix, for which a name has not yet been generated.private final Map<String, Unifier.Sequence> private final Map<String, Unifier.Variable> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(String operator, Iterable<? extends Unifier.Term> args) Creates a sequence, or returns an existing one with the same terms.apply(String operator, Unifier.Term... args) Creates a sequence, or returns an existing one with the same terms.Creates an atom, or returns an existing one with the same name.atomUnique(String prefix) Creates an atom with a unique name.private static voidcheckCycles(Map<Unifier.Variable, Unifier.Term> map, Map<Unifier.Variable, Unifier.Variable> active) constraint(Unifier.Variable arg, PairList<Unifier.Term, Unifier.Constraint.Action> termActions) Creates a Constraint.constraint(Unifier.Variable arg, Unifier.Variable result, PairList<Unifier.Term, Unifier.Term> argResults) Creates a constraint arising from a call to an overloaded function.protected Unifier.Failureprivate <T> TnewName(String prefix, BiFunction<String, Integer, T> consumer) Finds an ordinal that makes a name unique among atomcs and variables.booleanoccurs()Whether this unifier checks for cycles in substitutions.(package private) static Unifier.SequencesequenceApply(String operator, Map<Unifier.Variable, Unifier.Term> substitutions, Iterable<Unifier.Term> terms) substitution(Unifier.Term... varTerms) Creates a substitution.abstract @NonNull Unifier.Resultunify(List<Unifier.TermTerm> termPairs, Map<Unifier.Variable, Unifier.Action> termActions, List<Unifier.Constraint> constraints, Unifier.Tracer tracer) variable()Creates a new variable, with a new name.variable(int ordinal) Creates a variable, or returns an existing one with the same ordinal.Creates a variable, or returns an existing one with the same name.
-
Field Details
-
variableMap
-
atomMap
-
sequenceMap
-
nameMap
Assists with the generation of unique names by recording the lowest ordinal, for a given prefix, for which a name has not yet been generated.For example, if we have called
name("T")twice, and thereby generated "T0" and "T1, then the map will containcode("T", 2), indicating that the next call toname("T")should generate "T2".
-
-
Constructor Details
-
Unifier
public Unifier()
-
-
Method Details
-
occurs
public boolean occurs()Whether this unifier checks for cycles in substitutions. -
apply
Creates a sequence, or returns an existing one with the same terms. -
apply
Creates a sequence, or returns an existing one with the same terms. -
variable
Creates a variable, or returns an existing one with the same name. -
variable
Creates a variable, or returns an existing one with the same ordinal. -
variable
Creates a new variable, with a new name. -
atom
Creates an atom, or returns an existing one with the same name. -
constraint
public Unifier.Constraint constraint(Unifier.Variable arg, Unifier.Variable result, PairList<Unifier.Term, Unifier.Term> argResults) Creates a constraint arising from a call to an overloaded function.Consider a call to an overloaded function with two overloads
c -> dande -> f. If the argument (a) unifies tocthen the result (b) isd; if the argument unifies toethen the result isf.This is created with the following call:
Constraint constraint = unifier.constraint(a, b, PairList.of(c, d, e, f)); -
constraint
public Unifier.Constraint constraint(Unifier.Variable arg, PairList<Unifier.Term, Unifier.Constraint.Action> termActions) Creates a Constraint.The following code creates a constraint where
ais allowed to be eitherterm1orterm2. When the unifier has narrowed down the options to justterm2, it will callaction2with a consumer that accepts a pair ofUnifier.Termarguments.Constraint constraint = unifier.constraint(a, PairList.of(term1, action1, term2, action2)); -
atomUnique
Creates an atom with a unique name. -
newName
Finds an ordinal that makes a name unique among atomcs and variables. -
substitution
Creates a substitution.The arguments are alternating variable / term pairs. For example,
substitution(a, x, b, y)becomes [a/X, b/Y]. -
sequenceApply
static Unifier.Sequence sequenceApply(String operator, Map<Unifier.Variable, Unifier.Term> substitutions, Iterable<Unifier.Term> terms) -
unify
public abstract @NonNull Unifier.Result unify(List<Unifier.TermTerm> termPairs, Map<Unifier.Variable, Unifier.Action> termActions, List<Unifier.Constraint> constraints, Unifier.Tracer tracer) -
checkCycles
private static void checkCycles(Map<Unifier.Variable, Unifier.Term> map, Map<Unifier.Variable, throws Unifier.CycleExceptionUnifier.Variable> active) - Throws:
Unifier.CycleException
-
failure
-