1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! # AST Utility Functions
//!
//! This module provides utility methods for querying and analyzing the AST.
//! These methods allow consumers to extract information about expressions
//! without manually traversing the tree structure.
//!
//! ## Key Features
//!
//! - **Variable Discovery**: `find_variables()`, `contains_variable()`
//! - **Function Discovery**: `find_functions()`
//! - **Constant Discovery**: `find_constants()`
//! - **Tree Traversal**: `map()`, `fold()`
//! - **Substitution**: `substitute()`, `substitute_all()`
//! - **Tree Metrics**: `depth()`, `node_count()`
//!
//! ## Examples
//!
//! ```
//! use mathlex::ast::{Expression, ExprKind, BinaryOp, MathConstant};
//!
//! // Create expression: 2 * π * x
//! let expr: Expression = ExprKind::Binary {
//! op: BinaryOp::Mul,
//! left: Box::new(ExprKind::Binary {
//! op: BinaryOp::Mul,
//! left: Box::new(Expression::integer(2)),
//! right: Box::new(Expression::constant(MathConstant::Pi)),
//! }.into()),
//! right: Box::new(Expression::variable("x".to_string())),
//! }.into();
//!
//! // Query the expression
//! assert_eq!(expr.find_variables().len(), 1); // {x}
//! assert_eq!(expr.find_constants().len(), 1); // {π}
//! assert_eq!(expr.depth(), 3);
//! assert_eq!(expr.node_count(), 5);
//! ```
pub