-
Notifications
You must be signed in to change notification settings - Fork 59
/
HeckeTypes.jl
2298 lines (1936 loc) · 64 KB
/
HeckeTypes.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
################################################################################
#
# Abstract types for number fields
#
################################################################################
"""
NonSimpleNumField{T}
Common, abstract, overtype for all number fields that are (by type) generated
by more than one generator. `T` is the type of the elements of the coefficient field.
Typical example is a bi-quadratic field:
QQ[sqrt 2, sqrt 3]
It can be converted to a simple extension (with maps), see e.g.
`absolute_simple_field` or `simple_extension`.
"""
abstract type NonSimpleNumField{T} <: NumField{T} end
"""
NonSimpleNumFieldElem{T}
Common, abstract, overtype for elements of non-simple number fields, see
`NonSimpleNumField`
"""
abstract type NonSimpleNumFieldElem{T} <: NumFieldElem{T} end
################################################################################
#
# Abstract types for orders
#
################################################################################
"""
NumFieldOrder
Abstract overtype for all orders in number fields. An order is a unitary
subring that has the same ZZ-dimension as the QQ-dimension of the field.
"""
abstract type NumFieldOrder <: Ring end
abstract type NumFieldOrderElem <: RingElem end
################################################################################
#
# Abstract types for ideals
#
################################################################################
"""
NumFieldOrderIdeal
Common, abstract, type for all integral ideals in orders. See also
`NumFieldOrder`.
"""
abstract type NumFieldOrderIdeal end
"""
NumFieldOrderFractionalIdeal
Common, abstract, type for all fractional ideals in orders, fractional
ideals are, as a set, just an integral ideal divided by some integer. See also
`NumFieldOrder`.
"""
abstract type NumFieldOrderFractionalIdeal end
################################################################################
#
# Transformations for matrices
#
################################################################################
# 1 = scale
# 2 = swap
# 3 = add scaled
# 4 = parallel scaled addition
# 5 = trafo partial dense
# 6 = move row to other row (everything moves up)
# 7 = trafo id
mutable struct SparseTrafoElem{T, S}
type::Int
i::Int
j::Int
a::T
b::T
c::T
d::T
rows::UnitRange{Int}
cols::UnitRange{Int}
U::S
function SparseTrafoElem{T, S}() where {T, S}
z = new{T, S}()
return z
end
end
abstract type Trafo end
mutable struct TrafoScale{T} <: Trafo
i::Int
c::T
function TrafoScale{T}(i::Int, c::T) where {T}
return new{T}(i, c)
end
end
mutable struct TrafoSwap{T} <: Trafo
i::Int
j::Int
function TrafoSwap{T}(i, j) where {T}
return new{T}(i, j)
end
end
# j -> j + s*i
mutable struct TrafoAddScaled{T} <: Trafo
i::Int
j::Int
s::T
function TrafoAddScaled{T}(i::Int, j::Int, s::T) where {T}
return new{T}(i, j, s)
end
end
TrafoAddScaled(i::Int, j::Int, s::T) where {T} = TrafoAddScaled{T}(i, j, s)
# if from left, then
# row i -> a*row i + b * row j
# row j -> c*row i + d * row j
mutable struct TrafoParaAddScaled{T} <: Trafo
i::Int
j::Int
a::T
b::T
c::T
d::T
function TrafoParaAddScaled{T}(i::Int, j::Int, a::T, b::T, c::T, d::T) where {T}
return new{T}(i, j, a, b, c, d)
end
end
TrafoParaAddScaled(i::Int, j::Int, a::T, b::T, c::T, d::T) where {T} =
TrafoParaAddScaled{T}(i, j, a, b, c, d)
mutable struct TrafoId{T} <: Trafo
end
mutable struct TrafoPartialDense{S} <: Trafo
i::Int
rows::UnitRange{Int}
cols::UnitRange{Int}
U::S
end
function TrafoPartialDense(i::Int, rows::AbstractUnitRange{Int},
cols::AbstractUnitRange{Int}, U::S) where S
return TrafoPartialDense{S}(i, UnitRange(rows), UnitRange(cols), U)
end
# this is shorthand for the permutation matrix corresponding to
# (i i+1)(i+1 i+2)...(rows-1 rows)
mutable struct TrafoDeleteZero{T} <: Trafo
i::Int
end
################################################################################
#
# Wrapper for fmpz_preinvn_struct
#
################################################################################
mutable struct fmpz_preinvn_struct
dinv::Ptr{UInt}
n::Int
norm::Int
function fmpz_preinvn_struct(f::ZZRingElem)
z = new()
ccall((:fmpz_preinvn_init, libflint), Nothing,
(Ref{fmpz_preinvn_struct}, Ref{ZZRingElem}), z, f)
finalizer(_fmpz_preinvn_struct_clear_fn, z)
return z
end
end
################################################################################
#
# Root context for fmpq_polys and roots modelled as acbs
#
################################################################################
struct acb_roots
p::Int
roots::Vector{AcbFieldElem}
real_roots::Vector{ArbFieldElem}
complex_roots::Vector{AcbFieldElem}
end
mutable struct acb_root_ctx
poly::QQPolyRingElem
_roots::Ptr{acb_struct}
prec::Int
roots::Vector{AcbFieldElem}
real_roots::Vector{ArbFieldElem}
complex_roots::Vector{AcbFieldElem}
signature::Tuple{Int, Int}
function acb_root_ctx(x::QQPolyRingElem, p::Int = 32)
z = new()
z.roots = _roots(x, p, p)
z.poly = x
z.prec = p
z._roots = acb_vec(degree(x))
r, s = signature(x)
z.signature = (r, s)
for i = 1:degree(x)
ccall((:acb_set, libarb), Nothing, (Ptr{acb_struct}, Ref{AcbFieldElem}),
z._roots + (i - 1) * sizeof(acb_struct), z.roots[i])
end
z.prec = p
A = Array{ArbFieldElem}(undef, z.signature[1])
B = Array{AcbFieldElem}(undef, z.signature[2])
for i in 1:r
@assert isreal(z.roots[i])
A[i] = real(z.roots[i])
end
j = 0
for i in r+1:degree(x)
if is_positive(imag(z.roots[i]))
j += 1
B[j] = z.roots[i]
end
end
@assert j == s
z.real_roots = A
z.complex_roots = B
finalizer(_acb_root_ctx_clear_fn, z)
return z
end
end
function _acb_root_ctx_clear_fn(x::acb_root_ctx)
ccall((:_acb_vec_clear, libarb), Nothing,
(Ptr{acb_struct}, Int), x._roots, degree(x.poly))
end
################################################################################
#
# SRow/SMat
#
################################################################################
mutable struct SMatSLP_add_row{T}
row::Int
col::Int
val::T
end
mutable struct SMatSLP_swap_row
row::Int
col::Int
end
################################################################################
#
# Sparse rows
#
################################################################################
"""
SRowSpace
Parent type for rows of sparse matrices.
"""
mutable struct SRowSpace{T} <: Ring
base_ring::Ring
function SRowSpace{T}(R::Ring, cached::Bool = false) where {T<:RingElem}
return get_cached!(SRowSpaceDict, R, cached) do
return new{T}(R)
end::SRowSpace{T}
end
end
const SRowSpaceDict = AbstractAlgebra.CacheDictType{Ring, SRowSpace}()
"""
SRow{T, S}
Type for rows of sparse matrices, to create one use
`sparse_row`
`S` is the type of the array used for the values - see `ZZRingElem_Vector` for
an example.
"""
mutable struct SRow{T, S} # S <: AbstractVector{T}
#in this row, in column pos[1] we have value values[1]
base_ring
values::S
pos::Vector{Int}
function SRow(R::Ring)
@assert R != ZZ
S = sparse_inner_type(R)
r = new{elem_type(R), S}(R, S(), Vector{Int}())
return r
end
function SRow(R::Ring, p::Vector{Int64}, S::AbstractVector; check::Bool = true)
if check && any(iszero, S)
p = copy(p)
S = deepcopy(S)
i=1
while i <= length(p)
if iszero(S[i])
deleteat!(S, i)
deleteat!(p, i)
else
i += 1
end
end
end
r = new{elem_type(R), typeof(S)}(R, S, p)
@assert r isa sparse_row_type(R)
return r
end
function SRow(R::Ring, A::Vector{Tuple{Int, T}}) where T
r = SRow(R)
for (i, v) = A
if !iszero(v)
@assert parent(v) === R
push!(r.pos, i)
push!(r.values, v)
end
end
return r
end
function SRow(R::Ring, A::Vector{Tuple{Int, Int}})
r = SRow(R)
for (i, v) = A
if !iszero(v)
push!(r.pos, i)
push!(r.values, R(v))
end
end
return r
end
function SRow{T, S}(A::SRow{T, S}; copy::Bool = false) where {T, S}
copy || return A
@assert Vector{T} === S
r = new{T, Vector{T}}(base_ring(A), Vector{T}(undef, length(A.pos)), copy(A.pos))
for i=1:length(r.values)
r.values[i] = A.values[i]
end
return r
end
function SRow{T}(R::Ring, pos::Vector{Int}, val::Vector{T}) where {T}
length(pos) == length(val) || error("Arrays must have same length")
r = SRow(R)
for i=1:length(pos)
v = val[i]
if !iszero(v)
@assert parent(v) === R
push!(r.pos, pos[i])
push!(r.values, v)
end
end
r.base_ring = R
return
end
end
# helper function used by SRow construct and also by the default
# methods for `sparse_matrix_type` and `sparse_row_type`.
sparse_inner_type(::T) where {T <: Union{Ring, RingElem}} = sparse_inner_type(T)
sparse_inner_type(::Type{T}) where {T <: Ring} = sparse_inner_type(elem_type(T))
sparse_inner_type(::Type{T}) where {T <: RingElem} = Vector{T}
################################################################################
#
# Sparse matrices
#
################################################################################
"""
SMatSpace
Parent for sparse matrices. Usually only created from a sparse matrix
via a call to parent.
"""
struct SMatSpace{T}
rows::Int
cols::Int
base_ring::Ring
function SMatSpace{T}(R::Ring, r::Int, c::Int) where {T}
return new{T}(r, c, R)
end
end
"""
SMat{T}
Type of sparse matrices, to create one use `sparse_matrix`.
"""
mutable struct SMat{T, S}
r::Int
c::Int
rows::Vector{SRow{T, S}}
nnz::Int
base_ring::Union{Ring, Nothing}
tmp::Vector{SRow{T, S}}
function SMat{T, S}() where {T, S}
r = new{T, S}(0,0,Vector{SRow{T, S}}(), 0, nothing, Vector{SRow{T, S}}())
return r
end
function SMat{T, S}(a::SMat{T, S}) where {S, T}
r = new{T, S}(a.r, a.c, Array{SRow{T, S}}(undef, length(a.rows)), a.nnz, a.base_ring, Vector{SRow{T, S}}())
for i=1:nrows(a)
r.rows[i] = a.rows[i]
end
return r
end
end
################################################################################
#
# enum_ctx
#
################################################################################
# now that x is a ZZMatrix, the type for x is not really used
mutable struct enum_ctx{Tx, TC, TU}
G::ZZMatrix
n::Int
limit::Int # stop recursion at level limit, defaults to n
d::IntegerUnion #we actually want G/d
C::Matrix{TC} # the pseudo-cholesky form - we don't have QQMatrix
last_non_zero::Int
x::ZZMatrix # 1 x n
U::Vector{TU}
L::Vector{TU}
l::Vector{TU}
tail::Vector{TU}
c::ZZRingElem # the length of the elements we want
t::ZZMatrix # if set, a transformation to be applied to all elements
t_den::ZZRingElem
cnt::Int
function enum_ctx{Tx, TC, TU}() where {Tx, TC, TU}
return new{Tx, TC, TU}()
end
end
################################################################################
#
# EnumCtxArb
#
################################################################################
mutable struct EnumCtxArb
G::ArbMatrix
L::Vector{ZZMatrix}
x::ZZMatrix
p::Int
function EnumCtxArb(G::ArbMatrix)
z = new()
z.G = G
z.x = zero_matrix(FlintZZ, 1, nrows(G))
z.p = precision(base_ring(G))
return z
end
end
################################################################################
#
# FakeFmpqMatSpace/FakeFmpqMat
#
################################################################################
struct FakeFmpqMatSpace
rows::Int
cols::Int
function FakeFmpqMatSpace(r::Int, c::Int)
return new(r,c)
end
end
"""
FakeFmpqMat
A container type for a pair: an integer matrix (ZZMatrix) and an integer
denominator.
Used predominantly to represent bases of orders in absolute number fields.
"""
mutable struct FakeFmpqMat
num::ZZMatrix
den::ZZRingElem
rows::Int
cols::Int
function FakeFmpqMat()
z = new()
return z
end
function FakeFmpqMat(x::ZZMatrix, y::ZZRingElem, simplified::Bool = false)
z = new()
z.num = x
z.den = y
z.rows = nrows(x)
z.cols = ncols(x)
if !simplified
simplify_content!(z)
end
return z
end
function FakeFmpqMat(x::Tuple{ZZMatrix, ZZRingElem}, simplified::Bool = false)
z = new()
z.num = x[1]
z.den = x[2]
z.rows = nrows(x[1])
z.cols = ncols(x[1])
if !simplified
simplify_content!(z)
end
return z
end
# TODO: Maybe this should be a copy option
function FakeFmpqMat(x::ZZMatrix)
z = new()
z.num = x
z.den = one(FlintZZ)
z.rows = nrows(x)
z.cols = ncols(x)
return z
end
function FakeFmpqMat(x::QQMatrix)
z = new()
z.rows = nrows(x)
z.cols = ncols(x)
n, d = _fmpq_mat_to_fmpz_mat_den(x)
z.num = n
z.den = d
return z
end
end
################################################################################
#
# FacElemMon/FacElem
#
################################################################################
"""
FacElemMon{S}
Parent for factored elements, ie. power products.
"""
mutable struct FacElemMon{S} <: Ring
base_ring::S # for the base
basis_conjugates_log::Dict{RingElem, Tuple{Int, Vector{ArbFieldElem}}}
basis_conjugates::Dict{RingElem, Tuple{Int, Vector{ArbFieldElem}}}
conj_log_cache::Dict{Int, Dict{AbsSimpleNumFieldElem, Vector{ArbFieldElem}}}
function FacElemMon{S}(R::S, cached::Bool = false) where {S}
return get_cached!(FacElemMonDict, R, cached) do
new{S}(R,
Dict{RingElem, Vector{ArbFieldElem}}(),
Dict{RingElem, Vector{ArbFieldElem}}(),
Dict{Int, Dict{AbsSimpleNumFieldElem, Vector{ArbFieldElem}}}()
)
end::FacElemMon{S}
end
function FacElemMon{AbsSimpleNumField}(R::AbsSimpleNumField, cached::Bool = true)
if haskey(FacElemMonDict, R)
return FacElemMonDict[R]::FacElemMon{AbsSimpleNumField}
end
if has_attribute(R, :fac_elem_mon)
F = get_attribute(R, :fac_elem_mon)::FacElemMon{AbsSimpleNumField}
return F
end
z = new{AbsSimpleNumField}(R,
Dict{RingElem, Vector{ArbFieldElem}}(),
Dict{RingElem, Vector{ArbFieldElem}}(),
Dict{Int, Dict{AbsSimpleNumFieldElem, Vector{ArbFieldElem}}}()
)
if cached
set_attribute!(R, :fac_elem_mon => z)
end
return z
end
end
FacElemMon(R::S) where {S} = FacElemMon{S}(R)
"""
FacElem{B, S}
Type for factored elements, that is elements of the form
prod a_i^k_i
for elements `a_i` of type `B` in a ring of type `S`.
"""
mutable struct FacElem{B, S}
fac::Dict{B, ZZRingElem}
hash::UInt
parent::FacElemMon{S}
function FacElem{B, S}() where {B, S}
z = new{B, S}()
z.fac = Dict{B, ZZRingElem}()
z.hash = UInt(0)
return z
end
end
################################################################################
#
# AbsNumFieldOrderSet/AbsSimpleNumFieldOrder
#
################################################################################
mutable struct AbsNumFieldOrderSet{T}
nf::T
function AbsNumFieldOrderSet{T}(a::T, cached::Bool = false) where {T}
return get_cached!(AbsNumFieldOrderSetID, a, cached) do
return new{T}(a)::AbsNumFieldOrderSet{T}
end::AbsNumFieldOrderSet{T}
end
end
AbsNumFieldOrderSet(a::T, cached::Bool = false) where {T} = AbsNumFieldOrderSet{T}(a, cached)
const AbsNumFieldOrderSetID = AbstractAlgebra.CacheDictType{NumField, AbsNumFieldOrderSet}()
@attributes mutable struct AbsNumFieldOrder{S, T} <: NumFieldOrder
nf::S
basis_nf::Vector{T} # Basis as array of number field elements
basis_ord#::Vector{AbsNumFieldOrderElem} # Basis as array of order elements
basis_matrix::FakeFmpqMat # Basis matrix of order wrt basis of K
basis_mat_inv::FakeFmpqMat # Inverse of basis matrix
gen_index::QQFieldElem # The det of basis_mat_inv as QQFieldElem
index::ZZRingElem # The det of basis_mat_inv
# (this is the index of the equation order
# in the given order)
disc::ZZRingElem # Discriminant
is_equation_order::Bool # Equation order of ambient number field?
minkowski_matrix::Tuple{ArbMatrix, Int} # Minkowski matrix
minkowski_gram_mat_scaled::Tuple{ZZMatrix, Int} # Minkowski matrix - gram * 2^prec and rounded
minkowski_gram_CMfields::ZZMatrix
complex_conjugation_CM::Map
torsion_units#::Tuple{Int, AbsNumFieldOrderElem}
is_maximal::Int # 0 Not known
# 1 Known to be maximal
# 2 Known to not be maximal
primesofmaximality::Vector{ZZRingElem} # primes at the which the order is known to
# to be maximal
norm_change_const::Tuple{BigFloat, BigFloat}
# Tuple c1, c2 as in the paper of
# Fieker-Friedrich
trace_mat::ZZMatrix # The trace matrix (if known)
tcontain::FakeFmpqMat # Temporary variable for _check_elem_in_order
# and den.
tcontain_fmpz::ZZRingElem # Temporary variable for _check_elem_in_order
tcontain_fmpz2::ZZRingElem # Temporary variable for _check_elem_in_order
tidempotents::ZZMatrix # Temporary variable for idempotents()
index_div::Dict{ZZRingElem, Vector} # the index divisor splitting
# Any = Array{AbsNumFieldOrderIdeal, Int}
# but forward references are illegal
lllO::AbsNumFieldOrder{S, T} # the same order with a lll-reduced basis
function AbsNumFieldOrder{S, T}(a::S) where {S, T}
# "Default" constructor with default values.
r = new{S, elem_type(S)}()
r.nf = a
#r.signature = (-1,0)
r.primesofmaximality = Vector{ZZRingElem}()
#r.norm_change_const = (-1.0, -1.0)
r.is_equation_order = false
r.is_maximal = 0
r.tcontain = FakeFmpqMat(zero_matrix(FlintZZ, 1, degree(a)))
r.tcontain_fmpz = ZZRingElem()
r.tcontain_fmpz2 = ZZRingElem()
r.tidempotents = zero_matrix(FlintZZ, 1 + 2*degree(a), 1 + 2*degree(a))
r.index_div = Dict{ZZRingElem, Vector}()
return r
end
function AbsNumFieldOrder{S, T}(K::S, x::FakeFmpqMat, xinv::FakeFmpqMat, B::Vector{T}, cached::Bool = false) where {S, T}
return get_cached!(AbsNumFieldOrderID, (K, x), cached) do
z = AbsNumFieldOrder{S, T}(K)
n = degree(K)
z.basis_nf = B
z.basis_matrix = x
z.basis_mat_inv = xinv
return z
end::AbsNumFieldOrder{S, T}
end
function AbsNumFieldOrder{S, T}(K::S, x::FakeFmpqMat, cached::Bool = false) where {S, T}
return get_cached!(AbsNumFieldOrderID, (K, x), cached) do
z = AbsNumFieldOrder{S, T}(K)
n = degree(K)
B_K = basis(K)
d = Vector{T}(undef, n)
for i in 1:n
d[i] = elem_from_mat_row(K, x.num, i, x.den)
end
z.basis_nf = d
z.basis_matrix = x
return z
end::AbsNumFieldOrder{S, T}
end
function AbsNumFieldOrder{S, T}(b::Vector{T}, cached::Bool = false) where {S, T}
K = parent(b[1])
A = basis_matrix(b, FakeFmpqMat)
return get_cached!(AbsNumFieldOrderID, (K, A), cached) do
z = AbsNumFieldOrder{parent_type(T), T}(K)
z.basis_nf = b
z.basis_matrix = A
return z
end::AbsNumFieldOrder{S, T}
end
end
AbsNumFieldOrder(K::S, x::FakeFmpqMat, xinv::FakeFmpqMat, B::Vector{T}, cached::Bool = false) where {S, T} = AbsNumFieldOrder{S, T}(K, x, xinv, B, cached)
AbsNumFieldOrder(K::S, x::FakeFmpqMat, cached::Bool = false) where {S} = AbsNumFieldOrder{S, elem_type(S)}(K, x, cached)
AbsNumFieldOrder(b::Vector{T}, cached::Bool = false) where {T} = AbsNumFieldOrder{parent_type(T), T}(b, cached)
const AbsNumFieldOrderID = AbstractAlgebra.CacheDictType{Tuple{Any, FakeFmpqMat}, AbsNumFieldOrder}()
const AbsSimpleNumFieldOrder = AbsNumFieldOrder{AbsSimpleNumField, AbsSimpleNumFieldElem}
################################################################################
#
# AbsSimpleNumFieldOrder/AbsSimpleNumFieldOrderElem
#
################################################################################
mutable struct AbsNumFieldOrderElem{S, T} <: NumFieldOrderElem
elem_in_nf::T
coordinates::Vector{ZZRingElem}
has_coord::Bool
parent::AbsNumFieldOrder{S, T}
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}) where {S, T}
z = new{S, T}()
z.parent = O
z.elem_in_nf = nf(O)()
z.coordinates = Vector{ZZRingElem}(undef, degree(O))
z.has_coord = false
return z
end
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}, a::T) where {S, T}
z = new{S, T}()
z.elem_in_nf = a
z.coordinates = Vector{ZZRingElem}(undef, degree(O))
z.parent = O
z.has_coord = false
return z
end
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}, a::T, arr::Vector{ZZRingElem}) where {S, T}
z = new{S, T}()
z.parent = O
z.elem_in_nf = a
z.has_coord = true
z.coordinates = arr
return z
end
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}, arr::ZZMatrix) where {S, T}
(nrows(arr) > 1 && ncols(arr) > 1) &&
error("Matrix must have 1 row or 1 column")
z = new{S, T}()
y = zero(nf(O))
for i in 1:degree(O)
y += arr[i] * O.basis_nf[i]
end
z.elem_in_nf = y
z.has_coord = true
z.coordinates = reshape(collect(arr), :)
z.parent = O
return z
end
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}, arr::Vector{ZZRingElem}) where {S, T}
z = new{S, T}()
k = nf(O)
if isa(k, AbsSimpleNumField)
if is_equation_order(O)
z.elem_in_nf = k(k.pol.parent(arr))
else
#avoids rational (polynomial) arithmetic
xx = arr*O.basis_matrix.num
z.elem_in_nf = divexact(k(k.pol.parent(xx)), O.basis_matrix.den)
end
else
z.elem_in_nf = dot(O.basis_nf, arr)
end
z.has_coord = true
z.coordinates = arr
z.parent = O
return z
end
function AbsNumFieldOrderElem{S, T}(O::AbsNumFieldOrder{S, T}, arr::Vector{U}) where {S, T, U <: Integer}
return AbsNumFieldOrderElem{S, T}(O, map(FlintZZ, arr))
end
function AbsNumFieldOrderElem{S, T}(x::AbsNumFieldOrderElem{S, T}) where {S, T}
return deepcopy(x) ### Check parent?
end
end
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}) where {S, T} = AbsNumFieldOrderElem{S, T}(O)
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, a::T) where {S, T} = AbsNumFieldOrderElem{S, T}(O, a)
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, a::T, arr::Vector{ZZRingElem}) where {S, T} = AbsNumFieldOrderElem{S, T}(O, a, arr)
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, arr::Vector{ZZRingElem}) where {S, T} = AbsNumFieldOrderElem{S, T}(O, arr)
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, arr::ZZMatrix) where {S, T} = AbsNumFieldOrderElem{S, T}(O, arr)
AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, arr::Vector{U}) where {S, T, U <: Integer} = AbsNumFieldOrderElem{S, T}(O, arr)
#AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, p::Integer) where {S, T} = AbsNumFieldOrderElem{S, T}(O, p)
#AbsNumFieldOrderElem(O::AbsNumFieldOrder{S, T}, p::ZZRingElem) where {S, T} = AbsNumFieldOrderElem{S, T}(O, p)
const AbsSimpleNumFieldOrderElem = AbsNumFieldOrderElem{AbsSimpleNumField,AbsSimpleNumFieldElem}
################################################################################
#
# AbsNumFieldOrderIdealSet{AbsSimpleNumField, AbsSimpleNumFieldElem}/AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}
#
################################################################################
struct AbsNumFieldOrderIdealSet{S, T}
order::AbsNumFieldOrder{S, T}
function AbsNumFieldOrderIdealSet{S, T}(O::AbsNumFieldOrder{S, T}, cached::Bool = false) where {S, T}
return get_cached!(AbsNumFieldOrderIdealSetID, O, cached) do
return new{S, T}(O)
end::AbsNumFieldOrderIdealSet{S, T}
end
end
function AbsNumFieldOrderIdealSet(O::AbsNumFieldOrder{S, T}, cached::Bool = false) where {S, T}
return AbsNumFieldOrderIdealSet{S, T}(O, cached)
end
const AbsNumFieldOrderIdealSetID = AbstractAlgebra.CacheDictType{AbsNumFieldOrder, AbsNumFieldOrderIdealSet}()
@doc raw"""
AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}(O::AbsSimpleNumFieldOrder, a::ZZMatrix) -> AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}
Creates the ideal of $O$ with basis matrix $a$.
No sanity checks. No data is copied, $a$ should not be used anymore.
AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}(a::ZZRingElem, b::AbsSimpleNumFieldOrderElem) -> AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}
Creates the ideal $(a,b)$ of the order of $b$.
No sanity checks. No data is copied, $a$ and $b$ should not be used anymore.
AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}(O::AbsSimpleNumFieldOrder, a::ZZRingElem, b::AbsSimpleNumFieldElem) -> AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}
Creates the ideal $(a,b)$ of $O$.
No sanity checks. No data is copied, $a$ and $b$ should not be used anymore.
AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}(x::AbsSimpleNumFieldOrderElem) -> AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}
Creates the principal ideal $(x)$ of the order of $O$.
No sanity checks. No data is copied, $x$ should not be used anymore.
"""
@attributes mutable struct AbsNumFieldOrderIdeal{S, T} <: NumFieldOrderIdeal
order::AbsNumFieldOrder{S, T}
basis::Vector{AbsNumFieldOrderElem{S, T}}
basis_matrix::ZZMatrix
basis_mat_inv::FakeFmpqMat
lll_basis_matrix::ZZMatrix
gen_one::ZZRingElem
gen_two::AbsNumFieldOrderElem{S, T}
gens_short::Bool
gens_normal::ZZRingElem
gens_weakly_normal::Bool # true if Norm(A) = gcd(Norm, Norm)
# weaker than normality - at least potentially
norm::ZZRingElem
minimum::ZZRingElem
is_prime::Int # 0: don't know
# 1 known to be prime
# 2 known to be not prime
iszero::Int # as above
is_principal::Int # as above
princ_gen::AbsNumFieldOrderElem{S, T}
princ_gen_fac_elem::FacElem{T, S}
princ_gen_special::Tuple{Int, Int, ZZRingElem}
# Check if the ideal is generated by an integer
# First entry encodes the following:
# 0: don't know
# 1: second entry generates the ideal
# 2: third entry generates the ideal
splitting_type::Tuple{Int, Int}
#ordered as ramification index, inertia degree
anti_uniformizer::T
valuation::Function # a function returning "the" valuation -
# mind that the ideal is not prime
gens::Vector{AbsNumFieldOrderElem{S, T}} # A set of generators of the ideal
## For residue fields of non-index divisors
prim_elem::AbsNumFieldOrderElem{S, T}
min_poly_prim_elem::ZZPolyRingElem # minimal polynomial modulo P
basis_in_prim::Vector{ZZMatrix} #
function AbsNumFieldOrderIdeal{S, T}(O::AbsNumFieldOrder{S, T}) where {S, T}
# populate the bits types (Bool, Int) with default values
r = new{S, T}()
r.order = O
r.gens_short = false
r.gens_weakly_normal = false
r.iszero = 0
r.is_prime = 0
r.is_principal = 0
r.splitting_type = (0,0)
return r
end
function AbsNumFieldOrderIdeal{S, T}(O::AbsNumFieldOrder{S, T}, a::ZZMatrix) where {S, T}
# create ideal of O with basis_matrix a
# Note that the constructor 'destroys' a, a should not be used anymore
r = AbsNumFieldOrderIdeal(O)
r.basis_matrix = a
return r
end
function AbsNumFieldOrderIdeal{S, T}(a::ZZRingElem, b::AbsNumFieldOrderElem{S, T}) where {S, T}
# create ideal (a,b) of order(b)
r = AbsNumFieldOrderIdeal(parent(b))
r.gen_one = a
r.gen_two = b
return r
end
function AbsNumFieldOrderIdeal{S, T}(O::AbsNumFieldOrder{S, T}, a::ZZRingElem, b::AbsSimpleNumFieldElem) where {S, T}
# create ideal (a,b) of O
r = AbsNumFieldOrderIdeal(a, O(b, false))
return r
end
function AbsNumFieldOrderIdeal{S, T}(O::AbsNumFieldOrder{S, T}, a::AbsNumFieldOrderElem{S, T}) where {S, T}
return AbsNumFieldOrderIdeal(a)
end