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

Add ZZ[i] and QQ[i] #1168

Merged
merged 13 commits into from
Sep 9, 2021
Merged
2 changes: 2 additions & 0 deletions src/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ include("calcium/qqbar.jl")

include("calcium/ca.jl")

include("gaussiannumbers/QQi.jl")

2 changes: 2 additions & 0 deletions src/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ include("arb/ArbTypes.jl")

include("calcium/CalciumTypes.jl")

include("gaussiannumbers/GaussianNumberTypes.jl")

#include("ambiguities.jl") # remove ambiguity warnings

include("flint/adhoc.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ include("arb/arb_mat.jl")

include("arb/acb_mat.jl")

include("gaussiannumbers/ZZi.jl")

include("Factor.jl")

include("polysubst.jl")
36 changes: 19 additions & 17 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -850,23 +850,6 @@ end

add!(c::fmpq, a::Int, b::fmpq) = add!(c, b, a)

###############################################################################
#
# Conversions to/from flint Julia rationals
#
###############################################################################

function Rational(z::fmpq)
r = Rational{BigInt}(0)
ccall((:fmpq_get_mpz_frac, libflint), Nothing,
(Ref{BigInt}, Ref{BigInt}, Ref{fmpq}), r.num, r.den, z)
return r
end

function Rational(z::fmpz)
return Rational{BigInt}(BigInt(z))
end

###############################################################################
#
# Parent object call overloads
Expand Down Expand Up @@ -939,8 +922,27 @@ promote_rule(::Type{fmpq}, ::Type{fmpz}) = fmpq

Base.promote_rule(::Type{fmpq}, ::Type{Rational{T}}) where {T <: Integer} = fmpq

function Base.convert(::Type{Rational{T}}, a::fmpq) where T <: Integer
return Rational{T}(convert(T, numerator(a)), convert(T, denominator(a)))
end

function Base.convert(::Type{fmpq}, a::Rational{T}) where T <: Integer
return convert(fmpz, numerator(a))//convert(fmpz, denominator(a))
end

convert(::Type{Rational{BigInt}}, a::fmpq) = Rational(a)

function Rational(z::fmpq)
r = Rational{BigInt}(0)
ccall((:fmpq_get_mpz_frac, libflint), Nothing,
(Ref{BigInt}, Ref{BigInt}, Ref{fmpq}), r.num, r.den, z)
return r
end

function Rational(z::fmpz)
return Rational{BigInt}(BigInt(z))
end

###############################################################################
#
# FractionField constructor
Expand Down
130 changes: 113 additions & 17 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,98 @@ end
#
###############################################################################

function zero!(z::fmpz)
ccall((:fmpz_zero, libflint), Nothing,
(Ref{fmpz},), z)
return z
end

function one!(z::fmpz)
ccall((:fmpz_set_ui, libflint), Nothing,
(Ref{fmpz}, UInt),
z, 1)
return z
end

function set!(z::fmpz, a::fmpz)
ccall((:fmpz_set, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
z, a)
return z
end

function swap!(a::fmpz, b::fmpz)
ccall((:fmpz_swap, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
a, b)
end

function addeq!(z::fmpz, x::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, z, x)
return z
end

function add!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
return z
end

function add!(z::fmpz, x::fmpz, y::Int)
ccall((:fmpz_add_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int), z, x, y)
return z
end

function add!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_add_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

add!(z::fmpz, a::fmpz, b::Integer) = add!(z, a, fmpz(b))
add!(z::fmpz, x::Int, y::fmpz) = add!(z, y, x)

function neg!(z::fmpz, a::fmpz)
ccall((:fmpz_neg, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
z, a)
return z
end

function sub!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_sub, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::Int)
ccall((:fmpz_sub_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_sub_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::Integer)
return sub!(z, a, fmpz(b))
end

function sub!(z::fmpz, b::Integer, a::fmpz)
sub!(z, a, b)
return neg!(z, z)
end


function mul!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_mul, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
Expand All @@ -2006,6 +2098,15 @@ function mul!(z::fmpz, x::fmpz, y::Int)
return z
end

function mul!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_mul_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

mul!(z::fmpz, a::fmpz, b::Integer) = mul!(z, a, fmpz(b))

mul!(z::fmpz, x::Int, y::fmpz) = mul!(z, y, x)

function addmul!(z::fmpz, x::fmpz, y::fmpz)
Expand All @@ -2024,29 +2125,24 @@ end

addmul!(z::fmpz, x::fmpz, y::Int, ::fmpz) = addmul!(z, x, y)

function addeq!(z::fmpz, x::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, z, x)
return z
end

function add!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
function submul!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_submul, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

function add!(z::fmpz, x::fmpz, y::Int)
ccall((:fmpz_add_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int), z, x, y)
function divexact!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_divexact, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

add!(z::fmpz, x::Int, y::fmpz) = add!(z, y, x)

function zero!(z::fmpz)
ccall((:fmpz_zero, libflint), Nothing,
(Ref{fmpz},), z)
function pow!(z::fmpz, a::fmpz, b::Union{Int, UInt})
ccall((:fmpz_pow_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, UInt(b))
return z
end

Expand Down
22 changes: 22 additions & 0 deletions src/gaussiannumbers/GaussianNumberTypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#### QQ(i) and ZZ(i) ####

mutable struct FlintZZiRing <: Nemo.Ring
end

const ZZi = FlintZZiRing()

struct fmpzi <: RingElem
x::fmpz
y::fmpz
end

mutable struct FlintQQiField <: Nemo.Field
end

const QQi = FlintQQiField()

struct fmpqi <: FieldElem
num::fmpzi
den::fmpz
end

Loading