Package com.singularsys.extensions.rewrite
package com.singularsys.extensions.rewrite
Allow expression rewriting to be created and applied. Rules must implement
RewriteRuleI providing methods
boolean test(ASTFunNode node,Node children[])
and Node apply(ASTFunNode node,Node children[]).
The set of rewriting rules can be applied using the
RewriteVisitor.
For example
Jep jep = new Jep();
jep.setComponent(new DeepCopyVisitor());
jep.setComponent(new TreeUtils());
jep.setComponent(new SimplificationVisitor());
RewriteVisitor ev = new RewriteVisitor();
jep.setComponent(ev);
RewriteRuleI expand = new ExpandBrackets();
ev.add(expand); // Add the rule
jep.reinitializeComponents(); // reinitialize Jep
Node node = jep.parse("(a+b)*(c+d)");
Node expanded = ev.rewrite(node,false); // perform the rewriting
jep.println(expanded);
- Since:
- Jep 3.5 / Extensions 2.0
- See Also:
-
ClassDescriptionBasic implementation for a RewriteRule.Consolidate nested
NaryBinaryFunctionfunctions to a single function with multiple arguments.Collect powers together so thatx*x -> x^2andx^n*x -> x^(n+1).A rule which expands brackets (a+b)*(c+d) -> a*c+a*d+b*c+b*dExpands powers (a+b)^2 -> a^2+2*a*b+b^2ConvertsNaryBinaryFunctionfunctions with multiple arguments to nested binary functions.Therewrite(x)command.Defines a rule for symbolic rewriting of an expressionA visitor which allows rewrite rules to be added and applied.Define a rule which may modify a constant node.Define a rule which may modify a variable node.A rule where numbers very close to zero are replaces by zero.Replaces a variable "x" by "x + d" where d is a double value.