mathhook-core 0.2.0

Core mathematical engine for MathHook - expressions, algebra, and solving
Documentation
//! Hermite Polynomial Intelligence
//!
//! Mathematically accurate implementation of Hermite polynomials H_n(x)
//! for quantum harmonic oscillator eigenfunctions with verified properties.

use crate::core::{Expression, Symbol};
use crate::functions::properties::*;
use std::collections::HashMap;
use std::sync::Arc;

/// Hermite Polynomial Intelligence
///
/// Complete mathematical intelligence for Hermite polynomials H_n(x)
/// with ABSOLUTE MATHEMATICAL ACCURACY for quantum mechanics applications.
pub struct HermiteIntelligence {
    /// Function properties for Hermite polynomials
    properties: HashMap<String, FunctionProperties>,
}

impl Default for HermiteIntelligence {
    fn default() -> Self {
        Self::new()
    }
}

impl HermiteIntelligence {
    /// Create new Hermite polynomial intelligence system
    pub fn new() -> Self {
        let mut intelligence = Self {
            properties: HashMap::with_capacity(4),
        };

        intelligence.initialize_hermite_polynomials();

        intelligence
    }

    /// Get all Hermite polynomial properties
    pub fn get_properties(&self) -> HashMap<String, FunctionProperties> {
        self.properties.clone()
    }

    /// Check if function is a Hermite polynomial
    pub fn has_function(&self, name: &str) -> bool {
        self.properties.contains_key(name)
    }

    /// Initialize Hermite polynomials with ABSOLUTE MATHEMATICAL ACCURACY
    fn initialize_hermite_polynomials(&mut self) {
        // Hermite Polynomials H_n(x) - MATHEMATICALLY VERIFIED
        // Reference: Quantum Mechanics textbooks, Abramowitz & Stegun
        // These are the "physicist's" Hermite polynomials
        self.properties.insert(
            "hermite".to_owned(),
            FunctionProperties::Polynomial(Box::new(PolynomialProperties {

                family: PolynomialFamily::Hermite,

                // THREE-TERM RECURRENCE RELATION (MATHEMATICALLY VERIFIED)
                // H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x)
                recurrence: ThreeTermRecurrence {
                    // Coefficient of x*H_n(x): 2x
                    alpha_coeff: Expression::mul(vec![Expression::integer(2), Expression::symbol("x")]),

                    // No constant term
                    beta_coeff: Expression::integer(0),

                    // Coefficient of H_{n-1}(x): -2n
                    gamma_coeff: Expression::mul(vec![Expression::integer(-2), Expression::symbol("n")]),

                    // Initial conditions (mathematically verified)
                    // H_0(x) = 1, H_1(x) = 2x
                    initial_conditions: (
                        Expression::integer(1),
                        Expression::mul(vec![Expression::integer(2), Expression::symbol("x")])
                    ),
                },

                // Orthogonality properties (mathematically verified)
                // ∫_{-∞}^{∞} H_m(x) H_n(x) e^{-x²} dx = √π 2^n n! δ_{mn}
                orthogonality: Some(OrthogonalityData {
                    // Weight function: w(x) = e^{-x²}
                    weight_function: Expression::function("gaussian_weight", vec![Expression::symbol("x")]),

                    // Orthogonality interval: (-∞, ∞)
                    interval: (
                        Expression::mul(vec![Expression::integer(-1), Expression::symbol("")]),
                        Expression::symbol("")
                    ),

                    // Normalization: ||H_n||² = √π 2^n n!
                    norm_squared: Expression::function("hermite_norm_squared", vec![Expression::symbol("n")]),
                }),

                // Rodrigues' formula (mathematically verified)
                // H_n(x) = (-1)^n e^{x²} d^n/dx^n e^{-x²}
                rodrigues_formula: Some(RodriguesFormula {
                    formula: "H_n(x) = (-1)^n e^{x²} d^n/dx^n e^{-x²}".to_owned(),
                    normalization: Expression::pow(Expression::integer(-1), Expression::symbol("n")),
                    weight_function: Expression::function("gaussian_weight", vec![Expression::symbol("x")]),
                }),

                // Generating function (mathematically verified)
                // e^{2xt - t²} = Σ_{n=0}^∞ H_n(x) t^n/n!
                generating_function: Some(GeneratingFunction {
                    function: Expression::function("hermite_generating", vec![Expression::symbol("x"), Expression::symbol("t")]),
                    gf_type: GeneratingFunctionType::Exponential,
                }),

                // Special values (mathematically verified)
                special_values: vec![
                    // H_n(0) depends on parity of n
                    SpecialValue {
                        input: "0".to_owned(),
                        output: Expression::function("hermite_zero_value", vec![Expression::symbol("n")]),
                        latex_explanation: "H_n(0) = \\begin{cases} (-1)^{n/2} \\frac{n!}{(n/2)!} 2^{-n/2} & \\text{if } n \\text{ even} \\\\ 0 & \\text{if } n \\text{ odd} \\end{cases}".to_owned(),
                    },
                ],

                // Evaluation method: Recurrence is most numerically stable
                evaluation_method: EvaluationMethod::Recurrence,

                // Numerical evaluator using recurrence relation),

                // Symbolic expansion method for intelligence-driven computation
                symbolic_expander: Some(super::super::properties::special::SymbolicExpander::Custom(
                    super::symbolic::expand_hermite_symbolic
                )),

                antiderivative_rule: AntiderivativeRule {
                    rule_type: AntiderivativeRuleType::Custom {
                        builder: Arc::new(|var: Symbol| {
                            Expression::integral(
                                Expression::function("hermite", vec![Expression::symbol(var.clone())]),
                                var
                            )
                        }),
                    },
                    result_template: "∫H_n(x) dx (symbolic - orthogonal polynomial integration requires specialized techniques)".to_owned(),
                    constant_handling: ConstantOfIntegration::AddConstant,
                },
                wolfram_name: None,
            })),
        );
    }
}