simplify method

  1. @override
Expression simplify()
override

Possible simplifications:

  1. a - 0 = a
  2. 0 - a = - a
  3. 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)
}