mathhook_core/functions/elementary/
exponential.rs

1//! Exponential function intelligence
2//!
3//! Complete mathematical intelligence for exponential functions
4//! with derivatives, special values, and mathematical properties.
5
6use crate::core::{Expression, Symbol};
7use crate::functions::properties::*;
8use std::collections::HashMap;
9use std::sync::Arc;
10/// Exponential Function Intelligence
11///
12/// Dedicated intelligence system for exponential functions
13/// with complete mathematical properties.
14pub struct ExponentialIntelligence {
15    /// Function properties for exponential functions
16    properties: HashMap<String, FunctionProperties>,
17}
18
19impl Default for ExponentialIntelligence {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl ExponentialIntelligence {
26    /// Create new exponential intelligence system
27    pub fn new() -> Self {
28        let mut intelligence = Self {
29            properties: HashMap::with_capacity(4),
30        };
31
32        intelligence.initialize_exp();
33        intelligence.initialize_sqrt();
34
35        intelligence
36    }
37
38    /// Get all exponential function properties
39    pub fn get_properties(&self) -> HashMap<String, FunctionProperties> {
40        self.properties.clone()
41    }
42
43    /// Check if function is exponential
44    pub fn has_function(&self, name: &str) -> bool {
45        self.properties.contains_key(name)
46    }
47
48    /// Initialize exponential function
49    fn initialize_exp(&mut self) {
50        self.properties.insert(
51            "exp".to_owned(),
52            FunctionProperties::Elementary(Box::new(ElementaryProperties {
53                derivative_rule: Some(DerivativeRule {
54                    rule_type: DerivativeRuleType::SimpleFunctionSubstitution("exp".to_owned()),
55                    result_template: "exp(x)".to_owned(),
56                }),
57                antiderivative_rule: Some(AntiderivativeRule {
58                    rule_type: AntiderivativeRuleType::Simple {
59                        antiderivative_fn: "exp".to_owned(),
60                        coefficient: Expression::integer(1),
61                    },
62                    result_template: "∫exp(x)dx = exp(x) + C".to_owned(),
63                    constant_handling: ConstantOfIntegration::AddConstant,
64                }),
65                special_values: vec![
66                    SpecialValue {
67                        input: "0".to_owned(),
68                        output: Expression::integer(1),
69                        latex_explanation: "e^0 = 1".to_owned(),
70                    },
71                    SpecialValue {
72                        input: "1".to_owned(),
73                        output: Expression::e(),
74                        latex_explanation: "e^1 = e".to_owned(),
75                    },
76                ],
77                identities: Box::new(vec![MathIdentity {
78                    name: "Exponential Law".to_owned(),
79                    lhs: Expression::function(
80                        "exp",
81                        vec![Expression::add(vec![
82                            Expression::symbol("x"),
83                            Expression::symbol("y"),
84                        ])],
85                    ),
86                    rhs: Expression::mul(vec![
87                        Expression::function("exp", vec![Expression::symbol("x")]),
88                        Expression::function("exp", vec![Expression::symbol("y")]),
89                    ]),
90                    conditions: vec!["x, y ∈ ℝ".to_owned()],
91                }]),
92                domain_range: Box::new(DomainRangeData {
93                    domain: Domain::Real,
94                    range: Range::Unbounded,
95                    singularities: vec![],
96                }),
97                periodicity: None,
98                wolfram_name: Some("Exp"),
99            })),
100        );
101    }
102
103    /// Initialize sqrt function
104    fn initialize_sqrt(&mut self) {
105        self.properties.insert(
106            "sqrt".to_owned(),
107            FunctionProperties::Elementary(Box::new(ElementaryProperties {
108                derivative_rule: Some(DerivativeRule {
109                    rule_type: DerivativeRuleType::Custom {
110                        builder: Arc::new(|arg: &Expression| {
111                            Expression::mul(vec![
112                                Expression::rational(1, 2),
113                                Expression::pow(arg.clone(), Expression::rational(-1, 2)),
114                            ])
115                        }),
116                    },
117                    result_template: "1/(2√x)".to_owned(),
118                }),
119                antiderivative_rule: Some(AntiderivativeRule {
120                    rule_type: AntiderivativeRuleType::Custom {
121                        builder: Arc::new(|var: Symbol| {
122                            Expression::mul(vec![
123                                Expression::rational(2, 3),
124                                Expression::pow(
125                                    Expression::symbol(var),
126                                    Expression::rational(3, 2),
127                                ),
128                            ])
129                        }),
130                    },
131                    result_template: "∫√x dx = (2/3)x^(3/2) + C".to_owned(),
132                    constant_handling: ConstantOfIntegration::AddConstant,
133                }),
134                special_values: vec![
135                    SpecialValue {
136                        input: "0".to_owned(),
137                        output: Expression::integer(0),
138                        latex_explanation: "\\sqrt{0} = 0".to_owned(),
139                    },
140                    SpecialValue {
141                        input: "1".to_owned(),
142                        output: Expression::integer(1),
143                        latex_explanation: "\\sqrt{1} = 1".to_owned(),
144                    },
145                ],
146                identities: Box::new(vec![MathIdentity {
147                    name: "Power Rule".to_owned(),
148                    lhs: Expression::function("sqrt", vec![Expression::symbol("x")]),
149                    rhs: Expression::pow(
150                        Expression::symbol("x"),
151                        Expression::mul(vec![
152                            Expression::integer(1),
153                            Expression::pow(Expression::integer(2), Expression::integer(-1)),
154                        ]),
155                    ),
156                    conditions: vec!["x ≥ 0".to_owned()],
157                }]),
158                domain_range: Box::new(DomainRangeData {
159                    domain: Domain::Real,
160                    range: Range::Unbounded,
161                    singularities: vec![],
162                }),
163                periodicity: None,
164                wolfram_name: Some("Sqrt"),
165            })),
166        );
167    }
168}