Skip to content

Commit

Permalink
Added more convencience methods for arithmetics with Vector{QQFieldEl…
Browse files Browse the repository at this point in the history
…em} (#1559)
  • Loading branch information
YueRen authored Oct 19, 2023
1 parent 4f99e9e commit f2e3115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,20 @@ Rational(z::ZZRingElem) = Rational{BigInt}(z)

###############################################################################
#
# Convenience methods for arithmetics (since `QQFieldElem` is not a `Number` type)
# Convenience methods for arithmetics (since `QQFieldElem` and `ZZRingElem` are not `Number` types)
#
###############################################################################

//(v::Vector{QQFieldElem}, x::QQFieldElem) = v .// x
/(v::Vector{QQFieldElem}, x::QQFieldElem) = v ./ x
*(x::QQFieldElem, v::Vector{QQFieldElem}) = x .* v
*(v::Vector{QQFieldElem}, x::QQFieldElem) = v .* x

//(v::Vector{QQFieldElem}, x::ZZRingElem) = v .// x
/(v::Vector{QQFieldElem}, x::ZZRingElem) = v ./ x
*(x::ZZRingElem, v::Vector{QQFieldElem}) = x .* v
*(v::Vector{QQFieldElem}, x::ZZRingElem) = v .* x


###############################################################################
#
Expand Down
6 changes: 6 additions & 0 deletions test/flint/fmpq-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ end

@testset "QQFieldElem.vector_arithmetics" begin
@test QQFieldElem[1, 2, 3] // QQFieldElem(2) == QQFieldElem[1//2, 1, 3//2]
@test QQFieldElem[1, 2, 3] / QQFieldElem(2) == QQFieldElem[1//2, 1, 3//2]
@test QQFieldElem(2) * QQFieldElem[1, 2, 3] == QQFieldElem[2, 4, 6]
@test QQFieldElem[1, 2, 3] * QQFieldElem(2) == QQFieldElem[2, 4, 6]

@test QQFieldElem[1, 2, 3] // ZZRingElem(2) == QQFieldElem[1//2, 1, 3//2]
@test QQFieldElem[1, 2, 3] / ZZRingElem(2) == QQFieldElem[1//2, 1, 3//2]
@test ZZRingElem(2) * QQFieldElem[1, 2, 3] == QQFieldElem[2, 4, 6]
@test QQFieldElem[1, 2, 3] * ZZRingElem(2) == QQFieldElem[2, 4, 6]
end

@testset "QQFieldElem.manipulation" begin
Expand Down

0 comments on commit f2e3115

Please sign in to comment.