Skip to content

Commit

Permalink
Add some missing MPolyElem_dec method
Browse files Browse the repository at this point in the history
- Fixes #223
- Small refactoring
  • Loading branch information
thofma committed Jan 7, 2021
1 parent 5eb1943 commit e44ce71
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/Rings/mpoly-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,40 @@ parent_type(::Type{MPolyElem_dec{T}}) where {T} = MPolyRing_dec{T}
one(W::MPolyRing_dec) = MPolyElem_dec(one(W.R), W)
zero(W::MPolyRing_dec) = MPolyElem_dec(zero(W.R), W)

+(a::MPolyElem_dec, b::MPolyElem_dec) = MPolyElem_dec(a.f+b.f, a.parent)
-(a::MPolyElem_dec, b::MPolyElem_dec) = MPolyElem_dec(a.f-b.f, a.parent)
################################################################################
#
# Binary operations
#
################################################################################

for T in [:(+), :(-), :(*), :divexact]
@eval ($T)(a::MPolyElem_dec,
b::MPolyElem_dec) = MPolyElem_dec($T(a.f, b.f), a.parent)
end

################################################################################
#
# Unitary operations
#
################################################################################

-(a::MPolyElem_dec) = MPolyElem_dec(-a.f, a.parent)
*(a::MPolyElem_dec, b::MPolyElem_dec) = MPolyElem_dec(a.f*b.f, a.parent)
==(a::MPolyElem_dec, b::MPolyElem_dec) = a.f == b.f
^(a::MPolyElem_dec, i::Int) = MPolyElem_dec(a.f^i, a.parent)

function Oscar.mul!(a::MPolyElem_dec, b::MPolyElem_dec, c::MPolyElem_dec)
################################################################################
#
# Equality
#
################################################################################

==(a::MPolyElem_dec, b::MPolyElem_dec) = a.f == b.f

^(a::MPolyElem_dec, i::Int) = MPolyElem_dec(a.f^i, a.parent)

function mul!(a::MPolyElem_dec, b::MPolyElem_dec, c::MPolyElem_dec)
return b*c
end

function Oscar.addeq!(a::MPolyElem_dec, b::MPolyElem_dec)
function addeq!(a::MPolyElem_dec, b::MPolyElem_dec)
return a+b
end

Expand Down
5 changes: 5 additions & 0 deletions test/Rings/mpoly-graded-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
Polys[i,j] = rmPols(i,j)
@test one(Rings_dec[i][j]) == Rings_dec[i][j](1)
@test zero(Rings_dec[i][j])== Rings_dec[i][j](0)
@test iszero(zero(Rings_dec[i][j]))
@test !iszero(one(Rings_dec[i][j]))
@test isone(one(Rings_dec[i][j]))
@test !isone(zero(Rings_dec[i][j]))
@test divexact(one(Rings_dec[i][j]), one(Rings_dec[i][j])) == one(Rings_dec[i][j])
@test (Polys[i,j][1] + Polys[i,j][2])^2 == Polys[i,j][1]^2 + 2*Polys[i,j][1]*Polys[i,j][2] + Polys[i,j][2]^2
@test (Polys[i,j][3] - Polys[i,j][4])^2 == Polys[i,j][3]^2 + 2*(-Polys[i,j][3])*Polys[i,j][4] + Polys[i,j][4]^2
@test Polys[i,j][2] * (Polys[i,j][3] + Polys[i,j][4]) == Oscar.addeq!(Oscar.mul!(Polys[i,j][1], Polys[i,j][2], Polys[i,j][3]), Oscar.mul!(Polys[i,j][1], Polys[i,j][2], Polys[i,j][4]))
Expand Down

0 comments on commit e44ce71

Please sign in to comment.