mathhook_core/algebra/simplification/strategy.rs
1//! Simplification Strategy Trait
2//!
3//! Defines the interface for function-specific simplification strategies.
4//! Each function family can implement custom algebraic rewrite rules.
5
6use crate::core::Expression;
7
8/// Simplification strategy for a specific function or function family
9///
10/// Implements pattern-based algebraic rewrites (e.g., log(x^n) → n*log(x))
11/// Distinct from FunctionProperties which store declarative mathematical data.
12pub trait SimplificationStrategy: Send + Sync {
13 /// Apply simplification rules to function call
14 ///
15 /// # Arguments
16 ///
17 /// * `args` - Function arguments to simplify
18 ///
19 /// # Returns
20 ///
21 /// Simplified expression (may be unchanged if no rules apply)
22 ///
23 /// # Examples
24 ///
25 /// Common simplification patterns:
26 /// - log(1) → 0
27 /// - log(x^n) → n*log(x)
28 /// - sin(0) → 0
29 fn simplify(&self, args: &[Expression]) -> Expression;
30
31 /// Check if simplification strategy applies to given arguments
32 ///
33 /// Allows early rejection of inapplicable strategies
34 fn applies_to(&self, args: &[Expression]) -> bool {
35 !args.is_empty()
36 }
37
38 /// Get strategy name for debugging
39 fn name(&self) -> &str {
40 "UnnamedStrategy"
41 }
42}