Expand description
§Abstract Syntax Tree (AST) Types
This module defines the core AST types used to represent mathematical expressions. The AST is the contract between mathlex parsers and consuming libraries.
§Design Philosophy
- Format Agnostic: The same mathematical concept produces the same AST regardless of input format (LaTeX or plain text)
- Structural Representation: AST nodes represent syntax, not evaluated values
- Complete Coverage: Supports algebra, calculus, linear algebra, and equations
§Key Types
Expression: The main AST node type representing any mathematical expressionMathConstant: Mathematical constants (π, e, i, ∞)BinaryOp: Binary operators (+, -, *, /, ^, %)UnaryOp: Unary operators (negation, factorial, transpose)MathFloat: Wrapper for f64 with proper equality and hashing semantics
§Examples
use mathlex::ast::{Expression, BinaryOp, MathConstant};
// Representing: 2 * π
let expr = Expression::Binary {
op: BinaryOp::Mul,
left: Box::new(Expression::Integer(2)),
right: Box::new(Expression::Constant(MathConstant::Pi)),
};
// Verify structure
match expr {
Expression::Binary { op: BinaryOp::Mul, .. } => println!("It's multiplication!"),
_ => panic!("Unexpected expression type"),
}Structs§
- Integral
Bounds - Bounds for definite integrals.
- Math
Float - Wrapper type for f64 that provides proper equality and hashing semantics.
Enums§
- Binary
Op - Binary operators for mathematical expressions.
- Direction
- Direction for limit evaluation.
- Expression
- The main AST node type representing mathematical expressions.
- Inequality
Op - Inequality operators for comparisons.
- Math
Constant - Mathematical constants used in expressions.
- UnaryOp
- Unary operators for mathematical expressions.