mathhook_core/calculus/
derivatives.rs1mod advanced_differentiation;
7mod basic;
8mod chain_rule;
9mod checker;
10pub mod educational;
11mod higher_order;
12mod partial;
13mod power_rule;
14mod product_rule;
15use crate::core::{Expression, Symbol};
16pub use advanced_differentiation::{
17 AdvancedDifferentiation, ImplicitCurveAnalysis, ImplicitDifferentiation,
18 ParametricCurveAnalysis, ParametricDifferentiation, VectorValuedDifferentiation,
19};
20pub use basic::BasicDerivatives;
21pub use chain_rule::{ChainRule, FunctionDerivatives};
22pub use checker::DifferentiabilityChecker;
23pub use educational::DerivativeWithSteps;
24pub use higher_order::HigherOrderDerivatives;
25pub use partial::{
26 ConservativeFields, DirectionalDerivatives, FluidDynamicsOperations, GradientOperations,
27 HessianOperations, JacobianDeterminant, JacobianOperations, MatrixUtils, PartialDerivatives,
28 PartialUtils, VectorFieldOperations,
29};
30pub use power_rule::PowerRule;
31pub use product_rule::{GeneralProductRule, ProductRule};
32pub trait Derivative {
34 fn derivative(&self, variable: Symbol) -> Expression;
47 fn nth_derivative(&self, variable: Symbol, order: u32) -> Expression;
60 fn is_differentiable(&self, variable: Symbol) -> bool;
73}
74impl Derivative for Expression {
75 fn derivative(&self, variable: Symbol) -> Expression {
76 match self {
77 Expression::Calculus(data) => BasicDerivatives::handle_calculus(self, data, variable),
78 Expression::Number(_) | Expression::Constant(_) => Expression::integer(0),
79 Expression::Symbol(sym) => BasicDerivatives::handle_symbol(sym, &variable),
80 Expression::Add(terms) => BasicDerivatives::handle_sum(terms, &variable),
81 Expression::Mul(factors) => ProductRule::handle_product(factors, variable),
82 Expression::Pow(base, exponent) => PowerRule::apply(base, exponent, variable),
83 Expression::Function { name, args } => ChainRule::handle_function(name, args, variable),
84 _ => Expression::derivative(self.clone(), variable, 1),
85 }
86 }
87 fn nth_derivative(&self, variable: Symbol, order: u32) -> Expression {
88 HigherOrderDerivatives::compute(self, variable, order)
89 }
90 fn is_differentiable(&self, variable: Symbol) -> bool {
91 DifferentiabilityChecker::check(self, variable)
92 }
93}