01: /*************************************************************************
02: * *
03: * 1) This source code file, in unmodified form, and compiled classes *
04: * derived from it can be used and distributed without restriction, *
05: * including for commercial use. (Attribution is not required *
06: * but is appreciated.) *
07: * *
08: * 2) Modified versions of this file can be made and distributed *
09: * provided: the modified versions are put into a Java package *
10: * different from the original package, edu.hws; modified *
11: * versions are distributed under the same terms as the original; *
12: * and the modifications are documented in comments. (Modification *
13: * here does not include simply making subclasses that belong to *
14: * a package other than edu.hws, which can be done without any *
15: * restriction.) *
16: * *
17: * David J. Eck *
18: * Department of Mathematics and Computer Science *
19: * Hobart and William Smith Colleges *
20: * Geneva, New York 14456, USA *
21: * Email: eck@hws.edu WWW: http://math.hws.edu/eck/ *
22: * *
23: *************************************************************************/package edu.hws.jcm.data;
24:
25: /**
26: * An ExpressionCommand can occur as a command in an ExpressionProgram. ExpressionCommands
27: * exists so that ExprssionPrograms can be extened to include new types of operations beyond
28: * the basic operations (such as PLUS and SIN) which are represented by constants in the
29: * ExpressionProgram class. Examples include ConditionalExpressions and user-defined functions.
30: * This interface is not meant for casual programmers. It is for programmers who want to
31: * extend the notion of Expression in an orginal way.
32: *
33: */
34: public interface ExpressionCommand extends java.io.Serializable {
35:
36: /**
37: * This routine is called when an ExpressionCommand object is encountered during
38: * the evaluation of an ExpressionProgram. The stack may contain results of
39: * previous commands in the program. For example, for a ConditionalExpression, it
40: * contains the value of the boolean condition, and for a user-defined function,
41: * it contains the values of the arguments of the function. When apply() is called,
42: * the ExpressionCommand should perform any stack operations that are necessary
43: * to evaluate itself. For example, a user-defined function would remove its arguments
44: * from the stack and replace them with the value of the function at those arguments.
45: * If cases is non-null, then any case information generated during the evaluation
46: * should be recorded in cases. (See the Cases class for more information.)
47: *
48: * @param stack contains results of previous commands in the program.
49: * @param cases if non-null, any case information generated during evaluation should be recorded here.
50: */
51: public void apply(StackOfDouble stack, Cases cases);
52:
53: /**
54: * The ExpressionCommand occurs in the program prog at the index indicated by myIndex.
55: * Add commands to deriv that will evaluate the derivative of this command with respect to
56: * the variable wrt. prog and myIndex are provided so that this routine will have access
57: * to any commands in prog that generate data used by this command (for example, the commands
58: * that evaluate the arguments of a user-defined function).
59: *
60: * @param prog program in which ExpressionCommand occurs.
61: * @param myIndex point at which ExpressionCommand occurs in the ExpressionProgram.
62: * @param deriv the derivative of the ExpressionPorgram prog, which is in the process of being computed.
63: Commands should added to deriv that will compute the derivative of this ExpressionCommand.
64: * @param wrt commands are added to deriv with respect to this Variable.
65: */
66: public void compileDerivative(ExpressionProgram prog, int myIndex,
67: ExpressionProgram deriv, Variable wrt);
68:
69: /**
70: * The ExpressionCommand occurs in the program prog at the index indicated by myIndex.
71: * Return the total number of indices in prog occupied by this command and the commands
72: * that generate data used by this command.
73: *
74: * @param prog ExpressionProgram in which this ExpressionCommand occurs.
75: * @param myIndex index at which ExpressionCommand occurs in prog.
76: * @return total number of indices in prog occupied by this command and commands that generate data used by this command.
77: */
78: public int extent(ExpressionProgram prog, int myIndex);
79:
80: /**
81: * Return true if this command depends on the value of x, false otherwise.
82: * That is, when apply() is called, can the result depend on the value of x?
83: */
84: public boolean dependsOn(Variable x);
85:
86: /**
87: * The ExpressionCommand occurs in the program prog at the index indicated by myIndex.
88: * Add a print string representation of the sub-expression represented by this command
89: * (including any previous commands in the program that generate data used by this
90: * command).
91: */
92: public void appendOutputString(ExpressionProgram prog, int myIndex,
93: StringBuffer buffer);
94:
95: }
|