Skip to content

Commit

Permalink
Add some ring / field conformance tests
Browse files Browse the repository at this point in the history
... and fix some issues this revealed
  • Loading branch information
fingolfin committed Dec 19, 2024
1 parent 88eed80 commit 2a5446b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/LocalField/LocalField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ prime(K::LocalField) = prime(base_field(K))
#
################################################################################

base_ring_type(::Type{LocalField{S, T}}) where {S <: FieldElem, T <: LocalFieldParameter} = parent_type(S)

base_field_type(::Type{LocalField{S, T}}) where {S <: FieldElem, T <: LocalFieldParameter} = parent_type(S)

elem_type(::Type{LocalField{S, T}}) where {S <: FieldElem, T <: LocalFieldParameter} = LocalFieldElem{S, T}
Expand All @@ -47,8 +49,8 @@ elem_type(::Type{LocalField{S, T}}) where {S <: FieldElem, T <: LocalFieldParame
#
################################################################################

is_domain_type(::Type{S}) where S <: LocalField = true
is_exact_type(::Type{S}) where S <: LocalField = false
is_domain_type(::Type{<: LocalFieldElem}) = true
is_exact_type(::Type{<: LocalFieldElem}) = false
isfinite(K::LocalField) = isfinite(base_field(K))

################################################################################
Expand Down Expand Up @@ -130,6 +132,10 @@ end
#
################################################################################

function base_ring(L::LocalField)
return base_ring(defining_polynomial(L))
end

function base_field(L::LocalField)
return base_ring(defining_polynomial(L))
end
Expand Down
8 changes: 7 additions & 1 deletion src/Misc/RelFiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ end

base_field_type(::Type{RelFinField{S}}) where S = parent_type(S)

base_field(F::RelFinField{S}) where S= base_ring(F.defining_polynomial)::parent_type(S)
base_field(F::RelFinField{S}) where S = base_ring(F.defining_polynomial)::parent_type(S)

base_ring_type(::Type{RelFinField{S}}) where S = parent_type(S)

base_ring(F::RelFinField{S}) where S = base_ring(F.defining_polynomial)::parent_type(S)

characteristic(F::RelFinField) = characteristic(base_field(F))

Expand Down Expand Up @@ -141,6 +145,8 @@ iszero(x::RelFinFieldElem) = iszero(x.data)
isone(x::RelFinFieldElem) = isone(x.data)
is_unit(x::RelFinFieldElem) = !iszero(x)

hash(x::RelFinFieldElem, h::UInt) = hash(x.data, h)

==(x::RelFinFieldElem{S, T}, y::RelFinFieldElem{S, T}) where {S, T} = x.data == y.data

coeff(a::RelFinFieldElem, i::Int) = coeff(a.data, i)
Expand Down
2 changes: 2 additions & 0 deletions src/NumField/Embedded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ base_ring_type(::Type{<:EmbeddedNumField}) = QQField

data(x::EmbeddedNumFieldElem) = x.element

characteristic(::EmbeddedNumField) = 0

function embedded_field(K::SimpleNumField, i::NumFieldEmb)
@assert number_field(i) === K
E = EmbeddedNumField(K, i)
Expand Down
4 changes: 4 additions & 0 deletions src/NumField/NfRel/NfRel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ order_type(::Type{RelSimpleNumField{T}}) where {T} = RelNumFieldOrder{T, fractio

@inline base_field(a::RelSimpleNumField{T}) where {T} = a.base_ring::parent_type(T)

base_ring(a::RelSimpleNumField{T}) where {T} = a.base_ring::parent_type(T)

base_ring_type(::Type{RelSimpleNumField{T}}) where {T} = parent_type(T)

@inline data(a::RelSimpleNumFieldElem) = a.data

@inline parent(a::RelSimpleNumFieldElem{T}) where {T} = a.parent::RelSimpleNumField{T}
Expand Down
22 changes: 22 additions & 0 deletions test/LocalField/LocalField.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# the following is copied from the `random_elem` function
function test_elem(L::Union{QadicField, Hecke.LocalField})
b = basis(L)
n = degree(L)
r = [rand(1:5*n) for i in 1:n] # Choose small coordinates
return sum( [r[i]*b[i] for i in 1:n])
end

# TODO/FIXME: implement isapprox so we can get rid of the following HACK:
function equality(a::T, b::T) where {T <: Union{QadicFieldElem, Hecke.LocalFieldElem}}
return a == b
end

@testset "LocalField" begin

@testset "Creation" begin
Expand All @@ -8,6 +21,9 @@
@test characteristic(K) == 0
@test prime(K) == 2

test_Field_interface(K)
#test_Field_interface_recursive(K) # TODO/FIXME: does not work due to missing isapprox

Kt, t = polynomial_ring(K, "t")
g = t^2+2
L, b = local_field(g, "b", Hecke.EisensteinLocalField, check = false)
Expand Down Expand Up @@ -40,8 +56,14 @@

@testset "Norm" begin
K = qadic_field(3, 4, precision = 10)[1]
test_Field_interface(K)
#test_Field_interface_recursive(K) # TODO/FIXME: does not work due to missing isapprox

Kx, x = polynomial_ring(K, "x")
L = eisenstein_extension(x^20+3)[1]
test_Field_interface(L)
#test_Field_interface_recursive(L) # TODO/FIXME: does not work due to missing isapprox

b = @inferred basis(L)
for i = 1:10
r = 1+2*uniformizer(L)^i * sum([rand(1:10)*b[i] for i in 1:5])
Expand Down
7 changes: 7 additions & 0 deletions test/Misc/RelFinField.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@testset "RelFinField" begin

@testset "conformance" begin
F = Native.finite_field(3, 3, cached = false)[1]
x = polynomial_ring(F, "x", cached = false)[2]
K, gK = @inferred Native.finite_field(x^2+1, :a)
test_Field_interface_recursive(K)
end

@testset "Basic properties" begin
F = Native.finite_field(3, 3, cached = false)[1]
x = polynomial_ring(F, "x", cached = false)[2]
Expand Down
16 changes: 16 additions & 0 deletions test/NfRel/NfRel.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
function test_elem(K::RelSimpleNumField)
return rand(K, -10:10)
end

@testset "RelSimpleNumField" begin

@testset "conformance" begin
Qx, x = QQ["x"]
f = x^2 + 12x - 92
K, a = number_field(f, "a")
Ky, y = K["y"]

L, b = number_field(y^2 + y + 1, "b")

test_Field_interface_recursive(L)
end

@testset "is_subfield" begin
Qx, x = QQ["x"]
f = x^2 + 12x - 92
Expand Down
2 changes: 1 addition & 1 deletion test/NumField/Embedded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_elem(E::Hecke.EmbeddedNumField) = E(rand(number_field(E), -10:10))
@test sprint(show, a) isa String
@test sprint(show, "text/plain", a) isa String
@test E([1, 2]) == 1 + 2*a
test_Ring_interface(E)
test_Field_interface(E)
# trigger expressify
Et, t = E["t"]
@test sprint(show, a * t) isa String
Expand Down

0 comments on commit 2a5446b

Please sign in to comment.