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

Fixes for zero algebra #1321

Merged
merged 1 commit into from
Dec 13, 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
11 changes: 9 additions & 2 deletions src/AlgAss/AbsAlgAss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ function _dec_com_given_idempotents(A::AbsAlgAss{T}, v::Vector) where {T}
end

function _dec_com_gen(A::AbsAlgAss{T}) where {T <: FieldElem}
if dim(A) == 0
# The zero-dimensional algebra is the zero ring, which is semisimple, but not simple
# It has *no* simple components.
A.is_simple = -1
return Tuple{AlgAss{T}, morphism_type(AlgAss{T}, typeof(A))}[]
end

if dim(A) == 1
A.is_simple = 1
B, mB = AlgAss(A)
Expand Down Expand Up @@ -1550,10 +1557,10 @@ function product_of_components_with_projection(A::AbsAlgAss, a::Vector{Int})
algs = [dec[i][1] for i in a]
injs = [dec[i][2] for i in a]
r = length(a)
B, injstoB = direct_product(algs)
B, injstoB = direct_product(base_ring(A), algs)
imgs = elem_type(B)[]
for b in basis(A)
push!(imgs, sum(injstoB[i](injs[i]\b) for i in 1:r))
push!(imgs, sum(injstoB[i](injs[i]\b) for i in eachindex(a); init = zero(B)))
end
p = hom(A, B, basis_matrix(imgs))
_transport_refined_wedderburn_decomposition_forward(p)
Expand Down
34 changes: 26 additions & 8 deletions src/AlgAss/AlgAss.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export associative_algebra, is_split, multiplication_table, restrict_scalars, center
export associative_algebra, is_split, multiplication_table, restrict_scalars, center, zero_algebra

add_assertion_scope(:AlgAss)

Expand Down Expand Up @@ -55,7 +55,6 @@ If the function returns $M$ and the basis of $A$ is $e_1,\dots, e_n$ then
it holds $e_i \cdot e_j = \sum_k M[i, j, k] \cdot e_k$.
"""
function multiplication_table(A::AlgAss; copy::Bool = true)
@assert !iszero(A)
if copy
return deepcopy(A.mult_table)
else
Expand Down Expand Up @@ -129,12 +128,18 @@ function find_one(A::AlgAss)
return true, one
end

function _zero_algebra(R::Ring)
raw"""
zero_algebra(R::Ring) -> AlgAss

Return the zero ring as an associative $R$-algebra.
"""
function zero_algebra(R::Ring)
A = AlgAss{elem_type(R)}(R)
A.iszero = true
A.is_commutative = 1
A.has_one = true
A.one = elem_type(R)[]
A.mult_table = Array{elem_type(R), 3}(undef, 0, 0, 0)
return A
end

Expand All @@ -148,9 +153,11 @@ raw"""
associative_algebra(R::Ring, mult_table::Array{<:Any, 3}; check::Bool = true) = AlgAss(R, mult_table; check)
associative_algebra(R::Ring, mult_table::Array{T, 3}, one::Vector{T}; check::Bool = true) where T = AlgAss(R, mult_table, one; check)

function AlgAss(R::Ring, mult_table::Array{T, 3}, one::Vector{T}; check::Bool = get_assertion_level(:AlgAss)>0) where {T}
function AlgAss(R::Ring, mult_table::Array{T, 3}, one::Vector{T}; check::Bool = get_assertion_level(:AlgAss) > 0) where {T}
@req all(isequal(size(mult_table, 1)), size(mult_table)) "Multiplication must have dimensions have same length"

if size(mult_table, 1) == 0
return _zero_algebra(R)
return zero_algebra(R)
end
A = AlgAss{T}(R, mult_table, one)
if check
Expand All @@ -160,9 +167,10 @@ function AlgAss(R::Ring, mult_table::Array{T, 3}, one::Vector{T}; check::Bool =
return A
end

function AlgAss(R::Ring, mult_table::Array{T, 3}; check::Bool = get_assertion_level(:AlgAss)>0) where {T}
function AlgAss(R::Ring, mult_table::Array{T, 3}; check::Bool = get_assertion_level(:AlgAss) > 0) where {T}
@req all(isequal(size(mult_table, 1)), size(mult_table)) "Multiplication must have dimensions have same length"
if size(mult_table, 1) == 0
return _zero_algebra(R)
return zero_algebra(R)
end
A = AlgAss{T}(R)
A.mult_table = mult_table
Expand Down Expand Up @@ -1404,7 +1412,17 @@ Returns the algebra $A = A_1 \times \cdots \times A_k$. `task` can be
":sum", ":prod", ":both" or ":none" and determines which canonical maps
are computed as well: ":sum" for the injections, ":prod" for the projections.
"""
function direct_product(algebras::Vector{ <: AlgAss{T} }; task::Symbol = :sum) where T
function direct_product(algebras::Vector{<: AlgAss{T}}; task::Symbol = :sum) where T
@req !isempty(algebras) "Must be at least one algebra for direct product (or specifiy the field)"
return direct_product(algebras..., task = task)
end

function direct_product(K, algebras::Vector{<: AlgAss{T}}; task::Symbol = :sum) where T
if length(algebras) == 0
mt = zeros(K, 0, 0, 0)
A = AlgAss(K, mt; check = false)
return A, morphism_type(eltype(algebras), typeof(A))[]
end
return direct_product(algebras..., task = task)
end

Expand Down
2 changes: 1 addition & 1 deletion src/AlgAssAbsOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _algebra(a::AlgAssAbsOrdIdl) = algebra(a)

# The basis matrix is (should be) in lowerleft HNF, so if the upper left corner
# is not zero, then the matrix has full rank.
is_full_lattice(a::AlgAssAbsOrdIdl) = !iszero(basis_matrix(a, copy = false)[1, 1])
is_full_lattice(a::AlgAssAbsOrdIdl) = dim(algebra(a)) == 0 || !iszero(basis_matrix(a, copy = false)[1, 1])

# Whether I is equal to order(I)
function isone(I::AlgAssAbsOrdIdl)
Expand Down
5 changes: 4 additions & 1 deletion src/AlgAssAbsOrd/Order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ rand(rng::AbstractRNG, O::AlgAssAbsOrd, n::Integer) = rand(rng, make(O, n))
################################################################################

function basis_matrix(A::Vector{S}, ::Type{FakeFmpqMat}) where {S <: AbsAlgAssElem{QQFieldElem}}
if length(A) == 0
return M = FakeFmpqMat(zero_matrix(FlintZZ, 0, 0), ZZ(1))
end
@assert length(A) > 0
n = length(A)
d = dim(parent(A[1]))
Expand Down Expand Up @@ -820,7 +823,7 @@ function MaximalOrder(O::AlgAssAbsOrd{S, T}) where { S <: AlgGrp, T <: AlgGrpEle
end

function _denominator_of_mult_table(A::AbsAlgAss{QQFieldElem})
l = denominator(multiplication_table(A, copy = false)[1, 1, 1])
l = one(ZZ)
for i = 1:dim(A)
for j = 1:dim(A)
for k = 1:dim(A)
Expand Down
6 changes: 6 additions & 0 deletions src/AlgAssAbsOrd/PIP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ end

function _unit_group_generators_maximal_simple(M)
A = algebra(M)
if dim(A) == 0
return [zero(A)]
end
ZA, ZAtoA = _as_algebra_over_center(A)
if dim(ZA) == 1
# this is a field
Expand Down Expand Up @@ -2216,6 +2219,9 @@ function __unit_reps_simple(M, F)
B = algebra(M)
@vprintln :PIP _describe(B)
@vprintln :PIP "Computing generators of the maximal order"
if dim(B) == 0
return [zero(B)]
end
UB = _unit_group_generators_maximal_simple(M)
Q, MtoQ = quo(M, F)
for u in UB
Expand Down
6 changes: 3 additions & 3 deletions src/AlgAssAbsOrd/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

function AlgAssAbsOrdElem{S, T}(O::AlgAssAbsOrd{S, T}, arr::Vector{ZZRingElem}) where {S, T}
z = new{S, T}()
z.elem_in_algebra = dot(O.basis_alg, arr)
z.elem_in_algebra = degree(O) == 0 ? zero(algebra(O)) : dot(O.basis_alg, arr)
z.coordinates = arr
z.parent = O
z.has_coord = true
Expand Down Expand Up @@ -198,7 +198,7 @@
r.full_rank = (i == 0) ? 1 : -1
r.rank = n - i
if r.full_rank == 1
r.eldiv_mul = reduce(lcm, diagonal(numerator(M, copy = false)), init = one(ZZ))
r.eldiv_mul = reduce(*, diagonal(numerator(M, copy = false)), init = one(ZZ))
else
r.eldiv_mul = zero(ZZ)
end
Expand All @@ -210,7 +210,7 @@
r.rank = i - 1
r.full_rank = (i == n + 1) ? 1 : -1
if r.full_rank == 1
r.eldiv_mul = reduce(lcm, diagonal(numerator(M, copy = false)), init = one(ZZ))
r.eldiv_mul = reduce(*, diagonal(numerator(M, copy = false)), init = one(ZZ))

Check warning on line 213 in src/AlgAssAbsOrd/Types.jl

View check run for this annotation

Codecov / codecov/patch

src/AlgAssAbsOrd/Types.jl#L213

Added line #L213 was not covered by tests
else
r.eldiv_mul = zero(ZZ)
end
Expand Down
4 changes: 4 additions & 0 deletions src/NumFieldOrd/NfOrd/NfOrd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ equation_order(M::NfAbsOrd) = equation_order(nf(M))
# Via extends one may supply an order which will then be extended by the elements
# in elt.
function _order(K::S, elt::Vector{T}; cached::Bool = true, check::Bool = true, extends = nothing) where {S <: Union{NumField{QQFieldElem}, AbsAlgAss{QQFieldElem}}, T}
if dim(K) == 0
return Order(K, FakeFmpqMat(zero_matrix(ZZ, 0, 0), ZZ(1)), cached = cached, check = false)::order_type(K)
end

elt = unique(elt)
n = dim(K)
is_comm = is_commutative(K)
Expand Down
20 changes: 20 additions & 0 deletions test/AlgAss/AbsAlgAss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,24 @@
Qx, x = QQ["x"]
@test is_etale(AlgAss(x))
@test !is_etale(AlgAss(x^2))

# zero algebra

K, = quadratic_field(-1)
for k in (K, QQ)
A = zero_algebra(k)
@test !is_simple(A)
@test length(decompose(A)) == 0
@test is_semisimple(A)
B, m = direct_product(k, typeof(A)[]; task = :sum)
@test is_zero(B) && dim(B) == 0
@test length(m) == 0
end

# product of components

A = group_algebra(QQ, small_group(2, 1))
C, p = Hecke.product_of_components_with_projection(A, Int[])
@test is_zero(C) && dim(C) == 0
@test domain(p) === A && codomain(p) === C && is_one(p(one(A)))
end
8 changes: 8 additions & 0 deletions test/AlgAss/AlgAss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ end

test_alg_morphism_char_p(B, A, BtoA)

# zero algebra

A = associative_algebra(QQ, Array{QQFieldElem}(undef, 0, 0, 0))
@test dim(A) == 0
A = associative_algebra(QQ, Array{QQFieldElem}(undef, 0, 0, 0), QQFieldElem[])
@test dim(A) == 0
end

# n = dim(A)^2 = dim(B)^2
Expand Down Expand Up @@ -226,4 +232,6 @@ end
@test is_split(A, Ps[2])
end

A = zero_algebra(QQ)
@test_throws ArgumentError direct_product(typeof(A)[])
end
7 changes: 7 additions & 0 deletions test/AlgAssAbsOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,11 @@
J = typeof(I)(A, FakeFmpqMat(identity_matrix(QQ, 4)))
@test J * J == typeof(I)(A, FakeFmpqMat(48 * identity_matrix(QQ, 4)))

# zero algebra

A = zero_algebra(QQ)
O = Order(A, elem_type(A)[])
I = 1 * O
@test Hecke.is_full_lattice(I)

end
11 changes: 11 additions & 0 deletions test/AlgAssAbsOrd/Order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,15 @@
OO = Hecke._order(B, [BtoA\A(matrix(K, [ d 0 0; 0 0 0; 0 0 0 ]))], extends = O)
@test discriminant(OO) == ZZ(2304)^9
end

# zero algebra

A = zero_algebra(QQ)
B = basis_matrix(elem_type(A)[], FakeFmpqMat)
@test (nrows(B), ncols(B)) == (0, 0)
M = maximal_order(A)
@test is_maximal(M)
O = Order(A, [zero(A)])
@test is_maximal(O)

end
9 changes: 9 additions & 0 deletions test/AlgAssAbsOrd/PIP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@
R, = quo(OK, I)
mats = Hecke._write_as_product_of_elementary_matrices(N, R)
@test map_entries(R, reduce(*, mats)) == map_entries(R, N)

# zero algebra
A = zero_algebra(QQ)
M = maximal_order(A)
F = 1 * M
reps = Hecke.__unit_reps_simple(M, F)
@test length(reps) <= 1
reps = Hecke._unit_group_generators_maximal_simple(M)
@test length(reps) <= 1
end
Loading