|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.hws.jcm.functions.FunctionParserExtension | +--edu.hws.jcm.functions.ExpressionFunction
An ExpressionFunction is a Function that is created from an expression and a list of variables that serve as the parameter(s) of the function. (This is essentially a lambda operation, forming a function such as "lambda(x,y) (x^2+y^2)") Since an ExpressionFunction is a FunctionParserExtension, functions defined from this class can be added to a Parser and then used in expressions parsed by that parser.
Fields inherited from class edu.hws.jcm.functions.FunctionParserExtension |
name |
Constructor Summary | |
ExpressionFunction(java.lang.String name,
java.lang.String def)
Constuct a function of one parameter, named "x", by parsing the String, def, to get the definition of the function. |
|
ExpressionFunction(java.lang.String name,
java.lang.String[] paramNames,
java.lang.String def,
Parser parser)
Constuct a function of one or more parameters by parsing the String, def, to get the definition of the function. |
|
ExpressionFunction(java.lang.String name,
Variable[] params,
Expression definition)
Construct a function from a list of variables that serve as parameters and an expression that, presumably, can include those variables. |
Method Summary | |
void |
apply(StackOfDouble stack,
Cases cases)
Find the value of the function applied to arguments popped from the stack, and push the result back onto the stack. |
boolean |
dependsOn(Variable x)
Return true if the definition of this function depends in some way on the variable x. |
Function |
derivative(int wrt)
Return the derivative of the function with repect to argument number wrt, where the arguments are numbered 1, 2, 3,.... |
Function |
derivative(Variable x)
Return the derivative of the function with respect to the variable x. |
int |
getArity()
Return the number of arguments of this function. |
java.lang.String |
getDefinitionString()
Return the expression that defines this function, as a string. |
double |
getVal(double[] arguments)
Find the value of the function at the argument values given by arguments[0], arguments[1], ... |
double |
getValueWithCases(double[] arguments,
Cases cases)
Find the value of the function at the argument values given by arguments[0], arguments[1], ... |
void |
redefine(java.lang.String def)
Set the definition of this function by parsing the given string, using a default parser. |
void |
redefine(java.lang.String def,
Parser parser)
Set the definition of this function, using the specified parser (or a default parser if parser is null). |
java.lang.String |
toString()
Return a string that describes this function, such as "function f(x,y) given by x^2 - y^2". |
Methods inherited from class edu.hws.jcm.functions.FunctionParserExtension |
appendOutputString, compileDerivative, doParse, extent, getName, setName, setParensCanBeOptional |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ExpressionFunction(java.lang.String name, java.lang.String def)
name
- Name of function. This should not be null if the function is to be used in a Parser.def
- contains definition of the function, as a function of "x".public ExpressionFunction(java.lang.String name, java.lang.String[] paramNames, java.lang.String def, Parser parser)
name
- Name of function.paramNames
- Names of the parameters of the function. The lenght of this array determines the arity of the function.def
- The definition of the function, in terms of the parameters from the paramNames array.parser
- Used to parse the definition. If this is null, a standard parser is used. The
paramaters are temporarily added onto the parser while the function definition is being parsed.public ExpressionFunction(java.lang.String name, Variable[] params, Expression definition)
Method Detail |
public void redefine(java.lang.String def)
public void redefine(java.lang.String def, Parser parser)
public java.lang.String getDefinitionString()
public java.lang.String toString()
toString
in class java.lang.Object
public int getArity()
public double getVal(double[] arguments)
public double getValueWithCases(double[] arguments, Cases cases)
public Function derivative(int wrt)
public Function derivative(Variable x)
public boolean dependsOn(Variable x)
public void apply(StackOfDouble stack, Cases cases)
apply
in class FunctionParserExtension
edu.hws.jcm.data.ExpressionCommand
stack
- contains results of previous commands in the program.cases
- if non-null, any case information generated during evaluation should be recorded here.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |