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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//! Operator types for mathematical expressions.
/// Binary operators for mathematical expressions.
///
/// Represents operators that take two operands (left and right).
///
/// ## Operator Precedence
///
/// When displaying or parsing expressions, operators follow standard mathematical precedence:
/// 1. **`Pow`** (highest) - Exponentiation: `^`
/// 2. **`Mul`, `Div`, `Mod`** - Multiplication, division, modulo: `*`, `/`, `%`
/// 3. **`Add`, `Sub`** - Addition, subtraction: `+`, `-`
/// 4. **`PlusMinus`, `MinusPlus`** (lowest) - Combined operators: `±`, `∓`
///
/// ## Usage Notes
///
/// - **Associativity**: Most operators are left-associative except `Pow`, which is right-associative.
/// For example, `2^3^4` is parsed as `2^(3^4)`, not `(2^3)^4`.
/// - **PlusMinus and MinusPlus**: These represent the special combined operators `±` and `∓`,
/// commonly used in mathematics to indicate dual solutions (e.g., `x = 1 ± 2`).
///
/// ## Examples
///
/// ```
/// use mathlex::ast::{BinaryOp, ExprKind, Expression};
///
/// let add = BinaryOp::Add; // +
/// let pow = BinaryOp::Pow; // ^
/// assert_ne!(add, pow);
///
/// // Right-associative power: 2^3^4 is 2^(3^4)
/// let expr: Expression = ExprKind::Binary {
/// op: BinaryOp::Pow,
/// left: Box::new(Expression::integer(2)),
/// right: Box::new(ExprKind::Binary {
/// op: BinaryOp::Pow,
/// left: Box::new(Expression::integer(3)),
/// right: Box::new(Expression::integer(4)),
/// }.into()),
/// }.into();
/// ```
/// Unary operators for mathematical expressions.
///
/// Represents operators that take a single operand.
///
/// ## Operator Semantics
///
/// - **`Neg`**: Arithmetic negation (`-x`). Applied as a prefix operator.
/// - **`Pos`**: Unary plus (`+x`). Applied as a prefix operator. Usually redundant but
/// can be explicitly represented in the AST.
/// - **`Factorial`**: Factorial operator (`n!`). Applied as a postfix operator.
/// Typically used with non-negative integers.
/// - **`Transpose`**: Matrix or vector transpose (`Aᵀ` or `A'`). Applied as a postfix
/// operator. Used in linear algebra contexts.
///
/// ## Position
///
/// - **Prefix operators**: `Neg`, `Pos` - appear before the operand
/// - **Postfix operators**: `Factorial`, `Transpose` - appear after the operand
///
/// ## Examples
///
/// ```
/// use mathlex::ast::{UnaryOp, ExprKind, Expression};
///
/// // Negation: -5
/// let neg_expr = ExprKind::Unary {
/// op: UnaryOp::Neg,
/// operand: Box::new(Expression::integer(5)),
/// };
///
/// // Factorial: n!
/// let fact_expr = ExprKind::Unary {
/// op: UnaryOp::Factorial,
/// operand: Box::new(Expression::variable("n".to_string())),
/// };
///
/// // Transpose: A'
/// let transpose_expr = ExprKind::Unary {
/// op: UnaryOp::Transpose,
/// operand: Box::new(Expression::variable("A".to_string())),
/// };
/// ```
/// Direction for limit evaluation.
///
/// Specifies the direction from which a limit approaches a value.
///
/// # Examples
///
/// ```
/// use mathlex::ast::Direction;
///
/// let from_left = Direction::Left; // lim x→a⁻
/// let from_right = Direction::Right; // lim x→a⁺
/// let both = Direction::Both; // lim x→a
/// assert_ne!(from_left, both);
/// ```
/// Inequality operators for comparisons.
///
/// Represents relational operators used in inequalities.
///
/// # Examples
///
/// ```
/// use mathlex::ast::InequalityOp;
///
/// let less_than = InequalityOp::Lt; // <
/// let less_equal = InequalityOp::Le; // ≤
/// let not_equal = InequalityOp::Ne; // ≠
/// assert_ne!(less_than, less_equal);
/// ```
/// Logical operators for propositional logic.
/// Relation operators for mathematical relations.
///
/// Represents relations between mathematical objects such as similarity,
/// equivalence, congruence, and approximation.
///
/// # Examples
///
/// ```
/// use mathlex::ast::RelationOp;
///
/// let similar = RelationOp::Similar; // ~
/// let equiv = RelationOp::Equivalent; // ≡
/// let approx = RelationOp::Approx; // ≈
/// assert_ne!(similar, equiv);
/// ```