

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +edu.hws.jcm.data.ExpressionProgram
An ExprssionProgram represents a mathematical expression such as "3" or "sin(x^2)", stored in the form of a program for a stack machine. The program consists of a sequence of commands that, when executed, will compute the value of the expression.
Each command is encoded as an integer. There are three types of commands that can occur: (1) A negative integer must be one of the 36 constant values PLUS, MINUS,..., CUBERT. These constants represent unary and binary operators and standard functions. (2) An integer in the range 0 <= n < 0x3FFFFFFF encodes an operation of the form "push a constant onto the stack". The constant that is being pushed is encoded as an index in the array "constant", which is a private member of this class that holds all the constants that occur in this ExpressionProgram. (3) An integer >= 0x3FFFFFFF represents an ExpressionCommand object. When 0x3FFFFFFF is subtracted from the integer, the result is an index into the array "command", which is a private member of this class that holds all the ExpressionCommands that occur in this ExpressionProgram.
Field Summary  
static int 
ABS
Code for a unary or binary operator or a standard function. 
static int 
AND
Code for a unary or binary operator or a standard function. 
static int 
ARCCOS
Code for a unary or binary operator or a standard function. 
static int 
ARCSIN
Code for a unary or binary operator or a standard function. 
static int 
ARCTAN
Code for a unary or binary operator or a standard function. 
static int 
CEILING
Code for a unary or binary operator or a standard function. 
static int 
COS
Code for a unary or binary operator or a standard function. 
static int 
COT
Code for a unary or binary operator or a standard function. 
static int 
CSC
Code for a unary or binary operator or a standard function. 
static int 
CUBERT
Code for a unary or binary operator or a standard function. 
static int 
DIVIDE
Code for a unary or binary operator or a standard function. 
static int 
EQ
Code for a unary or binary operator or a standard function. 
static int 
EXP
Code for a unary or binary operator or a standard function. 
static int 
FACTORIAL
Code for a unary or binary operator or a standard function. 
static int 
FLOOR
Code for a unary or binary operator or a standard function. 
static int 
GE
Code for a unary or binary operator or a standard function. 
static int 
GT
Code for a unary or binary operator or a standard function. 
static int 
LE
Code for a unary or binary operator or a standard function. 
static int 
LN
Code for a unary or binary operator or a standard function. 
static int 
LOG10
Code for a unary or binary operator or a standard function. 
static int 
LOG2
Code for a unary or binary operator or a standard function. 
static int 
LT
Code for a unary or binary operator or a standard function. 
static int 
MINUS
Code for a unary or binary operator or a standard function. 
static int 
NE
Code for a unary or binary operator or a standard function. 
static int 
NOT
Code for a unary or binary operator or a standard function. 
static int 
OR
Code for a unary or binary operator or a standard function. 
static int 
PLUS
Code for a unary or binary operator or a standard function. 
static int 
POWER
Code for a unary or binary operator or a standard function. 
static int 
ROUND
Code for a unary or binary operator or a standard function. 
static int 
SEC
Code for a unary or binary operator or a standard function. 
static int 
SIN
Code for a unary or binary operator or a standard function. 
java.lang.String 
sourceString
If this is nonnull, it is used as the print string for this expression in the toString() method. 
static int 
SQRT
Code for a unary or binary operator or a standard function. 
static int 
TAN
Code for a unary or binary operator or a standard function. 
static int 
TIMES
Code for a unary or binary operator or a standard function. 
static int 
TRUNC
Code for a unary or binary operator or a standard function. 
static int 
UNARY_MINUS
Code for a unary or binary operator or a standard function. 
Constructor Summary  
ExpressionProgram()
Default constructor creates an initially empty program. 
Method Summary  
void 
addCommand(int code)
Add a command code to the program, where code is one of the opCode constants that are public final members of this class, from CUBERT to PLUS. 
void 
addCommandObject(ExpressionCommand com)
Adds com as the next command in the program. 
void 
addConstant(double d)
Add the number d as the next command in the program. 
void 
appendOutputString(int index,
java.lang.StringBuffer buffer)
Add a string representing part of the expression to the output buffer. 
protected double 
applyCommandCode(int code)
Apply the stack operation represented by code (a number < 0) to the stack. 
void 
compileDerivative(int index,
ExpressionProgram deriv,
Variable wrt)
The command at position index in the program represents a subexpression of the whole expression. 
void 
copyExpression(int index,
ExpressionProgram destination)
The command at position index in the program represents a subexpression of the whole expression. 
boolean 
dependsOn(int index,
Variable x)
The command at position index in the program represents a subexpression of the whole expression. 
boolean 
dependsOn(Variable x)
Checks whether the expression as a whole has any dependence on the variable x. 
Expression 
derivative(Variable wrt)
Compute the derivative of this expression with respect to the Variable wrt. 
int 
extent(int index)
The command at position index in the program represents a subexpression of the whole expression. 
double 
getVal()
Run the ExprssionProgram and return the value that it computes. 
double 
getValueWithCases(Cases c)
Run the ExprssionProgram and return the value that it computes. 
java.lang.String 
toString()
If a source string has been saved, use it as the print string. 
void 
trim()
To save space, cut the arrays that holds the program data down to the actual amount of data that they contain. 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Field Detail 
public static final int PLUS
public static final int MINUS
public static final int TIMES
public static final int DIVIDE
public static final int POWER
public static final int EQ
public static final int NE
public static final int LT
public static final int GT
public static final int LE
public static final int GE
public static final int AND
public static final int OR
public static final int NOT
public static final int UNARY_MINUS
public static final int FACTORIAL
public static final int SIN
public static final int COS
public static final int TAN
public static final int COT
public static final int SEC
public static final int CSC
public static final int ARCSIN
public static final int ARCCOS
public static final int ARCTAN
public static final int ABS
public static final int SQRT
public static final int EXP
public static final int LN
public static final int LOG2
public static final int LOG10
public static final int TRUNC
public static final int ROUND
public static final int FLOOR
public static final int CEILING
public static final int CUBERT
public java.lang.String sourceString
Constructor Detail 
public ExpressionProgram()
Method Detail 
public void addCommandObject(ExpressionCommand com)
com
 added as next command in the program.public void addConstant(double d)
d
 added as next command in program.public void addCommand(int code)
public void trim()
public double getVal()
getVal
in interface Value
public double getValueWithCases(Cases c)
getValueWithCases
in interface Expression
protected double applyCommandCode(int code)
public java.lang.String toString()
toString
in interface Expression
toString
in class java.lang.Object
public void appendOutputString(int index, java.lang.StringBuffer buffer)
public Expression derivative(Variable wrt)
derivative
in interface Expression
public void compileDerivative(int index, ExpressionProgram deriv, Variable wrt)
public int extent(int index)
public void copyExpression(int index, ExpressionProgram destination)
public boolean dependsOn(int index, Variable x)
public boolean dependsOn(Variable x)
dependsOn
in interface Expression


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 