blog
Class LogicalVar

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

public class LogicalVar
extends Term

A logical variable. Specifically, a single LogicalVar object is used for the introduction of a logical variable in a particular scope, and for all uses of the variable in that scope. Unlike other terms, LogicalVar objects can be compared safely using ==.

Note that some LogicalVar objects are not created directly by the parser, but are returned by the getTermInScope method on SymbolTerm. This is because, in some contexts, the parser cannot distinguish a logical variable from a constant symbol based on local syntax alone.


Field Summary
 
Fields inherited from class blog.ArgSpec
location
 
Constructor Summary
LogicalVar(java.lang.String name, Type type)
          Creates a new LogicalVar with the given name and type.
 
Method Summary
 boolean checkTypesAndScope(Model model, java.util.Map scope)
          Returns true if, within the given scope, all the variables used in this ArgSpec are in scope and all type constraints are satisfied.
 int compile(java.util.LinkedHashSet callStack)
          Does compilation steps that can only be done correctly once the model is complete.
 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).
static LogicalVar createVar(Type type)
           
 java.lang.Object evaluate(EvalContext context)
          Returns the value of this argument specification in the given context.
 Term getCanonicalVersion()
          Returns a version of this term that uses canonical terms as much as possible.
 java.util.Set getFreeVars()
          Returns the logical variables that occur free in this expression.
 java.lang.String getName()
          Returns the name of this variable.
 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.
 Type getType()
          Returns the type of this variable.
 BayesNetVar getVariable()
          Returns the (basic or derived) random variable that this argument specification corresponds to.
 LogicalVar makeNew()
           
 boolean makeOverlapSubst(Term t, Substitution theta)
          Function for computing a substitution that will make the two terms overlap.
 java.lang.String toString()
          Returns the name of this variable.
 
Methods inherited from class blog.Term
containsTerm, getGenFuncsApplied, getTermInScope, isConstantNull, isNumeric, makeOverlapSubst
 
Methods inherited from class blog.ArgSpec
evaluate, evaluate, getLocation, getSubExprs, getSubstResult, getValueIfNonRandom, isDetermined, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogicalVar

public LogicalVar(java.lang.String name,
                  Type type)
Creates a new LogicalVar with the given name and type.

Method Detail

getName

public java.lang.String getName()
Returns the name of this variable.


checkTypesAndScope

public boolean checkTypesAndScope(Model model,
                                  java.util.Map scope)
Description copied from class: ArgSpec
Returns true if, within the given scope, all the variables used in this ArgSpec are in scope and all type constraints are satisfied. If there is a type or scope error, prints an appropriate message to standard error and returns false.

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

compile

public int compile(java.util.LinkedHashSet callStack)
Description copied from class: ArgSpec
Does compilation steps that can only be done correctly once the model is complete. Prints messages to standard error if any errors are encountered. Returns the number of errors encountered.

This default implementation just returns 0.

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.

getType

public Type getType()
Returns the type of this variable.

Specified by:
getType in class Term

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()
Description copied from class: ArgSpec
Returns the (basic or derived) random variable that this argument specification corresponds to. Assumes this argument specification contains no free variables. The default implementation just returns a DerivedVar with this ArgSpec. However, some argument specifications (such as function application terms and atomic formulas) may correspond to BasicVars.

Overrides:
getVariable in class 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

getFreeVars

public java.util.Set getFreeVars()
Description copied from class: ArgSpec
Returns the logical variables that occur free in this expression. If this expression was loaded from a file, then this method should be called only after checkTypesAndScope, which converts SymbolTerms to LogicalVars.

The default implementation returns the union of the sets of free variables in this expression's sub-expressions.

Overrides:
getFreeVars in class ArgSpec
Returns:
unmodifiable Set of LogicalVar

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

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

makeNew

public LogicalVar makeNew()

toString

public java.lang.String toString()
Returns the name of this variable.

Overrides:
toString in class java.lang.Object

createVar

public static LogicalVar createVar(Type type)