Skip to content

Commit

Permalink
fix: adjust to new residue_ring interface
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Jan 25, 2024
1 parent 6fab2d3 commit 575d760
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
10 changes: 7 additions & 3 deletions src/number/n_Zn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,16 @@ promote_rule(C::Type{n_Zn}, ::Type{n_Z}) = n_Zn

(R::Nemo.ZZModRing)(n::n_Zn) = R(BigInt(n))

lift(n::n_Zn) = ZZ(BigInt(n))

###############################################################################
#
# SingularResidueRing constructor
#
###############################################################################

residue_ring(R::Integers, a::Int; cached=true) = N_ZnRing(BigInt(a), cached)

residue_ring(R::Integers, a::BigInt; cached=true) = N_ZnRing(a, cached)
function residue_ring(R::Integers, a::Integer; cached=true)
S = N_ZnRing(BigInt(a), cached)
f = Generic.EuclideanRingResidueMap(R, S)
return S, f
end
2 changes: 1 addition & 1 deletion test/number-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
testrings = [
(n_Z, Integers, Union{}, ZZ),
(n_Q, Rationals, ZZ, QQ),
(n_Zn, N_ZnRing, ZZ, residue_ring(ZZ, 7)),
(n_Zn, N_ZnRing, ZZ, residue_ring(ZZ, 7)[1]),
(n_Zp, N_ZpField, Union{}, Fp(7)),
(n_GF, N_GField, Union{}, FiniteField(7, 2, "x")[1]),
(n_transExt, N_FField, QQ, FunctionField(QQ, ["a", "b", "c"])[1]),
Expand Down
41 changes: 23 additions & 18 deletions test/number/n_Zn-test.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
@testset "n_Zn.constructors" begin
F = residue_ring(ZZ, 8)
F1 = residue_ring(ZZ, 8)
F2 = residue_ring(ZZ, 8, cached = false)
F, f = residue_ring(ZZ, 8)
F1, = residue_ring(ZZ, 8)
F2, = residue_ring(ZZ, 8, cached = false)

@test f(ZZ(1)) == F(1)
@test f(preimage(f, f(ZZ(1)))) == F(1)

@test domain(f) === ZZ
@test codomain(f) === F
@test F isa Singular.Ring
@test F1 isa Singular.Ring
@test F2 isa Singular.Ring
@test F == F1
@test F != F2
@test F1 != F2

F = residue_ring(ZZ, BigInt(10)^50)
F1 = residue_ring(ZZ, BigInt(10)^50)
F2 = residue_ring(ZZ, BigInt(10)^50, cached = false)
F, = residue_ring(ZZ, BigInt(10)^50)
F1, = residue_ring(ZZ, BigInt(10)^50)
F2, = residue_ring(ZZ, BigInt(10)^50, cached = false)

@test F isa Singular.Ring
@test F1 isa Singular.Ring
Expand All @@ -26,15 +31,15 @@
end

@testset "n_Zn.printing" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test string(R(3)) == "3"

@test sprint(show, "text/plain", (R(3))) == "3"
end

@testset "n_Zn.manipulation" begin
R = residue_ring(ZZ, 6)
R, = residue_ring(ZZ, 6)

@test isone(one(R))
@test iszero(zero(R))
Expand All @@ -55,18 +60,18 @@ end
end

@testset "n_Zn.unary_ops" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test -R(3) == R(2)
@test -R() == R()

R = residue_ring(ZZ, BigInt(10)^40)
R, = residue_ring(ZZ, BigInt(10)^40)
@test iszero(R(10)^40)

end

@testset "n_Zn.binary_ops" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

a = R(2)
b = R(3)
Expand All @@ -77,14 +82,14 @@ end
end

@testset "n_Zn.comparison" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test R(2) == R(2)
@test isequal(R(2), R(2))
end

@testset "n_Zn.ad_hoc_comparison" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test R(2) == 2
@test 2 == R(2)
Expand All @@ -96,14 +101,14 @@ end
end

@testset "n_Zn.powering" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test R(2)^10 == R(4)
@test_throws DomainError R(2)^-rand(1:99)
end

@testset "n_Zn.exact_division" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test_throws ErrorException inv(zero(R))
@test_throws ErrorException divexact(one(R), zero(R))
Expand All @@ -113,14 +118,14 @@ end
end

@testset "n_Zn.gcd_lcm" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)

@test gcd(R(2), R(3)) == R(1)
@test gcd(R(0), R(0)) == R(0)
end

@testset "n_Zn.extended_gcd" begin
R = residue_ring(ZZ, 6)
R, = residue_ring(ZZ, 6)

g, s, t = gcdx(R(2), R(4))

Expand All @@ -132,7 +137,7 @@ end
end

@testset "n_Zn.Polynomials" begin
R = residue_ring(ZZ, 5)
R, = residue_ring(ZZ, 5)
S, x = Nemo.polynomial_ring(R, "x")

f = 1 + 2x + 3x^2
Expand Down
4 changes: 2 additions & 2 deletions test/poly/poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
@test length(string(3x^2 + 2x + 1)) > 3
@test length(sprint(show, "text/plain", 3x^2 + 2x + 1)) > 3

R, (x, ) = polynomial_ring(residue_ring(ZZ, 5), ["x", ])
R, (x, ) = polynomial_ring(residue_ring(ZZ, 5)[1], ["x", ])

@test length(string(3x^2 + 2x + 1)) > 3
@test length(sprint(show, "text/plain", 3x^2 + 2x + 1)) > 3
Expand Down Expand Up @@ -191,7 +191,7 @@ end

@test pol == r

R, (x, ) = polynomial_ring(residue_ring(ZZ, 6), ["x", ])
R, (x, ) = polynomial_ring(residue_ring(ZZ, 6)[1], ["x", ])

@test characteristic(R) == 6

Expand Down

0 comments on commit 575d760

Please sign in to comment.