/
SubquoModuleElem.jl
1116 lines (907 loc) · 32.5 KB
/
SubquoModuleElem.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
###############################################################################
# SubquoModuleElem constructors
###############################################################################
@doc raw"""
SubquoModuleElem(v::SRow{R}, SQ::SubquoModule) where {R}
Return the element $\sum_i v[i] \cdot SQ[i]$.
"""
SubquoModuleElem(v::SRow{R}, SQ::SubquoModule) where {R} = SubquoModuleElem{R}(v, SQ)
@doc raw"""
SubquoModuleElem(a::FreeModElem{R}, SQ::SubquoModule) where {R}
Construct an element $v \in SQ$ that is represented by $a$.
"""
SubquoModuleElem(a::FreeModElem{R}, SQ::SubquoModule; is_reduced::Bool=false) where {R} = SubquoModuleElem{R}(a, SQ; is_reduced)
elem_type(::Type{SubquoModule{T}}) where {T} = SubquoModuleElem{T}
parent_type(::Type{SubquoModuleElem{T}}) where {T} = SubquoModule{T}
function in(v::SubquoModuleElem, M::SubquoModule)
ambient_free_module(parent(v)) === ambient_free_module(M) || return false
return represents_element(repres(v), M)
end
@doc raw"""
getindex(v::SubquoModuleElem, i::Int)
Let $v \in M$ with $v = \sum_i a[i] \cdot M[i]$. Return $a[i]$
"""
function getindex(v::SubquoModuleElem, i::Int)
if isempty(coordinates(v))
return zero(base_ring(v.parent))
end
return coordinates(v)[i]
end
#######################################################
@doc raw"""
coordinates(m::SubquoModuleElem)
Given an element `m` of a subquotient $M$ over a ring $R$, say,
return the coefficients of an $R$-linear combination of the generators of $M$
which gives $m$.
Return the coefficients of `m` with respect to the basis of standard unit vectors.
The result is returned as a sparse row.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; x*y; y^2; z^4]
[x^2]
[x*y]
[y^2]
[z^4]
julia> M = SubquoModule(A, B);
julia> m = z*M[1] + M[2]
(x*z + y)*e[1]
julia> coordinates(m)
Sparse row with positions [1, 2] and values QQMPolyRingElem[z, 1]
```
"""
function coordinates(m::SubquoModuleElem)
if !isdefined(m, :coeffs)
@assert isdefined(m, :repres) "neither coeffs nor repres is defined on a SubquoModuleElem"
m.coeffs = coordinates(repres(m), parent(m))
end
return m.coeffs
end
#########################################################
@doc raw"""
repres(v::SubquoModuleElem)
Return a free module element that is a representative of `v`.
"""
function repres(v::SubquoModuleElem)
if !isdefined(v, :repres)
@assert isdefined(v, :coeffs) "neither coeffs nor repres is defined on a SubquoModuleElem"
M = parent(v)
v.repres = sum(a*M.sub[i] for (i, a) in v.coeffs; init=zero(M.sub))
end
return v.repres
end
#######################################################
# simplify modifies the representative v of el as follows:
#
# - if el is zero, v is zero
# - if el is homogeneous, but the current representative is not
# then a homogeneous representative is returned.
# - it sets the field is_reduced to true.
function simplify(el::SubquoModuleElem{<:MPolyRingElem{T}}) where {T<:Union{<:FieldElem, <:ZZRingElem}}
el.is_reduced && return el
if is_zero(el) # We have to do this check because otherwise the coordinates of the representative are not reset.
result = zero(parent(el))
result.is_reduced = true # Todo: Should be done in zero(...)
return result
end
if !isdefined(parent(el), :quo) || is_zero(parent(el).quo)
el.is_reduced = true
return el
end
!isdefined(el, :repres) && repres(el) # Make sure the field is filled
reduced = reduce(el.repres, parent(el).quo)
result = SubquoModuleElem(reduced, parent(el), is_reduced=true)
return result
end
function simplify!(el::SubquoModuleElem{<:MPolyRingElem{T}}) where {T<:Union{<:FieldElem, <:ZZRingElem}}
el.is_reduced && return el
if is_zero(el) # We have to do this check because otherwise the coordinates of the representative are not reset.
result = zero(parent(el))
result.is_reduced = true # Todo: Should be done in zero(...)
return result
end
if !isdefined(parent(el), :quo) || is_zero(parent(el).quo)
el.is_reduced = true
return el
end
!isdefined(el, :repres) && repres(el) # Make sure the field is filled
el.repres = reduce(el.repres, parent(el).quo)
el.is_reduced = true
return el
end
# The default only checks whether an element is zero.
function simplify(el::SubquoModuleElem)
el.is_reduced && return el
if is_zero(el)
result = zero(parent(el))
result.is_reduced = true # Todo: Should be done in zero(...)
return result
end
el.is_reduced = true
return el
end
function simplify!(el::SubquoModuleElem)
el.is_reduced && return el
if is_zero(el)
el.coeffs = sparse_row(base_ring(parent(el)))
el.repres = zero(ambient_free_module(parent(el)))
el.is_reduced = true
return el
end
el.is_reduced = true
return el
end
#######################################################
@doc raw"""
ambient_representative(m::SubquoModuleElem)
Given an element `m` of a subquotient $M$, say, return
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> A = R[x; y]
[x]
[y]
julia> B = R[x^2; x*y; y^2; z^4]
[x^2]
[x*y]
[y^2]
[z^4]
julia> M = SubquoModule(A, B);
julia> m = z*M[1] + M[2]
(x*z + y)*e[1]
julia> typeof(m)
SubquoModuleElem{QQMPolyRingElem}
julia> fm = ambient_representative(m)
(x*z + y)*e[1]
julia> typeof(fm)
FreeModElem{QQMPolyRingElem}
julia> parent(fm) == ambient_free_module(M)
true
```
"""
ambient_representative(m::SubquoModuleElem) = repres(m)
# another method for compatibility in generic code
ambient_representative(a::FreeModElem) = a
#######################################################
@doc raw"""
Vector(v::SubquoModuleElem)
Return the coefficients of a representative of `v` as a Vector.
"""
function Vector(v::SubquoModuleElem)
return Vector(repres(v))
end
@doc raw"""
standard_basis(F::ModuleGens{T}, reduced::Bool=false) where {T <: MPolyRingElem}
Return a standard basis of `F` as an object of type `ModuleGens`.
If `reduced` is set to `true` and the ordering of the underlying ring is global,
a reduced Gröbner basis is computed.
"""
function standard_basis(F::ModuleGens{T}, reduced::Bool=false) where {T <: MPolyRingElem}
@req is_exact_type(elem_type(base_ring(F))) "This functionality is only supported over exact fields."
singular_assure(F)
if reduced
@assert Singular.has_global_ordering(base_ring(F.SF))
end
if singular_generators(F).isGB && !reduced
return F
end
return ModuleGens(F.F, Singular.std(singular_generators(F), complete_reduction=reduced))
end
@doc raw"""
lift_std(M::ModuleGens{T}) where {T <: MPolyRingElem}
Return a standard basis `G` of `F` as an object of type `ModuleGens` along with
a transformation matrix `T` such that `T*matrix(M) = matrix(G)`.
"""
function lift_std(M::ModuleGens{T}) where {T <: MPolyRingElem}
singular_assure(M)
R = base_ring(M)
G,Trans_mat = Singular.lift_std(singular_generators(M)) # When Singular supports reduction add it also here
mg = ModuleGens(M.F, G)
mg.isGB = true
mg.S.isGB = true
mg.ordering = default_ordering(M.F)
mat = map_entries(R, transpose(Trans_mat))
set_attribute!(mg, :transformation_matrix => mat)
return mg, mat
end
@doc raw"""
lift_std(M::ModuleGens{T}, ordering::ModuleOrdering) where {T <: MPolyRingElem}
Return a standard basis `G` of `F` with respect to the given `ordering`
as an object of type `ModuleGens` along with a transformation
matrix `T` such that `T*matrix(M) = matrix(G)`.
"""
function lift_std(M::ModuleGens{T}, ordering::ModuleOrdering) where {T <: MPolyRingElem}
M = ModuleGens(M.O, M.F, ordering)
mg, mat = lift_std(M)
mg.ordering = ordering
return mg, mat
end
@doc raw"""
leading_monomials(F::ModuleGens)
Return the leading monomials of `F` as an object of type `ModuleGens`.
The leading module is with respect to the ordering defined on the Singular side.
"""
function leading_monomials(F::ModuleGens)
# TODO
# The following doesn't work yet. When comparison / lead for module elements
# is implemented this should be uncommented.
#if !isdefined(F, :S)
#return ModuleGens(F.F, [lead(g) for g in F.O])
#end
singular_assure(F)
singular_gens = singular_generators(F)
return ModuleGens(F.F, Singular.lead(singular_gens))
end
function show(io::IO, b::SubquoModuleElem)
print(io, repres(b))
end
@doc raw"""
parent(b::SubquoModuleElem)
Let $b \in M$. Return $M$.
"""
parent(b::SubquoModuleElem) = b.parent
@doc raw"""
(M::SubquoModule{T})(f::FreeModElem{T}) where T
Given an element `f` of the ambient free module of `M` which represents an element of `M`,
return the represented element.
"""
function (M::SubquoModule{T})(f::FreeModElem{T}) where T
coords = coordinates(f, M)
if coords === nothing
error("not in the module")
end
return SubquoModuleElem(coords, M)
end
@doc raw"""
(M::SubquoModule{T})(c::SRow{T}) where T
Return the subquotient element $\sum_i a[i] \cdot M[i]\in M$.
"""
function (R::SubquoModule)(a::SRow)
return SubquoModuleElem(a, R)
end
@doc raw"""
SubquoModuleElem(c::Vector{T}, parent::SubquoModule{T}) where T
Return the element of `parent` defined as a linear combination
of the generators of $parent$ with coefficients given by the entries of `c`.
"""
function SubquoModuleElem(c::Vector{T}, parent::SubquoModule{T}) where T
@assert length(c) == ngens(parent)
sparse_coords = sparse_row(base_ring(parent), collect(1:ngens(parent)), c)
return SubquoModuleElem{T}(sparse_coords,parent)
end
@doc raw"""
(M::SubquoModule{T})(c::Vector{T}) where T
Return the element of `M` defined as a linear combination
of the generators of $M$ with coefficients given by the entries of `c`.
"""
function (M::SubquoModule{T})(c::Vector{T}) where T
return SubquoModuleElem(c, M)
end
@doc raw"""
(R::SubquoModule)(a::SubquoModuleElem)
Return `a` if it lives in `R`.
"""
function (R::SubquoModule)(a::SubquoModuleElem)
if parent(a) == R
return a
end
error("illegal coercion")
end
@doc raw"""
index_of_gen(v::SubquoModuleElem)
Let $v \in G$ with $v$ the `i`th generator of $G$. Return `i`.
"""
function index_of_gen(v::SubquoModuleElem)
@assert length(coordinates(v).pos) == 1
@assert isone(coordinates(v).values[1])
return coordinates(v).pos[1]
end
# function to check whether two module elements are in the same module
function check_parent(a::Union{AbstractFreeModElem,SubquoModuleElem}, b::Union{AbstractFreeModElem,SubquoModuleElem})
if parent(a) !== parent(b)
error("elements not compatible")
end
end
function +(a::SubquoModuleElem, b::SubquoModuleElem)
check_parent(a,b)
if isdefined(a, :coeffs) && isdefined(b, :coeffs)
return SubquoModuleElem(coordinates(a)+coordinates(b), a.parent)
else
return SubquoModuleElem(repres(a) + repres(b), parent(a))
end
end
function -(a::SubquoModuleElem, b::SubquoModuleElem)
check_parent(a,b)
if isdefined(a, :coeffs) && isdefined(b, :coeffs)
return SubquoModuleElem(coordinates(a)-coordinates(b), a.parent)
else
return SubquoModuleElem(repres(a) - repres(b), parent(a))
end
end
-(a::SubquoModuleElem) = SubquoModuleElem(-coordinates(a), a.parent)
function *(a::MPolyDecRingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
isdefined(b, :coeffs) && return SubquoModuleElem(a*coordinates(b), b.parent)
return SubquoModuleElem(a*repres(b), b.parent)
end
function *(a::MPolyRingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
isdefined(b, :coeffs) && return SubquoModuleElem(a*coordinates(b), b.parent)
return SubquoModuleElem(a*repres(b), b.parent)
end
function *(a::RingElem, b::SubquoModuleElem)
if parent(a) !== base_ring(parent(b))
return base_ring(parent(b))(a)*b # this will throw if conversion is not possible
end
isdefined(b, :coeffs) && return SubquoModuleElem(a*coordinates(b), b.parent)
return SubquoModuleElem(a*repres(b), b.parent)
end
*(a::Int, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)
*(a::Integer, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)
*(a::QQFieldElem, b::SubquoModuleElem) = SubquoModuleElem(a*coordinates(b), b.parent)
function (==)(a::SubquoModuleElem, b::SubquoModuleElem)
if parent(a) !== parent(b)
return false
end
return iszero(a-b)
end
function Base.hash(a::SubquoModuleElem)
b = 0xaa2ba4a32dd0b431 % UInt
h = hash(typeof(a), h)
h = hash(parent(a), h)
return xor(h, b)
end
function Base.hash(a::SubquoModuleElem{<:MPolyRingElem{<:FieldElem}}, h::UInt)
b = 0xaa2ba4a32dd0b431 % UInt
h = hash(typeof(a), h)
h = hash(parent(a), h)
simplify!(a)
return hash(a.repres, h)
end
function Base.deepcopy_internal(a::SubquoModuleElem, dict::IdDict)
return SubquoModuleElem(deepcopy_internal(coordinates(a), dict), a.parent)
end
@doc raw"""
sub(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where {T}
Given a vector `V` of (homogeneous) elements of `F`, return a pair `(I, inc)`
consisting of the (graded) submodule `I` of `F` generated by these elements
and its inclusion map `inc : I ↪ F`.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
If only the submodule itself is desired, use `sub_object` instead.
"""
function sub(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where {T}
s = SubquoModule(F, V)
emb = hom(s, F, V; check=false)
set_attribute!(s, :canonical_inclusion => emb)
cache_morphism && register_morphism!(emb)
return s, emb
end
function sub_object(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}) where {T}
return SubquoModule(F, V)
end
@doc raw"""
sub(F::FreeMod{T}, A::MatElem{T}; cache_morphism::Bool=false) where {T}
Given a (homogeneous) matrix `A` interpret the rows of `A` as elements
of the free module `F` and return a pair `(I, inc)`
consisting of the (graded) submodule `I` of `F` generated by these row vectors,
together with its inclusion map `inc : I ↪ F`.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
If only the submodule itself is desired, use `sub_object` instead.
"""
function sub(F::FreeMod{T}, A::MatElem{T}; cache_morphism::Bool=false) where {T}
M = SubquoModule(SubModuleOfFreeModule(F, A))
#M = SubquoModule(F, A, zero_matrix(base_ring(F), 1, rank(F)))
emb = hom(M, F, ambient_representatives_generators(M); check=false)
emb.matrix = A
set_attribute!(M, :canonical_inclusion => emb) # TODO: Can this be removed?
cache_morphism && register_morphism!(emb)
return M, emb
end
function sub_object(F::FreeMod{T}, A::MatElem{T}) where {T}
return SubquoModule(SubModuleOfFreeModule(F, A))
end
@doc raw"""
sub(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
Suppose the `ambient_free_module` of the `parent` `M` of the elements `v_i`
in `O` is `F` and `M` is a submodule (i.e. no relations are present).
Then this returns a pair `(I, inc)` consisting of the submodule `I`
generated by the elements in `O` in `F`, together with its inclusion
morphism `inc : I ↪ F`.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
If only the submodule itself is desired, use `sub_object` instead.
"""
function sub(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
s = SubquoModule(F, [repres(x) for x = O])
return sub(F, s; cache_morphism)
end
function sub_object(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}) where T
return SubquoModule(F, [repres(x) for x = O])
end
@doc raw"""
sub(F::FreeMod{T}, M::SubquoModule{T}; cache_morphism::Bool=false) where T
Return `M` as a submodule of `F`, together with its inclusion morphism
`inc : M ↪ F`.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
The `ambient_free_module` of `M` needs to be `F` and `M` has to have no
relations.
If only the submodule itself is desired, use `sub_object` instead.
"""
function sub(F::FreeMod{T}, s::SubquoModule{T}; cache_morphism::Bool=false) where T
@assert !isdefined(s, :quo)
@assert s.F === F
emb = hom(s, F, elem_type(F)[repres(x) for x in gens(s)]; check=false)
#emb = hom(s, F, [FreeModElem(x.repres.coords, F) for x in gens(s)])
set_attribute!(s, :canonical_inclusion => emb)
cache_morphism && register_morphism!(emb)
return s, emb
end
function sub_object(F::FreeMod{T}, s::SubquoModule{T}) where T
@assert !isdefined(s, :quo)
@assert s.F === F
return s
end
@doc raw"""
sub(M::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `M`, return the (graded) submodule `I` of `M` generated by these elements
together with its inclusion map `inc : I ↪ M.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
If only the submodule itself is desired, use `sub_object` instead.
"""
function sub(M::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
@assert all(x -> x.parent === M, V)
t = SubquoModule(M.F, FreeModElem[repres(x) for x in V])
if isdefined(M, :quo)
t.quo = M.quo
t.sum = sum(t.sub, t.quo)
end
emb = hom(t, M, V; check=false)
set_attribute!(t, :canonical_inclusion => emb) # TODO: Can this be removed?
cache_morphism && register_morphism!(emb)
return t, emb
end
function sub_object(M::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}) where T
@assert all(x -> x.parent === M, V)
t = SubquoModule(M.F, FreeModElem[repres(x) for x in V])
if isdefined(M, :quo)
t.quo = M.quo
t.sum = sum(t.sub, t.quo)
end
return t
end
@doc raw"""
sub(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `M`, return the (graded) submodule `I` of `M` generated by these elements
together with its inclusion map `inc : I ↪ M.
When `cache_morphism` is set to true, then `inc` will be cached and available
for `transport` and friends.
If only the submodule itself is desired, use `sub_object` instead.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 1);
julia> V = [x^2*F[1]; y^3*F[1]; z^4*F[1]];
julia> N, incl = sub(F, V);
julia> N
Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
represented as subquotient with no relations.
julia> incl
Map with following data
Domain:
=======
Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
represented as subquotient with no relations.
Codomain:
=========
Free module of rank 1 over Multivariate polynomial ring in 3 variables over QQ
```
"""
function sub(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; cache_morphism::Bool=false) where T
error("sub is not implemented for the given types.")
end
#=
@doc raw"""
return_sub_wrt_task(M::SubquoModule, emb::SubQuoHom, task::Symbol)
This helper function returns `M`, `emb` or both according
to `task`.
"""
function return_sub_wrt_task(M::SubquoModule, emb::SubQuoHom, task::Symbol)
(task == :none || task == :module) && return M
task == :cache_morphism && register_morphism!(emb)
task == :only_morphism && return emb
(task == :cache_morphism || task == :both || task == :with_morphism) && return M, emb
error("No valid option for task.")
end
=#
@doc raw"""
quo(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `F`, return a pair `(M, pr)` consisting
of the quotient `M = F/⟨V⟩` and the projection map `pr : F → M`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where T
S = SubquoModule(F, basis(F))
Q = SubquoModule(S, V)
phi = hom(F, Q, gens(Q), check=false)
cache_morphism && register_morphism!(phi)
return Q, phi
end
function quo_object(F::FreeMod{T}, V::Vector{<:FreeModElem{T}}) where T
S = SubquoModule(F, basis(F))
Q = SubquoModule(S, V)
return Q
end
@doc raw"""
quo(F::FreeMod{T}, A::MatElem{T}; cache_morphism::Bool=false) where {T}
Given a matrix `A`, interpret the row vectors `v_i` of `A` as elements of `F`
and return a pair `(M, pr)` consisting of the quotient `M = F/I` of `F` by the
submodule `I ⊂ F` generated by the rows of `A`, together with the projection
map `pr : F → M`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(F::FreeMod{T}, A::MatElem{T}; cache_morphism::Bool=false) where {T}
E = identity_matrix(base_ring(F), rank(F))
Q = SubquoModule(F, E, A)
phi = hom(F, Q, gens(Q), check=false)
cache_morphism && register_morphism!(phi)
return Q, phi
end
function quo_object(F::FreeMod{T}, A::MatElem{T}) where {T}
E = identity_matrix(base_ring(F), rank(F))
Q = SubquoModule(F, E, A)
return Q
end
@doc raw"""
quo(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
Given a vector `O` of (homogeneous) elements of some submodule `I` of `F`,
return a pair `(M, pr)` consisting of the quotient `M = F/⟨V⟩` and
the projection map `pr : F → M`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
Compute $F / T$, where $T$ is generated by $O$.
Note that the submodule `I` must have `F` as its `ambient_free_module`.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
S = SubquoModule(F, basis(F))
Q = SubquoModule(S, [repres(x) for x = O])
phi = hom(F, Q, gens(Q), check=false)
cache_morphism && register_morphism!(phi)
return Q, phi
end
function quo_object(F::FreeMod{T}, O::Vector{<:SubquoModuleElem{T}}) where T
S = SubquoModule(F, basis(F))
Q = SubquoModule(S, [repres(x) for x = O])
return Q
end
@doc raw"""
quo(S::SubquoModule{T}, O::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `S`, return a pair `(M, pr)` consisting
of the quotient `M = S/⟨V⟩` and the projection map `pr : S → M`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
Note that the elements of `O` must belong to the `ambient_free_module` of `S` and represent
elements of `S`.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(F::SubquoModule{T}, O::Vector{<:FreeModElem{T}}; cache_morphism::Bool=false) where T
if length(O) > 0
@assert parent(O[1]) === F.F
end
if isdefined(F, :quo)
oscar_assure(F.quo.gens)
singular_assure(F.quo.gens)
s = Singular.Module(base_ring(F.quo.gens.SF), [F.quo.gens.SF(x) for x = [O; oscar_generators(F.quo.gens)]]...)
Q = SubquoModule(F.F, singular_generators(F.sub.gens), s)
phi = hom(F, Q, gens(Q), check=false)
cache_morphism && register_morphism!(phi)
return Q, phi
end
Q = SubquoModule(F, O)
phi = hom(F, Q, gens(Q), check=false)
cache_morphism && register_morphism!(phi)
return Q, phi
end
function quo_object(F::SubquoModule{T}, O::Vector{<:FreeModElem{T}}) where T
if length(O) > 0
@assert parent(O[1]) === F.F
end
if isdefined(F, :quo)
oscar_assure(F.quo.gens)
singular_assure(F.quo.gens)
s = Singular.Module(base_ring(F.quo.gens.SF), [F.quo.gens.SF(x) for x = [O; oscar_generators(F.quo.gens)]]...)
return SubquoModule(F.F, singular_generators(F.sub.gens), s)
end
return SubquoModule(F, O)
end
@doc raw"""
quo(S::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `S`, return a pair `(M, pr)` consisting
of the quotient `M = S/⟨V⟩` and the projection map `pr : S → M`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(M::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}; cache_morphism::Bool=false) where T
return quo(M, [repres(x) for x = V]; cache_morphism)
end
function quo_object(M::SubquoModule{T}, V::Vector{<:SubquoModuleElem{T}}) where T
return quo_object(M, [repres(x) for x = V])
end
@doc raw"""
quo(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; cache_morphism::Bool=false) where T
Given a vector `V` of (homogeneous) elements of `M`, return a pair `(N, pr)` consisting
of the quotient `N = M/⟨V⟩` and the projection map `pr : M → N`.
If one is only interested in the actual object `M`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> F = free_module(R, 1);
julia> V = [x^2*F[1]; y^3*F[1]; z^4*F[1]];
julia> N, proj = quo(F, V);
julia> N
Subquotient of Submodule with 1 generator
1 -> e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
julia> proj
Map with following data
Domain:
=======
Free module of rank 1 over Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Subquotient of Submodule with 1 generator
1 -> e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]
3 -> z^4*e[1]
```
"""
function quo(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; cache_morphism::Bool=false) where T
error("quo is not implemented for the given types.")
end
@doc raw"""
quo(M::SubquoModule{T}, U::SubquoModule{T}) where T
Return a pair `(N, pr)` consisting of the quotient $N = M / U$ together with the projection
map `pr : M → N`.
If one is only interested in the actual object `N`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(M::SubquoModule{T}, U::SubquoModule{T}; cache_morphism::Bool=false) where T
if isdefined(M, :quo) && isdefined(U, :quo)
F = ambient_free_module(M)
@assert F === ambient_free_module(U)
# We can not assume that the SubModuleOfFreeModule layer is implemented in general,
# so we deflect to the Subquo-layer instead.
@assert SubquoModule(F, relations(M)) == SubquoModule(F, relations(U))
else
@assert !isdefined(M, :quo) && !isdefined(U, :quo)
end
Q = SubquoModule(M, gens(U.sub))
pr = hom(M, Q, gens(Q), check=false)
cache_morphism && register_morphism!(pr)
return Q, pr
end
function quo_object(M::SubquoModule{T}, U::SubquoModule{T}) where T
if isdefined(M, :quo) && isdefined(U, :quo)
F = ambient_free_module(M)
@assert F === ambient_free_module(U)
# We can not assume that the SubModuleOfFreeModule layer is implemented in general,
# so we deflect to the Subquo-layer instead.
@assert SubquoModule(F, relations(M)) == SubquoModule(F, relations(U))
else
@assert !isdefined(M, :quo) && !isdefined(U, :quo)
end
return SubquoModule(M, gens(U.sub))
end
function quo(M::SubquoModule{T}, U::SubquoModule{T}; cache_morphism::Bool=false) where {T<:MPolyRingElem}
if isdefined(M, :quo) && isdefined(U, :quo)
@assert M.quo == U.quo
else
@assert !isdefined(M, :quo) && !isdefined(U, :quo)
end
Q = SubquoModule(M, oscar_generators(U.sub.gens))
pr = hom(M, Q, gens(Q), check=false)
cache_morphism && register_morphism!(pr)
return Q, pr
end
function quo_object(M::SubquoModule{T}, U::SubquoModule{T}) where {T<:MPolyRingElem}
if isdefined(M, :quo) && isdefined(U, :quo)
@assert M.quo == U.quo
else
@assert !isdefined(M, :quo) && !isdefined(U, :quo)
end
return SubquoModule(M, oscar_generators(U.sub.gens))
end
@doc raw"""
quo(F::FreeMod{R}, T::SubquoModule{R}; cache_morphism::Bool=false) where R
Return a pair `(N, pr)` consisting of the quotient $N = F / T$ together with the projection
map `pr : F → N`.
If one is only interested in the actual object `N`, but not the map, use `quo_object` instead.
If `cache_morphism` is set to `true`, the projection is cached and available to `transport` and friends.
"""
function quo(F::FreeMod{R}, T::SubquoModule{R}; cache_morphism::Bool=false) where R
@assert !isdefined(T, :quo)
return quo(F, gens(T); cache_morphism)
end
function quo_object(F::FreeMod{R}, T::SubquoModule{R}) where R
@assert !isdefined(T, :quo)
return quo_object(F, gens(T))
end
@doc raw"""
syzygy_module(F::ModuleGens; sub = FreeMod(base_ring(F.F), length(oscar_generators(F))))
"""
function syzygy_module(F::ModuleGens{T}; sub = FreeMod(base_ring(F.F), length(oscar_generators(F)))) where {T <: MPolyRingElem}
singular_assure(F)
# TODO Obtain the Gröbner basis and cache it
s = Singular.syz(singular_generators(F))
return SubquoModule(sub, s)
end
@doc raw"""
gens(M::SubquoModule{T}) where T
Return the generators of `M`.
"""
function gens(M::SubquoModule{T}) where T
return SubquoModuleElem{T}[gen(M,i) for i=1:ngens(M)]
end
@doc raw"""
gen(M::SubquoModule{T}, i::Int) where T
Return the `i`th generator of `M`.
"""
function gen(M::SubquoModule{T}, i::Int) where T
R = base_ring(M)
v::SRow{T} = sparse_row(R)
v.pos = [i]
v.values = [R(1)]
return SubquoModuleElem{T}(v, M)
end
@doc raw"""
number_of_generators(M::SubquoModule)
Return the number of generators of `M`.
"""
number_of_generators(M::SubquoModule) = number_of_generators(M.sub)
@doc raw"""
base_ring(M::SubquoModule)
Given an `R`-module `M`, return `R`.
"""
base_ring(M::SubquoModule) = base_ring(M.F)::base_ring_type(M.F)
@doc raw"""
zero(M::SubquoModule)
Return the zero element of `M`.
"""
zero(M::SubquoModule) = SubquoModuleElem(SRow(base_ring(M)), M)
@doc raw"""
is_zero(M::SubquoModule)
Return `true` if `M` is the zero module, `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^2+y^2;]
[x^2 + y^2]
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 1 generator
1 -> (x^2 + y^2)*e[1]
by Submodule with 3 generators
1 -> x^2*e[1]
2 -> y^3*e[1]