@@ -148,62 +148,6 @@ function _error_for_negative_degree(deg)
148
148
end
149
149
end
150
150
151
- const _Lex = Union{MP. LexOrder,MP. InverseLexOrder}
152
-
153
- _last_lex_index (n, :: Type{MP.LexOrder} ) = n
154
- _prev_lex_index (i, :: Type{MP.LexOrder} ) = i - 1
155
- _not_first_indices (n, :: Type{MP.LexOrder} ) = n: - 1 : 2
156
- _last_lex_index (_, :: Type{MP.InverseLexOrder} ) = 1
157
- _prev_lex_index (i, :: Type{MP.InverseLexOrder} ) = i + 1
158
- _not_first_indices (n, :: Type{MP.InverseLexOrder} ) = 1 : (n- 1 )
159
-
160
- function _fill_exponents! (Z, n, degs, :: Type{Commutative} , M:: Type{<:_Lex} , filter:: Function )
161
- _error_for_negative_degree .(degs)
162
- maxdeg = maximum (degs, init = 0 )
163
- I = _not_first_indices (n, M)
164
- z = zeros (Int, n)
165
- while true
166
- deg = sum (z)
167
- if deg in degs && filter (z)
168
- push! (Z, z)
169
- z = copy (z)
170
- end
171
- if deg == maxdeg
172
- i = findfirst (i -> ! iszero (z[i]), I)
173
- if isnothing (i)
174
- break
175
- end
176
- j = I[i]
177
- z[j] = 0
178
- z[_prev_lex_index (j, M)] += 1
179
- else
180
- z[_last_lex_index (n, M)] += 1
181
- end
182
- end
183
- end
184
-
185
- function _fill_exponents! (Z, n, deg, :: Type{Commutative} , M:: Type{<:_Lex} , filter:: Function , :: Int )
186
- _error_for_negative_degree (deg)
187
- I = _not_first_indices (n, M)
188
- z = zeros (Int, n)
189
- z[_last_lex_index (n, M)] = deg
190
- while true
191
- if filter (z)
192
- push! (Z, z)
193
- z = copy (z)
194
- end
195
- i = findfirst (i -> ! iszero (z[i]), I)
196
- if isnothing (i)
197
- break
198
- end
199
- j = I[i]
200
- p = z[j]
201
- z[j] = 0
202
- z[_last_lex_index (n, M)] = p - 1
203
- z[_prev_lex_index (j, M)] += 1
204
- end
205
- end
206
-
207
151
function _fill_noncomm_exponents_rec! (Z, z, i, n, deg, :: Type{MP.LexOrder} , filter:: Function )
208
152
if deg == 0
209
153
if filter (z)
@@ -235,68 +179,12 @@ function _fill_exponents!(
235
179
return reverse! (view (Z, start: length (Z)))
236
180
end
237
181
238
- function _fill_exponents! (Z, n, deg, :: Type{V} , :: Type{MP.Reverse{M}} , args... ) where {V,M}
239
- prev = lastindex (Z)
240
- _fill_exponents! (Z, n, deg, V, M, args... )
241
- reverse! (view (Z, (prev + 1 ): lastindex (Z)))
242
- return
243
- end
244
-
245
- function _fill_exponents! (
246
- Z:: Vector{Vector{Int}} ,
247
- n,
248
- degs:: AbstractVector{Int} ,
249
- :: Type{V} ,
250
- :: Type{MP.Graded{M}} ,
251
- filter:: Function ,
252
- ) where {V,M}
253
- # For non-commutative, lower degree need to create a vector of exponent as large as for the highest degree
254
- maxdeg = maximum (degs, init = 0 )
255
- for deg in sort (degs)
256
- _fill_exponents! (Z, n, deg, V, M, filter, maxdeg)
257
- end
258
- return
259
- end
260
-
261
182
# List exponents in decreasing Graded Lexicographic Order
262
- function _all_exponents (
263
- n,
264
- degs:: AbstractVector{Int} ,
265
- :: Type{V} ,
266
- :: Type{M} ,
267
- filter:: Function ,
268
- ) where {V,M}
269
- Z = Vector{Int}[]
270
- _fill_exponents! (Z, n, degs, V, M, filter)
271
- _isless = let M = M
272
- (a, b) -> MP. compare (a, b, M) < 0
273
- end
274
- @assert issorted (Z, lt = _isless)
275
- return Z
276
- end
277
-
278
- function MonomialVector (
279
- vars:: Vector{<:Variable{<:Commutative,M}} ,
280
- degs:: AbstractVector{Int} ,
281
- filter:: Function = x -> true ,
282
- ) where {M}
283
- vars = unique! (sort (vars, rev = true ))
284
- return MonomialVector (
285
- vars,
286
- _all_exponents (
287
- length (vars),
288
- degs,
289
- Commutative,
290
- M,
291
- z -> filter (Monomial (vars, z)),
292
- ),
293
- )
294
- end
295
-
296
183
function getvarsforlength (vars:: Vector{<:Variable{<:NonCommutative}} , len:: Int )
297
184
n = length (vars)
298
185
return map (i -> vars[((i- 1 )% n)+ 1 ], 1 : len)
299
186
end
187
+
300
188
function MonomialVector (
301
189
vars:: Vector{<:Variable{<:NonCommutative,M}} ,
302
190
degs:: AbstractVector{Int} ,
@@ -313,6 +201,23 @@ function MonomialVector(
313
201
v = isempty (Z) ? vars : getvarsforlength (vars, length (first (Z)))
314
202
return MonomialVector (v, Z)
315
203
end
204
+
205
+ function MonomialVector (
206
+ vars:: Vector{<:Variable{<:Commutative,M}} ,
207
+ degs:: AbstractVector{Int} ,
208
+ filter:: Function = x -> true ,
209
+ ) where {M}
210
+ vars = unique! (sort (vars, rev = true ))
211
+ Z = Iterators. Filter (MP. ExponentsIterator {M} (
212
+ zeros (Int, length (vars));
213
+ mindegree = minimum (degs),
214
+ maxdegree = maximum (degs),
215
+ )) do z
216
+ filter (Monomial (vars, z))
217
+ end
218
+ return MonomialVector (v, Z)
219
+ end
220
+
316
221
function MonomialVector (
317
222
vars:: Vector{<:Variable} ,
318
223
degs:: Int ,
324
229
function MP. monomials (vars:: AbstractVector{<:Variable} , args... )
325
230
return MonomialVector (vars, args... )
326
231
end
232
+
327
233
function MP. monomials (vars:: Tuple{Vararg{Variable}} , args... )
328
234
return monomials ([vars... ], args... )
329
235
end
0 commit comments