Class Substitution
java.lang.Object
edu.upc.fib.inlab.imp.kse.logics.logicschema.domain.operations.Substitution
This class represents a substitution of variables to terms. I.e., it is a mapping from variables to terms, where each
variable can be mapped, at most, to one term.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an emptySubstitution
.Substitution
(Substitution toCopy) Constructs a newSubstitution
with the same mappings as the specifiedSubstitution
.Substitution
(List<Term> domainTerms, List<Term> rangeTerms) Constructs a newSubstitution
that maps each i-th term from domainTerms with the i-th rangeTerm. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMapping
(Variable domainVariable, Term rangeTerm) Modifies theSubstitution
adding a new mapping from the domainVariable to the rangeTerm.int
getSize()
Returns substitution map size.Returns the image of theVariable
.Returns all the variables appearing in the mappings (either in the domain or the range).boolean
isEmpty()
Returnstrue
if this substitution contains no mappings.boolean
Returnstrue
if all mappings of the substitutions map variable to identical variables.boolean
replacesSomeVariableOf
(Set<Variable> variables) Returnstrue
if any of the variable from the input appear as the domain of a mapping.union
(Substitution otherSubstitution) Constructs a newSubstitution
making the union between thisSubstitution
, and the otherSubstitution.
-
Constructor Details
-
Substitution
public Substitution()Constructs an emptySubstitution
. -
Substitution
Constructs a newSubstitution
with the same mappings as the specifiedSubstitution
.- Parameters:
toCopy
- the substitution whose mappings are to be placed in this substitution.- Throws:
IllegalArgumentException
- if toCopy parameter isnull
.
-
Substitution
Constructs a newSubstitution
that maps each i-th term from domainTerms with the i-th rangeTerm.If such
Substitution
does not exist, it throws aSubstitutionException
. This could happen if the domainTerms contains aConstant
in the i-th position and the rangeTerms has a different term (differentConstant
, orVariable
), in the i-th position.- Parameters:
domainTerms
- list ofTerm
which forms the domain of the substitution mapping.rangeTerms
- list ofTerm
which forms the range of the substitution mapping.- Throws:
IllegalArgumentException
- if domainTerms or rangeTerms parameters arenull
.SubstitutionException
- if arity mismatch between domain and range or if domainConstant
is mapped to differentConstant
orVariable
.
-
-
Method Details
-
addMapping
Modifies theSubstitution
adding a new mapping from the domainVariable to the rangeTerm.- Parameters:
domainVariable
- domain variable to be mapped.rangeTerm
- range term to be mapped.- Throws:
IllegalArgumentException
- if the domainVariable
or the rangeTerm
arenull
.SubstitutionException
- if such mapping already exists in theSubstitution
.
-
union
Constructs a newSubstitution
making the union between thisSubstitution
, and the otherSubstitution.- Parameters:
otherSubstitution
- differentSubstitution
.- Returns:
- a new
Substitution
as a union of substitutions. - Throws:
IllegalArgumentException
- if the otherSubstitution
isnull
.SubstitutionException
- if both substitutions try to map the same variable to different terms.
-
getTerm
Returns the image of theVariable
.- Parameters:
variable
- domainVariable
.- Returns:
- the image of the
Variable
. - Throws:
IllegalArgumentException
- if input domainVariable
isnull
.
-
getSize
public int getSize()Returns substitution map size.- Returns:
- substitution map size.
-
isEmpty
public boolean isEmpty()Returnstrue
if this substitution contains no mappings.- Returns:
true
if this substitution contains no mappings
-
replacesSomeVariableOf
Returnstrue
if any of the variable from the input appear as the domain of a mapping.- Parameters:
variables
- set ofVariable
.- Returns:
true
if any of the variable from the input appear as the domain of a mapping.
-
getUsedVariables
Returns all the variables appearing in the mappings (either in the domain or the range).- Returns:
- all the variables appearing in the mappings (either in the domain or the range).
-
isIdentity
public boolean isIdentity()Returnstrue
if all mappings of the substitutions map variable to identical variables.- Returns:
true
if all mappings of the substitutions map variable to identical variables.
-