forked from oscar-system/Oscar.jl
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRings.jl
825 lines (701 loc) · 25.8 KB
/
Rings.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
################################################################################
# Common union types
const RingMatElemUnion = Union{RingElem, MatElem, FreeAssociativeAlgebraElem,
SMat, TropicalSemiringElem}
const RingMatSpaceUnion = Union{Ring, MatSpace, SMatSpace,
FreeAssociativeAlgebra, TropicalSemiring}
const ModRingUnion = Union{zzModRing, ZZModRing}
const ModRingElemUnion = Union{zzModRingElem, ZZModRingElem}
const PolyRingUnionType = Union{UniversalPolyRing,
MPolyRing,
PolyRing,
AbstractAlgebra.Generic.LaurentMPolyWrapRing}
const IdealUnionType = Union{MPolyIdeal,
MPolyQuoIdeal,
MPolyLocalizedIdeal,
MPolyQuoLocalizedIdeal,
LaurentMPolyIdeal,
FreeAssociativeAlgebraIdeal,
IdealGens
}
const RelPowerSeriesUnionType = Union{Generic.RelPowerSeriesRing,
QQRelPowerSeriesRing,
ZZRelPowerSeriesRing,
fqPolyRepRelPowerSeriesRing,
FqRelPowerSeriesRing,
zzModRelPowerSeriesRing}
const AbsPowerSeriesUnionType = Union{Generic.AbsPowerSeriesRing,
QQAbsPowerSeriesRing,
ZZAbsPowerSeriesRing,
FqAbsPowerSeriesRing,
fqPolyRepAbsPowerSeriesRing,
zzModAbsPowerSeriesRing}
const LaurentUnionType = Union{Generic.LaurentSeriesRing,
Generic.LaurentSeriesField,
ZZLaurentSeriesRing}
################################################################################
# type_params functions
type_params(x::T) where T <: RingMatElemUnion = TypeParams(T, parent(x))
type_params(R::T) where T <: RingMatSpaceUnion = TypeParams(T, base_ring(R))
type_params(x::T) where T <: IdealUnionType = TypeParams(T, base_ring(x))
# exclude from ring union
type_params(::ZZRing) = TypeParams(ZZRing, nothing)
type_params(::ZZRingElem) = TypeParams(ZZRingElem, nothing)
type_params(R::T) where T <: ModRingUnion = TypeParams(T, nothing)
################################################################################
# ring of integers (singleton type)
@register_serialization_type ZZRing
################################################################################
# Mod Rings
@register_serialization_type Nemo.zzModRing
@register_serialization_type Nemo.ZZModRing
function save_object(s::SerializerState, R::T) where T <: ModRingUnion
save_object(s, modulus(R))
end
function load_object(s::DeserializerState, ::Type{zzModRing})
modulus = load_object(s, UInt64)
return zzModRing(modulus)
end
function load_object(s::DeserializerState, ::Type{ZZModRing})
modulus = load_object(s, ZZRingElem)
return ZZModRing(modulus)
end
#elements
@register_serialization_type zzModRingElem
@register_serialization_type ZZModRingElem
function save_object(s::SerializerState, x::ModRingElemUnion)
save_data_basic(s, string(x))
end
function load_object(s::DeserializerState, ::Type{<:ModRingElemUnion},
parent_ring::T) where T <: ModRingUnion
return parent_ring(load_object(s, ZZRingElem, ZZRing()))
end
################################################################################
# Polynomial Rings
@register_serialization_type PolyRing uses_id
@register_serialization_type MPolyRing uses_id
@register_serialization_type UniversalPolyRing uses_id
@register_serialization_type MPolyDecRing uses_id
@register_serialization_type AbstractAlgebra.Generic.LaurentMPolyWrapRing uses_id
function save_object(s::SerializerState, R::PolyRingUnionType)
base = base_ring(R)
save_data_dict(s) do
save_object(s, symbols(R), :symbols)
end
end
function load_object(s::DeserializerState,
T::Type{<: PolyRingUnionType},
params::Ring)
symbols = load_object(s, Vector{Symbol}, :symbols)
if T <: PolyRing
return polynomial_ring(params, symbols..., cached=false)[1]
elseif T <: UniversalPolyRing
poly_ring = universal_polynomial_ring(params, cached=false)
gens(poly_ring, symbols)
return poly_ring
elseif T <: AbstractAlgebra.Generic.LaurentMPolyWrapRing
return laurent_polynomial_ring(params, symbols, cached=false)[1]
end
return polynomial_ring(params, symbols, cached=false)[1]
end
# with grading
type_params(R::MPolyDecRing) = TypeParams(
MPolyDecRing,
:grading_group => grading_group(R),
:ring => forget_grading(R),
)
function save_object(s::SerializerState, R::MPolyDecRing)
save_object(s, _grading(R))
end
function load_object(s::DeserializerState, ::Type{<:MPolyDecRing}, d::Dict)
ring = d[:ring]
grading = load_object(s, Vector{elem_type(d[:grading_group])}, d[:grading_group])
return grade(ring, grading)[1]
end
################################################################################
# Polynomial Ring Elem Types
@register_serialization_type MPolyRingElem
@register_serialization_type MPolyDecRingElem
@register_serialization_type UniversalPolyRingElem
@register_serialization_type AbstractAlgebra.Generic.LaurentMPolyWrap
# elements
function save_object(s::SerializerState, p::Union{UniversalPolyRingElem, MPolyRingElem})
# we use this line instead of typeof(coeff(p, 1)) to catch the 0 polynomial
coeff_type = elem_type(base_ring(parent(p)))
save_data_array(s) do
for i in 1:length(p)
save_data_array(s) do
save_object(s, map(string, exponent_vector(p, i)))
save_object(s, coeff(p, i))
end
end
end
end
function save_object(s::SerializerState, p::AbstractAlgebra.Generic.LaurentMPolyWrap)
exponent_vectors_gen = AbstractAlgebra.exponent_vectors(p)
index = 0
save_data_array(s) do
for c in coefficients(p)
exponent_vector, index = iterate(exponent_vectors_gen, index)
save_data_array(s) do
save_object(s, map(string, exponent_vector))
save_object(s, c)
end
end
end
end
################################################################################
# Univariate Polynomials
@register_serialization_type PolyRingElem
function save_object(s::SerializerState, p::PolyRingElem)
coeffs = coefficients(p)
exponent = 0
save_data_array(s) do
for coeff in coeffs
# collect only non trivial terms
if is_zero(coeff)
exponent += 1
continue
end
save_data_array(s) do
save_object(s, string(exponent))
save_object(s, coeff)
end
exponent += 1
end
end
end
function load_object(s::DeserializerState, ::Type{<: PolyRingElem},
parent_ring::PolyRing)
load_node(s) do terms
if isempty(terms)
return parent_ring(0)
end
# load exponents and account for shift
exponents = []
for i in 1:length(terms)
e = load_node(s, i) do _
load_object(s, Int, 1) + 1
end
push!(exponents, e)
end
degree = max(exponents...)
base = base_ring(parent_ring)
loaded_terms = zeros(base, degree)
coeff_type = elem_type(base)
for (i, exponent) in enumerate(exponents)
load_node(s, i) do _
load_node(s, 2) do _
loaded_terms[exponent] = load_object(s, coeff_type, base)
end
end
end
return parent_ring(loaded_terms)
end
end
function load_object(s::DeserializerState,
::Type{<:Union{MPolyRingElem, UniversalPolyRingElem, AbstractAlgebra.Generic.LaurentMPolyWrap}},
parent_ring::PolyRingUnionType)
load_node(s) do terms
exponents = [term[1] for term in terms]
base = base_ring(parent_ring)
polynomial = MPolyBuildCtx(parent_ring)
coeff_type = elem_type(base)
for (i, e) in enumerate(exponents)
load_node(s, i) do _
c = load_object(s, coeff_type, base, 2)
e_int = load_array_node(s, 1) do _
load_object(s, Int)
end
push_term!(polynomial, c, e_int)
end
end
return finish(polynomial)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyDecRingElem}, parent_ring::MPolyDecRingElem)
poly = load_object(s, MPolyRingElem, forget_grading(parent_ring))
return parent_ring(poly)
end
################################################################################
# Polynomial Ideals
@register_serialization_type MPolyIdeal
@register_serialization_type LaurentMPolyIdeal
@register_serialization_type MPolyLocalizedIdeal
@register_serialization_type MPolyQuoLocalizedIdeal
@register_serialization_type MPolyQuoIdeal
function save_object(s::SerializerState, I::T) where T <: IdealUnionType
# we might want to serialize generating_system(I) and I.gb
# in the future
save_object(s, gens(I))
end
function load_object(s::DeserializerState, ::Type{<: IdealUnionType}, parent_ring::RingMatSpaceUnion)
gens = elem_type(parent_ring)[]
load_array_node(s) do _
push!(gens, load_object(s, elem_type(parent_ring), parent_ring))
end
return ideal(parent_ring, gens)
end
################################################################################
# IdealGens
# this will need adjustments to cover the NCRing case
@register_serialization_type IdealGens
type_params(ig::IdealGens) = TypeParams(
IdealGens,
:base_ring => base_ring(ig),
:ordering_type => TypeParams(typeof(ordering(ig)), nothing)
)
function save_object(s::SerializerState, obj::IdealGens)
save_data_dict(s) do
save_object(s, ordering(obj), :ordering)
save_object(s, gens(obj), :gens)
save_object(s, is_groebner_basis(obj), :is_gb)
save_object(s, obj.isReduced, :is_reduced)
save_object(s, obj.keep_ordering, :keep_ordering)
end
end
function load_object(s::DeserializerState, ::Type{<:IdealGens}, params::Dict)
base_ring = params[:base_ring]
ordering_type = params[:ordering_type]
if ordering_type <: MonomialOrdering
ord = load_object(s, ordering_type, base_ring, :ordering)
else
ord = load_node(s, :ordering) do _
MonomialOrdering(base_ring, load_object(s, ordering_type, :internal_ordering))
end
end
generators = load_object(s, Vector{elem_type(base_ring)}, base_ring, :gens)
is_gb = load_object(s, Bool, :is_gb)
is_reduced = load_object(s, Bool, :is_reduced)
keep_ordering = load_object(s, Bool, :keep_ordering)
return IdealGens(base_ring, generators, ord;
keep_ordering=keep_ordering,
isReduced=is_reduced,
isGB=is_gb)
end
################################################################################
# Matrices
@register_serialization_type MatSpace uses_id
@register_serialization_type MatElem
@register_serialization_type SMatSpace uses_id
@register_serialization_type SMat
function save_object(s::SerializerState, obj::MatSpace{T}) where T
save_data_dict(s) do
save_object(s, ncols(obj), :ncols)
save_object(s, nrows(obj), :nrows)
end
end
function save_object(s::SerializerState, obj::SMatSpace)
save_data_dict(s) do
# getters currently do not seem to exist
save_object(s, obj.cols, :ncols)
save_object(s, obj.rows, :nrows)
end
end
function load_object(s::DeserializerState, ::Type{MatSpace}, base_ring::Ring)
ncols = load_object(s, Int, :ncols)
nrows = load_object(s, Int, :nrows)
return matrix_space(base_ring, nrows, ncols)
end
function load_object(s::DeserializerState, ::Type{SMatSpace}, base_ring::Ring)
ncols = load_object(s, Int, :ncols)
nrows = load_object(s, Int, :nrows)
return SMatSpace(base_ring, nrows, ncols)
end
# elems
function save_object(s::SerializerState, obj::MatElem)
save_object(s, Array(obj))
end
function save_object(s::SerializerState, obj::SMat)
save_data_array(s) do
for r in obj
save_object(s, collect(r))
end
end
end
function load_object(s::DeserializerState, ::Type{<:MatElem}, parent::MatSpace{T}) where T
m = load_object(s, Matrix{T}, base_ring(parent))
if isempty(m)
return parent()
end
return parent(m)
end
function load_object(s::DeserializerState, ::Type{<:SMat}, parent::SMatSpace{T}) where T
base = base_ring(parent)
M = sparse_matrix(base)
load_array_node(s) do _
row_entries = Tuple{Int, T}[]
load_array_node(s) do _
push!(row_entries, load_object(s, Tuple{Int, T}, (nothing, base)))
end
push!(M, sparse_row(base, row_entries))
end
return M
end
################################################################################
# Power Series
@register_serialization_type SeriesRing uses_id
function save_object(s::SerializerState, R::RelPowerSeriesUnionType)
save_data_dict(s) do
save_object(s, var(R), :var)
save_object(s, max_precision(R), :max_precision)
save_object(s, :capped_relative, :model)
end
end
function save_object(s::SerializerState, R::AbsPowerSeriesUnionType)
save_data_dict(s) do
save_object(s, var(R), :var)
save_object(s, max_precision(R), :max_precision)
save_object(s, :capped_absolute, :model)
end
end
function load_object(s::DeserializerState, ::Type{<: SeriesRing}, base_ring::Ring)
var = load_object(s, Symbol, :var)
max_precision = load_object(s, Int, :max_precision)
model = load_object(s, Symbol, :model)
return power_series_ring(base_ring, max_precision, var; cached=false, model=model)[1]
end
# elements
@register_serialization_type RelPowerSeriesRingElem
@register_serialization_type AbsPowerSeriesRingElem
function save_object(s::SerializerState, r::RelPowerSeriesRingElem)
v = valuation(r)
pl = pol_length(r)
encoded_terms = []
save_data_dict(s) do
save_data_array(s, :terms) do
for exponent in v: v + pl
coefficient = coeff(r, exponent)
#collect only non trivial values
if is_zero(coefficient)
continue
end
save_data_array(s) do
save_object(s, exponent)
save_object(s, coefficient)
end
end
end
save_object(s, pl, :pol_length)
save_object(s, precision(r), :precision)
save_object(s, v, :valuation)
end
end
function save_object(s::SerializerState, r::AbsPowerSeriesRingElem)
pl = pol_length(r)
encoded_terms = []
parents = []
parent_ring = parent(r)
save_data_dict(s) do
save_data_array(s, :terms) do
for exponent in 0:pl
coefficient = coeff(r, exponent)
#collect only non trivial values
if is_zero(coefficient)
continue
end
save_data_array(s) do
save_object(s, exponent)
save_object(s, coefficient)
end
end
end
save_object(s, pl, :pol_length)
save_object(s, precision(r),:precision)
end
end
function load_object(s::DeserializerState, ::Type{<:RelPowerSeriesRingElem},
parent_ring::RelPowerSeriesUnionType)
valuation = load_object(s, Int, :valuation)
pol_length = load_object(s, Int, :pol_length)
precision = load_object(s, Int, :precision)
base = base_ring(parent_ring)
loaded_terms = zeros(base, pol_length)
coeff_type = elem_type(base)
load_node(s, :terms) do _
load_array_node(s) do _
e = load_object(s, Int, 1)
loaded_terms[e] = load_object(s, coeff_type, base, 2)
end
end
return parent_ring(loaded_terms, pol_length, precision, valuation)
end
function load_object(s::DeserializerState, ::Type{<:AbsPowerSeriesRingElem},
parent_ring::AbsPowerSeriesUnionType)
pol_length = load_object(s, Int, :pol_length)
precision = load_object(s, Int, :precision)
base = base_ring(parent_ring)
loaded_terms = zeros(base, pol_length)
coeff_type = elem_type(base)
load_node(s, :terms) do _
load_array_node(s) do _
e = load_object(s, Int, 1)
loaded_terms[e + 1] = load_object(s, coeff_type, base, 2)
end
end
return parent_ring(loaded_terms, pol_length, precision)
end
################################################################################
# Laurent Series
@register_serialization_type Generic.LaurentSeriesRing "LaurentSeriesRing" uses_id
@register_serialization_type Generic.LaurentSeriesField "LaurentSeriesField" uses_id
@register_serialization_type ZZLaurentSeriesRing uses_id
function save_object(s::SerializerState, R::LaurentUnionType)
save_data_dict(s) do
save_object(s, var(R), :var)
save_object(s, max_precision(R), :max_precision)
end
end
function load_object(s::DeserializerState, ::Type{<: LaurentUnionType}, base_ring::Ring)
var = load_object(s, Symbol, :var)
max_precision = load_object(s, Int, :max_precision)
return laurent_series_ring(base_ring, max_precision, var; cached=false)[1]
end
# elements
@register_serialization_type Generic.LaurentSeriesFieldElem "LaurentSeriesFieldElem"
@register_serialization_type Generic.LaurentSeriesRingElem "LaurentSeriesRingElem"
@register_serialization_type ZZLaurentSeriesRingElem
function save_object(s::SerializerState, r:: Union{Generic.LaurentSeriesElem, ZZLaurentSeriesRingElem})
v = valuation(r)
pl = pol_length(r)
encoded_terms = []
save_data_dict(s) do
save_data_array(s, :terms) do
for exponent in v: v + pl
coefficient = coeff(r, exponent)
#collect only non trivial values
if is_zero(coefficient)
continue
end
save_data_array(s) do
save_object(s, exponent)
save_object(s, coefficient)
end
end
end
save_object(s, pl, :pol_length)
save_object(s, precision(r), :precision)
save_object(s, v, :valuation)
save_object(s, Generic.scale(r), :scale)
end
end
function load_object(s::DeserializerState,
::Type{<: Union{Generic.LaurentSeriesElem, ZZLaurentSeriesRingElem}},
parent_ring::LaurentUnionType)
terms = load_node(s, :terms) do terms_data
# reading all exponents before ...
# might be more efficient way ...
exponents = Int[]
for i in 1:length(terms_data)
load_node(s, i) do _
push!(exponents, load_object(s, Int, 1))
end
end
highest_degree = max(exponents...)
lowest_degree = min(exponents...)
base = base_ring(parent_ring)
coeff_type = elem_type(base)
# account for index shift
loaded_terms = zeros(base, highest_degree - lowest_degree + 1)
for (i, e) in enumerate(exponents)
e -= lowest_degree - 1
load_node(s, i) do _
loaded_terms[e] = load_object(s, coeff_type, base, 2)
end
end
return loaded_terms
end
valuation = load_object(s, Int, :valuation)
pol_length = load_object(s, Int, :pol_length)
precision = load_object(s, Int, :precision)
scale = load_object(s, Int, :scale)
return parent_ring(terms, pol_length, precision, valuation, scale)
end
### Affine algebras
@register_serialization_type MPolyQuoRing uses_id
type_params(A::MPolyQuoRing) = TypeParams(
MPolyQuoRing,
:base_ring => base_ring(A),
:ordering => typeof(ordering(A))
)
function save_object(s::SerializerState, A::MPolyQuoRing)
save_data_dict(s) do # Saves stuff in a JSON dictionary. This opens a `{`, puts stuff
# inside there for the various keys and then closes it with `}`.
# It's not using Julia Dicts.
save_object(s, modulus(A), :modulus)
save_object(s, ordering(A), :ordering)
end
end
function load_object(s::DeserializerState, ::Type{MPolyQuoRing}, params::Dict)
R = params[:base_ring]
ordering_type = params[:ordering]
o = load_object(s, ordering_type, R, :ordering)
I = load_object(s, ideal_type(R), R, :modulus)
return MPolyQuoRing(R, I, o)
end
@register_serialization_type MPolyQuoRingElem
function save_object(s::SerializerState, a::MPolyQuoRingElem)
save_object(s, lift(a))
end
function load_object(s::DeserializerState, ::Type{<:MPolyQuoRingElem}, Q::MPolyQuoRing)
R = base_ring(Q)
rep = load_object(s, elem_type(R), R)
return Q(rep)
end
### Serialization of Monomial orderings
@register_serialization_type MonomialOrdering
function save_object(s::SerializerState, o::MonomialOrdering)
save_data_dict(s) do
save_object(s, o.o, :internal_ordering) # TODO: Is there a getter for this?
if isdefined(o, :is_total)
save_object(s, o.is_total, :is_total)
end
end
end
function load_object(s::DeserializerState, ::Type{<:MonomialOrdering}, ring::MPolyRing)
# this will need to be changed to include other orderings, see below
ord = load_object(s, Orderings.SymbOrdering, :internal_ordering)
result = MonomialOrdering(ring, ord)
if haskey(s, :is_total)
result.is_total = load_object(s, Bool, :is_total)
end
return result
end
# we will need to extend this to more orderings at some point
@register_serialization_type Orderings.SymbOrdering
function save_object(s::SerializerState, o::Orderings.SymbOrdering{S}) where {S}
save_data_dict(s) do
save_object(s, S, :ordering_symbol_as_type)
save_object(s, o.vars, :vars) # TODO: Is there a getter?
end
end
function load_object(s::DeserializerState, ::Type{Orderings.SymbOrdering})
S = load_object(s, Symbol, :ordering_symbol_as_type)
vars = load_object(s, Vector{Int}, :vars) # are these always Vector{Int} ?
return Orderings.SymbOrdering(S, vars)
end
# localizations of polynomial rings
@register_serialization_type MPolyPowersOfElement uses_id
type_params(U::MPolyPowersOfElement) = typeof(U), Dict(:ring => (typeof(ring(U)), ring(U)))
function save_object(s::SerializerState, U::MPolyPowersOfElement)
save_data_dict(s) do
save_object(s, denominators(U), :dens)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyPowersOfElement}, params::Dict)
R = params[:ring]
dens = Vector{elem_type(R)}(load_object(s, Vector{elem_type(R)}, R, :dens)) # casting is necessary for empty arrays
return MPolyPowersOfElement(R, dens)
end
@register_serialization_type MPolyComplementOfPrimeIdeal uses_id
type_params(U::MPolyComplementOfPrimeIdeal) = typeof(U), Dict(:ring => (typeof(ring(U)), ring(U)))
function save_object(s::SerializerState, U::MPolyComplementOfPrimeIdeal)
save_data_dict(s) do
save_object(s, prime_ideal(U), :ideal)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyComplementOfPrimeIdeal}, params::Dict)
R = params[:ring]
id = load_object(s, ideal_type(R), R, :ideal)
return MPolyComplementOfPrimeIdeal(id)
end
#=
@register_serialization_type MPolyComplementOfKPointIdeal uses_id
function save_object(s::SerializerState, U::MPolyComplementOfKPointIdeal)
save_data_dict(s) do
save_typed_object(s, ring(U), :ring)
save_typed_object(s, point_coordinates(U), :pt_coords)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyComplementOfKPointIdeal})
R = load_typed_object(s, :ring)
a = load_typed_object(s, :pt_coords)
return MPolyComplementOfKPointIdeal(R, a)
end
@register_serialization_type MPolyLocRing uses_id
function save_object(s::SerializerState, L::MPolyLocRing)
save_data_dict(s) do
save_typed_object(s, base_ring(L), :ring)
save_typed_object(s, inverted_set(L), :inv_set)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyLocRing})
R = load_typed_object(s, :ring)
U = load_typed_object(s, :inv_set)
return MPolyLocRing(R, U)
end
@register_serialization_type MPolyLocRingElem uses_params
function save_object(s::SerializerState, a::MPolyLocRingElem)
# Because the `parent` of `a` is a `Ring` the generic implementation
# for `uses_params` above calls `save_type_params` and that stores
# the ring. Hopefully.
save_data_array(s) do
save_object(s, numerator(a))
save_object(s, denominator(a))
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyLocRingElem}, prts::Vector)
L = prts[end]::MPolyLocRing
P = base_ring(L)
RET = elem_type(P)
num = load_object(s, RET, P, 1)
den = load_object(s, RET, P, 2)
return L(num, den; check=false)
end
@register_serialization_type MPolyQuoLocRing uses_id
function save_object(s::SerializerState, L::MPolyQuoLocRing)
save_data_dict(s) do
save_typed_object(s, underlying_quotient(L), :quo_ring)
save_typed_object(s, inverted_set(L), :inv_set)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyQuoLocRing})
Q = load_typed_object(s, :quo_ring)
U = load_typed_object(s, :inv_set)
return MPolyQuoLocRing(base_ring(Q), modulus(Q), U)
end
@register_serialization_type MPolyQuoLocRingElem uses_params
function save_object(s::SerializerState, a::MPolyQuoLocRingElem)
save_data_array(s) do
save_object(s, lifted_numerator(a))
save_object(s, lifted_denominator(a))
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyQuoLocRingElem}, prts::Vector)
L = prts[end]::MPolyQuoLocRing
P = base_ring(L)
RET = elem_type(P)
num = load_object(s, RET, P, 1)
den = load_object(s, RET, P, 2)
return L(num, den; check=false)
end
### Morphisms of the four types of rings
@register_serialization_type MPolyLocalizedRingHom uses_id
function save_object(s::SerializerState, phi::MPolyLocalizedRingHom)
save_data_dict(s) do
save_typed_object(s, domain(phi), :domain)
save_typed_object(s, codomain(phi), :codomain)
save_typed_object(s, restricted_map(phi), :res_map)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyLocalizedRingHom})
dom = load_typed_object(s, :domain)
cod = load_typed_object(s, :codomain)
res = load_typed_object(s, :res_map)
return MPolyLocalizedRingHom(dom, cod, res; check=false)
end
@register_serialization_type MPolyQuoLocalizedRingHom uses_id
function save_object(s::SerializerState, phi::MPolyQuoLocalizedRingHom)
save_data_dict(s) do
save_typed_object(s, domain(phi), :domain)
save_typed_object(s, codomain(phi), :codomain)
save_typed_object(s, restricted_map(phi), :res_map)
end
end
function load_object(s::DeserializerState, ::Type{<:MPolyQuoLocalizedRingHom})
dom = load_typed_object(s, :domain)
cod = load_typed_object(s, :codomain)
res = load_typed_object(s, :res_map)
return MPolyQuoLocalizedRingHom(dom, cod, res; check=false)
end
=#