An expression-based calculator capable of dealing with derivatives and simplifying the results with a varying degree of success.
Input:
Simplification:
Derivative:
Solution at x = 2
Some of these features are left out because they're tedious to encode since they involve deep pattern matching on commutative operations.
Some other identities are tricky since they don't necessarily always make things simpler. For example:
- Sum Rule
- Difference Rule
- Product Rule
- Chain Rule
- Power Rule
- Quotient Rule
- Logarithms
-
e
- Regular trig rules (sin, cos, tan)
- Confusing trig rules (cot, sin^-1, cos^-1, tan^-1)
- The ones that made me fail calc1 class (sinh, cosh, tanh)
- Square roots
- Constant operations for addition, subtraction, division, multiplication
- Identity operations, eg:
n * 1 = n
orn + 0 = n
- Exponent Rules, eg:
a^m + a^n = a^(m + n)
- Variable substitution
- Combining same terms at arbitrary levels
2x^2 + 5x^2
- Distributing terms
- A bunch of other things
let operation = div(
sub(
mult(
pow(
x.clone(),
constant(3.0),
),
pow(x.clone(), constant(3.0)),
),
add(mult(constant(2.0), x.clone()), x.clone())
),
pow(
x.clone(),
constant(2.0),
),
);
let derivative = Derivative::of(&operation.simplify())
// (((x^2 * (6x^5 - 3)) - ((x^6 - 3x) * 2x))/x^4)
let terms = HashMap::from(
[(&x, Math::Constant(2.0))]
);
let solution = derivative.solve(&terms);
// Math::Constant(32.75)
input = "(((x^3 * x^3) - (2x + x))/x^2)"
input (simplified) = "((x^6 - 3x)/x^2)"
derivative (simplified) = "(((x^2 * (6x^5 - 3)) - ((x^6 - 3x) * 2x))/x^4)"
derivative solution (simplified) {x = 2} = "32.75"