Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Implementation of :class:`Ring` class. """
from __future__ import print_function, division
from sympy.polys.domains.domain import Domain from sympy.polys.polyerrors import ExactQuotientFailed, NotInvertible, NotReversible
from sympy.utilities import public
@public class Ring(Domain): """Represents a ring domain. """
has_Ring = True
def get_ring(self): """Returns a ring associated with ``self``. """
def exquo(self, a, b): """Exact quotient of ``a`` and ``b``, implies ``__floordiv__``. """ raise ExactQuotientFailed(a, b, self) else:
def quo(self, a, b): """Quotient of ``a`` and ``b``, implies ``__floordiv__``. """
def rem(self, a, b): """Remainder of ``a`` and ``b``, implies ``__mod__``. """ return a % b
def div(self, a, b): """Division of ``a`` and ``b``, implies ``__divmod__``. """ return divmod(a, b)
def invert(self, a, b): """Returns inversion of ``a mod b``. """
else: raise NotInvertible("zero divisor")
def revert(self, a): """Returns ``a**(-1)`` if possible. """ if self.is_one(a): return a else: raise NotReversible('only unity is reversible in a ring')
def is_unit(self, a): try: self.revert(a) return True except NotReversible: return False
def numer(self, a): """Returns numerator of ``a``. """ return a
def denom(self, a): """Returns denominator of `a`. """ return self.one
def free_module(self, rank): """ Generate a free module of rank ``rank`` over self.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).free_module(2) QQ[x]**2 """ raise NotImplementedError
def ideal(self, *gens): """ Generate an ideal of ``self``.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).ideal(x**2) <x**2> """ from sympy.polys.agca.ideals import ModuleImplementedIdeal return ModuleImplementedIdeal(self, self.free_module(1).submodule( *[[x] for x in gens]))
def quotient_ring(self, e): """ Form a quotient ring of ``self``.
Here ``e`` can be an ideal or an iterable.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).quotient_ring(QQ.old_poly_ring(x).ideal(x**2)) QQ[x]/<x**2> >>> QQ.old_poly_ring(x).quotient_ring([x**2]) QQ[x]/<x**2>
The division operator has been overloaded for this:
>>> QQ.old_poly_ring(x)/[x**2] QQ[x]/<x**2> """ from sympy.polys.agca.ideals import Ideal from sympy.polys.domains.quotientring import QuotientRing if not isinstance(e, Ideal): e = self.ideal(*e) return QuotientRing(self, e)
def __div__(self, e): return self.quotient_ring(e)
__truediv__ = __div__ |