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

Commit

Permalink
Fix some doctests, work on comparison functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Sinclair committed Jul 21, 2017
1 parent 275bc9d commit 93f4fe8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
17 changes: 16 additions & 1 deletion src/sage/rings/polynomial/padics/omtree/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -273,7 +288,7 @@ def root(self):
technically be a forest.
.. SEEALSO::
:meth:`omtree.OMTree.roots`
EXAMPLES:
Expand Down
14 changes: 7 additions & 7 deletions src/sage/rings/polynomial/padics/omtree/frameelt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.<x> = ZpFM(2, 20, 'terse')
sage: R.<x> = ZpFM(2, 20, 'terse')[]
sage: f = Frame(x^32 + 16); f.seed(x)
sage: fe = FrameElt(f, 20)
sage: fe == fe
Expand All @@ -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.<x> = ZpFM(2, 20, 'terse')
sage: R.<x> = ZpFM(2, 20, 'terse')[]
sage: f = Frame(x^32 + 16); f.seed(x)
sage: fe = FrameElt(f, 20)
sage: fe != fe
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/padics/omtree/omtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/padics/omtree/residual_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __eq__(self, other):
sage: R.<x> = 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
Expand All @@ -180,7 +180,7 @@ def __ne__(self, other):
sage: R.<x> = 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)
Expand Down
53 changes: 33 additions & 20 deletions src/sage/rings/polynomial/padics/omtree/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.<x> = 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):
"""
Expand Down Expand Up @@ -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.<x> = 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.<x> = 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)

0 comments on commit 93f4fe8

Please sign in to comment.