-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathmpoly-localizations.jl
2713 lines (2334 loc) · 88.7 KB
/
mpoly-localizations.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
import Base: issubset
import AbstractAlgebra: Ring, RingElem
########################################################################
# General framework for localizations of multivariate polynomial rings #
########################################################################
########################################################################
# Multiplicatively closed sets in multivariate polynomial rings #
########################################################################
abstract type AbsMPolyMultSet{BRT, BRET, RT, RET} <: AbsMultSet{RT, RET} end
########################################################################
# Powers of elements #
########################################################################
@doc raw"""
MPolyPowersOfElement{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
The set `S = { aᵏ : k ∈ ℕ₀ }` for some ``a ∈ R`` with ``R`` of type `BaseRingType`.
"""
mutable struct MPolyPowersOfElement{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
R::RingType # the parent ring
a::Vector{RingElemType} # the list of elements whose powers belong to this set
function MPolyPowersOfElement(R::RingType, a::Vector{RingElemType}) where {RingType<:MPolyRing, RingElemType<:MPolyRingElem}
for f in a
parent(f) == R || error("element does not belong to the given ring")
!iszero(f) || error("can not localize at the zero element")
end
k = coefficient_ring(R)
return new{typeof(k), elem_type(k), RingType, RingElemType}(R, a)
end
end
### required getter functions
ambient_ring(S::MPolyPowersOfElement) = S.R
### additional constructors
MPolyPowersOfElement(f::RET) where {RET<:MPolyRingElem} = MPolyPowersOfElement(parent(f), [f])
units_of(R::RT) where {RT<:MPolyRing} = MPolyPowersOfElement(R, [one(R)])
### additional functionality
denominators(S::MPolyPowersOfElement) = copy(S.a)
### required functionality
function Base.in(
f::RingElemType,
S::MPolyPowersOfElement{BaseRingType, BaseRingElemType, RingType, RingElemType}
) where {BaseRingType, BaseRingElemType, RingType, RingElemType}
R = parent(f)
R == ambient_ring(S) || return false
if iszero(f)
return false
end
d = (length(denominators(S)) == 0 ? one(R) : prod(denominators(S)))
# We need to check whether for some a ∈ R and k ∈ ℕ we have
# a⋅f = dᵏ.
(i, o) = ppio(f, d)
#return divides(one(R), o)[1]
return is_unit(o)
end
### iteration
Base.iterate(U::MPolyPowersOfElement) = (length(U.a)>0 ? (U.a[1], 1) : nothing)
Base.iterate(U::MPolyPowersOfElement, a::Tuple{<:MPolyRingElem, Int}) = (a[2] < length(U.a) ? (U.a[a[2]+1], a[2]+1) : nothing)
Base.iterate(U::MPolyPowersOfElement, i::Int) = (i < length(U.a) ? (U.a[i+1], i+1) : nothing)
is_trivial(U::MPolyPowersOfElement) = (U == units_of(ambient_ring(U)))
### printing
function Base.show(io::IO, S::MPolyPowersOfElement)
print(io, "powers of ")
print(io, denominators(S))
end
### generation of random elements
function rand(S::MPolyPowersOfElement, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
R = ambient_ring(S)
return prod(f^rand(0:2) for f in denominators(S); init = one(R))::elem_type(R)
end
function rand(rng::Random.AbstractRNG, S::MPolyPowersOfElement, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
R = ambient_ring(S)
return prod(f^rand(rng, 0:2) for f in denominators(S); init = one(R))::elem_type(R)
end
### simplification.
# Replaces each element d by its list of square free prime divisors.
function simplify!(S::MPolyPowersOfElement)
R = ambient_ring(S)
new_denom = Vector{elem_type(R)}()
for d in denominators(S)
for a in factor(d)
push!(new_denom, a[1])
end
end
S.a = new_denom
return S
end
########################################################################
# Complements of prime ideals #
########################################################################
@doc raw"""
MPolyComplementOfPrimeIdeal{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
The complement of a prime ideal ``P ⊂ 𝕜[x₁,…,xₙ]`` in a multivariate polynomial ring
with elements of type `RingElemType` over a base ring ``𝕜`` of type `BaseRingType`.
"""
mutable struct MPolyComplementOfPrimeIdeal{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
# The parent polynomial ring 𝕜[x₁,…,xₙ]
R::RingType
# The prime ideal whose complement this is
P::MPolyIdeal{RingElemType}
function MPolyComplementOfPrimeIdeal(
P::MPolyIdeal{RingElemType};
check::Bool=false
) where {RingElemType}
R = base_ring(P)
check && (is_prime(P) || error("the ideal $P is not prime"))
return new{typeof(coefficient_ring(R)), elem_type(coefficient_ring(R)), typeof(R), elem_type(R)}(R, P)
end
end
### required getter functions
ambient_ring(
S::MPolyComplementOfPrimeIdeal) = S.R
### required functionality
function Base.in(
f::RingElemType,
S::MPolyComplementOfPrimeIdeal{BaseRingType, BaseRingElemType, RingType, RingElemType}
) where {BaseRingType, BaseRingElemType, RingType, RingElemType}
return !(f in prime_ideal(S))
end
### additional functionality
prime_ideal(S::MPolyComplementOfPrimeIdeal) = S.P
### printing
function Base.show(io::IO, S::MPolyComplementOfPrimeIdeal)
print(io, "complement of ")
print(io, prime_ideal(S))
end
### generation of random elements
function rand(S::MPolyComplementOfPrimeIdeal, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
f = rand(ambient_ring(S), v1, v2, v3)
if f in prime_ideal(S)
return rand(S, v1, v2, v3)
end
return f
end
function rand(rng::Random.AbstractRNG, S::MPolyComplementOfPrimeIdeal, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
f = rand(rng, ambient_ring(S), v1, v2, v3)
if f in prime_ideal(S)
return rand(rng, S, v1, v2, v3)
end
return f
end
########################################################################
# Complements of maximal ideals corresponding to 𝕜-points #
########################################################################
@doc raw"""
MPolyComplementOfKPointIdeal{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
Complement of a maximal ideal ``𝔪 = ⟨x₁-a₁,…,xₙ-aₙ⟩⊂ 𝕜[x₁,…xₙ]`` with ``aᵢ∈ 𝕜``.
"""
mutable struct MPolyComplementOfKPointIdeal{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
# The parent polynomial ring 𝕜[x₁,…,xₙ]
R::RingType
# The coordinates aᵢ of the point in 𝕜ⁿ corresponding to the maximal ideal
a::Vector{BaseRingElemType}
function MPolyComplementOfKPointIdeal(R::RingType, a::Vector{T}) where {RingType<:MPolyRing, T<:RingElement}
length(a) == ngens(R) || error("the number of variables in the ring does not coincide with the number of coordinates")
n = length(a)
kk = coefficient_ring(R)
b = kk.(a) # fails if the input is not compatible
S = new{typeof(kk), elem_type(kk), RingType, elem_type(R)}(R, b)
return S
end
end
@doc raw"""
complement_of_point_ideal(R::MPolyRing, a::Vector)
Given a polynomial ring ``R``, say ``R = K[x_1,\dots, x_n]``, and given a vector
``a = (a_1, \dots, a_n)`` of ``n`` elements of ``K``, return the multiplicatively
closed subset ``R\setminus m``, where ``m`` is the maximal ideal
$$m = \langle x_1-a_1,\dots, x_n-a_n\rangle \subset R.$$
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> U = complement_of_point_ideal(R, [0, 0 ,0])
complement of maximal ideal corresponding to point with coordinates QQFieldElem[0, 0, 0]
```
"""
complement_of_point_ideal(R::MPolyRing, a::Vector) = MPolyComplementOfKPointIdeal(R, a)
@doc raw"""
complement_of_prime_ideal(P::MPolyIdeal; check::Bool=false)
Given a prime ideal ``P`` of a polynomial ring ``R``, say,
return the multiplicatively closed subset ``R\setminus P.``
!!! note
If `check` is set to `true`, the function checks whether ``P`` is indeed a prime ideal.
This may take some time.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> P = ideal(R, [x])
ideal(x)
julia> U = complement_of_prime_ideal(P)
complement of ideal(x)
```
"""
complement_of_prime_ideal(P::MPolyIdeal; check::Bool=false) = MPolyComplementOfPrimeIdeal(P; check)
@doc raw"""
powers_of_element(f::MPolyRingElem)
Given an element `f` of a polynomial ring, return the multiplicatively
closed subset of the polynomial ring which is formed by the powers of `f`.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> f = x
x
julia> U = powers_of_element(f)
powers of QQMPolyRingElem[x]
```
"""
powers_of_element(f::MPolyRingElem) = MPolyPowersOfElement(f)
### required getter functions
ambient_ring(S::MPolyComplementOfKPointIdeal) = S.R
### additional getter functions
point_coordinates(S::MPolyComplementOfKPointIdeal) = S.a
### required functionality
function Base.in(
f::RingElemType,
S::MPolyComplementOfKPointIdeal{BaseRingType, BaseRingElemType, RingType, RingElemType}
) where {BaseRingType, BaseRingElemType, RingType, RingElemType}
parent(f) == ambient_ring(S) || return false
return !(evaluate(f, point_coordinates(S)) == zero(ambient_ring(S)))
end
### printing
function Base.show(io::IO, S::MPolyComplementOfKPointIdeal)
print(io, "complement of maximal ideal corresponding to point with coordinates ")
print(io, point_coordinates(S))
end
### generation of random elements
function rand(S::MPolyComplementOfKPointIdeal, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
f = rand(ambient_ring(S), v1, v2, v3)
if !(f in S)
return rand(S, v1, v2, v3)
end
return f
end
function rand(rng::Random.AbstractRNG, S::MPolyComplementOfKPointIdeal, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
f = rand(rng, ambient_ring(S), v1, v2, v3)
if !(f in S)
return rand(rng, S, v1, v2, v3)
end
return f
end
@doc raw"""
MPolyProductOfMultSets{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
A finite product `T⋅U = { a⋅b : a ∈ T, b∈ U}` of arbitrary other
multiplicative sets in a multivariate polynomial ring.
"""
mutable struct MPolyProductOfMultSets{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
R::RingType
U::Vector{<:AbsMPolyMultSet{BaseRingType, BaseRingElemType, RingType, RingElemType}}
function MPolyProductOfMultSets(R::RT, U::Vector{<:AbsMPolyMultSet{BRT, BRET, RT, RET}}) where {BRT<:Ring, BRET<:RingElement, RT<:MPolyRing, RET<:MPolyRingElem}
for s in U
ambient_ring(s) == R || error("multiplicative set does not live in the given ring")
end
return new{typeof(coefficient_ring(R)), elem_type(coefficient_ring(R)), typeof(R), elem_type(R)}(R, U)
end
end
### required getter functions
ambient_ring(S::MPolyProductOfMultSets) = S.R
### additional functionality
getindex(S::MPolyProductOfMultSets, i::Integer) = S.U[i]
sets(S::MPolyProductOfMultSets) = copy(S.U)
### required functionality
function Base.in(
f::RingElemType,
S::MPolyProductOfMultSets{BaseRingType, BaseRingElemType, RingType, RingElemType}
) where {BaseRingType, BaseRingElemType, RingType, RingElemType}
R = ambient_ring(S)
divides(one(R), f)[1] && return true
U = sets(S)
for s in U
f in s && return true
end
# From here onwards, computations might not be cheap anymore
a = factor(f)
for fac in a
# check for each factor whether it belongs to one of the admissible sets
tmp_result = false
for s in U
if fac[1] in s
tmp_result = true
break
end
end
tmp_result || return false
end
return true
end
### printing
function Base.show(io::IO, S::MPolyProductOfMultSets)
print(io, "product of the multiplicative sets [")
for s in sets(S)
print(io, s)
s != last(sets(S)) && print(io, ", ")
end
print(io, "]")
end
### generation of random elements
function rand(S::MPolyProductOfMultSets, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
return prod([rand(s, v1, v2, v3) for s in sets(S)])::elem_type(ambient_ring(S))
end
function rand(rng::Random.AbstractRNG, S::MPolyProductOfMultSets, v1::UnitRange{Int}, v2::UnitRange{Int}, v3::UnitRange{Int})
return prod([rand(rng, s, v1, v2, v3) for s in sets(S)])::elem_type(ambient_ring(S))
end
########################################################################
# Localization associated to a monomial ordering #
########################################################################
@doc raw"""
MPolyLeadingMonOne{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
The set `S = { a in R : leading_monomial(a, ord) = 1 }` for a fixed
monomial ordering `ord`.
"""
mutable struct MPolyLeadingMonOne{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
} <: AbsMPolyMultSet{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType
}
R::RingType # the parent ring
ord::MonomialOrdering
function MPolyLeadingMonOne(R::RingType, ord::MonomialOrdering) where {RingType <: MPolyRing}
@assert R === ord.R "Ordering does not belong to the given ring"
k = coefficient_ring(R)
return new{typeof(k), elem_type(k), RingType, elem_type(R)}(R, ord)
end
end
### required getter functions
ambient_ring(S::MPolyLeadingMonOne) = S.R
### additional constructors
MPolyLeadingMonOne(ord::MonomialOrdering) = MPolyLeadingMonOne(ord.R, ord)
ordering(S::MPolyLeadingMonOne) = S.ord
### required functionality
function Base.in(
f::RingElemType,
S::MPolyLeadingMonOne{BaseRingType, BaseRingElemType, RingType, RingElemType}
) where {BaseRingType, BaseRingElemType, RingType, RingElemType}
R = parent(f)
R == ambient_ring(S) || return false
if iszero(f)
return false
end
return isone(leading_monomial(f; ordering = ordering(S)))
end
### printing
function Base.show(io::IO, S::MPolyLeadingMonOne)
print(io, "elements of ")
print(io, ambient_ring(S))
print(io, " with leading monomial 1 w.r.t. ")
print(io, ordering(S))
end
########################################################################
# Arithmetic of multiplicative sets #
########################################################################
### containment ########################################################
⊂(T::AbsMPolyMultSet, U::AbsMPolyMultSet) = issubset(T, U)
function issubset(T::AbsMPolyMultSet, U::AbsMPolyMultSet)
ambient_ring(T) == ambient_ring(U) || return false
error("comparison of multiplicative sets of type $(typeof(T)) and $(typeof(U)) is not implemented")
end
function ==(T::AbsMPolyMultSet, U::AbsMPolyMultSet)
return (issubset(T, U) && issubset(U, T))
end
function issubset(
T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET},
U::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
return issubset(prime_ideal(U), prime_ideal(T))
end
function issubset(
T::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET},
U::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
a = point_coordinates(U)
b = point_coordinates(T)
for i in 1:length(a)
a[i] == b[i] || return false
end
return true
end
function issubset(
T::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET},
U::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
a = point_coordinates(T)
for i in 1:length(a)
(gen(R, i)- R(a[i])) in prime_ideal(U) || return false
end
return true
end
function issubset(
T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET},
U::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
a = point_coordinates(U)
for f in gens(prime_ideal(T))
iszero(evaluate(f, a)) || return false
end
return true
end
function issubset(
T::MPolyPowersOfElement{BRT, BRET, RT, RET},
U::AbsMPolyMultSet{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
for a in denominators(T)
a in U || return false
end
return true
end
function issubset(
T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET},
U::MPolyPowersOfElement{BRT, BRET, RT, RET},
) where {BRT, BRET, RT, RET}
return false
end
function issubset(
T::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET},
U::MPolyPowersOfElement{BRT, BRET, RT, RET},
) where {BRT, BRET, RT, RET}
return false
end
function issubset(
T::MPolyProductOfMultSets{BRT, BRET, RT, RET},
U::MPolyProductOfMultSets{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
for V in sets(T)
issubset(V, U) || return false
end
return true
end
function issubset(
T::MPolyProductOfMultSets{BRT, BRET, RT, RET},
U::AbsMPolyMultSet{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
for V in sets(T)
issubset(V, U) || return false
end
return true
end
function issubset(
T::AbsMPolyMultSet{BRT, BRET, RT, RET},
U::MPolyProductOfMultSets{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
for V in sets(U)
issubset(T, V) && return true
end
error("containment can not be checked")
end
function issubset(
T::MPolyPowersOfElement{BRT, BRET, RT, RET},
U::MPolyProductOfMultSets{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
for d in denominators(T)
d in U || return false
end
return true
end
### intersections ######################################################
function intersect(T::AbsMPolyMultSet, U::AbsMPolyMultSet)
error("intersection of multiplicative sets of type $(typeof(T)) and $(typeof(U)) is not implemented")
end
# TODO: Implement this if necessary!
### functionality for taking products
#
# Definition.
# Let T and U be multiplicative sets in a commutative ring R. The product
# of T and U is defined as
#
# T⋅U = { f⋅g : f ∈ T and g ∈ U }.
#
# A product of multiplicative sets U = U₁⋅…⋅Uₙ is called interreduced
# if neither one of the factors Uᵢ is contained in one of the others Uⱼ, j≠i.
#
# Lemma.
# Any product of multiplicative sets U = U₁⋅…⋅Uₙ may be replaced by
# an interreduced one.
#
# Remark.
# An interreduced factorization of a product of multiplicative sets may
# not be unique: Consider the ring ℤ[x] and the multiplicative sets
# T = {powers of 5x}
# T' = {powers of x}
# S = {constant polynomials outside 7ℤ }.
# Then
# T⋅S = { a⋅xᵏ : a ∉ 7ℤ, k ∈ ℕ₀ } = T'⋅S.
#
# Upshot: Whenever a product is taken, some interreduced form of the
# entire product is returned. Besides the obvious simplification in
# case all factors are contained in a single one, it is difficult to
# determine which interreduction is the best one.
*(T::AbsMPolyMultSet, U::AbsMPolyMultSet) = product(T, U)
@doc raw"""
product(T::AbsMPolyMultSet, U::AbsMPolyMultSet)
Return the product of the multiplicative subsets `T` and `U`.
Alternatively, write `T*U`.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> T = complement_of_point_ideal(R, [0, 0 ,0])
complement of maximal ideal corresponding to point with coordinates QQFieldElem[0, 0, 0]
julia> f = x
x
julia> U = powers_of_element(f)
powers of QQMPolyRingElem[x]
julia> S = product(T, U)
product of the multiplicative sets [complement of maximal ideal corresponding to point with coordinates QQFieldElem[0, 0, 0], powers of QQMPolyRingElem[x]]
```
"""
function product(T::AbsMPolyMultSet, U::AbsMPolyMultSet)
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
issubset(T, U) && return U
issubset(U, T) && return T
return MPolyProductOfMultSets(R, [T, U])
end
function product(T::MST, U::MST) where {MST<:MPolyProductOfMultSets}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
new_sets = Vector()
for S in sets(T)
push!(new_sets, S)
for V in sets(U)
if issubset(S, V)
pop!(new_sets)
break
end
end
end
n = length(new_sets)
for V in sets(U)
push!(new_sets, V)
for U in new_sets[1:n]
if issubset(V, U)
pop!(new_sets)
break
end
end
end
return MPolyProductOfMultSets(R, [x for x in new_sets])
end
function product(T::MPolyProductOfMultSets{BRT, BRET, RT, RET}, U::MST) where {BRT, BRET, RT, RET, MST<:AbsMPolyMultSet{BRT, BRET, RT, RET}}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
for V in sets(T)
issubset(U, T) && return T
end
new_sets = U
for V in sets(T)
issubset(V, U) || push!(new_sets, V)
end
return MPolyProductOfMultSets(R, new_sets)
end
product(U::MST, T::MPolyProductOfMultSets{BRT, BRET, RT, RET}) where {BRT, BRET, RT, RET, MST<:AbsMPolyMultSet{BRT, BRET, RT, RET}} = product(T, U)
function product(T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET}, U::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET}) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
P = prime_ideal(T)
for f in gens(P)
if iszero(evaluate(f, point_coordinates(U)))
return MPolyProductOfMultSets(R, [U, T])
end
end
return U
end
function product(
U::MPolyComplementOfKPointIdeal{BRT, BRET, RT, RET},
T::MPolyComplementOfPrimeIdeal{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
return product(T, U)
end
function product(T::MST, U::MST) where {MST<:MPolyComplementOfKPointIdeal}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
a = point_coordinates(U)
b = point_coordinates(T)
for i in 1:length(a)
a[i] == b[i] || return MPolyProductOfMultSets(R, [U, T])
end
return T
end
function product(T::MST, U::MST) where {MST<:MPolyComplementOfPrimeIdeal}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
if issubset(prime_ideal(T), prime_ideal(U))
return T
end
if issubset(prime_ideal(U), prime_ideal(T))
return U
end
return MPolyProductOfMultSets(R, [U, T])
end
function product(T::MST, U::MST) where {MST<:MPolyPowersOfElement}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
new_denoms = Vector{elem_type(R)}()
for f in denominators(T)
for g in denominators(U)
(_, f) = ppio(f, g)
end
if !(divides(one(parent(f)), f)[1])
push!(new_denoms, f)
end
end
n = length(new_denoms)
for g in denominators(U)
for f in new_denoms[1:n]
(_, g) = ppio(g, f)
end
if !(divides(one(parent(g)), g)[1])
push!(new_denoms, g)
end
end
return (length(new_denoms) == 0 ? units_of(R) : MPolyPowersOfElement(R, new_denoms))
end
function product(
U::AbsMPolyMultSet{BRT, BRET, RT, RET},
T::MPolyPowersOfElement{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
for a in denominators(T)
a in U || return MPolyProductOfMultSets(R, [U, T])
end
return U
end
function product(
T::MPolyPowersOfElement{BRT, BRET, RT, RET},
U::AbsMPolyMultSet{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
for a in denominators(T)
a in U || return MPolyProductOfMultSets(R, [U, T])
end
return U
end
function product(
T::MPolyPowersOfElement{BRT, BRET, RT, RET},
U::MPolyProductOfMultSets{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
R = ambient_ring(T)
R == ambient_ring(U) || error("multiplicative sets do not belong to the same ring")
keep_denom = Vector{RET}()
for a in denominators(T)
a in U || (push!(keep_denom, a))
end
length(keep_denom) == 0 && return U
return MPolyProductOfMultSets(vcat(sets(U), MPolyPowersOfElement(keep_denom)))
end
function product(
U::MPolyProductOfMultSets{BRT, BRET, RT, RET},
T::MPolyPowersOfElement{BRT, BRET, RT, RET}
) where {BRT, BRET, RT, RET}
return T*U
end
### Preimages of multiplicative sets.
# In general for a ring homomorphism f : R → S and a multiplicative
# set U ⊂ S the preimage V = f⁻¹(U) is a multiplicative set in R.
# Membership in V can easily be tested, but introducing a new type
# for preimages makes it necessary to extend all dispatch routines.
# It is not clear what is the best strategy for all this.
function preimage(f::Oscar.AffAlgHom, U::MST) where {MST<:AbsMPolyMultSet}
error("not implemented")
end
### Transfer of multiplicative sets along ring homomorphisms
function (phi::MPolyAnyMap{<:MPolyRing, <:MPolyRing, Nothing})(U::MPolyPowersOfElement;
check::Bool=true
)
ambient_ring(U) === domain(phi) || error("multiplicative set does not lay in the domain of the morphism")
S = codomain(phi)
SU = MPolyPowersOfElement(S, phi.(denominators(U)))
return SU
end
function (phi::MPolyAnyMap{<:MPolyRing, <:MPolyRing, Nothing})(U::MPolyComplementOfPrimeIdeal;
check::Bool=true
)
ambient_ring(U) === domain(phi) || error("multiplicative set does not lay in the domain of the morphism")
S = codomain(phi)
Q = ideal(S, phi.(gens(prime_ideal(U))))
SU = MPolyComplementOfPrimeIdeal(S, Q, check=check)
return SU
end
########################################################################
# Localizations of polynomial rings over admissible fields #
########################################################################
@doc raw"""
MPolyLocRing{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType,
MultSetType
} <: AbsLocalizedRing{
RingType,
RingType,
MultSetType
}
The localization of a multivariate polynomial ring ``R = 𝕜[x₁,…,xₙ]`` over a
base field ``𝕜`` of type `BaseRingType` and with elements of type `RingElemType`
at a multiplicative set ``S ⊂ R`` of type `MultSetType`.
"""
@attributes mutable struct MPolyLocRing{
BaseRingType,
BaseRingElemType,
RingType,
RingElemType,
MultSetType <: AbsMPolyMultSet{BaseRingType, BaseRingElemType, RingType, RingElemType}
} <: AbsLocalizedRing{
RingType,
RingType,
MultSetType
}
R::RingType # The parent ring which is being localized
S::MultSetType # The multiplicatively closed set that has been inverted
function MPolyLocRing(
R::RingType,
S::MultSetType
) where {RingType<:MPolyRing, MultSetType<:AbsMPolyMultSet}
# TODO: Add some sanity checks here?
ambient_ring(S) == R || error("the multiplicative set is not contained in the given ring")
k = coefficient_ring(R)
R_loc = new{typeof(k), elem_type(k), RingType, elem_type(R), MultSetType}(R, S)
return R_loc
end
end
### required getter functions
base_ring(W::MPolyLocRing) = W.R
inverted_set(W::MPolyLocRing) = W.S
### additional getter functions
gens(W::MPolyLocRing) = W.(gens(base_ring(W)))
ngens(W::MPolyLocRing) = ngens(base_ring(W))
### required extension of the localization function
@doc raw"""
localization(R::MPolyRing, U::AbsMPolyMultSet)
Return the localization of `R` at `U`, together with the localization map.
# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
julia> P = ideal(R, [x])
ideal(x)
julia> U = complement_of_prime_ideal(P)
complement of ideal(x)
julia> Rloc, iota = localization(R, U);
julia> Rloc
localization of Multivariate polynomial ring in 3 variables over QQ at the complement of ideal(x)
julia> iota
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
localization of Multivariate polynomial ring in 3 variables over QQ at the complement of ideal(x)
```
""" localization(R::MPolyRing, U::AbsMPolyMultSet)
###localization is an Abstract Algebra alias for Localization
function Localization(S::AbsMPolyMultSet)
R = ambient_ring(S)
Rloc = MPolyLocRing(R, S)
#iota = MapFromFunc(x -> Rloc(x), R, Rloc)
iota = hom(R, Rloc, Rloc.(gens(R)))
return Rloc, iota
end
function Localization(R::MPolyRing, ord::MonomialOrdering)
@assert R === ord.R
return Localization(MPolyLeadingMonOne(ord))
end