* Attempt to rewrite the specified node.
* @param parent The parent node to start from.
* @return The rewritten node, or the same node if no rewrite occurs.
*/
private ProgramNode internalRewrite(final ProgramNode parent) {
ProgramNode rewrittenParent = parent;
rewrittenParent = tryDoubleNegative(rewrittenParent);
rewrittenParent = tryMinusMinus(rewrittenParent);
rewrittenParent = tryPlusNeg(rewrittenParent);
rewrittenParent = tryVarOpVar(rewrittenParent);
rewrittenParent = tryPowerZero(rewrittenParent);
rewrittenParent = tryOnePower(rewrittenParent);
rewrittenParent = tryZeroPlus(rewrittenParent);
rewrittenParent = tryZeroDiv(rewrittenParent);
rewrittenParent = tryZeroMul(rewrittenParent);
rewrittenParent = tryMinusZero(rewrittenParent);
// try children
for (int i = 0; i < rewrittenParent.getChildNodes().size(); i++) {
final ProgramNode childNode = (ProgramNode) rewrittenParent
.getChildNodes().get(i);
final ProgramNode rewriteChild = internalRewrite(childNode);
if (childNode != rewriteChild) {
rewrittenParent.getChildNodes().remove(i);
rewrittenParent.getChildNodes().add(i, rewriteChild);
this.rewritten = true;
}