Skip to content

Commit

Permalink
Yet more flinitfy (and related tweaks) (#1876)
Browse files Browse the repository at this point in the history
Also remove redundant `jacobi_symbol` method.
  • Loading branch information
fingolfin authored Oct 4, 2024
1 parent fbef9d1 commit d457d82
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 223 deletions.
2 changes: 0 additions & 2 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,6 @@ function Base.rem(a::ZZModRingElem, b::ZZModRingElem)
return r
end

jacobi_symbol(x::Integer, y::ZZRingElem) = jacobi_symbol(ZZRingElem(x), y)

@doc raw"""
zeros(f::ZZPolyRingElem) -> Vector{ZZRingElem}
Expand Down
24 changes: 12 additions & 12 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ function -(a::QQFieldElem, b::AbsSimpleNumFieldElem)
return r
end

+(a::AbsSimpleNumFieldElem, b::Integer) = a + ZZRingElem(b)
+(a::AbsSimpleNumFieldElem, b::Integer) = a + flintify(b)

-(a::AbsSimpleNumFieldElem, b::Integer) = a - ZZRingElem(b)
-(a::AbsSimpleNumFieldElem, b::Integer) = a - flintify(b)

-(a::Integer, b::AbsSimpleNumFieldElem) = ZZRingElem(a) - b
-(a::Integer, b::AbsSimpleNumFieldElem) = flintify(a) - b

+(a::Integer, b::AbsSimpleNumFieldElem) = b + a

Expand Down Expand Up @@ -444,7 +444,7 @@ end

*(a::AbsSimpleNumFieldElem, b::Rational) = b * a

*(a::AbsSimpleNumFieldElem, b::Integer) = a * ZZRingElem(b)
*(a::AbsSimpleNumFieldElem, b::Integer) = a * flintify(b)

*(a::Integer, b::AbsSimpleNumFieldElem) = b * a

Expand All @@ -456,7 +456,7 @@ end

//(a::AbsSimpleNumFieldElem, b::ZZRingElem) = divexact(a, b)

//(a::AbsSimpleNumFieldElem, b::Integer) = a//ZZRingElem(b)
//(a::AbsSimpleNumFieldElem, b::Integer) = a//flintify(b)

//(a::AbsSimpleNumFieldElem, b::QQFieldElem) = divexact(a, b)

Expand Down Expand Up @@ -534,7 +534,7 @@ function ==(a::AbsSimpleNumFieldElem, b::UInt)
return Bool(b)
end

==(a::AbsSimpleNumFieldElem, b::Integer) = a == ZZRingElem(b)
==(a::AbsSimpleNumFieldElem, b::Integer) = a == flintify(b)

==(a::AbsSimpleNumFieldElem, b::Rational) = a == QQFieldElem(b)

Expand Down Expand Up @@ -611,7 +611,7 @@ function divexact(a::AbsSimpleNumFieldElem, b::ZZRingElem; check::Bool=true)
return r
end

divexact(a::AbsSimpleNumFieldElem, b::Integer; check::Bool=true) = divexact(a, ZZRingElem(b); check=check)
divexact(a::AbsSimpleNumFieldElem, b::Integer; check::Bool=true) = divexact(a, flintify(b); check=check)

function divexact(a::AbsSimpleNumFieldElem, b::QQFieldElem; check::Bool=true)
iszero(b) && throw(DivideError())
Expand Down Expand Up @@ -814,7 +814,7 @@ function add!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Int)
return c
end

add!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = add!(c, a, ZZRingElem(b))
add!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = add!(c, a, flintify(b))

function sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::QQFieldElem)
ccall((:nf_elem_sub_fmpq, libflint), Nothing,
Expand All @@ -837,7 +837,7 @@ function sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Int)
return c
end

sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = sub!(c, a, ZZRingElem(b))
sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = sub!(c, a, flintify(b))

function sub!(c::AbsSimpleNumFieldElem, a::QQFieldElem, b::AbsSimpleNumFieldElem)
ccall((:nf_elem_fmpq_sub, libflint), Nothing,
Expand All @@ -860,7 +860,7 @@ function sub!(c::AbsSimpleNumFieldElem, a::Int, b::AbsSimpleNumFieldElem)
return c
end

sub!(c::AbsSimpleNumFieldElem, a::Integer, b::AbsSimpleNumFieldElem) = sub!(c, ZZRingElem(a), b)
sub!(c::AbsSimpleNumFieldElem, a::Integer, b::AbsSimpleNumFieldElem) = sub!(c, flintify(a), b)

function mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::QQFieldElem)
ccall((:nf_elem_scalar_mul_fmpq, libflint), Nothing,
Expand All @@ -883,7 +883,7 @@ function mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Int)
return c
end

mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = mul!(c, a, ZZRingElem(b))
mul!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = mul!(c, a, flintify(b))

###############################################################################
#
Expand Down Expand Up @@ -1090,7 +1090,7 @@ function (a::AbsSimpleNumField)(c::Int)
return z
end

(a::AbsSimpleNumField)(c::Integer) = a(ZZRingElem(c))
(a::AbsSimpleNumField)(c::Integer) = a(flintify(c))

function (a::AbsSimpleNumField)(c::ZZRingElem)
z = AbsSimpleNumFieldElem(a)
Expand Down
20 changes: 10 additions & 10 deletions src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,21 @@ function -(x::RealFieldElem, y::ComplexFieldElem)
return z
end

+(x::ComplexFieldElem, y::Integer) = x + ZZRingElem(y)
+(x::ComplexFieldElem, y::Integer) = x + flintify(y)

-(x::ComplexFieldElem, y::Integer) = x - ZZRingElem(y)
-(x::ComplexFieldElem, y::Integer) = x - flintify(y)

*(x::ComplexFieldElem, y::Integer) = x*ZZRingElem(y)
*(x::ComplexFieldElem, y::Integer) = x*flintify(y)

//(x::ComplexFieldElem, y::Integer) = x//ZZRingElem(y)
//(x::ComplexFieldElem, y::Integer) = x//flintify(y)

+(x::Integer, y::ComplexFieldElem) = ZZRingElem(x) + y
+(x::Integer, y::ComplexFieldElem) = flintify(x) + y

-(x::Integer, y::ComplexFieldElem) = ZZRingElem(x) - y
-(x::Integer, y::ComplexFieldElem) = flintify(x) - y

*(x::Integer, y::ComplexFieldElem) = ZZRingElem(x)*y
*(x::Integer, y::ComplexFieldElem) = flintify(x)*y

//(x::Integer, y::ComplexFieldElem) = ZZRingElem(x)//y
//(x::Integer, y::ComplexFieldElem) = flintify(x)//y

divexact(x::ComplexFieldElem, y::ComplexFieldElem; check::Bool=true) = x // y
divexact(x::ZZRingElem, y::ComplexFieldElem; check::Bool=true) = x // y
Expand Down Expand Up @@ -352,8 +352,8 @@ end
==(x::ComplexFieldElem,y::ZZRingElem) = (x == parent(x)(y))
==(x::ZZRingElem,y::ComplexFieldElem) = (y == parent(y)(x))

==(x::ComplexFieldElem,y::Integer) = x == ZZRingElem(y)
==(x::Integer,y::ComplexFieldElem) = ZZRingElem(x) == y
==(x::ComplexFieldElem,y::Integer) = x == flintify(y)
==(x::Integer,y::ComplexFieldElem) = flintify(x) == y

==(x::ComplexFieldElem,y::Float64) = (x == parent(x)(y))
==(x::Float64,y::ComplexFieldElem) = (y == parent(y)(x))
Expand Down
132 changes: 0 additions & 132 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4715,85 +4715,6 @@ mutable struct QQMatrix <: MatElem{QQFieldElem}
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{QQFieldElem})
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j])
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem})
z = QQMatrix(r, c)
b = ZZRingElem(1)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j], b)
end
end
return z
end


function QQMatrix(r::Int, c::Int, arr::AbstractVector{QQFieldElem})
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j])
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem})
z = QQMatrix(r, c)
b = ZZRingElem(1)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j], b)
end
end
return z
end


function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: Integer}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, QQFieldElem(arr[i, j]))
end
end
return z
end

function QQMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: Integer}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, QQFieldElem(arr[(i-1)*c+j]))
end
end
return z
end

function QQMatrix(r::Int, c::Int, d::QQFieldElem)
z = QQMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

function QQMatrix(m::QQMatrix)
z = new()
ccall((:fmpq_mat_init_set, libflint), Nothing,
Expand Down Expand Up @@ -4837,59 +4758,6 @@ mutable struct ZZMatrix <: MatElem{ZZRingElem}
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractMatrix{ZZRingElem})
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[i, j])
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractVector{ZZRingElem})
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, arr[(i-1)*c+j])
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: Integer}
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, ZZRingElem(arr[i, j]))
end
end
return z
end

function ZZMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: Integer}
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, ZZRingElem(arr[(i-1)*c+j]))
end
end
return z
end

function ZZMatrix(r::Int, c::Int, d::ZZRingElem)
z = ZZMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

function ZZMatrix(m::ZZMatrix)
z = new()
ccall((:fmpz_mat_init_set, libflint), Nothing,
Expand Down
43 changes: 26 additions & 17 deletions src/flint/fmpq_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -910,36 +910,45 @@ promote_rule(::Type{QQMatrix}, ::Type{Rational{T}}) where T <: Union{Int, BigInt
#
###############################################################################

function matrix(R::QQField, arr::AbstractMatrix{QQFieldElem})
function matrix(R::QQField, arr::AbstractMatrix{T}) where {T <: RationalUnion}
z = QQMatrix(size(arr, 1), size(arr, 2), arr)
return z
end

function matrix(R::QQField, arr::AbstractMatrix{<: Union{ZZRingElem, Int, BigInt}})
z = QQMatrix(size(arr, 1), size(arr, 2), arr)
return z
end

function matrix(R::QQField, arr::AbstractMatrix{Rational{T}}) where {T <: Integer}
z = QQMatrix(size(arr, 1), size(arr, 2), map(QQFieldElem, arr))
function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{T}) where {T <: RationalUnion}
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{QQFieldElem})
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
function QQMatrix(r::Int, c::Int, arr::AbstractMatrix{T}) where {T <: RationalUnion}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, flintify(arr[i, j]))
end
end
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{<: Union{ZZRingElem, Int, BigInt}})
_check_dim(r, c, arr)
z = QQMatrix(r, c, arr)
function QQMatrix(r::Int, c::Int, arr::AbstractVector{T}) where {T <: RationalUnion}
z = QQMatrix(r, c)
GC.@preserve z for i = 1:r
for j = 1:c
el = mat_entry_ptr(z, i, j)
set!(el, flintify(arr[(i-1)*c+j]))
end
end
return z
end

function matrix(R::QQField, r::Int, c::Int, arr::AbstractVector{Rational{T}}) where {T <: Union{ZZRingElem, Int, BigInt}}
_check_dim(r, c, arr)
z = QQMatrix(r, c, map(QQFieldElem, arr))
function QQMatrix(r::Int, c::Int, d::RationalUnion)
z = QQMatrix(r, c)
GC.@preserve z for i = 1:min(r, c)
el = mat_entry_ptr(z, i, i)
set!(el, d)
end
return z
end

Expand Down
14 changes: 7 additions & 7 deletions src/flint/fmpq_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ end

*(x::QQPolyRingElem, y::QQFieldElem) = y*x

+(x::Integer, y::QQPolyRingElem) = y + ZZRingElem(x)
+(x::Integer, y::QQPolyRingElem) = y + flintify(x)

-(x::Integer, y::QQPolyRingElem) = ZZRingElem(x) - y
-(x::Integer, y::QQPolyRingElem) = flintify(x) - y

*(x::Integer, y::QQPolyRingElem) = ZZRingElem(x)*y
*(x::Integer, y::QQPolyRingElem) = flintify(x)*y

+(x::QQPolyRingElem, y::Integer) = x + ZZRingElem(y)
+(x::QQPolyRingElem, y::Integer) = x + flintify(y)

-(x::QQPolyRingElem, y::Integer) = x - ZZRingElem(y)
-(x::QQPolyRingElem, y::Integer) = x - flintify(y)

*(x::QQPolyRingElem, y::Integer) = ZZRingElem(y)*x
*(x::QQPolyRingElem, y::Integer) = flintify(y)*x

+(x::Rational, y::QQPolyRingElem) = QQFieldElem(x) + y

Expand Down Expand Up @@ -488,7 +488,7 @@ function divexact(x::QQPolyRingElem, y::Int; check::Bool=true)
return z
end

divexact(x::QQPolyRingElem, y::Integer; check::Bool=true) = divexact(x, ZZRingElem(y); check=check)
divexact(x::QQPolyRingElem, y::Integer; check::Bool=true) = divexact(x, flintify(y); check=check)

divexact(x::QQPolyRingElem, y::Rational{T}; check::Bool=true) where T <: Union{Int, BigInt} = divexact(x, QQFieldElem(y); check=check)

Expand Down
4 changes: 2 additions & 2 deletions src/flint/fmpq_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ end

*(x::QQRelPowerSeriesRingElem, y::QQFieldElem) = y * x

*(x::QQRelPowerSeriesRingElem, y::Integer) = x * ZZRingElem(y)
*(x::QQRelPowerSeriesRingElem, y::Integer) = x * flintify(y)

*(x::Integer, y::QQRelPowerSeriesRingElem) = ZZRingElem(x) * y
*(x::Integer, y::QQRelPowerSeriesRingElem) = flintify(x) * y

*(x::QQRelPowerSeriesRingElem, y::Rational) = x * QQFieldElem(y)

Expand Down
Loading

0 comments on commit d457d82

Please sign in to comment.