blog
Class FuncAppTerm

java.lang.Object
  extended by blog.ArgSpec
      extended by blog.Term
          extended by blog.FuncAppTerm

public class FuncAppTerm
extends Term

Represents a function invocation.

See Also:
Term

Field Summary
 
Fields inherited from class blog.ArgSpec
location
 
Constructor Summary
FuncAppTerm(Function f)
          Creates a new function application term with the given function and no arguments.
FuncAppTerm(Function f, java.util.List argList)
          Creates a new function application term with the given function and argument list.
FuncAppTerm(Function f, Term arg)
          Creates a new function application term with the given function and a single given argument.
FuncAppTerm(Function f, Term arg1, Term arg2)
          Creates a new function application term with the given function and two given arguments.
FuncAppTerm(java.lang.String funcName, java.util.List argList)
          Creates a new function application term with the given function name and argument list.
 
Method Summary
 boolean checkTypesAndScope(Model model, java.util.Map scope)
          Type checks this function application.
 int compile(java.util.LinkedHashSet callStack)
          Ensures that all the functions used in this term are compiled.
 boolean containsRandomSymbol()
          Returns true if this ArgSpec contains any random function symbols or any type symbols (any type might have a number statement, and thus could be random).
 boolean equals(java.lang.Object o)
          Two function application terms are equal if all their arguments are equal and their functions are equal.
 java.lang.Object evaluate(EvalContext context)
          Returns the value of this argument specification in the given context.
 Term[] getArgs()
          Returns the arguments in this function application term.
 Term getCanonicalVersion()
          Returns a version of this term that uses canonical terms as much as possible.
 Function getFunction()
          Returns the function in this function application term.
 java.util.Set getGenFuncsApplied(Term subject)
          Returns the set of generating functions that are applied to the term subject by this term or any of its subterms.
 java.util.Collection getSubExprs()
          Returns the proper sub-expressions of this ArgSpec.
 ArgSpec getSubstResult(Substitution subst, java.util.Set<LogicalVar> boundVars)
          Returns the result of applying the substitution subst to this expression, excluding the logical variables in boundVars.
 Term getTimeArg()
          If the top-level function in this term is indexed by time, returns the argument that serves as the time index.
 Type getType()
          Returns the type of this term.
 BayesNetVar getVariable()
          Returns the (basic or derived) random variable that this function application term corresponds to.
 int hashCode()
           
 boolean makeOverlapSubst(Term t, Substitution theta)
          Function for computing a substitution that will make the two terms overlap.
 java.lang.String toString()
          If this function application terms involves a non-zero number of arguments, returns a string of the form f(t1, ..., tK) where f is the string representation of the function and t1, ..., tK are string representations of the argument terms.
 
Methods inherited from class blog.Term
containsTerm, getTermInScope, isConstantNull, isNumeric, makeOverlapSubst
 
Methods inherited from class blog.ArgSpec
evaluate, evaluate, getFreeVars, getLocation, getSubstResult, getValueIfNonRandom, isDetermined, setLocation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FuncAppTerm

public FuncAppTerm(Function f)
Creates a new function application term with the given function and no arguments.


FuncAppTerm

public FuncAppTerm(Function f,
                   Term arg)
Creates a new function application term with the given function and a single given argument.


FuncAppTerm

public FuncAppTerm(Function f,
                   Term arg1,
                   Term arg2)
Creates a new function application term with the given function and two given arguments.


FuncAppTerm

public FuncAppTerm(Function f,
                   java.util.List argList)
Creates a new function application term with the given function and argument list.

Parameters:
f - a Function
argList - a List of Term objects representing arguments

FuncAppTerm

public FuncAppTerm(java.lang.String funcName,
                   java.util.List argList)
Creates a new function application term with the given function name and argument list. The function itself will be found in the compilation phase based on the function name and the types of the arguments.

Parameters:
funcName - the name of a function
argList - a List of Term objects representing arugments
Method Detail

getFunction

public Function getFunction()
Returns the function in this function application term.


getArgs

public Term[] getArgs()
Returns the arguments in this function application term.


compile

public int compile(java.util.LinkedHashSet callStack)
Ensures that all the functions used in this term are compiled.

Overrides:
compile in class ArgSpec
Parameters:
callStack - Set of objects whose compile methods are parents of this method invocation. Ordered by invocation order. Used to detect cycles.

evaluate

public java.lang.Object evaluate(EvalContext context)
Description copied from class: ArgSpec
Returns the value of this argument specification in the given context. Returns null if the partial world in this context is not complete enough to evaluate this ArgSpec, or if this ArgSpec contains a free variable that is not assigned a value in the given context.

Specified by:
evaluate in class ArgSpec

getVariable

public BayesNetVar getVariable()
Returns the (basic or derived) random variable that this function application term corresponds to. If all the arguments in this function application are non-random and the function itself is random, then this is a BasicVar (specifically, a RandFuncAppVar). Otherwise, it's a DerivedVar.

Overrides:
getVariable in class ArgSpec

getSubExprs

public java.util.Collection getSubExprs()
Description copied from class: ArgSpec
Returns the proper sub-expressions of this ArgSpec. This is an empty collection if this ArgSpec has no proper sub-expressions.

This default implementation returns an empty collection.

Overrides:
getSubExprs in class ArgSpec
Returns:
unmodifiable Collection of ArgSpec

containsRandomSymbol

public boolean containsRandomSymbol()
Description copied from class: ArgSpec
Returns true if this ArgSpec contains any random function symbols or any type symbols (any type might have a number statement, and thus could be random).

Specified by:
containsRandomSymbol in class ArgSpec

getGenFuncsApplied

public java.util.Set getGenFuncsApplied(Term subject)
Description copied from class: Term
Returns the set of generating functions that are applied to the term subject by this term or any of its subterms.

The default implementation returns the union of the generating functions applied in this term's sub-expressions. This is overridden by FuncAppTerm.

Overrides:
getGenFuncsApplied in class Term
Returns:
unmodifiable set of OriginFunc

equals

public boolean equals(java.lang.Object o)
Two function application terms are equal if all their arguments are equal and their functions are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
If this function application terms involves a non-zero number of arguments, returns a string of the form f(t1, ..., tK) where f is the string representation of the function and t1, ..., tK are string representations of the argument terms. If this function application term involves zero arguments, just returns the string representation of the function.

Overrides:
toString in class java.lang.Object

checkTypesAndScope

public boolean checkTypesAndScope(Model model,
                                  java.util.Map scope)
Type checks this function application.

Specified by:
checkTypesAndScope in class ArgSpec
scope - a Map from variable names (Strings) to LogicalVar objects

getType

public Type getType()
Description copied from class: Term
Returns the type of this term. Throws an IllegalStateException if this term has not been compiled successfully (e.g., if this term is a variable that is not in scope).

Specified by:
getType in class Term

getSubstResult

public ArgSpec getSubstResult(Substitution subst,
                              java.util.Set<LogicalVar> boundVars)
Description copied from class: ArgSpec
Returns the result of applying the substitution subst to this expression, excluding the logical variables in boundVars. This method is used for recursive calls. The set boundVars should contain those variables that are bound in the syntax tree between this sub-expression and the top-level expression to which the substitution is being applied.

Specified by:
getSubstResult in class ArgSpec

getTimeArg

public Term getTimeArg()
If the top-level function in this term is indexed by time, returns the argument that serves as the time index. Otherwise, returns null.


makeOverlapSubst

public boolean makeOverlapSubst(Term t,
                                Substitution theta)
Description copied from class: Term
Function for computing a substitution that will make the two terms overlap. The necessary mappings are added to the given substitution theta. If there is no extension of theta that makes this term and t overlap, this method returns false.

Specified by:
makeOverlapSubst in class Term

getCanonicalVersion

public Term getCanonicalVersion()
Description copied from class: Term
Returns a version of this term that uses canonical terms as much as possible. The canonical term for a guaranteed object obj of type type is returned by type.getCanonicalTerm(obj). A term can be converted to canonical form only if it is non-random and has no free variables (note that if the term is non-random, its value must be a guaranteed object). This method returns a canonical version of this term if possible; otherwise, it returns a version where the subterms have been converted to canonical form as much as possible.

Specified by:
getCanonicalVersion in class Term