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
"""Computations with ideals of polynomial rings."""
""" Abstract base class for ideals.
Do not instantiate - use explicit constructors in the ring class instead:
>>> from sympy import QQ >>> from sympy.abc import x >>> QQ.old_poly_ring(x).ideal(x+1) <x + 1>
Attributes
- ring - the ring this ideal belongs to
Non-implemented methods:
- _contains_elem - _contains_ideal - _quotient - _intersect - _union - _product - is_whole_ring - is_zero - is_prime, is_maximal, is_primary, is_radical - is_principal - height, depth - radical
Methods that likely should be overridden in subclasses:
- reduce_element """
"""Implementation of element containment.""" raise NotImplementedError
"""Implementation of ideal containment.""" raise NotImplementedError
"""Implementation of ideal quotient.""" raise NotImplementedError
"""Implementation of ideal intersection.""" raise NotImplementedError
"""Return True if ``self`` is the whole ring.""" raise NotImplementedError
"""Return True if ``self`` is the zero ideal.""" raise NotImplementedError
"""Implementation of ideal equality.""" return self._contains_ideal(J) and J._contains_ideal(self)
"""Return True if ``self`` is a prime ideal.""" raise NotImplementedError
"""Return True if ``self`` is a maximal ideal.""" raise NotImplementedError
"""Return True if ``self`` is a radical ideal.""" raise NotImplementedError
"""Return True if ``self`` is a primary ideal.""" raise NotImplementedError
"""Return True if ``self`` is a principal ideal.""" raise NotImplementedError
"""Compute the radical of ``self``.""" raise NotImplementedError
"""Compute the depth of ``self``.""" raise NotImplementedError
"""Compute the height of ``self``.""" raise NotImplementedError
# TODO more
# non-implemented methods end here
self.ring = ring
"""Helper to check ``J`` is an ideal of our ring.""" if not isinstance(J, Ideal) or J.ring != self.ring: raise ValueError( 'J must be an ideal of %s, got %s' % (self.ring, J))
""" Return True if ``elem`` is an element of this ideal.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).ideal(x+1, x-1).contains(3) True >>> QQ.old_poly_ring(x).ideal(x**2, x**3).contains(x) False """ return self._contains_elem(self.ring.convert(elem))
""" Returns True if ``other`` is is a subset of ``self``.
Here ``other`` may be an ideal.
>>> from sympy.abc import x >>> from sympy import QQ >>> I = QQ.old_poly_ring(x).ideal(x+1) >>> I.subset([x**2 - 1, x**2 + 2*x + 1]) True >>> I.subset([x**2 + 1, x + 1]) False >>> I.subset(QQ.old_poly_ring(x).ideal(x**2 - 1)) True """ if isinstance(other, Ideal): return self._contains_ideal(other) return all(self._contains_elem(x) for x in other)
r""" Compute the ideal quotient of ``self`` by ``J``.
That is, if ``self`` is the ideal `I`, compute the set `I : J = \{x \in R | xJ \subset I \}`.
>>> from sympy.abc import x, y >>> from sympy import QQ >>> R = QQ.old_poly_ring(x, y) >>> R.ideal(x*y).quotient(R.ideal(x)) <y> """ self._check_ideal(J) return self._quotient(J, **opts)
""" Compute the intersection of self with ideal J.
>>> from sympy.abc import x, y >>> from sympy import QQ >>> R = QQ.old_poly_ring(x, y) >>> R.ideal(x).intersect(R.ideal(y)) <x*y> """ self._check_ideal(J) return self._intersect(J)
r""" Compute the ideal saturation of ``self`` by ``J``.
That is, if ``self`` is the ideal `I`, compute the set `I : J^\infty = \{x \in R | xJ^n \subset I \text{ for some } n\}`. """ raise NotImplementedError # Note this can be implemented using repeated quotient
""" Compute the ideal generated by the union of ``self`` and ``J``.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).ideal(x**2 - 1).union(QQ.old_poly_ring(x).ideal((x+1)**2)) == QQ.old_poly_ring(x).ideal(x+1) True """ self._check_ideal(J) return self._union(J)
""" Compute the ideal product of ``self`` and ``J``.
That is, compute the ideal generated by products `xy`, for `x` an element of ``self`` and `y \in J`.
>>> from sympy.abc import x, y >>> from sympy import QQ >>> QQ.old_poly_ring(x, y).ideal(x).product(QQ.old_poly_ring(x, y).ideal(y)) <x*y> """ self._check_ideal(J) return self._product(J)
""" Reduce the element ``x`` of our ring modulo the ideal ``self``.
Here "reduce" has no specific meaning: it could return a unique normal form, simplify the expression a bit, or just do nothing. """ return x
if not isinstance(e, Ideal): R = self.ring.quotient_ring(self) if isinstance(e, R.dtype): return e if isinstance(e, R.ring.dtype): return R(e) return R.convert(e) self._check_ideal(e) return self.union(e)
if not isinstance(e, Ideal): try: e = self.ring.ideal(e) except CoercionFailed: return NotImplemented self._check_ideal(e) return self.product(e)
if exp < 0: raise NotImplementedError # TODO exponentiate by squaring return reduce(lambda x, y: x*y, [self]*exp, self.ring.ideal(1))
if not isinstance(e, Ideal) or e.ring != self.ring: return False return self._equals(e)
return not (self == e)
""" Ideal implementation relying on the modules code.
Attributes:
- _module - the underlying module """
Ideal.__init__(self, ring) self._module = module
return self._module.contains([x])
if not isinstance(J, ModuleImplementedIdeal): raise NotImplementedError return self._module.is_submodule(J._module)
if not isinstance(J, ModuleImplementedIdeal): raise NotImplementedError return self.__class__(self.ring, self._module.intersect(J._module))
if not isinstance(J, ModuleImplementedIdeal): raise NotImplementedError return self._module.module_quotient(J._module, **opts)
if not isinstance(J, ModuleImplementedIdeal): raise NotImplementedError return self.__class__(self.ring, self._module.union(J._module))
def gens(self): """ Return generators for ``self``.
>>> from sympy import QQ >>> from sympy.abc import x, y >>> list(QQ.old_poly_ring(x, y).ideal(x, y, x**2 + y).gens) [x, y, x**2 + y] """ return (x[0] for x in self._module.gens)
""" Return True if ``self`` is the zero ideal.
>>> from sympy.abc import x >>> from sympy import QQ >>> QQ.old_poly_ring(x).ideal(x).is_zero() False >>> QQ.old_poly_ring(x).ideal().is_zero() True """ return self._module.is_zero()
""" Return True if ``self`` is the whole ring, i.e. one generator is a unit.
>>> from sympy.abc import x >>> from sympy import QQ, ilex >>> QQ.old_poly_ring(x).ideal(x).is_whole_ring() False >>> QQ.old_poly_ring(x).ideal(3).is_whole_ring() True >>> QQ.old_poly_ring(x, order=ilex).ideal(2 + x).is_whole_ring() True """ return self._module.is_full_module()
from sympy import sstr return '<' + ','.join(sstr(x) for [x] in self._module.gens) + '>'
# NOTE this is the only method using the fact that the module is a SubModule if not isinstance(J, ModuleImplementedIdeal): raise NotImplementedError return self.__class__(self.ring, self._module.submodule( *[[x*y] for [x] in self._module.gens for [y] in J._module.gens]))
""" Express ``e`` in terms of the generators of ``self``.
>>> from sympy.abc import x >>> from sympy import QQ >>> I = QQ.old_poly_ring(x).ideal(x**2 + 1, x) >>> I.in_terms_of_generators(1) [1, -x] """ return self._module.in_terms_of_generators([e])
return self._module.reduce_element([x], **options)[0] |