ai.krr.fol
Class FunctionTerm

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

public class FunctionTerm
extends Term

This class allows to build structured Terms that consist of a function symbol and a number of arguments. There must be at least one argument, otherwise this FunctionTerm is a Constant and should be represented as such.

Author:
Gerhard Wickler

Field Summary
protected  Term[] arguments
           
protected  Symbol function
           
 
Constructor Summary
FunctionTerm(Symbol fSymbol, java.util.List<Term> someTerms)
           This constructor for a FunctionTerm takes a function Symbol and a List of argument Terms.
FunctionTerm(Symbol fSymbol, Term... someTerms)
           This constructor for a FunctionTerm takes a function Symbol and a number of argument Terms; at least one.
 
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 FunctionTerm to the given Set.
 FunctionTerm clone()
           Returns a shallow copy of this FunctionTerm.
 FunctionTerm clone(Substitution s)
           Returns a deep copy of this FunctionTerm with Variables replaced according to the given Substitution.
 int compareTo(FunctionTerm other)
           This function compares this FunctionTerm to the given FunctionTerm.
 int compareTo(Term other)
           This function compares this FunctionTerm to the given Term.
 boolean equals(FunctionTerm other)
           A FunctionTerm is equal to any other FunctionTerm that consists of an equal function symbol followed by an equal number of equal Terms.
 boolean equals(java.lang.Object obj)
           A FunctionTerm is only equal to another FunctionTerm.
 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.
 Term[] getArguments()
           This function returns the arguments of this FunctionTerm.
 int getDepth()
           This function returns the nesting depth of this Term.
 Symbol getFunction()
           This function returns the function symbol used in this FunctionTerm which is a NamedSymbol.
 int hashCode()
           This function returns the hash code of this FunctionTerm.
 boolean isGround()
           This function tests whether this Term contains any Variables.
 java.lang.String toString()
           A FunctionTerm is printed as <function> ( <term>+ ).
 boolean unify(Term other, Substitution s)
           This function attempts to extend the given Substitution so that this FunctionTerm 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

function

protected final Symbol function

arguments

protected final Term[] arguments
Constructor Detail

FunctionTerm

public FunctionTerm(Symbol fSymbol,
                    java.util.List<Term> someTerms)

This constructor for a FunctionTerm takes a function Symbol and a List of argument Terms. Note that the given List must contain at least one Term.

Parameters:
fSymbol - the function symbol
someTerms - the List of argument Terms

FunctionTerm

public FunctionTerm(Symbol fSymbol,
                    Term... someTerms)

This constructor for a FunctionTerm takes a function Symbol and a number of argument Terms; at least one.

Parameters:
fSymbol - the function symbol
someTerms - the argument Terms
Method Detail

clone

public FunctionTerm clone()

Returns a shallow copy of this FunctionTerm. Argument Terms in the copy will be the same as the original ones.

Specified by:
clone in class Term
Returns:
an equal copy of this FunctionTerm

clone

public FunctionTerm clone(Substitution s)

Returns a deep copy of this FunctionTerm with Variables replaced according to the given Substitution. Symbols in the copy will be the same as the original ones but Variables will be replaced by the respective Terms in the given Substitution. The function uses Term.clone(Substitution) again to generate the copies of all the argument Terms in this FunctionTerm.

Specified by:
clone in class Term
Parameters:
s - the Substitution that tells us how to replace Variables
Returns:
a new FunctionTerm that is an instance of this FunctionTerm; the Substitution s will extended with any new Variable replacements introduced

isGround

public boolean isGround()

This function tests whether this Term contains any Variables. This is true only if one of the arguments contains a Variable.

Specified by:
isGround in class Term
Returns:
true iff this Term contains no Variables

getDepth

public int getDepth()

This function returns the nesting depth of this Term. The depth of a FunctionTerm is the maximum depth of the sub-Term plus 1.

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

exceedsDepth

public 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 an Object which is an element of 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 FunctionTerm and the given Term are unified. It returns true if and only if this is possible. If the other Term is a FunctionTerm then unification succeeds only if the two function symbols are equal and the Substitution can be extended to unify all arguments. If the other Term is a Variable then unification succeeds only if the given Substitution can be extended accordingly.

Specified by:
unify in class Term
Parameters:
other - the other Term this FunctionTerm 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 FunctionTerm to the given Term. Variables and Constants are both considered to come before FunctionTerms 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 FunctionTerm is to be compared
Returns:
0 if the two FunctionTerms are equal; -1 if the given Term should come after this FunctionTerm; and +1 if the given Term should come before this FunctionTerm

getFunction

public final Symbol getFunction()

This function returns the function symbol used in this FunctionTerm which is a NamedSymbol.

Returns:
the function used in this FunctionTerm

getArguments

public final Term[] getArguments()

This function returns the arguments of this FunctionTerm.

Returns:
the arguments of this FunctionTerm

compareTo

public int compareTo(FunctionTerm other)

This function compares this FunctionTerm to the given FunctionTerm. The order between FunctionTerms is defined by the order of the function symbols and the sub-Terms they contain. First the function symbols are compared. Next, the first sub-Terms are compared and if they are equal the second sub-Terms are compared etc. It is like an alphabetical sorting.

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

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 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 void addVariables(java.util.Set<Variable> vars)

This function adds the Variables in this FunctionTerm to the given Set.

Specified by:
addVariables in class Term
Parameters:
vars - a Set of Variables that will be extended

addFreeVariables

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. 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 FunctionTerm is printed as <function> ( <term>+ ).

Overrides:
toString in class java.lang.Object
Returns:
the String that represents this FunctionTerm

equals

public boolean equals(java.lang.Object obj)

A FunctionTerm is only equal to another FunctionTerm.

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

equals

public boolean equals(FunctionTerm other)

A FunctionTerm is equal to any other FunctionTerm that consists of an equal function symbol followed by an equal number of equal Terms.

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

hashCode

public int hashCode()

This function returns the hash code of this FunctionTerm.

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