Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 81228f5

Browse files
committed
remove CenterSkewPolynomial_generic_dense and duplicate methods
1 parent 1725800 commit 81228f5

File tree

2 files changed

+21
-102
lines changed

2 files changed

+21
-102
lines changed

src/sage/rings/polynomial/skew_polynomial_finite_field.pxd

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from sage.rings.polynomial.skew_polynomial_finite_order cimport SkewPolynomial_finite_order_dense
2-
from sage.rings.polynomial.skew_polynomial_element cimport CenterSkewPolynomial_generic_dense
32
from sage.matrix.matrix_dense cimport Matrix_dense
43

54
cdef class SkewPolynomial_finite_field_dense (SkewPolynomial_finite_order_dense):
@@ -9,7 +8,7 @@ cdef class SkewPolynomial_finite_field_dense (SkewPolynomial_finite_order_dense)
98
cdef _factorization
109

1110
# Finding divisors
12-
cdef SkewPolynomial_finite_field_dense _rdivisor_c(P, CenterSkewPolynomial_generic_dense N)
11+
cdef SkewPolynomial_finite_field_dense _rdivisor_c(P, N)
1312

1413
# Finding factorizations
1514
cdef _factor_c(self)

src/sage/rings/polynomial/skew_polynomial_finite_field.pyx

+20-100
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ from sage.matrix.matrix_dense cimport Matrix_dense
3535
from sage.matrix.matrix_space import MatrixSpace
3636
from sage.rings.all import ZZ
3737
from sage.rings.polynomial.polynomial_element cimport Polynomial
38-
from sage.rings.polynomial.skew_polynomial_element cimport CenterSkewPolynomial_generic_dense
3938
from sage.rings.integer cimport Integer
4039
from sage.structure.element cimport RingElement
4140
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
@@ -225,7 +224,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
225224
# Finding divisors
226225
# ----------------
227226

228-
cdef SkewPolynomial_finite_field_dense _rdivisor_c(P, CenterSkewPolynomial_generic_dense N):
227+
cdef SkewPolynomial_finite_field_dense _rdivisor_c(P, N):
229228
"""
230229
cython procedure computing an irreducible monic right divisor
231230
of `P` whose reduced norm is `N`
@@ -246,8 +245,8 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
246245
D = D.right_monic()
247246
return D
248247

249-
Z = PolynomialRing(N.parent().base_ring(), name='xr')
250-
E = Z.quo(Z(N.list()))
248+
center = N.parent()
249+
E = center.quo(N)
251250
PE = PolynomialRing(E, name='T')
252251
cdef Integer exp
253252
if skew_ring.characteristic() != 2:
@@ -293,7 +292,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
293292
yy += 2
294293
dd = xx.gcd(yy)
295294
if dd.degree() != 1: continue
296-
D = P.right_gcd(R + skew_ring.center()((dd[0]/dd[1]).list()))
295+
D = P.right_gcd(R + skew_ring(center((dd[0]/dd[1]).list())))
297296
if D.degree() == 0:
298297
continue
299298
D = D.right_monic()
@@ -467,7 +466,6 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
467466
x + 2*t^2 + 4*t
468467
"""
469468
cdef SkewPolynomial_finite_field_dense cP1
470-
cdef CenterSkewPolynomial_generic_dense cN
471469
if self.is_zero():
472470
raise "No irreducible divisor having given reduced norm"
473471
skew_ring = self._parent
@@ -491,7 +489,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
491489
except (KeyError, TypeError):
492490
if N.is_irreducible():
493491
cP1 = <SkewPolynomial_finite_field_dense>self.right_gcd(self._parent(N))
494-
cN = <CenterSkewPolynomial_generic_dense>N
492+
cN = N
495493
if cP1.degree() > 0:
496494
D = cP1._rdivisor_c(cN)
497495
if self._rdivisors is None:
@@ -762,7 +760,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
762760
val += 1
763761

764762
cdef Py_ssize_t degQ, degrandom, m, mP, i
765-
cdef CenterSkewPolynomial_generic_dense N
763+
cdef N
766764
cdef list factors = [ (skew_ring.gen(), val) ]
767765
cdef SkewPolynomial_finite_field_dense P, Q, P1, NS, g, right, Pn
768766
cdef RingElement unit = <RingElement>self.leading_coefficient()
@@ -826,14 +824,13 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
826824
"""
827825
skew_ring = self._parent
828826
cdef Integer cardE, cardcenter = skew_ring.center().base_ring().cardinality()
829-
cdef CenterSkewPolynomial_generic_dense gencenter = <CenterSkewPolynomial_generic_dense>skew_ring.center().gen()
827+
cdef gencenter = skew_ring.center().gen()
830828
cdef SkewPolynomial_finite_field_dense gen = <SkewPolynomial_finite_field_dense>skew_ring.gen()
831829

832830
cdef list factorsN = [ ]
833831
cdef dict dict_divisor = { }
834832
cdef dict dict_type = { }
835833
cdef dict dict_right = { }
836-
cdef CenterSkewPolynomial_generic_dense N
837834
cdef Py_ssize_t m
838835
cdef list type
839836

@@ -1055,37 +1052,9 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
10551052
count /= factorial(m)
10561053
return count * factorial(summ)
10571054

1058-
def count_factorisations(self):
1059-
"""
1060-
Return the number of factorisations (as a product of a
1061-
unit and a product of irreducible monic factors) of this
1062-
skew polynomial.
1063-
1064-
EXAMPLES::
1065-
1066-
sage: k.<t> = GF(5^3)
1067-
sage: Frob = k.frobenius_endomorphism()
1068-
sage: S.<x> = k['x',Frob]
1069-
sage: a = x^4 + (4*t + 3)*x^3 + t^2*x^2 + (4*t^2 + 3*t)*x + 3*t
1070-
sage: a.count_factorisations()
1071-
216
1072-
1073-
We illustrate that an irreducible polynomial in the center have
1074-
in general a lot of distinct factorisations in the skew polynomial
1075-
ring::
1076-
1077-
sage: Z = S.center(); x3 = Z.gen()
1078-
sage: N = x3^5 + 4*x3^4 + 4*x3^2 + 4*x3 + 3; N
1079-
(x^3)^5 + 4*(x^3)^4 + 4*(x^3)^2 + 4*(x^3) + 3
1080-
sage: N.is_irreducible()
1081-
True
1082-
sage: S(N).count_factorisations()
1083-
30537115626
1084-
"""
1085-
return self.count_factorizations()
10861055

1087-
1088-
# Not optimized (many calls to reduced_norm, reduced_norm_factor,_rdivisor_c, which are slow)
1056+
# Not optimized:
1057+
# many calls to reduced_norm, reduced_norm_factor,_rdivisor_c, which are slow
10891058
def factorizations(self):
10901059
"""
10911060
Return an iterator over all factorizations (as a product
@@ -1132,65 +1101,16 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense):
11321101
"""
11331102
if self.is_zero():
11341103
raise ValueError("factorization of 0 not defined")
1135-
unit = self.leading_coefficient()
1136-
poly = self.right_monic()
1137-
for factors in self._factorizations_rec():
1104+
def factorizations_rec(P):
1105+
if P.is_irreducible():
1106+
yield [ (P,1) ]
1107+
else:
1108+
for div in P._irreducible_divisors(True):
1109+
poly = self // div
1110+
# Here, we should update poly._norm, poly._norm_factor, poly._rdivisors
1111+
for factors in P._factorizations_rec():
1112+
factors.append((div,1))
1113+
yield factors
1114+
for factors in factorizations_rec(self):
11381115
yield Factorization(factors,sort=False,unit=unit)
11391116

1140-
def _factorizations_rec(self):
1141-
if self.is_irreducible():
1142-
yield [ (self,1) ]
1143-
else:
1144-
for div in self._irreducible_divisors(True):
1145-
poly = self // div
1146-
# Here, we should update poly._norm, poly._norm_factor, poly._rdivisors
1147-
for factors in poly._factorizations_rec():
1148-
factors.append((div,1))
1149-
yield factors
1150-
1151-
1152-
def factorisations(self):
1153-
"""
1154-
Return an iterator over all factorisations (as a product
1155-
of a unit and a product of irreducible monic factors) of
1156-
this skew polynomial.
1157-
1158-
.. NOTE::
1159-
1160-
The algorithm is probabilistic. As a consequence, if
1161-
we execute two times with the same input we can get
1162-
the list of all factorizations in two differents orders.
1163-
1164-
EXAMPLES::
1165-
1166-
sage: k.<t> = GF(5^3)
1167-
sage: Frob = k.frobenius_endomorphism()
1168-
sage: S.<x> = k['x',Frob]
1169-
sage: a = x^3 + (t^2 + 1)*x^2 + (2*t + 3)*x + t^2 + t + 2
1170-
sage: iter = a.factorisations(); iter
1171-
<generator object at 0x...>
1172-
sage: iter.next() # random
1173-
(x + 3*t^2 + 4*t) * (x + 2*t^2) * (x + 4*t^2 + 4*t + 2)
1174-
sage: iter.next() # random
1175-
(x + 3*t^2 + 4*t) * (x + 3*t^2 + 2*t + 2) * (x + 4*t^2 + t + 2)
1176-
1177-
We can use this function to build the list of factorizations
1178-
of `a`::
1179-
1180-
sage: factorisations = [ F for F in a.factorisations() ]
1181-
1182-
We do some checks::
1183-
1184-
sage: len(factorisations) == a.count_factorisations()
1185-
True
1186-
sage: len(factorisations) == len(Set(factorisations)) # check no duplicates
1187-
True
1188-
sage: for F in factorisations:
1189-
... if F.value() != a:
1190-
... print "Found %s which is not a correct factorization" % d
1191-
... continue
1192-
... for d,_ in F:
1193-
... if not d.is_irreducible():
1194-
... print "Found %s which is not a correct factorization" % d
1195-
"""
1196-
return self.factorizations()

0 commit comments

Comments
 (0)