simplify method
Simplifies the expression, if possible, and returns a new simplified expression.
Implementation
@override
Expression simplify() {
final simplifiedOperand = operand.simplify();
// If the operand is a literal, evaluate and return a new Literal.
if (simplifiedOperand is Literal) {
final value = simplifiedOperand.value;
if (value == 0) {
return Literal(1); // e^0 = 1
}
if (value == 1) {
return Literal(math.e); // e^1 = e
}
return Literal(math.exp(value));
}
// If the operand is ln(x), then e^ln(x) = x
if (simplifiedOperand is Ln) {
return simplifiedOperand.operand;
}
// If operand changed during simplification, return new Exp
if (simplifiedOperand != operand) {
return Exp(simplifiedOperand);
}
return this;
}