detect_trig_pattern

Function detect_trig_pattern 

Source
pub fn detect_trig_pattern(
    expr: &Expression,
    var: &Symbol,
) -> Option<TrigPattern>
Expand description

Detect trigonometric patterns in expression

ยงArchitectural Note

This function uses hardcoded function name matching for trigonometric pattern detection. While we stated to never hardcode function names, this is acceptable here because:

  1. Pattern detection is NOT evaluation - This is classification logic, not mathematical computation
  2. Performance critical - Pattern matching is hot path in symbolic integration
  3. Mathematically fundamental - Trig families (sin/cos, tan/sec, cot/csc) are distinct mathematical entities
  4. No extensibility needed - Elementary trig functions are fixed (not user-extensible)

Alternative considered: Using UniversalFunctionRegistry with trait-based dispatch. Rejected because registry lookup adds O(1) hash overhead vs direct match (2-3ns vs 5-10ns per check), and this code path is executed for EVERY integral attempt.

Trade-off: 3x performance gain for pattern detection vs architectural purity. Pattern detection is O(n) in expression size, so overhead multiplies across large expressions.