mathhook_core/calculus/derivatives/
advanced_differentiation.rs

1//! Advanced differentiation techniques
2//!
3//! Provides specialized differentiation methods for implicit functions,
4//! parametric curves, and vector-valued functions with optimized performance
5//! and memory usage.
6
7mod implicit;
8mod parametric;
9mod vector_valued;
10
11use crate::core::{Expression, Symbol};
12
13pub use implicit::{ImplicitCurveAnalysis, ImplicitDifferentiation};
14pub use parametric::{ParametricCurveAnalysis, ParametricDifferentiation};
15pub use vector_valued::VectorValuedDifferentiation;
16
17/// Advanced differentiation methods with performance optimization
18pub struct AdvancedDifferentiation;
19
20impl AdvancedDifferentiation {
21    /// Compute implicit derivative dy/dx for F(x,y) = 0
22    ///
23    /// Uses the formula: dy/dx = -∂F/∂x / ∂F/∂y
24    ///
25    /// # Examples
26    ///
27    /// ```rust
28    /// use mathhook_core::Expression;
29    /// use mathhook_core::symbol;
30    /// use mathhook_core::calculus::derivatives::AdvancedDifferentiation;
31    ///
32    /// let x = symbol!(x);
33    /// let y = symbol!(y);
34    /// let equation = Expression::add(vec![
35    ///     Expression::pow(Expression::symbol(x.clone()), Expression::integer(2)),
36    ///     Expression::pow(Expression::symbol(y.clone()), Expression::integer(2))
37    /// ]);
38    /// let dy_dx = AdvancedDifferentiation::implicit(&equation, x, y);
39    /// ```
40    pub fn implicit(equation: &Expression, x_var: Symbol, y_var: Symbol) -> Expression {
41        ImplicitDifferentiation::compute(equation, x_var, y_var)
42    }
43
44    /// Compute parametric derivative dy/dx for x = f(t), y = g(t)
45    ///
46    /// Uses formula: dy/dx = (dy/dt) / (dx/dt)
47    ///
48    /// # Examples
49    ///
50    /// ```rust
51    /// use mathhook_core::Expression;
52    /// use mathhook_core::symbol;
53    /// use mathhook_core::calculus::derivatives::AdvancedDifferentiation;
54    ///
55    /// let t = symbol!(t);
56    /// let x_param = Expression::function("cos", vec![Expression::symbol(t.clone())]);
57    /// let y_param = Expression::function("sin", vec![Expression::symbol(t.clone())]);
58    /// let dy_dx = AdvancedDifferentiation::parametric(&x_param, &y_param, t);
59    /// ```
60    pub fn parametric(x_param: &Expression, y_param: &Expression, parameter: Symbol) -> Expression {
61        ParametricDifferentiation::first_derivative(x_param, y_param, parameter)
62    }
63
64    /// Compute derivative of vector-valued function r'(t)
65    ///
66    /// Returns velocity vector for position vector r(t) = [x(t), y(t), z(t)]
67    ///
68    /// # Examples
69    ///
70    /// ```rust
71    /// use mathhook_core::Expression;
72    /// use mathhook_core::symbol;
73    /// use mathhook_core::calculus::derivatives::AdvancedDifferentiation;
74    ///
75    /// let t = symbol!(t);
76    /// let components = vec![
77    ///     Expression::function("cos", vec![Expression::symbol(t.clone())]),
78    ///     Expression::function("sin", vec![Expression::symbol(t.clone())]),
79    ///     Expression::symbol(t.clone())
80    /// ];
81    /// let velocity = AdvancedDifferentiation::vector_valued(&components, t);
82    /// ```
83    pub fn vector_valued(components: &[Expression], parameter: Symbol) -> Vec<Expression> {
84        VectorValuedDifferentiation::derivative(components, parameter)
85    }
86
87    /// Compute curvature for parametric curves
88    ///
89    /// Uses formula: κ = |x'y'' - y'x''| / (x'² + y'²)^(3/2)
90    ///
91    /// # Examples
92    ///
93    /// ```rust
94    /// use mathhook_core::Expression;
95    /// use mathhook_core::symbol;
96    /// use mathhook_core::calculus::derivatives::AdvancedDifferentiation;
97    ///
98    /// let t = symbol!(t);
99    /// let x_param = Expression::function("cos", vec![Expression::symbol(t.clone())]);
100    /// let y_param = Expression::function("sin", vec![Expression::symbol(t.clone())]);
101    /// let curvature = AdvancedDifferentiation::parametric_curvature(&x_param, &y_param, t);
102    /// ```
103    pub fn parametric_curvature(
104        x_param: &Expression,
105        y_param: &Expression,
106        parameter: Symbol,
107    ) -> Expression {
108        ParametricDifferentiation::curvature(x_param, y_param, parameter)
109    }
110
111    /// Compute curvature for vector-valued functions (space curves)
112    ///
113    /// Uses formula: κ = |r' × r''| / |r'|³
114    ///
115    /// # Examples
116    ///
117    /// ```rust
118    /// use mathhook_core::Expression;
119    /// use mathhook_core::symbol;
120    /// use mathhook_core::calculus::derivatives::AdvancedDifferentiation;
121    ///
122    /// let t = symbol!(t);
123    /// let components = vec![
124    ///     Expression::symbol(t.clone()),
125    ///     Expression::pow(Expression::symbol(t.clone()), Expression::integer(2)),
126    ///     Expression::pow(Expression::symbol(t.clone()), Expression::integer(3))
127    /// ];
128    /// let curvature = AdvancedDifferentiation::vector_curvature(&components, t);
129    /// ```
130    pub fn vector_curvature(components: &[Expression], parameter: Symbol) -> Expression {
131        VectorValuedDifferentiation::curvature(components, parameter)
132    }
133}