Skip to content
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
32 changes: 25 additions & 7 deletions src/NumField/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,34 @@ coefficientwise.
"""
function norm(f::PolyRingElem{<: NumFieldElem})
K = base_ring(f)
P = polynomial_to_power_sums(f, degree(f)*degree(K))
PQ = elem_type(base_field(K))[tr(x) for x in P]
return power_sums_to_polynomial(PQ)
n, ff = remove(f, gen(parent(f)))
if degree(ff) > 0
P = polynomial_to_power_sums(ff, degree(ff)*degree(K))
PQ = elem_type(base_field(K))[tr(x) for x in P]
N = power_sums_to_polynomial(PQ)
else
k = base_field(K)
kt, = polynomial_ring(k, :t; cached = false)
N = kt(norm(constant_coefficient(ff)))
end
(n > 0) && (N = shift_left(N, n*degree(K)))
return N
end

function norm(f::PolyRingElem{<:NumFieldElem}, k::NumField)
K = base_ring(f)
P = polynomial_to_power_sums(f, degree(f)*degree(K))
PQ = elem_type(base_field(K))[tr(x, k) for x in P]
return power_sums_to_polynomial(PQ)
n, ff = remove(f, gen(parent(f)))
if degree(ff) > 0
P = polynomial_to_power_sums(ff, degree(ff)*degree(K))
PQ = elem_type(base_field(K))[tr(x, k) for x in P]
N = power_sums_to_polynomial(PQ)
else
k = base_field(K)
kt, = polynomial_ring(k, :t; cached = false)
N = kt(norm(constant_coefficient(ff), k))
end
(n > 0) && (N = shift_left(N, n*degree(K)))
return N
end

norm(a::QQPolyRingElem) = a
Expand Down Expand Up @@ -686,7 +704,7 @@ end

absolute_minpoly(a::AbsSimpleNumFieldElem) = minpoly(a)

absolute_minpoly(a::AbsNonSimpleNumField) = minpoly(a)
absolute_minpoly(a::AbsNonSimpleNumFieldElem) = minpoly(a)

absolute_minpoly(a::T) where T <: Union{RelNonSimpleNumFieldElem, RelSimpleNumFieldElem} = minpoly(a, QQ)

Expand Down
32 changes: 32 additions & 0 deletions test/NumField/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,35 @@ let # issue #2079, Hanselmann
f = L(b) * u^2 + L(c)
@test length(roots(f)) == 2
end

let
Qx, x = QQ["x"]
K, a = number_field([x^2 - 2, x^2 - 3])
@test absolute_minpoly(a[1])(x) == x^2 - 2
end

let # norm of polynomials
QQ, = rationals_as_number_field()
Qx, xQ = QQ["x"]
F, _ = number_field(xQ^2-2)
Fx, xF = F["x"]
d = degree(F)
@test norm(xF)(xQ) == xQ^(d)
for i in 1:11
@test norm(xF^i + xF^(i+1))(xQ) == xQ^(i*d) * norm(xF+1)(xQ)
end
end

let
QQ, = rationals_as_number_field()
Qx, xQ = QQ["x"]
F, a = number_field(xQ^2 - 2)
Fx, xF = F["x"]
L, z = number_field(xF^2 - 3)
Lt, t = L["t"]
d = degree(F)
@test norm(xF, F)(xQ) == xQ^(d)
for i in 1:11
@test norm(t^i + t^(i+1), F)(xF) == xF^(i*d) * norm(t + 1, F)(xF)
end
end
Loading