mathhook-core 0.2.0

Core mathematical engine for MathHook - expressions, algebra, and solving
Documentation
//! Elementary Function Properties
//!
//! Properties and mathematical intelligence for elementary functions including
//! trigonometric, exponential, logarithmic, and hyperbolic functions.
//! Performance-optimized with hot path data first for cache-friendly access patterns.

use super::rules::{
    AntiderivativeRule, DerivativeRule, DomainRangeData, MathIdentity, SpecialValue,
};
use crate::core::Expression;
use std::collections::HashMap;

/// Elementary function properties (sin, cos, exp, log)
///
/// Performance-optimized layout with hot path data first
/// for cache-friendly access patterns.
///
/// **Note**: Evaluation is handled by direct dispatch through
/// `Expression::evaluate_function_dispatch()` for performance.
/// This struct stores only mathematical properties, not evaluation logic.
#[derive(Clone)]
pub struct ElementaryProperties {
    /// Most frequently accessed property (hot path data)
    pub derivative_rule: Option<DerivativeRule>,

    /// Antiderivative rule for integration
    pub antiderivative_rule: Option<AntiderivativeRule>,

    /// Special values for exact computation
    /// Examples: sin(0) = 0, cos(π/2) = 0, exp(0) = 1
    pub special_values: Vec<SpecialValue>,

    /// Mathematical identities (boxed to keep struct small)
    /// Examples: sin²(x) + cos²(x) = 1, e^(ln(x)) = x
    pub identities: Box<Vec<MathIdentity>>,

    /// Domain and range information (cold path data)
    pub domain_range: Box<DomainRangeData>,

    /// Periodicity information (if applicable)
    pub periodicity: Option<Expression>,

    /// Wolfram Language function name
    /// Used for Wolfram formatting without hardcoded matches
    /// Example: "sin" → "Sin", "ln" → "Log"
    pub wolfram_name: Option<&'static str>,
}

impl std::fmt::Debug for ElementaryProperties {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ElementaryProperties")
            .field("derivative_rule", &self.derivative_rule)
            .field("antiderivative_rule", &self.antiderivative_rule)
            .field("special_values", &self.special_values)
            .field("identities", &self.identities)
            .field("domain_range", &self.domain_range)
            .field("periodicity", &self.periodicity)
            .field("wolfram_name", &self.wolfram_name)
            .finish()
    }
}

/// User-defined function properties
///
/// Properties for functions defined by users (f, g, h, etc.)
/// Minimal overhead while supporting mathematical analysis.
#[derive(Debug, Clone)]
pub struct UserProperties {
    /// Function definition (if provided by user)
    pub definition: Option<Expression>,

    /// Known mathematical properties
    pub properties: Vec<UserProperty>,

    /// Known derivatives (if computed or provided)
    pub derivatives: HashMap<crate::core::Symbol, Expression>,

    /// Domain restriction (if specified)
    pub domain: Option<super::rules::Domain>,

    /// Wolfram Language function name (if different from internal name)
    pub wolfram_name: Option<&'static str>,
}

/// User-defined function properties
#[derive(Debug, Clone)]
pub enum UserProperty {
    Even,
    Odd,
    Periodic(Expression),
    Monotonic,
    Bounded,
}