| java.lang.Object edu.hws.jcm.functions.FunctionParserExtension edu.hws.jcm.functions.ExpressionFunction
ExpressionFunction | public class ExpressionFunction extends FunctionParserExtension (Code) | | 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.
|
Constructor Summary | |
public | ExpressionFunction(String name, String def) Constuct a function of one parameter, named "x", by parsing the String, def,
to get the definition of the function. | public | ExpressionFunction(String name, String[] paramNames, String def, Parser parser) Constuct a function of one or more parameters by parsing the String, def,
to get the definition of the function. | public | ExpressionFunction(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 | |
public 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. | public boolean | dependsOn(Variable x) Return true if the definition of this function depends
in some way on the variable x. | public Function | derivative(int wrt) Return the derivative of the function with repect to
argument number wrt, where the arguments are numbered 1, 2, 3,....
For a function of one variable, call derivative(1) to find its derivative.
If arity > 1, this is effectively a partial derivative. | public Function | derivative(Variable x) Return the derivative of the function with respect to the
variable x. | public int | getArity() Return the number of arguments of this function. | public String | getDefinitionString() Return the expression that defines this function, as a string. | public double | getVal(double[] arguments) Find the value of the function at the argument values
given by arguments[0], arguments[1], ... | public double | getValueWithCases(double[] arguments, Cases cases) Find the value of the function at the argument values
given by arguments[0], arguments[1], ... | public void | redefine(String def) Set the definition of this function by parsing the given string,
using a default parser. | public void | redefine(String def, Parser parser) Set the definition of this function, using the specified parser (or a default
parser if parser is null). | public String | toString() Return a string that describes this function, such as "function f(x,y) given by x^2 - y^2". |
ExpressionFunction | public ExpressionFunction(String name, String def)(Code) | | Constuct a function of one parameter, named "x", by parsing the String, def,
to get the definition of the function. A standard Parser, with
default options and knowledge only of "pi", "e" and the standard functions
is used. The variable "x" is also added to this parser while the function is being parsed.
Parameters: name - Name of function. This should not be null if the function is to be used in a Parser. Parameters: def - contains definition of the function, as a function of "x". |
ExpressionFunction | public ExpressionFunction(String name, String[] paramNames, String def, Parser parser)(Code) | | Constuct a function of one or more parameters by parsing the String, def,
to get the definition of the function. The given parser is used to
parse the definition, so the definition can refer to objects registered
with the parser (such as other variables or functions). Furthermore, if
both name and parser are non-null, then the function is registered with
the parser so that it can then be used in expressions parsed by the
parser. (It's possible to have a function of zero arguements. In that case, the
function serves as a "named expression".)
Parameters: name - Name of function. Parameters: paramNames - Names of the parameters of the function. The lenght of this array determines the arity of the function. Parameters: def - The definition of the function, in terms of the parameters from the paramNames array. Parameters: 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. |
ExpressionFunction | public ExpressionFunction(String name, Variable[] params, Expression definition)(Code) | | Construct a function from a list of variables that serve as parameters and an expression that,
presumably, can include those variables. WARNING: When the function is
evaluated, the values of the parameter variables can change, so you should
probably not use variables that are being used elsewhere in your program.
|
apply | public void apply(StackOfDouble stack, Cases cases)(Code) | | Find the value of the function applied to arguments popped
from the stack, and push the result back onto the stack.
(Overrides general method inherited from FunctionParserExtension.
This is done for efficiency and because the general method
can't deal properly with "cases".) Not meant to be called directly
|
dependsOn | public boolean dependsOn(Variable x)(Code) | | Return true if the definition of this function depends
in some way on the variable x. (Note that a function does
NOT depend on its parameter variables!)
|
derivative | public Function derivative(int wrt)(Code) | | Return the derivative of the function with repect to
argument number wrt, where the arguments are numbered 1, 2, 3,....
For a function of one variable, call derivative(1) to find its derivative.
If arity > 1, this is effectively a partial derivative. If wrt is
not in the legal range, an IllegalArgumentException is thrown.
|
derivative | public Function derivative(Variable x)(Code) | | Return the derivative of the function with respect to the
variable x. This will be non-zero if x occurs somehow in
the definition of x: For example, f(y) = sin(x*y);
|
getArity | public int getArity()(Code) | | Return the number of arguments of this function.
|
getDefinitionString | public String getDefinitionString()(Code) | | Return the expression that defines this function, as a string.
|
getVal | public double getVal(double[] arguments)(Code) | | Find the value of the function at the argument values
given by arguments[0], arguments[1], ... The length
of the array argument should be equal to the arity of
the function. If not, an IllegalArgumentException is
thrown.
|
getValueWithCases | public double getValueWithCases(double[] arguments, Cases cases)(Code) | | Find the value of the function at the argument values
given by arguments[0], arguments[1], ... The length
of the array argument should be equal to the arity of
the function. If not, an IllegalArgumentException is
thrown. Store information about "cases" that occur in
the evaluation in the second parameter, if that parameter is non-null.
|
redefine | public void redefine(String def)(Code) | | Set the definition of this function by parsing the given string,
using a default parser. The definition is in terms of the parameter
names originally provided in the constructor.
|
redefine | public void redefine(String def, Parser parser)(Code) | | Set the definition of this function, using the specified parser (or a default
parser if parser is null). The definition is in terms of the parameter
names originally provided in the constructor. (This routine does
not register the function with the parser, but if it was already
registered with the parser, it stays registered with the new
definition.) Note that changing the definition of the function
effectively changes the definition of any other expression that
refers to this function.
|
toString | public String toString()(Code) | | Return a string that describes this function, such as "function f(x,y) given by x^2 - y^2".
|
|
|