/
SubQuoHom.jl
1365 lines (1116 loc) · 37.5 KB
/
SubQuoHom.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
###############################################################################
# SubQuoHom constructors
###############################################################################
@doc raw"""
SubQuoHom(D::SubquoModule, C::ModuleFP{T}, im::Vector{<:ModuleFPElem{T}}) where T
Return the morphism $D \to C$ for a subquotient $D$ where `D[i]` is mapped to `im[i]`.
In particular, `length(im) == ngens(D)` must hold.
"""
SubQuoHom(D::SubquoModule, C::ModuleFP{T}, im::Vector{<:ModuleFPElem{T}}; check::Bool=true) where {T} = SubQuoHom{typeof(D), typeof(C), Nothing}(D, C, im; check)
SubQuoHom(D::SubquoModule, C::ModuleFP{T}, im::Vector{<:ModuleFPElem{T}}, h::RingMapType; check::Bool=true) where {T, RingMapType} = SubQuoHom{typeof(D), typeof(C), RingMapType}(D, C, im, h; check)
@doc raw"""
SubQuoHom(D::SubquoModule, C::ModuleFP{T}, mat::MatElem{T})
Return the morphism $D \to C$ corresponding to the given matrix, where $D$ is a subquotient.
`mat` must have `ngens(D)` many rows and `ngens(C)` many columns.
"""
function SubQuoHom(D::SubquoModule, C::ModuleFP{T}, mat::MatElem{T}; check::Bool=true) where T
@assert nrows(mat) == ngens(D)
@assert ncols(mat) == ngens(C)
if C isa FreeMod
hom = SubQuoHom(D, C, [FreeModElem(sparse_row(mat[i:i,:]), C) for i=1:ngens(D)]; check)
return hom
else
hom = SubQuoHom(D, C, [SubquoModuleElem(sparse_row(mat[i:i,:]), C) for i=1:ngens(D)]; check)
return hom
end
end
function SubQuoHom(D::SubquoModule, C::ModuleFP{T}, mat::MatElem{T}, h::RingMapType; check::Bool=true) where {T, RingMapType}
@assert nrows(mat) == ngens(D)
@assert ncols(mat) == ngens(C)
if C isa FreeMod
hom = SubQuoHom(D, C, [FreeModElem(sparse_row(mat[i:i,:]), C) for i=1:ngens(D)], h; check)
return hom
else
hom = SubQuoHom(D, C, [SubquoModuleElem(sparse_row(mat[i:i,:]), C) for i=1:ngens(D)], h; check)
return hom
end
end
function Base.show(io::IO, ::MIME"text/plain", fmh::SubQuoHom{T1, T2, RingMapType}) where {T1 <: AbstractSubQuo, T2 <: ModuleFP, RingMapType}
# HACK
show(io, fmh)
end
function Base.show(io::IO, fmh::SubQuoHom{T1, T2, RingMapType}) where {T1 <: AbstractSubQuo, T2 <: ModuleFP, RingMapType}
compact = get(io, :compact, false)
io_compact = IOContext(io, :compact => true)
domain_gens = gens(domain(fmh))
if is_graded(fmh)
print(io_compact, domain(fmh))
print(io, " -> ")
print(io_compact, codomain(fmh))
if !compact
print(io, "\n")
for i in 1:length(domain_gens)
print(io, domain_gens[i], " -> ")
print(io_compact, fmh(domain_gens[i]))
print(io, "\n")
end
A = grading_group(fmh)
if degree(fmh) == A[0]
print(io, "Homogeneous module homomorphism")
else
print(io_compact, "Graded module homomorphism of degree ", degree(fmh))
print(io, "\n")
end
end
else
println(io, "Map with following data")
println(io, "Domain:")
println(io, "=======")
println(io, domain(fmh))
println(io, "Codomain:")
println(io, "=========")
print(io, codomain(fmh))
end
end
images_of_generators(phi::SubQuoHom) = phi.im::Vector{elem_type(codomain(phi))}
image_of_generator(phi::SubQuoHom, i::Int) = phi.im[i]::elem_type(codomain(phi))
###################################################################
@doc raw"""
hom(M::SubquoModule{T}, N::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}) where T
Given a vector `V` of `ngens(M)` elements of `N`,
return the homomorphism `M` $\to$ `N` which sends the `i`-th
generator `M[i]` of `M` to the `i`-th entry of `V`.
hom(M::SubquoModule{T}, N::ModuleFP{T}, A::MatElem{T})) where T
Given a matrix `A` with `ngens(M)` rows and `ngens(N)` columns, return the
homomorphism `M` $\to$ `N` which sends the `i`-th generator `M[i]` of `M` to
the linear combination $\sum_j A[i,j]*N[j]$ of the generators `N[j]` of `N`.
!!! note
The module `N` may be of type `FreeMod` or `SubquoMod`. If both modules
`M` and `N` are graded, the data must define a graded module homomorphism of some degree.
If this degree is the zero element of the (common) grading group, we refer to
the homomorphism under consideration as a *homogeneous module homomorphism*.
!!! warning
The functions do not check whether the resulting homomorphism is well-defined,
that is, whether it sends the relations of `M` into the relations of `N`.
If you are uncertain with regard to well-definedness, use the function below.
Note, however, that the check performed by the function requires a Gröbner basis computation. This may take some time.
is_welldefined(a::ModuleFPHom)
Return `true` if `a` is well-defined, and `false` otherwise.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> F = free_module(R, 1)
Free module of rank 1 over Multivariate polynomial ring in 3 variables over QQ
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; y^3; z^4]
[x^2]
[y^3]
[z^4]
julia> M = SubquoModule(F, A, B)
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x*N[2]]
2-element Vector{SubquoModuleElem{QQMPolyRingElem}}:
x*y^2*e[1]
x*y*e[1]
julia> a = hom(M, N, V)
Map with following data
Domain:
=======
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
Codomain:
=========
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> is_welldefined(a)
true
julia> W = R[y^2 0; 0 x]
[y^2 0]
[ 0 x]
julia> b = hom(M, N, W);
julia> a == b
true
```
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> F = free_module(R, 1)
Free module of rank 1 over Multivariate polynomial ring in 3 variables over QQ
julia> A = R[x; y];
julia> B = R[x^2; y^3; z^4];
julia> M = SubquoModule(F, A, B);
julia> N = M;
julia> W = [y*N[1], x*N[2]]
2-element Vector{SubquoModuleElem{QQMPolyRingElem}}:
x*y*e[1]
x*y*e[1]
julia> c = hom(M, N, W);
julia> is_welldefined(c)
false
```
```jldoctest
julia> Rg, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = graded_free_module(Rg, 1);
julia> A = Rg[x; y];
julia> B = Rg[x^2; y^3; z^4];
julia> M = SubquoModule(F, A, B)
Graded subquotient of submodule of F generated by
1 -> x*e[1]
2 -> y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x^2*N[2]];
julia> a = hom(M, N, V)
M -> M
x*e[1] -> x*y^2*e[1]
y*e[1] -> x^2*y*e[1]
Graded module homomorphism of degree [2]
julia> is_welldefined(a)
true
julia> W = Rg[y^2 0; 0 x^2]
[y^2 0]
[ 0 x^2]
julia> b = hom(M, N, W)
M -> M
x*e[1] -> x*y^2*e[1]
y*e[1] -> x^2*y*e[1]
Graded module homomorphism of degree [2]
julia> a == b
true
julia> W = [y*N[1], x*N[2]]
2-element Vector{SubquoModuleElem{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}}:
x*y*e[1]
x*y*e[1]
julia> c = hom(M, N, W)
M -> M
x*e[1] -> x*y*e[1]
y*e[1] -> x*y*e[1]
Graded module homomorphism of degree [1]
julia> is_welldefined(c)
false
```
"""
hom(M::SubquoModule, N::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; check::Bool=true) where T = SubQuoHom(M, N, V; check)
hom(M::SubquoModule, N::ModuleFP{T}, A::MatElem{T}; check::Bool=true) where T = SubQuoHom(M, N, A; check)
@doc raw"""
hom(M::SubquoModule, N::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}, h::RingMapType) where {T, RingMapType}
Given a vector `V` of `ngens(M)` elements of `N`,
return the homomorphism `M` $\to$ `N` which sends the `i`-th
generator `M[i]` of `M` to the `i`-th entry of `V`, and the
scalars in `base_ring(M)` to their images under `h`.
hom(M::SubquoModule, N::ModuleFP{T}, A::MatElem{T}, h::RingMapType) where {T, RingMapType}
Given a matrix `A` with `ngens(M)` rows and `ngens(N)` columns, return the
homomorphism `M` $\to$ `N` which sends the `i`-th generator `M[i]` of `M` to
the linear combination $\sum_j A[i,j]*N[j]$ of the generators `N[j]` of `N`,
and the scalars in `base_ring(M)` to their images under `h`.
!!! note
The module `N` may be of type `FreeMod` or `SubquoMod`. If both modules
`M` and `N` are graded, the data must define a graded module homomorphism of some degree.
If this degree is the zero element of the (common) grading group, we refer to
the homomorphism under consideration as a *homogeneous module homomorphism*.
!!! warning
The functions do not check whether the resulting homomorphism is well-defined,
that is, whether it sends the relations of `M` into the relations of `N`.
If you are uncertain with regard to well-definedness, use the function below.
Note, however, that the check performed by the function requires a Gröbner basis computation. This may take some time.
is_welldefined(a::ModuleFPHom)
Return `true` if `a` is well-defined, and `false` otherwise.
"""
hom(M::SubquoModule, N::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}, h::RingMapType; check::Bool=true) where {T, RingMapType} = SubQuoHom(M, N, V, h; check)
hom(M::SubquoModule, N::ModuleFP{T}, A::MatElem{T}, h::RingMapType; check::Bool=true) where {T, RingMapType} = SubQuoHom(M, N, A, h; check)
function is_welldefined(H::Union{FreeModuleHom,FreeModuleHom_dec})
return true
end
function is_welldefined(H::SubQuoHom)
M = domain(H)
pres = presentation(M)
# is a short exact sequence with maps
# M <--eps-- F0 <--g-- F1
# and H : M -> N
eps = map(pres, 0)
g = map(pres, 1)
F0 = pres[0]
N = codomain(H)
# the induced map phi : F0 --> N
phi = hom(F0, N, elem_type(N)[H(eps(v)) for v in gens(F0)]; check=false)
# now phi ∘ g : F1 --> N has to be zero.
return iszero(compose(g, phi))
C = present_as_cokernel(M).quo
n = ngens(C)
m = rank(C.F)
ImH = images_of_generators(H)
for i=1:n
if !iszero(sum([C[i][j]*ImH[j] for j=1:m]; init=zero(codomain(H))))
return false
end
end
return true
end
function (==)(f::ModuleFPHom, g::ModuleFPHom)
domain(f) === domain(g) || return false
codomain(f) === codomain(g) || return false
M = domain(f)
for v in gens(M)
f(v) == g(v) || return false
end
return true
end
function Base.hash(f::ModuleFPHom{T}, h::UInt) where {U<:FieldElem, S<:MPolyRingElem{U}, T<:ModuleFP{S}}
b = 0x535bbdbb2bc54b46 % UInt
h = hash(typeof(f), h)
h = hash(domain(f), h)
h = hash(codomain(f), h)
for g in images_of_generators(f)
h = hash(g, h)
end
return xor(h, b)
end
function Base.hash(f::ModuleFPHom, h::UInt)
b = 0x535bbdbb2bc54b46 % UInt
h = hash(typeof(f), h)
h = hash(domain(f), h)
h = hash(codomain(f), h)
# We can not assume that the images of generators
# have a hash in general
return xor(h, b)
end
###################################################################
@doc raw"""
matrix(a::SubQuoHom)
Given a homomorphism `a` of type `SubQuoHom` with domain `M`
and codomain `N`, return a matrix `A` with `ngens(M)` rows and
`ngens(N)` columns such that `a == hom(M, N, A)`.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> F = free_module(R, 1)
Free module of rank 1 over Multivariate polynomial ring in 3 variables over QQ
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; y^3; z^4]
[x^2]
[y^3]
[z^4]
julia> M = SubquoModule(F, A, B)
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x*N[2]];
julia> a = hom(M, N, V);
julia> A = matrix(a)
[y^2 0]
[ 0 x]
julia> a(M[1])
x*y^2*e[1]
```
```jldoctest
julia> Rg, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = graded_free_module(Rg, 1);
julia> A = Rg[x; y];
julia> B = Rg[x^2; y^3; z^4];
julia> M = SubquoModule(F, A, B)
Graded subquotient of submodule of F generated by
1 -> x*e[1]
2 -> y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x^2*N[2]];
julia> a = hom(M, N, V)
M -> M
x*e[1] -> x*y^2*e[1]
y*e[1] -> x^2*y*e[1]
Graded module homomorphism of degree [2]
julia> matrix(a)
[y^2 0]
[ 0 x^2]
```
"""
function matrix(f::SubQuoHom)
if !isdefined(f, :matrix)
D = domain(f)
C = codomain(f)
R = base_ring(D)
matrix = zero_matrix(R, ngens(D), ngens(C))
for i=1:ngens(D), j=1:ngens(C)
matrix[i,j] = f.im[i][j]
end
f.matrix = matrix
end
return f.matrix
end
function show_morphism(f::ModuleFPHom)
show(stdout, "text/plain", matrix(f))
end
@doc raw"""
image(a::SubQuoHom, m::SubquoModuleElem)
Return the image $a(m)$.
"""
function image(f::SubQuoHom, a::SubquoModuleElem)
@assert a.parent === domain(f)
iszero(a) && return zero(codomain(f))
# The code in the comment below was an attempt to make
# evaluation of maps faster. However, it turned out that
# for the average use case the comparison was more expensive
# than the gain for mappings. The flag should be set by constructors
# nevertheless when applicable.
#if f.generators_map_to_generators === nothing
# f.generators_map_to_generators = images_of_generators(f) == gens(codomain(f))
#end
f.generators_map_to_generators === true && return codomain(f)(map_entries(base_ring_map(f), coordinates(a)))
h = base_ring_map(f)
return sum(h(b)*image_of_generator(f, i) for (i, b) in coordinates(a); init=zero(codomain(f)))
end
function image(f::SubQuoHom{<:SubquoModule, <:ModuleFP, Nothing}, a::SubquoModuleElem)
# TODO matrix vector multiplication
@assert a.parent === domain(f)
#if f.generators_map_to_generators === nothing
# f.generators_map_to_generators = images_of_generators(f) == gens(codomain(f))
#end
f.generators_map_to_generators === true && return codomain(f)(coordinates(a))
return sum(c*image_of_generator(f, i) for (i, c) in coordinates(a); init=zero(codomain(f)))
end
@doc raw"""
image(f::SubQuoHom, a::FreeModElem)
Return $f(a)$. `a` must represent an element in the domain of `f`.
"""
function image(f::SubQuoHom, a::FreeModElem)
return image(f, SubquoModuleElem(a, domain(f)))
end
function image(f::SubQuoHom{<:SubquoModule, <:ModuleFP, Nothing}, a::FreeModElem)
return image(f, SubquoModuleElem(a, domain(f)))
end
@doc raw"""
preimage(f::SubQuoHom, a::Union{SubquoModuleElem,FreeModElem})
Compute a preimage of `a` under `f`.
"""
function preimage(f::SubQuoHom{<:SubquoModule, <:ModuleFP}, a::Union{SubquoModuleElem,FreeModElem})
@assert parent(a) === codomain(f)
phi = base_ring_map(f)
D = domain(f)
i = zero(D)
b = coordinates(a isa FreeModElem ? a : repres(a), image(f)[1])
bb = map_entries(x->(preimage(phi, x)), b)
for (p,v) = bb
i += v*gen(D, p)
end
return i
end
function preimage(f::SubQuoHom{<:SubquoModule, <:ModuleFP, Nothing},
a::Union{SubquoModuleElem,FreeModElem})
@assert parent(a) === codomain(f)
D = domain(f)
i = zero(D)
b = coordinates(a isa FreeModElem ? a : repres(a), image(f)[1])
for (p,v) = b
i += v*gen(D, p)
end
return i
end
(f::SubQuoHom)(a::FreeModElem) = image(f, SubquoModuleElem(a, domain(f)))
(f::SubQuoHom)(a::SubquoModuleElem) = image(f, a)
@doc raw"""
image(a::SubQuoHom)
Return the image of `a` as an object of type `SubquoModule`.
Additionally, if `I` denotes this object, return the inclusion map `I` $\to$ `codomain(a)`.
"""
@attr Tuple{<:SubquoModule, <:ModuleFPHom} function image(h::SubQuoHom)
s = sub_object(codomain(h), images_of_generators(h))
inc = hom(s, codomain(h), images_of_generators(h), check=false)
return s, inc
end
@doc raw"""
image(a::ModuleFPHom)
Return the image of `a` as an object of type `SubquoModule`.
Additionally, if `I` denotes this object, return the inclusion map `I` $\to$ `codomain(a)`.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 3);
julia> G = free_module(R, 2);
julia> W = R[y 0; x y; 0 z]
[y 0]
[x y]
[0 z]
julia> a = hom(F, G, W);
julia> I, incl = image(a);
julia> I
Submodule with 3 generators
1 -> y*e[1]
2 -> x*e[1] + y*e[2]
3 -> z*e[2]
represented as subquotient with no relations.
julia> incl
Map with following data
Domain:
=======
Submodule with 3 generators
1 -> y*e[1]
2 -> x*e[1] + y*e[2]
3 -> z*e[2]
represented as subquotient with no relations.
Codomain:
=========
Free module of rank 2 over Multivariate polynomial ring in 3 variables over QQ
```
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 1);
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; y^3; z^4]
[x^2]
[y^3]
[z^4]
julia> M = SubquoModule(F, A, B)
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x*N[2]]
2-element Vector{SubquoModuleElem{QQMPolyRingElem}}:
x*y^2*e[1]
x*y*e[1]
julia> a = hom(M, N, V);
julia> I, incl = image(a);
julia> I
Subquotient of Submodule with 2 generators
1 -> x*y^2*e[1]
2 -> x*y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> incl
Map with following data
Domain:
=======
Subquotient of Submodule with 2 generators
1 -> x*y^2*e[1]
2 -> x*y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
Codomain:
=========
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
```
```jldoctest
julia> Rg, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = graded_free_module(Rg, 1);
julia> A = Rg[x; y];
julia> B = Rg[x^2; y^3; z^4];
julia> M = SubquoModule(F, A, B)
Graded subquotient of submodule of F generated by
1 -> x*e[1]
2 -> y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x^2*N[2]];
julia> a = hom(M, N, V)
M -> M
x*e[1] -> x*y^2*e[1]
y*e[1] -> x^2*y*e[1]
Graded module homomorphism of degree [2]
julia> image(a)
(Graded subquotient of submodule of F generated by
1 -> x*y^2*e[1]
2 -> x^2*y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1], Graded subquotient of submodule of F generated by
1 -> x*y^2*e[1]
2 -> x^2*y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1] -> M
x*y^2*e[1] -> x*y^2*e[1]
x^2*y*e[1] -> x^2*y*e[1]
Homogeneous module homomorphism)
```
"""
function image(a::ModuleFPHom)
error("image is not implemented for the given types.")
end
@doc raw"""
kernel(a::SubQuoHom)
Return the kernel of `a` as an object of type `SubquoModule`.
Additionally, if `K` denotes this object, return the inclusion map `K` $\to$ `domain(a)`.
"""
function kernel(h::SubQuoHom)
D = domain(h)
R = base_ring(D)
is_graded(h) ? F = graded_free_module(R, degrees_of_generators(D)) : F = FreeMod(R, ngens(D))
hh = hom(F, codomain(h), images_of_generators(h), check=false)
K, inc_K = kernel(hh)
@assert domain(inc_K) === K
@assert codomain(inc_K) === F
v = gens(D)
imgs = Vector{elem_type(D)}(filter(!iszero, [sum(a*v[i] for (i, a) in coordinates(g); init=zero(D)) for g in images_of_generators(inc_K)]))
k = sub_object(D, imgs)
return k, hom(k, D, imgs, check=false)
end
@doc raw"""
kernel(a::ModuleFPHom)
Return the kernel of `a` as an object of type `SubquoModule`.
Additionally, if `K` denotes this object, return the inclusion map `K` $\to$ `domain(a)`.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 3);
julia> G = free_module(R, 2);
julia> W = R[y 0; x y; 0 z]
[y 0]
[x y]
[0 z]
julia> a = hom(F, G, W);
julia> K, incl = kernel(a);
julia> K
Submodule with 1 generator
1 -> x*z*e[1] - y*z*e[2] + y^2*e[3]
represented as subquotient with no relations.
julia> incl
Map with following data
Domain:
=======
Submodule with 1 generator
1 -> x*z*e[1] - y*z*e[2] + y^2*e[3]
represented as subquotient with no relations.
Codomain:
=========
Free module of rank 3 over Multivariate polynomial ring in 3 variables over QQ
```
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 1);
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; y^3; z^4]
[x^2]
[y^3]
[z^4]
julia> M = SubquoModule(F, A, B)
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x*N[2]]
2-element Vector{SubquoModuleElem{QQMPolyRingElem}}:
x*y^2*e[1]
x*y*e[1]
julia> a = hom(M, N, V);
julia> K, incl = kernel(a);
julia> K
Subquotient of Submodule with 3 generators
1 -> (-x + y^2)*e[1]
2 -> x*y*e[1]
3 -> -x*y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> incl
Map with following data
Domain:
=======
Subquotient of Submodule with 3 generators
1 -> (-x + y^2)*e[1]
2 -> x*y*e[1]
3 -> -x*y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
Codomain:
=========
Subquotient of Submodule with 2 generators
1 -> x*e[1]
2 -> y*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
```
```jldoctest
julia> Rg, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = graded_free_module(Rg, 1);
julia> A = Rg[x; y];
julia> B = Rg[x^2; y^3; z^4];
julia> M = SubquoModule(F, A, B)
Graded subquotient of submodule of F generated by
1 -> x*e[1]
2 -> y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> N = M;
julia> V = [y^2*N[1], x^2*N[2]];
julia> a = hom(M, N, V)
M -> M
x*e[1] -> x*y^2*e[1]
y*e[1] -> x^2*y*e[1]
Graded module homomorphism of degree [2]
julia> kernel(a)
(Graded subquotient of submodule of F generated by
1 -> y*e[1]
2 -> -x*y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1], Graded subquotient of submodule of F generated by
1 -> y*e[1]
2 -> -x*y*e[1]
by submodule of F generated by
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1] -> M
y*e[1] -> y*e[1]
-x*y*e[1] -> -x*y*e[1]
Homogeneous module homomorphism)
```
"""
function kernel(a::ModuleFPHom)
error("kernel is not implemented for the given types.")
end
#TODO
# replace the +/- for the homs by proper constructors for homs and direct sums
# relshp to store the maps elsewhere
@doc raw"""
*(a::ModuleFPHom, b::ModuleFPHom)
Return the composition `b` $\circ$ `a`.
"""
function *(h::ModuleFPHom{T1, T2, Nothing}, g::ModuleFPHom{T2, T3, Nothing}) where {T1, T2, T3}
@assert codomain(h) === domain(g)
return hom(domain(h), codomain(g), Vector{elem_type(codomain(g))}([g(h(x)) for x = gens(domain(h))]), check=false)
end
function *(h::ModuleFPHom{T1, T2, <:Map}, g::ModuleFPHom{T2, T3, <:Map}) where {T1, T2, T3}
@assert codomain(h) === domain(g)
return hom(domain(h), codomain(g), Vector{elem_type(codomain(g))}([g(h(x)) for x = gens(domain(h))]), compose(base_ring_map(h), base_ring_map(g)), check=false)
end
function *(h::ModuleFPHom{T1, T2, <:Any}, g::ModuleFPHom{T2, T3, <:Any}) where {T1, T2, T3}
@assert codomain(h) === domain(g)
return hom(domain(h), codomain(g),
Vector{elem_type(codomain(g))}([g(h(x)) for x = gens(domain(h))]),
MapFromFunc(base_ring(domain(h)),
base_ring(codomain(g)),
x->(base_ring_map(g)(base_ring_map(h)(x)))),
check=false
)
end
compose(h::ModuleFPHom, g::ModuleFPHom) = h*g
-(h::ModuleFPHom{D, C, Nothing}) where {D, C} = hom(domain(h), codomain(h), elem_type(codomain(h))[-h(x) for x in gens(domain(h))], check=false)
-(h::ModuleFPHom{D, C, T}) where {D, C, T} = hom(domain(h), codomain(h), elem_type(codomain(h))[-h(x) for x in gens(domain(h))], base_ring_map(h), check=false)
function -(h::ModuleFPHom{D, C, T}, g::ModuleFPHom{D, C, T}) where {D, C, T}
@assert domain(h) === domain(g)
@assert codomain(h) === codomain(g)
@assert base_ring_map(h) === base_ring_map(g)
return hom(domain(h), codomain(h), elem_type(codomain(h))[h(x) - g(x) for x in gens(domain(h))], base_ring_map(h), check=false)
end
function -(h::ModuleFPHom{D, C, Nothing}, g::ModuleFPHom{D, C, Nothing}) where {D, C}
@assert domain(h) === domain(g)
@assert codomain(h) === codomain(g)
return hom(domain(h), codomain(h), elem_type(codomain(h))[h(x) - g(x) for x in gens(domain(h))], check=false)
end
function +(h::ModuleFPHom{D, C, T}, g::ModuleFPHom{D, C, T}) where {D, C, T}
@assert domain(h) === domain(g)
@assert codomain(h) === codomain(g)
@assert base_ring_map(h) === base_ring_map(g)
return hom(domain(h), codomain(h), elem_type(codomain(h))[h(x) + g(x) for x in gens(domain(h))], base_ring_map(h), check=false)
end
function +(h::ModuleFPHom{D, C, Nothing}, g::ModuleFPHom{D, C, Nothing}) where {D, C}
@assert domain(h) === domain(g)
@assert codomain(h) === codomain(g)
return hom(domain(h), codomain(h), elem_type(codomain(h))[h(x) + g(x) for x in gens(domain(h))], check=false)
end
function *(a::RingElem, g::ModuleFPHom{D, C, Nothing}) where {D, C}
@assert base_ring(codomain(g)) === parent(a)
return hom(domain(g), codomain(g), elem_type(codomain(g))[a*g(x) for x in gens(domain(g))], check=false)
end
function *(a::RingElem, g::ModuleFPHom{D, C, T}) where {D, C, T}
@assert base_ring(codomain(g)) === parent(a)
return hom(domain(g), codomain(g), elem_type(codomain(g))[a*g(x) for x in gens(domain(g))], base_ring_map(g), check=false)
end
@doc raw"""
restrict_codomain(H::ModuleFPHom, M::SubquoModule)
Return, if possible, a homomorphism, which is mathematically identical to `H`,
but has codomain `M`. `M` has to be a submodule of the codomain of `H`.
"""
function restrict_codomain(H::ModuleFPHom, M::SubquoModule)
D = domain(H)
return hom(D, M, map(v -> SubquoModuleElem(v, M), map(x -> repres(H(x)), gens(D))), check=false)
end
@doc raw"""
restrict_domain(H::SubQuoHom, M::SubquoModule)
Restrict the morphism `H` to `M`. For this `M` has to be a submodule
of the domain of `H`. The relations of `M` must be the relations of
the domain of `H`.
"""
function restrict_domain(H::SubQuoHom, M::SubquoModule)
for (cod, t) in M.outgoing
if cod === domain(H)
return _recreate_morphism(M, cod, t)*H
end