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 integer_ring(), rational_field() #1547

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RandomExtensions = "fb686558-2515-59ef-acaa-46db3789a887"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[compat]
AbstractAlgebra = "0.32.3"
AbstractAlgebra = "0.32.4"
Antic_jll = "~0.201.500"
Arb_jll = "~200.2300.000"
Calcium_jll = "~0.401.100"
Expand Down
4 changes: 4 additions & 0 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ end

const FlintZZ = ZZRing()

integer_ring() = ZZRing()

@doc zz_ring_doc
mutable struct ZZRingElem <: RingElem
d::Int
Expand Down Expand Up @@ -163,6 +165,8 @@ end

const FlintQQ = QQField()

rational_field() = FlintQQ

@doc qq_field_doc
mutable struct QQFieldElem <: FracElem{ZZRingElem}
num::Int
Expand Down
5 changes: 2 additions & 3 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export QQFieldElem, FlintQQ, fraction_field, Rational, QQField, height,
height_bits, isless, reconstruct, next_minimal, next_signed_minimal,
next_calkin_wilf, next_signed_calkin_wilf, dedekind_sum, harmonic,
bernoulli, bernoulli_cache, rand_bits, simplest_between, valuation!,
remove!
remove!, rational_field

###############################################################################
#
Expand Down Expand Up @@ -218,8 +218,7 @@ end
function show(io::IO, a::QQField)
if get(io, :supercompact, false)
# no nested printing
io = AbstractAlgebra.pretty(io)
print(io, AbstractAlgebra.LowercaseOff(), "QQ")
print(pretty(io), LowercaseOff(), "QQ")
else
# nested printing allowed, preferably supercompact
print(io, "Rational field")
Expand Down
5 changes: 2 additions & 3 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export ZZRingElem, FlintZZ, ZZRing, parent, show, convert, hash, bell,
one, zero, divexact, fits, sign, nbits, deepcopy, tdivpow2, fdivpow2,
cdivpow2, flog, clog, cmpabs, clrbit!, setbit!, combit!, crt,
crt_with_lcm, divisible, divisors, prime_divisors, divisor_lenstra,
fmodpow2,
fmodpow2, integer_ring,
gcdinv, gcd_with_cofactors,
is_probable_prime, jacobi_symbol, kronecker_symbol, remove, root, size,
isqrtrem, sqrtmod, trailing_zeros, divisor_sigma, euler_phi, fibonacci,
Expand Down Expand Up @@ -271,9 +271,8 @@ show(io::IO, x::ZZRingElem) = print(io, string(x))

function show(io::IO, a::ZZRing)
if get(io, :supercompact, false)
io = pretty(io)
# no nested printing
print(io, LowercaseOff(), "ZZ")
print(pretty(io), LowercaseOff(), "ZZ")
else
# nested printing allowed, preferably supercompact
print(io, "Integer ring")
Expand Down
13 changes: 13 additions & 0 deletions test/flint/fmpq-test.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Nemo: AbstractAlgebra.PrettyPrinting

function test_elem(R::QQField)
return rand_bits(ZZ, rand(0:100))//rand_bits(ZZ, rand(1:100))
end
Expand Down Expand Up @@ -538,3 +540,14 @@ end
@test b_copy == b
@test c_copy == c
end

@testset "QQFieldElem.printing" begin
@test FlintQQ === rational_field()
@test PrettyPrinting.detailed(FlintQQ) == "Rational field"
@test PrettyPrinting.oneline(FlintQQ) == "Rational field"
@test PrettyPrinting.supercompact(FlintQQ) == "QQ"

io = PrettyPrinting.pretty(IOBuffer())
print(IOContext(io, :supercompact => true), PrettyPrinting.Lowercase(), FlintQQ)
@test String(take!(io)) == "QQ"
end
14 changes: 13 additions & 1 deletion test/flint/fmpz-test.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Nemo: AbstractAlgebra.PrettyPrinting

function test_elem(R::ZZRing)
return rand_bits(ZZ, rand(0:100))
end

@testset "ZZFieldElem.conformance_tests" begin
@testset "ZZRingElem.conformance_tests" begin
test_Ring_interface_recursive(FlintZZ)
end

Expand Down Expand Up @@ -1371,3 +1373,13 @@ end
@test ncdivrem(ZZ(-6), ZZ(-4)) == (+2, +2)
end

@testset "ZZRingElem.printing" begin
@test FlintZZ === integer_ring()
@test PrettyPrinting.detailed(FlintZZ) == "Integer ring"
@test PrettyPrinting.oneline(FlintZZ) == "Integer ring"
@test PrettyPrinting.supercompact(FlintZZ) == "ZZ"

io = PrettyPrinting.pretty(IOBuffer())
print(IOContext(io, :supercompact => true), PrettyPrinting.Lowercase(), FlintZZ)
@test String(take!(io)) == "ZZ"
end
Loading