@@ -16,6 +16,7 @@ AUTHOR:
16
16
from cysignals.signals cimport sig_on, sig_off
17
17
18
18
from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class
19
+ from sage.libs.ntl.ntl_ZZ_pE cimport ntl_ZZ_pE
19
20
from sage.libs.ntl.ZZ_pE cimport ZZ_pE_to_ZZ_pX
20
21
from sage.libs.ntl.ZZ_pX cimport ZZ_pX_deg, ZZ_pX_coeff
21
22
from sage.libs.ntl.ZZ_p cimport ZZ_p_rep
@@ -25,23 +26,22 @@ from sage.libs.ntl.convert cimport ZZ_to_mpz
25
26
# to make sure the function get_cparent is found since it is used in
26
27
# 'polynomial_template.pxi'.
27
28
28
- cdef cparent get_cparent(parent) except ? NULL :
29
+ cdef cparent get_cparent(parent) except ? NULL :
29
30
if parent is None :
30
31
return NULL
31
32
cdef ntl_ZZ_pEContext_class pec
32
33
try :
33
34
pec = parent._modulus
34
35
except AttributeError :
35
36
return NULL
36
- return & (pec.ptrs)
37
+ return & (pec.ptrs)
37
38
38
39
# first we include the definitions
39
40
include " sage/libs/ntl/ntl_ZZ_pEX_linkage.pxi"
40
41
41
42
# and then the interface
42
43
include " polynomial_template.pxi"
43
44
44
- from sage.libs.ntl.ntl_ZZ_pE cimport ntl_ZZ_pE
45
45
46
46
cdef inline ZZ_pE_c_to_list(ZZ_pE_c x):
47
47
cdef list L = []
@@ -52,12 +52,12 @@ cdef inline ZZ_pE_c_to_list(ZZ_pE_c x):
52
52
53
53
c_pX = ZZ_pE_to_ZZ_pX(x)
54
54
d = ZZ_pX_deg(c_pX)
55
- if d>= 0 :
55
+ if d >= 0 :
56
56
for 0 <= j <= d:
57
57
c_p = ZZ_pX_coeff(c_pX, j)
58
58
c_c = ZZ_p_rep(c_p)
59
59
ans = Integer.__new__ (Integer)
60
- ZZ_to_mpz(ans.value, & c_c)
60
+ ZZ_to_mpz(ans.value, & c_c)
61
61
L.append(ans)
62
62
return L
63
63
@@ -73,6 +73,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
73
73
sage: ( x^ 3 + a* x^ 2 + 1) * ( x + a)
74
74
x^ 4 + 2* a* x^ 3 + a^ 2* x^ 2 + x + a
75
75
"""
76
+
76
77
def __init__ (self , parent , x = None , check = True , is_gen = False , construct = False ):
77
78
r """
78
79
Create a new univariate polynomials over `\G F{p^ n}`.
@@ -124,8 +125,8 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
124
125
try :
125
126
if (x.parent() is parent.base_ring()) or (x.parent() == parent.base_ring()):
126
127
Polynomial.__init__ (self , parent, is_gen = is_gen)
127
- (< Polynomial_template> self )._cparent = get_cparent(parent)
128
- celement_construct(& self .x, (< Polynomial_template> self )._cparent)
128
+ ( < Polynomial_template > self )._cparent = get_cparent(parent)
129
+ celement_construct(& self .x, ( < Polynomial_template > self )._cparent)
129
130
d = parent._modulus.ZZ_pE(list (x.polynomial()))
130
131
ZZ_pEX_SetCoeff(self .x, 0 , d.x)
131
132
return
@@ -137,10 +138,10 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
137
138
138
139
if isinstance (x, (list , tuple )):
139
140
Polynomial.__init__ (self , parent, is_gen = is_gen)
140
- (< Polynomial_template> self )._cparent = get_cparent(parent)
141
- celement_construct(& self .x, (< Polynomial_template> self )._cparent)
141
+ ( < Polynomial_template > self )._cparent = get_cparent(parent)
142
+ celement_construct(& self .x, ( < Polynomial_template > self )._cparent)
142
143
K = parent.base_ring()
143
- for i,e in enumerate (x):
144
+ for i, e in enumerate (x):
144
145
# self(x) is supposed to be a conversion,
145
146
# not necessarily a coercion. So, we must
146
147
# not do K.coerce(e) but K(e).
@@ -195,7 +196,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
195
196
196
197
K = self ._parent.base_ring()
197
198
return [K(ZZ_pE_c_to_list(ZZ_pEX_coeff(self .x, i)))
198
- for i in range (celement_len(& self .x, (< Polynomial_template> self )._cparent))]
199
+ for i in range (celement_len(& self .x, ( < Polynomial_template > self )._cparent))]
199
200
200
201
cpdef _lmul_(self , Element left):
201
202
r """
@@ -211,9 +212,9 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
211
212
cdef ntl_ZZ_pE d
212
213
cdef Polynomial_ZZ_pEX r
213
214
r = Polynomial_ZZ_pEX.__new__ (Polynomial_ZZ_pEX)
214
- celement_construct(& r.x, (< Polynomial_template> self )._cparent)
215
- r._parent = (< Polynomial_template> self )._parent
216
- r._cparent = (< Polynomial_template> self )._cparent
215
+ celement_construct(& r.x, ( < Polynomial_template > self )._cparent)
216
+ r._parent = ( < Polynomial_template > self )._parent
217
+ r._cparent = ( < Polynomial_template > self )._cparent
217
218
d = self ._parent._modulus.ZZ_pE(list (left.polynomial()))
218
219
ZZ_pEX_mul_ZZ_pE(r.x, self .x, d.x)
219
220
return r
@@ -262,15 +263,15 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
262
263
263
264
if kwds:
264
265
if x:
265
- raise TypeError (" %s __call__() takes exactly 1 argument" % type (self ))
266
+ raise TypeError (" %s __call__() takes exactly 1 argument" % type (self ))
266
267
try :
267
268
x = [kwds.pop(self .variable_name())]
268
269
except KeyError :
269
270
pass
270
271
if kwds:
271
- raise TypeError (" %s __call__() accepts no named argument except '%s '" % (type (self ),self .variable_name()))
272
- if len (x)! = 1 :
273
- raise TypeError (" %s __call__() takes exactly 1 positional argument" % type (self ))
272
+ raise TypeError (" %s __call__() accepts no named argument except '%s '" % (type (self ), self .variable_name()))
273
+ if len (x) ! = 1 :
274
+ raise TypeError (" %s __call__() takes exactly 1 positional argument" % type (self ))
274
275
275
276
a = x[0 ]
276
277
try :
@@ -310,7 +311,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
310
311
if other.parent() is not self ._parent:
311
312
other = self ._parent.coerce(other)
312
313
313
- ZZ_pEX_resultant(r, self .x, (< Polynomial_ZZ_pEX> other).x)
314
+ ZZ_pEX_resultant(r, self .x, ( < Polynomial_ZZ_pEX > other).x)
314
315
315
316
K = self ._parent.base_ring()
316
317
return K(K.polynomial_ring()(ZZ_pE_c_to_list(r)))
@@ -349,15 +350,15 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
349
350
False
350
351
"""
351
352
self ._parent._modulus.restore()
352
- if algorithm== " fast_when_false" :
353
+ if algorithm == " fast_when_false" :
353
354
sig_on()
354
355
res = ZZ_pEX_IterIrredTest(self .x)
355
356
sig_off()
356
- elif algorithm== " fast_when_true" :
357
+ elif algorithm == " fast_when_true" :
357
358
sig_on()
358
359
res = ZZ_pEX_DetIrredTest(self .x)
359
360
sig_off()
360
- elif algorithm== " probabilistic" :
361
+ elif algorithm == " probabilistic" :
361
362
sig_on()
362
363
res = ZZ_pEX_ProbIrredTest(self .x, iter )
363
364
sig_off()
@@ -402,11 +403,11 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
402
403
403
404
cdef Polynomial_ZZ_pEX r
404
405
r = Polynomial_ZZ_pEX.__new__ (Polynomial_ZZ_pEX)
405
- celement_construct(& r.x, (< Polynomial_template> self )._cparent)
406
- r._parent = (< Polynomial_template> self )._parent
407
- r._cparent = (< Polynomial_template> self )._cparent
406
+ celement_construct(& r.x, ( < Polynomial_template > self )._cparent)
407
+ r._parent = ( < Polynomial_template > self )._parent
408
+ r._cparent = ( < Polynomial_template > self )._cparent
408
409
409
- ZZ_pEX_MinPolyMod(r.x, (< Polynomial_ZZ_pEX> (self % other)).x, (< Polynomial_ZZ_pEX> other).x)
410
+ ZZ_pEX_MinPolyMod(r.x, ( < Polynomial_ZZ_pEX > (self % other)).x, ( < Polynomial_ZZ_pEX > other).x)
410
411
return r
411
412
412
413
cpdef _richcmp_(self , other, int op):
@@ -452,9 +453,9 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
452
453
self ._parent._modulus.restore()
453
454
cdef Polynomial_ZZ_pEX r
454
455
r = Polynomial_ZZ_pEX.__new__ (Polynomial_ZZ_pEX)
455
- celement_construct(& r.x, (< Polynomial_template> self )._cparent)
456
- r._parent = (< Polynomial_template> self )._parent
457
- r._cparent = (< Polynomial_template> self )._cparent
456
+ celement_construct(& r.x, ( < Polynomial_template > self )._cparent)
457
+ r._parent = ( < Polynomial_template > self )._parent
458
+ r._cparent = ( < Polynomial_template > self )._cparent
458
459
ZZ_pEX_LeftShift(r.x, self .x, n)
459
460
return r
460
461
@@ -502,26 +503,46 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
502
503
4* x^ 15 + 32* x^ 9 + 11* x^ 5 + x^ 2
503
504
sage: f. reverse( degree=2)
504
505
4* x^ 2
506
+
507
+ TESTS::
508
+
509
+ sage: R. <x> = GF( 163^ 2) []
510
+ sage: f. reverse( degree=10)
511
+ 2* x^ 10 + 3* x^ 9
512
+ sage: f = R( [p for p in primes(20) ])
513
+ sage: f. reverse( )
514
+ 2* x^ 7 + 3* x^ 6 + 5* x^ 5 + 7* x^ 4 + 11* x^ 3 + 13* x^ 2 + 17* x + 19
515
+ sage: f. reverse( degree=200)
516
+ 2* x^ 200 + 3* x^ 199 + 5* x^ 198 + 7* x^ 197 + 11* x^ 196 + 13* x^ 195 + 17* x^ 194 + 19* x^ 193
517
+ sage: f. reverse( degree=0)
518
+ ValueError Traceback ( most recent call last)
519
+ ...
520
+ sage: f. reverse( degree=-5)
521
+ ValueError Traceback ( most recent call last)
522
+ ...
523
+ ValueError: degree argument must be a non-negative integer, got -5
505
524
"""
506
525
self ._parent._modulus.restore()
507
526
508
527
# Construct output polynomial
509
528
cdef Polynomial_ZZ_pEX r
510
529
r = Polynomial_ZZ_pEX.__new__ (Polynomial_ZZ_pEX)
511
- celement_construct(& r.x, (< Polynomial_template> self )._cparent)
512
- r._parent = (< Polynomial_template> self )._parent
513
- r._cparent = (< Polynomial_template> self )._cparent
530
+ celement_construct(& r.x, ( < Polynomial_template > self )._cparent)
531
+ r._parent = ( < Polynomial_template > self )._parent
532
+ r._cparent = ( < Polynomial_template > self )._cparent
514
533
515
534
# When a degree has been supplied, ensure it is a valid input
516
535
cdef unsigned long d
517
536
if degree is not None :
537
+ if degree <= 0 :
538
+ raise ValueError (" degree argument must be a non-negative integer, got %s " % (degree))
518
539
try :
519
540
d = degree
520
541
except ValueError :
521
- raise ValueError (" degree argument must be a non-negative integer, got %s " % (degree))
522
- ZZ_pEX_reverse_hi(r.x, (< Polynomial_ZZ_pEX> self ).x, d)
542
+ raise ValueError (" degree argument must be a non-negative integer, got %s " % (degree))
543
+ ZZ_pEX_reverse_hi(r.x, ( < Polynomial_ZZ_pEX > self ).x, d)
523
544
else :
524
- ZZ_pEX_reverse(r.x, (< Polynomial_ZZ_pEX> self ).x)
545
+ ZZ_pEX_reverse(r.x, ( < Polynomial_ZZ_pEX > self ).x)
525
546
return r
526
547
527
548
def inverse_series_trunc (self , prec ):
@@ -534,7 +555,6 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
534
555
sage: R. <x> = GF( 101^ 2) []
535
556
sage: z2 = R. base_ring( ) . gen( )
536
557
sage: f = ( 3* z2 + 57) * x^ 3 + ( 13* z2 + 94) * x^ 2 + ( 7* z2 + 2) * x + 66* z2 + 15
537
- sage:
538
558
sage: f. inverse_series_trunc( 1)
539
559
51* z2 + 92
540
560
sage: f. inverse_series_trunc( 2)
@@ -543,6 +563,30 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
543
563
( 42* z2 + 94) * x^ 2 + ( 30* z2 + 30) * x + 51* z2 + 92
544
564
sage: f. inverse_series_trunc( 4)
545
565
( 99* z2 + 96) * x^ 3 + ( 42* z2 + 94) * x^ 2 + ( 30* z2 + 30) * x + 51* z2 + 92
566
+
567
+ TESTS::
568
+
569
+ sage: R. <x> = GF( 163^ 2) []
570
+ sage: f = R( [p for p in primes(20) ])
571
+ sage: f. inverse_series_trunc( 1)
572
+ 82
573
+ sage: f. inverse_series_trunc( 2)
574
+ 40* x + 82
575
+ sage: f. inverse_series_trunc( 3)
576
+ 61* x^ 2 + 40* x + 82
577
+ sage: f. inverse_series_trunc( 0)
578
+ ValueError Traceback ( most recent call last)
579
+ ...
580
+ ValueError: the precision must be positive, got 0
581
+ sage: f. inverse_series_trunc( -1)
582
+ ValueError Traceback ( most recent call last)
583
+ ...
584
+ ValueError: the precision must be positive, got -1
585
+ sage: f = x + x^ 2 + x^ 3
586
+ sage: f. inverse_series_trunc( 5)
587
+ ValueError Traceback ( most recent call last)
588
+ ...
589
+ ValueError: constant term 0 is not a unit
546
590
"""
547
591
self ._parent._modulus.restore()
548
592
@@ -558,13 +602,13 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
558
602
# Construct output polynomial
559
603
cdef Polynomial_ZZ_pEX r
560
604
r = Polynomial_ZZ_pEX.__new__ (Polynomial_ZZ_pEX)
561
- celement_construct(& r.x, (< Polynomial_template> self )._cparent)
562
- r._parent = (< Polynomial_template> self )._parent
563
- r._cparent = (< Polynomial_template> self )._cparent
605
+ celement_construct(& r.x, (< Polynomial_template > self )._cparent)
606
+ r._parent = (< Polynomial_template > self )._parent
607
+ r._cparent = (< Polynomial_template > self )._cparent
564
608
565
609
# Call to NTL for the inverse truncation
566
610
if prec > 0 :
567
611
sig_on()
568
612
ZZ_pEX_InvTrunc(r.x, self .x, prec)
569
613
sig_off()
570
- return r
614
+ return r
0 commit comments