|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.lsmp.djep.xjep.DoNothingVisitor org.lsmp.djep.xjep.SimplificationVisitor
public class SimplificationVisitor
Simplifies an expression. To use
JEP j = ...; Node in = ...; SimplificationVisitor sv = new SimplificationVisitor(tu); Node out = sv.simplify(in);
Its intended to completly rewrite this class to that simplification rules can be specified by strings in a way similar to DiffRulesI. It also would be nice to change the rules depending on the type of arguments, for example matrix multiplication is not commutative. But some of the in built rules exploit commutativity.
Constructor Summary | |
---|---|
SimplificationVisitor()
|
Method Summary | |
---|---|
Node |
simplify(Node node,
XJep xjep)
must be implemented for subclasses. |
Node |
simplifyAdd(Node lhs,
Node rhs)
Simplifies an addition. |
Node |
simplifyBuiltOperatorNode(Operator op,
Node lhs,
Node rhs)
First create a new node and then simplify it. |
Node |
simplifyDivide(Node child1,
Node child2)
Simplifies a division. |
Node |
simplifyMultiply(Node child1,
Node child2)
Simplifies a multiplication. |
Node |
simplifyOp(ASTFunNode node,
Node[] children)
simplifies operators, does not descend into children |
Node |
simplifyPower(Node child1,
Node child2)
Simplify a power. |
Node |
simplifySubtract(Node lhs,
Node rhs)
Simplifies a subtraction. |
Node |
simplifyTripple(XOperator op,
Node lhs,
Node rhs)
Simplifies expressions like 2+(3+x) or (2+x)+3 |
java.lang.Object |
visit(ASTFunNode node,
java.lang.Object data)
|
Methods inherited from class org.lsmp.djep.xjep.DoNothingVisitor |
---|
acceptChildrenAsArray, visit, visit, visit, visit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimplificationVisitor()
Method Detail |
---|
public Node simplify(Node node, XJep xjep) throws ParseException, java.lang.IllegalArgumentException
ParseException
java.lang.IllegalArgumentException
public Node simplifyBuiltOperatorNode(Operator op, Node lhs, Node rhs) throws ParseException
ParseException
public Node simplifyTripple(XOperator op, Node lhs, Node rhs) throws ParseException
op
- the root operatorlhs
- the left hand side noderhs
- the right hand side node
ParseException
public Node simplifyAdd(Node lhs, Node rhs) throws ParseException
0+x -> x x+0 -> x m+n -> (m+n) where m,n are numbers x - (-2) -> x + 2 for any negative number -2 x + (-2) -> x - 2 for any negative number -2 2 +/- ( 3 +/- x ) -> (2 +/- 3 ) +/- x and similar
ParseException
public Node simplifySubtract(Node lhs, Node rhs) throws ParseException
0-x -> 0-x x-0 -> x m-n -> (m-n) where m,n are numbers x - (-2) -> x + 2 for any negative number -2 x + (-2) -> x - 2 for any negative number -2 2 +/- ( 3 +/- x ) -> (2 +/- 3 ) +/- x and similar
lhs
- the left hand siderhs
- the right hand side
ParseException
public Node simplifyMultiply(Node child1, Node child2) throws ParseException
0 * Inf -> NaN 0 * x -> 0 x * 0 -> 0 1 * x -> x x * 1 -> x Inf * x -> Inf x * Inf -> Inf 2 * ( 3 * x) -> (2*3) * x and similar.
ParseException
public Node simplifyDivide(Node child1, Node child2) throws ParseException
0/0 -> NaN 0/Inf -> Inf 0/x -> Inf x/0 -> Inf x/1 -> x Inf / x -> Inf x / Inf -> 0 2 / ( 3 * x) -> (2/3) / x 2 / ( x * 3) -> (2/3) / x 2 / ( 3 / x) -> (2/3) * x 2 / ( x / 3) -> (2*3) / x (2 * x) / 3 -> (2/3) * x (x * 2) / 3 -> x * (2/3) (2 / x) / 3 -> (2/3) / x (x / 2) / 3 -> x / (2*3)
ParseException
public Node simplifyPower(Node child1, Node child2) throws ParseException
x^0 -> 1 x^1 -> x 0^0 -> NaN 0^x -> 0 1^x -> 1
ParseException
public Node simplifyOp(ASTFunNode node, Node[] children) throws ParseException
ParseException
public java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
visit
in class DoNothingVisitor
ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |