Class UnionFindBasedUnifier
java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.substitution.UnionFindBasedUnifier
- All Implemented Interfaces:
Substitution
,TermUnifier
A mapping from variables to terms. Implemented using a union-find data structure.
-
Constructor Summary
ConstructorDescriptionConstructs an empty substitution.Constructs a substitution from another substitution. -
Method Summary
Modifier and TypeMethodDescriptionTerm[]
Apply this substitution to a list of terms, creating a new list.static Substitution
Creates a substitution from unifying two arrays of terms.static UnionFindBasedUnifier
Creates a substitution from unifying two lists of terms.Retrieves the mapping of a variable.void
Adds a mapping from a variable to a term.toString()
boolean
Attempts to unify a variable with a term.
-
Constructor Details
-
UnionFindBasedUnifier
public UnionFindBasedUnifier()Constructs an empty substitution. -
UnionFindBasedUnifier
Constructs a substitution from another substitution.- Parameters:
other
- the other substitution
-
-
Method Details
-
get
Retrieves the mapping of a variable.- Specified by:
get
in interfaceSubstitution
- Parameters:
x
- the variable- Returns:
- the term that the variable is bound to, or null if the variable is not in the substitution
-
apply
Description copied from interface:Substitution
Apply this substitution to a list of terms, creating a new list.- Specified by:
apply
in interfaceSubstitution
- Parameters:
original
- the original list- Returns:
- the new list
-
fromTerms
Creates a substitution from unifying two lists of terms.- Parameters:
xs
- the first listys
- the second list- Returns:
- the substitution, or null if the two lists do not unify
-
fromTerms
Creates a substitution from unifying two arrays of terms.- Parameters:
xs
- the first arrayys
- the second array- Returns:
- the substitution, or null if the two lists do not unify
-
put
Adds a mapping from a variable to a term. Throws an IllegalArgumentException if doing so would result in a variable mapping to multiple constants.- Parameters:
v
- the variablet
- the term- Throws:
IllegalArgumentException
- If the variable is already mapped to a different term
-
toString
-
unify
Description copied from interface:TermUnifier
Attempts to unify a variable with a term. Returns a boolean representing whether the unification was successful. Unification fails if it would lead to a variable being unified with two distinct constants.- Specified by:
unify
in interfaceTermUnifier
- Parameters:
u
- the variablev
- the term- Returns:
- whether the unification was successful
-