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

Commit

Permalink
Added new base classes for p-adic polynomial elements
Browse files Browse the repository at this point in the history
This should make it easier to add methods to all padic polynomials in the future.
  • Loading branch information
saraedum committed Sep 12, 2013
1 parent 1456c52 commit 901f953
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 153 deletions.
6 changes: 3 additions & 3 deletions src/sage/misc/classgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def class_graph(top, depth=5, name_filter=None, classes=None, as_graph = True):
sage: from sage.rings.polynomial.padics import polynomial_padic_capped_relative_dense, polynomial_padic_flat
sage: G = class_graph(sage.rings.polynomial.padics); G
Digraph on 4 vertices
Digraph on 8 vertices
sage: G.vertices()
['Polynomial_generic_dense', 'Polynomial_generic_domain', 'Polynomial_padic_capped_relative_dense', 'Polynomial_padic_flat']
['Polynomial_generic_dense', 'Polynomial_generic_dense_field', 'Polynomial_generic_domain', 'Polynomial_padic', 'Polynomial_padic_capped_relative_dense', 'Polynomial_padic_flat', 'Polynomial_padic_generic_field', 'Polynomial_padic_generic_ring']
sage: G.edges(labels=False)
[('Polynomial_padic_capped_relative_dense', 'Polynomial_generic_domain'), ('Polynomial_padic_flat', 'Polynomial_generic_dense')]
[('Polynomial_padic', 'Polynomial_generic_domain'), ('Polynomial_padic_capped_relative_dense', 'Polynomial_padic'), ('Polynomial_padic_flat', 'Polynomial_padic_generic_ring'), ('Polynomial_padic_generic_field', 'Polynomial_generic_dense_field'), ('Polynomial_padic_generic_field', 'Polynomial_padic'), ('Polynomial_padic_generic_ring', 'Polynomial_generic_dense'), ('Polynomial_padic_generic_ring', 'Polynomial_generic_domain'), ('Polynomial_padic_generic_ring', 'Polynomial_padic')]
We construct the inheritance graph of a given class::
Expand Down
57 changes: 57 additions & 0 deletions src/sage/rings/polynomial/padics/polynomial_padic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
r"""
Common base class for all polynomials over `p`-adic rings
AUTHORS:
- Julian Rueth (2013-09-12): initial version
"""
#*****************************************************************************
# Copyright (C) 2013 Julian Rueth <julian.rueth@fsfe.org>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_domain

class Polynomial_padic(Polynomial_generic_domain):
r"""
A polynomial over a `p`-adic ring.
INPUT:
- ``parent`` -- a polynomial ring over a `p`-adic ring
- ``is_gen`` -- whether this is the generator of the polynomial ring
(default: ``False``)
.. NOTE::
In contrast to :class:`polynomial_padic.Polynomial_padic_generic`
(which inherits from this class), this class is meant as a base class
for implementations which provide their own handling of the polynomial
data.
EXAMPLES::
sage: R.<x> = Zp(3)[] # indirect doctest
sage: from sage.rings.polynomial.padics.polynomial_padic import Polynomial_padic
sage: isinstance(x, Polynomial_padic)
True
"""
def __init__(self, parent, is_gen=False):
r"""
Initialization.
TESTS::
sage: from sage.rings.polynomial.padics.polynomial_padic import Polynomial_padic
sage: R.<x> = Zp(3)[]
sage: type(Polynomial_padic(R))
<class 'sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic'>
"""
Polynomial_generic_domain.__init__(self, parent, is_gen=is_gen)
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
r"""
`p`-adic polynomials with capped relative precision
This module provides classes for `p`-adic polynomials over a ring with capped
relative precision.
AUTHORS:
- David Roe (2007): initial version
- Julian Rueth (2013- 09-12): added some docstrings and cleanup of the inheritance
"""
p-adic Capped Relative Dense Polynomials
"""
#*****************************************************************************
# Copyright (C) 2007-2008 David Roe <roed.math@gmail.com>
# 2012-2013 Julian Rueth <julian.rueth@fsfe.org>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************

import sage.rings.polynomial.polynomial_element_generic
from sage.rings.polynomial.polynomial_element import Polynomial
Expand All @@ -16,17 +35,53 @@
from sage.libs.ntl.all import ZZX
from sage.structure.factorization import Factorization
from sage.rings.infinity import infinity
from polynomial_padic_generic import Polynomial_padic

min = misc.min
ZZ = sage.rings.integer_ring.ZZ
PrecisionError = precision_error.PrecisionError
Integer = sage.rings.integer.Integer
Polynomial_generic_domain = sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_domain
Polynomial_integer_dense = sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl

class Polynomial_padic_capped_relative_dense(Polynomial_generic_domain):
class Polynomial_padic_capped_relative_dense(Polynomial_padic):
r"""
A polynomial over a `p`-adic base ring with capped relative precision.
Every coefficient of this polynomial can have its own relative precision,
however, the class keeps track of the precision data of the coefficients.
INPUT:
- ``parent`` -- a polynomial ring over a `p`-adic ring
- ``x`` -- data to construct a polynomial (default: ``None``)
- ``check`` -- a boolean (default: ``True``), whether to make sure that all
coefficients are in the `p`-adic base ring
- ``is_gen`` -- a boolean (default: ``False``), whether this is the
generator of the polynomial ring
- ``construct`` -- a boolean (default: ``False``), used internally, if
``True``, then ``x`` contains the attributes of a polynomial
- ``absprec`` -- an integer or ``infinity`` (default: ``infinity``), every
coefficient is capped to this absolute precision
- ``absprec`` -- an integer or ``infinity`` (default: ``infinity``), every
coefficient is capped to this relative precision
EXAMPLES::
sage: from sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense import Polynomial_padic_capped_relative_dense
sage: R.<x> = Qp(3)[] # indirect doctest
sage: isinstance(x, Polynomial_padic_capped_relative_dense)
True
"""
def __init__(self, parent, x=None, check=True, is_gen=False, construct = False, absprec = infinity, relprec = infinity):
"""
Initialization.
TESTS::
sage: K = Qp(13,7)
Expand All @@ -37,7 +92,7 @@ def __init__(self, parent, x=None, check=True, is_gen=False, construct = False,
sage: R(t + 2)
(1 + O(13^7))*t + (2 + O(13^7))
"""
Polynomial.__init__(self, parent, is_gen=is_gen)
Polynomial_padic.__init__(self, parent, is_gen=is_gen)
parentbr = parent.base_ring()
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
if construct:
Expand Down
71 changes: 64 additions & 7 deletions src/sage/rings/polynomial/padics/polynomial_padic_flat.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,82 @@
r"""
`p`-adic polynomials with a flat precision
This module provides classes for `p`-adic polynomials with a flat precision,
i.e., the absolute precision is the same for all coefficients of the
polynomial.
AUTHORS:
- Julian Rueth (2013- 09-12): added some docstrings and cleanup of the inheritance
"""
from sage.rings.integer import Integer
from sage.rings.polynomial.polynomial_element import Polynomial_generic_dense, Polynomial
from sage.rings.infinity import infinity
from sage.libs.all import pari_gen
from sage.structure.factorization import Factorization
from polynomial_padic_generic import Polynomial_padic_generic_ring
import sage.rings.padics.misc
#*****************************************************************************
# Copyright (C) 2008 David Roe <roed.math@gmail.com>
# 2008 John Cremona <john.cremona@gmail.com>
# 2013 Julian Rueth <julian.rueth@fsfe.org>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************

class Polynomial_padic_flat(Polynomial_padic_generic_ring):
r"""
A polynomial with a flat precision over a `p`-adic base ring.
INPUT:
- ``parent`` -- a polynomial ring over a `p`-adic ring
- ``x`` -- data to construct a polynomial (default: ``None``)
- ``check`` -- a boolean (default: ``True``), whether to make sure that all
coefficients are in the `p`-adic base ring
class Polynomial_padic_flat(Polynomial_generic_dense):
- ``is_gen`` -- a boolean (default: ``False``), whether this is the
generator of the polynomial ring
- ``construct`` -- a boolean (default: ``False``), unused
- ``absprec`` -- an integer or ``None`` (default: ``None``), if given,
every coefficient is capped to this precision
EXAMPLES::
sage: from sage.rings.polynomial.padics.polynomial_padic_flat import Polynomial_padic_flat
sage: R.<x> = ZpFM(3)[] # indirect doctest
sage: isinstance(x, Polynomial_padic_flat)
True
"""
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, absprec=None):
"""
Initialization function for the class Polynomial_padic_flat.
"""
Initialization.
TESTS::
sage: R.<x> = ZpFM(3)[]
sage: type(x)
<class 'sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat'>
"""
if x is None:
Polynomial_generic_dense.__init__(self, parent, x = None, is_gen = is_gen)
Polynomial_padic_generic_ring.__init__(self, parent, x = None, is_gen = is_gen)
return
R = parent.base_ring()
if sage.rings.fraction_field_element.is_FractionFieldElement(x):
if x.denominator() != 1:
raise TypeError, "denominator must be 1"
else:
x = x.numerator()
from sage.rings.polynomial.polynomial_element import Polynomial
if isinstance(x, Polynomial):
if x.base_ring() is R:
x = list(x.list())
Expand All @@ -42,7 +99,7 @@ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, ab
m = sage.rings.padics.misc.min(a.precision_absolute() for a in x.values())
if not absprec is None:
m = min(m, absprec)
Polynomial_generic_dense.__init__(self, parent, x, absprec = m)
Polynomial_generic_dense_ring.__init__(self, parent, x, absprec = m)
return
elif isinstance(x, pari_gen):
x = [R(w) for w in x.list()]
Expand All @@ -51,7 +108,7 @@ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, ab
if absprec is None:
absprec = infinity
m = min([a.precision_absolute() for a in x] + [absprec])
Polynomial_generic_dense.__init__(self, parent, x, absprec = m)
Polynomial_padic_generic_ring.__init__(self, parent, x)

def _mul_(self, right):
"""
Expand Down
122 changes: 122 additions & 0 deletions src/sage/rings/polynomial/padics/polynomial_padic_generic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
r"""
Common implementation for polynomials over `p`-adic rings
AUTHORS:
- Julian Rueth (2013-09-12): initial version
"""
#*****************************************************************************
# Copyright (C) 2013 Julian Rueth <julian.rueth@fsfe.org>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from sage.rings.polynomial.polynomial_element import Polynomial_generic_dense
from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_dense_field, Polynomial_generic_domain
from polynomial_padic import Polynomial_padic

class Polynomial_padic_generic_ring(Polynomial_padic, Polynomial_generic_domain, Polynomial_generic_dense):
r"""
A polynomial over a `p`-adic ring which is not a field.
INPUT:
- ``parent`` -- a polynomial ring over a `p`-adic ring
- ``x`` -- data which can be used to construct a polynomial
- ``check`` -- a boolean (default: ``True``), unused
- ``is_gen`` -- whether this is the generator of the polynomial ring
(default: ``False``)
- ``construct`` -- a boolean (default: ``False``), unused
- ``absprec`` -- an integer or ``None`` (default: ``None``), unused
.. NOTE::
In contrast to :class:`polynomial_padic.Polynomial_padic`, this class
is meant as a base class for implementations which want to use the
generic handling of the polynomial data from
:class:`sage.rings.polynomial.polynomial_element.Polynomial_generic_dense`.
EXAMPLES::
sage: R.<x> = ZpFM(3)[] # indirect doctest
sage: from sage.rings.polynomial.padics.polynomial_padic_generic import Polynomial_padic_generic_ring
sage: isinstance(x, Polynomial_padic_generic_ring)
True
"""
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, absprec=None):
r"""
Initialization.
TESTS::
sage: from sage.rings.polynomial.padics.polynomial_padic_generic import Polynomial_padic_generic_ring
sage: R.<x> = ZpFM(3)[]
sage: type(Polynomial_padic_generic_ring(R, None))
<class 'sage.rings.polynomial.padics.polynomial_padic_generic.Polynomial_padic_generic_ring'>
"""
Polynomial_padic.__init__(self, parent, is_gen=is_gen)
Polynomial_generic_domain.__init__(self, parent, is_gen=is_gen)
Polynomial_generic_dense.__init__(self, parent, x)

class Polynomial_padic_generic_field(Polynomial_padic, Polynomial_generic_dense_field):
r"""
A polynomial over a `p`-adic field.
INPUT:
- ``parent`` -- a polynomial ring over a `p`-adic ring
- ``x`` -- data which can be used to construct a polynomial
- ``check`` -- a boolean (default: ``True``), unused
- ``is_gen`` -- whether this is the generator of the polynomial ring
(default: ``False``)
- ``construct`` -- a boolean (default: ``False``), unused
- ``absprec`` -- an integer or ``None`` (default: ``None``), unused
.. NOTE::
In contrast to :class:`polynomial_padic.Polynomial_padic`, this class
is meant as a base class for implementations which want to use the
generic handling of the polynomial data from
:class:`sage.rings.polynomial.polynomial_element.Polynomial_generic_dense`.
EXAMPLES::
sage: R.<a> = Qp(3)[]
sage: L.<a> = Qp(3).extension(a^2 - 3)
sage: R.<x> = L[] # indirect doctest
sage: from sage.rings.polynomial.padics.polynomial_padic_generic import Polynomial_padic_generic_field
sage: isinstance(x, Polynomial_padic_generic_field)
True
"""
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, absprec=None):
r"""
Initialization.
TESTS::
sage: from sage.rings.polynomial.padics.polynomial_padic_generic import Polynomial_padic_generic_field
sage: R.<a> = Qp(3)[]
sage: L.<a> = Qp(3).extension(a^2 - 3)
sage: R.<x> = L[]
sage: type(Polynomial_padic_generic_field(R, None))
<class 'sage.rings.polynomial.padics.polynomial_padic_generic.Polynomial_padic_generic_field'>
"""
Polynomial_padic.__init__(self, parent, is_gen=is_gen)
Polynomial_generic_dense_field.__init__(self, parent, x)
Loading

0 comments on commit 901f953

Please sign in to comment.