ubc.cs.JLog.Terms
Class jNaryBuiltinPredicate

java.lang.Object
  extended by ubc.cs.JLog.Foundation.jType
      extended by ubc.cs.JLog.Terms.jTerm
          extended by ubc.cs.JLog.Terms.iPredicate
              extended by ubc.cs.JLog.Terms.jBuiltinPredicate
                  extended by ubc.cs.JLog.Terms.jNaryBuiltinPredicate
All Implemented Interfaces:
iType, iUnifiable, iConsultable, iName, iNameArity, iTerm, iValue
Direct Known Subclasses:
jInvoke5

public abstract class jNaryBuiltinPredicate
extends jBuiltinPredicate


Field Summary
protected  jCompoundTerm arguments
           
protected  int arity
           
 
Fields inherited from class ubc.cs.JLog.Foundation.jType
type
 
Fields inherited from interface ubc.cs.JLog.Terms.iTerm
EQUAL, GREATER_THAN, LESS_THAN
 
Fields inherited from interface ubc.cs.JLog.Foundation.iType
TYPE_ARITHMETIC, TYPE_ATOM, TYPE_BUILTINPREDICATE, TYPE_COMMAND, TYPE_COMPARE, TYPE_COMPOUND, TYPE_CONS, TYPE_IF, TYPE_INTEGER, TYPE_LIST, TYPE_NULLLIST, TYPE_NUMERICCOMPARE, TYPE_OBJECT, TYPE_OPERATOR, TYPE_OR, TYPE_ORPREDICATE, TYPE_PREDICATE, TYPE_PREDICATETERMS, TYPE_REAL, TYPE_TYPE, TYPE_UNARYARITHMETIC, TYPE_UNARYOPERATOR, TYPE_UNDEFINED, TYPE_VARIABLE
 
Constructor Summary
jNaryBuiltinPredicate(jCompoundTerm args, int t)
          jNaryBuiltinPredicate constructor.
 
Method Summary
 void addGoals(jGoal g, iGoalStack goals)
          Adds goal to prove this predicate onto goal stack.
 void addGoals(jGoal g, jVariable[] vars, iGoalStack goals)
          Adds goal to prove this predicate onto goal stack.
protected  int compareArguments(iPredicate ipred, boolean first_call, boolean var_equal)
          Compares predicate aguments.
 void consult(jKnowledgeBase kb)
          Consult the given jKnowledgeBase and cache any invariant values (those which would not change until the next time the jKnowledgeBase changes).
 void consultReset()
          Called when the jKnowledgeBase changes.
 jTerm copy(jVariableRegistry vars)
          Internal member function which creates a copy of this term.
protected abstract  jNaryBuiltinPredicate duplicate(jCompoundTerm args)
           
 jTerm duplicate(jVariable[] vars)
          Creates a complete and entirely independant duplicate of this term.
 void enumerateVariables(jVariableVector v, boolean all)
          Adds variables belonging to this term (or belonging to any sub-part of this term) to the jVariableVector
protected  boolean equivalenceArguments(jBuiltinPredicate pterm, jEquivalenceMapping v)
          Equivalence test arguments.
 jCompoundTerm getArguments()
          The arugments for this predicate.
 int getArity()
          Returns the arity of this instance.
 jTerm getTermAt(int i)
           
 boolean isConsultNeeded()
          Determine if cached values already exist and hence if consulting is required.
 boolean prove(jNaryBuiltinPredicateGoal bg)
           
 void registerUnboundVariables(jUnifiedVector v)
          Adds any unbound variables belonging to this term (or belonging to any sub-part of this term) to the jUnifiedVector
 void registerVariables(jVariableVector v)
          Adds all variables belonging to this term (or belonging to any sub-part of this term) to the jUnifiedVector Should be called during the consultation phase by rules for their owned terms both head and base.
 java.lang.String toString(boolean usename)
          Produces a string identifying this term, suitable for display to the console.
protected  boolean unifyArguments(jBuiltinPredicate pterm, jUnifiedVector v)
          Unification of arguments.
 
Methods inherited from class ubc.cs.JLog.Terms.jBuiltinPredicate
equivalence, unify
 
Methods inherited from class ubc.cs.JLog.Terms.iPredicate
compare
 
Methods inherited from class ubc.cs.JLog.Terms.jTerm
compare, copy, getName, getTerm, getValue, requiresCompleteVariableState, toString
 
Methods inherited from class ubc.cs.JLog.Foundation.jType
getType, objectToString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ubc.cs.JLog.Terms.iName
getName
 

Field Detail

arity

protected int arity

arguments

protected jCompoundTerm arguments
Constructor Detail

jNaryBuiltinPredicate

public jNaryBuiltinPredicate(jCompoundTerm args,
                             int t)
jNaryBuiltinPredicate constructor.

Parameters:
args - The arguments for the predicate. Arity of args must not change after construction.
t - The predicates type (typically TYPE_BUILTINPREDICATE).
Method Detail

getArity

public final int getArity()
Description copied from interface: iNameArity
Returns the arity of this instance.

Specified by:
getArity in interface iNameArity
Overrides:
getArity in class jBuiltinPredicate
Returns:
int whose value is the arity of this instance.

getTermAt

public final jTerm getTermAt(int i)

getArguments

public final jCompoundTerm getArguments()
The arugments for this predicate.

Overrides:
getArguments in class iPredicate
Returns:
The arguments of the n-ary predicate as a jCompoundTerm. The returned arguments must not be modified by adding or removing terms.

compareArguments

protected int compareArguments(iPredicate ipred,
                               boolean first_call,
                               boolean var_equal)
Description copied from class: jBuiltinPredicate
Compares predicate aguments. Override in classes with different arities.

Overrides:
compareArguments in class jBuiltinPredicate
Parameters:
ipred - the iPredicate to compare with this instance of iPredicate.
first_call - true if just invoked by public compare member function. false otherwise.
var_equal - if var_equal is true, then unbound variables are considered equal. var_equal = false is standard prolog behavior.
Returns:
LESS_THAN if this instance is less than term, EQUAL if the two terms are equal, and GREATER_THAN if this instance is greater than term.

equivalenceArguments

protected final boolean equivalenceArguments(jBuiltinPredicate pterm,
                                             jEquivalenceMapping v)
Description copied from class: jBuiltinPredicate
Equivalence test arguments. Similar behavior to that of equivalence.

Overrides:
equivalenceArguments in class jBuiltinPredicate
Parameters:
pterm - We are assured that pterm has the same type, name, and arity.
v - same as jEquivalenceMapping parameter in equivalence.
Returns:
Should test for instanceof as required and return false if there is no match, true otherwise.

unifyArguments

protected final boolean unifyArguments(jBuiltinPredicate pterm,
                                       jUnifiedVector v)
Description copied from class: jBuiltinPredicate
Unification of arguments. Similar behavior to that of unify.

Overrides:
unifyArguments in class jBuiltinPredicate
Parameters:
pterm - We are assured that pterm has the same type, name, and arity.
v - same as jUnifiedVector parameter in unify.
Returns:
Should test for instanceof as required and return false if there is no match, true otherwise.

registerVariables

public void registerVariables(jVariableVector v)
Description copied from class: jTerm
Adds all variables belonging to this term (or belonging to any sub-part of this term) to the jUnifiedVector Should be called during the consultation phase by rules for their owned terms both head and base. all variables encountered should be unbound. After call, this term should not be modified in any way.

Specified by:
registerVariables in interface iTerm
Overrides:
registerVariables in class jBuiltinPredicate
Parameters:
v - The jUnifiedVector where variables are added to. This parameter is used to as output to the caller, not as input.

enumerateVariables

public void enumerateVariables(jVariableVector v,
                               boolean all)
Description copied from class: jTerm
Adds variables belonging to this term (or belonging to any sub-part of this term) to the jVariableVector

Specified by:
enumerateVariables in interface iTerm
Overrides:
enumerateVariables in class jBuiltinPredicate
Parameters:
v - The jVariabeVector where variables are added to. This parameter is used to as output to the caller, not as input.
all - If true, then all variables should register, otherwise only add non-existentially qualified variables.

registerUnboundVariables

public void registerUnboundVariables(jUnifiedVector v)
Description copied from class: jTerm
Adds any unbound variables belonging to this term (or belonging to any sub-part of this term) to the jUnifiedVector

Specified by:
registerUnboundVariables in interface iTerm
Overrides:
registerUnboundVariables in class jTerm
Parameters:
v - The jUnifiedVector where unbound variables are added to. This parameter is used to as output to the caller, not as input.

prove

public boolean prove(jNaryBuiltinPredicateGoal bg)

addGoals

public void addGoals(jGoal g,
                     jVariable[] vars,
                     iGoalStack goals)
Description copied from class: iPredicate
Adds goal to prove this predicate onto goal stack. This version is called when the original predicate must duplicate itself (or its arguments). Add goals in the reverse order you want them evaluated.

Specified by:
addGoals in class iPredicate
Parameters:
g - The super-goal jGoal for the sub-goal that this function will add.
vars - The vector of duplicate variables produced from the previous call to registerVariables. Needed for call to duplicate.
goals - The iGoalStack to add the goal to.

addGoals

public void addGoals(jGoal g,
                     iGoalStack goals)
Description copied from class: iPredicate
Adds goal to prove this predicate onto goal stack. This version is called when the original predicate is already duplicated (usually as part of an argument for another predicate). Add goals in the reverse order you want them evaluated.

Specified by:
addGoals in class iPredicate
Parameters:
g - The super-goal jGoal for the sub-goal that this function will add.
goals - The iGoalStack to add the goal to.

duplicate

protected abstract jNaryBuiltinPredicate duplicate(jCompoundTerm args)

duplicate

public jTerm duplicate(jVariable[] vars)
Description copied from class: jTerm
Creates a complete and entirely independant duplicate of this term. User should call only for terms for which registerVariables has already been invoked. Within duplicate, any other calls to duplicate should pass along the same vars array produced by registerVariables since the same duplication path previously taken by registerVariables should be taken by duplicate. This call is designed only for terms which belong to rules and are templates for instantiation. Any variables in the term should be unbound. As implied by the modification restrictions on registerVariables, terms and their children cannot change (especially during call!)

Specified by:
duplicate in interface iTerm
Overrides:
duplicate in class jBuiltinPredicate
Parameters:
vars - The user passes in a duplicate of the variable vector produced from the previous call to registerVariables. vars is produced from the jVariableVector by creating a single duplicate variable for each variable. Since this is created in the same order as the registerVariables, it is now efficient for jVariables to return their unique duplicate.
Returns:
jTerm which is an instantiated duplicate of this term.

copy

public jTerm copy(jVariableRegistry vars)
Description copied from class: jTerm
Internal member function which creates a copy of this term. This member function is designed to duplicate a term, but without the restrictions of the duplicate function. Should only be invoked by copy() or other copy(vars). Should only invoke other copy(vars) functions. Bound variables should return a copy of the bound term.

Specified by:
copy in interface iTerm
Overrides:
copy in class jBuiltinPredicate
Parameters:
vars - The registry of variables and their duplicates. Initially this is empty. As variables generate copies, they add themselves and their copy to the jVariableRegistry, and this is output from the function call. Any further calls with the same vars ensures that the same variable (in a different term) returns the same copy.
Returns:
jTerm which is an instantiated copy of this term.

consult

public void consult(jKnowledgeBase kb)
Description copied from interface: iConsultable
Consult the given jKnowledgeBase and cache any invariant values (those which would not change until the next time the jKnowledgeBase changes). Where possible, consultable objects should minimize computation and assume that any cached values are still accurate.

Specified by:
consult in interface iConsultable
Specified by:
consult in interface iTerm
Overrides:
consult in class jTerm
Parameters:
kb - the knowledge base which attempted proofs are based upon.

consultReset

public void consultReset()
Description copied from interface: iConsultable
Called when the jKnowledgeBase changes. Should set all cached values to dirty so that a following call to consult would perform a full lookup as required.

Specified by:
consultReset in interface iConsultable
Specified by:
consultReset in interface iTerm
Overrides:
consultReset in class jTerm

isConsultNeeded

public boolean isConsultNeeded()
Description copied from interface: iConsultable
Determine if cached values already exist and hence if consulting is required. If object does not knowimmediatly whether consulting is needed, then assuming it is required.

Specified by:
isConsultNeeded in interface iConsultable
Specified by:
isConsultNeeded in interface iTerm
Overrides:
isConsultNeeded in class jBuiltinPredicate
Returns:
false if cached values are valid, true otherwise, if consult should be called.

toString

public java.lang.String toString(boolean usename)
Description copied from class: jTerm
Produces a string identifying this term, suitable for display to the console. param usename determines whether to display variables by name or identity. false is the default for displaying the term, true for displaying this term in a user query.

Specified by:
toString in interface iTerm
Overrides:
toString in class jBuiltinPredicate
Returns:
String which is a textual representation of this term.