Module ast

Module ast 

Source
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 expression
  • MathConstant: 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§

IntegralBounds
Bounds for definite integrals.
MathFloat
Wrapper type for f64 that provides proper equality and hashing semantics.

Enums§

BinaryOp
Binary operators for mathematical expressions.
Direction
Direction for limit evaluation.
Expression
The main AST node type representing mathematical expressions.
InequalityOp
Inequality operators for comparisons.
MathConstant
Mathematical constants used in expressions.
UnaryOp
Unary operators for mathematical expressions.