/
mpoly-ideals.jl
2146 lines (1790 loc) · 62.4 KB
/
mpoly-ideals.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
# constructors #######################################################
@doc raw"""
ideal(R::MPolyRing, V::Vector)
Given a vector `V` of polynomials in `R`, return the ideal of `R` generated by these polynomials.
!!! note
In the graded case, the entries of `V` must be homogeneous.
# Examples
```jldoctest
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> I = ideal(R, [x*y-3*x,y^3-2*x^2*y])
Ideal generated by
x*y - 3*x
-2*x^2*y + y^3
julia> typeof(I)
MPolyIdeal{QQMPolyRingElem}
julia> S, (x, y) = graded_polynomial_ring(QQ, ["x", "y"], [1, 2])
(Graded multivariate polynomial ring in 2 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y])
julia> J = ideal(S, [(x^2+y)^2])
Ideal generated by
x^4 + 2*x^2*y + y^2
julia> typeof(J)
MPolyIdeal{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}
```
"""
function ideal(R::MPolyRing, g::Vector)
h = elem_type(R)[R(f) for f = g]
#if isempty(g)
# push!(h, R())
#end
return MPolyIdeal(R, h)
end
function ideal(I::IdealGens{T}) where {T <: MPolyRingElem}
return MPolyIdeal(I)
end
# TODO: Can we make this the default?
# (Or maybe remove ideal(...) without a ring completely?)
function ideal(Qxy::MPolyRing{T}, x::MPolyRingElem{T}) where T <: RingElem
return ideal(Qxy, [x])
end
function ideal(g::Vector{T}) where {T <: MPolyRingElem}
@req length(g) > 0 "List of elements must be non-empty"
return ideal(parent(g[1]), g)
end
# Coerce an ungraded ideal in a graded ring
function ideal(S::MPolyDecRing, I::MPolyIdeal)
@req base_ring(I) === forget_grading(S) "Rings do not coincide"
return ideal(S, [ S(f) for f in gens(I) ])
end
function is_graded(I::MPolyIdeal)
return is_graded(Hecke.ring(I))
end
# elementary operations #######################################################
@doc raw"""
check_base_rings(I::MPolyIdeal, J::MPolyIdeal)
Throws an error if the base rings of the ideals `I` and `J` do not coincide.
"""
function check_base_rings(I::MPolyIdeal, J::MPolyIdeal)
if !isequal(base_ring(I), base_ring(J))
error("Base rings must coincide.")
end
end
@doc raw"""
^(I::MPolyIdeal, m::Int)
Return the `m`-th power of `I`.
# 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> I = ideal(R, [x, y])
Ideal generated by
x
y
julia> I^3
Ideal generated by
x^3
x^2*y
x*y^2
y^3
```
"""
function Base.:^(I::MPolyIdeal, m::Int)
return MPolyIdeal(base_ring(I), (singular_generators(I))^m)
end
@doc raw"""
+(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
Return the sum of `I` and `J`.
# 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> I = ideal(R, [x, y])
Ideal generated by
x
y
julia> J = ideal(R, [z^2])
Ideal generated by
z^2
julia> I+J
Ideal generated by
x
y
z^2
```
"""
function Base.:+(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
oscar_assure(I)
oscar_assure(J)
check_base_rings(I, J)
newgens = filter!(!iszero, unique!(vcat(I.gens.O,J.gens.O)))
return ideal(base_ring(I), newgens)
end
Base.:-(I::MPolyIdeal, J::MPolyIdeal) = I+J
@doc raw"""
*(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
Return the product of `I` and `J`.
# 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> I = ideal(R, [x, y])
Ideal generated by
x
y
julia> J = ideal(R, [z^2])
Ideal generated by
z^2
julia> I*J
Ideal generated by
x*z^2
y*z^2
```
"""
function Base.:*(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
oscar_assure(I)
oscar_assure(J)
check_base_rings(I, J)
newgens = elem_type(base_ring(I))[]
for g in I.gens.O
for h in J.gens.O
gh = g * h
if !iszero(gh)
push!(newgens, gh)
end
end
end
return ideal(base_ring(I), unique!(newgens))
end
#######################################################
# ideal intersection #######################################################
@doc raw"""
intersect(I::MPolyIdeal{T}, Js::MPolyIdeal{T}...) where T
intersect(V::Vector{MPolyIdeal{T}}) where T
Return the intersection of two or more ideals.
# Examples
```jldoctest
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> I = ideal(R, [x, y])^2;
julia> J = ideal(R, [y^2-x^3+x]);
julia> intersect(I, J)
Ideal generated by
x^3*y - x*y - y^3
x^4 - x^2 - x*y^2
julia> intersect([I, J])
Ideal generated by
x^3*y - x*y - y^3
x^4 - x^2 - x*y^2
```
"""
function Base.intersect(I::MPolyIdeal{T}, Js::MPolyIdeal{T}...) where T
si = singular_generators(I)
si = Singular.intersection(si, [singular_generators(J) for J in Js]...)
return MPolyIdeal(base_ring(I), si)
end
function Base.intersect(V::Vector{MPolyIdeal{T}}) where T
@assert length(V) != 0
length(V) == 1 && return V[1]
return Base.intersect(V[1], V[2:end]...)
end
#######################################################
@doc raw"""
quotient(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
Return the ideal quotient of `I` by `J`. Alternatively, use `I:J`.
quotient(I::MPolyIdeal{T}, f::MPolyRingElem{T}) where T
Return the ideal quotient of `I` by the ideal generated by `f`. Alternatively, use `I:f`.
# 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> I = ideal(R, [x^4+x^2*y*z+y^3*z, y^4+x^3*z+x*y^2*z, x^3*y+x*y^3])
Ideal generated by
x^4 + x^2*y*z + y^3*z
x^3*z + x*y^2*z + y^4
x^3*y + x*y^3
julia> J = ideal(R, [x, y, z])^2
Ideal generated by
x^2
x*y
x*z
y^2
y*z
z^2
julia> L = quotient(I, J)
Ideal generated by
x^3*z + x*y^2*z + y^4
x^3*y + x*y^3
x^4 + x^2*y*z + y^3*z
x^3*z^2 - x^2*y*z^2 + x*y^2*z^2 - y^3*z^2
x^2*y^2*z - x^2*y*z^2 - y^3*z^2
x^3*z^2 + x^2*y^3 - x^2*y^2*z + x*y^2*z^2
julia> I:J
Ideal generated by
x^3*z + x*y^2*z + y^4
x^3*y + x*y^3
x^4 + x^2*y*z + y^3*z
x^3*z^2 - x^2*y*z^2 + x*y^2*z^2 - y^3*z^2
x^2*y^2*z - x^2*y*z^2 - y^3*z^2
x^3*z^2 + x^2*y^3 - x^2*y^2*z + x*y^2*z^2
julia> I:x
Ideal generated by
x^2*y + y^3
x^3*z + x*y^2*z + y^4
x^2*z^2 + x*y^3 - x*y^2*z + y^2*z^2
x^4
x^3*z^2 - x^2*z^3 + 2*x*y^2*z^2 - y^2*z^3
-x^2*z^4 + x*y^2*z^3 - y^2*z^4
```
"""
function quotient(I::MPolyIdeal{T}, J::MPolyIdeal{T}) where T
@assert base_ring(I) == base_ring(J)
return MPolyIdeal(base_ring(I), Singular.quotient(singular_generators(I), singular_generators(J)))
end
function quotient(I::MPolyIdeal{T}, f::T) where T
R = base_ring(I)
@assert R == parent(f)
return quotient(I, ideal(R, [f]))
end
(::Colon)(I::MPolyIdeal, J::MPolyIdeal) = quotient(I, J)
(::Colon)(I::MPolyIdeal, f::MPolyRingElem) = quotient(I, f)
#######################################################
# saturation #######################################################
@doc raw"""
saturation(I::MPolyIdeal{T}, J::MPolyIdeal{T} = ideal(base_ring(I), gens(base_ring(I)))) where T
Return the saturation of `I` with respect to `J`.
If the second ideal `J` is not given, the ideal generated by the generators (variables) of `base_ring(I)` is used.
# 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> I = ideal(R, [z^3, y*z^2, x*z^2, y^2*z, x*y*z, x^2*z, x*y^2, x^2*y])
Ideal generated by
z^3
y*z^2
x*z^2
y^2*z
x*y*z
x^2*z
x*y^2
x^2*y
julia> J = ideal(R, [x, y, z])
Ideal generated by
x
y
z
julia> K = saturation(I, J)
Ideal generated by
z
x*y
julia> K = saturation(I)
Ideal generated by
z
x*y
```
"""
function saturation(I::MPolyIdeal{T}, J::MPolyIdeal{T} = ideal(base_ring(I), gens(base_ring(I)))) where T
K, _ = Singular.saturation(singular_generators(I), singular_generators(J))
return MPolyIdeal(base_ring(I), K)
end
# the following is corresponding to saturation2 from Singular
# TODO: think about how to use use this properly/automatically
function _saturation2(I::MPolyIdeal{T}, J::MPolyIdeal{T} = ideal(base_ring(I), gens(base_ring(I)))) where T
K, _ = Singular.saturation2(singular_generators(I), singular_generators(J))
return MPolyIdeal(base_ring(I), K)
end
#######################################################
@doc raw"""
saturation_with_index(I::MPolyIdeal{T}, J::MPolyIdeal{T} = ideal(base_ring(I), gens(base_ring(I)))) where T
Return $I:J^{\infty}$ together with the smallest integer $m$ such that $I:J^m = I:J^{\infty}$.
If the second ideal `J` is not given, the ideal generated by the generators (variables) of `base_ring(I)` is used.
# 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> I = ideal(R, [z^3, y*z^2, x*z^2, y^2*z, x*y*z, x^2*z, x*y^2, x^2*y])
Ideal generated by
z^3
y*z^2
x*z^2
y^2*z
x*y*z
x^2*z
x*y^2
x^2*y
julia> J = ideal(R, [x, y, z])
Ideal generated by
x
y
z
julia> K, m = saturation_with_index(I, J)
(Ideal (z, x*y), 2)
julia> K, m = saturation_with_index(I)
(Ideal (z, x*y), 2)
```
"""
function saturation_with_index(I::MPolyIdeal{T}, J::MPolyIdeal{T} = ideal(base_ring(I), gens(base_ring(I)))) where T
K, k = Singular.saturation(singular_generators(I), singular_generators(J))
return (MPolyIdeal(base_ring(I), K), k)
end
# elimination #######################################################
@doc raw"""
eliminate(I::MPolyIdeal{T}, V::Vector{T}) where T <: MPolyRingElem
Given a vector `V` of polynomials which are variables, these variables are eliminated from `I`.
That is, return the ideal generated by all polynomials in `I` which only involve the remaining variables.
eliminate(I::MPolyIdeal, V::AbstractVector{Int})
Given a vector `V` of indices which specify variables, these variables are eliminated from `I`.
That is, return the ideal generated by all polynomials in `I` which only involve the remaining variables.
!!! note
The return value is an ideal of the original ring.
# Examples
```jldoctest
julia> R, (t, x, y, z) = polynomial_ring(QQ, ["t", "x", "y", "z"])
(Multivariate polynomial ring in 4 variables over QQ, QQMPolyRingElem[t, x, y, z])
julia> I = ideal(R, [t-x, t^2-y, t^3-z])
Ideal generated by
t - x
t^2 - y
t^3 - z
julia> A = [t]
1-element Vector{QQMPolyRingElem}:
t
julia> TC = eliminate(I, A)
Ideal generated by
-x*z + y^2
x*y - z
x^2 - y
julia> A = [1]
1-element Vector{Int64}:
1
julia> TC = eliminate(I, A)
Ideal generated by
-x*z + y^2
x*y - z
x^2 - y
julia> base_ring(TC)
Multivariate polynomial ring in 4 variables t, x, y, z
over rational field
```
"""
function eliminate(I::MPolyIdeal{T}, l::Vector{T}) where T <: MPolyRingElem
S = singular_polynomial_ring(I)
s = Singular.eliminate(singular_generators(I), [S(x) for x = l]...)
return MPolyIdeal(base_ring(I), s)
end
function eliminate(I::MPolyIdeal, l::AbstractVector{Int})
R = base_ring(I)
return eliminate(I, [gen(R, i) for i=l])
end
### todo: wenn schon GB bzgl. richtiger eliminationsordnung bekannt ...
### Frage: return MPolyIdeal(base_ring(I), s) ???
###################################################
# primary decomposition #######################################################
#######################################################
@doc raw"""
radical(I::MPolyIdeal)
Return the radical of `I`.
# Implemented Algorithms
If the base ring of `I` is a polynomial
ring over a field, a combination of the algorithms of Krick and Logar
(with modifications by Laplagne) and Kemper is used. For polynomial
rings over the integers, the algorithm proceeds as suggested by
Pfister, Sadiq, and Steidel. See [KL91](@cite),
[Kem02](@cite), and [PSS11](@cite).
# Examples
```jldoctest
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> I = intersect(ideal(R, [x, y])^2, ideal(R, [y^2-x^3+x]))
Ideal generated by
x^3*y - x*y - y^3
x^4 - x^2 - x*y^2
julia> I = intersect(I, ideal(R, [x-y-1])^2)
Ideal generated by
x^5*y - 2*x^4*y^2 - 2*x^4*y + x^3*y^3 + 2*x^3*y^2 - x^2*y^3 + 2*x^2*y^2 + 2*x^2*y + 2*x*y^4 + x*y^3 - 2*x*y^2 - x*y - y^5 - 2*y^4 - y^3
x^6 - 2*x^5 - 3*x^4*y^2 - 2*x^4*y + 2*x^3*y^3 + 3*x^3*y^2 + 2*x^3*y + 2*x^3 + 5*x^2*y^2 + 2*x^2*y - x^2 + 3*x*y^4 - 5*x*y^2 - 2*x*y - 2*y^5 - 4*y^4 - 2*y^3
julia> RI = radical(I)
Ideal generated by
x^4 - x^3*y - x^3 - x^2 - x*y^2 + x*y + x + y^3 + y^2
```
```jldoctest
julia> R, (a, b, c, d) = polynomial_ring(ZZ, ["a", "b", "c", "d"])
(Multivariate polynomial ring in 4 variables over ZZ, ZZMPolyRingElem[a, b, c, d])
julia> I = intersect(ideal(R, [9,a,b]), ideal(R, [3,c]))
Ideal generated by
9
3*b
3*a
b*c
a*c
julia> I = intersect(I, ideal(R, [11,2a,7b]))
Ideal generated by
99
3*b
3*a
b*c
a*c
julia> I = intersect(I, ideal(R, [13a^2,17b^4]))
Ideal generated by
39*a^2
13*a^2*c
51*b^4
17*b^4*c
3*a^2*b^4
a^2*b^4*c
julia> I = intersect(I, ideal(R, [9c^5,6d^5]))
Ideal generated by
78*a^2*d^5
117*a^2*c^5
102*b^4*d^5
153*b^4*c^5
6*a^2*b^4*d^5
9*a^2*b^4*c^5
39*a^2*c^5*d^5
51*b^4*c^5*d^5
3*a^2*b^4*c^5*d^5
julia> I = intersect(I, ideal(R, [17,a^15,b^15,c^15,d^15]))
Ideal generated by
1326*a^2*d^5
1989*a^2*c^5
102*b^4*d^5
153*b^4*c^5
663*a^2*c^5*d^5
51*b^4*c^5*d^5
78*a^2*d^15
117*a^2*c^15
78*a^15*d^5
117*a^15*c^5
6*a^2*b^4*d^15
9*a^2*b^4*c^15
39*a^2*c^5*d^15
39*a^2*c^15*d^5
6*a^2*b^15*d^5
9*a^2*b^15*c^5
6*a^15*b^4*d^5
9*a^15*b^4*c^5
39*a^15*c^5*d^5
3*a^2*b^4*c^5*d^15
3*a^2*b^4*c^15*d^5
3*a^2*b^15*c^5*d^5
3*a^15*b^4*c^5*d^5
julia> RI = radical(I)
Ideal generated by
102*b*d
78*a*d
51*b*c
39*a*c
6*a*b*d
3*a*b*c
```
"""
@attr T function radical(I::T) where {T <: MPolyIdeal}
R = base_ring(I)
if isa(base_ring(R), NumField) && !isa(base_ring(R), AbsSimpleNumField)
A, mA = absolute_simple_field(base_ring(R))
r = radical(map_coefficients(pseudo_inv(mA), I))
Irad = map_coefficients(mA, r, parent = R)
set_attribute!(Irad, :is_radical => true)
return Irad
elseif elem_type(base_ring(R)) <: FieldElement
J = Singular.LibPrimdec.radical(singular_polynomial_ring(I), singular_generators(I))
elseif base_ring(singular_polynomial_ring(I)) isa Singular.Integers
J = Singular.LibPrimdecint.radicalZ(singular_polynomial_ring(I), singular_generators(I))
else
error("not implemented for base ring")
end
Irad = ideal(R, J)
set_attribute!(Irad, :is_radical => true)
return Irad
end
function map_coefficients(mp, I::MPolyIdeal; parent = nothing)
if parent === nothing
parent = Oscar.parent(map_coefficients(mp, gen(I, 1)))
end
return ideal(parent, [map_coefficients(mp, g, parent = parent) for g = gens(I)])
end
@doc raw"""
is_radical(I::MPolyIdeal)
Return whether `I` is a radical ideal.
Computes the radical.
"""
@attr Bool function is_radical(I::MPolyIdeal)
if has_attribute(I, :is_prime) && is_prime(I)
return true
end
return I == radical(I)
end
#######################################################
@doc raw"""
primary_decomposition(I::MPolyIdeal; algorithm = :GTZ, cache=true)
Return a minimal primary decomposition of `I`.
The decomposition is returned as a vector of tuples $(Q_1, P_1), \dots, (Q_t, P_t)$, say,
where each $Q_i$ is a primary ideal with associated prime $P_i$, and where the intersection of
the $Q_i$ is `I`.
# Implemented Algorithms
If the base ring of `I` is a polynomial ring over a field, the algorithm of Gianni, Trager, and Zacharias
is used by default (`algorithm = :GTZ`). Alternatively, the algorithm by Shimoyama and Yokoyama can be used
by specifying `algorithm = :SY`. For polynomial rings over the integers, the algorithm proceeds as suggested by
Pfister, Sadiq, and Steidel. See [GTZ88](@cite), [SY96](@cite), and [PSS11](@cite).
!!! warning
The algorithm of Gianni, Trager, and Zacharias may not terminate over a small finite field. If it terminates, the result is correct.
!!! warning
If computations are done in a ring over a number field, then the output may contain redundant components.
If `cache=false` is set, the primary decomposition is recomputed and not cached.
# Examples
```jldoctest
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> I = intersect(ideal(R, [x, y])^2, ideal(R, [y^2-x^3+x]))
Ideal generated by
x^3*y - x*y - y^3
x^4 - x^2 - x*y^2
julia> I = intersect(I, ideal(R, [x-y-1])^2)
Ideal generated by
x^5*y - 2*x^4*y^2 - 2*x^4*y + x^3*y^3 + 2*x^3*y^2 - x^2*y^3 + 2*x^2*y^2 + 2*x^2*y + 2*x*y^4 + x*y^3 - 2*x*y^2 - x*y - y^5 - 2*y^4 - y^3
x^6 - 2*x^5 - 3*x^4*y^2 - 2*x^4*y + 2*x^3*y^3 + 3*x^3*y^2 + 2*x^3*y + 2*x^3 + 5*x^2*y^2 + 2*x^2*y - x^2 + 3*x*y^4 - 5*x*y^2 - 2*x*y - 2*y^5 - 4*y^4 - 2*y^3
julia> L = primary_decomposition(I)
3-element Vector{Tuple{MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{QQMPolyRingElem}}}:
(Ideal (x^3 - x - y^2), Ideal (x^3 - x - y^2))
(Ideal (x^2 - 2*x*y - 2*x + y^2 + 2*y + 1), Ideal (x - y - 1))
(Ideal (y, x^2), Ideal (x, y))
julia> L = primary_decomposition(I, algorithm = :SY, cache=false)
3-element Vector{Tuple{MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{QQMPolyRingElem}}}:
(Ideal (x^3 - x - y^2), Ideal (x^3 - x - y^2))
(Ideal (x^2 - 2*x*y - 2*x + y^2 + 2*y + 1), Ideal (x - y - 1))
(Ideal (y, x^2), Ideal (y, x))
```
```jldoctest
julia> R, (a, b, c, d) = polynomial_ring(ZZ, ["a", "b", "c", "d"])
(Multivariate polynomial ring in 4 variables over ZZ, ZZMPolyRingElem[a, b, c, d])
julia> I = ideal(R, [1326*a^2*d^5, 1989*a^2*c^5, 102*b^4*d^5, 153*b^4*c^5,
663*a^2*c^5*d^5, 51*b^4*c^5*d^5, 78*a^2*d^15, 117*a^2*c^15,
78*a^15*d^5, 117*a^15*c^5, 6*a^2*b^4*d^15, 9*a^2*b^4*c^15,
39*a^2*c^5*d^15, 39*a^2*c^15*d^5, 6*a^2*b^15*d^5, 9*a^2*b^15*c^5,
6*a^15*b^4*d^5, 9*a^15*b^4*c^5, 39*a^15*c^5*d^5, 3*a^2*b^4*c^5*d^15,
3*a^2*b^4*c^15*d^5, 3*a^2*b^15*c^5*d^5, 3*a^15*b^4*c^5*d^5])
Ideal generated by
1326*a^2*d^5
1989*a^2*c^5
102*b^4*d^5
153*b^4*c^5
663*a^2*c^5*d^5
51*b^4*c^5*d^5
78*a^2*d^15
117*a^2*c^15
78*a^15*d^5
117*a^15*c^5
6*a^2*b^4*d^15
9*a^2*b^4*c^15
39*a^2*c^5*d^15
39*a^2*c^15*d^5
6*a^2*b^15*d^5
9*a^2*b^15*c^5
6*a^15*b^4*d^5
9*a^15*b^4*c^5
39*a^15*c^5*d^5
3*a^2*b^4*c^5*d^15
3*a^2*b^4*c^15*d^5
3*a^2*b^15*c^5*d^5
3*a^15*b^4*c^5*d^5
julia> L = primary_decomposition(I)
8-element Vector{Tuple{MPolyIdeal{ZZMPolyRingElem}, MPolyIdeal{ZZMPolyRingElem}}}:
(Ideal (d^5, c^5), Ideal (d, c))
(Ideal (a^2, b^4), Ideal (b, a))
(Ideal (2, c^5), Ideal (2, c))
(Ideal (3), Ideal (3))
(Ideal (13, b^4), Ideal (13, b))
(Ideal (17, a^2), Ideal (17, a))
(Ideal (17, d^15, c^15, b^15, a^15), Ideal (17, d, c, b, a))
(Ideal (9, 3*d^5, d^10), Ideal (3, d))
```
"""
function primary_decomposition(I::T; algorithm::Symbol=:GTZ, cache::Bool=true) where {T<:MPolyIdeal}
!cache && return _compute_primary_decomposition(I, algorithm=algorithm)
return get_attribute!(I, :primary_decomposition) do
return _compute_primary_decomposition(I, algorithm=algorithm)
end::Vector{Tuple{T,T}}
end
function primary_decomposition(
I::MPolyIdeal{T};
algorithm::Symbol=:GTZ, cache::Bool=true
) where {U<:Union{AbsSimpleNumFieldElem, <:Hecke.RelSimpleNumFieldElem}, T<:MPolyRingElem{U}}
if has_attribute(I, :primary_decomposition)
return get_attribute(I, :primary_decomposition)::Vector{Tuple{typeof(I), typeof(I)}}
end
R = base_ring(I)
R_flat, iso, iso_inv = _expand_coefficient_field_to_QQ(R)
I_flat = ideal(R_flat, iso_inv.(gens(I)))
dec = primary_decomposition(I_flat; algorithm, cache)
result = Vector{Tuple{typeof(I), typeof(I)}}()
for (P, Q) in dec
push!(result, (ideal(R, unique!([x for x in iso.(gens(P)) if !iszero(x)])),
ideal(R, unique!([x for x in iso.(gens(Q)) if !iszero(x)]))))
end
for (Q,P) in result
set_attribute!(P, :is_prime=>true)
set_attribute!(Q, :is_primary=>true)
end
cache && set_attribute!(I, :primary_decomposition=>result)
return result
end
function _compute_primary_decomposition(I::MPolyIdeal; algorithm::Symbol=:GTZ)
R = base_ring(I)
if isa(base_ring(R), NumField) && !isa(base_ring(R), AbsSimpleNumField)
A, mA = absolute_simple_field(base_ring(R))
pd = primary_decomposition(map_coefficients(pseudo_inv(mA), I), algorithm = algorithm, cache = false)
if isempty(pd)
return Tuple{typeof(I), typeof(I)}[]
end
return Tuple{typeof(I), typeof(I)}[(map_coefficients(mA, x[1], parent = R), map_coefficients(mA, x[2], parent = R)) for x = pd]
end
if elem_type(base_ring(R)) <: FieldElement
if algorithm == :GTZ
L = Singular.LibPrimdec.primdecGTZ(singular_polynomial_ring(I), singular_generators(I))
elseif algorithm == :SY
L = Singular.LibPrimdec.primdecSY(singular_polynomial_ring(I), singular_generators(I))
else
error("algorithm invalid")
end
elseif base_ring(singular_polynomial_ring(I)) isa Singular.Integers
L = Singular.LibPrimdecint.primdecZ(singular_polynomial_ring(I), singular_generators(I))
else
error("base ring not implemented")
end
V = [(ideal(R, q[1]), ideal(R, q[2])) for q in L]
if length(V) == 1 && is_one(gen(V[1][1], 1))
return Tuple{typeof(I), typeof(I)}[]
end
return V
end
########################################################
@doc raw"""
absolute_primary_decomposition(I::MPolyIdeal{<:MPolyRingElem{QQFieldElem}})
Given an ideal `I` in a multivariate polynomial ring over the rationals, return an absolute minimal primary decomposition of `I`.
Return the decomposition as a vector of tuples $(Q_i, P_i, P_{ij}, d_{ij})$, say,
where $(Q_i, P_i)$ is a (primary, prime) tuple as returned by `primary_decomposition(I)`,
and $P_{ij}$ represents a corresponding class of conjugated absolute associated primes
defined over a number field of degree $d_{ij}$ whose generator prints as `_a`.
# Implemented Algorithms
The implementation combines the algorithm of Gianni, Trager, and Zacharias for primary
decomposition with absolute polynomial factorization.
!!! warning
Over number fields this proceduce might return redundant output.
# Examples
```jldoctest
julia> R, (y, z) = polynomial_ring(QQ, ["y", "z"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[y, z])
julia> p = z^2+1
z^2 + 1
julia> q = z^3+2
z^3 + 2
julia> I = ideal(R, [p*q^2, y-z^2])
Ideal generated by
z^8 + z^6 + 4*z^5 + 4*z^3 + 4*z^2 + 4
y - z^2
julia> L = primary_decomposition(I)
2-element Vector{Tuple{MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{QQMPolyRingElem}}}:
(Ideal (z^2 + 1, y - z^2), Ideal (z^2 + 1, y - z^2))
(Ideal (z^6 + 4*z^3 + 4, y - z^2), Ideal (z^3 + 2, y - z^2))
julia> AL = absolute_primary_decomposition(I)
2-element Vector{Tuple{MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{AbstractAlgebra.Generic.MPoly{AbsSimpleNumFieldElem}}, Int64}}:
(Ideal (z^2 + 1, y + 1), Ideal (z^2 + 1, y + 1), Ideal (z - _a, y + 1), 2)
(Ideal (z^6 + 4*z^3 + 4, y - z^2), Ideal (z^3 + 2, y - z^2), Ideal (z - _a, y - _a^2), 3)
julia> AP = AL[1][3]
Ideal generated by
z - _a
y + 1
julia> RAP = base_ring(AP)
Multivariate polynomial ring in 2 variables y, z
over number field of degree 2 over QQ
julia> NF = coefficient_ring(RAP)
Number field with defining polynomial x^2 + 1
over rational field
julia> a = gen(NF)
_a
julia> minpoly(a)
x^2 + 1
```
```jldoctest
julia> R, (x, y) = graded_polynomial_ring(QQ, ["x", "y"])
(Graded multivariate polynomial ring in 2 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y])
julia> I = ideal(R, [x^2+y^2])
Ideal generated by
x^2 + y^2
julia> AL = absolute_primary_decomposition(I)
1-element Vector{Tuple{MPolyIdeal{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}, MPolyIdeal{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}, MPolyIdeal{MPolyDecRingElem{AbsSimpleNumFieldElem, AbstractAlgebra.Generic.MPoly{AbsSimpleNumFieldElem}}}, Int64}}:
(Ideal (x^2 + y^2), Ideal (x^2 + y^2), Ideal (x + _a*y), 2)
julia> AP = AL[1][3]
Ideal generated by
x + _a*y
julia> RAP = base_ring(AP)
Multivariate polynomial ring in 2 variables over number field graded by
x -> [1]
y -> [1]
```
"""
@attr function absolute_primary_decomposition(I::MPolyIdeal{<:MPolyRingElem{QQFieldElem}})
R = base_ring(I)
if is_zero(I)
return [(ideal(R, zero(R)), ideal(R, zero(R)), ideal(R, zero(R)), 1)]
end
(S, d) = Singular.LibPrimdec.absPrimdecGTZ(singular_polynomial_ring(I), singular_generators(I))
decomp = d[:primary_decomp]
absprimes = d[:absolute_primes]
@assert length(decomp) == length(absprimes)
V = [(_map_last_var(R, decomp[i][1], 1, one(QQ))) for i in 1:length(decomp)]
if length(V) == 1 && is_one(gen(V[1], 1))
return Tuple{MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{QQMPolyRingElem}, MPolyIdeal{AbstractAlgebra.Generic.MPoly{AbsSimpleNumFieldElem}}, Int64}[]
end
return [(V[i], _map_last_var(R, decomp[i][2], 1, one(QQ)),
_map_to_ext(R, absprimes[i][1]),
absprimes[i][2]::Int)
for i in 1:length(decomp)]
end
@attr function absolute_primary_decomposition(
I::MPolyIdeal{T}
) where {U<:Union{AbsSimpleNumFieldElem, <:Hecke.RelSimpleNumFieldElem}, T<:MPolyRingElem{U}}
R = base_ring(I)
kk = coefficient_ring(R)
R_exp, iso, iso_inv = _expand_coefficient_field_to_QQ(R)
iso_inv(one(R))
I_exp = ideal(R_exp, iso_inv.(gens(I)))
res = absolute_primary_decomposition(I_exp)
full_res = []
for (P_ext, Q_ext, P_prime, d) in res
@assert base_ring(P_ext) === R_exp
P = ideal(R, unique!(iso.(gens(P_ext))))
Q = ideal(R, unique!(iso.(gens(Q_ext))))
RR = base_ring(P_prime)
L = coefficient_ring(RR)
f = defining_polynomial(L)
f_kk = map_coefficients(kk, f)
h = first([h for (h, _) in factor(f_kk)])
kk_ext, zeta = extension_field(h)
iso_kk_ext = hom(L, kk_ext, zeta)
br = base_ring(P_prime)
LoR, to_LoR = change_base_ring(kk_ext, R)
help_map = hom(br, LoR, iso_kk_ext, to_LoR.(iso.(gens(R_exp))))
P_prime_ext = ideal(LoR, help_map.(gens(P_prime)))
push!(full_res, (P, Q, P_prime_ext, degree(h)))
end
return full_res
end
# the ideals in QQbar[x] come back in QQ[x,a] with an extra variable a added
# and the minpoly of a prepended to the ideal generator list
function _map_to_ext(Qx::MPolyRing, I::Oscar.Singular.sideal)
Qxa = base_ring(I)
@assert nvars(Qxa) == nvars(Qx) + 1
p = I[1]
minpoly = zero(Hecke.Globals.Qx)
for (c, e) in zip(AbstractAlgebra.coefficients(p), AbstractAlgebra.exponent_vectors(p))
setcoeff!(minpoly, e[nvars(Qxa)], QQ(c))
end
R, a = number_field(minpoly)
if is_graded(Qx)
Rx, _ = graded_polynomial_ring(R, symbols(Qx), [degree(x) for x = gens(Qx)])
else
Rx, _ = polynomial_ring(R, symbols(Qx))
end
return _map_last_var(Rx, I, 2, a)
end
# the ideals in QQ[x] also come back in QQ[x,a]
function _map_last_var(Qx::MPolyRing, I::Singular.sideal, start, a)
newgens = elem_type(Qx)[]
for i in start:ngens(I)
p = I[i]
g = MPolyBuildCtx(Qx)
for (c, e) in zip(AbstractAlgebra.coefficients(p), AbstractAlgebra.exponent_vectors(p))
ca = QQ(c)*a^pop!(e)
push_term!(g, ca, e)
end
push!(newgens, finish(g))
end
return ideal(Qx, newgens)
end
#######################################################
@doc raw"""
minimal_primes(I::MPolyIdeal; algorithm::Symbol = :GTZ)
Return a vector containing the minimal associated prime ideals of `I`.
# Implemented Algorithms
If the base ring of `I` is a polynomial ring over a field, the algorithm of
Gianni, Trager, and Zacharias is used by default (`algorithm = :GTZ`). Alternatively, characteristic sets can be
used by specifying `algorithm = :charSets`. For polynomial rings over the integers,
the algorithm proceeds as suggested by Pfister, Sadiq, and Steidel.
See [GTZ88](@cite) and [PSS11](@cite).
# Examples
```jldoctest
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> I = intersect(ideal(R, [x, y])^2, ideal(R, [y^2-x^3+x]))
Ideal generated by
x^3*y - x*y - y^3
x^4 - x^2 - x*y^2
julia> I = intersect(I, ideal(R, [x-y-1])^2)
Ideal generated by
x^5*y - 2*x^4*y^2 - 2*x^4*y + x^3*y^3 + 2*x^3*y^2 - x^2*y^3 + 2*x^2*y^2 + 2*x^2*y + 2*x*y^4 + x*y^3 - 2*x*y^2 - x*y - y^5 - 2*y^4 - y^3
x^6 - 2*x^5 - 3*x^4*y^2 - 2*x^4*y + 2*x^3*y^3 + 3*x^3*y^2 + 2*x^3*y + 2*x^3 + 5*x^2*y^2 + 2*x^2*y - x^2 + 3*x*y^4 - 5*x*y^2 - 2*x*y - 2*y^5 - 4*y^4 - 2*y^3
julia> L = minimal_primes(I)
2-element Vector{MPolyIdeal{QQMPolyRingElem}}:
Ideal (x - y - 1)
Ideal (x^3 - x - y^2)
julia> L = minimal_primes(I, algorithm = :charSets)
2-element Vector{MPolyIdeal{QQMPolyRingElem}}:
Ideal (x - y - 1)
Ideal (x^3 - x - y^2)
```
```jldoctest
julia> R, (a, b, c, d) = polynomial_ring(ZZ, ["a", "b", "c", "d"])
(Multivariate polynomial ring in 4 variables over ZZ, ZZMPolyRingElem[a, b, c, d])
julia> I = ideal(R, [1326*a^2*d^5, 1989*a^2*c^5, 102*b^4*d^5, 153*b^4*c^5,
663*a^2*c^5*d^5, 51*b^4*c^5*d^5, 78*a^2*d^15, 117*a^2*c^15,
78*a^15*d^5, 117*a^15*c^5, 6*a^2*b^4*d^15, 9*a^2*b^4*c^15,
39*a^2*c^5*d^15, 39*a^2*c^15*d^5, 6*a^2*b^15*d^5, 9*a^2*b^15*c^5,
6*a^15*b^4*d^5, 9*a^15*b^4*c^5, 39*a^15*c^5*d^5, 3*a^2*b^4*c^5*d^15,
3*a^2*b^4*c^15*d^5, 3*a^2*b^15*c^5*d^5, 3*a^15*b^4*c^5*d^5])
Ideal generated by
1326*a^2*d^5
1989*a^2*c^5
102*b^4*d^5