Class SimpleConstSubstitution

java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.substitution.SimpleConstSubstitution
All Implemented Interfaces:
ConstOnlySubstitution, Substitution

public class SimpleConstSubstitution extends Object implements ConstOnlySubstitution
A mapping from variables to constants.
  • Constructor Details

    • SimpleConstSubstitution

      public SimpleConstSubstitution()
      Constructs an empty substitution.
    • SimpleConstSubstitution

      public SimpleConstSubstitution(SimpleConstSubstitution other)
      Constructs a copy of another substitution.
      Parameters:
      other - the other substitution
  • Method Details

    • get

      public Constant get(Variable v)
      Returns the constant a variable is mapped to in this substitution.
      Specified by:
      get in interface ConstOnlySubstitution
      Specified by:
      get in interface Substitution
      Parameters:
      v - the variable
      Returns:
      the constant, or null if v is not mapped
    • put

      public void put(Variable v, Constant c)
      Adds a mapping from a variable to a constant to this substitution.
      Parameters:
      v - the variable
      c - the constant
      Throws:
      IllegalArgumentException - if v is already mapped to another constant
    • unify

      public static SimpleConstSubstitution unify(Term[] xs, Term[] ys)
      Creates a substitution from unifying two lists of terms, the second of which must be ground (i.e., contain no variables).
      Parameters:
      xs - the first list
      ys - the second list, which must be ground
      Returns:
      the substitution, or null if the unification is not possible
      Throws:
      IllegalArgumentException - if the second list of terms is not ground
    • apply

      public Term[] apply(Term[] terms)
      Description copied from interface: Substitution
      Apply this substitution to a list of terms, creating a new list.
      Specified by:
      apply in interface Substitution
      Parameters:
      terms - the original list
      Returns:
      the new list
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • add

      public boolean add(Variable x, Constant c)
      Description copied from interface: ConstOnlySubstitution
      Attempts to add a mapping to the substitution. Returns true if the mapping was made successfully (i.e., if the variable was not already mapped to another constant).
      Specified by:
      add in interface ConstOnlySubstitution
      Parameters:
      x - the variable
      c - the constant
      Returns:
      whether the mapping was successfully added