java.lang.Object
edu.upc.fib.inlab.imp.kse.logics.logicschema.domain.operations.Substitution

public class Substitution extends Object
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 Details

    • Substitution

      public Substitution()
      Constructs an empty Substitution.
    • Substitution

      public Substitution(Substitution toCopy)
      Constructs a new Substitution with the same mappings as the specified Substitution.
      Parameters:
      toCopy - the substitution whose mappings are to be placed in this substitution.
      Throws:
      IllegalArgumentException - if toCopy parameter is null.
    • Substitution

      public Substitution(List<Term> domainTerms, List<Term> rangeTerms)
      Constructs a new Substitution that maps each i-th term from domainTerms with the i-th rangeTerm.

      If such Substitution does not exist, it throws a SubstitutionException. This could happen if the domainTerms contains a Constant in the i-th position and the rangeTerms has a different term (different Constant, or Variable), in the i-th position.

      Parameters:
      domainTerms - list of Term which forms the domain of the substitution mapping.
      rangeTerms - list of Term which forms the range of the substitution mapping.
      Throws:
      IllegalArgumentException - if domainTerms or rangeTerms parameters are null.
      SubstitutionException - if arity mismatch between domain and range or if domain Constant is mapped to different Constant or Variable.
  • Method Details

    • addMapping

      public void addMapping(Variable domainVariable, Term rangeTerm)
      Modifies the Substitution 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 domain Variable or the range Term are null.
      SubstitutionException - if such mapping already exists in the Substitution.
    • union

      public Substitution union(Substitution otherSubstitution)
      Constructs a new Substitution making the union between this Substitution, and the otherSubstitution.
      Parameters:
      otherSubstitution - different Substitution.
      Returns:
      a new Substitution as a union of substitutions.
      Throws:
      IllegalArgumentException - if the other Substitution is null.
      SubstitutionException - if both substitutions try to map the same variable to different terms.
    • getTerm

      public Optional<Term> getTerm(Variable variable)
      Returns the image of the Variable.
      Parameters:
      variable - domain Variable.
      Returns:
      the image of the Variable.
      Throws:
      IllegalArgumentException - if input domain Variable is null.
    • getSize

      public int getSize()
      Returns substitution map size.
      Returns:
      substitution map size.
    • isEmpty

      public boolean isEmpty()
      Returns true if this substitution contains no mappings.
      Returns:
      true if this substitution contains no mappings
    • replacesSomeVariableOf

      public boolean replacesSomeVariableOf(Set<Variable> variables)
      Returns true if any of the variable from the input appear as the domain of a mapping.
      Parameters:
      variables - set of Variable.
      Returns:
      true if any of the variable from the input appear as the domain of a mapping.
    • getUsedVariables

      public Set<Variable> 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()
      Returns true if all mappings of the substitutions map variable to identical variables.
      Returns:
      true if all mappings of the substitutions map variable to identical variables.