Class Expression

java.lang.Object
org.oristool.lello.ast.Expression
Direct Known Subclasses:
BinaryExpression, Brackets, Constant, FunctionCall, UnaryExpression, Variable

public abstract class Expression extends Object
The base class for every node in Lello AST (Abstract Syntax Tree). This class provides several services to the algorithms involved in manipulating the AST, both in the form of static methods and instance methods, which can eventually be overridden in subclasses.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The tolerance beyond which two numeric values are considered the same.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Expression
    Creates a copy of the object.
    abstract Value
    eval(Bindings bindings)
    Evaluates this expression using the specified variable bindings.
    Formats this expression.
    abstract Truth
    Checks whether this expression is equal to 1 (with respect to the EPSILON tolerance).
    static final boolean
    isOneNumber(double x)
    Checks whether a double is equal to 1 (with respect to the EPSILON tolerance).
    static final boolean
    Checks whether a value is equal to 1 (with respect to the EPSILON tolerance).
    abstract Truth
    Checks whether this expression is equal to 0 (with respect to the EPSILON tolerance).
    static final boolean
    isZeroNumber(double x)
    Checks whether a double is equal to 0 (with respect to the EPSILON tolerance).
    static final boolean
    Checks whether a value is equal to 0 (with respect to the EPSILON tolerance).
    abstract Expression
    simplify(Bindings bindings, SymbolicVisitor visitor)
    Tries to simplify this expression.
     
    abstract Set<String>
    Retrieves the names of all the variables appearing in this expression.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • EPSILON

      public static final double EPSILON
      The tolerance beyond which two numeric values are considered the same.
      See Also:
  • Constructor Details

    • Expression

      public Expression()
  • Method Details

    • isZeroNumber

      public static final boolean isZeroNumber(Value x)
      Checks whether a value is equal to 0 (with respect to the EPSILON tolerance).
      Parameters:
      x - The value to be tested.
      Returns:
      true if x is equal to 0, false otherwise.
    • isZeroNumber

      public static final boolean isZeroNumber(double x)
      Checks whether a double is equal to 0 (with respect to the EPSILON tolerance). This method is internally called by isZeroNumber(Value) but it is also exposed so that the same identical rule to address the tolerance issue is available to programmers.
      Parameters:
      x - The double to be tested.
      Returns:
      true if x is equal to 0, false otherwise.
    • isOneNumber

      public static final boolean isOneNumber(Value x)
      Checks whether a value is equal to 1 (with respect to the EPSILON tolerance).
      Parameters:
      x - The value to be tested.
      Returns:
      true if x is equal to 1, false otherwise.
    • isOneNumber

      public static final boolean isOneNumber(double x)
      Checks whether a double is equal to 1 (with respect to the EPSILON tolerance). This method is internally called by isOneNumber(Value) but it is also exposed so that the same identical rule to address the tolerance issue is available to programmers.
      Parameters:
      x - The double to be tested.
      Returns:
      true if x is equal to 1, false otherwise.
    • eval

      public abstract Value eval(Bindings bindings)
      Evaluates this expression using the specified variable bindings. Calling this method does not alter this expression.

      It is important to note that this method will not attempt any kind of simplification on the expression, which means that all the variables appearing in it must be either bound or correspond to Java static fields defined somewhere; if this is not the case an exception will be thrown.

      Parameters:
      bindings - Variable bindings.
      Returns:
      The value of the expression.
    • simplify

      public abstract Expression simplify(Bindings bindings, SymbolicVisitor visitor)
      Tries to simplify this expression. Calling this method does not alter this expression.

      This method will not throw an exception if some variables appearing in the expression are not bound. However it may still be able to cancel a variable, if an appropriate rule is found.

      Parameters:
      bindings - Variable bindings.
      visitor - The visitor implementing the simplification rules.
      Returns:
      A simplified expression if an appropriate rule was found, the same expression otherwise.
    • isZero

      public abstract Truth isZero()
      Checks whether this expression is equal to 0 (with respect to the EPSILON tolerance).

      To decrease the probability that this method will return DONTKNOW, simplify or eval should be preventively called on this expression.

      Returns:
      YES if this expression is equal to 0, NO if it is not, DONTKNOW if it is not known.
    • isOne

      public abstract Truth isOne()
      Checks whether this expression is equal to 1 (with respect to the EPSILON tolerance).

      To decrease the probability that this method will return DONTKNOW, simplify or eval should be preventively called on this expression.

      Returns:
      YES if this expression is equal to 1, NO if it is not, DONTKNOW if it is not known.
    • variables

      public abstract Set<String> variables()
      Retrieves the names of all the variables appearing in this expression.
      Returns:
      set of variables
    • copy

      public abstract Expression copy()
      Creates a copy of the object.
      Returns:
      a copy
    • format

      public String format(FormatVisitor visitor)
      Formats this expression.
      Parameters:
      visitor - The visitor implementing the formatting rules.
      Returns:
      The formatted string.
    • toString

      public String toString()
      Overrides:
      toString in class Object