Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global Flint* objects #1935

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ export FlintPuiseuxSeriesField
export FlintPuiseuxSeriesFieldElem
export FlintPuiseuxSeriesRing
export FlintPuiseuxSeriesRingElem
export FlintQQ
export FlintQQi
export FlintZZ
export FlintZZi
export flog
export floor
export fmma!
Expand Down
16 changes: 2 additions & 14 deletions src/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -573,26 +573,14 @@ const _ecm_nC = Int[25, 90, 300, 700, 1800, 5100, 10600, 19300, 49000, 124000, 2
const _ecm_B1s = Vector{Int}[_ecm_B1]
const _ecm_nCs = Vector{Int}[_ecm_nC]

###############################################################################
#
# Set domain for ZZ, QQ to Flint
#
###############################################################################

@doc zz_ring_doc
const FlintZZ = ZZ

@doc qq_field_doc
const FlintQQ = QQ

###############################################################################
#
# Set domain for RR, CC to Arb
#
###############################################################################

GaussianIntegers() = FlintZZi
GaussianRationals() = FlintQQi
GaussianIntegers() = ZZiRing()
GaussianRationals() = QQiField()

###############################################################################
#
Expand Down
4 changes: 0 additions & 4 deletions src/gaussiannumbers/GaussianNumberTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
struct ZZiRing <: Ring
end

const FlintZZi = ZZiRing()

struct ZZiRingElem <: RingElem
x::ZZRingElem
y::ZZRingElem
Expand All @@ -13,8 +11,6 @@ end
struct QQiField <: Field
end

const FlintQQi = QQiField()

struct QQiFieldElem <: FieldElem
num::ZZiRingElem
den::ZZRingElem
Expand Down
24 changes: 12 additions & 12 deletions src/gaussiannumbers/QQi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ elem_type(::Type{QQiField}) = QQiFieldElem

parent_type(::Type{QQiFieldElem}) = QQiField

parent(a::QQiFieldElem) = FlintQQi
parent(a::QQiFieldElem) = QQiField()

base_ring_type(::Type{QQiField}) = ZZiRing

base_ring(a::QQiField) = FlintZZi
base_ring(a::QQiField) = ZZiRing()

is_domain_type(::Type{QQiFieldElem}) = true

Expand Down Expand Up @@ -155,7 +155,7 @@ end
function rand_bits(a::QQiField, b::Int)
b = max(1, b)
t = clamp(cld(rand(0:b)^2, b), 1, b) # average b/3 for the denominator
return reduce!(QQiFieldElem(rand_bits(FlintZZi, clamp(b - t, 0, b)), rand_bits(ZZ, t)))
return reduce!(QQiFieldElem(rand_bits(ZZiRing(), clamp(b - t, 0, b)), rand_bits(ZZ, t)))
end

###############################################################################
Expand Down Expand Up @@ -186,11 +186,11 @@ function abs2(a::QQiFieldElem)
end

function zero(a::QQiField)
return QQiFieldElem(zero(FlintZZi), ZZRingElem(1))
return QQiFieldElem(zero(ZZiRing), ZZRingElem(1))
end

function one(a::QQiField)
return QQiFieldElem(one(FlintZZi), ZZRingElem(1))
return QQiFieldElem(one(ZZiRing), ZZRingElem(1))
end

function iszero(a::QQiFieldElem)
Expand Down Expand Up @@ -462,22 +462,22 @@ for (A, Bs) in [
return QQiFieldElem
end
function +(a::($A), b::($B))
return FlintQQi(a) + FlintQQi(b)
return QQiField()(a) + QQiField()(b)
end
function +(a::($B), b::($A))
return FlintQQi(a) + FlintQQi(b)
return QQiField()(a) + QQiField()(b)
end
function -(a::($A), b::($B))
return FlintQQi(a) - FlintQQi(b)
return QQiField()(a) - QQiField()(b)
end
function -(a::($B), b::($A))
return FlintQQi(a) - FlintQQi(b)
return QQiField()(a) - QQiField()(b)
end
function *(a::($A), b::($B))
return FlintQQi(a) * FlintQQi(b)
return QQiField()(a) * QQiField()(b)
end
function *(a::($B), b::($A))
return FlintQQi(a) * FlintQQi(b)
return QQiField()(a) * QQiField()(b)
end
end
end
Expand All @@ -493,7 +493,7 @@ for (As, Bs) in [
for A in As, B in Bs
@eval begin
function //(a::($A), b::($B))
return divexact(FlintQQi(a), FlintQQi(b))
return divexact(QQiField()(a), QQiField()(b))
end
end
end
Expand Down
22 changes: 15 additions & 7 deletions src/gaussiannumbers/ZZi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ elem_type(::Type{ZZiRing}) = ZZiRingElem

parent_type(::Type{ZZiRingElem}) = ZZiRing

parent(a::ZZiRingElem) = FlintZZi
parent(a::ZZiRingElem) = ZZiRing()

base_ring_type(::Type{ZZiRing}) = ZZRing

Expand Down Expand Up @@ -70,7 +70,7 @@ function (a::ZZiRing)(b::IntegerUnion, c::IntegerUnion)
end

function (R::ZZiRing)(a::Complex{T}) where T <: Integer
return FlintZZi(ZZRingElem(real(a)), ZZRingElem(imag(a)))
return R(ZZRingElem(real(a)), ZZRingElem(imag(a)))
end

###############################################################################
Expand Down Expand Up @@ -164,10 +164,18 @@ function zero(a::ZZiRing)
return ZZiRingElem(ZZRingElem(0), ZZRingElem(0))
end

function zero(::Type{ZZiRing})
return ZZiRingElem(ZZRingElem(0), ZZRingElem(0))
end

function one(a::ZZiRing)
return ZZiRingElem(ZZRingElem(1), ZZRingElem(0))
end

function one(::Type{ZZiRing})
return ZZiRingElem(ZZRingElem(1), ZZRingElem(0))
end

function iszero(a::ZZiRingElem)
return iszero(a.x) && iszero(a.y)
end
Expand Down Expand Up @@ -739,14 +747,14 @@ end
function gcdx(a::ZZiRingElem, b::ZZiRingElem)
if iszero(a)
if iszero(b)
return (zero(FlintZZi), zero(FlintZZi), zero(FlintZZi))
return (zero(ZZiRing), zero(ZZiRing), zero(ZZiRing))
else
u = canonical_unit(b)
return (divexact(b, u), zero(FlintZZi), inv(u))
return (divexact(b, u), zero(ZZiRing), inv(u))
end
elseif iszero(b)
u = canonical_unit(a)
return (divexact(a, u), inv(u), zero(FlintZZi))
return (divexact(a, u), inv(u), zero(ZZiRing))
end
m = zero_matrix(ZZ, 4, 2)
m[1,1] = a.x; m[1,2] = a.y
Expand Down Expand Up @@ -847,8 +855,8 @@ promote_rule(a::Type{<:Complex{<:Integer}}, b::Type{ZZRingElem}) = ZZiRingElem

promote_rule(a::Type{ZZiRingElem}, b::Type{<:Complex{<:Integer}}) = ZZiRingElem
promote_rule(a::Type{<:Complex{<:Integer}}, b::Type{ZZiRingElem}) = ZZiRingElem
*(a::ZZiRingElem, b::Complex{<:Integer}) = a*FlintZZi(b)
*(b::Complex{<:Integer}, a::ZZiRingElem) = a*FlintZZi(b)
*(a::ZZiRingElem, b::Complex{<:Integer}) = a*parent(a)(b)
*(b::Complex{<:Integer}, a::ZZiRingElem) = a*parent(a)(b)
+(a::ZZiRingElem, b::Complex{<:Integer}) = ZZiRingElem(a.x + real(b), a.y + imag(b))
+(b::Complex{<:Integer}, a::ZZiRingElem) = ZZiRingElem(a.x + real(b), a.y + imag(b))
-(a::ZZiRingElem, b::Complex{<:Integer}) = ZZiRingElem(a.x - real(b), a.y - imag(b))
Expand Down
Loading