Skip to content
This repository was archived by the owner on Mar 6, 2018. It is now read-only.

Commit 1912ed5

Browse files
committed
Minor speedup by more agressive caching
Not sure if this is really worth the little change it makes
1 parent 2414d0d commit 1912ed5

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

developing_valuation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _quo_rem_monomial(self, degree):
200200
f = self.domain().one() << degree
201201
return f.quo_rem(self.phi())
202202

203-
def newton_polygon(self, f):
203+
def newton_polygon(self, f, valuations=None):
204204
r"""
205205
Return the newton polygon the `\phi`-adic development of ``f``.
206206
@@ -228,7 +228,9 @@ def newton_polygon(self, f):
228228
f = self.domain().coerce(f)
229229

230230
from sage.geometry.newton_polygon import NewtonPolygon
231-
return NewtonPolygon(enumerate(self.valuations(f)))
231+
if valuations is None:
232+
valuations = self.valuations(f)
233+
return NewtonPolygon(enumerate(valuations))
232234

233235
def _call_(self, f):
234236
r"""

inductive_valuation.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def augmentation(self, phi, mu, check=True):
651651
from augmented_valuation import AugmentedValuation
652652
return AugmentedValuation(self, phi, mu, check)
653653

654-
def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducible=False, report_degree_bounds=False):
654+
def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducible=False, report_degree_bounds_and_caches=False, coefficients=None, valuations=None):
655655
r"""
656656
Perform an approximation step towards the squarefree monic non-constant
657657
integral polynomial ``G`` which is not an :meth:`equivalence_unit`.
@@ -686,8 +686,10 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
686686
if not G.is_monic():
687687
raise ValueError("G must be monic")
688688

689-
coefficients = list(self.coefficients(G))
690-
valuations = list(self.valuations(G, coefficients=coefficients))
689+
if coefficients is None:
690+
coefficients = list(self.coefficients(G))
691+
if valuations is None:
692+
valuations = list(self.valuations(G, coefficients=coefficients))
691693

692694
if min(valuations) < 0:
693695
raise ValueError("G must be integral")
@@ -707,7 +709,7 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
707709
assert len(F), "%s equivalence-decomposes as an equivalence-unit %s"%(G, F)
708710
if len(F) == 1 and F[0][1] == 1 and F[0][0].degree() == G.degree():
709711
assert self.is_key(G, assume_equivalence_irreducible=assume_equivalence_irreducible)
710-
ret.append((self.augmentation(G, infinity, check=False), G.degree()))
712+
ret.append((self.augmentation(G, infinity, check=False), G.degree(), None, None))
711713
else:
712714
for phi,e in F:
713715
if G == phi:
@@ -720,7 +722,7 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
720722
prec = min([c.precision_absolute() for c in phi.list()])
721723
g = G.map_coefficients(lambda c:c.add_bigoh(prec))
722724
assert self.is_key(g)
723-
ret.append((self.augmentation(g, infinity, check=False), g.degree()))
725+
ret.append((self.augmentation(g, infinity, check=False), g.degree(), None, None))
724726
assert len(F) == 1
725727
break
726728

@@ -739,7 +741,9 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
739741
verbose("Determining the augmentation for %s"%phi, level=11)
740742
old_mu = self(phi)
741743
w = self.augmentation(phi, old_mu, check=False)
742-
NP = w.newton_polygon(G).principal_part()
744+
w_coefficients = list(w.coefficients(G))
745+
w_valuations = list(w.valuations(G, coefficients=w_coefficients))
746+
NP = w.newton_polygon(G, valuations=w_valuations).principal_part()
743747
verbose("Newton-Polygon for v(phi)=%s : %s"%(self(phi), NP), level=11)
744748
slopes = NP.slopes(repetition=True)
745749
multiplicities = {slope : len([s for s in slopes if s == slope]) for slope in slopes}
@@ -768,13 +772,14 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
768772

769773
phi = G.parent()(phi)
770774
w = self._base_valuation.augmentation(phi, infinity, check=False)
771-
ret.append((w, phi.degree()))
775+
ret.append((w, phi.degree(), None, None))
772776
continue
773777

774778
for i, slope in enumerate(slopes):
775779
slope = slopes[i]
776780
verbose("Slope = %s"%slope, level=12)
777781
new_mu = old_mu - slope
782+
new_valuations = [val - (j*slope if slope is not -infinity else (0 if j == 0 else -infinity)) for j,val in enumerate(w_valuations)]
778783
base = self
779784
if phi.degree() == base.phi().degree():
780785
assert new_mu > self(phi)
@@ -786,11 +791,11 @@ def mac_lane_step(self, G, assume_squarefree=False, assume_equivalence_irreducib
786791
from sage.rings.all import ZZ
787792
assert (phi.degree() / self.phi().degree()) in ZZ
788793
degree_bound = multiplicities[slope] * self.phi().degree()
789-
ret.append((w, degree_bound))
794+
ret.append((w, degree_bound, w_coefficients, new_valuations))
790795

791796
assert ret
792-
if not report_degree_bounds:
793-
ret = [v for v,_ in ret]
797+
if not report_degree_bounds_and_caches:
798+
ret = [v for v,_,_,_ in ret]
794799
return ret
795800

796801
def is_key(self, phi, explain=False, assume_equivalence_irreducible=False):

valuation.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,15 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru
637637
from gauss_valuation import GaussValuation
638638

639639
# Leaves in the computation of the tree of approximants. Each vertex
640-
# consists of a triple (v,ef,p) where v is an approximant, i.e., a
641-
# valuation, ef is a boolean, and p is the parent of this vertex.
640+
# consists of a tuple (v,ef,p,coeffs,vals) where v is an approximant, i.e., a
641+
# valuation, ef is a boolean, p is the parent of this vertex, and
642+
# coeffs and vals are cached values. (Only v and ef are relevant,
643+
# everything else are caches/debug info.)
642644
# The boolean ef denotes whether v already has the final ramification
643645
# index E and residue degree F of this approximant.
644646
# An edge V -- P represents the relation P.v ≤ V.v (pointwise on the
645647
# polynomial ring K[x]) between the valuations.
646-
leaves = [ (GaussValuation(R, self), G.degree() == 1, None) ]
648+
leaves = [ (GaussValuation(R, self), G.degree() == 1, None, None, None) ]
647649

648650
if require_maximal_degree:
649651
# we can only assert maximality of degrees when E and F are final
@@ -660,7 +662,7 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru
660662
pass
661663

662664
def is_sufficient(leaf, others):
663-
valuation, ef, parent = leaf
665+
valuation, ef, _, _, _ = leaf
664666
if valuation.mu() < required_precision:
665667
return False
666668
if require_final_EF and not ef:
@@ -675,21 +677,21 @@ def is_sufficient(leaf, others):
675677
while True:
676678
new_leaves = []
677679
for leaf in leaves:
678-
v, ef, parent = leaf
679-
others = [w for (w,_,_) in leaves if w != v]
680-
if is_sufficient((v,ef,parent), others):
680+
v, ef, coefficients, valuations, parent = leaf
681+
others = [w for (w,_,_,_,_) in leaves if w != v]
682+
if is_sufficient(leaf, others):
681683
new_leaves.append(leaf)
682684
else:
683-
augmentations = v.mac_lane_step(G, report_degree_bounds=True)
684-
for w, bound in augmentations:
685+
augmentations = v.mac_lane_step(G, report_degree_bounds_and_caches=True, coefficients=coefficients, valuations=valuations)
686+
for w, bound, coefficients, valuations in augmentations:
685687
ef = bound == w.E()*w.F()
686-
new_leaves.append((w, ef, leaf))
688+
new_leaves.append((w, ef, coefficients, valuations, leaf))
687689

688690
if leaves == new_leaves:
689691
break
690692
leaves = new_leaves
691693

692-
return [v for v,_,_ in leaves]
694+
return [v for v,_,_,_,_ in leaves]
693695

694696
def mac_lane_approximant(self, G, valuation, approximants = None):
695697
r"""

0 commit comments

Comments
 (0)