ai.krr.fol
Class Constant

java.lang.Object
  extended by ai.krr.fol.Term
      extended by ai.krr.fol.Constant
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Term>

public class Constant
extends Term

The most basic Term is a Constant that is represented by a Symbol. ConstantTerms or constants are usually used in logic to represent named individuals or concepts.

Author:
Gerhard Wickler
See Also:
Symbol

Field Summary
protected  Symbol theSy
          the Symbol contained in this Constant
 
Constructor Summary
Constant(Symbol aSy)
           This constructor just takes the Symbol that is this Term.
 
Method Summary
protected  void addConstants(java.util.Set<Symbol> sys)
           This function adds all the constant Symbols used in this Term to the given Set.
protected  void addFreeVariables(java.util.Set<Variable> free, java.util.Set<Variable> bound)
           This function adds the free Variables in this Term to the first given Set.
protected  void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)
           This function adds all the function Symbols used in this Term to the given Set.
protected  void addVariables(java.util.Set<Variable> vars)
           This function adds the Variables in this Term to the given Set.
 Constant clone()
           Cloning a Constant returns this Constant (containing the same Symbol).
 Constant clone(Substitution s)
           Cloning a Constant under a given Substitution returns this Constant.
 int compareTo(Constant other)
           This function compares this Constant to the given Constant.
 int compareTo(Term other)
           This function compares this Constant to the given Term.
 boolean equals(Constant other)
           A Constant is equal to any other Constant that holds an equal Symbol.
 boolean equals(java.lang.Object other)
           A Constant can only be equal to any other Constant.
 java.lang.Object evaluate(Interpretation ipt, Substitution s)
           This function evaluates this Term under the given Interpretation and Substitution for Variables.
 boolean exceedsDepth(int depth)
           This function tests whether this Term exceeds the given depth which should be a non-negative integer.
 int getDepth()
           This function returns the nesting depth of this Term.
 Symbol getSymbol()
           This function can be used to extract the Symbol contained in this Constant.
 int hashCode()
           This function returns the hash code of this Constant which is the hash code of the contained symbol.
 boolean isGround()
           This function tests whether this Term contains any Variables.
 java.lang.String toString()
           A Constant is printed as the Symbol it holds.
 boolean unify(Term other, Substitution s)
           This function attempts to extend the given Substitution so that this Term and the given Term are unified.
 
Methods inherited from class ai.krr.fol.Term
getVariables
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

theSy

protected final Symbol theSy
the Symbol contained in this Constant

Constructor Detail

Constant

public Constant(Symbol aSy)

This constructor just takes the Symbol that is this Term. Note that there is only one NamedSymbol (in memory) with this name, but there may well be several Constants containing the same Symbol. The given Symbol can be any type of Symbol, except a BooleanSymbol.

Parameters:
aSy - the Symbol that is this Term
Method Detail

clone

public Constant clone()

Cloning a Constant returns this Constant (containing the same Symbol).

Specified by:
clone in class Term
Returns:
this same Java Object

clone

public Constant clone(Substitution s)

Cloning a Constant under a given Substitution returns this Constant. Since a Constant cannot contain Variables the Substitution will be ignored.

Specified by:
clone in class Term
Parameters:
s - a Substitution (will be ignored)
Returns:
this same Java Object

isGround

public final boolean isGround()

This function tests whether this Term contains any Variables. Constants never contain Variables.

Specified by:
isGround in class Term
Returns:
always true

getDepth

public final int getDepth()

This function returns the nesting depth of this Term. The depth of a Constant is defined to be 0.

Specified by:
getDepth in class Term
Returns:
the depth of this Term when seen as a tree

exceedsDepth

public final boolean exceedsDepth(int depth)

This function tests whether this Term exceeds the given depth which should be a non-negative integer.

Specified by:
exceedsDepth in class Term
Parameters:
depth - the depth value that is tested for
Returns:
true iff this.getDepth() > depth

evaluate

public java.lang.Object evaluate(Interpretation ipt,
                                 Substitution s)

This function evaluates this Term under the given Interpretation and Substitution for Variables. If all sub-Terms occurring in the Term have a value assigned by the Interpretation the result will be a Object from the Interpretation's domain.

Specified by:
evaluate in class Term
Parameters:
ipt - the Interpretation giving values for Terms
s - the Substitution for Variables occurring in this Term
Returns:
the value of this Term under the given Interpretation

unify

public boolean unify(Term other,
                     Substitution s)

This function attempts to extend the given Substitution so that this Term and the given Term are unified. It returns true if and only if this is possible. If the other Term is a Constant then unification succeeds only if the two contained Symbols are equal. If the other Term is a Variable then unification succeeds only if the given Substitution can be extended accordingly. FunctionTerms can never be unified with Constants.

Specified by:
unify in class Term
Parameters:
other - the other Term this Constant is to be unified with
s - the Substitution to be extended for the unification
Returns:
whether a unifying extension of the given Substitution was possible

compareTo

public int compareTo(Term other)

This function compares this Constant to the given Term. Variables and FunctionTerms are both considered to come after Constants in the order defined here.

Specified by:
compareTo in interface java.lang.Comparable<Term>
Specified by:
compareTo in class Term
Parameters:
other - the Term to which this Constant is to be compared
Returns:
0 if the two Constants are equal; -1 if the given Term should come after this Constant; and +1 if the given Term should come before this Constant

getSymbol

public final Symbol getSymbol()

This function can be used to extract the Symbol contained in this Constant.

Returns:
the Symbol contained in this Constant

compareTo

public int compareTo(Constant other)

This function compares this Constant to the given Constant. The order between Constants is defined by the order of the Symbols they contain.

Parameters:
other - the Constant to which this Constant is to be compared
Returns:
0 if the two Constants are equal; -1 if the given Constant should come after this Constant; and +1 if the given Constant should come before this Constant

addConstants

protected void addConstants(java.util.Set<Symbol> sys)

This function adds all the constant Symbols used in this Term to the given Set.

Specified by:
addConstants in class Term
Parameters:
sys - the Set that will contain all the Constants

addFunctions

protected final void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)

This function adds all the function Symbols used in this Term to the given Set.

Specified by:
addFunctions in class Term
Parameters:
sys - the Set that will contain all the function names

addVariables

protected final void addVariables(java.util.Set<Variable> vars)

This function adds the Variables in this Term to the given Set. However, since Constants do not contain Variables this function effectively does nothing.

Specified by:
addVariables in class Term
Parameters:
vars - a Set of Variables (will be ignored)

addFreeVariables

protected final void addFreeVariables(java.util.Set<Variable> free,
                                      java.util.Set<Variable> bound)

This function adds the free Variables in this Term to the first given Set. Variables in the second given Set are bound and will not be added.

Specified by:
addFreeVariables in class Term
Parameters:
free - a Set of free Variables that will be extended
bound - a Set of bound Variables that will not be added

toString

public java.lang.String toString()

A Constant is printed as the Symbol it holds.

Overrides:
toString in class java.lang.Object
Returns:
the String for the contained Symbol

equals

public boolean equals(java.lang.Object other)

A Constant can only be equal to any other Constant. It never equals a Variable or any other kind of Term.

Overrides:
equals in class java.lang.Object
Parameters:
other - the Object this Constant is compared to
Returns:
whether the given Object equals this Constant

equals

public boolean equals(Constant other)

A Constant is equal to any other Constant that holds an equal Symbol.

Parameters:
other - the Constant this Constant is compared to
Returns:
whether the given Constant equals this Constant

hashCode

public final int hashCode()

This function returns the hash code of this Constant which is the hash code of the contained symbol.

Overrides:
hashCode in class java.lang.Object
Returns:
a positive integer that may be used for hashing