-
Notifications
You must be signed in to change notification settings - Fork 120
/
K3Auto.jl
2099 lines (1858 loc) · 64.4 KB
/
K3Auto.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################################
# Types
################################################################################
@doc raw"""
BorcherdsCtx
Contains all the data necessary to run Borcherds' method.
The assumptions are as follows:
- `L::ZZLat`: even, hyperbolic, unimodular `Z`-lattice of rank n = 10, 18 or 26
with basis given by the n x n standard basis
- `S::ZZLat`: primitive sublattice
- `weyl_vector::ZZMatrix`: given in the basis of `L`
- `R::ZZLat`: the orthogonal complement of `S` in `L`
We assume that the basis of R consists of the last rank R standard basis vectors.
- `SS::ZZLat`: lattice with standard basis and same gram matrix as `S`.
- `deltaR::Vector{ZZMatrix}`:
- `dualDeltaR::Vector{ZZMatrix}`:
- `prRdelta::Vector{Tuple{QQMatrix,QQFieldElem}}`:
- `membership_test`: takes the `s x s` matrix describing `g: S -> S` with respect
to the basis of `S` and returns whether `g` lies in the group `G`.
- `prS::QQMatrix`: `prS: L --> S^\vee` given with respect to the (standard)
basis of `L` and the basis of `S`
"""
mutable struct BorcherdsCtx
L::ZZLat
S::ZZLat
weyl_vector::ZZMatrix # given in the basis of L
SS::ZZLat
R::ZZLat
deltaR::Vector{ZZMatrix}
dualDeltaR::Vector{ZZMatrix}
prRdelta::Vector{Tuple{QQMatrix,QQFieldElem}}
membership_test
gramL::ZZMatrix # avoid a few conversions because gram_matrix(::ZZLat) -> QQMatrix
gramS::ZZMatrix
prS::QQMatrix
compute_OR::Bool
# TODO: Store temporary variables for the computations
# in order to make the core-functions adjacent_chamber and walls
# as non-allocating as possible.
end
function Base.show(io::IOContext, d::BorcherdsCtx)
print(io, "BorcherdsCtx: dim(L) = $(rank(d.L)), rank(S) = $(rank(d.S)), det(S) = $(det(d.S))")
end
@doc raw"""
BorcherdsCtx(L::ZZLat, S::ZZLat; compute_OR::Bool=true) -> BorcherdsCtx, QQMatrix
Return the context for Borcherds' method.
And the basis matrix of the new `L` in the BorcherdsCtx.
# Arguments
- `L::ZZLat`: an even, hyperbolic, unimodular `Z`-lattice of rank 10, 18, or 26
- `S::ZZLat`: a primitive sublattice of `L` in the same ambient space
- `weyl::ZZMatrix`: a weyl vector with respect to the basis of `L`
- if `compute_OR` is `false`, then `G` is the subgroup of the orthogonal group
of `S` acting as $\pm 1$ on the discriminant group.
If `compute_OR` is `true`, then `G` consists the subgroup consisting of
isometries of `S` that can be extended to isometries of `L`.
"""
function BorcherdsCtx(L::ZZLat, S::ZZLat, weyl::ZZMatrix; compute_OR::Bool=true)
r = rank(L)
lw = (weyl*gram_matrix(L)*transpose(weyl))[1,1]
if r == 26
@req lw == 0 "not a Weyl vector"
end
if r == 18
@req lw == 620 "not a Weyl vector"
end
if r == 10
@req lw == 1240 "not a Weyl vector"
end
# transform L to have the standard basis
# we assume that the basis of L is obtained by completing a basis of R
# hence we can throw away the R coordinates of a Weyl vector when projecting to S
R = lll(Hecke.orthogonal_submodule(L, S))
# the following completes the basis of R to a basis of L
basisRL = solve(basis_matrix(L),basis_matrix(R); side = :left)
basisRL = change_base_ring(ZZ, basisRL)
A, j = snf(abelian_group(basisRL))
T = reduce(vcat, [j(i).coeff for i in gens(A)])
basisL1 = vcat(T, basisRL)*basis_matrix(L)
# carry the Weyl vector along
L1 = lattice(ambient_space(L), basisL1)
weyl = change_base_ring(ZZ, solve(basisL1, weyl*basis_matrix(L); side = :left))
basisSL1 = solve(basis_matrix(L1), basis_matrix(S); side = :left)
basisRL1 = solve(basis_matrix(L1), basis_matrix(R); side = :left)
# Assure that L has the standard basis.
L = integer_lattice(gram=gram_matrix(L1))
V = ambient_space(L)
# carry S along
S = lattice(V, basisSL1)
R = lattice(V, basisRL1)
@req is_S_nondegenerate(L, S, change_base_ring(QQ,weyl)) "Weyl vector is S degenerate"
SS = integer_lattice(gram=gram_matrix(S))
# precomputations
@assert iszero(basis_matrix(R)[1:end,1:rank(S)])
bSR = vcat(basis_matrix(S),basis_matrix(R))
ibSR = inv(bSR)
I = identity_matrix(QQ,degree(L))
# prS: L --> S^\vee given with respect to the standard basis of L and the basis of S
prS = ibSR*I[:,1:rank(S)]#*basis_matrix(S)
@assert prS[[rank(S)+1],:]==0
if compute_OR
dd = diagonal(gram_matrix(R))
@vprint :K3Auto 2 "computing orthogonal group\n"
OR = orthogonal_group(R)
@vprint :K3Auto 2 "done\n"
DR = discriminant_group(R)
ODR = orthogonal_group(DR)
imOR = [ODR(hom(DR,DR,[DR(lift(d)*f) for d in gens(DR)])) for f in gens(OR)]
DS = discriminant_group(S)
DSS = discriminant_group(SS)
ODSS = orthogonal_group(DSS)
orderimOR = order(sub(ODR,imOR)[1])
@vprint :K3Auto 1 "[O(S):G] = $(order(ODSS)//orderimOR)\n"
if order(ODR)== orderimOR
membership_test = (g->true)
else
phiSS_S = hom(DSS,DS,[DS(lift(x)*basis_matrix(S)) for x in gens(DSS)])
phi,i,j = glue_map(L,S,R)
phi = phiSS_S*inv(i)*phi*j
img,_ = sub(ODSS,[ODSS(phi*hom(g)*inv(phi)) for g in imOR])
ds = degree(SS)
membership_test = (g->ODSS(hom(DSS,DSS,[DSS(_vec(matrix(QQ, 1, ds, lift(x))*g)) for x in gens(DSS)])) in img)
end
else
membership_test(g) = is_pm1_on_discr(SS,g)
end
d = exponent(discriminant_group(S))
Rdual = dual(R)
sv = short_vectors(rescale(Rdual,-1), 2, ZZRingElem)
# not storing the following for efficiency
# append!(sv,[(-v[1],v[2]) for v in sv])
# but for convenience we include zero
push!(sv,(zeros(ZZRingElem, rank(Rdual)), QQ(0)))
rkR = rank(R)
prRdelta = [(matrix(QQ, 1, rkR, v[1])*basis_matrix(Rdual),v[2]) for v in sv]
gramL = change_base_ring(ZZ,gram_matrix(L))
gramS = change_base_ring(ZZ,gram_matrix(S))
deltaR = [change_base_ring(ZZ, matrix(QQ, 1, rkR, v[1])*basis_matrix(R)) for v in short_vectors(rescale(R,-1),2)]
dualDeltaR = [gramL*transpose(r) for r in deltaR]
BCtx = BorcherdsCtx(L, S, weyl, SS, R, deltaR, dualDeltaR, prRdelta, membership_test,
gramL, gramS, prS, compute_OR)
return BCtx, basisL1
end
################################################################################
# Chambers
################################################################################
@doc raw"""
K3Chamber
The ``L|S`` chamber induced from a Weyl vector in `L`.
Let ``L`` be an even, unimodular and hyperbolic lattice of rank ``10``, ``18``
or ``26`` and ``S`` be a primitive sublattice.
Any Weyl vector ``w`` of ``L`` defines a Weyl chamber ``C(w)``
in the positive cone of ``L``.
The Weyl chamber is a rational locally polyhedral cone with infinitely many
facets, i.e. walls. It is the intersection of the positive half-spaces defined by
$\Delta_L(w) = \{r \in L | r^2=-2, r.w = 1\}$.
We have
```math
C(w)=\{x \in \mathcal{P}_L | \forall r \in \Delta_L(w): x.r \geq 0\}
```
The Weyl chamber is a fundamental domain for the action of
the Weyl group on the positive cone.
We say that $S \otimes \mathbb{R} \cap C(w)$ is the ``L|S``-chamber induced by ``w``.
Note that two Weyl vectors induce the same chamber if and only if
their orthogonal projections to ``S`` coincide.
"""
mutable struct K3Chamber
weyl_vector::ZZMatrix
# for v in walls, the corresponding half space is defined by the equation
# x * gram_matrix(S)*v >= 0, further v is primitive in S (and, in contrast to Shimada, not S^\vee)
walls::Vector{ZZMatrix}
lengths::Vector{QQFieldElem} #
B::ZZMatrix # QQ-basis consisting of rays #... why do we bother to save this?
gramB::ZZMatrix # the basis matrix inferred from the QQ-basis
parent_wall::ZZMatrix # for the spanning tree
data::BorcherdsCtx
fp::Matrix{Int} # fingerprint for the backtrack search
#per::Vector{Int} # permutation
fp_diagonal::Vector{Int}
# TODO: Be more memory efficient and store only the indices for the
# basis matrix and the permutation.
# I am not sure if storing gram matrix stuff in memory actually increases performance...
function K3Chamber()
return new()
end
end
@doc raw"""
chamber(data::BorcherdsCtx, weyl_vector::ZZMatrix, [parent_wall::ZZMatrix, walls::Vector{ZZMatrix}])
Return the ``L|S``-chamber with the given Weyl vector.
The lattices ``L`` and ``S`` are stored in `data`.
Via the parent walls we can obtain a spanning tree of the chamber graph.
"""
function chamber(data::BorcherdsCtx, weyl_vector::ZZMatrix, parent_wall::ZZMatrix=zero_matrix(ZZ, 0, 0))
D = K3Chamber()
D.weyl_vector = weyl_vector
D.parent_wall = parent_wall
D.data = data
return D
end
function chamber(data::BorcherdsCtx, weyl_vector::ZZMatrix, parent_wall::ZZMatrix, walls::Vector{ZZMatrix})
D = K3Chamber()
D.weyl_vector = weyl_vector
D.parent_wall = parent_wall
D.data = data
D.walls = walls
return D
end
# needed to create sets of K3Chambers
function Base.hash(C::K3Chamber)
return hash(C.weyl_vector[:,1:rank(C.data.S)])
end
# Two chambers are equal if and only if their Weyl vectors
# project to the same point in S
# By the choice of our coordinates this projection is determined
# by the first rank(S) coordinates.
function Base.:(==)(C::K3Chamber, D::K3Chamber)
@req C.data===D.data "K3Chambers do not have the same context"
return C.weyl_vector[:,1:rank(C.data.S)] == D.weyl_vector[:,1:rank(D.data.S)]
end
@doc raw"""
walls(D::K3Chamber) -> Vector{ZZMatrix}
Return the walls of the chamber `D`, i.e. its facets.
The corresponding half space of the wall defined by `v` in `walls(D)` is
```math
\{x \in S \otimes \mathbb{R} | \langle x,v \rangle \geq 0\}.
```
`v` is given with respect to the basis of `S` and is primitive in `S`.
Note that [Shi15](@cite) follows a different convention
and takes `v` primitive in `S^\vee`.
"""
function walls(D::K3Chamber)
if !isdefined(D, :walls)
D.walls = _walls_of_chamber(D.data, D.weyl_vector)
@assert length(D.walls)>=rank(D.data.S) "$(D.weyl_vector)"
end
return D.walls
end
@doc raw"""
weyl_vector(D::K3Chamber) -> ZZMatrix
Return the Weyl vector defining this chamber.
"""
weyl_vector(D::K3Chamber) = D.weyl_vector
@doc raw"""
rays(D::K3Chamber)
Return the rays of the chamber `D`.
They are represented as primitive row vectors with respect to the basis of `S`.
"""
function rays(D::K3Chamber)
r = reduce(vcat, walls(D), init=zero_matrix(ZZ,0,rank(D.data.SS)))
rQ = change_base_ring(QQ, r) * gram_matrix(D.data.SS)
C = positive_hull(rQ)
Cd = polarize(C)
L = rays(Cd)
Lq = QQMatrix[matrix(QQ,1,rank(D.data.SS),i) for i in L]
# clear denominators
Lz = ZZMatrix[change_base_ring(ZZ,i*denominator(i)) for i in Lq]
# primitive in S
Lz = ZZMatrix[divexact(i,gcd(_vec(i))) for i in Lz]
@hassert :K3Auto 2 all(all(x>=0 for x in _vec(r*gram_matrix(D.data.SS)*transpose(i))) for i in Lz)
return Lz
end
function Base.show(io::IO, c::K3Chamber)
if isdefined(c,:walls)
print(IOContext(io, :compact => true), "Chamber in dimension $(length(walls(c)[1])) with $(length(walls(c))) walls")
else
print(IOContext(io, :compact => true), "Chamber: $(c.weyl_vector[1,1:rank(c.data.S)])")
end
end
@doc raw"""
fingerprint(D::K3Chamber)
Return the fingerprint of this chamber.
The fingerprint is an invariant computed from the rays and their inner products.
"""
function fingerprint(D::K3Chamber)
v = sum(walls(D))
G = D.data.gramS
m1 = (v*G*transpose(v))[1,1]
m2 = [(a*G*transpose(a))[1,1] for a in walls(D)]
sort!(m2)
m3 = [(v*G*transpose(a))[1,1] for a in walls(D)]
sort!(m3)
m4 = ZZRingElem[]
for i in 1:length(walls(D))
for j in 1:i-1
push!(m4,(walls(D)[i]*G*transpose(walls(D)[j]))[1,1])
end
end
sort!(m4)
V = Dict{Tuple{ZZRingElem,ZZRingElem},Vector{ZZMatrix}}()
for w in walls(D)
i = (v*G*transpose(w))[1,1]
j = (w*G*transpose(w))[1,1]
if (i,j) in keys(V)
push!(V[(i,j)],w)
else
V[(i,j)] = [w]
end
end
#=
# so far m5 was not needed to separate the O(S)-orbits
m5 = []
for i in keys(V)
vi = sum(V[i])
push!(m5, [i,sort!([(vi*G*transpose(j))[1,1] for j in walls(D)])])
end
sort!(m5)
# So far we have only O(S)-invariants. There are also ways to produce G-invariants
# by working the the images of the rays in the discriminant group and their
# G-orbits. Perhaps one has to switch to S^\vee primitive vectors in this case.
=#
return (m1, m2, m3, m4)
end
"""
Compute the fingerprint defined by Plesken-Souvignier and change the basis
matrix and gram matrix accordingly.
It is computed from the walls and the gram matrix of `S`.
A permutation `per` for the
order of the basis-vectors is chosen
such that in every step the number of
possible continuations is minimal,
for j from per[i] to per[dim-1] the
value f[i][j] in the fingerprint f is
the number of vectors, which have the
same scalar product with the
basis-vectors per[0]...per[i-1] as the
basis-vector j and the same length as
this vector with respect to all
invariant forms
"""
function _fingerprint_backtrack!(D::K3Chamber)
n = rank(D.data.S)
V = walls(D)
gramS = gram_matrix(D.data.S)
B, indB = _find_basis(V, n)
tmp = V[indB]
deleteat!(V, indB)
prepend!(V, tmp)
lengths = QQFieldElem[(v*gramS*transpose(v))[1,1] for v in V]
D.lengths = lengths
gramB = change_base_ring(ZZ, B*gramS*transpose(B))
D.gramB = gramB
D.B = B
per = Vector{Int}(undef, n)
for i in 1:n
per[i] = i
end
fp = zeros(Int, n, n)
# fp[1, i] = # vectors v such that v has same length as b_i for all forms
for i in 1:n
cvl = gramB[i,i]
fp[1, i] = count(x->x==cvl, lengths)
end
for i in 1:(n - 1)
# Find the minimal non-zero entry in the i-th row
mini = i
@inbounds for j in (i+1):n
if fp[i, per[j]] < fp[i, per[mini]]
mini = j
end
end
per[mini], per[i] = per[i], per[mini]
# Set entries below the minimal entry to zero
@inbounds for j in (i + 1):n
fp[j, per[i]] = 0
end
# Now compute row i + 1
for j in (i + 1):n
fp[i + 1, per[j]] = _possible(D, per, i, per[j])
end
end
# Extract the diagonal
res = Vector{Int}(undef, n)
@inbounds for i in 1:n
res[i] = fp[i, per[i]]
@assert res[i]>0
end
#D.per = per
D.B = B[per,:]
D.gramB = gramB[per,per]
D.fp = fp[:,per]
D.fp_diagonal = res
end
@doc raw"""
_possible(D::K3Chamber, per, I, J) -> Int
Return the number of possible extensions of an `n`-partial isometry to
an `n+1`-partial one.
"""
function _possible(D::K3Chamber, per, I, J)
vectors = walls(D)
lengths = D.lengths
gramB = D.gramB
gramS = D.data.gramS
n = length(vectors)
@assert n == length(lengths)
count = 0
T = gramS*transpose(reduce(vcat,vectors[per[1:I]]))
for j in 1:n
lengthsj = lengths[j]
vectorsj = vectors[j]
good_scalar = true
if lengthsj != gramB[J, J]
continue
end
for i in 1:I
if (vectorsj*T[:,i:i])[1,1] != gramB[J,per[i]]
good_scalar = false
break
end
end
if !good_scalar
continue
end
count = count + 1
# length is correct
end
return count
end
################################################################################
# close vector functions
################################################################################
@doc raw"""
enumerate_quadratic_triple -> Vector{Tuple{Vector{Int}, QQFieldElem}}
Return $\{x \in \mathbb Z^n : x Q x^T + 2xb^T + c <=0\}$.
#Input:
- `Q`: positive definite matrix
- `b`: row vector
- `c`: rational number
"""
function enumerate_quadratic_triple(Q, b, c; algorithm=:short_vectors, equal=false)
if algorithm == :short_vectors
L, p, dist = Hecke._convert_type(Q, b, QQ(c))
#@vprint :K3Auto 1 ambient_space(L), basis_matrix(L), p, dist
if equal
cv = Hecke.close_vectors(L, _vec(p), dist, dist, check=false)
else
cv = Hecke.close_vectors(L, _vec(p), dist, check=false)
end
end
return cv
end
@doc raw"""
short_vectors_affine(S::ZZLat, v::MatrixElem, alpha, d)
short_vectors_affine(gram::MatrixElem, v::MatrixElem, alpha, d)
Return the vectors of squared length `d` in the given affine hyperplane.
```math
\{x \in S : x^2=d, x.v=\alpha \}.
```
The matrix version takes `S` with standard basis and the given gram matrix.
# Arguments
- `v`: row vector with $v^2 > 0$
- `S`: a hyperbolic `Z`-lattice
The output is given in the ambient representation.
The implementation is based on Algorithm 2.2 in [Shi15](@cite)
"""
function short_vectors_affine(S::ZZLat, v::MatrixElem, alpha, d)
alpha = QQ(alpha)
gram = gram_matrix(S)
tmp = v*gram_matrix(ambient_space(S))*transpose(basis_matrix(S))
v_S = solve(gram_matrix(S),tmp; side = :left)
sol = short_vectors_affine(gram, v_S, alpha, d)
B = basis_matrix(S)
return [s*B for s in sol]
end
function short_vectors_affine(gram::MatrixElem, v::MatrixElem, alpha::QQFieldElem, d)
# find a solution <x,v> = alpha with x in L if it exists
w = gram*transpose(v)
tmp = Hecke.FakeFmpqMat(w)
wn = numerator(tmp)
wd = denominator(tmp)
b, x = can_solve_with_solution(transpose(wn), matrix(ZZ, 1, 1, [alpha*wd]); side = :right)
if !b
return QQMatrix[]
end
K = kernel(wn; side = :left)
# (x + y*K)*gram*(x + y*K) = x gram x + 2xGKy + y K G K y
# now I want to formulate this as a cvp
# (x +y K) gram (x+yK) ==d
# (x
GK = gram*transpose(K)
Q = K * GK
b = transpose(x) * GK
c = (transpose(x)*gram*x)[1,1] - d
# solve the quadratic triple
Q = change_base_ring(QQ, Q)
b = change_base_ring(QQ, transpose(b))
cv = enumerate_quadratic_triple(-Q, -b,-QQ(c),equal=true)
xt = transpose(x)
cv = [xt+matrix(ZZ,1,nrows(Q),u[1])*K for u in cv]
@hassert :K3Auto 1 all((v*gram*transpose(u))[1,1]==alpha for u in cv)
@hassert :K3Auto 1 all((u*gram*transpose(u))[1,1]== d for u in cv)
return cv #[u for u in cv if (u*gram*transpose(u))[1,1]==d]
end
@doc raw"""
separating_hyperplanes(S::ZZLat, v::QQMatrix, h::QQMatrix, d)
Return $\{x \in S | x^2=d, x.v>0, x.h<0\}$.
# Arguments
- `S`: a hyperbolic lattice
- `d`: a negative integer
- `v`,`h`: vectors of positive square
"""
function separating_hyperplanes(S::ZZLat, v::QQMatrix, h::QQMatrix, d)
V = ambient_space(S)
@hassert :K3Auto 1 inner_product(V,v,v)[1,1]>0
@hassert :K3Auto 1 inner_product(V,h,h)[1,1]>0
gram = gram_matrix(S)
B = basis_matrix(S)
vS = solve(B,v; side = :left)
hS = solve(B,h; side = :left)
return [a*B for a in separating_hyperplanes(gram,vS,hS,d)]
end
function separating_hyperplanes(gram::QQMatrix, v::QQMatrix, h::QQMatrix, d)
L = integer_lattice(gram=gram)
n = ncols(gram)
ch = QQ((h*gram*transpose(h))[1,1])
cv = QQ((h*gram*transpose(v))[1,1])
b = basis_matrix(L)
prW = reduce(vcat,[b[i:i,:] - (b[i:i,:]*gram*transpose(h))*ch^-1*h for i in 1:n])
W = lattice(ambient_space(L), prW, isbasis=false)
bW = basis_matrix(W)
# set up the quadratic triple for SW
gramW = gram_matrix(W)
s = solve(bW, v*prW; side = :left) * gramW
Q = gramW + transpose(s)*s*ch*cv^-2
@vprint :K3Auto 5 Q
LQ = integer_lattice(gram=-Q*denominator(Q))
S = QQMatrix[]
h = change_base_ring(QQ, h)
rho = abs(d)*ch^-1
t,sqrtho = is_square_with_sqrt(rho)
if t
r = sqrtho*h
if denominator(r)==1 && (r*gram*transpose(h))[1,1]>0 && (r*gram*transpose(v))[1,1] < 0
push!(S,r)
end
end
for (x,_) in short_vectors_iterator(LQ, abs(d*denominator(Q)))
rp = matrix(ZZ, 1, nrows(Q), x)*bW
rho = abs(d - (rp*gram*transpose(rp))[1,1])*ch^-1
t,rho = is_square_with_sqrt(rho)
if !t
continue
end
r = rho*h + rp
if denominator(r)==1 && (r*gram*transpose(h))[1,1]>0 && (r*gram*transpose(v))[1,1] < 0
push!(S,r)
end
r = rho*h - rp
if denominator(r)==1 && (r*gram*transpose(h))[1,1]>0 && (r*gram*transpose(v))[1,1] < 0
push!(S,r)
end
end
return S
end
@doc raw"""
_find_basis(row_matrices::Vector, dim::Integer)
Return the first `dim` linearly independent vectors in row_matrices and their indices.
We assume that row_matrices consists of row vectors.
"""
function _find_basis(row_matrices::Vector, dim::Integer)
@req length(row_matrices)>=dim > 0 "must contain at least a single vector"
r = row_matrices[1]
n = ncols(r)
B = zero_matrix(base_ring(r), 0, n)
rk = 0
indices = Int[]
for i in 1:length(row_matrices)
r = row_matrices[i]
Br = vcat(B, r)
rk = rank(Br)
if rk > nrows(B)
B = Br
push!(indices, i)
end
if rk == dim
break
end
end
@assert length(indices) == rk == dim
return B, indices
end
_find_basis(row_matrices::Vector) = _find_basis(row_matrices, ncols(row_matrices[1]))
@doc raw"""
is_pm1_on_discr(S::ZZLat, g::ZZMatrix) -> Bool
Return whether the isometry `g` of `S` acts as `+-1` on the discriminant group.
"""
function is_pm1_on_discr(S::ZZLat, g::ZZMatrix)
D = discriminant_group(S)
imgs = [D(_vec(matrix(QQ,1,rank(S),lift(d))*g)) for d in gens(D)]
return all(imgs[i] == gen(D, i) for i in 1:ngens(D)) || all(imgs[i] == -gen(D, i) for i in 1:ngens(D))
# OD = orthogonal_group(D)
# g1 = hom(D,D,[D(lift(d)*g) for d in gens(D)])
# gg = OD(g1)
# return isone(gg) || gg == OD(-matrix(one(OD)))
end
@doc raw"""
hom(D::K3Chamber, E::K3Chamber) -> Vector{ZZMatrix}
Return the set ``\mathrm{Hom}_G(D, E)`` of elements of ``G`` mapping `D` to `E`.
The elements are represented with respect to the basis of ``S``.
"""
Hecke.hom(D::K3Chamber, E::K3Chamber) = alg319(D, E)
#alg319(gram_matrix(D.data.SS), D.B,D.gramB, walls(D), walls(E), D.data.membership_test)
@doc raw"""
aut(E::K3Chamber) -> Vector{ZZMatrix}
Return the stabilizer ``\mathrm{Aut}_G(E)`` of ``E`` in ``G``.
The elements are represented with respect to the basis of ``S``.
"""
aut(D::K3Chamber) = hom(D, D)
function alg319(D::K3Chamber, E::K3Chamber)
if !isdefined(D,:B)
_fingerprint_backtrack!(D) # compute a favorable basis
end
gram_basis = D.gramB
gram = D.data.gramS
fp = D.fp_diagonal
basis = D.B
n = ncols(gram)
raysD = walls(D)
raysE = walls(E)
partial_homs = [zero_matrix(ZZ, 0, n)]
# breadth first search
# Since we expect D and E to be isomorphic,
# a depth first search with early abort could be more efficient.
# for now this does not seem to be a bottleneck
for i in 1:n
@vprint :K3Auto 4 "level $(i-1), partial homs $(length(partial_homs)) \n"
partial_homs_new = ZZMatrix[]
for img in partial_homs
extensions = ZZMatrix[]
k = nrows(img)
gi = gram*transpose(img)
for r in raysE
if (r*gram*transpose(r))[1,1] != gram_basis[k+1,k+1] || (k>0 && r*gi != gram_basis[k+1:k+1,1:k])
continue
end
# now r has the correct inner products with what we need
push!(extensions, vcat(img, r))
end
if fp[i] != length(extensions)
continue
end
append!(partial_homs_new, extensions)
end
partial_homs = partial_homs_new
end
basisinv = inv(change_base_ring(QQ, basis))
homs = ZZMatrix[]
is_in_hom_D_E(fz) = all(r*fz in raysE for r in raysD)
vE = sum(raysE) # center of mass of the dual cone
vD = sum(raysD)
for f in partial_homs
f = basisinv*f
if denominator(f)!=1
continue
end
fz = change_base_ring(ZZ, f)
if !D.data.membership_test(fz)
continue
end
if !(vD*fz == vE)
continue
end
# The center of mass is an interior point
# Further it uniquely determines the chamber and is compatible with homomorphisms
# This is basically Remark 3.20
# -> but this is not true for the center of mass of the dual cone
# hence this extra check
if !is_in_hom_D_E(fz)
continue
end
push!(homs, fz)
end
@hassert :K3Auto 1 all(f*gram*transpose(f)==gram for f in homs)
return homs
end
# legacy worker for hom and aut without Plesken-Souvignier preprocessing
function alg319(gram::MatrixElem, raysD::Vector{ZZMatrix}, raysE::Vector{ZZMatrix}, membership_test)
n = ncols(gram)
partial_homs = [zero_matrix(ZZ, 0, n)]
basis,_ = _find_basis(raysD, n)
gram_basis = basis*gram*transpose(basis)
return alg319(gram, basis, gram_basis, raysD, raysE, membership_test)
end
function alg319(gram::MatrixElem, basis::ZZMatrix, gram_basis::QQMatrix, raysD::Vector{ZZMatrix}, raysE::Vector{ZZMatrix}, membership_test)
n = ncols(gram)
partial_homs = [zero_matrix(ZZ, 0, n)]
# breadth first search
# Since we expect D and E to be isomorphic,
# a depth first search with early abort would be more efficient.
# for now this does not seem to be a bottleneck
for i in 1:n
@vprint :K3Auto 4 "level $(i), partial homs $(length(partial_homs)) \n"
partial_homs_new = ZZMatrix[]
for img in partial_homs
extensions = ZZMatrix[]
k = nrows(img)
gi = gram*transpose(img)
for r in raysE
if (r*gram*transpose(r))[1,1] != gram_basis[k+1,k+1] || (k>0 && r*gi != gram_basis[k+1:k+1,1:k])
continue
end
# now r has the correct inner products with what we need
push!(extensions, vcat(img,r))
end
append!(partial_homs_new, extensions)
end
partial_homs = partial_homs_new
end
basisinv = inv(change_base_ring(QQ, basis))
homs = ZZMatrix[]
is_in_hom_D_E(fz) = all(r*fz in raysE for r in raysD)
vE = sum(raysE) # center of mass of the dual cone
vD = sum(raysD)
for f in partial_homs
f = basisinv*f
if denominator(f)!=1
continue
end
fz = change_base_ring(ZZ,f)
if !membership_test(fz)
continue
end
if !(vD*fz == vE)
continue
end
# The center of mass is an interior point
# Further it uniquely determines the chamber and is compatible with homomorphisms
# This is basically Remark 3.20
# -> but this is not true for the center of mass of the dual cone
if !is_in_hom_D_E(fz)
continue
end
push!(homs, fz)
end
@hassert :K3Auto 1 all(f*gram*transpose(f)==gram for f in homs)
return homs
end
@doc raw"""
_alg58(L::ZZLat, S::ZZLat, R::ZZLat, prRdelta, w)
Compute Delta_w
Tuples (r_S, r) where r is an element of Delta_w and r_S is the
orthogonal projection of `r` to `S`.
Corresponds to Algorithm 5.8 in [Shi15](@cite)
but this implementation is different.
"""
# legacy function needed for precomputations
function _alg58(L::ZZLat, S::ZZLat, R::ZZLat, prRdelta, w::QQMatrix)
V = ambient_space(L)
d = exponent(discriminant_group(S))
@hassert :K3Auto 1 V == ambient_space(S)
n_R = [QQ(i)//d for i in (-2*d+1):0 if mod(d*i,2)==0]
Rdual = dual(R)
Sdual = dual(S)
rkR = rank(R)
delta_w = QQMatrix[]
iB = inv(basis_matrix(L))
for c in n_R
cm = -c
for (vr0,vsquare) in prRdelta
if vsquare != cm
continue
end
a0 = inner_product(V,w,vr0)[1,1]
if c == 0
VA = [(vr0,a0)]
else
VA = [(vr0,a0),(-vr0,-a0)]
end
for (vr,a) in VA
Sdual_na = short_vectors_affine(Sdual, w, 1 - a, -2 - c)
for vs in Sdual_na
vv = vs + vr
if all(denominator(i)==1 for i in collect(vv*iB))
push!(delta_w, vs)
end
end
end
end
end
return delta_w
end
function _alg58(L::ZZLat, S::ZZLat, R::ZZLat, w::MatrixElem)
Rdual = dual(R)
sv = short_vectors(rescale(Rdual, -1), 2, ZZRingElem)
# not storing the following for efficiency
# append!(sv,[(-v[1],v[2]) for v in sv])
# but for convenience we include zero
push!(sv,(zeros(ZZRingElem, rank(Rdual)), QQ(0)))
rkR = rank(R)
prRdelta = [(matrix(QQ, 1, rkR, v[1])*basis_matrix(Rdual),v[2]) for v in sv]
return _alg58(L, S, R, prRdelta, w)
end
# the actual somewhat optimized implementation relying on short vector enumeration
function _alg58_short_vector(data::BorcherdsCtx, w::ZZMatrix)
L = data.L
V = ambient_space(L)
S = data.S
R = data.R
wS = w*data.prS
wSL = wS*basis_matrix(S)
wL = gram_matrix(L)*transpose(w)
wSsquare = (wS*data.gramS*transpose(wS))[1,1]
W = lattice(V, wS*basis_matrix(S))
N = orthogonal_submodule(S, W)
# W + N + R < L of finite index
svp_input = Tuple{QQFieldElem,QQMatrix,QQFieldElem,Int}[]
for (rR, rRsq) in data.prRdelta
if rRsq == 2
continue
end
@inbounds rwS = (rR*wL)[1,1]
alpha = 1 - rwS
usq = alpha^2*wSsquare^-1 - rRsq
sq = -2 - usq
push!(svp_input, (alpha, rR,sq,1))
alpha = 1 + rwS
usq = alpha^2*wSsquare^-1 - rRsq
sq = -2 - usq
push!(svp_input, (alpha, rR, sq, -1))
end
@inbounds bounds = unique!([-i[3] for i in svp_input])
Ndual = dual(N)
G = -gram_matrix(Ndual)
d = denominator(G)
bounds = [i for i in bounds if divides(d,denominator(i))[1]]
mi = minimum(bounds)
ma = maximum(bounds)
svN = Hecke._short_vectors_gram(Hecke.LatEnumCtx, G,mi,ma, ZZRingElem)
result = QQMatrix[]
# treat the special case of the zero vector by copy paste.
if QQ(0) in bounds
(rN,sqrN) = (zeros(Int64,rank(Ndual)),0)
rN1 = zero_matrix(ZZ,1,degree(Ndual))
found1 = false
found2 = false
sqrN = QQ(0)
for (alpha, rR, sq, si) in svp_input
if sqrN != sq
continue
end
rr = alpha*wSsquare^-1*wSL + si*rR
r = rr + rN1
if !found1 && @inbounds all(denominator(r[1,i])==1 for i in 1:ncols(r))==1
found1 = true
push!(result, r*data.prS)
break
end
r = rr - rN1
if !found2 && @inbounds all(denominator(r[1,i])==1 for i in 1:ncols(r))==1
found2 = true
push!(result, r*data.prS)
break
end
if found1 && found2
break
end
end
end
for (rN, sqrN) in svN
if !(sqrN in bounds)
continue
end
rN1 = matrix(ZZ,1,rank(Ndual),rN)*basis_matrix(Ndual)
found1 = false
found2 = false
sqrN = -sqrN
for (alpha, rR, sq, si) in svp_input
if sqrN != sq
continue
end
rr = alpha*wSsquare^-1*wSL + si*rR
r = rr + rN1
if !found1 && @inbounds all(denominator(r[1,i])==1 for i in 1:ncols(r))==1