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

Commit

Permalink
Better use of modular exponentiation in Cantor-Zassenhaus + sig_on ma…
Browse files Browse the repository at this point in the history
…gic.
  • Loading branch information
Jean-Pierre Flori committed May 16, 2014
1 parent 630bc0b commit 27ae9b7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1518,13 +1518,15 @@ cdef class Polynomial(CommutativeAlgebraElement):
if degree is None:
x = self.parent().gen()
if allowed_deg_mult == 1:
self = self.gcd(x**q-x)
xq = pow(x,q,self)
self = self.gcd(xq-x)
degree = -1
if self.degree() == 0:
raise ValueError, "no roots B %s"%self
else:
xq = x
d = Integer(0)
sig_on()
while True:
# one pass for roots that actually lie within ring.
e = self.degree()
Expand All @@ -1545,11 +1547,13 @@ cdef class Polynomial(CommutativeAlgebraElement):
break
if d == allowed_deg_mult:
break
sig_off()
if degree is None:
if allowed_deg_mult == 1:
raise ValueError, "no roots C %s"%self
xq = x
d = Integer(0)
sig_on()
while True:
# now another for roots that will lie in an extension.
e = self.degree()
Expand All @@ -1568,17 +1572,20 @@ cdef class Polynomial(CommutativeAlgebraElement):
self = A
degree = -d
break
sig_off()
if degree == 0:
raise ValueError, "degree should be nonzero"
R = self.parent()
x = R.gen()
if degree > 0:
xq = x
d = 0
sig_on()
while True:
e = self.degree()
if 2*d > e:
if degree != e:
sig_off()
raise ValueError, "no roots D %s"%self
break
d = d+1
Expand All @@ -1588,6 +1595,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
A = self.gcd(xq-x)
if A != 1:
self = self // A
sig_off()
if d == degree:
self = self.gcd(xq-x)
if self.degree() == 0:
Expand All @@ -1608,6 +1616,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
except IndexError:
raise ValueError, "no roots F %s"%self
if q % 2 == 0:
sig_on()
while True:
T = R.random_element(2*degree-1)
if T == 0:
Expand All @@ -1620,10 +1629,13 @@ cdef class Polynomial(CommutativeAlgebraElement):
hd = h.degree()
if hd != 0 or hd != self.degree():
if 2*hd <= self.degree():
sig_off()
return h.any_root(ring, -degree, True)
else:
sig_off()
return (self//h).any_root(ring, -degree, True)
else:
sig_on()
while True:
T = R.random_element(2*degree-1)
if T == 0:
Expand All @@ -1633,8 +1645,10 @@ cdef class Polynomial(CommutativeAlgebraElement):
hd = h.degree()
if hd != 0 and hd != self.degree():
if 2*hd <= self.degree():
sig_off()
return h.any_root(ring, -degree, True)
else:
sig_off()
return (self//h).any_root(ring, -degree, True)
else:
return self.roots(ring=ring, multiplicities=False)[0]
Expand Down

0 comments on commit 27ae9b7

Please sign in to comment.