diff --git a/src/Hecke.jl b/src/Hecke.jl index 4e82997c2b..d5de31fd7e 100644 --- a/src/Hecke.jl +++ b/src/Hecke.jl @@ -556,6 +556,8 @@ order_type(T::DataType) = throw(MethodError(order_type, (T,))) embedding_type(x) = embedding_type(typeof(x)) embedding_type(T::DataType) = throw(MethodError(embedding_type, (T,))) +base_field_type(x) = base_field_type(typeof(x)) +base_field_type(T::DataType) = throw(MethodError(base_field_type, (T,))) ################################################################################ # diff --git a/src/LocalField/LocalField.jl b/src/LocalField/LocalField.jl index 20ccf69de5..30b1b6688d 100644 --- a/src/LocalField/LocalField.jl +++ b/src/LocalField/LocalField.jl @@ -37,22 +37,20 @@ prime(K::LocalField) = prime(base_field(K)) # ################################################################################ -base_field_type(K::LocalField{S, T}) where {S <: FieldElem, T <: LocalFieldParameter} = parent_type(S) +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} -dense_poly_type(K::LocalField{S, T}) where {S <: FieldElem, T <: LocalFieldParameter} = Generic.Poly{LocalFieldElem{S, T}} -dense_poly_type(::Type{LocalField{S, T}}) where {S <: FieldElem, T <: LocalFieldParameter} = Generic.Poly{LocalFieldElem{S, T}} - ################################################################################ # # Basic predicates # ################################################################################ -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)) ################################################################################ @@ -134,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 diff --git a/src/Map/NumField.jl b/src/Map/NumField.jl index 24275814cb..64848a6a80 100644 --- a/src/Map/NumField.jl +++ b/src/Map/NumField.jl @@ -182,13 +182,9 @@ end # ################################################################################ -base_field_type(::AbsSimpleNumField) = QQField +base_field_type(::Type{AbsSimpleNumField}) = QQField -base_field_type(::AbsNonSimpleNumField) = QQField - -base_field_type(::RelSimpleNumField{T}) where {T} = parent_type(T) - -base_field_type(::RelNonSimpleNumField{T}) where {T} = parent_type(T) +base_field_type(::Type{AbsNonSimpleNumField}) = QQField base_field_type(::Type{RelNonSimpleNumField{T}}) where {T} = parent_type(T) diff --git a/src/Misc/RelFiniteField.jl b/src/Misc/RelFiniteField.jl index 2c030a6177..a99b16b60c 100644 --- a/src/Misc/RelFiniteField.jl +++ b/src/Misc/RelFiniteField.jl @@ -56,7 +56,13 @@ function defining_polynomial(F::RelFinField{T}) where T return F.defining_polynomial::dense_poly_type(T) end -base_field(F::RelFinField{S}) where S= base_ring(F.defining_polynomial)::parent_type(S) +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_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)) @@ -139,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) diff --git a/src/NumField/Embedded.jl b/src/NumField/Embedded.jl index 9612a79154..5b5ee17116 100644 --- a/src/NumField/Embedded.jl +++ b/src/NumField/Embedded.jl @@ -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) diff --git a/src/NumField/NfRel/NfRel.jl b/src/NumField/NfRel/NfRel.jl index cae1046b17..ad9be6e1aa 100644 --- a/src/NumField/NfRel/NfRel.jl +++ b/src/NumField/NfRel/NfRel.jl @@ -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} diff --git a/test/LocalField/LocalField.jl b/test/LocalField/LocalField.jl index 0cc4d11468..381203bd8d 100644 --- a/test/LocalField/LocalField.jl +++ b/test/LocalField/LocalField.jl @@ -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 @@ -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) @@ -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]) diff --git a/test/Misc/RelFinField.jl b/test/Misc/RelFinField.jl index 6794fa39d8..ed15344b1e 100644 --- a/test/Misc/RelFinField.jl +++ b/test/Misc/RelFinField.jl @@ -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] diff --git a/test/NfRel/NfRel.jl b/test/NfRel/NfRel.jl index 6917f23377..a1199dd816 100644 --- a/test/NfRel/NfRel.jl +++ b/test/NfRel/NfRel.jl @@ -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 diff --git a/test/NumField/Embedded.jl b/test/NumField/Embedded.jl index 9989441a33..5f31a59508 100644 --- a/test/NumField/Embedded.jl +++ b/test/NumField/Embedded.jl @@ -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