simplify method

  1. @override
Expression simplify()
override

Possible simplifications:

  1. 0^x = 0
  2. 1^x = 1
  3. x^0 = 1
  4. x^1 = x

Implementation

@override
Expression simplify() {
  final Expression baseOp = first.simplify();
  final Expression exponentOp = second.simplify();

  //TODO unboxing
  /*
  bool baseNegative = false, expNegative = false;

  // unbox unary minuses
  if (baseOp is UnaryMinus) {
    baseOp = baseOp.exp;
    baseNegative = !baseNegative;
  }
  if (exponentOp is UnaryMinus) {
    exponentOp = exponentOp.exp;
    expNegative = !expNegative;
  }
  */

  if (_isNumber(baseOp, 0)) {
    return baseOp; // 0^x = 0
  }

  if (_isNumber(baseOp, 1)) {
    return baseOp; // 1^x = 1
  }

  if (_isNumber(exponentOp, 0)) {
    return Number(1.0); // x^0 = 1
  }

  if (_isNumber(exponentOp, 1)) {
    return baseOp; // x^1 = x
  }

  return Power(baseOp, exponentOp);
}