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
//! Additional trait implementations for generated codes
/// Creates a [`crate::Coefficient`] from a floating-point expression.
///
/// This macro is a convenience wrapper around `Coefficient::try_from().expect()`
/// for use with floating-point values. It accepts both literals and expressions.
///
/// # Panics
///
/// Panics if the value is zero, infinite, or NaN.
///
/// # Examples
///
/// ```
/// use ommx::{coeff, linear, LinearMonomial, VariableID};
///
/// // Create coefficients from literals
/// let c1 = coeff!(2.5);
/// let c2 = coeff!(-1.0);
/// let c3 = coeff!(0.5);
///
/// // Create coefficients from expressions
/// let x = 2.0;
/// let c4 = coeff!(x + 0.5);
/// let c5 = coeff!(x * 3.0);
///
/// // Use in expressions
/// let expr = c1 * linear!(1)
/// + c2 * linear!(2);
/// ```
///
/// # Note
///
/// For runtime values or when error handling is needed, use `Coefficient::try_from()` instead:
///
/// ```
/// use ommx::Coefficient;
///
/// let runtime_value = 3.14;
/// let coeff = Coefficient::try_from(runtime_value)?;
/// # Ok::<(), ommx::CoefficientError>(())
/// ```
/// Creates a [`crate::LinearMonomial`] from a variable ID expression.
///
/// This macro is a convenience wrapper for creating linear monomials from integer expressions
/// representing variable IDs.
///
/// # Examples
///
/// ```
/// use ommx::{linear, LinearMonomial, VariableID};
///
/// // Create a linear monomial for variable x1
/// let x1 = linear!(1);
/// assert_eq!(x1, LinearMonomial::Variable(VariableID::from(1)));
///
/// // Create from expressions
/// let i = 2;
/// let x2 = linear!(i);
/// let x3 = linear!(i + 1);
/// ```
/// Creates a [`crate::QuadraticMonomial`] from variable ID expressions.
///
/// This macro supports creating quadratic monomials in multiple forms:
/// - `quadratic!(id)` creates a linear term within the quadratic space
/// - `quadratic!(id1, id2)` creates a quadratic pair term
///
/// # Examples
///
/// ```
/// use ommx::{quadratic, QuadraticMonomial, VariableID};
///
/// // Create a linear term in quadratic space (x1)
/// let x1 = quadratic!(1);
/// assert_eq!(x1, QuadraticMonomial::Linear(VariableID::from(1)));
///
/// // Create a quadratic pair term (x1 * x2)
/// let x1_x2 = quadratic!(1, 2);
/// assert_eq!(x1_x2, QuadraticMonomial::new_pair(VariableID::from(1), VariableID::from(2)));
///
/// // Create from expressions
/// let i = 1;
/// let j = 2;
/// let xi_xj = quadratic!(i, j);
/// ```
/// Creates a [`crate::MonomialDyn`] from variable ID expressions.
///
/// This macro creates a general monomial from one or more variable ID expressions.
/// The degree of the monomial depends on the number of variables provided.
///
/// # Examples
///
/// ```
/// use ommx::{monomial, MonomialDyn, VariableID};
///
/// // Create a linear monomial (x1)
/// let x1 = monomial!(1);
///
/// // Create a quadratic monomial (x1 * x2)
/// let x1_x2 = monomial!(1, 2);
///
/// // Create a cubic monomial (x1 * x2 * x3)
/// let x1_x2_x3 = monomial!(1, 2, 3);
///
/// // Create from expressions
/// let i = 1;
/// let j = 2;
/// let k = 3;
/// let xi_xj_xk = monomial!(i, j, k);
/// ```
/// Creates a [`crate::VariableIDSet`] from variable ID expressions.
///
/// This macro creates a `VariableIDSet` from one or more variable ID expressions.
/// It's a convenience wrapper for creating binary variable sets for use with
/// binary power reduction operations.
///
/// # Examples
///
/// ```
/// use ommx::{variable_ids, VariableIDSet, VariableID};
///
/// // Create a set containing variable x1
/// let binary_set = variable_ids!(1);
///
/// // Create a set containing variables x1 and x3
/// let binary_set = variable_ids!(1, 3);
///
/// // Create a set containing variables x1, x2, and x5
/// let binary_set = variable_ids!(1, 2, 5);
///
/// // Create from expressions
/// let i = 1;
/// let j = 3;
/// let binary_set = variable_ids!(i, j, i + 4);
/// ```
pub use impl_add_inverse;
pub use impl_mul_inverse;