Skip to content

Commit

Permalink
Fix degree with noncommutative variables
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 28, 2020
1 parent 45e69b8 commit 2b20331
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ degree(v::AbstractVariable, var::AbstractVariable) = (v == var ? 1 : 0)
#degree(m::AbstractMonomial, v::AbstractVariable) = _deg(v, powers(t)...)

function degree(m::AbstractMonomial, v::AbstractVariable)
i = findfirst(isequal(v), variables(m))
if i === nothing || iszero(i)
0
else
exponents(m)[i]
deg = 0
# With Noncommutative variables, there may be several powers with the same variable
for (var, exp) in powers(m)
if var == v
deg += exp
end
end
return deg
end

"""
Expand Down
7 changes: 7 additions & 0 deletions test/ncmonomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
@test collect(exponents(Y)) == [2]
end
end
@testset "Issue #148" begin
@ncpolyvar x y z
m = x * y^4 * x^2
@test 3 == @inferred degree(m, x)
@test 4 == @inferred degree(m, y)
@test 0 == @inferred degree(m, z)
end
@testset "Issue #71 of DynamicPolynomials" begin
Mod.@ncpolyvar x y
@test x^0 * y == y * x^0
Expand Down

0 comments on commit 2b20331

Please sign in to comment.