Skip to content

Commit 4510adc

Browse files
committed
More tests and fixes
1 parent 44f230e commit 4510adc

File tree

4 files changed

+62
-27
lines changed

4 files changed

+62
-27
lines changed

src/QuadForm.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ include("QuadForm/MassQuad.jl")
5151
# Close vectors
5252
include("QuadForm/CloseVectors.jl")
5353

54-
# indefinite LLL
54+
# indefinite LLL
5555
include("QuadForm/indefiniteLLL.jl")
5656

5757
# Functionality for IO with Hecke/Magma

src/QuadForm/Morphism.jl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ function init_vector_sums(C::ZLatAutoCtx{S1, S2, S3}, depth::Int) where {S1, S2,
584584
if depth == -1
585585
depth = round(Int, C.dim/10)
586586
end
587+
@assert depth >= 0 "`depth` must be non-negative"
587588
C.depth = depth
588589

589590
small = S1 <: Int
@@ -717,6 +718,7 @@ function bacher_polynomial(C::ZLatAutoCtx{T}, I::Int, S::T) where T
717718
end
718719

719720
function init_bacher_polynomials(C::ZLatAutoCtx{T}, depth::Int) where T
721+
@assert depth >= 0 "`bacher_depth` must be non-negative"
720722
C.bacher_depth = depth
721723
C.bacher_polys = Vector{BacherPoly{T}}(undef, depth)
722724
for i in 1:depth
@@ -1371,7 +1373,7 @@ end
13711373
# allowing overflows via Di/Do and only verify a positive result with ZZRingElem
13721374
# via Ci/Co.
13731375
function cand(candidates::Vector{Int}, I::Int, x::Vector{Int}, Ci::ZLatAutoCtx{ZZRingElem}, Co::ZLatAutoCtx{ZZRingElem}, Di::ZLatAutoCtx{Int}, Do::ZLatAutoCtx{Int})
1374-
if _cand(candidates, I, x, Di, Do)
1376+
if _cand(candidates, I, x, Di, Do, true)
13751377
# _cand with Integers returned true, so we have to verify the result with
13761378
# ZZRingElem
13771379
return _cand(candidates, I, x, Ci, Co)
@@ -1382,7 +1384,7 @@ end
13821384
# If the short vectors fit in Int, the last arguments (Di/Do) are ignored.
13831385
cand(candidates::Vector{Int}, I::Int, x::Vector{Int}, Ci::ZLatAutoCtx{Int}, Co::ZLatAutoCtx{Int}, Di::ZLatAutoCtx, Do::ZLatAutoCtx) = _cand(candidates, I, x, Ci, Co)
13841386

1385-
function _cand(candidates::Vector{Int}, I::Int, x::Vector{Int}, Ci::ZLatAutoCtx{S, T, U}, Co::ZLatAutoCtx{S, T, U}) where {S, T, U}
1387+
function _cand(candidates::Vector{Int}, I::Int, x::Vector{Int}, Ci::ZLatAutoCtx{S, T, U}, Co::ZLatAutoCtx{S, T, U}, overflows::Bool = false) where {S, T, U}
13861388
dep = Ci.depth
13871389
use_vector_sums = (I > 1 && dep > 0)
13881390
dim = Hecke.dim(Ci)
@@ -1509,11 +1511,21 @@ function _cand(candidates::Vector{Int}, I::Int, x::Vector{Int}, Ci::ZLatAutoCtx{
15091511

15101512
if use_vector_sums
15111513
sign = false
1512-
if !is_normalized(scpvec)
1513-
neg!(scpvec)
1514-
sign = true
1514+
# If we work with Int's allowing overflows we can't trust the sign anymore
1515+
if overflows
1516+
k = get(comb.scpcombs.lookup, scpvec, 0)
1517+
if k == 0
1518+
neg!(scpvec)
1519+
sign = true
1520+
k = get(comb.scpcombs.lookup, scpvec, 0)
1521+
end
1522+
else
1523+
if !is_normalized(scpvec)
1524+
neg!(scpvec)
1525+
sign = true
1526+
end
1527+
k = get(comb.scpcombs.lookup, scpvec, 0)
15151528
end
1516-
k = get(comb.scpcombs.lookup, scpvec, 0)
15171529
is0 = is_zero(scpvec)
15181530
if k > 0
15191531
if !is0
@@ -1933,7 +1945,7 @@ function isometry(Ci::ZLatAutoCtx{SS, T, U}, Co::ZLatAutoCtx{SS, T, U}) where {S
19331945
if found
19341946
ISO = matgen(x, d, Ci.per, Co.V)
19351947
for k in 1:length(Ci.G)
1936-
ISO * Co.G[k] * ISO' == Ci.G[k]
1948+
ISO * Co.G[k] * transpose(ISO) == Ci.G[k]
19371949
end
19381950
return true, ISO
19391951
else
@@ -2418,10 +2430,13 @@ function _make_small(C::ZLatAutoCtx{ZZRingElem})
24182430
for i in 1:length(C.v)
24192431
D.v[i] = [ _int_vector_with_overflow(M, tmp) for M in C.v[i] ]
24202432
end
2421-
D.per = copy(C.per)
2422-
D.fp = copy(C.fp)
2423-
D.fp_diagonal = copy(C.fp_diagonal)
2424-
D.std_basis = copy(C.std_basis)
2433+
2434+
if isdefined(C, :per)
2435+
D.per = copy(C.per)
2436+
D.fp = copy(C.fp)
2437+
D.fp_diagonal = copy(C.fp_diagonal)
2438+
D.std_basis = copy(C.std_basis)
2439+
end
24252440

24262441
if isdefined(C, :scpcomb)
24272442
D.scpcomb = Vector{SCPComb{Int, Vector{Int}}}(undef, length(C.scpcomb))

test/QuadForm/Lattices.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@
162162
R = @inferred fixed_ring(L)
163163
@test R == ZZ
164164
@test R != base_ring(base_ring(L))
165+
166+
# Use ZZRingElem in the automorphism group computation (issue 1054)
167+
Qx, x = FlintQQ["x"]
168+
K, a = number_field(x^2 + 1, "a")
169+
OK = maximal_order(K)
170+
G = pseudo_matrix(matrix(K, 6, 6 ,[876708188094148315826780735392810, 798141405233250328867679564294410, -352823337641433300965521329447720, 326768950610851461363580717982402, -690595881941554449465975342845028, 433433545243019702766746394677218, 798141405233250328867679564294410, 867615301468758683549323652197099, -301315621373858240463110267500961, 316796431934778296047626373086339, -725765288914917260527454069649226, 505082964151083450666500945258490, -352823337641433300965521329447720, -301315621373858240463110267500961, 809946152369211852531731702980788, -343784636213856787915462553587466, 84764902049682607076640678540130, -613908853150167850995565570653796, 326768950610851461363580717982402, 316796431934778296047626373086339, -343784636213856787915462553587466, 219957919673551825679009958633894, -226934633316066727073394927118195, 298257387132139131540277459301842, -690595881941554449465975342845028, -725765288914917260527454069649226, 84764902049682607076640678540130, -226934633316066727073394927118195, 671443408734467545153681225010914, -277626128761200144008657217470664, 433433545243019702766746394677218, 505082964151083450666500945258490, -613908853150167850995565570653796, 298257387132139131540277459301842, -277626128761200144008657217470664, 640432299215298238271419741190578]), [ one(K)*OK, one(K)*OK, one(K)*OK, one(K)*OK, one(K)*OK, one(K)*OK ])
171+
L = lattice(hermitian_space(K, identity_matrix(K, 6)), G)
172+
@test automorphism_group_order(L) == 4
173+
@test is_isometric_with_isometry(L, L)[1]
165174
end
166175

167176
@testset "Misc" begin
@@ -199,7 +208,7 @@ end
199208
@test ambient_space(Lres) === Vres
200209
@test all(v -> VrestoV(VrestoV\v) == v, generators(L))
201210

202-
211+
203212
Qx, x = polynomial_ring(FlintQQ, "x")
204213
f = x - 1
205214
K, a = number_field(f, "a", cached = false)

test/QuadForm/Quad/ZLattices.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,21 @@ end
273273
@test automorphism_group_order(L) == lattice_automorphism_group_order(D, i)
274274
end
275275

276+
# Force using ZZRingElem's
277+
L = lattice(D, 75)
278+
Hecke.assert_has_automorphisms(L, try_small = false)
279+
test_automorphisms(L, L.automorphism_group_generators, true)
280+
@test L.automorphism_group_order == lattice_automorphism_group_order(D, 75)
281+
276282
# Call the Bacher polynomials
277-
L = integer_lattice(gram = gram_matrix(lattice(D, 100)))
278-
Ge = automorphism_group_generators(L, ambient_representation = true, bacher_depth = 1)
279-
test_automorphisms(L, Ge, true)
280-
Ge = automorphism_group_generators(L, ambient_representation = false, bacher_depth = 1)
281-
test_automorphisms(L, Ge, false)
282-
@test automorphism_group_order(L) == lattice_automorphism_group_order(D, 100)
283+
for i in [ 1, 101, 113 ] # triggering different checks in the Bacher polynomials
284+
L = integer_lattice(gram = gram_matrix(lattice(D, i)))
285+
Ge = automorphism_group_generators(L, ambient_representation = true, bacher_depth = 1)
286+
test_automorphisms(L, Ge, true)
287+
Ge = automorphism_group_generators(L, ambient_representation = false, bacher_depth = 1)
288+
test_automorphisms(L, Ge, false)
289+
@test automorphism_group_order(L) == lattice_automorphism_group_order(D, i)
290+
end
283291

284292
# automorphisms for indefinite of rank 2
285293
U = hyperbolic_plane_lattice()
@@ -334,14 +342,16 @@ end
334342
end
335343

336344
# Call the Bacher polynomials
337-
L = integer_lattice(gram = gram_matrix(lattice(D, 100)))
338-
n = rank(L)
339-
X = change_base_ring(FlintQQ, _random_invertible_matrix(n, -3:3))
340-
@assert abs(det(X)) == 1
341-
L2 = integer_lattice(gram = X * gram_matrix(L) * transpose(X))
342-
b, T = is_isometric_with_isometry(L, L2, ambient_representation = false, bacher_depth = 1)
343-
@test b
344-
@test T * gram_matrix(L2) * transpose(T) == gram_matrix(L)
345+
for i in [ 1, 101, 113 ] # triggering different checks in the Bacher polynomials
346+
L = integer_lattice(gram = gram_matrix(lattice(D, i)))
347+
n = rank(L)
348+
X = change_base_ring(FlintQQ, _random_invertible_matrix(n, -3:3))
349+
@assert abs(det(X)) == 1
350+
L2 = integer_lattice(gram = X * gram_matrix(L) * transpose(X))
351+
b, T = is_isometric_with_isometry(L, L2, ambient_representation = false, bacher_depth = 1)
352+
@test b
353+
@test T * gram_matrix(L2) * transpose(T) == gram_matrix(L)
354+
end
345355

346356
#discriminant of a lattice
347357
L = integer_lattice(ZZ[1 0; 0 1], gram = matrix(QQ, 2,2, [2, 1, 1, 2]))
@@ -727,6 +737,7 @@ let
727737
G = matrix(FlintQQ, 6, 6 ,[876708188094148315826780735392810, 798141405233250328867679564294410, -352823337641433300965521329447720, 326768950610851461363580717982402, -690595881941554449465975342845028, 433433545243019702766746394677218, 798141405233250328867679564294410, 867615301468758683549323652197099, -301315621373858240463110267500961, 316796431934778296047626373086339, -725765288914917260527454069649226, 505082964151083450666500945258490, -352823337641433300965521329447720, -301315621373858240463110267500961, 809946152369211852531731702980788, -343784636213856787915462553587466, 84764902049682607076640678540130, -613908853150167850995565570653796, 326768950610851461363580717982402, 316796431934778296047626373086339, -343784636213856787915462553587466, 219957919673551825679009958633894, -226934633316066727073394927118195, 298257387132139131540277459301842, -690595881941554449465975342845028, -725765288914917260527454069649226, 84764902049682607076640678540130, -226934633316066727073394927118195, 671443408734467545153681225010914, -277626128761200144008657217470664, 433433545243019702766746394677218, 505082964151083450666500945258490, -613908853150167850995565570653796, 298257387132139131540277459301842, -277626128761200144008657217470664, 640432299215298238271419741190578])
728738
L = integer_lattice(B, gram = G)
729739
@test automorphism_group_order(L) == 2
740+
@test is_isometric_with_isometry(L, L)[1]
730741
G = [ ZZ[15 0 2 0; 0 30 0 4; 2 0 32 0; 0 4 0 64],
731742
ZZ[0 15 0 2; 15 0 2 0; 0 2 0 32; 2 0 32 0]];
732743
C = Hecke.ZLatAutoCtx(G)

0 commit comments

Comments
 (0)