-
Notifications
You must be signed in to change notification settings - Fork 59
/
Lattices.jl
2079 lines (1730 loc) · 68.6 KB
/
Lattices.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
################################################################################
#
# Verbosity and assertion scopes
#
################################################################################
add_verbosity_scope(:Lattice)
add_assertion_scope(:Lattice)
################################################################################
#
# Ambient space
#
################################################################################
@doc raw"""
has_ambient_space(L::AbstractLat) -> Bool
Return whether the ambient space of the lattice `L` is set.
"""
function has_ambient_space(L::AbstractLat)
return isdefined(L, :space)
end
@doc raw"""
ambient_space(L::AbstractLat) -> AbstractSpace
Return the ambient space of the lattice `L`. If the ambient space is not known, an
error is raised.
"""
function ambient_space(L::AbstractLat)
if !has_ambient_space(L)
B = matrix(pseudo_matrix(L))
@assert isone(B)
L.space = rational_span(L)
end
return L.space
end
################################################################################
#
# Rational span
#
################################################################################
@doc raw"""
rational_span(L::AbstractLat) -> AbstractSpace
Return the rational span of the lattice `L`.
"""
rational_span(::AbstractLat)
################################################################################
#
# Diagonal
#
################################################################################
@doc raw"""
diagonal_of_rational_span(L::AbstractLat) -> Vector
Return the diagonal of the rational span of the lattice `L`.
"""
function diagonal_of_rational_span(L::AbstractLat)
D, _ = _gram_schmidt(gram_matrix_of_rational_span(L), involution(L))
return diagonal(D)
end
################################################################################
#
# Module properties
#
################################################################################
@doc raw"""
pseudo_matrix(L::AbstractLat) -> PMat
Return a basis pseudo-matrix of the lattice `L`.
"""
pseudo_matrix(L::AbstractLat) = L.pmat
@doc raw"""
pseudo_basis(L::AbstractLat) -> Vector{Tuple{Vector, Ideal}}
Return a pseudo-basis of the lattice `L`.
"""
function pseudo_basis(L::AbstractLat)
M = matrix(pseudo_matrix(L))
LpM = pseudo_matrix(L)
O = base_ring(LpM)
z = Vector{Tuple{Vector{elem_type(nf(O))}, fractional_ideal_type(O)}}(undef, nrows(M))
for i in 1:nrows(M)
z[i] = (elem_type(base_ring(M))[ M[i, j] for j in 1:ncols(M) ],
coefficient_ideals(LpM)[i])
end
return z
end
@doc raw"""
coefficient_ideals(L::AbstractLat) -> Vector{AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}}
Return the coefficient ideals of a pseudo-basis of the lattice `L`.
"""
coefficient_ideals(L::AbstractLat) = coefficient_ideals(pseudo_matrix(L))
@doc raw"""
basis_matrix_of_rational_span(L::AbstractLat) -> MatElem
Return a basis matrix of the rational span of the lattice `L`.
"""
basis_matrix_of_rational_span(L::AbstractLat) = matrix(pseudo_matrix(L))
@doc raw"""
base_field(L::AbstractLat) -> Field
Return the algebra over which the rational span of the lattice `L` is defined.
"""
base_field(L::AbstractLat) = L.base_algebra
@doc raw"""
base_ring(L::AbstractLat) -> Ring
Return the order over which the lattice `L` is defined.
"""
base_ring(L::AbstractLat) = base_ring(L.pmat)
@doc raw"""
fixed_field(L::AbstractLat) -> Field
Returns the fixed field of the involution of the lattice `L`.
"""
fixed_field(L::AbstractLat) = fixed_field(rational_span(L))
@doc raw"""
fixed_ring(L::AbstractLat) -> Ring
Return the maximal order in the fixed field of the lattice `L`.
"""
fixed_ring(L::AbstractLat) = maximal_order(fixed_field(L))
@doc raw"""
involution(L::AbstractLat) -> Map
Return the involution of the rational span of the lattice `L`.
"""
involution(::AbstractLat)
@doc raw"""
rank(L::AbstractLat) -> Int
Return the rank of the underlying module of the lattice `L`.
"""
rank(L::AbstractLat) = dim(rational_span(L))
@doc raw"""
degree(L::AbstractLat) -> Int
Return the dimension of the ambient space of the lattice `L`.
"""
function degree(L::AbstractLat)
if isdefined(L, :space)
return dim(L.space)
else
return ncols(L.pmat.matrix)
end
end
@doc raw"""
is_sublattice(L::AbstractLat, M::AbstractLat) -> Bool
Return whether `M` is a sublattice of the lattice `L`.
"""
function is_sublattice(L::AbstractLat, M::AbstractLat)
if L === M
return true
end
if ambient_space(L) != ambient_space(M)
return false
end
return _spans_subset_of_pseudohnf(pseudo_matrix(M), _pseudo_hnf(L), :lowerleft)
end
@doc raw"""
issubset(M::AbstractLat, L::AbstractLat) -> Bool
Return whether `M` is a subset of the lattice `L`.
"""
Base.issubset(M::AbstractLat, L::AbstractLat) = is_sublattice(L, M)
################################################################################
#
# Pseudo-HNF
#
################################################################################
# Return a lowerleft pseudo hnf
function _pseudo_hnf(L::AbstractLat)
get_attribute!(L, :pseudo_hnf) do
pseudo_hnf(pseudo_matrix(L), :lowerleft)
end::typeof(L.pmat)
end
################################################################################
#
# Equality and hash
#
################################################################################
function Base.:(==)(L::AbstractLat, M::AbstractLat)
if L === M
return true
end
if ambient_space(L) != ambient_space(M)
return false
end
return pseudo_hnf(pseudo_matrix(L), :lowerleft) == pseudo_hnf(pseudo_matrix(M), :lowerleft)
end
function Base.hash(L::AbstractLat, u::UInt)
V = ambient_space(L)
B = _pseudo_hnf(L)
# Pseudo-hnf are unique for lattices in a given space. Since we require that
# equal lattices lie in the same space, we just have to hash and compare the
# space and the pseudo lattice. Here equality for spaces is strong (`===`).
h = xor(hash(V), hash(B))
return xor(h, u)
end
################################################################################
#
# Gram matrix
#
################################################################################
@doc raw"""
gram_matrix_of_rational_span(L::AbstractLat) -> MatElem
Return the Gram matrix of the rational span of the lattice `L`.
"""
function gram_matrix_of_rational_span(L::AbstractLat)
if isdefined(L, :gram)
return L.gram
else
return gram_matrix(ambient_space(L), L.pmat.matrix)
end
end
################################################################################
#
# Generators
#
################################################################################
# Check if one really needs minimal
# Steinitz form is not pretty
@doc raw"""
generators(L::AbstractLat; minimal = false) -> Vector{Vector}
Return a set of generators of the lattice `L` over the base ring of `L`.
If `minimal == true`, the number of generators is minimal. Note that computing
minimal generators is expensive.
"""
function generators(L::AbstractLat; minimal::Bool = false)
K = nf(base_ring(L))
T = elem_type(K)
if !minimal
if isdefined(L, :generators)
return L.generators::Vector{Vector{T}}
end
v = Vector{T}[]
St = pseudo_matrix(L)
d = ncols(St)
for i in 1:nrows(St)
if base_ring(L) isa AbsSimpleNumFieldOrder
I = numerator(coefficient_ideals(St)[i])
den = denominator(coefficient_ideals(St)[i])
_assure_weakly_normal_presentation(I)
push!(v, T[K(I.gen_one)//den * matrix(St)[i, j] for j in 1:d])
push!(v, T[K(I.gen_two)//den * matrix(St)[i, j] for j in 1:d])
else
I = numerator(coefficient_ideals(St)[i])
den = denominator(coefficient_ideals(St)[i])
for g in absolute_basis(I)
push!(v, T[K(g)//den * matrix(St)[i, j] for j in 1:d])
end
end
end
L.generators = v
return v
else # minimal
if isdefined(L, :minimal_generators)
return L.minimal_generators::Vector{Vector{T}}
end
St = steinitz_form(pseudo_matrix(L))
d = nrows(St)
n = degree(L)
v = Vector{T}[]
for i in 1:(d - 1)
#@assert is_principal(coefficient_ideals(St)[i])[1]
push!(v, T[matrix(St)[i, j] for j in 1:d])
end
I = numerator(coefficient_ideals(St)[d])
den = denominator(coefficient_ideals(St)[d])
if minimal && base_ring(L) isa AbsSimpleNumFieldOrder
b, a = is_principal_with_data(I)
if b
push!(v, T[K(a)//den * matrix(St)[n, j] for j in 1:d])
end
return v
end
if base_ring(L) isa AbsSimpleNumFieldOrder
_assure_weakly_normal_presentation(I)
push!(v, T[K(I.gen_one)//den * matrix(St)[n, j] for j in 1:d])
push!(v, T[K(I.gen_two)//den * matrix(St)[n, j] for j in 1:d])
else
for g in absolute_basis(I)
push!(v, T[K(g)//den * matrix(St)[n, j] for j in 1:d])
end
end
end
L.minimal_generators = v
return v
end
###############################################################################
#
# Constructors
#
###############################################################################
@doc raw"""
lattice(V::AbstractSpace, B::PMat ; check::Bool = true) -> AbstractLat
Given an ambient space `V` and a pseudo-matrix `B`, return the lattice spanned
by the pseudo-matrix `B` inside `V`. If `V` is hermitian (resp. quadratic) then
the output is a hermitian (resp. quadratic) lattice.
By default, `B` is checked to be of full rank. This test can be disabled by setting
`check` to false.
"""
lattice(V::AbstractSpace, B::PMat ; check::Bool = true)
@doc raw"""
lattice(V::AbstractSpace, basis::MatElem ; check::Bool = true) -> AbstractLat
Given an ambient space `V` and a matrix `basis`, return the lattice spanned
by the rows of `basis` inside `V`. If `V` is hermitian (resp. quadratic) then
the output is a hermitian (resp. quadratic) lattice.
By default, `basis` is checked to be of full rank. This test can be disabled by setting
`check` to false.
"""
lattice(V::AbstractSpace, basis::MatElem ; check::Bool = true) = lattice(V, pseudo_matrix(basis); check)
@doc raw"""
lattice(V::AbstractSpace, gens::Vector) -> AbstractLat
Given an ambient space `V` and a list of generators `gens`, return the lattice
spanned by `gens` in `V`. If `V` is hermitian (resp. quadratic) then the output
is a hermitian (resp. quadratic) lattice.
If `gens` is empty, the function returns the zero lattice in `V`.
"""
function lattice(V::Hecke.AbstractSpace, _gens::Vector)
if length(_gens) == 0
pm = pseudo_matrix(matrix(base_ring(V), 0, dim(V), []))
return lattice(V, pm; check = false)
end
@assert length(_gens[1]) > 0
@req all(v -> length(v) == length(_gens[1]), _gens) "All vectors in gens must be of the same length"
@req length(_gens[1]) == dim(V) "Incompatible arguments: the length of the elements of gens must correspond to the dimension of V"
F = base_ring(V)
gens = [map(F, v) for v in _gens]
M = zero_matrix(F, length(gens), length(gens[1]))
for i=1:nrows(M)
for j=1:ncols(M)
M[i,j] = gens[i][j]
end
end
pm = pseudo_hnf(pseudo_matrix(M), :lowerleft)
i = 1
while is_zero_row(pm.matrix, i)
i += 1
end
pm = sub(pm, i:nrows(pm), 1:ncols(pm))
L = lattice(V, pm; check = false)
L.generators = gens
return L
end
@doc raw"""
lattice(V::AbstractSpace) -> AbstractLat
Given an ambient space `V`, return the lattice with the standard basis
matrix. If `V` is hermitian (resp. quadratic) then the output is a hermitian
(resp. quadratic) lattice.
"""
lattice(V::AbstractSpace) = lattice(V, identity_matrix(base_ring(V), rank(V)); check = false)
################################################################################
#
# Gram matrix of generators
#
################################################################################
@doc raw"""
gram_matrix_of_generators(L::AbstractLat; minimal::Bool = false) -> MatElem
Return the Gram matrix of a generating set of the lattice `L`.
If `minimal == true`, then a minimal generating set is used. Note that computing
minimal generators is expensive.
"""
function gram_matrix_of_generators(L::AbstractLat; minimal::Bool = false)
m = generators(L; minimal)
M = matrix(nf(base_ring(L)), m)
return gram_matrix(ambient_space(L), M)
end
################################################################################
#
# Discriminant
#
################################################################################
@doc raw"""
discriminant(L::AbstractLat) -> AbsSimpleNumFieldOrderFractionalIdeal
Return the discriminant of the lattice `L`, that is, the generalized index ideal
$[L^\# : L]$.
"""
function discriminant(L::AbstractLat)
d = det(gram_matrix_of_rational_span(L))
v = involution(L)
C = coefficient_ideals(L)
I = prod(C; init = one(base_field(L))*base_ring(L))
return d * I * v(I)
end
################################################################################
#
# Rational (local) isometry
#
################################################################################
@doc raw"""
hasse_invariant(L::AbstractLat, p::Union{InfPlc, AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}}) -> Int
Return the Hasse invariant of the rational span of the lattice `L` at the place `p`.
The lattice must be quadratic.
"""
hasse_invariant(L::AbstractLat, p)
@doc raw"""
witt_invariant(L::AbstractLat, p::Union{InfPlc, AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}}) -> Int
Return the Witt invariant of the rational span of the lattice `L` at the place `p`.
The lattice must be quadratic.
"""
witt_invariant(L::AbstractLat, p)
################################################################################
#
# Rational isometry
#
################################################################################
@doc raw"""
is_rationally_isometric(L::AbstractLat, M::AbstractLat, p::Union{InfPlc, AbsNumFieldOrderIdeal})
-> Bool
Return whether the rational spans of the lattices `L` and `M` are isometric over
the completion at the place `p`.
"""
is_rationally_isometric(::AbstractLat, ::AbstractLat, ::AbsNumFieldOrderIdeal)
function is_rationally_isometric(L::AbstractLat, M::AbstractLat, p::AbsNumFieldOrderIdeal)
return is_isometric(rational_span(L), rational_span(M), p)
end
function is_rationally_isometric(L::AbstractLat, M::AbstractLat, p::InfPlc)
return is_isometric(rational_span(L), rational_span(M), p)
end
@doc raw"""
is_rationally_isometric(L::AbstractLat, M::AbstractLat) -> Bool
Return whether the rational spans of the lattices `L` and `M` are isometric.
"""
function is_rationally_isometric(L::AbstractLat, M::AbstractLat)
return is_isometric(rational_span(L), rational_span(M))
end
################################################################################
#
# Definiteness
#
################################################################################
@doc raw"""
is_positive_definite(L::AbstractLat) -> Bool
Return whether the rational span of the lattice `L` is positive definite.
"""
is_positive_definite(L::AbstractLat) = is_positive_definite(rational_span(L))
@doc raw"""
is_negative_definite(L::AbstractLat) -> Bool
Return whether the rational span of the lattice `L` is negative definite.
"""
is_negative_definite(L::AbstractLat) = is_negative_definite(rational_span(L))
@doc raw"""
is_definite(L::AbstractLat) -> Bool
Return whether the rational span of the lattice `L` is definite.
"""
@attr Bool is_definite(L::AbstractLat) = is_definite(rational_span(L))
@doc raw"""
can_scale_totally_positive(L::AbstractLat) -> Bool, NumFieldElem
Return whether there is a totally positive rescaled lattice of the lattice `L`.
If so, the second returned value is an element $a$ such that $L^a$ is totally positive.
"""
function can_scale_totally_positive(L::AbstractLat)
a = _isdefinite(rational_span(L))
if iszero(a)
return false, a
else
return true, a
end
end
################################################################################
#
# Addition
#
################################################################################
# Some of these assertions can be relaxed, in particular in the scaling
@doc raw"""
+(L::AbstractLat, M::AbstractLat) -> AbstractLat
Return the sum of the lattices `L` and `M`.
The lattices `L` and `M` must have the same ambient space.
"""
Base.:(+)(::AbstractLat, ::AbstractLat)
function Base.:(+)(L::T, M::T) where {T <: AbstractLat}
@assert has_ambient_space(L) && has_ambient_space(M)
@assert ambient_space(L) === ambient_space(M)
V = ambient_space(L)
fr = nrows(pseudo_matrix(L)) == dim(V) || nrows(pseudo_matrix(M)) == dim(V)
m = _sum_modules(L, pseudo_matrix(L), pseudo_matrix(M), fr)
return lattice_in_same_ambient_space(L, m)
end
################################################################################
#
# Intersection
#
################################################################################
@doc raw"""
intersect(L::AbstractLat, M::AbstractLat) -> AbstractLat
Return the intersection of the lattices `L` and `M`.
The lattices `L` and `M` must have the same ambient space.
"""
intersect(::AbstractLat, ::AbstractLat)
function intersect(L::T, M::T) where T <: AbstractLat
@assert has_ambient_space(L) && has_ambient_space(M)
@req ambient_space(L) === ambient_space(M) "Lattices must be in the same ambient space"
V = ambient_space(L)
fr = nrows(pseudo_matrix(L)) == dim(V) && nrows(pseudo_matrix(M)) == dim(V)
if !fr
return _intersect_via_restriction_of_scalars(L, M)
end
m = _intersect_modules(L, pseudo_matrix(L), pseudo_matrix(M), fr)
return lattice_in_same_ambient_space(L, m)
end
function _intersect_via_restriction_of_scalars(L::AbstractLat, M::AbstractLat)
@assert has_ambient_space(L) && has_ambient_space(M)
@assert ambient_space(L) === ambient_space(M)
@assert !(L isa ZZLat)
Lres, f = restrict_scalars_with_map(L, FlintQQ)
Mres = restrict_scalars(M, f)
Nres = intersect(Lres, Mres)
Bres = basis_matrix(Nres)
gens = [f(vec(collect(Bres[i,:]))) for i in 1:nrows(Bres)]
return lattice(ambient_space(L), gens)
end
################################################################################
#
# Scalar multiplication
#
################################################################################
@doc raw"""
*(a::NumFieldElem, L::AbstractLat) -> AbstractLat
Return the lattice $aL$ inside the ambient space of the lattice `L`.
"""
function Base.:(*)(a::NumFieldElem, L::AbstractLat)
@assert has_ambient_space(L)
O = maximal_order(parent(a))
m = _module_scale_ideal(a*O, pseudo_matrix(L))
return lattice_in_same_ambient_space(L, m)
end
function Base.:(*)(L::QuadLat, a)
return a * L
end
@doc raw"""
*(a::NumFieldOrderIdeal, L::AbstractLat) -> AbstractLat
Return the lattice $aL$ inside the ambient space of the lattice `L`.
"""
Base.:(*)(::NumFieldOrderIdeal, ::AbstractLat)
function Base.:(*)(a::Union{RelNumFieldOrderIdeal, AbsNumFieldOrderIdeal}, L::AbstractLat)
@assert has_ambient_space(L)
m = _module_scale_ideal(a, pseudo_matrix(L))
return lattice_in_same_ambient_space(L, m)
end
@doc raw"""
*(a::NumFieldOrderFractionalIdeal, L::AbstractLat) -> AbstractLat
Return the lattice $aL$ inside the ambient space of the lattice `L`.
"""
Base.:(*)(::NumFieldOrderFractionalIdeal, ::AbstractLat)
function Base.:(*)(a::Union{RelNumFieldOrderFractionalIdeal, AbsNumFieldOrderFractionalIdeal}, L::AbstractLat)
@assert has_ambient_space(L)
m = _module_scale_ideal(a, pseudo_matrix(L))
return lattice_in_same_ambient_space(L, m)
end
################################################################################
#
# Absolute basis
#
################################################################################
@doc raw"""
absolute_basis(L::AbstractLat) -> Vector
Return a $\mathbf{Z}$-basis of the lattice `L`.
"""
function absolute_basis(L::AbstractLat)
pb = pseudo_basis(L)
z = Vector{Vector{elem_type(base_field(L))}}()
for (v, a) in pb
for w in absolute_basis(a)
push!(z, w .* v)
end
end
@assert length(z) == absolute_degree(base_field(L)) * rank(L)
return z
end
################################################################################
#
# Absolute basis matrix
#
################################################################################
@doc raw"""
absolute_basis_matrix(L::AbstractLat) -> MatElem
Return a $\mathbf{Z}$-basis matrix of the lattice `L`.
"""
function absolute_basis_matrix(L::AbstractLat)
pb = pseudo_basis(L)
E = base_field(L)
c = ncols(matrix(pseudo_matrix(L)))
z = zero_matrix(E, rank(L) * absolute_degree(E), c)
k = 1
for (v, a) in pb
for w in absolute_basis(a)
for j in 1:c
z[k, j] = w * v[j]
end
k += 1
end
end
return z
end
################################################################################
#
# Norm
#
################################################################################
@doc raw"""
norm(L::AbstractLat) -> AbsNumFieldOrderFractionalIdeal
Return the norm of the lattice `L`. This is a fractional ideal of the fixed field
of `L`.
"""
norm(::AbstractLat)
################################################################################
#
# Scale
#
################################################################################
@doc raw"""
scale(L::AbstractLat) -> AbsSimpleNumFieldOrderFractionalIdeal
Return the scale of the lattice `L`.
"""
scale(L::AbstractLat)
################################################################################
#
# Rescale
#
################################################################################
@doc raw"""
rescale(L::AbstractLat, a::NumFieldElem) -> AbstractLat
Return the rescaled lattice $L^a$. Note that this has a different ambient
space than the lattice `L`.
"""
rescale(::AbstractLat, ::NumFieldElem)
Base.:(^)(L::AbstractLat, a::RingElement) = rescale(L, a)
################################################################################
#
# Is integral
#
################################################################################
@doc raw"""
is_integral(L::AbstractLat) -> Bool
Return whether the lattice `L` is integral.
"""
function is_integral(L::AbstractLat)
return is_integral(scale(L))
end
################################################################################
#
# Dual lattice
#
################################################################################
@doc raw"""
dual(L::AbstractLat) -> AbstractLat
Return the dual lattice of the lattice `L`.
"""
dual(::AbstractLat)
################################################################################
#
# Volume
#
################################################################################
@doc raw"""
volume(L::AbstractLat) -> AbsSimpleNumFieldOrderFractionalIdeal
Return the volume of the lattice `L`.
"""
function volume(L::AbstractLat)
return discriminant(L)
end
################################################################################
#
# Modularity
#
################################################################################
@doc raw"""
is_modular(L::AbstractLat) -> Bool, AbsSimpleNumFieldOrderFractionalIdeal
Return whether the lattice `L` is modular. In this case, the second returned value
is a fractional ideal $\mathfrak a$ of the base algebra of `L` such that
$\mathfrak a L^\# = L$, where $L^\#$ is the dual of `L`.
"""
function is_modular(L::AbstractLat)
a = scale(L)
if volume(L) == a^rank(L)
return true, a
else
return false, a
end
end
@doc raw"""
is_modular(L::AbstractLat, p) -> Bool, Int
Return whether the completion $L_{p}$ of the lattice `L` at the prime ideal or
integer `p` is modular. If it is the case the second returned value is an
integer `v` such that $L_{p}$ is $p^v$-modular.
"""
is_modular(::AbstractLat, p)
function is_modular(L::AbstractLat{<: NumField}, p)
a = scale(L)
if base_ring(L) == order(p)
v = valuation(a, p)
if v * rank(L) == valuation(volume(L), p)
return true, v
else
return false, 0
end
else
@assert base_ring(base_ring(L)) == order(p)
q = prime_decomposition(base_ring(L), p)[1][1]
v = valuation(a, q)
if v * rank(L) == valuation(volume(L), q)
return true, v
else
return false, 0
end
end
end
################################################################################
#
# Local basis matrix
#
################################################################################
@doc raw"""
local_basis_matrix(L::AbstractLat, p::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}; type = :any) -> MatElem
Given a prime ideal `p` and a lattice `L`, return a basis matrix of a lattice
`M` such that $M_{p} = L_{p}$. Note that if `p` is an ideal in the base ring of
`L`, the completions are taken at the minimum of `p` (which is an ideal in the
base ring of the order of `p`).
- If `type == :submodule`, the lattice `M` will be a sublattice of `L`.
- If `type == :supermodule`, the lattice `M` will be a superlattice of `L`.
- If `type == :any`, there may not be any containment relation between `M` and
`L`.
"""
function local_basis_matrix(L::AbstractLat, p; type::Symbol = :any)
R = base_ring(L)
S = order(p)
if R === S
return local_basis_matrix(L, minimum(p), type = type)
#if type == :any
# return _local_basis_matrix(pseudo_matrix(L), p)
#elseif type == :submodule
# return _local_basis_submodule_matrix(pseudo_matrix(L), p)
#elseif type == :supermodule
# return _local_basis_supermodule_matrix(pseudo_matrix(L), p)
#else
# error("""Invalid :type keyword :$(type).
# Must be either :any, :submodule, or :supermodule""")
#end
elseif S === base_ring(R)
if type == :any
return _local_basis_matrix_prime_below(pseudo_matrix(L), p)
elseif type == :submodule
return _local_basis_matrix_prime_below_submodule(pseudo_matrix(L), p)
elseif type == :supermodule
throw(NotImplemented())
else
error("""Invalid :type keyword :$(type).
Must be either :any, :submodule, or :supermodule""")
end
else
error("Something wrong")
end
end
################################################################################
#
# Jordan decomposition
#
################################################################################
@doc raw"""
jordan_decomposition(L::AbstractLat, p::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
-> Vector{MatElem}, Vector{MatElem}, Vector{Int}
Return a Jordan decomposition of the completion of the lattice `L` at a prime
ideal `p`.
The returned value consists of three lists $(M_i)_i$, $(G_i)_i$ and $(s_i)_i$ of
the same length $r$. The completions of the row spans of the matrices $M_i$
yield a Jordan decomposition of $L_{p}$ into modular sublattices
$L_i$ with Gram matrices $G_i$ and scale of $p$-adic valuation $s_i$.
"""
jordan_decomposition(L::AbstractLat, p::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
################################################################################
#
# Local isometry
#
################################################################################
@doc raw"""
is_locally_isometric(L::AbstractLat, M::AbstractLat, p::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}) -> Bool
Return whether the completions of the lattices `L` and `M` at the prime ideal
`p` are isometric.
"""
is_locally_isometric(::AbstractLat, ::AbstractLat, ::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
################################################################################
#
# Isotropy
#
################################################################################
@doc raw"""
is_isotropic(L::AbstractLat, p::Union{AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}, InfPlc}) -> Bool
Return whether the completion of the lattice `L` at the place `p` is
isotropic.
"""
is_isotropic(L::AbstractLat, p) = is_isotropic(rational_span(L), p)
################################################################################
#
# Restrict scalars
#
################################################################################
@doc raw"""
restrict_scalars(L::AbstractLat, K::QQField,
alpha::FieldElem = one(base_field(L))) -> ZZLat
Given a lattice `L` in a space $(V, \Phi)$, return the $\mathcal O_K$-lattice
obtained by restricting the scalars of $(V, \alpha\Phi)$ to the number field `K`.
The rescaling factor $\alpha$ is set to 1 by default.
Note that for now one can only restrict scalars to $\mathbb Q$.
"""
function restrict_scalars(L::AbstractLat, K::QQField,
alpha::FieldElem = one(base_field(L)))
V = ambient_space(L)
Vabs, f = restrict_scalars(V, K, alpha)
Babs = absolute_basis(L)
Mabs = zero_matrix(FlintQQ, length(Babs), rank(Vabs))
for i in 1:length(Babs)
v = f\(Babs[i])
for j in 1:length(v)
Mabs[i, j] = v[j]
end
end
return ZZLat(Vabs, Mabs)
end
@doc raw"""
restrict_scalars_with_map(L::AbstractLat, K::QQField,
alpha::FieldElem = one(base_field(L)))
-> Tuple{ZZLat, AbstractSpaceRes}
Given a lattice `L` in a space $(V, \Phi)$, return the $\mathcal O_K$-lattice
obtained by restricting the scalars of $(V, \alpha\Phi)$ to the number field `K`,
together with the map `f` for extending scalars back.
The rescaling factor $\alpha$ is set to 1 by default.
Note that for now one can only restrict scalars to $\mathbb Q$.
"""
function restrict_scalars_with_map(L::AbstractLat, K::QQField,
alpha::FieldElem = one(base_field(L)))
V = ambient_space(L)
Vabs, f = restrict_scalars(V, K, alpha)
Babs = absolute_basis(L)
Mabs = zero_matrix(FlintQQ, length(Babs), rank(Vabs))
for i in 1:length(Babs)
v = f\(Babs[i])
for j in 1:length(v)
Mabs[i, j] = v[j]
end
end
return ZZLat(Vabs, Mabs), f