org.jscience.mathematics.analysis.expressions
Interface Expression

All Superinterfaces:
JavaExpressible, java.io.Serializable, XMLExpressible
All Known Implementing Classes:
Abs, Acos, Addition, Asin, Atan, Atan2, Auxiliary, BinaryOperator, Clip, Constant, Cos, DataExpression, Diff, Division, Exp, Gauss, IFTE, Log, Max, Min, Minus, Mod, Multiplication, NamedDataExpression, OperatorExpression, Parameter, Pow, QuartaryOperator, Rand, Sign, Sin, Sqrt, Step, Subtraction, Tan, TernaryOperator, UnaryOperator, Variable

public interface Expression
extends java.io.Serializable, JavaExpressible, XMLExpressible

Interface for creating symbolic expressions, which may be evaluated. Expressions may be differentiable in which case we can obtain their derivatives in symbolic for such as in: Expression derivative = expression.diff( new Variable( "x", 0 ) ); It is possible to generate Java source code for computing an expression. In addition expressions may be expandable meaning that one can generate a Taylor expansion of the solution of an ordinary differential equation like x'=f where f is an expandable function. The latter feature can, of course, only be used if the functions used have Taylor expansions.
Example of use:

 Constant c = new Constant( 1 ); // constant with value 1
 Variable x = new Variable( "x", 3 ); // variable with name x and value 3
 Variable y = new Variable( "y", 7 ); // variable with name y and value 7
 Expression e1 = new Multiplication( x, new Addition( y, c ) ); // e1 = (x*(y+1))
 double value  = e1.eval(); // value = 24
 Expression e2 = e1.diff( x ); // e2 = ((1.0*(y+1.0))+(x*(0.0+0.0)))
 Expression e3 = e2.optimize(); // e3 = (y+1.0)
 Expression e4 = new Addition( e3, new Multiplication( x, new Sin( y ) ) ); // e4 = ((y+1.0)+(x*sin(y)))
 String javacode = e4.toJava(); // javacode = "((y+1.0)+(x*Math.sin(y)))"
 String tmapcode = e4.toTaylorMap(); // tmapcode = "new TaylorAdd(new TaylorAdd(y, new TaylorConstant( 1.0 )),new TaylorMultiply(x,new TaylorSin(y)))"
 

See Also:
Constant, Variable, Addition, Multiplication, Sin

Method Summary
 boolean contains(Expression e)
          The method contains should return true if the Expression e is found in the expression (this), else false should be returned.
 Expression diff(NamedDataExpression x)
          Returns the differential quotient for the Expression object.
 double eval()
          Returns the value of the Expression object.
 Expression factor(Expression e)
          The method should attempt to return the factor of the Expression e in the Expression this.
 java.util.List getElements()
          The getElements method must return a java.util.List whose elements are all the subexpressions of the Expression.
 boolean isDifferentiable()
          Returns whether the object in question is differentiable.
 boolean isExpandable()
          Returns whether the object in question is expandable as a Taylor expansion.
 Expression isolate(Expression e)
          The method should attempt to isolate the Expression e in the equation this=0, and return the resulting Expression.
 Expression isolate(Expression f, Expression e)
          The method should attempt to isolate the expression e in the equation this=f, and return the resulting Expression.
 Expression optimize()
          Returns a new Expression object that represents the optimized expression.
 Expression replace(Expression a, Expression b)
          Replace all occurences of the Expression a in the current expression with the Expression b.
 java.lang.String toJava()
          Returns String object representing Expression in Java source code.
 java.lang.String toTaylorMap()
          Returns String object representing TaylorMap
 java.lang.String toXML()
          Returns String XML representation
 

Method Detail

eval

double eval()
Returns the value of the Expression object.

Returns:
DOCUMENT ME!
Since:
1.0

isDifferentiable

boolean isDifferentiable()
Returns whether the object in question is differentiable. Note that whether the object is differentiable or not, it is still required to define the diff method.

See Also:
diff(NamedDataExpression)

isExpandable

boolean isExpandable()
Returns whether the object in question is expandable as a Taylor expansion. Note that whether the object is expandable or not, it is still required to define the diff method.

Returns:
DOCUMENT ME!

diff

Expression diff(NamedDataExpression x)
Returns the differential quotient for the Expression object.

Parameters:
x - The NamedDataExpression object representing the variable/parameter we wish to differentiate with respect to.
Returns:
A new Expression representing the differential quotient.
Since:
1.0

optimize

Expression optimize()
Returns a new Expression object that represents the optimized expression.

Returns:
DOCUMENT ME!

replace

Expression replace(Expression a,
                   Expression b)
Replace all occurences of the Expression a in the current expression with the Expression b.

Parameters:
a - DOCUMENT ME!
b - DOCUMENT ME!
Returns:
DOCUMENT ME!

toJava

java.lang.String toJava()
Returns String object representing Expression in Java source code.

Specified by:
toJava in interface JavaExpressible
Returns:
String object representing Expression in Java source code.
Since:
1.0

toTaylorMap

java.lang.String toTaylorMap()
Returns String object representing TaylorMap

Returns:
String object representing TaylorMap.
Since:
1.0

toXML

java.lang.String toXML()
Returns String XML representation

Specified by:
toXML in interface XMLExpressible
Returns:
String XML representation.
Since:
1.0

getElements

java.util.List getElements()
The getElements method must return a java.util.List whose elements are all the subexpressions of the Expression. For example the expression "acos(ct)" should return a java.util.List with six subexpressions: "[,a,cos,,c,t]" (the order of which is unspecified).

Returns:
DOCUMENT ME!

contains

boolean contains(Expression e)
The method contains should return true if the Expression e is found in the expression (this), else false should be returned.

Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!

isolate

Expression isolate(Expression e)
The method should attempt to isolate the Expression e in the equation this=0, and return the resulting Expression. If unable to isolate the Expression null should be returned.

Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!

isolate

Expression isolate(Expression f,
                   Expression e)
The method should attempt to isolate the expression e in the equation this=f, and return the resulting Expression. If unable to isolate the Expression null should be returned.

Parameters:
f - DOCUMENT ME!
e - DOCUMENT ME!
Returns:
DOCUMENT ME!

factor

Expression factor(Expression e)
The method should attempt to return the factor of the Expression e in the Expression this. If unable to locate a factor null should be returned.

Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!