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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! # formulac
//!
//! `formulac` is a Rust library for parsing and evaluating mathematical
//! expressions with support for **complex numbers** and **extensible user-defined functions**.
//!
//! ## Overview
//! - Parse and evaluate expressions containing real and imaginary numbers.
//! - Use built-in operators, constants, and mathematical functions.
//! - Register your own constants and functions.
//! - Compile expressions into callable closures for repeated evaluation without re-parsing.
//!
//! Internally, expressions are first tokenized into lexeme,
//! then converted to an AST using the Shunting-Yard algorithm,
//! and finally compiled into Reverse Polish Notation (RPN) stack operations
//! for fast repeated execution.
//!
//! ## Feature Highlights
//! - **Complex number support** using [`num_complex::Complex<f64>`]
//! - **User-defined functions and constants**
//! - **Variables and arguments**
//! - **Operator precedence** and parentheses handling
//! - **Efficient compiled closures** avoiding repeated parsing
//!
//! ## Example
//! ```rust
//! use num_complex::Complex;
//! use formulac::Builder;
//!
//! let expr = Builder::new("sin(z) + a * cos(z)", ["z"])
//! .with_constants([("a", Complex::new(3.0, 2.0))])
//! .compile()
//! .expect("Failed to compile formula");
//!
//! let result = expr([Complex::new(1.0, 2.0)]);
//! println!("Result = {}", result);
//! ```
//!
//! ## Example: Retrieving All Names
//! ```rust
//! use formulac::constants::Constants;
//! use formulac::operators::OperatorKind;
//! use formulac::functions::FunctionKind;
//!
//!
//! // Constants
//! let constant_names = Constants::<f64>::symbols();
//! println!("Constants: {:?}", constant_names);
//!
//! // Unary / Binary operators
//! let unary_names = OperatorKind::symbols();
//! println!("Operators: {:?}", unary_names);
//!
//! // Functions
//! let function_names = FunctionKind::symbols();
//! println!("Functions: {:?}", function_names);
//! ```
//!
//! ## When to Use
//! Use `formulac` when you need:
//! - Fast repeated evaluation of mathematical formulas
//! - Complex number support in expressions
//! - Runtime extensibility via custom functions or constants
//!
//! ## License
//! Licensed under either **MIT** or **Apache-2.0** at your option.
pub type Builder<T, const N: usize> = Builder;
pub type UserFn<T> = UserFn;