simplify method
Possible simplifications:
- a - 0 = a
- 0 - a = - a
- a - -(b) = a + b
Implementation
@override
Expression simplify() {
final Expression firstOp = first.simplify();
final Expression secondOp = second.simplify();
if (_isNumber(secondOp, 0)) {
return firstOp;
}
if (_isNumber(firstOp, 0)) {
return -secondOp;
}
if (secondOp is UnaryMinus) {
return firstOp + secondOp.exp; // a - -(b) = a + b
}
return Minus(firstOp, secondOp);
//TODO -a + b = b - a
//TODO -a - b = - (a + b)
}