org.deri.iris.builtins
Class ArithmeticBuiltin

java.lang.Object
  extended by org.deri.iris.builtins.AbstractBuiltin
      extended by org.deri.iris.builtins.ArithmeticBuiltin
All Implemented Interfaces:
Comparable<IAtom>, IAtom, IBuiltinAtom
Direct Known Subclasses:
AddBuiltin, DivideBuiltin, EqualBuiltin, ExactEqualBuiltin, MaxBuiltin, ModulusBuiltin, MultiplyBuiltin, SubtractBuiltin

public abstract class ArithmeticBuiltin
extends AbstractBuiltin

Base class of arithmetic built-in predicates. This kind of built-in has: a) can have any arity b) can be evaluated with up to 1 unknown variable c) the unknown variable can be at any position d) if all terms are known at evaluation time, the result is checked to indicate true or false


Field Summary
 
Fields inherited from class org.deri.iris.builtins.AbstractBuiltin
EMPTY_TERM
 
Constructor Summary
ArithmeticBuiltin(IPredicate predicate, ITerm... terms)
          Constructor.
 
Method Summary
protected abstract  ITerm computeMissingTerm(int missingTermIndex, ITerm[] terms)
          Compute the missing term when the other two are known.
protected  ITerm evaluateTerms(ITerm[] terms, int[] variableIndexes)
          Evaluate the predicate once the terms and variable indexes have been found.
 int maxUnknownVariables()
          The maximum number of unknown variables allowed such that the predicate can still be evaluated.
protected  boolean testForEquality(ITerm t1, ITerm t2)
           
 
Methods inherited from class org.deri.iris.builtins.AbstractBuiltin
compareTo, equals, evaluate, getPredicate, getTuple, hashCode, isBuiltin, isGround, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArithmeticBuiltin

public ArithmeticBuiltin(IPredicate predicate,
                         ITerm... terms)
Constructor.

Parameters:
predicate - The predicate that identifies this built-in.
terms - The terms of the instance. Must be 3.
Method Detail

evaluateTerms

protected ITerm evaluateTerms(ITerm[] terms,
                              int[] variableIndexes)
                       throws EvaluationException
Description copied from class: AbstractBuiltin
Evaluate the predicate once the terms and variable indexes have been found.

Overrides:
evaluateTerms in class AbstractBuiltin
Parameters:
terms - The array of all terms for this evaluation.
variableIndexes - the indexes of the terms which should be computed (starting at 0)
Returns:
The result of the evaluation.
Throws:
EvaluationException

testForEquality

protected boolean testForEquality(ITerm t1,
                                  ITerm t2)

computeMissingTerm

protected abstract ITerm computeMissingTerm(int missingTermIndex,
                                            ITerm[] terms)
                                     throws EvaluationException
Compute the missing term when the other two are known.

Parameters:
terms - The collection of all terms.
Returns:
The computed value.
Throws:
EvaluationException

maxUnknownVariables

public int maxUnknownVariables()
Description copied from interface: IBuiltinAtom
The maximum number of unknown variables allowed such that the predicate can still be evaluated.

Specified by:
maxUnknownVariables in interface IBuiltinAtom
Overrides:
maxUnknownVariables in class AbstractBuiltin
Returns:
The maximum number of unknown variables.