public class DefaultFunctionInterpreter extends java.lang.Object implements FunctionInterpreter
Default implementation of FunctionInterpreter. This implementation produces PostfixFunctions.
TODO: faster Functions could be produced by compiling expressions into Java classes.Constructor and Description |
---|
DefaultFunctionInterpreter()
Initializes data structures
TODO: Make this a static list or something, why are we doing this for each function
|
Modifier and Type | Method and Description |
---|---|
java.util.List<java.io.Serializable> |
getPostfixList(java.lang.String expression) |
java.util.Map<java.lang.String,Function> |
getRegisteredFunctions()
Returns a map of registered functions.
|
Function |
parse(java.lang.String expression,
int dimension)
Parses a mathematical expression into a Function instance.
|
void |
registerFunction(java.lang.String name,
Function function)
Registers a non-standard function for use in future interpretation of
function expressions.
|
void |
removeRegisteredFunction(java.lang.String name)
Removes a registered function.
|
static DefaultFunctionInterpreter |
sharedInstance() |
public DefaultFunctionInterpreter()
public static DefaultFunctionInterpreter sharedInstance()
public void registerFunction(java.lang.String name, Function function)
FunctionInterpreter
registerFunction
in interface FunctionInterpreter
name
- Short name of function as it is to appear in parsed expressionsfunction
- Function instanceFunctionInterpreter.registerFunction(java.lang.String, ca.nengo.math.Function)
public Function parse(java.lang.String expression, int dimension)
FunctionInterpreter
Parses a mathematical expression into a Function instance. The function can include the unary operators - and !, the binary operators +-/^*&|, the standard functions sin() cos() tan() asin(), acos(), atan(), exp(), and ln(), and user-defined unary functions functions that have been registered with the registerFunction(...) method. The constant "pi" and literal constants are also allowed. The logical operators produce 1f or 0f, on the basis of whether their operands are > 1/2. Functions must be given in infix notation and can include brackets.
Function operands have the form x0, x1, etc., which serve as placeholders for values that are given at each dimension of the map() method of the resulting function.
An example of a valid expression would be "x0 * (x1 + x2)^x3 * ln(x4/3)"
parse
in interface FunctionInterpreter
expression
- Mathematical expressiondimension
- Input dimension of the desired Function (must be at least as great
as any referenced inputs, eg if x3 appears in the expression, the dimension
must be at least 4)FunctionInterpreter.parse(java.lang.String, int)
public java.util.List<java.io.Serializable> getPostfixList(java.lang.String expression)
expression
- Mathematical expression, as in parse(...)public java.util.Map<java.lang.String,Function> getRegisteredFunctions()
FunctionInterpreter
getRegisteredFunctions
in interface FunctionInterpreter
public void removeRegisteredFunction(java.lang.String name)
FunctionInterpreter
removeRegisteredFunction
in interface FunctionInterpreter
name
- Name of function to be removed