Simplify an expression
To simplify an expression you have to call the method
on an ExpressionConfiguration object. For Example:
ExpressionConfiguration config=new ExpressionConfiguration(RealType.TYPE);
config.setExpression("0+9");
config.setExpression(config.simplify());
After this, the Expression of config will be "9".
The following table shows source operations and it's simplifications. a and b are
arbitrary expressions. Note that often there is no simplification (e.g. 1 + a).
| source operation # | + | - | * | / | ^ |
| #a | a | -a |
| #(#a) | a | a |
| 0 # a | a | -a | 0 | 0 | 0 |
| a # 0 | a | a | 0 | a / 0 | 1 |
| 1 # a | 1 + a | 1 - a | a | 1 / a | 1 |
| a # 1 | a + 1 | a - 1 | a | a | a |
| a # a | a + a | 0 | a * a | 1 | a ^ a |
| a # b | a + b | a - b | a * b | a / b | a ^ b |
| -a # b | b - a | -(a + b) | -(a * b) | -(a / b) | -a ^ b |
| a # -b | a - b | a + b | -(a * b) | -(a / b) | a ^ -b |
| -a # -b | -(a + b) | b - a | a * b | a / b | -(a ^ -b) |
Note: An Expressions wont be simplified in the following cases:
- constant expressions, e.g.: "9+1" wont be simplified to "10"
- cancel down divisions, e.g.: "a^2/a" wont be simplified to "a"
- commutative law wont be detected, e.g.: "(a+b)/(b+a)" wont be simplified to "1"
Differentiate an expression
To get the derivative of an Expression with respect to any Symbol you have to call one of the
following methods on an ExpressionConfiguration object:
- differentiate(String s)
- differentiate(Symbol s)
The easiest way is to give the respection by a String.
Example:
ExpressionConfiguration config=new ExpressionConfiguration(RealType.TYPE);
config.setExpression("a^2");
config.setExpression(config.differentiate("a"));
After this, the Expression of config will be "a^2 * (2/a)".
It's not simplified to "2*a" because cancel down simplification is not implemented yet.