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