@@ -148,62 +148,6 @@ function _error_for_negative_degree(deg)
148148 end
149149end
150150
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-
207151function _fill_noncomm_exponents_rec! (Z, z, i, n, deg, :: Type{MP.LexOrder} , filter:: Function )
208152 if deg == 0
209153 if filter (z)
@@ -235,13 +179,6 @@ function _fill_exponents!(
235179 return reverse! (view (Z, start: length (Z)))
236180end
237181
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-
245182function _fill_exponents! (
246183 Z:: Vector{Vector{Int}} ,
247184 n,
@@ -266,7 +203,7 @@ function _all_exponents(
266203 :: Type{M} ,
267204 filter:: Function ,
268205) where {V,M}
269- Z = Vector {Vector{ Int}} ()
206+ Z = Vector{Int}[]
270207 _fill_exponents! (Z, n, degs, V, M, filter)
271208 _isless = let M = M
272209 (a, b) -> MP. compare (a, b, M) < 0
@@ -275,28 +212,11 @@ function _all_exponents(
275212 return Z
276213end
277214
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-
296215function getvarsforlength (vars:: Vector{<:Variable{<:NonCommutative}} , len:: Int )
297216 n = length (vars)
298217 return map (i -> vars[((i- 1 )% n)+ 1 ], 1 : len)
299218end
219+
300220function MonomialVector (
301221 vars:: Vector{<:Variable{<:NonCommutative,M}} ,
302222 degs:: AbstractVector{Int} ,
@@ -313,6 +233,31 @@ function MonomialVector(
313233 v = isempty (Z) ? vars : getvarsforlength (vars, length (first (Z)))
314234 return MonomialVector (v, Z)
315235end
236+
237+ function MonomialVector (
238+ vars:: Vector{<:Variable{<:Commutative,M}} ,
239+ degs:: AbstractVector{Int} ,
240+ filter:: Function = x -> true ,
241+ ) where {M}
242+ vars = unique! (sort (vars, rev = true ))
243+ if isempty (degs)
244+ mindegree = 0
245+ maxdegree = - 1
246+ else
247+ mindegree = minimum (degs)
248+ maxdegree = maximum (degs)
249+ end
250+ Z = Iterators. Filter (MP. ExponentsIterator {M} (
251+ zeros (Int, length (vars));
252+ mindegree,
253+ maxdegree,
254+ )) do z
255+ mono = Monomial (vars, z)
256+ MP. degree (mono) in degs && filter (mono)
257+ end
258+ return MonomialVector (vars, collect (Z))
259+ end
260+
316261function MonomialVector (
317262 vars:: Vector{<:Variable} ,
318263 degs:: Int ,
324269function MP. monomials (vars:: AbstractVector{<:Variable} , args... )
325270 return MonomialVector (vars, args... )
326271end
272+
327273function MP. monomials (vars:: Tuple{Vararg{Variable}} , args... )
328274 return monomials ([vars... ], args... )
329275end
390336function MonomialVector {V,M} (X:: DMonoVec{V,M} ) where {V,M}
391337 allvars, Z = buildZvarsvec (Variable{V,M}, X)
392338 _isless = let M = M
393- (a, b) -> MP . compare (a, b, M ) < 0
339+ (a, b) -> cmp ( M (), a, b ) < 0
394340 end
395341 sort! (Z, lt = _isless)
396342 dups = findall (i -> Z[i] == Z[i- 1 ], 2 : length (Z))
0 commit comments