ó
¡¼™\c           @  s˜   d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z e d e f d „  ƒ  Yƒ Z d	 e f d
 „  ƒ  YZ d S(   s.   Implementation of :class:`QuotientRing` class.iÿÿÿÿ(   t   print_functiont   division(   t   FreeModuleQuotientRing(   t   Ring(   t   NotReversiblet   CoercionFailed(   t   publict   QuotientRingElementc           B  s’   e  Z d  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z	 d „  Z
 e
 Z d „  Z e Z d	 „  Z e Z d
 „  Z d „  Z d „  Z RS(   sº   
    Class representing elements of (commutative) quotient rings.

    Attributes:

    - ring - containing ring
    - data - element of ring.ring (i.e. base ring) representing self
    c         C  s   | |  _  | |  _ d  S(   N(   t   ringt   data(   t   selfR   R	   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __init__   s    	c         C  s1   d d l  m } | |  j ƒ d t |  j j ƒ S(   Niÿÿÿÿ(   t   sstrs    + (   t   sympyR   R	   t   strR   t
   base_ideal(   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __str__   s    c         C  sp   t  | |  j ƒ s% | j |  j k rY y |  j j | ƒ } WqY t t f k
 rU t SXn  |  j |  j | j ƒ S(   N(   t
   isinstancet	   __class__R   t   convertt   NotImplementedErrorR   t   NotImplementedR	   (   R
   t   om(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __add__"   s    %c         C  s#   |  j  |  j |  j  j  j d ƒ ƒ S(   Niÿÿÿÿ(   R   R	   R   (   R
   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __neg__,   s    c         C  s   |  j  | ƒ S(   N(   R   (   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __sub__/   s    c         C  s   |  j  | ƒ S(   N(   R   (   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __rsub__2   s    c         C  s]   t  | |  j ƒ sF y |  j j | ƒ } WqF t t f k
 rB t SXn  |  j |  j | j ƒ S(   N(   R   R   R   R   R   R   R   R	   (   R
   t   o(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __mul__5   s    c         C  s   |  j  j |  ƒ | S(   N(   R   t   revert(   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __rdiv__?   s    c         C  sZ   t  | |  j ƒ sF y |  j j | ƒ } WqF t t f k
 rB t SXn  |  j j | ƒ |  S(   N(   R   R   R   R   R   R   R   R   (   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __div__D   s    c         C  s   |  j  |  j | ƒ S(   N(   R   R	   (   R
   t   oth(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __pow__N   s    c         C  s=   t  | |  j ƒ s% | j |  j k r) t S|  j j |  | ƒ S(   N(   R   R   R   t   Falset   is_zero(   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __eq__Q   s    %c         C  s   |  | k S(   N(    (   R
   R   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __ne__V   s    (   t   __name__t
   __module__t   __doc__R   R   R   t   __radd__R   R   R   R   t   __rmul__R   t   __rtruediv__R   t   __truediv__R!   R$   R%   (    (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR      s"   												t   QuotientRingc           B  sÂ   e  Z d  Z e Z e Z e Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z e Z e Z e Z e Z e Z e Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   sa  
    Class representing (commutative) quotient rings.

    You should not usually instantiate this by hand, instead use the constructor
    from the base ring in the construction.

    >>> from sympy.abc import x
    >>> from sympy import QQ
    >>> I = QQ.old_poly_ring(x).ideal(x**3 + 1)
    >>> QQ.old_poly_ring(x).quotient_ring(I)
    QQ[x]/<x**3 + 1>

    Shorter versions are possible:

    >>> QQ.old_poly_ring(x)/I
    QQ[x]/<x**3 + 1>

    >>> QQ.old_poly_ring(x)/[x**3 + 1]
    QQ[x]/<x**3 + 1>

    Attributes:

    - ring - the base ring
    - base_ideal - the ideal used to form the quotient
    c         C  sh   | j  | k s( t d | | f ƒ ‚ n  | |  _  | |  _ |  |  j  j ƒ |  _ |  |  j  j ƒ |  _ d  S(   Ns   Ideal must belong to %s, got %s(   R   t
   ValueErrorR   t   zerot   one(   R
   R   t   ideal(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR   y   s    		c         C  s   t  |  j ƒ d t  |  j ƒ S(   Nt   /(   R   R   R   (   R
   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR      s    c         C  s%   t  |  j j |  j |  j |  j f ƒ S(   N(   t   hashR   R&   t   dtypeR   R   (   R
   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   __hash__„   s    c         C  sC   t  | |  j j ƒ s' |  j | ƒ } n  |  j |  |  j j | ƒ ƒ S(   s0   Construct an element of `self` domain from `a`. (   R   R   R4   R   t   reduce_element(   R
   t   a(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   new‡   s    c         C  s1   t  | t ƒ o0 |  j | j k o0 |  j | j k S(   s.   Returns `True` if two domains are equivalent. (   R   R-   R   R   (   R
   t   other(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR$   Ž   s    c         C  s   |  |  j  j | | ƒ ƒ S(   s*   Convert a Python `int` object to `dtype`. (   R   R   (   t   K1R7   t   K0(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   from_ZZ_python“   s    c         C  s   |  |  j  j | ƒ ƒ S(   N(   R   t
   from_sympy(   R
   R7   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR=   ž   s    c         C  s   |  j  j | j ƒ S(   N(   R   t   to_sympyR	   (   R
   R7   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR>   ¡   s    c         C  s   | |  k r | Sd  S(   N(    (   R
   R7   R;   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   from_QuotientRing¤   s    c         G  s   t  d ƒ ‚ d S(   s(   Returns a polynomial ring, i.e. `K[X]`. s   nested domains not allowedN(   R   (   R
   t   gens(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt	   poly_ring¨   s    c         G  s   t  d ƒ ‚ d S(   s'   Returns a fraction field, i.e. `K(X)`. s   nested domains not allowedN(   R   (   R
   R@   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt
   frac_field¬   s    c         C  se   |  j  j | j ƒ |  j } y |  | j d ƒ d ƒ SWn' t k
 r` t d | |  f ƒ ‚ n Xd S(   s/   
        Compute a**(-1), if possible.
        i   i    s   %s not a unit in %rN(   R   R1   R	   R   t   in_terms_of_generatorsR.   R   (   R
   R7   t   I(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR   °   s
    c         C  s   |  j  j | j ƒ S(   N(   R   t   containsR	   (   R
   R7   (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR#   º   s    c         C  s   t  |  | ƒ S(   sè   
        Generate a free module of rank ``rank`` over ``self``.

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
        (QQ[x]/<x**2 + 1>)**2
        (   R   (   R
   t   rank(    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   free_module½   s    	(   R&   R'   R(   t   Truet   has_assoc_RingR"   t   has_assoc_FieldR   R4   R   R   R5   R8   R$   R<   t   from_QQ_pythont   from_ZZ_gmpyt   from_QQ_gmpyt   from_RealFieldt   from_GlobalPolynomialRingt   from_FractionFieldR=   R>   R?   RA   RB   R   R#   RG   (    (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyR-   Z   s0   												
	N(   R(   t
   __future__R    R   t   sympy.polys.agca.modulesR   t   sympy.polys.domains.ringR   t   sympy.polys.polyerrorsR   R   t   sympy.utilitiesR   t   objectR   R-   (    (    (    s?   lib/python2.7/site-packages/sympy/polys/domains/quotientring.pyt   <module>   s   J