|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.webcompmath.functions.FunctionParserExtension
net.sourceforge.webcompmath.functions.ExpressionFunction
public class 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.
| Field Summary | |
|---|---|
protected Expression |
definition
|
protected Variable[] |
params
Variable(s) that act as the parameters. |
| Fields inherited from class net.sourceforge.webcompmath.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 net.sourceforge.webcompmath.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 |
| Field Detail |
|---|
protected Expression definition
protected Variable[] params
| 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)
name - name of the functionparams - variables to usedefinition - definition of the function| Method Detail |
|---|
public void redefine(java.lang.String def)
def - definition of the function
public void redefine(java.lang.String def,
Parser parser)
def - definition of the functionparser - parser to usepublic java.lang.String getDefinitionString()
public java.lang.String toString()
toString in class java.lang.Objectpublic int getArity()
public double getVal(double[] arguments)
arguments - array of args. to use in evaluation
public double getValueWithCases(double[] arguments,
Cases cases)
arguments - array of args. to use in evaluationcases - cases to use
public Function derivative(int wrt)
wrt - index of the arg. with respect to
public Function derivative(Variable x)
x - variable with respect to
public boolean dependsOn(Variable x)
x - variable to check
public void apply(StackOfDouble stack,
Cases cases)
apply in interface ExpressionCommandapply in class FunctionParserExtensionstack - stack to usecases - cases to use
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||