Skip to content

Commit

Permalink
Fix some ad hoc binary methods
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Jul 14, 2021
1 parent dcecbba commit 0b497f0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/poly/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,35 @@ function divexact(x::spoly, y::Rational)
return divexact(x, base_ring(x)(y))
end

################################################################################
#
# Ad hoc binary
#
################################################################################

# We cannot use the promote_rule mechanism, since n_Q and fmpq have no and
# should not have a promote_rule

function +(x::spoly, y::fmpq)
return x + parent(x)(y)
end

function +(x::fmpq, y::spoly)
return parent(y)(x) + y
end

function *(x::spoly, y::fmpq)
return x * parent(x)(y)
end

function *(x::fmpq, y::spoly)
return parent(y)(x) * y
end

function divexact(x::spoly, y::fmpq)
return divexact(x, parent(x)(y))
end

###############################################################################
#
# Divisibility testing
Expand Down
12 changes: 12 additions & 0 deletions test/poly/spoly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ end
@test divexact(2a, BigInt(2)//3) == 3a
end

@testset "spoly.adhoc_binary_operation" begin
R, (x, ) = PolynomialRing(QQ, ["x", ])

a = x^2 + 3x + 1

@test Nemo.QQ(2)*a == 2*a
@test a*Nemo.QQ(2) == 2*a
@test Nemo.QQ(2) + a == 2 + a
@test a + Nemo.QQ(2) == 2 + a
@test divexact(2a, Nemo.QQ(2)) == a
end

@testset "spoly.euclidean_division" begin
for k in [QQ, Nemo.QQ]
R, (x, y) = PolynomialRing(k, ["x", "y"])
Expand Down

0 comments on commit 0b497f0

Please sign in to comment.