-
Notifications
You must be signed in to change notification settings - Fork 61
/
Torsion.jl
2265 lines (1943 loc) · 71.3 KB
/
Torsion.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
################################################################################
#
# Construction
#
################################################################################
# compute the torsion quadratic module M/N
@doc raw"""
torsion_quadratic_module(M::ZZLat, N::ZZLat; gens::Union{Nothing, Vector{<:Vector}} = nothing,
snf::Bool = true,
modulus::RationalUnion = QQFieldElem(0),
modulus_qf::RationalUnion = QQFieldElem(0),
check::Bool = true) -> TorQuadModule
Given a Z-lattice $M$ and a sublattice $N$ of $M$, return the torsion quadratic
module $M/N$.
If `gens` is set, the images of `gens` will be used as the
generators of the abelian group $M/N$.
If `snf` is `true`, the underlying abelian group will be in Smith normal form.
Otherwise, the images of the basis of $M$ will be used as the generators.
One can decide on the modulus for the associated finite bilinear and quadratic
forms by setting `modulus` and `modulus_qf` respectively to the desired values.
"""
function torsion_quadratic_module(M::ZZLat, N::ZZLat; gens::Union{Nothing, Vector{<:Vector}} = nothing,
snf::Bool = true,
modulus::RationalUnion = QQFieldElem(0),
modulus_qf::RationalUnion = QQFieldElem(0),
check::Bool = true)
@req ambient_space(M) === ambient_space(N) """
Lattices must have same ambient space
"""
fl, _rels = is_sublattice_with_relations(M, N)
@req fl "Second lattice must be a sublattice of first lattice"
rels = change_base_ring(FlintZZ, _rels)
A = abelian_group(rels)
n = dim(ambient_space(M))
BM = basis_matrix(M)
if gens !== nothing && length(gens) > 0
gens_in_A = elem_type(A)[]
for g in gens
@req length(g) == n "Generator not an element of the ambient space"
fl, v = can_solve_with_solution(BM,
matrix(FlintQQ, 1, n, g);
side = :left)
@req denominator(v) == 1 "Generator not an element of the lattice"
ginA = A(change_base_ring(FlintZZ, v))
push!(gens_in_A, ginA)
end
S, mS = sub(A, gens_in_A, false)
if check
if order(S) != order(A)
throw(ArgumentError("Generators do not generate the torsion module"))
end
end
else
if snf
S, mS = Hecke.snf(A)
else
S, mS = A, id_hom(A)
end
end
# mS : S -> A
# generators of S lifted along M -> M/N = A -> S
if gens !== nothing && length(gens) > 0
gens_lift = gens
else
gens_lift = Vector{QQFieldElem}[reshape(collect(change_base_ring(FlintQQ, mS(s).coeff) * BM), :) for s in Hecke.gens(S)]
end
num = basis_matrix(M) * gram_matrix(ambient_space(M)) * transpose(basis_matrix(N))
if iszero(modulus)
_modulus = reduce(gcd, num; init = zero(QQFieldElem))
else
_modulus = QQ(modulus)
end
norm = reduce(gcd, diagonal(gram_matrix(N)); init = zero(QQFieldElem))
if iszero(modulus_qf)
_modulus_qf = gcd(norm, 2 * _modulus)
else
_modulus_qf = QQ(modulus_qf)
end
T = TorQuadModule()
T.cover = M
T.rels = N
T.ab_grp = S
T.proj = inv(mS).map
T.gens_lift = gens_lift
T.gens_lift_mat = matrix(FlintQQ, length(gens_lift), degree(M), reduce(vcat, gens_lift; init = QQFieldElem[]))
T.modulus = _modulus
T.modulus_qf = _modulus_qf
T.value_module = QmodnZ(_modulus)
T.value_module_qf = QmodnZ(_modulus_qf)
T.is_normal = false
return T
end
@doc raw"""
discriminant_group(L::ZZLat) -> TorQuadModule
Return the discriminant group of `L`.
The discriminant group of an integral lattice `L` is the finite abelian
group `D = dual(L)/L`.
It comes equipped with the discriminant bilinear form
$$D \times D \to \mathbb{Q} / \mathbb{Z} \qquad (x,y) \mapsto \Phi(x,y) + \mathbb{Z}.$$
If `L` is even, then the discriminant group is equipped with the discriminant
quadratic form $D \to \mathbb{Q} / 2 \mathbb{Z}, x \mapsto \Phi(x,x) + 2\mathbb{Z}$.
"""
@attr TorQuadModule function discriminant_group(L::ZZLat)
@req is_integral(L) "The lattice must be integral"
if rank(L) == 0
T = torsion_quadratic_module(dual(L), L; modulus = one(QQ), modulus_qf = QQ(2))
else
T = torsion_quadratic_module(dual(L), L)
end
set_attribute!(T, :is_degenerate => false)
return T
end
@doc raw"""
order(T::TorQuadModule) -> ZZRingElem
Return the order of `T`
"""
function order(T::TorQuadModule)
return order(abelian_group(T))
end
@doc raw"""
exponent(T::TorQuadModule) -> ZZRingElem
Return the exponent of `T`
"""
function exponent(T::TorQuadModule)
return exponent(abelian_group(T))
end
@doc raw"""
elementary_divisors(T::TorQuadModule) -> Vector{ZZRingElem}
Return the elementary divisors of underlying abelian group of `T`.
"""
function elementary_divisors(T::TorQuadModule)
return elementary_divisors(abelian_group(T))
end
################################################################################
#
# Basic field access
#
################################################################################
@doc raw"""
abelian_group(T::TorQuadModule) -> FinGenAbGroup
Return the underlying abelian group of `T`.
"""
abelian_group(T::TorQuadModule) = T.ab_grp
@doc raw"""
cover(T::TorQuadModule) -> ZZLat
For $T=M/N$ this returns $M$.
"""
cover(T::TorQuadModule) = T.cover
@doc raw"""
relations(T::TorQuadModule) -> ZZLat
For $T=M/N$ this returns $N$.
"""
relations(T::TorQuadModule) = T.rels
@doc raw"""
value_module(T::TorQuadModule) -> QmodnZ
Return the value module `Q/nZ` of the bilinear form of `T`.
"""
value_module(T::TorQuadModule) = T.value_module
@doc raw"""
value_module_quadratic_form(T::TorQuadModule) -> QmodnZ
Return the value module `Q/mZ` of the quadratic form of `T`.
"""
value_module_quadratic_form(T::TorQuadModule) = T.value_module_qf
@doc raw"""
modulus_bilinear_form(T::TorQuadModule) -> QQFieldElem
Return the modulus of the value module of the bilinear form of`T`.
"""
modulus_bilinear_form(T::TorQuadModule) = T.modulus
@doc raw"""
modulus_quadratic_form(T::TorQuadModule) -> QQFieldElem
Return the modulus of the value module of the quadratic form of `T`.
"""
modulus_quadratic_form(T::TorQuadModule) = T.modulus_qf
################################################################################
#
# Gram matrices
#
################################################################################
@doc raw"""
gram_matrix_bilinear(T::TorQuadModule) -> QQMatrix
Return the gram matrix of the bilinear form of `T`.
"""
function gram_matrix_bilinear(T::TorQuadModule)
if isdefined(T, :gram_matrix_bilinear)
return T.gram_matrix_bilinear
end
g = gens(T)
G = zero_matrix(FlintQQ, length(g), length(g))
for i in 1:length(g)
for j in 1:i
G[i, j] = G[j, i] = lift(g[i] * g[j])
end
end
T.gram_matrix_bilinear = G
return G
end
@doc raw"""
gram_matrix_quadratic(T::TorQuadModule) -> QQMatrix
Return the 'gram matrix' of the quadratic form of `T`.
The off diagonal entries are given by the bilinear form whereas the
diagonal entries are given by the quadratic form.
"""
function gram_matrix_quadratic(T::TorQuadModule)
if isdefined(T, :gram_matrix_quadratic)
return T.gram_matrix_quadratic
end
g = gens(T)
r = length(g)
G = zero_matrix(FlintQQ, r, r)
for i in 1:r
for j in 1:(i - 1)
G[i, j] = G[j, i] = lift(g[i] * g[j])
end
G[i, i] = lift(quadratic_product(g[i]))
end
T.gram_matrix_quadratic = G
return G
end
################################################################################
#
# I/O
#
################################################################################
# TODO: Print like abelian group
function Base.show(io::IO, ::MIME"text/plain" , T::TorQuadModule)
io = pretty(io)
println(io, "Finite quadratic module")
println(io, Indent(), "over integer ring")
print(io, Dedent())
print(io, "Abelian group: ")
show_snf_structure(io, snf(abelian_group(T))[1])
println(io)
println(io, "Bilinear value module: ", value_module(T))
println(io, "Quadratic value module: ", value_module_quadratic_form(T))
println(io, "Gram matrix quadratic form: ")
show(io, MIME"text/plain"() , gram_matrix_quadratic(T))
end
function Base.show(io::IO, T::TorQuadModule)
if is_terse(io)
print(io, "Finite quadratic module")
else
print(io, "Finite quadratic module: ")
show_snf_structure(io, snf(abelian_group(T))[1])
print(io, " -> ", value_module_quadratic_form(T))
end
end
################################################################################
#
# Elements
#
################################################################################
elem_type(::Type{TorQuadModule}) = TorQuadModuleElem
###############################################################################
#
# Creation
#
###############################################################################
@doc raw"""
(T::TorQuadModule)(a::FinGenAbGroupElem) -> TorQuadModuleElem
Coerce `a` to `T`.
```jldoctest
julia> R = rescale(root_lattice(:D,4),2);
julia> T = discriminant_group(R);
julia> A = abelian_group(T)
(Z/2)^2 x (Z/4)^2
julia> a = rand(A);
julia> A(T(a)) == a
true
```
"""
function (T::TorQuadModule)(a::FinGenAbGroupElem)
@req abelian_group(T) === parent(a) "Parents do not match"
return TorQuadModuleElem(T, a)
end
# Coerces an element of the ambient space of cover(T) to T
@doc raw"""
(T::TorQuadModule)(v::Vector) -> TorQuadModuleElem
Coerce `v` to `T`.
For `T = M/N` this assumes that `v` lives in the ambient space of `M`
and $v \in M$.
"""
function (T::TorQuadModule)(v::Vector)
@req length(v) == dim(ambient_space(cover(T))) "Vector of wrong length"
vv = map(FlintQQ, v)
if eltype(vv) != QQFieldElem
error("Cannot coerce elements to the rationals")
end
return T(vv::Vector{QQFieldElem})
end
function (T::TorQuadModule)(v::Vector{QQFieldElem})
@req length(v) == degree(cover(T)) "Vector of wrong length"
vv = matrix(FlintQQ, 1, length(v), v)
vv = change_base_ring(ZZ, solve(basis_matrix(cover(T)), vv; side = :left))
return T(abelian_group(T)(vv * T.proj))
end
################################################################################
#
# Printing
#
################################################################################
function Base.show(io::IO, ::MIME"text/plain", a::TorQuadModuleElem)
io = pretty(io)
T = parent(a)
println(io, "Element")
print(io, Indent(), "of ", Lowercase(), T)
println(io, Dedent())
comps = a.data.coeff
if length(comps) == 1
print(io, "with component ", comps)
else
print(io, "with components ", comps)
end
end
function show(io::IO, a::TorQuadModuleElem)
if is_terse(io)
print(io, "Element of finite quadratic module")
else
print(terse(io), a.data.coeff)
end
end
################################################################################
#
# Equalities and hashes
#
################################################################################
# To compare torsion quadratic module defined by quotients of lattices (defined
# in a same quadratic space), we just compare the top and the bottom lattices as
# embedded in the fixed ambient space.
# Of course, for a similar quotient one could mix up change the moduli for the
# given form, so we require those moduli to agree on both sides.
function Base.:(==)(S::TorQuadModule, T::TorQuadModule)
modulus_bilinear_form(S) != modulus_bilinear_form(T) && return false
modulus_quadratic_form(S) != modulus_quadratic_form(T) && return false
relations(S) != relations(T) && return false
return cover(S) == cover(T)
end
# Follow precisely the equlity test above
function Base.hash(T::TorQuadModule, u::UInt)
u = Base.hash(modulus_bilinear_form(T), u)
u = Base.hash(modulus_quadratic_form(T), u)
u = Base.hash(relations(T), u)
return Base.hash(cover(T), u)
end
function Base.:(==)(a::TorQuadModuleElem, b::TorQuadModuleElem)
if parent(a) !== parent(b)
return false
else
return data(a) == data(b)
end
end
# Elements in the same parents and with the same data. Even though the equality
# of the parents is soft, the "data" comparison enforces strong equality of the
# parents (`===`) because of we want strong equality on the underlying abelian
# group structure.
function Base.hash(a::TorQuadModuleElem, u::UInt)
h = xor(hash(parent(a)), hash(data(a)))
return xor(h, u)
end
iszero(a::TorQuadModuleElem) = iszero(a.data)
################################################################################
#
# Generators
#
################################################################################
function gens(T::TorQuadModule)
if isdefined(T, :gens)
return T.gens::Vector{TorQuadModuleElem}
else
_gens = TorQuadModuleElem[T(g) for g in gens(abelian_group(T))]
T.gens = _gens
return _gens
end
end
number_of_generators(T::TorQuadModule) = length(T.gens_lift)
function gen(T::TorQuadModule, i::Int)
if isdefined(T, :gens)
return gens(T)[i]
end
return T(gen(abelian_group(T), i))
end
@doc raw"""
getindex(T::TorQuadModule, i::Int) -> TorQuadModuleElem
Return the `i`-th generator of `T`.
This is equivalent to `gens(T)[i]`.
# Example
```jldoctest
julia> R = rescale(root_lattice(:D,4),2);
julia> D = discriminant_group(R);
julia> D[1]
Element
of finite quadratic module: (Z/2)^2 x (Z/4)^2 -> Q/2Z
with components [1 0 0 0]
julia> D[2]
Element
of finite quadratic module: (Z/2)^2 x (Z/4)^2 -> Q/2Z
with components [0 1 0 0]
```
"""
getindex(T::TorQuadModule, i::Int) = gen(T, i)
parent(a::TorQuadModuleElem) = a.parent
@doc raw"""
data(a::TorQuadModuleElem) -> FinGenAbGroupElem
Return `a` as an element of the underlying abelian group.
"""
data(a::TorQuadModuleElem) = a.data
@doc raw"""
(A::FinGenAbGroup)(a::TorQuadModuleElem)
Return `a` as an element of the underlying abelian group.
# Example
```jldoctest
julia> R = rescale(root_lattice(:D,4),2);
julia> D = discriminant_group(R);
julia> A = abelian_group(D)
(Z/2)^2 x (Z/4)^2
julia> d = D[1]
Element
of finite quadratic module: (Z/2)^2 x (Z/4)^2 -> Q/2Z
with components [1 0 0 0]
julia> d == D(A(d))
true
```
"""
function (A::FinGenAbGroup)(a::TorQuadModuleElem)
@req A === abelian_group(parent(a)) "Parents do not match"
return a.data
end
@doc raw"""
id(T::TorQuadModule) -> TorQuadModuleElem
Return the identity element for the abelian group structure on `T`.
"""
id(T::TorQuadModule) = T(id(abelian_group(T)))
################################################################################
#
# Arithmetic of elements
#
################################################################################
function Base.:(+)(a::TorQuadModuleElem, b::TorQuadModuleElem)
@req parent(a) === parent(b) "Parents do not match"
T = parent(a)
return T(a.data + b.data)
end
function Base.:(-)(a::TorQuadModuleElem)
T = parent(a)
return T(-a.data)
end
function Base.:(-)(a::TorQuadModuleElem, b::TorQuadModuleElem)
@req parent(a) === parent(b) "Parents do not match"
T = parent(a)
return T(a.data - b.data)
end
function Base.:(*)(a::TorQuadModuleElem, b::ZZRingElem)
T = parent(a)
return T(a.data * b)
end
Base.:(*)(a::ZZRingElem, b::TorQuadModuleElem) = b * a
Base.:(*)(a::Integer, b::TorQuadModuleElem) = ZZRingElem(a) * b
Base.:(*)(a::TorQuadModuleElem, b::Integer) = b * a
################################################################################
#
# Inner product
#
################################################################################
function Base.:(*)(a::TorQuadModuleElem, b::TorQuadModuleElem)
T = parent(a)
z = inner_product(ambient_space(cover(T)), lift(a), lift(b))
return value_module(T)(z)
end
@doc raw"""
inner_product(a::TorQuadModuleElem, b::TorQuadModuleElem) -> QmodnZElem
Return the inner product of `a` and `b`.
"""
inner_product(a::TorQuadModuleElem, b::TorQuadModuleElem)=(a*b)
################################################################################
#
# Quadratic product
#
################################################################################
@doc raw"""
quadratic_product(a::TorQuadModuleElem) -> QmodnZElem
Return the quadratic product of `a`.
It is defined in terms of a representative:
for $b + M \in M/N=T$, this returns
$\Phi(b,b) + n \mathbb{Z}$.
"""
function quadratic_product(a::TorQuadModuleElem)
T = parent(a)
al = lift(a)
z = inner_product(ambient_space(cover(T)), al, al)
return value_module_quadratic_form(T)(z)
end
################################################################################
#
# Order
#
################################################################################
order(a::TorQuadModuleElem) = order(a.data)
################################################################################
#
# Lift
#
################################################################################
@doc raw"""
lift(a::TorQuadModuleElem) -> Vector{QQFieldElem}
Lift `a` to the ambient space of `cover(parent(a))`.
For $a + N \in M/N$ this returns the representative $a$.
"""
function lift(a::TorQuadModuleElem)
T = parent(a)
z = change_base_ring(FlintQQ, a.data.coeff) * T.gens_lift_mat
return QQFieldElem[z[1, i] for i in 1:ncols(z)]
end
@doc raw"""
representative(a::TorQuadModuleElem) -> Vector{QQFieldElem}
For $a + N \in M/N$ this returns the representative $a$.
An alias for `lift(a)`.
"""
representative(x::TorQuadModuleElem) = lift(x)
################################################################################
#
# Iterator
#
################################################################################
Base.length(T::TorQuadModule) = Int(order(T))
Base.IteratorSize(::Type{TorQuadModule}) = Base.HasLength()
Base.eltype(::Type{TorQuadModule}) = TorQuadModuleElem
function Base.iterate(T::TorQuadModule)
a, st = iterate(abelian_group(T))
return T(a), st
end
function Base.iterate(T::TorQuadModule, st::UInt)
st >= order(T) && return nothing
a, st = iterate(abelian_group(T), st)
return T(a), st
end
################################################################################
#
# Map between torsion quadratic modules
#
################################################################################
@doc raw"""
hom(T::TorQuadModule, S::TorQuadModule, M::ZZMatrix) -> TorQuadModuleMap
Given two torsion quadratic modules `T` and `S`, and a matrix `M` representing
an abelian group homomorphism between the underlying groups of `T` and `S`,
return the corresponding abelian group homomorphism between `T` and `S`.
"""
function hom(T::TorQuadModule, S::TorQuadModule, M::ZZMatrix)
map_ab = hom(abelian_group(T), abelian_group(S), M)
return TorQuadModuleMap(T, S, map_ab)
end
@doc raw"""
hom(T::TorQuadModule, s::TorQuadModule, img::Vector{TorQuadModuleElem})
-> TorQuadModuleMap
Given two torsion quadratic modules `T` and `S`, and a set of elements of `S`
containing as many elements as `ngens(T)`, return the abelian group homomorphism
between `T` and `S` mapping the generators of `T` to the elements of `img`.
"""
function hom(T::TorQuadModule, S::TorQuadModule, img::Vector{TorQuadModuleElem})
_img = FinGenAbGroupElem[]
@req length(img) == ngens(T) "Wrong number of elements"
for g in img
@req parent(g) === S "Elements have the wrong parent"
push!(_img, abelian_group(S)(g))
end
map_ab = hom(abelian_group(T), abelian_group(S), _img)
return TorQuadModuleMap(T, S, map_ab)
end
@doc raw"""
abelian_group_homomorphism(f::TorQuadModuleMap) -> FinGenAbGroupHom
Return the underlying abelian group homomorphism of `f`.
"""
abelian_group_homomorphism(f::TorQuadModuleMap) = f.map_ab
@doc raw"""
matrix(f::TorQuadModuleMap) -> ZZMatrix
Return the matrix defining the underlying abelian group homomorphism of `f`.
"""
matrix(f::TorQuadModuleMap) = matrix(abelian_group_homomorphism(f))
@doc raw"""
identity_map(T::TorQuadModule) -> TorQuadModuleMap
Return the identity map of `T`.
"""
function identity_map(T::TorQuadModule)
map_ab = id_hom(abelian_group(T))
return TorQuadModuleMap(T, T, map_ab)
end
@doc raw"""
trivial_morphism(T::TorQuadModule, U::TorQuadModule) -> TorQuadModuleMap
Return the abelian group homomorphism between `T` and `U` sending every
elements of `T` to the zero element of `U`.
"""
trivial_morphism(T::TorQuadModule, U::TorQuadModule) = hom(T, U, zero_matrix(ZZ, ngens(T), ngens(U)))
@doc raw"""
trivial_morphism(T::TorQuadModule) -> TorQuadModuleMap
Return the abelian group endomorphism of `T` sending every elements of `T`
to the zero element of `T`.
"""
trivial_morphism(T::TorQuadModule) = trivial_morphism(T, T)
@doc raw"""
zero(f::TorQuadModuleMap) -> TorQuadModuleMap
Given a map `f` between two torsion quadratic modules `T` and `U`,
return the trivial map between `T` and `U` (see [`trivial_morphism`](@ref)).
"""
zero(f::TorQuadModuleMap) = trivial_morphism(domain(f), codomain(f))
@doc raw"""
id_hom(T::TorQuadModule) -> TorQuadModuleMap
Alias for [`identity_map`](@ref).
"""
id_hom(T::TorQuadModule) = identity_map(T)
@doc raw"""
inv(f::TorQuadModuleMap) -> TorQuadModuleMap
Given a bijective abelian group homomorphism `f` between two torsion
quadratic modules, return the inverse of `f`.
"""
function inv(f::TorQuadModuleMap)
@req is_bijective(f) "Underlying map must be bijective"
map_ab = inv(f.map_ab)
return TorQuadModuleMap(codomain(f),domain(f),map_ab)
end
@doc raw"""
compose(f::TorQuadModuleMap, g::TorQuadModuleMap) -> TorQuadModuleMap
Given two abelian group homomorphisms $f\colon T \to S$ and
$g \colon S \to U$ between torsion quadratic modules, return the
composition $f\circ g\colon T \to U$.
"""
function compose(f::TorQuadModuleMap, g::TorQuadModuleMap)
@req codomain(f) == domain(g) "Codomain of the first map should agree with the domain of the second one"
map_ab = compose(f.map_ab, g.map_ab)
return TorQuadModuleMap(domain(f), codomain(g), map_ab)
end
@doc raw"""
image(f::TorQuadModuleMap, a::TorQuadModuleElem) -> TorQuadModuleElem
Given an abelian group homomorphism $f\colon T \to S$ between two torsion
quadratic modules, and given an element `a` of `T`, return the image
$f(a) \in S$.
"""
function image(f::TorQuadModuleMap, a::TorQuadModuleElem)
@req parent(a) === domain(f) "a must be an element of the domain of f"
A = abelian_group(domain(f))
return codomain(f)(f.map_ab(A(a)))
end
@doc raw"""
has_preimage_with_preimage(f::TorQuadModuleMap, b::TorQuadModuleElem)
-> Bool, TorQuadModuleElem
Given an abelian group homomorphism $f\colon T \to S$ between two
torsion quadratic modules, and given an element `b` of `S`, return
whether `b` is in the image of `T`. If it is the case, the function
also returns a preimage of `b` by `f`. Otherwise, it returns the
identity element in `T`.
"""
function has_preimage_with_preimage(f::TorQuadModuleMap, b::TorQuadModuleElem)
@req parent(b) === codomain(f) "b must be an element of the codomain of f"
ok, a = has_preimage_with_preimage(f.map_ab, data(b))
return ok, domain(f)(a)
end
@doc raw"""
preimage(f::TorQuadModuleMap, b::TorQuadModuleElem)
-> TorQuadModuleElem
Given an abelian group homomorphism `f` between two torsion quadratic
modules, and given an element `b` in the image of `f`, return a preimage
of `b` by `f`.
"""
function preimage(f::TorQuadModuleMap, a::TorQuadModuleElem)
ok, b = has_preimage_with_preimage(f, a)
@req ok "a is not in the image of f"
return b
end
@doc raw"""
is_bijective(f::TorQuadModuleMap) -> Bool
Return whether `f` is bijective.
"""
is_bijective(f::TorQuadModuleMap) = is_bijective(f.map_ab)
@doc raw"""
is_surjective(f::TorQuadModuleMap) -> Bool
Return whether `f` is surjective.
"""
is_surjective(f::TorQuadModuleMap) = is_surjective(f.map_ab)
@doc raw"""
is_injective(f::TorQuadModuleMap) -> Bool
Return whether `f` is injective.
"""
is_injective(f::TorQuadModuleMap) = is_injective(f.map_ab)
# Rely on the algorithm implemented for FinGenAbGroupHom
@doc raw"""
has_complement(i::TorQuadModuleMap) -> Bool, TorQuadModuleMap
Given a map representing the injection of a submodule $W$ of a torsion
quadratic module $T$, return whether $W$ has a complement $U$ in $T$.
If yes, it returns an injection $U \to T$.
Note: if such a $U$ exists, $W$ and $U$ are in direct sum inside $T$
but they are not necessarily orthogonal to each other.
"""
function has_complement(i::TorQuadModuleMap)
@req is_injective(i) "i must be injective"
T = codomain(i)
bool, jab = Hecke.has_complement(i.map_ab)
if !bool
return (false, sub(T, TorQuadModuleElem[])[2])
end
Qab = domain(jab)
Q, j = sub(T, TorQuadModuleElem[T(jab(a)) for a in gens(Qab)])
return (true, j)
end
@doc raw"""
kernel(f::TorQuadModuleMap) -> TorQuadModule, TorQuadModuleMap
Given an abelian group homomorphism `f` between two torsion quadratic modules `T`
and `U`, return the kernel `S` of `f` as well as the injection $S \to T$.
"""
function kernel(f::TorQuadModuleMap)
g = abelian_group_homomorphism(f)
Kg, KgtoA = kernel(g)
S, StoKg = snf(Kg)
return sub(domain(f), TorQuadModuleElem[domain(f)(KgtoA(StoKg(a))) for a in gens(S)])
end
################################################################################
#
# Arithmetic of maps
#
################################################################################
@doc raw"""
+(f::TorQuadModuleMap, g::TorQuadModuleMap) -> TorQuadModuleMap
Given two abelian group homomorphisms `f` and `g` between the same torsion
quadratic modules `T` and `U`, return the pointwise sum `h` of `f` and `g`
which sends every element `a` of `T` to $h(a) := f(a) + g(a)$.
"""
function Base.:(+)(f::TorQuadModuleMap, g::TorQuadModuleMap)
@req domain(f) === domain(g) "f and g must have the same domain"
@req codomain(f) === codomain(g) "f and g must have the same codomain"
hab = abelian_group_homomorphism(f) + abelian_group_homomorphism(g)
return TorQuadModuleMap(domain(f), codomain(f), hab)
end
@doc raw"""
-(f::TorQuadModuleMap) -> TorQuadModuleMap
Given an abelian group homomorphism `f` between two torsion quadratic modules
`T` and `U`, return the pointwise opposite morphism `h` of `f` which sends every
element `a` of `T` to $h(a) := -f(a)$.
"""
function Base.:(-)(f::TorQuadModuleMap)
hab = -abelian_group_homomorphism(f)
return TorQuadModuleMap(domain(f), codomain(f), hab)
end
@doc raw"""
-(f::TorQuadModuleMap, g::TorQuadModuleMap) -> TorQuadModuleMap
Given two abelian group homomorphisms `f` and `g` between the same torsion
quadratic modules `T` and `U`, return the pointwise difference `h` of `f` and
`g` which sends every element `a` of `T` to $h(a) := f(a) - g(a)$.
"""
function Base.:(-)(f::TorQuadModuleMap, g::TorQuadModuleMap)
@req domain(f) === domain(g) "f and g must have the same domain"
@req codomain(f) === codomain(g) "f and g must have the same codomain"
hab = abelian_group_homomorphism(f) - abelian_group_homomorphism(g)
return TorQuadModuleMap(domain(f), codomain(g), hab)
end
@doc raw"""
*(a::IntegerUnion, f::TorQuadModuleMap) -> TorQuadModuleMap
*(f::TorQuadModuleMap, a::IntegerUnion) -> TorQuadModuleMap
Given an abelian group homomorphism `f` between two torsion quadratic modules
`T` and `U`, return the pointwise $a$-twist morphism `h` of `f` which sends every
element `b` of `T` to $h(b) := a*f(b)$.
"""
function Base.:(*)(a::IntegerUnion, f::TorQuadModuleMap)
hab = a*abelian_group_homomorphism(f)
return TorQuadModuleMap(domain(f), codomain(f), hab)
end
Base.:(*)(f::TorQuadModuleMap, a::IntegerUnion) = a*f
@doc raw"""
^(f::TorQuadModuleMap, n::Integer) -> TorQuadModuleMap
Given an abelian group endomorphism `f` of a torsion quadratic module `T`
return the $n$-fold self-composition of `f`.
Note that `n` must be non-negative and $f^0$ is by default the identity map
of the domain of `f` (see [`identity_map`](@ref)).
"""
function Base.:^(f::TorQuadModuleMap, n::Integer)
@req n >= 0 "n must be a positive integer"
@assert domain(f) === codomain(f) "f must be a self-map"
hab = abelian_group_homomorphism(f)^n
return TorQuadModuleMap(domain(f), codomain(f), hab)
end
@doc raw"""
evaluate(p::Union{ZZPolyRingElem, QQPolyRingElem}, f::TorQuadModuleMap)
-> TorQuadModuleMap
Given an abelian group endomorphism `f` of a torsion quadratic module `T` and
an univariate polynomial `p` with integral coefficients, return the abelian
group endomorphism $h := p(f)$ of `T` obtained by substituting the variable of
`p` by `f`.
Note that one also simply call `p(f)` instead of writing `evaluate(p, f)`.
"""
function evaluate(p::ZZPolyRingElem, f::TorQuadModuleMap)
@req domain(f) === codomain(f) "f must be a self-map"
hab = p(abelian_group_homomorphism(f))
return TorQuadModuleMap(domain(f), codomain(f), hab)
end
function evaluate(p::QQPolyRingElem, f::TorQuadModuleMap)
@req domain(f) === codomain(f) "f must be a self-map"
@req all(a -> is_integral(a), coefficients(p)) "p must have integral coefficients"
return evaluate(map_coefficients(ZZ, p, cached = false), f)
end
(p::ZZPolyRingElem)(f::TorQuadModuleMap) = evaluate(p, f)
(p::QQPolyRingElem)(f::TorQuadModuleMap) = evaluate(p, f)
################################################################################
#
# (Anti)-Isometry
#
################################################################################
# we test isometry in the semi-regular case: we compare the gram matrices of the
# quadratic forms associated to the respective normal forms.
function _isometry_semiregular(T::TorQuadModule, U::TorQuadModule)
# the zero map for default output
hz = hom(T, U, zero_matrix(ZZ, ngens(T), ngens(U)))
NT, TtoNT = normal_form(T)
NU, UtoNU = normal_form(U)
gqNT = gram_matrix_quadratic(NT)
gqNU = gram_matrix_quadratic(NU)
if gqNT != gqNU
return (false, hz)
end
NTtoNU = hom(NT, NU, identity_matrix(ZZ, ngens(NT)))
TtoU = hom(T, U, TorQuadModuleElem[UtoNU\(NTtoNU(TtoNT(a))) for a in gens(T)])
@hassert :Lattice 1 is_bijective(TtoU)
@hassert :Lattice 1 all(a -> a*a == TtoU(a)*TtoU(a), gens(T))
return (true, TtoU)