
~9\c           @  s~  d  Z  d d l m Z m Z d d l m Z m Z m Z m Z m	 Z	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z m Z d d	 l m Z m Z d d
 l m Z d d l  m! Z! d d l" m# Z# d d l$ m% Z% m& Z& d d l' m( Z( d d l) m* Z* d d l+ m, Z, d d l- m. Z. d d l/ m0 Z0 d d l1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 d d l6 m7 Z8 m9 Z: m; Z; d d l< m= Z= m> Z> m? Z? d d l@ mA ZA d d lB mC ZC d d lD mE ZE eC e0 d   ZF eC e0 d   ZG eC e0 d   ZH eC d    ZI d   ZJ i  ZK d eA e! f d     YZL d  e( eA e eM f d!     YZN d" S(#   s   Sparse polynomial rings. i(   t   print_functiont   division(   t   addt   mult   ltt   let   gtt   ge(   t   GeneratorType(   t   is_sequencet   reducet   string_typest   range(   t   Expr(   t   igcdt   oo(   t   Symbolt   symbols(   t   CantSympifyt   sympify(   t   multinomial_coefficients(   t   IPolys(   t   construct_domain(   t   dmp_to_dictt   dmp_from_dict(   t   DomainElement(   t   PolynomialRing(   t   heugcd(   t   MonomialOps(   t   lex(   t   CoercionFailedt   GeneratorsErrort   ExactQuotientFailedt   MultivariatePolynomialError(   t   Domaint   Ordert   build_options(   t   expr_from_dictt   _dict_reordert   _parallel_dict_from_expr(   t   DefaultPrinting(   t   public(   t   pollutec         C  s    t  |  | |  } | f | j S(   s  Construct a polynomial ring returning ``(ring, x_1, ..., x_n)``.

    Parameters
    ==========

    symbols : str
        Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
    domain : :class:
        `Domain` or coercible
    order : :class:, optional
        `Order` or coercible, optional, defaults to ``lex``

    Examples
    ========

    >>> from sympy.polys.rings import ring
    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.orderings import lex

    >>> R, x, y, z = ring("x,y,z", ZZ, lex)
    >>> R
    Polynomial ring in x, y, z over ZZ with lex order
    >>> x + y + z
    x + y + z
    >>> type(_)
    <class 'sympy.polys.rings.PolyElement'>

    (   t   PolyRingt   gens(   R   t   domaint   ordert   _ring(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   ring!   s    c         C  s   t  |  | |  } | | j f S(   s  Construct a polynomial ring returning ``(ring, (x_1, ..., x_n))``.

    Parameters
    ==========

    symbols : str
        Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
    domain : :class:
        `Domain` or coercible
    order : :class:, optional
        `Order` or coercible, optional, defaults to ``lex``

    Examples
    ========

    >>> from sympy.polys.rings import xring
    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.orderings import lex

    >>> R, (x, y, z) = xring("x,y,z", ZZ, lex)
    >>> R
    Polynomial ring in x, y, z over ZZ with lex order
    >>> x + y + z
    x + y + z
    >>> type(_)
    <class 'sympy.polys.rings.PolyElement'>

    (   R+   R,   (   R   R-   R.   R/   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   xringB   s    c         C  s?   t  |  | |  } t g  | j D] } | j ^ q | j  | S(   s  Construct a polynomial ring and inject ``x_1, ..., x_n`` into the global namespace.

    Parameters
    ==========

    symbols : str
        Symbol/Expr or sequence of str, Symbol/Expr (non-empty)
    domain : :class:
        `Domain` or coercible
    order : :class:, optional
        `Order` or coercible, optional, defaults to ``lex``

    Examples
    ========

    >>> from sympy.polys.rings import vring
    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.orderings import lex

    >>> vring("x,y,z", ZZ, lex)
    Polynomial ring in x, y, z over ZZ with lex order
    >>> x + y + z
    x + y + z
    >>> type(_)
    <class 'sympy.polys.rings.PolyElement'>

    (   R+   R*   R   t   nameR,   (   R   R-   R.   R/   t   sym(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   vringc   s    )c         O  s  t  } t |   s% |  g t }  } n  t t t |    }  t | |  } t |  |  \ } } | j d k r t
 g  | D] } t | j    ^ qw g   } t | d | \ | _ } n  t | j | j | j  }	 t t |	 j |   }
 | r |	 |
 d f S|	 |
 f Sd S(   s  Construct a ring deriving generators and domain from options and input expressions.

    Parameters
    ==========

    exprs : :class:
        `Expr` or sequence of :class:`Expr` (sympifiable)
    symbols : sequence of :class:`Symbol`/:class:`Expr`
    options : keyword arguments understood by :class:`Options`

    Examples
    ========

    >>> from sympy.core import symbols
    >>> from sympy.polys.rings import sring
    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.orderings import lex

    >>> x, y, z = symbols("x,y,z")
    >>> R, f = sring(x + 2*y + 3*z)
    >>> R
    Polynomial ring in x, y, z over ZZ with lex order
    >>> f
    x + 2*y + 3*z
    >>> type(_)
    <class 'sympy.polys.rings.PolyElement'>

    t   opti    N(   t   FalseR	   t   Truet   listt   mapR   R$   R'   R-   t   Nonet   sumt   valuesR   R+   R,   R.   t	   from_dict(   t   exprsR   t   optionst   singleR5   t   repst   rept   coeffst   _R/   t   polys(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sring   s    .c         C  s   t  |  t  r) |  r% t |  d t Sd St  |  t  r? |  f St |   r t d   |  D  rk t |   St d   |  D  r |  Sn  t d   d  S(   Nt   seqc         s  s   |  ] } t  | t  Vq d  S(   N(   t
   isinstanceR   (   t   .0t   s(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>   s    c         s  s   |  ] } t  | t  Vq d  S(   N(   RH   R   (   RI   RJ   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>   s    sb   expected a string, Symbol or expression or a non-empty sequence of strings, Symbols or expressions(    (   RH   R   t   _symbolsR7   R   R	   t   allR   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _parse_symbols   s    
R+   c           B  sd  e  Z d  Z e d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d" d" d" d  Z d	   Z e d
    Z e d    Z d" d  Z d   Z d   Z d   Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  e d    Z! e d    Z" d   Z# d   Z$ d   Z% d    Z& d!   Z' RS(#   s*   Multivariate distributed polynomial ring. c           s  t  t |   } t |  } t j |  } t j      |  j | | |   f } t j |  } | d  k r| j
 r t |  t | j  @r t d   n  t j |   } | | _ t |  | _ t d t f i | d 6 | _ | | _ | | _ | | _   | _ d	 | | _ | j   | _ t | j  | _ | j | j f g | _ | rt |  } | j    | _! | j"   | _# | j$   | _% | j&   | _' | j(   | _) | j*   | _+ | j,   | _- nK d   } | | _! | | _# d   | _% | | _' | | _) | | _+ | | _-   t. k r4d   | _/ n   f d   | _/ x` t0 | j | j  D]I \ }	 }
 t1 |	 t2  r\|	 j3 } t4 | |  st5 | | |
  qq\q\W| t | <n  | S(
   Ns7   polynomial ring and it's ground domain share generatorst   PolyElementR0   i    c         S  s   d S(   N(    (    (   t   at   b(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   <lambda>   t    c         S  s   d S(   N(    (    (   RO   RP   t   c(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ      RR   c         S  s
   t  |   S(   N(   t   max(   t   f(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ      RR   c           s   t  |  d   S(   Nt   key(   RT   (   RU   (   R.   (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ     RR   (   i    (6   t   tupleRM   t   lent	   DomainOptt
   preprocesst   OrderOptt   __name__t   _ring_cachet   getR:   t   is_Compositet   setR   R   t   objectt   __new__t   _hash_tuplet   hasht   _hasht   typeRN   t   dtypet   ngensR-   R.   t
   zero_monomt   _gensR,   t	   _gens_sett   onet   _oneR   R   t   monomial_mult   powt   monomial_powt   mulpowt   monomial_mulpowt   ldivt   monomial_ldivt   divt   monomial_divt   lcmt   monomial_lcmt   gcdt   monomial_gcdR   t   leading_expvt   zipRH   R   R2   t   hasattrt   setattr(   t   clsR   R-   R.   Rh   Rc   t   objt   codegent   monunitt   symbolt	   generatorR2   (    (   R.   s0   lib/python2.7/site-packages/sympy/polys/rings.pyRb      s`    "												"	c         C  se   |  j  j } g  } xF t |  j  D]5 } |  j |  } |  j } | | | <| j |  q" Wt |  S(   s(   Return a list of polynomial generators. (   R-   Rl   R   Rh   t   monomial_basist   zerot   appendRW   (   t   selfRl   Rj   t   it   expvt   poly(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRj     s    	
c         C  s   |  j  |  j |  j f S(   N(   R   R-   R.   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __getnewargs__  s    c         C  sP   |  j  j   } | d =x3 | j   D]% \ } } | j d  r# | | =q# q# W| S(   NR{   t	   monomial_(   t   __dict__t   copyt   itemst
   startswith(   R   t   stateRV   t   value(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __getstate__  s    c         C  s   |  j  S(   N(   Re   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __hash__&  s    c         C  sI   t  | t  oH |  j |  j |  j |  j f | j | j | j | j f k S(   N(   RH   R+   R   R-   Rh   R.   (   R   t   other(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __eq__)  s    c         C  s   |  | k S(   N(    (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __ne__.  s    c         C  s.   |  j  | p |  j | p |  j | p* |  j  S(   N(   t	   __class__R   R-   R.   (   R   R   R-   R.   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   clone1  s    c         C  s$   d g |  j  } d | | <t |  S(   s   Return the ith-basis element. i    i   (   Rh   RW   (   R   R   t   basis(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   4  s    
c         C  s
   |  j    S(   N(   Rg   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   :  s    c         C  s   |  j  |  j  S(   N(   Rg   Rm   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRl   >  s    c         C  s   |  j  j | |  S(   N(   R-   t   convert(   R   t   elementt   orig_domain(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   domain_newB  s    c         C  s   |  j  |  j |  S(   N(   t   term_newRi   (   R   t   coeff(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   ground_newE  s    c         C  s/   |  j  |  } |  j } | r+ | | | <n  | S(   N(   R   R   (   R   t   monomR   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   H  s
    	c         C  s  t  | t  re |  | j k r" | St  |  j t  rV |  j j | j k rV |  j |  St d   n t  | t  r t d   n t  | t  r |  j	 |  St  | t
  r y |  j |  SWq	t k
 r |  j |  SXn) t  | t  r |  j |  S|  j |  Sd  S(   Nt
   conversiont   parsing(   RH   RN   R0   R-   R   R   t   NotImplementedErrorR   t   dictR=   R8   t
   from_termst
   ValueErrort	   from_listR   t	   from_expr(   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   ring_newO  s$    'c         C  sR   |  j  } |  j } x9 | j   D]+ \ } } | |  } | r | | | <q q W| S(   N(   R   R   R   (   R   R   R   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR=   g  s    		c         C  s   |  j  t |   S(   N(   R=   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   r  s    c         C  s#   |  j  t | |  j d |  j   S(   Ni   (   R=   R   Rh   R-   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   u  s    c           s.   |  j       f d       t |   S(   Nc           s    j  |   } | d  k	 r | S|  j rG t t t t   |  j    S|  j ro t t	 t t   |  j    S|  j
 r |  j j r |  j d k r   |  j  t |  j  S j |   Sd  S(   Ni    (   R^   R:   t   is_AddR
   R   R8   R9   t   argst   is_MulR   t   is_Powt   expt
   is_Integert   baset   intR   (   t   exprR   (   t   _rebuildR-   t   mapping(    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   {  s    		$(   R-   R   (   R   R   R   (    (   R   R-   R   s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _rebuild_exprx  s    	c         C  sr   t  t t |  j |  j    } y |  j | |  } Wn' t k
 r` t d |  | f   n X|  j |  Sd  S(   Ns@   expected an expression convertible to a polynomial in %s, got %s(	   R   R8   R|   R   R,   R   R   R   R   (   R   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    !c         C  sF  | d k r' |  j r d } qBd } nt | t  r | } d | k rZ | |  j k  rZ qB|  j | k r | d k r | d } qBt d |   n t | |  j  r y |  j j |  } WqBt k
 r t d |   qBXn\ t | t  r2y |  j	 j |  } WqBt k
 r.t d |   qBXn t d |   | S(   s+   Compute index of ``gen`` in ``self.gens``. i    ii   s   invalid generator index: %ss   invalid generator: %ssE   expected a polynomial generator, an integer, a string or None, got %sN(
   R:   Rh   RH   R   R   Rg   R,   t   indexR   R   (   R   t   genR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s.    			c         G  sm   t  t |  j |   } g  t |  j  D] \ } } | | k r( | ^ q( } | sY |  j S|  j d |  Sd S(   s,   Remove specified generators from this ring. R   N(   R`   R9   R   t	   enumerateR   R-   R   (   R   R,   t   indicesR   RJ   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   drop  s
    4c         C  s.   |  j  | } | s |  j S|  j d |  Sd  S(   NR   (   R   R-   R   (   R   RV   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __getitem__  s    c         C  sK   |  j  j s t |  j  d  r4 |  j d |  j  j   St d |  j    d  S(   NR-   s   %s is not a composite domain(   R-   R_   R}   R   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   to_ground  s    c         C  s
   t  |   S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   to_domain  s    c         C  s)   d d l  m } | |  j |  j |  j  S(   Ni(   t	   FracField(   t   sympy.polys.fieldsR   R   R-   R.   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   to_field  s    c         C  s   t  |  j  d k S(   Ni   (   RX   R,   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_univariate  s    c         C  s   t  |  j  d k S(   Ni   (   RX   R,   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_multivariate  s    c         G  sP   |  j  } x@ | D]8 } t | d t r> | |  j |   7} q | | 7} q W| S(   sw  
        Add a sequence of polynomials or containers of polynomials.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> R, x = ring("x", ZZ)
        >>> R.add([ x**2 + 2*i + 3 for i in range(4) ])
        4*x**2 + 24
        >>> _.factor_list()
        (4, [(x**2 + 6, 1)])

        t   include(   R   R	   R   R   (   R   t   objst   pR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    	c         G  sP   |  j  } x@ | D]8 } t | d t r> | |  j |   9} q | | 9} q W| S(   s  
        Multiply a sequence of polynomials or containers of polynomials.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> R, x = ring("x", ZZ)
        >>> R.mul([ x**2 + 2*i + 3 for i in range(4) ])
        x**8 + 24*x**6 + 206*x**4 + 744*x**2 + 945
        >>> _.factor_list()
        (1, [(x**2 + 3, 1), (x**2 + 5, 1), (x**2 + 7, 1), (x**2 + 9, 1)])

        R   (   Rl   R	   R   R   (   R   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    	c         G  s   t  t |  j |   } g  t |  j  D] \ } } | | k r( | ^ q( } g  t |  j  D] \ } } | | k r\ | ^ q\ } | s |  S|  j d | d |  j |    Sd S(   sd   
        Remove specified generators from the ring and inject them into
        its domain.
        R   R-   N(   R`   R9   R   R   R   R,   R   R   (   R   R,   R   R   RJ   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   drop_to_ground  s    44c         C  sK   |  | k rC t  |  j  j t  | j   } |  j d t |   S|  Sd S(   s+   Add the generators of ``other`` to ``self``R   N(   R`   R   t   unionR   R8   (   R   R   t   syms(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   compose   s    !c         C  s4   t  |  j  j t  |   } |  j d t |   S(   s9   Add the elements of ``symbols`` as generators to ``self``R   (   R`   R   R   R   R8   (   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   add_gens(  s    N((   R\   t
   __module__t   __doc__R   Rb   Rj   R   R   R   R   R   R:   R   R   t   propertyR   Rl   R   R   R   R   t   __call__R=   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR+      sF   A			
												
		
								RN   c           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 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 d    Z  e d    Z! e d    Z" e d    Z# e d    Z$ e d     Z% e d!    Z& e d"    Z' e d#    Z( e d$    Z) e d%    Z* e d&    Z+ e d'    Z, e d(    Z- e d)    Z. e d*    Z/ e d+    Z0 d,   Z1 d-   Z2 d.   Z3 d/   Z4 d0   Z5 d1   Z6 d2   Z7 d3   Z8 d4   Z9 d5   Z: d6   Z; d7   Z< d8   Z= d9   Z> d:   Z? d;   Z@ d<   ZA d=   ZB eA ZC ZD eB ZE ZF d>   ZG d?   ZH d@   ZI dA   ZJ dB   ZK dC   ZL dD   ZM d dE  ZN dF   ZO d dG  ZP dH   ZQ dI   ZR dJ   ZS dK   ZT dL   ZU e dM    ZV e dN    ZW dO   ZX e dP    ZY dQ   ZZ dR   Z[ d dS  Z\ d dT  Z] d dU  Z^ dV   Z_ dW   Z` dX   Za dY   Zb dZ   Zc d[   Zd d\   Ze d]   Zf d^   Zg d_   Zh d`   Zi da   Zj db   Zk dc   Zl dd   Zm de   Zn en Zo df   Zp dg   Zq dh   Zr di   Zs dj   Zt dk   Zu dl   Zv dm   Zw dn   Zx do   Zy dp   Zz dq   Z{ dr   Z| ds   Z} dt   Z~ du   Z dv   Z d dw  Z d dx  Z d dy  Z dz   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 d  Z d   Z RS(   s5   Element of multivariate distributed polynomial ring. c         C  s   |  j  |  S(   N(   R   (   R   t   init(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   new1  s    c         C  s   |  j  j   S(   N(   R0   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   parent4  s    c         C  s   |  j  t |  j    f S(   N(   R0   R8   t	   iterterms(   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   7  s    c         C  sD   |  j  } | d  k r@ t |  j t |  j    f  |  _  } n  | S(   N(   Re   R:   Rd   R0   t	   frozensetR   (   R   Re   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   <  s    	+c         C  s   |  j  |   S(   s  Return a copy of polynomial self.

        Polynomials are mutable; if one is interested in preserving
        a polynomial, and one plans to use inplace operations, one
        can copy the polynomial. This method makes a shallow copy.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> R, x, y = ring('x, y', ZZ)
        >>> p = (x + y)**2
        >>> p1 = p.copy()
        >>> p2 = p
        >>> p[R.zero_monom] = 3
        >>> p
        x**2 + 2*x*y + y**2 + 3
        >>> p1
        x**2 + 2*x*y + y**2
        >>> p2
        x**2 + 2*x*y + y**2 + 3

        (   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   G  s    c         C  sm   |  j  | k r |  S|  j  j | j k r\ t t t |  |  j  j | j     } | j |  S| j |   Sd  S(   N(   R0   R   R8   R|   R&   R   R=   (   R   t   new_ringt   terms(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   set_ringc  s    'c         G  sb   | rC t  |  |  j j k rC t d |  j j t  |  f   n |  j j } t |  j   |  S(   Ns&   not enough symbols, expected %s got %s(   RX   R0   Rh   R   R   R%   t   as_expr_dict(   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   as_exprl  s    %c           s)   |  j  j j     f d   |  j   D S(   Nc           s%   i  |  ] \ } }   |  |  q S(    (    (   RI   R   R   (   t   to_sympy(    s0   lib/python2.7/site-packages/sympy/polys/rings.pys
   <dictcomp>v  s   	 (   R0   R-   R   R   (   R   (    (   R   s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   t  s    c   
      C  s   |  j  j } | j s  | j r- | j |  f S| j   } | j } | j } | j } x) |  j   D] } | | | |   } qa W|  j	 g  |  j
   D] \ } } | | | f ^ q  }	 | |	 f S(   N(   R0   R-   t   is_Fieldt   has_assoc_RingRl   t   get_ringRw   t   denomR<   R   R   (
   R   R-   t   ground_ringt   commonRw   R   R   t   kt   vR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   clear_denomsx  s    			8c         C  s7   x0 t  |  j    D] \ } } | s |  | =q q Wd S(   s+   Eliminate monomials with zero coefficient. N(   R8   R   (   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   strip_zero  s    c         C  so   | s |  St  | t  r< | j |  j k r< t j |  |  St |   d k rR t S|  j |  j j  | k Sd S(   sP  Equality test for polynomials.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> p1 = (x + y)**2 + (x - y)**2
        >>> p1 == 4*x*y
        False
        >>> p1 == 2*(x**2 + y**2)
        True

        i   N(	   RH   RN   R0   R   R   RX   R6   R^   Ri   (   t   p1t   p2(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    !c         C  s   |  | k S(   N(    (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    c         C  s   |  j  } t | | j  r t |  j    t | j    k rC t S| j j } x |  j   D]$ } | |  | | | |  s\ t Sq\ Wt Sn] t	 |   d k r t Sy | j j
 |  } Wn t k
 r t SX| j j |  j   | |  Sd S(   s+   Approximate equality test for polynomials. i   N(   R0   RH   Rg   R`   t   keysR6   R-   t   almosteqR7   RX   R   R   t   const(   R   R   t	   toleranceR0   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s     	$c         C  s   t  |   |  j   f S(   N(   RX   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sort_key  s    c         C  s6   t  | |  j j  r. | |  j   | j    St Sd  S(   N(   RH   R0   Rg   R   t   NotImplemented(   R   R   t   op(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _cmp  s    c         C  s   |  j  | t  S(   N(   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __lt__  s    c         C  s   |  j  | t  S(   N(   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __le__  s    c         C  s   |  j  | t  S(   N(   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __gt__  s    c         C  s   |  j  | t  S(   N(   R   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __ge__  s    c         C  sd   |  j  } | j |  } | j d k r4 | | j f St | j  } | | =| | j d |  f Sd  S(   Ni   R   (   R0   R   Rh   R-   R8   R   R   (   R   R   R0   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _drop  s    	c         C  s   |  j  |  \ } } |  j j d k rP |  j r= |  j d  St d |   np | j } x` |  j   D]R \ } } | | d k r t |  } | | =| | t	 |  <qf t d |   qf W| Sd  S(   Ni   s   can't drop %si    (
   R   R0   Rh   t	   is_groundR   R   R   R   R8   RW   (   R   R   R   R0   R   R   R   t   K(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    		c         C  sN   |  j  } | j |  } t | j  } | | =| | j d | d | |  f S(   NR   R-   (   R0   R   R8   R   R   (   R   R   R0   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _drop_to_ground  s
    	c         C  s   |  j  j d k r! t d   n  |  j |  \ } } | j } | j j d } x{ |  j   D]m \ } } | |  | | d } | | k r | | | j |  | | <q\ | | c | | | j |  7<q\ W| S(   Ni   s#   can't drop only generator to groundi    (	   R0   Rh   R   R   R   R-   R,   R   t
   mul_ground(   R   R   R   R0   R   R   R   t   mon(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    	%c         C  s    t  |  |  j j d |  j j  S(   Ni   (   R   R0   Rh   R-   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   to_dense  s    c         C  s
   t  |   S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   to_dict  s    c         C  s^  |  s | j  |  j j j  S| d } | d } |  j } | j } | j }	 | j }
 g  } x|  j   D]\ } } | j j |  } | r d n d } | j	 |  | |
 k r | j  |  } | j
 d  r| d } qn= | s | } n  | d k r| j | | d t } n d } g  } x t |	  D] } | | } | sJq.n  | j | | | d t } | d k r| t |  k s| d	 k  r| j | | d t } n | } | j	 | | | f  q.| j	 d
 |  q.W| r| g | } n  | j	 | j |   qg W| d	 d k rQ| j d	  } | d k rQ| j d	 d  qQn  d j |  S(   Nt   Mult   Atoms    + s    - t   -i   t   strictRR   i    s   %s(   s    + s    - (   t   _printR0   R-   R   R   Rh   Ri   R   t   is_positiveR   R   t   parenthesizeR7   R   R   R6   t   joint   popt   insert(   R   t   printert
   precedencet   exp_patternt
   mul_symbolt   prec_mult	   prec_atomR0   R   Rh   t   zmt   sexpvsR   R   t   positivet   signt   scoefft   sexpvR   R   R   t   sexpt   head(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   str  sT    

				

c         C  s   |  |  j  j k S(   N(   R0   Rk   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_generatorF  s    c         C  s)   |  p( t  |   d k o( |  j j |  k S(   Ni   (   RX   R0   Ri   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   J  s    c         C  s&   |  p% t  |   d k o% |  j d k S(   Ni   (   RX   t   LC(   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_monomialN  s    c         C  s   t  |   d k S(   Ni   (   RX   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_termR  s    c         C  s   |  j  j j |  j  S(   N(   R0   R-   t   is_negativeR  (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  V  s    c         C  s   |  j  j j |  j  S(   N(   R0   R-   R  R  (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  Z  s    c         C  s   |  j  j j |  j  S(   N(   R0   R-   t   is_nonnegativeR  (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  ^  s    c         C  s   |  j  j j |  j  S(   N(   R0   R-   t   is_nonpositiveR  (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  b  s    c         C  s   |  S(   N(    (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_zerof  s    c         C  s   |  |  j  j k S(   N(   R0   Rl   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_onej  s    c         C  s   |  j  j j |  j  S(   N(   R0   R-   R  R  (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_monicn  s    c         C  s   |  j  j j |  j    S(   N(   R0   R-   R  t   content(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_primitiver  s    c         C  s   t  d   |  j   D  S(   Nc         s  s!   |  ] } t  |  d  k Vq d S(   i   N(   R;   (   RI   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>x  s    (   RL   t
   itermonoms(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   is_linearv  s    c         C  s   t  d   |  j   D  S(   Nc         s  s!   |  ] } t  |  d  k Vq d S(   i   N(   R;   (   RI   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>|  s    (   RL   R"  (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_quadraticz  s    c         C  s    |  j  j s t S|  j  j |   S(   N(   R0   Rh   R7   t	   dmp_sqf_p(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_squarefree~  s    c         C  s    |  j  j s t S|  j  j |   S(   N(   R0   Rh   R7   t   dmp_irreducible_p(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_irreducible  s    c         C  s,   |  j  j r |  j  j |   St d   d  S(   Ns   cyclotomic polynomial(   R0   R   t   dup_cyclotomic_pR!   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   is_cyclotomic  s    c         C  s3   |  j  g  |  j   D] \ } } | | f ^ q  S(   N(   R   R   (   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __neg__  s    c         C  s   |  S(   N(    (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __pos__  s    c   
      C  s  | s |  j    S|  j } t | | j  r |  j    } | j } | j j } xG | j   D]9 \ } } | | |  | } | r | | | <qY | | =qY W| St | t  rt | j t	  r | j j | j k r qt | j j t	  r
| j j j | k r
| j
 |   St Sn  y | j |  } Wn t k
 r8t SX|  j    } | sO| S| j }	 |	 |  j   k rw| | |	 <n+ | | |	 k r| |	 =n | |	 c | 7<| Sd S(   s  Add two polynomials.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> (x + y)**2 + (x - y)**2
        2*x**2 + 2*y**2

        N(   R   R0   RH   Rg   R^   R-   R   R   RN   R   t   __radd__R   R   R   Ri   R   (
   R   R   R0   R   R^   R   R   R   t   cp2R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __add__  sB    
		'*	
c         C  s   |  j    } | s | S|  j } y | j |  } Wn t k
 rF t SX| j } | |  j   k ro | | | <n+ | | | k r | | =n | | c | 7<| Sd  S(   N(   R   R0   R   R   R   Ri   R   (   R   t   nR   R0   R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR-    s    		
c   	      C  s  | s |  j    S|  j } t | | j  r |  j    } | j } | j j } xG | j   D]9 \ } } | | |  | } | r | | | <qY | | =qY W| St | t  rt | j t	  r | j j | j k r qt | j j t	  r
| j j j | k r
| j
 |   St Sn  y | j |  } Wn t k
 r8t SX|  j    } | j } | |  j   k rn| | | <n* | | | k r| | =n | | c | 8<| Sd S(   s.  Subtract polynomial p2 from p1.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> p1 = x + y**2
        >>> p2 = x*y + y**2
        >>> p1 - p2
        -x*y + x

        N(   R   R0   RH   Rg   R^   R-   R   R   RN   R   t   __rsub__R   R   R   Ri   R   (	   R   R   R0   R   R^   R   R   R   R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __sub__  s>    
		'*	
c         C  sl   |  j  } y | j |  } Wn t k
 r0 t SX| j } x |  D] } |  | | | <qA W| | 7} | Sd S(   s#  n - p1 with n convertible to the coefficient domain.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y
        >>> 4 - p
        -x - y + 4

        N(   R0   R   R   R   R   (   R   R0  R0   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR1    s    		
c         C  s  |  j  } | j } |  s  | r$ | St | | j  r | j } | j j } | j } t | j    } x[ |  j   D]M \ } }	 x> | D]6 \ }
 } | | |
  } | | |  |	 | | | <q Wqs W| j	   | St | t
  rIt | j t  r| j j  | j  k rqIt | j  j t  rB| j  j j  | k rB| j |   St Sn  y | j |  } Wn t k
 rpt SXx7 |  j   D]) \ } }	 |	 | } | r~| | | <q~q~W| Sd S(   s!  Multiply two polynomials.

        Examples
        ========

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', QQ)
        >>> p1 = x + y
        >>> p2 = x - y
        >>> p1*p2
        x**2 - y**2

        N(   R0   R   RH   Rg   R^   R-   Rn   R8   R   R   RN   R   t   __rmul__R   R   R   (   R   R   R0   R   R^   R   Rn   t   p2itt   exp1t   v1t   exp2t   v2R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __mul__2  s<    				#
'*
c         C  s   |  j  j } | s | Sy | j  j |  } Wn t k
 r@ t SXx7 |  j   D]) \ } } | | } | rN | | | <qN qN W| Sd S(   s  p2 * p1 with p2 in the coefficient domain of p1.

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y
        >>> 4 * p
        4*x + 4*y

        N(   R0   R   R   R   R   R   (   R   R   R   R5  R6  R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR3  d  s    
c         C  sB  |  j  } | s+ |  r | j St d   nz t |   d k r t |  j    d \ } } | j } | d k r | | | j | |  <n | | | | j | |  <| St |  } | d k  r t d   nr | d k r |  j	   S| d k r |  j
   S| d k r|  |  j
   St |   d k r1|  j |  S|  j |  Sd S(	   s(  raise polynomial to power `n`

        Examples
        ========

        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.rings import ring

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y**2
        >>> p**3
        x**3 + 3*x**2*y**2 + 3*x*y**4 + y**6

        s   0**0i   i    s   Negative exponenti   i   i   N(   R0   Rl   R   RX   R8   R   R   Rp   R   R   t   squaret   _pow_multinomialt   _pow_generic(   R   R0  R0   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __pow__  s0    		

c         C  sd   |  j  j } |  } xK t r_ | d @rF | | } | d 8} | sF PqF n  | j   } | d } q W| S(   Ni   i   (   R0   Rl   R7   R:  (   R   R0  R   RS   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR<    s    	


c         C  s  t  t t |   |  j    } |  j j } |  j j } t  |  j    } |  j j j	 } |  j j	 } x | D] \ } }	 | }
 |	 } xL t
 | |  D]; \ } \ } } | r | |
 | |  }
 | | | 9} q q Wt |
  } | } | j | |  | } | r| | | <qm | | =qm W| S(   N(   R8   R   RX   R   R0   Rr   Ri   R   R-   R   R|   RW   R^   (   R   R0  t   multinomialsRr   Ri   R   R   R   t   multinomialt   multinomial_coefft   product_monomt   product_coeffR   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR;    s(    !"c         C  s/  |  j  } | j } | j } t |  j    } | j j } | j } x} t t |   D]i } | | } |  | }	 xL t |  D]> }
 | |
 } | | |  } | | |  |	 |  | | | <q| WqU W| j	 d  } | j } xD |  j
   D]6 \ } } | | |  } | | |  | d | | <q W| j   | S(   s  square of a polynomial

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y**2
        >>> p.square()
        x**2 + 2*x*y**2 + y**4

        i   (   R0   R   R^   R8   R   R-   Rn   R   RX   t   imul_numR   R   (   R   R0   R   R^   R   R   Rn   R   t   k1t   pkt   jt   k2R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR:    s(    				


'	
c         C  s   |  j  } | s t d   n t | | j  r= |  j |  St | t  r t | j t  rv | j j  | j  k rv q t | j  j t  r | j  j j  | k r | j |   St	 Sn  y | j
 |  } Wn t k
 r t	 SX|  j |  |  j |  f Sd  S(   Ns   polynomial division(   R0   t   ZeroDivisionErrorRH   Rg   Ru   RN   R-   R   t   __rdivmod__R   R   R   t
   quo_groundt
   rem_ground(   R   R   R0   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   __divmod__  s     	'*c         C  s   t  S(   N(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRI    s    c         C  s   |  j  } | s t d   n t | | j  r= |  j |  St | t  r t | j t  rv | j j  | j  k rv q t | j  j t  r | j  j j  | k r | j |   St	 Sn  y | j
 |  } Wn t k
 r t	 SX|  j |  Sd  S(   Ns   polynomial division(   R0   RH  RH   Rg   t   remRN   R-   R   t   __rmod__R   R   R   RK  (   R   R   R0   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __mod__  s     	'*c         C  s   t  S(   N(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRN  1  s    c         C  s  |  j  } | s t d   n t | | j  rU | j rE |  | d S|  j |  Snw t | t  r t | j t  r | j j  | j  k r q t | j  j t  r | j  j j  | k r | j	 |   St
 Sn  y | j |  } Wn t k
 r t
 SX|  j |  Sd  S(   Ns   polynomial divisioni(   R0   RH  RH   Rg   R  t   quoRN   R-   R   t   __rtruediv__R   R   R   RJ  (   R   R   R0   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   __truediv__4  s$    		'*c         C  s   t  S(   N(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ  M  s    c           sg   |  j  j  |  j  j } | j   |  j  j  | j rN     f d   } n     f d   } | S(   Nc           sc   |  \ } } | \ } } |  k r- | } n  | |  } | d  k	 r[ |   | |  f Sd  Sd  S(   N(   R:   (   t	   a_lm_a_lct	   b_lm_b_lct   a_lmt   a_lct   b_lmt   b_lcR   (   t
   domain_quoRv   R  (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   term_div\  s    	c           sm   |  \ } } | \ } } |  k r- | } n  | |  } | d  k pO | | se |   | |  f Sd  Sd  S(   N(   R:   (   RS  RT  RU  RV  RW  RX  R   (   RY  Rv   R  (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRZ  h  s    	(   R0   Ri   R-   RP  Rv   R   (   R   R-   RZ  (    (   RY  Rv   R  s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   _term_divU  s    		c         C  s  |  j  } t } t | t  r0 t } | g } n  t d   | D  rU t d   n  |  s | rq | j | j f Sg  | j f Sn  x, | D]$ } | j  | k r t d   q q Wt	 |  } g  t
 |  D] } | j ^ q } |  j   } | j }	 |  j   }
 g  | D] } | j   ^ q} x
| r*d } d } x | | k  r| d k r| j   } |
 | | | f | | | | | | f  } | d k	 r| \ } } | | j | | f  | | <| j | | | | f  } d } q6| d 7} q6W| s!| j   } |	 j | | | f  }	 | | =q!q!W| | j k rG|	 | 7}	 n  | rq| s`| j |	 f S| d |	 f Sn
 | |	 f Sd S(   sU  Division algorithm, see [CLO] p64.

        fv array of polynomials
           return qv, r such that
           self = sum(fv[i]*qv[i]) + r

        All polynomials are required not to be Laurent polynomials.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> f = x**3
        >>> f0 = x - y**2
        >>> f1 = x - y
        >>> qv, r = f.div((f0, f1))
        >>> qv[0]
        x**2 + x*y**2 + y**4
        >>> qv[1]
        0
        >>> r
        y**6

        c         s  s   |  ] } | Vq d  S(   N(    (   RI   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>  s    s   polynomial divisions"   self and f must have the same ringi    i   N(   R0   R6   RH   RN   R7   t   anyRH  R   R   RX   R   R   R[  R{   R:   t   _iadd_monomt   _iadd_poly_monomRi   (   R   t   fvR0   t
   ret_singleRU   RJ   R   t   qvR   t   rRZ  t   fxt   expvst   divoccurredR   t   termt   expv1RS   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRu   v  sV    	"		/	c         C  s  |  } t  | t  r! | g } n  t d   | D  rF t d   n  | j } | j } | j } | j } | j } | j   } | j	 }	 | j
   } | j }
 x8| rx+| D] } | |	 | j	  } | d  k	 r | \ } } xZ | j   D]L \ } } | | |  } |
 | |  | | } | s,| | =q | | | <q W| j   } | d  k	 re| | | f }	 n  Pq q W|	 \ } } | | k r| | c | 7<n
 | | | <| | =| j   } | d  k	 r | | | f }	 q q W| S(   Nc         s  s   |  ] } | Vq d  S(   N(    (   RI   t   g(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>  s    s   polynomial division(   RH   RN   R\  RH  R0   R-   R   Rn   R[  t   LTR   R^   R:   R   R{   (   R   t   GRU   R0   R-   R   Rn   Rb  RZ  t   ltfR^   Rh  t   tqt   mRS   t   mgt   cgt   m1t   c1t   ltmt   ltc(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRM    sL    								

c         C  s   |  j  |  d S(   Ni    (   Ru   (   RU   Rj  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRP    s    c         C  s2   |  j  |  \ } } | s | St |  |   d  S(   N(   Ru   R    (   RU   Rj  t   qRb  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   exquo  s    c         C  s   |  |  j  j k r! |  j   } n |  } | \ } } | j |  } | d k r[ | | | <n$ | | 7} | rx | | | <n | | =| S(   s  add to self the monomial coeff*x0**i0*x1**i1*...
        unless self is a generator -- then just return the sum of the two.

        mc is a tuple, (monom, coeff), where monomial is (i0, i1, ...)

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x**4 + 2*y
        >>> m = (1, 2)
        >>> p1 = p._iadd_monom((m, 5))
        >>> p1
        x**4 + 5*x*y**2 + 2*y
        >>> p1 is p
        True
        >>> p = x
        >>> p1 = p._iadd_monom((m, 5))
        >>> p1
        5*x*y**2 + x
        >>> p1 is p
        False

        N(   R0   Rk   R   R^   R:   (   R   t   mct   cpselfR   R   RS   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR]    s    
c         C  s   |  } | | j  j k r' | j   } n  | \ } } | j } | j  j j } | j  j } xZ | j   D]L \ }	 }
 | |	 |  } | | |  |
 | } | r | | | <qd | | =qd W| S(   sE  add to self the product of (p)*(coeff*x0**i0*x1**i1*...)
        unless self is a generator -- then just return the sum of the two.

        mc is a tuple, (monom, coeff), where monomial is (i0, i1, ...)

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y, z = ring('x, y, z', ZZ)
        >>> p1 = x**4 + 2*y
        >>> p2 = y + z
        >>> m = (1, 2, 3)
        >>> p1 = p1._iadd_poly_monom(p2, (m, 3))
        >>> p1
        x**4 + 3*x*y**3*z**3 + 3*x*y**2*z**4 + 2*y

        (   R0   Rk   R   R^   R-   R   Rn   R   (   R   R   Rv  R   Rm  RS   R^   R   Rn   R   R   t   kaR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR^  &  s    	c         C  sX   |  j  j |  } |  s t S| d k  r- d St g  |  j   D] } | | ^ q=  Sd S(   s   
        The leading degree in ``x`` or the main variable.

        Note that the degree of 0 is negative infinity (the SymPy object -oo).

        i    N(   R0   R   R   RT   R"  (   RU   t   xR   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   degreeK  s    c         C  sA   |  s t  f |  j j St t t t t |  j        Sd S(   s   
        A tuple containing leading degrees in all variables.

        Note that the degree of 0 is negative infinity (the SymPy object -oo)

        N(	   R   R0   Rh   RW   R9   RT   R8   R|   R"  (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   degrees[  s    c         C  sX   |  j  j |  } |  s t S| d k  r- d St g  |  j   D] } | | ^ q=  Sd S(   s   
        The tail degree in ``x`` or the main variable.

        Note that the degree of 0 is negative infinity (the SymPy object -oo)

        i    N(   R0   R   R   t   minR"  (   RU   Ry  R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   tail_degreeg  s    c         C  sA   |  s t  f |  j j St t t t t |  j        Sd S(   s   
        A tuple containing tail degrees in all variables.

        Note that the degree of 0 is negative infinity (the SymPy object -oo)

        N(	   R   R0   Rh   RW   R9   R|  R8   R|   R"  (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   tail_degreesw  s    c         C  s   |  r |  j  j |   Sd Sd S(   sT  Leading monomial tuple according to the monomial ordering.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y, z = ring('x, y, z', ZZ)
        >>> p = x**4 + x**3*y + x**2*z**2 + z**7
        >>> p.leading_expv()
        (4, 0, 0)

        N(   R0   R{   R:   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR{     s    c         C  s   |  j  | |  j j j  S(   N(   R^   R0   R-   R   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   _get_coeff  s    c         C  s   | d k r |  j  |  j j  St | |  j j  r t | j    } t |  d k r | d \ } } | |  j j j	 k r |  j  |  Sq n  t
 d |   d S(   s  
        Returns the coefficient that stands next to the given monomial.

        Parameters
        ==========

        element : PolyElement (with ``is_monomial = True``) or 1

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y, z = ring("x,y,z", ZZ)
        >>> f = 3*x**2*y - x*y*z + 7*z**3 + 23

        >>> f.coeff(x**2*y)
        3
        >>> f.coeff(x*y)
        0
        >>> f.coeff(1)
        23

        i   i    s   expected a monomial, got %sN(   R  R0   Ri   RH   Rg   R8   R   RX   R-   Rl   R   (   R   R   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    c         C  s   |  j  |  j j  S(   s!   Returns the constant coeffcient. (   R  R0   Ri   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    c         C  s   |  j  |  j    S(   N(   R  R{   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR    s    c         C  s*   |  j    } | d  k r" |  j j S| Sd  S(   N(   R{   R:   R0   Ri   (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   LM  s    
c         C  s8   |  j  j } |  j   } | r4 |  j  j j | | <n  | S(   s  
        Leading monomial as a polynomial element.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> (3*x*y + y**2).leading_monom()
        x*y

        (   R0   R   R{   R-   Rl   (   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   leading_monom  s
    c         C  sH   |  j    } | d  k r1 |  j j |  j j j f S| |  j |  f Sd  S(   N(   R{   R:   R0   Ri   R-   R   R  (   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRi    s    c         C  s9   |  j  j } |  j   } | d k	 r5 |  | | | <n  | S(   s  Leading term as a polynomial element.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> (3*x*y + y**2).leading_term()
        3*x*y

        N(   R0   R   R{   R:   (   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   leading_term  s
    c           sr     d  k r |  j j   n t j        t k rO t | d d   d t St | d   f d   d t Sd  S(   NRV   c         S  s   |  d S(   Ni    (    (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ     RR   t   reversec           s     |  d  S(   Ni    (    (   R   (   R.   (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ   	  RR   (   R:   R0   R.   R[   RZ   R   t   sortedR7   (   R   RG   R.   (    (   R.   s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _sorted   s    c         C  s&   g  |  j  |  D] \ } } | ^ q S(   s  Ordered list of polynomial coefficients.

        Parameters
        ==========

        order : :class:`Order` or coercible, optional

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.orderings import lex, grlex

        >>> _, x, y = ring("x, y", ZZ, lex)
        >>> f = x*y**7 + 2*x**2*y**3

        >>> f.coeffs()
        [2, 1]
        >>> f.coeffs(grlex)
        [1, 2]

        (   R   (   R   R.   RD   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRC     s    c         C  s&   g  |  j  |  D] \ } } | ^ q S(   s   Ordered list of polynomial monomials.

        Parameters
        ==========

        order : :class:`Order` or coercible, optional

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.orderings import lex, grlex

        >>> _, x, y = ring("x, y", ZZ, lex)
        >>> f = x*y**7 + 2*x**2*y**3

        >>> f.monoms()
        [(2, 3), (1, 7)]
        >>> f.monoms(grlex)
        [(1, 7), (2, 3)]

        (   R   (   R   R.   R   RD   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   monoms%  s    c         C  s   |  j  t |  j    |  S(   s  Ordered list of polynomial terms.

        Parameters
        ==========

        order : :class:`Order` or coercible, optional

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ
        >>> from sympy.polys.orderings import lex, grlex

        >>> _, x, y = ring("x, y", ZZ, lex)
        >>> f = x*y**7 + 2*x**2*y**3

        >>> f.terms()
        [((2, 3), 2), ((1, 7), 1)]
        >>> f.terms(grlex)
        [((1, 7), 1), ((2, 3), 2)]

        (   R  R8   R   (   R   R.   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   ?  s    c         C  s   t  |  j    S(   s,   Iterator over coefficients of a polynomial. (   t   iterR<   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   itercoeffsY  s    c         C  s   t  |  j    S(   s)   Iterator over monomials of a polynomial. (   R  R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR"  ]  s    c         C  s   t  |  j    S(   s%   Iterator over terms of a polynomial. (   R  R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   a  s    c         C  s   t  |  j    S(   s+   Unordered list of polynomial coefficients. (   R8   R<   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   listcoeffse  s    c         C  s   t  |  j    S(   s(   Unordered list of polynomial monomials. (   R8   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   listmonomsi  s    c         C  s   t  |  j    S(   s$   Unordered list of polynomial terms. (   R8   R   (   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   listtermsm  s    c         C  sS   |  |  j  j k r |  | S| s. |  j   d Sx |  D] } |  | c | 9<q5 W|  S(   s:  multiply inplace the polynomial p by an element in the
        coefficient ring, provided p is not one of the generators;
        else multiply not inplace

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y**2
        >>> p1 = p.imul_num(3)
        >>> p1
        3*x + 3*y**2
        >>> p1 is p
        True
        >>> p = x
        >>> p1 = p.imul_num(3)
        >>> p1
        3*x
        >>> p1 is p
        False

        N(   R0   Rk   t   clear(   R   RS   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRC  q  s    
c         C  sH   |  j  j } | j } | j } x# |  j   D] } | | |  } q+ W| S(   s*   Returns GCD of polynomial's coefficients. (   R0   R-   R   Ry   R  (   RU   R-   t   contRy   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    		c         C  s   |  j    } | |  j |  f S(   s,   Returns content and a primitive polynomial. (   R   RJ  (   RU   R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   primitive  s    c         C  s   |  s
 |  S|  j  |  j  Sd S(   s5   Divides all coefficients by the leading coefficient. N(   RJ  R  (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   monic  s    c         C  sL   | s |  j  j Sg  |  j   D] \ } } | | | f ^ q } |  j |  S(   N(   R0   R   R   R   (   RU   Ry  R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    
/c         C  sM   |  j  j } g  |  j   D]! \ } } | | |  | f ^ q } |  j |  S(   N(   R0   Rn   R   R   (   RU   R   Rn   t   f_monomt   f_coeffR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   mul_monom  s    4c         C  s   | \ } } |  s | r$ |  j  j S| |  j  j k rC |  j |  S|  j  j } g  |  j   D]% \ } } | | |  | | f ^ q\ } |  j |  S(   N(   R0   R   Ri   R   Rn   R   R   (   RU   Rf  R   R   Rn   R  R  R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   mul_term  s    
8c         C  s   |  j  j } | s! t d   n  |  s7 | | j k r; |  S| j r | j } g  |  j   D]! \ } } | | | |  f ^ qZ } n9 g  |  j   D]& \ } } | | s | | | f ^ q } |  j |  S(   Ns   polynomial division(   R0   R-   RH  Rl   R   RP  R   R   (   RU   Ry  R-   RP  R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRJ    s    		79c         C  s   | \ } } | s! t  d   n/ |  s1 |  j j S| |  j j k rP |  j |  S|  j   } g  |  j   D] } | | |  ^ qi } |  j g  | D] } | d  k	 r | ^ q  S(   Ns   polynomial division(	   RH  R0   R   Ri   RJ  R[  R   R   R:   (   RU   Rf  R   R   RZ  t   tR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   quo_term  s    
(c         C  s   |  j  j j ro g  } x |  j   D]F \ } } | | } | | d k rU | | } n  | j | | f  q" Wn/ g  |  j   D] \ } } | | | f ^ q| } |  j |  } | j   | S(   Ni   (   R0   R-   t   is_ZZR   R   R   R   (   RU   R   R   R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   trunc_ground  s    
/
c         C  sa   |  } | j    } | j    } | j j j | |  } | j |  } | j |  } | | | f S(   N(   R   R0   R-   Ry   RJ  (   R   Rh  RU   t   fct   gcRy   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   extract_ground  s    c         C  sO   |  s |  j  j j S|  j  j j } | g  |  j   D] } | |  ^ q2  Sd  S(   N(   R0   R-   R   t   absR  (   RU   t	   norm_funct
   ground_absR   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   _norm  s    c         C  s   |  j  t  S(   N(   R  RT   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   max_norm	  s    c         C  s   |  j  t  S(   N(   R  R;   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   l1_norm  s    c         G  st  |  j  } |  g t |  } d g | j } xY | D]Q } xH | j   D]: } x1 t |  D]# \ } } t | | |  | | <qY WqF Wq3 Wx- t |  D] \ } }	 |	 s d | | <q q Wt |  } t d   | D  r | | f Sg  }
 x} | D]u } | j } xV | j	   D]H \ } } g  t
 | |  D] \ } } | | ^ q)} | | t |  <qW|
 j |  q W| |
 f S(   Ni    i   c         s  s   |  ] } | d  k Vq d S(   i   N(    (   RI   RP   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pys	   <genexpr>   s    (   R0   R8   Rh   R"  R   R   RW   RL   R   R   R|   R   (   RU   Rj  R0   RE   t   JR   R   R   Rm  RP   t   Ht   ht   IR   RF  t   N(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   deflate  s*    	#
	,c         C  si   |  j  j } xV |  j   D]H \ } } g  t | |  D] \ } } | | ^ q5 } | | t |  <q W| S(   N(   R0   R   R   R|   RW   (   RU   R  R   R  R   R   RF  R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   inflate0  s
    ,c         C  s   |  } | j  j } | j sT | j   \ } } | j   \ } } | j | |  } n  | | j | j |   } | j s | j |  S| j   Sd  S(   N(	   R0   R-   R   R  Rw   RP  Ry   R   R  (   R   Rh  RU   R-   R  R  RS   R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRw   9  s    		c         C  s   |  j  |  d S(   Ni    (   t	   cofactors(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRy   I  s    c         C  sF  |  r' | r' |  j  j } | | | f S|  sR |  j |  \ } } } | | | f S| s} | j |   \ } } } | | | f St |   d k r |  j |  \ } } } | | | f St |  d k r | j |   \ } } } | | | f S|  j |  \ } \ }  } |  j |  \ } } } | j |  | j |  | j |  f S(   Ni   (   R0   R   t	   _gcd_zeroRX   t
   _gcd_monomR  t   _gcdR  (   RU   Rh  R   R  t   cfft   cfgR  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  L  s$    c         C  sB   |  j  j |  j  j } } | j r/ | | | f S| | | f Sd  S(   N(   R0   Rl   R   R  (   RU   Rh  Rl   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  b  s    	c         C  s,  |  j  } | j j } | j j } | j } | j } t |  j    d \ } } | | }	 }
 x8 | j   D]* \ } } | |	 |  }	 | |
 |  }
 qi W|  j |	 |
 f g  } |  j | | |	  | | |
  f g  } |  j g  | j   D]* \ } } | | |	  | | |
  f ^ q  } | | | f S(   Ni    (	   R0   R-   Ry   RP  Rz   Rt   R8   R   R   (   RU   Rh  R0   t
   ground_gcdt
   ground_quoRz   Rt   t   mft   cft   _mgcdt   _cgcdRn  Ro  R  R  R  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  i  s    			*Fc         C  sO   |  j  } | j j r" |  j |  S| j j r; |  j |  S| j |  |  Sd  S(   N(   R0   R-   t   is_QQt   _gcd_QQR  t   _gcd_ZZt   dmp_inner_gcd(   RU   Rh  R0   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  y  s    	c         C  s   t  |  |  S(   N(   R   (   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR    s    c         C  s  |  } | j  } | j d | j j    } | j   \ } } | j   \ } } | j |  } | j |  } | j |  \ } } }	 | j |  } | j | j   }
 } | j |  j	 | j j
 |
 |   } |	 j |  j	 | j j
 |
 |   }	 | | |	 f S(   NR-   (   R0   R   R-   R   R   R   R  R  R  R   RP  (   R   Rh  RU   R0   R   R  Ro  R  R  R  RS   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR    s    	''c         C  s  |  } | j  } | s" | | j f S| j } | j o: | j ss | j |  \ } } } | j r| | } } qn,| j d | j    } | j	   \ }	 } | j	   \ }
 } | j
 |  } | j
 |  } | j |  \ } } } | j j |
 |	  \ } }
 }	 | j
 |  } | j
 |  } | j } | j } | rQ| rQ| | } } n0 | ri|
 | }
 } n | r|
 | }
 } n  | j |
  } | j |	  } | | f S(   s  
        Cancel common factors in a rational function ``f/g``.

        Examples
        ========

        >>> from sympy.polys import ring, ZZ
        >>> R, x,y = ring("x,y", ZZ)

        >>> (2*x**2 - 2).cancel(x**2 - 2*x + 1)
        (2*x + 2, x - 1)

        R-   (   R0   Rl   R-   R   R   R  R  R   R   R   R   R   (   R   Rh  RU   R0   R-   RD   R   Rt  R   t   cqt   cpt   p_negt   q_neg(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   cancel  s:    					c   	      C  s   |  j  } | j |  } | j |  } | j } xT |  j   D]F \ } } | | r= | j | |  } | j | | |  | | <q= q= W| S(   s!  Computes partial derivative in ``x``.

        Examples
        ========

        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring("x,y", ZZ)
        >>> p = x + x**2*y**3
        >>> p.diff(x)
        2*x*y**3 + 1

        (   R0   R   R   R   R   Rt   R   (	   RU   Ry  R0   R   Rm  Rh  R   R   t   e(    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   diff  s    		
"c         G  sp   d t  |  k  o# |  j j k n rJ |  j t t |  j j |    St d |  j j t  |  f   d  S(   Ni    s1   expected at least 1 and at most %s values, got %s(   RX   R0   Rh   t   evaluateR8   R|   R,   R   (   RU   R<   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR     s    ("c         C  s  |  } t  | t  r | d  k r | d | d \ } } } | j | |  } | sX | Sg  | D]! \ } } | j |  | f ^ q_ } | j |  Sn  | j } | j |  } | j j |  } | j	 d k r| j j
 } x/ | j   D]! \ \ }	 }
 | |
 | |	 7} q W| S| j |  j
 } x | j   D] \ } }
 | | | |  | | d }	 } |
 | |	 }
 | | k r|
 | | }
 |
 r|
 | | <q| | =q0|
 r0|
 | | <q0q0W| Sd  S(   Ni    i   (   RH   R8   R:   R  R   R0   R   R-   R   Rh   R   R   (   R   Ry  RO   RU   t   Xt   YR0   R   t   resultR0  R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR    s8    .	!
c         C  s}  |  } t  | t  rN | d  k rN x& | D] \ } } | j | |  } q( W| S| j } | j |  } | j j |  } | j d k r | j j	 } x/ | j
   D]! \ \ } }	 | |	 | | 7} q W| j |  S| j	 }
 x | j
   D] \ } }	 | | | |  d | | d } } |	 | | }	 | |
 k r^|	 |
 | }	 |	 rT|	 |
 | <qq|
 | =q |	 r |	 |
 | <q q W|
 Sd  S(   Ni   i    (   i    (   RH   R8   R:   t   subsR0   R   R-   R   Rh   R   R   R   (   R   Ry  RO   RU   R  R0   R   R  R0  R   R   R   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyR  	  s2    		%
c           s  |  j  } | j } t t t | j t t | j        | d  k	 r] | | f g } nc t	 | t  r{ t |  } nE t	 | t  r t
 t | j    d   f d   } n t d   x= t |  D]/ \ } \ } }   | | j |  f | | <q Wx |  j   D] \ } }	 t |  } | j }
 x@ | D]8 \ } } | | d } | | <| r5|
 | | 9}
 q5q5W|
 j t |  |	 f  }
 | |
 7} qW| S(   NRV   c           s     |  d S(   Ni    (    (   R   (   t   gens_map(    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRQ   Q	  RR   s9   expected a generator, value pair a sequence of such pairsi    (   R0   R   R   R8   R|   R,   R   Rh   R:   RH   R  R   R   R   R   R   Rl   R  RW   (   RU   Ry  RO   R0   R   t   replacementsR   Rh  R   R   t   subpolyR   R0  (    (   R  s0   lib/python2.7/site-packages/sympy/polys/rings.pyR   F	  s,    		-*!	c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_pdiv(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   pdivi	  s    c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_prem(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   preml	  s    c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_quo(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   pquoo	  s    c         C  s   |  j  j |  |  S(   N(   R0   t	   dmp_exquo(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   pexquor	  s    c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_half_gcdex(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt
   half_gcdexu	  s    c         C  s   |  j  j |  |  S(   N(   R0   t	   dmp_gcdex(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   gcdexx	  s    c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_subresultants(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   subresultants{	  s    c         C  s   |  j  j |  |  S(   N(   R0   t   dmp_resultant(   RU   Rh  (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   resultant~	  s    c         C  s   |  j  j |   S(   N(   R0   t   dmp_discriminant(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   discriminant	  s    c         C  s,   |  j  j r |  j  j |   St d   d  S(   Ns   polynomial decomposition(   R0   R   t   dup_decomposeR!   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt	   decompose	  s    c         C  s/   |  j  j r |  j  j |  |  St d   d  S(   Ns   polynomial shift(   R0   R   t	   dup_shiftR!   (   RU   RO   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   shift	  s    c         C  s,   |  j  j r |  j  j |   St d   d  S(   Ns   sturm sequence(   R0   R   t	   dup_sturmR!   (   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sturm	  s    c         C  s   |  j  j |   S(   N(   R0   t   dmp_gff_list(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   gff_list	  s    c         C  s   |  j  j |   S(   N(   R0   t   dmp_sqf_norm(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sqf_norm	  s    c         C  s   |  j  j |   S(   N(   R0   t   dmp_sqf_part(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sqf_part	  s    c         C  s   |  j  j |  d | S(   NRL   (   R0   t   dmp_sqf_list(   RU   RL   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   sqf_list	  s    c         C  s   |  j  j |   S(   N(   R0   t   dmp_factor_list(   RU   (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   factor_list	  s    N(   R\   R   R   R   R   R   R:   Re   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  R   R  R  R  R  R  R  R  R  R  R!  R#  R$  R&  R(  R*  R+  R,  R/  R-  R2  R1  R9  R3  R=  R<  R;  R:  RL  RI  RO  RN  RR  RQ  t   __floordiv__t   __div__t   __rfloordiv__t   __rdiv__R[  Ru   RM  RP  Ru  R]  R^  Rz  R{  R}  R~  R{   R  R   R   R  R  R  Ri  R  R  RC   R  R   R  R"  R   R  R  R  RC  R   R  R  R   R  R  RJ  R  R  RK  R  R  R  R  R  R  Rw   Ry   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  R  R  R6   R  R  (    (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyRN   .  s  																										0			6		6		2		0			$						

	!	L	-			,	%					%											#														!								
			9		,'#															N(O   R   t
   __future__R    R   t   operatorR   R   R   R   R   R   t   typesR   t   sympy.core.compatibilityR	   R
   R   R   t   sympy.core.exprR   t   sympy.core.numbersR   R   t   sympy.core.symbolR   R   RK   t   sympy.core.sympifyR   R   t   sympy.ntheory.multinomialR   t   sympy.polys.compatibilityR   t   sympy.polys.constructorR   t   sympy.polys.densebasicR   R   t!   sympy.polys.domains.domainelementR   t"   sympy.polys.domains.polynomialringR   t   sympy.polys.heuristicgcdR   t   sympy.polys.monomialsR   t   sympy.polys.orderingsR   t   sympy.polys.polyerrorsR   R   R    R!   t   sympy.polys.polyoptionsR"   RY   R#   R[   R$   t   sympy.polys.polyutilsR%   R&   R'   t   sympy.printing.defaultsR(   t   sympy.utilitiesR)   t   sympy.utilities.magicR*   R0   R1   R4   RF   RM   R]   R+   R   RN   (    (    (    s0   lib/python2.7/site-packages/sympy/polys/rings.pyt   <module>   sF   .""   7	 e