ó
¡¼™\c           @  sl   d  Z  d d l m Z m Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 d	 S(
   s-   Computations with ideals of polynomial rings.iÿÿÿÿ(   t   print_functiont   division(   t   reduce(   t   CoercionFailedt   Idealc           B  s(  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z e Z d „  Z  d „  Z! d „  Z" RS(   sŠ  
    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
    c         C  s
   t  ‚ d S(   s&   Implementation of element containment.N(   t   NotImplementedError(   t   selft   x(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   _contains_elem,   s    c         C  s
   t  ‚ d S(   s$   Implementation of ideal containment.N(   R   (   R   t   I(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   _contains_ideal0   s    c         C  s
   t  ‚ d S(   s!   Implementation of ideal quotient.N(   R   (   R   t   J(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt	   _quotient4   s    c         C  s
   t  ‚ d S(   s%   Implementation of ideal intersection.N(   R   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt
   _intersect8   s    c         C  s
   t  ‚ d S(   s*   Return True if ``self`` is the whole ring.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   is_whole_ring<   s    c         C  s
   t  ‚ d S(   s*   Return True if ``self`` is the zero ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   is_zero@   s    c         C  s   |  j  | ƒ o | j  |  ƒ S(   s!   Implementation of ideal equality.(   R
   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   _equalsD   s    c         C  s
   t  ‚ d S(   s)   Return True if ``self`` is a prime ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   is_primeH   s    c         C  s
   t  ‚ d S(   s+   Return True if ``self`` is a maximal ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt
   is_maximalL   s    c         C  s
   t  ‚ d S(   s+   Return True if ``self`` is a radical ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt
   is_radicalP   s    c         C  s
   t  ‚ d S(   s+   Return True if ``self`` is a primary ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt
   is_primaryT   s    c         C  s
   t  ‚ d S(   s-   Return True if ``self`` is a principal ideal.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   is_principalX   s    c         C  s
   t  ‚ d S(   s    Compute the radical of ``self``.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   radical\   s    c         C  s
   t  ‚ d S(   s   Compute the depth of ``self``.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   depth`   s    c         C  s
   t  ‚ d S(   s   Compute the height of ``self``.N(   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   heightd   s    c         C  s   | |  _  d  S(   N(   t   ring(   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __init__l   s    c         C  sB   t  | t ƒ s" | j |  j k r> t d |  j | f ƒ ‚ n  d S(   s.   Helper to check ``J`` is an ideal of our ring.s    J must be an ideal of %s, got %sN(   t
   isinstanceR   R   t
   ValueError(   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   _check_idealo   s    "c         C  s   |  j  |  j j | ƒ ƒ S(   sD  
        Return True if ``elem`` is an element of this ideal.

        Examples
        ========

        >>> 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
        (   R   R   t   convert(   R   t   elem(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   containsu   s    c           s6   t  | t ƒ r ˆ  j | ƒ St ‡  f d †  | Dƒ ƒ S(   sÃ  
        Returns True if ``other`` is is a subset of ``self``.

        Here ``other`` may be an ideal.

        Examples
        ========

        >>> 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
        c         3  s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R   (   t   .0R   (   R   (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pys	   <genexpr>š   s    (   R   R   R
   t   all(   R   t   other(    (   R   s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   subset…   s    c         K  s   |  j  | ƒ |  j | |  S(   s~  
        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 \}`.

        Examples
        ========

        >>> 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>
        (   R   R   (   R   R   t   opts(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   quotientœ   s    c         C  s   |  j  | ƒ |  j | ƒ S(   s  
        Compute the intersection of self with ideal J.

        Examples
        ========

        >>> 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>
        (   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt	   intersect¯   s    c         C  s
   t  ‚ d S(   sÏ   
        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\}`.
        N(   R   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   saturate¿   s    c         C  s   |  j  | ƒ |  j | ƒ S(   sD  
        Compute the ideal generated by the union of ``self`` and ``J``.

        Examples
        ========

        >>> 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
        (   R   t   _union(   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   unionÉ   s    c         C  s   |  j  | ƒ |  j | ƒ S(   s‡  
        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`.

        Examples
        ========

        >>> 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>
        (   R   t   _product(   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   productØ   s    c         C  s   | S(   sâ   
        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.
        (    (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   reduce_elementê   s    c         C  s}   t  | t ƒ sc |  j j |  ƒ } t  | | j ƒ r7 | St  | | j j ƒ rV | | ƒ S| j | ƒ S|  j | ƒ |  j | ƒ S(   N(   R   R   R   t   quotient_ringt   dtypeR   R   R*   (   R   t   et   R(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __add__ó   s    
c         C  sW   t  | t ƒ s= y |  j j | ƒ } Wq= t k
 r9 t SXn  |  j | ƒ |  j | ƒ S(   N(   R   R   R   t   idealR   t   NotImplementedR   R,   (   R   R0   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __mul__   s    c         C  s;   | d k  r t  ‚ n  t d „  |  g | |  j j d ƒ ƒ S(   Ni    c         S  s   |  | S(   N(    (   R   t   y(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   <lambda>  t    i   (   R   R   R   R3   (   R   t   exp(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __pow__  s    	c         C  s3   t  | t ƒ s" | j |  j k r& t S|  j | ƒ S(   N(   R   R   R   t   FalseR   (   R   R0   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __eq__  s    "c         C  s   |  | k S(   N(    (   R   R0   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __ne__  s    (#   t   __name__t
   __module__t   __doc__R   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R$   R&   R'   R(   R*   R,   R-   R2   t   __radd__R5   t   __rmul__R:   R<   R=   (    (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   	   sB   !																						
									t   ModuleImplementedIdealc           B  s‰   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 d „  ƒ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   ss   
    Ideal implementation relying on the modules code.

    Attributes:

    - _module - the underlying module
    c         C  s   t  j |  | ƒ | |  _ d  S(   N(   R   R   t   _module(   R   R   t   module(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   #  s    c         C  s   |  j  j | g ƒ S(   N(   RD   R    (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   '  s    c         C  s+   t  | t ƒ s t ‚ n  |  j j | j ƒ S(   N(   R   RC   R   RD   t   is_submodule(   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR
   *  s    	c         C  s:   t  | t ƒ s t ‚ n  |  j |  j |  j j | j ƒ ƒ S(   N(   R   RC   R   t	   __class__R   RD   R'   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   /  s    	c         K  s.   t  | t ƒ s t ‚ n  |  j j | j |  S(   N(   R   RC   R   RD   t   module_quotient(   R   R   R%   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   4  s    	c         C  s:   t  | t ƒ s t ‚ n  |  j |  j |  j j | j ƒ ƒ S(   N(   R   RC   R   RG   R   RD   R*   (   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR)   9  s    	c         C  s   d „  |  j  j Dƒ S(   sú   
        Return generators for ``self``.

        Examples
        ========

        >>> 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]
        c         s  s   |  ] } | d  Vq d S(   i    N(    (   R!   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pys	   <genexpr>K  s    (   RD   t   gens(   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyRI   >  s    c         C  s   |  j  j ƒ  S(   s%  
        Return True if ``self`` is the zero ideal.

        Examples
        ========

        >>> 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
        (   RD   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   M  s    c         C  s   |  j  j ƒ  S(   s¬  
        Return True if ``self`` is the whole ring, i.e. one generator is a unit.

        Examples
        ========

        >>> 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
        (   RD   t   is_full_module(   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR   ]  s    c           s;   d d l  m ‰  d d j ‡  f d †  |  j j Dƒ ƒ d S(   Niÿÿÿÿ(   t   sstrt   <t   ,c         3  s   |  ] \ } ˆ  | ƒ Vq d  S(   N(    (   R!   R   (   RK   (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pys	   <genexpr>q  s    t   >(   t   sympyRK   t   joinRD   RI   (   R   (    (   RK   s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   __repr__o  s    c         C  sp   t  | t ƒ s t ‚ n  |  j |  j |  j j g  |  j j D], \ } | j j D] \ } | | g ^ qM q: Œ  ƒ S(   N(   R   RC   R   RG   R   RD   t	   submoduleRI   (   R   R   R   R6   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR+   t  s    	c         C  s   |  j  j | g ƒ S(   s  
        Express ``e`` in terms of the generators of ``self``.

        Examples
        ========

        >>> 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]
        (   RD   t   in_terms_of_generators(   R   R0   (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyRS   z  s    c         K  s   |  j  j | g |  d S(   Ni    (   RD   R-   (   R   R   t   options(    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyR-   ‰  s    (   R>   R?   R@   R   R   R
   R   R   R)   t   propertyRI   R   R   RQ   R+   RS   R-   (    (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyRC     s   											N(   R@   t
   __future__R    R   t   sympy.core.compatibilityR   t   sympy.polys.polyerrorsR   t   objectR   RC   (    (    (    s6   lib/python2.7/site-packages/sympy/polys/agca/ideals.pyt   <module>   s   ÿ 