mathhook_core/algebra/advanced_simplify/
helpers.rs

1//! Helper functions for advanced simplification
2
3use crate::algebra::simplification::registry::SIMPLIFICATION_REGISTRY;
4use crate::core::Expression;
5use std::slice::from_ref;
6
7impl Expression {
8    /// Simplify factorial function using registry
9    pub(super) fn compute_factorial(&self, arg: &Expression) -> Expression {
10        SIMPLIFICATION_REGISTRY.simplify_function("factorial", from_ref(arg))
11    }
12
13    /// Simplify logarithm functions using registry
14    pub(super) fn simplify_log_function(&self, args: &[Expression]) -> Expression {
15        SIMPLIFICATION_REGISTRY.simplify_function("log", args)
16    }
17
18    /// Simplify natural logarithm functions using registry
19    pub(super) fn simplify_ln_function(&self, args: &[Expression]) -> Expression {
20        SIMPLIFICATION_REGISTRY.simplify_function("ln", args)
21    }
22
23    /// Check if a function name is trigonometric
24    pub(super) fn is_trig_function(&self, name: &str) -> bool {
25        matches!(
26            name,
27            "sin"
28                | "cos"
29                | "tan"
30                | "csc"
31                | "sec"
32                | "cot"
33                | "asin"
34                | "acos"
35                | "atan"
36                | "sinh"
37                | "cosh"
38                | "tanh"
39        )
40    }
41
42    /// Simplify trigonometric functions using registry
43    pub(super) fn simplify_trig_function(&self, name: &str, args: &[Expression]) -> Expression {
44        SIMPLIFICATION_REGISTRY.simplify_function(name, args)
45    }
46
47    /// Simplify square root function using registry
48    pub(super) fn simplify_sqrt(&self, args: &[Expression]) -> Expression {
49        SIMPLIFICATION_REGISTRY.simplify_function("sqrt", args)
50    }
51
52    /// Simplify absolute value function using registry
53    pub(super) fn simplify_abs(&self, args: &[Expression]) -> Expression {
54        SIMPLIFICATION_REGISTRY.simplify_function("abs", args)
55    }
56
57    /// Simplify exponential function using registry
58    pub(super) fn simplify_exp(&self, args: &[Expression]) -> Expression {
59        SIMPLIFICATION_REGISTRY.simplify_function("exp", args)
60    }
61
62    /// Simplify gamma function using registry
63    pub(super) fn simplify_gamma(&self, args: &[Expression]) -> Expression {
64        SIMPLIFICATION_REGISTRY.simplify_function("gamma", args)
65    }
66
67    /// Create factorial expression
68    pub fn factorial(arg: Expression) -> Expression {
69        Expression::function("factorial", vec![arg])
70    }
71
72    /// Create natural logarithm expression
73    pub fn ln(arg: Expression) -> Expression {
74        Expression::function("ln", vec![arg])
75    }
76}