mathhook_core/functions/properties/
elementary.rs

1//! Elementary Function Properties
2//!
3//! Properties and mathematical intelligence for elementary functions including
4//! trigonometric, exponential, logarithmic, and hyperbolic functions.
5//! Performance-optimized with hot path data first for cache-friendly access patterns.
6
7use super::rules::{
8    AntiderivativeRule, DerivativeRule, DomainRangeData, MathIdentity, SpecialValue,
9};
10use crate::core::Expression;
11use std::collections::HashMap;
12
13/// Elementary function properties (sin, cos, exp, log)
14///
15/// Performance-optimized layout with hot path data first
16/// for cache-friendly access patterns.
17///
18/// **Note**: Evaluation is handled by direct dispatch through
19/// `Expression::evaluate_function_dispatch()` for performance.
20/// This struct stores only mathematical properties, not evaluation logic.
21#[derive(Clone)]
22pub struct ElementaryProperties {
23    /// Most frequently accessed property (hot path data)
24    pub derivative_rule: Option<DerivativeRule>,
25
26    /// Antiderivative rule for integration
27    pub antiderivative_rule: Option<AntiderivativeRule>,
28
29    /// Special values for exact computation
30    /// Examples: sin(0) = 0, cos(π/2) = 0, exp(0) = 1
31    pub special_values: Vec<SpecialValue>,
32
33    /// Mathematical identities (boxed to keep struct small)
34    /// Examples: sin²(x) + cos²(x) = 1, e^(ln(x)) = x
35    pub identities: Box<Vec<MathIdentity>>,
36
37    /// Domain and range information (cold path data)
38    pub domain_range: Box<DomainRangeData>,
39
40    /// Periodicity information (if applicable)
41    pub periodicity: Option<Expression>,
42
43    /// Wolfram Language function name
44    /// Used for Wolfram formatting without hardcoded matches
45    /// Example: "sin" → "Sin", "ln" → "Log"
46    pub wolfram_name: Option<&'static str>,
47}
48
49impl std::fmt::Debug for ElementaryProperties {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        f.debug_struct("ElementaryProperties")
52            .field("derivative_rule", &self.derivative_rule)
53            .field("antiderivative_rule", &self.antiderivative_rule)
54            .field("special_values", &self.special_values)
55            .field("identities", &self.identities)
56            .field("domain_range", &self.domain_range)
57            .field("periodicity", &self.periodicity)
58            .field("wolfram_name", &self.wolfram_name)
59            .finish()
60    }
61}
62
63/// User-defined function properties
64///
65/// Properties for functions defined by users (f, g, h, etc.)
66/// Minimal overhead while supporting mathematical analysis.
67#[derive(Debug, Clone)]
68pub struct UserProperties {
69    /// Function definition (if provided by user)
70    pub definition: Option<Expression>,
71
72    /// Known mathematical properties
73    pub properties: Vec<UserProperty>,
74
75    /// Known derivatives (if computed or provided)
76    pub derivatives: HashMap<crate::core::Symbol, Expression>,
77
78    /// Domain restriction (if specified)
79    pub domain: Option<super::rules::Domain>,
80
81    /// Wolfram Language function name (if different from internal name)
82    pub wolfram_name: Option<&'static str>,
83}
84
85/// User-defined function properties
86#[derive(Debug, Clone)]
87pub enum UserProperty {
88    Even,
89    Odd,
90    Periodic(Expression),
91    Monotonic,
92    Bounded,
93}