From 93f4fe8da590d743242ad4f2f92fb4a7801f4c36 Mon Sep 17 00:00:00 2001 From: Brian Sinclair Date: Fri, 21 Jul 2017 17:00:54 +0000 Subject: [PATCH] Fix some doctests, work on comparison functions --- .../rings/polynomial/padics/omtree/frame.py | 17 +++++- .../polynomial/padics/omtree/frameelt.py | 14 ++--- .../rings/polynomial/padics/omtree/omtree.py | 2 +- .../padics/omtree/residual_factor.py | 4 +- .../rings/polynomial/padics/omtree/segment.py | 53 ++++++++++++------- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/sage/rings/polynomial/padics/omtree/frame.py b/src/sage/rings/polynomial/padics/omtree/frame.py index c0dd91f18a7..b4f804024a3 100644 --- a/src/sage/rings/polynomial/padics/omtree/frame.py +++ b/src/sage/rings/polynomial/padics/omtree/frame.py @@ -150,6 +150,21 @@ def __init__(self, Phi, prev=None, iteration_count=0): self.F = self.prev_frame().F * self.prev.Fplus self.depth = self.prev_frame().depth + 1 + def __eq__(self, other): + """ + Check whether self is equal to other + + EXAMPLES:: + + sage: from sage.rings.polynomial.padics.omtree.frame import * + sage: Phi = ZpFM(2,20,'terse')['x'](x^32+16) + sage: f = Frame(Phi) + sage: g = Frame(Phi, iteration_count=4) + sage: f == g + False + """ + return type(self) == type(other) and self.Phi() == other.Phi() and self.phi == other.phi and self.iteration == other.iteration + def seed(self, phi, length=infinity): r""" Seed all of the intermediate values of the frame based on the new @@ -273,7 +288,7 @@ def root(self): technically be a forest. .. SEEALSO:: - + :meth:`omtree.OMTree.roots` EXAMPLES: diff --git a/src/sage/rings/polynomial/padics/omtree/frameelt.py b/src/sage/rings/polynomial/padics/omtree/frameelt.py index 43e42ef1716..0e3ce25934d 100644 --- a/src/sage/rings/polynomial/padics/omtree/frameelt.py +++ b/src/sage/rings/polynomial/padics/omtree/frameelt.py @@ -73,17 +73,17 @@ class FrameElt(SageObject): TypeError: not a constant polynomial Moving to a higher frame, the approximation `\phi` of the previous frame is - used. Here `6x^2 + 1` is expressed in its `x`-adic expansion as ``[1, - 6*x^2]``:: + used. Here `6x^2 + 1` is expressed in its `x`-adic expansion as ``[1, 6*x^2]``:: - sage: f = f.polygon[0].factors[0].next_frame(); f + sage: fr = f.polygon[0].factors[0].next_frame(); fr Frame with phi (1 + O(2^20))*x^8 + (0 + O(2^20))*x^7 + (0 + O(2^20))*x^6 + (0 + O(2^20))*x^5 + (0 + O(2^20))*x^4 + (0 + O(2^20))*x^3 + (0 + O(2^20))*x^2 + (0 + O(2^20))*x + (1048574 + O(2^20)) - sage: FrameElt(f, 6*x^2 + 1) + sage: fe = FrameElt(fr, 6*x^2 + 1) + sage: fe [[1*2^0]phi1^0, [3*2^1]phi1^2] TESTS:: - sage: isinstance(f, FrameElt) + sage: isinstance(fe, FrameElt) True """ @@ -142,7 +142,7 @@ def __eq__(self, other): sage: from sage.rings.polynomial.padics.omtree.frameelt import FrameElt sage: from sage.rings.polynomial.padics.omtree.frame import Frame - sage: R. = ZpFM(2, 20, 'terse') + sage: R. = ZpFM(2, 20, 'terse')[] sage: f = Frame(x^32 + 16); f.seed(x) sage: fe = FrameElt(f, 20) sage: fe == fe @@ -159,7 +159,7 @@ def __ne__(self, other): sage: from sage.rings.polynomial.padics.omtree.frameelt import FrameElt sage: from sage.rings.polynomial.padics.omtree.frame import Frame - sage: R. = ZpFM(2, 20, 'terse') + sage: R. = ZpFM(2, 20, 'terse')[] sage: f = Frame(x^32 + 16); f.seed(x) sage: fe = FrameElt(f, 20) sage: fe != fe diff --git a/src/sage/rings/polynomial/padics/omtree/omtree.py b/src/sage/rings/polynomial/padics/omtree/omtree.py index 4c75141e5a8..95077cfc92f 100644 --- a/src/sage/rings/polynomial/padics/omtree/omtree.py +++ b/src/sage/rings/polynomial/padics/omtree/omtree.py @@ -192,7 +192,7 @@ def approximations(self): def roots(self): """ - The roots of the trees with the leaves the OMTree. + The roots of the trees whose leaves are in the OMTree. As a note, the leaves for a polynomial's OM Tree may have different roots. Becuase optimal OM Trees remove 'improvement frames' (those for which diff --git a/src/sage/rings/polynomial/padics/omtree/residual_factor.py b/src/sage/rings/polynomial/padics/omtree/residual_factor.py index e0ff9f50c4f..def4e434d41 100644 --- a/src/sage/rings/polynomial/padics/omtree/residual_factor.py +++ b/src/sage/rings/polynomial/padics/omtree/residual_factor.py @@ -165,7 +165,7 @@ def __eq__(self, other): sage: R. = ZpFM(2, 20, 'terse')[] sage: T = OMTree(x^4 + 20*x^3 + 44*x^2 + 80*x + 1040) sage: T.leaves()[0].prev == T.leaves()[0].prev - False + True """ return type(self) == type(other) and self.segment == other.segment and self.rho == other.rho and self.multiplicity == other.multiplicity @@ -180,7 +180,7 @@ def __ne__(self, other): sage: R. = ZpFM(2, 20, 'terse')[] sage: T = OMTree(x^4 + 20*x^3 + 44*x^2 + 80*x + 1040) sage: T.leaves()[0].prev != T.leaves()[0].prev - True + False """ return not (self == other) diff --git a/src/sage/rings/polynomial/padics/omtree/segment.py b/src/sage/rings/polynomial/padics/omtree/segment.py index b7cb861b132..641451da9f5 100644 --- a/src/sage/rings/polynomial/padics/omtree/segment.py +++ b/src/sage/rings/polynomial/padics/omtree/segment.py @@ -6,6 +6,7 @@ - Brian Sinclair (2012-02-22): initial version """ + from sage.rings.polynomial.padics.omtree.residual_factor import ResidualFactor from sage.rings.infinity import infinity from sage.structure.sage_object import SageObject @@ -126,24 +127,6 @@ def __init__(self, frame, slope, verts): self.factors = [ResidualFactor(self, afact[0], afact[1]) for afact in list(self.residual_polynomial().factor())] - def __cmp__(self, other): - """ - Comparison. - - EXAMPLES:: - - sage: from sage.rings.polynomial.padics.omtree.frame import Frame - sage: k = ZpFM(2, 20, 'terse'); kx. = k[] - sage: Phi = x^4 + 20*x^3 + 44*x^2 + 80*x + 1040 - sage: f = Frame(Phi); f.seed(Phi.parent().gen()); P = f.polygon - sage: f = f.polygon[0].factors[0].next_frame(); Q = f.polygon - sage: P == Q - False - """ - c = cmp(type(self), type(other)) - if c: return c - return cmp((self.length, self.verts, self.slope), (other.length, other.verts, other.slope)) - @cached_method def residual_polynomial(self): """ @@ -215,7 +198,37 @@ def __hash__(self): return hash((self.length, self.slope)) def __eq__(self, other): - raise NotImplementedError + r""" + Return whether this is equal to the segment ``other``. + + EXAMPLES:: + + sage: from sage.rings.polynomial.padics.omtree.frame import Frame + sage: k = ZpFM(2, 20, 'terse'); kx. = k[] + sage: Phi = x^4 + 20*x^3 + 44*x^2 + 80*x + 1040 + sage: f1 = Frame(Phi); f1.seed(Phi.parent().gen()) + sage: s1 = f1.polygon[0] # first segment of the polygon of frame f1 + sage: f2 = f1.polygon[0].factors[0].next_frame() + sage: s2 = f2.polygon[0] # first segment of the polygon of frame f2 + sage: s1 == s2 + False + """ + return type(self) is type(other) and self.length == other.length and self.verts == other.verts and self.slope == other.slope def __ne__(self, other): - raise NotImplementedError + r""" + Return whether this is not equal to the segment ``other``. + + EXAMPLES:: + + sage: from sage.rings.polynomial.padics.omtree.frame import Frame + sage: k = ZpFM(2, 20, 'terse'); kx. = k[] + sage: Phi = x^4 + 20*x^3 + 44*x^2 + 80*x + 1040 + sage: f1 = Frame(Phi); f1.seed(Phi.parent().gen()) + sage: s1 = f1.polygon[0] # first segment of the polygon of frame f1 + sage: f2 = f1.polygon[0].factors[0].next_frame() + sage: s2 = f2.polygon[0] # first segment of the polygon of frame f2 + sage: s1 != s2 + True + """ + return not (self == other)