ó
¡¼™\c           @  sÌ  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m 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 „  Z0 d  „  Z1 d! „  Z2 d" „  Z3 d# „  Z4 d$ „  Z5 d% „  Z6 d& „  Z7 d' „  Z8 d( „  Z9 d) „  Z: d* „  Z; d+ „  Z< d, „  Z= d- „  Z> d. „  Z? d/ „  Z@ d0 „  ZA d1 „  ZB d2 „  ZC d3 „  ZD d4 „  ZE d5 „  ZF d6 „  ZG d7 „  ZH d8 „  ZI d9 „  ZJ d: „  ZK d; „  ZL d< „  ZM d= „  ZN d> „  ZO d? „  ZP d@ „  ZQ dA „  ZR dB „  ZS dC „  ZT dD S(E   sE   Arithmetics for dense recursive polynomials in ``K[x]`` or ``K[X]``. iÿÿÿÿ(   t   print_functiont   division(   t   range(   t	   dup_slicet   dup_LCt   dmp_LCt
   dup_degreet
   dmp_degreet	   dup_stript	   dmp_stript
   dmp_zero_pt   dmp_zerot	   dmp_one_pt   dmp_onet
   dmp_groundt	   dmp_zeros(   t   ExactQuotientFailedt   PolynomialDivisionFailedc         C  s¡   | s
 |  St  |  ƒ } | | d } | | d k rQ t |  d | g |  d ƒ S| | k rz | g | j g | | |  S|  |  |  | | g |  | d Sd S(   sÓ   
    Add ``c*x**i`` to ``f`` in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_add_term(x**2 - 1, ZZ(2), 4)
    2*x**4 + x**2 - 1

    i   i    N(   t   lenR   t   zero(   t   ft   ct   it   Kt   nt   m(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_add_term   s    c         C  sè   | s t  |  | | | ƒ S| d } t | | ƒ r6 |  St |  ƒ } | | d } | | d k r‹ t t |  d | | | ƒ g |  d | ƒ S| | k r¶ | g t | | | | ƒ |  S|  |  t |  | | | | ƒ g |  | d Sd S(   sÝ   
    Add ``c(x_2..x_u)*x_0**i`` to ``f`` in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_add_term(x*y + 1, 2, 2)
    2*x**2 + x*y + 1

    i   i    N(   R   R
   R   R	   t   dmp_addR   (   R   R   R   t   uR   t   vR   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_add_term-   s    
+c         C  s¢   | s
 |  St  |  ƒ } | | d } | | d k rQ t |  d | g |  d ƒ S| | k r{ | g | j g | | |  S|  |  |  | | g |  | d Sd S(   sÚ   
    Subtract ``c*x**i`` from ``f`` in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_sub_term(2*x**4 + x**2 - 1, ZZ(2), 4)
    x**2 - 1

    i   i    N(   R   R   R   (   R   R   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_sub_termO   s    c         C  sõ   | s t  |  | | | ƒ S| d } t | | ƒ r7 |  St |  ƒ } | | d } | | d k rŒ t t |  d | | | ƒ g |  d | ƒ S| | k rÃ t | | | ƒ g t | | | | ƒ |  S|  |  t |  | | | | ƒ g |  | d Sd S(   sä   
    Subtract ``c(x_2..x_u)*x_0**i`` from ``f`` in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_sub_term(2*x**2 + x*y + 1, 2, 2)
    x*y + 1

    i   i    N(   R   R
   R   R	   t   dmp_subt   dmp_negR   (   R   R   R   R   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_sub_terml   s    
++c         C  s?   | s |  r g  Sg  |  D] } | | ^ q | j  g | Sd S(   sÖ   
    Multiply ``f`` by ``c*x**i`` in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_mul_term(x**2 - 1, ZZ(3), 2)
    3*x**4 - 3*x**2

    N(   R   (   R   R   R   R   t   cf(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_mul_termŽ   s    c         C  s‰   | s t  |  | | | ƒ S| d } t |  | ƒ r6 |  St | | ƒ rO t | ƒ Sg  |  D] } t | | | | ƒ ^ qV t | | | ƒ Sd S(   sí   
    Multiply ``f`` by ``c(x_2..x_u)*x_0**i`` in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_mul_term(x**2*y + x, 3*y, 2)
    3*x**4*y**2 + 3*x**3*y

    i   N(   R$   R
   R   t   dmp_mulR   (   R   R   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_mul_term¢   s    

c         C  s   t  |  | d | ƒ S(   sð   
    Add an element of the ground domain to ``f``.

    Examples
    ========

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

    >>> R.dup_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
    x**3 + 2*x**2 + 3*x + 8

    i    (   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_add_ground½   s    c         C  s#   t  |  t | | d ƒ d | | ƒ S(   sô   
    Add an element of the ground domain to ``f``.

    Examples
    ========

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

    >>> R.dmp_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
    x**3 + 2*x**2 + 3*x + 8

    i   i    (   R   R   (   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_add_groundÎ   s    c         C  s   t  |  | d | ƒ S(   só   
    Subtract an element of the ground domain from ``f``.

    Examples
    ========

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

    >>> R.dup_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
    x**3 + 2*x**2 + 3*x

    i    (   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_sub_groundß   s    c         C  s#   t  |  t | | d ƒ d | | ƒ S(   s÷   
    Subtract an element of the ground domain from ``f``.

    Examples
    ========

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

    >>> R.dmp_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
    x**3 + 2*x**2 + 3*x

    i   i    (   R"   R   (   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_sub_groundð   s    c         C  s1   | s |  r g  Sg  |  D] } | | ^ q Sd S(   sâ   
    Multiply ``f`` by a constant value in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_mul_ground(x**2 + 2*x - 1, ZZ(3))
    3*x**2 + 6*x - 3

    N(    (   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_mul_ground  s    c         C  sF   | s t  |  | | ƒ S| d } g  |  D] } t | | | | ƒ ^ q' S(   sÚ   
    Multiply ``f`` by a constant value in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_mul_ground(2*x + 2*y, ZZ(3))
    6*x + 6*y

    i   (   R+   t   dmp_mul_ground(   R   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR,     s    
c         C  sj   | s t  d ƒ ‚ n  |  s |  S| j rK g  |  D] } | j | | ƒ ^ q/ Sg  |  D] } | | ^ qR Sd S(   s)  
    Quotient by a constant in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x = ring("x", ZZ)
    >>> R.dup_quo_ground(3*x**2 + 2, ZZ(2))
    x**2 + 1

    >>> R, x = ring("x", QQ)
    >>> R.dup_quo_ground(3*x**2 + 2, QQ(2))
    3/2*x**2 + 1

    s   polynomial divisionN(   t   ZeroDivisionErrort   is_Fieldt   quo(   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_quo_ground+  s    	#c         C  sF   | s t  |  | | ƒ S| d } g  |  D] } t | | | | ƒ ^ q' S(   s=  
    Quotient by a constant in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x,y = ring("x,y", ZZ)
    >>> R.dmp_quo_ground(2*x**2*y + 3*x, ZZ(2))
    x**2*y + x

    >>> R, x,y = ring("x,y", QQ)
    >>> R.dmp_quo_ground(2*x**2*y + 3*x, QQ(2))
    x**2*y + 3/2*x

    i   (   R0   t   dmp_quo_ground(   R   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR1   H  s    
c         C  sB   | s t  d ƒ ‚ n  |  s |  Sg  |  D] } | j | | ƒ ^ q& S(   sÔ   
    Exact quotient by a constant in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_exquo_ground(x**2 + 2, QQ(2))
    1/2*x**2 + 1

    s   polynomial division(   R-   t   exquo(   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_exquo_groundb  s
    c         C  sF   | s t  |  | | ƒ S| d } g  |  D] } t | | | | ƒ ^ q' S(   sÞ   
    Exact quotient by a constant in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_exquo_ground(x**2*y + 2*x, QQ(2))
    1/2*x**2*y + x

    i   (   R3   t   dmp_exquo_ground(   R   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR4   x  s    
c         C  s    |  s
 |  S|  | j  g | Sd S(   sÓ   
    Efficiently multiply ``f`` by ``x**n`` in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_lshift(x**2 + 1, 2)
    x**4 + x**2

    N(   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_lshiftŽ  s    c         C  s	   |  |  S(   s  
    Efficiently divide ``f`` by ``x**n`` in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_rshift(x**4 + x**2, 2)
    x**2 + 1
    >>> R.dup_rshift(x**4 + x**2 + 2, 2)
    x**2 + 1

    (    (   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_rshift¢  s    c         C  s    g  |  D] } | j  | ƒ ^ q S(   sÂ   
    Make all coefficients positive in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_abs(x**2 - 1)
    x**2 + 1

    (   t   abs(   R   R   t   coeff(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_absµ  s    c         C  s@   | s t  |  | ƒ S| d } g  |  D] } t | | | ƒ ^ q$ S(   sÊ   
    Make all coefficients positive in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_abs(x**2*y - x)
    x**2*y + x

    i   (   R9   t   dmp_abs(   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR:   Æ  s    
c         C  s   g  |  D] } | ^ q S(   s¸   
    Negate a polynomial in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_neg(x**2 - 1)
    -x**2 + 1

    (    (   R   R   R8   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_negÜ  s    c         C  s@   | s t  |  | ƒ S| d } g  |  D] } t | | | ƒ ^ q$ S(   sÀ   
    Negate a polynomial in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_neg(x**2*y - x)
    -x**2*y + x

    i   (   R;   R!   (   R   R   R   R   R#   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR!   í  s    
c   	      C  sã   |  s
 | S| s |  St  |  ƒ } t  | ƒ } | | k rh t g  t |  | ƒ D] \ } } | | ^ qK ƒ St | | ƒ } | | k rœ |  |  |  | } }  n | |  | | } } | g  t |  | ƒ D] \ } } | | ^ qÄ Sd S(   sÄ   
    Add dense polynomials in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_add(x**2 - 1, x - 2)
    x**2 + x - 3

    N(   R   R   t   zipR7   (	   R   t   gR   t   dft   dgt   at   bt   kt   h(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_add  s    0c         C  s.  | s t  |  | | ƒ St |  | ƒ } | d k  r5 | St | | ƒ } | d k  rT |  S| d } | | k r¨ t g  t |  | ƒ D]! \ } } t | | | | ƒ ^ q} | ƒ St | | ƒ }	 | | k rÜ |  |	  |  |	 }
 }  n | |	  | |	 }
 } |
 g  t |  | ƒ D]! \ } } t | | | | ƒ ^ qSd S(   sÖ   
    Add dense polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_add(x**2 + y, x**2*y + x)
    x**2*y + x**2 + x + y

    i    i   N(   RD   R   R	   R<   R   R7   (   R   R=   R   R   R>   R?   R   R@   RA   RB   RC   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR   &  s     
>c   	      C  sõ   |  s t  | | ƒ S| s |  St |  ƒ } t | ƒ } | | k rq t g  t |  | ƒ D] \ } } | | ^ qT ƒ St | | ƒ } | | k r¥ |  |  |  | } }  n t  | |  | ƒ | | } } | g  t |  | ƒ D] \ } } | | ^ qÖ Sd S(   sÉ   
    Subtract dense polynomials in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_sub(x**2 - 1, x - 2)
    x**2 - x + 1

    N(   R;   R   R   R<   R7   (	   R   R=   R   R>   R?   R@   RA   RB   RC   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_subP  s    0c         C  sF  | s t  |  | | ƒ St |  | ƒ } | d k  rA t | | | ƒ St | | ƒ } | d k  r` |  S| d } | | k r´ t g  t |  | ƒ D]! \ } } t | | | | ƒ ^ q‰ | ƒ St | | ƒ }	 | | k rè |  |	  |  |	 }
 }  n! t | |	  | | ƒ | |	 }
 } |
 g  t |  | ƒ D]! \ } } t | | | | ƒ ^ qSd S(   sÜ   
    Subtract dense polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_sub(x**2 + y, x**2*y + x)
    -x**2*y + x**2 - x + y

    i    i   N(   RE   R   R!   R	   R<   R    R7   (   R   R=   R   R   R>   R?   R   R@   RA   RB   RC   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR    s  s     
>!c         C  s   t  |  t | | | ƒ | ƒ S(   sá   
    Returns ``f + g*h`` where ``f, g, h`` are in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_add_mul(x**2 - 1, x - 2, x + 2)
    2*x**2 - 5

    (   RD   t   dup_mul(   R   R=   RC   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_add_mul  s    c         C  s"   t  |  t | | | | ƒ | | ƒ S(   sç   
    Returns ``f + g*h`` where ``f, g, h`` are in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_add_mul(x**2 + y, x, x + 2)
    2*x**2 + 2*x + y

    (   R   R%   (   R   R=   RC   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_add_mul®  s    c         C  s   t  |  t | | | ƒ | ƒ S(   sØ   
    Returns ``f - g*h`` where ``f, g, h`` are in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_sub_mul(x**2 - 1, x - 2, x + 2)
    3

    (   RE   RF   (   R   R=   RC   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_sub_mul¿  s    c         C  s"   t  |  t | | | | ƒ | | ƒ S(   sß   
    Returns ``f - g*h`` where ``f, g, h`` are in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_sub_mul(x**2 + y, x, x + 2)
    -2*x + y

    (   R    R%   (   R   R=   RC   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_sub_mulÐ  s    c         C  s  |  | k r t  |  | ƒ S|  o" | s) g  St |  ƒ } t | ƒ } t | | ƒ d } | d k  rö g  } xƒ t d | | d ƒ D]j } | j } xK t t d | | ƒ t | | ƒ d ƒ D]  }	 | |  |	 | | |	 7} q· W| j | ƒ q~ Wt | ƒ S| d }
 t |  d |
 | ƒ t | d |
 | ƒ } } t	 t |  |
 | | ƒ |
 | ƒ } t	 t | |
 | | ƒ |
 | ƒ } t
 | | | ƒ t
 | | | ƒ } } t
 t | | | ƒ t | | | ƒ | ƒ } t | t | | | ƒ | ƒ } t t | t | |
 | ƒ | ƒ t | d |
 | ƒ | ƒ Sd S(   sÂ   
    Multiply dense polynomials in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_mul(x - 2, x + 2)
    x**2 - 4

    i   id   i    i   N(   t   dup_sqrR   t   maxR   R   t   mint   appendR   R   R6   RF   RD   RE   R5   (   R   R=   R   R>   R?   R   RC   R   R8   t   jt   n2t   flt   glt   fht   ght   lot   hit   mid(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRF   á  s0    	0

+!!%*c      	   C  s-  | s t  |  | | ƒ S|  | k r2 t |  | | ƒ St |  | ƒ } | d k  rQ |  St | | ƒ } | d k  rp | Sg  | d } } xœ t d | | d ƒ D]ƒ } t | ƒ }	 xa t t d | | ƒ t | | ƒ d ƒ D]6 }
 t |	 t |  |
 | | |
 | | ƒ | | ƒ }	 qÕ W| j	 |	 ƒ q™ Wt
 | | ƒ S(   sÆ   
    Multiply dense polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_mul(x*y + 1, x)
    x**2*y + x

    i    i   (   RF   t   dmp_sqrR   R   R   RL   RM   R   R%   RN   R	   (   R   R=   R   R   R>   R?   RC   R   R   R8   RO   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR%     s"    04c         C  s  t  |  ƒ d g  } } xâ t d d | d ƒ D]É } | j } t d | | ƒ } t | | ƒ } | | d } | | d d } x5 t | | d ƒ D]  }	 | |  |	 |  | |	 7} q” W| | 7} | d @rë |  | d }
 | |
 d 7} n  | j | ƒ q/ Wt | ƒ S(   sÅ   
    Square dense polynomials in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_sqr(x**2 + 1)
    x**4 + 2*x**2 + 1

    i   i    i   (   R   R   R   RL   RM   RN   R   (   R   R   R>   RC   R   R   t   jmint   jmaxR   RO   t   elem(    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRK   E  s    	

c      	   C  sr  | s t  |  | ƒ St |  | ƒ } | d k  r2 |  Sg  | d } } xt d d | d ƒ D]} t | ƒ } t d | | ƒ } t | | ƒ }	 |	 | d }
 | |
 d d }	 xK t | |	 d ƒ D]6 } t | t |  | |  | | | | ƒ | | ƒ } qÃ Wt | | d ƒ | | ƒ } |
 d @rTt	 |  |	 d | | ƒ } t | | | | ƒ } n  | j
 | ƒ q[ Wt | | ƒ S(   sð   
    Square dense polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_sqr(x**2 + x*y + y**2)
    x**4 + 2*x**3*y + 3*x**2*y**2 + 2*x*y**3 + y**4

    i    i   i   (   RK   R   R   R   RL   RM   R   R%   R,   RX   RN   R	   (   R   R   R   R>   RC   R   R   R   RY   RZ   R   RO   R[   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRX   m  s(    4
c         C  sº   | s | j  g S| d k  r+ t d ƒ ‚ n  | d k sP |  sP |  | j  g k rT |  S| j  g } xS t rµ | d | } } | d r£ t | |  | ƒ } | s£ Pq£ n  t |  | ƒ }  qc W| S(   sÕ   
    Raise ``f`` to the ``n``-th power in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_pow(x - 2, 3)
    x**3 - 6*x**2 + 12*x - 8

    i    s*   can't raise polynomial to a negative poweri   i   (   t   onet
   ValueErrort   TrueRF   RK   (   R   R   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_pow  s    
%	
c         C  sä   | s t  |  | | ƒ S| s) t | | ƒ S| d k  rD t d ƒ ‚ n  | d k sq t |  | ƒ sq t |  | | ƒ ru |  St | | ƒ } xY t rß | d | } } | d @rÊ t | |  | | ƒ } | sÊ PqÊ n  t |  | | ƒ }  q‡ W| S(   sæ   
    Raise ``f`` to the ``n``-th power in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_pow(x*y + 1, 3)
    x**3*y**3 + 3*x**2*y**2 + 3*x*y + 1

    i    s*   can't raise polynomial to a negative poweri   i   (   R_   R   R]   R
   R   R^   R%   RX   (   R   R   R   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_powÂ  s"    -	
c         C  s  t  |  ƒ } t  | ƒ } g  |  | } } } | sA t d ƒ ‚ n | | k  rW | | f S| | d } t | | ƒ }	 xÒ t rHt | | ƒ }
 | | | d } } t | |	 | ƒ } t | |
 | | ƒ } t | |	 | ƒ } t | |
 | | ƒ } t | | | ƒ } | t  | ƒ } } | | k  r$Pqw | | k  sw t |  | | ƒ ‚ qw qw W|	 | } t | | | ƒ } t | | | ƒ } | | f S(   sÍ   
    Polynomial pseudo-division in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_pdiv(x**2 + 1, 2*x - 4)
    (2*x + 4, 20)

    s   polynomial divisioni   (	   R   R-   R   R^   R+   R   R$   RE   R   (   R   R=   R   R>   R?   t   qt   rt   drt   Nt   lc_gt   lc_rRO   t   Qt   Rt   Gt   _drR   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_pdivê  s4    
	
c         C  s)  t  |  ƒ } t  | ƒ } |  | } } | s: t d ƒ ‚ n | | k  rJ | S| | d } t | | ƒ } x« t rt | | ƒ }	 | | | d }
 } t | | | ƒ } t | |	 |
 | ƒ } t | | | ƒ } | t  | ƒ } } | | k  rð Pqj | | k  sj t |  | | ƒ ‚ qj qj Wt | | | | ƒ S(   sÃ   
    Polynomial pseudo-remainder in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_prem(x**2 + 1, 2*x - 4)
    20

    s   polynomial divisioni   (   R   R-   R   R^   R+   R$   RE   R   (   R   R=   R   R>   R?   Rb   Rc   Rd   Re   Rf   RO   Rh   Ri   Rj   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_prem  s*    	c         C  s   t  |  | | ƒ d S(   s   
    Polynomial exact pseudo-quotient in ``K[X]``.

    Examples
    ========

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

    >>> R.dup_pquo(x**2 - 1, 2*x - 2)
    2*x + 2

    >>> R.dup_pquo(x**2 + 1, 2*x - 4)
    2*x + 4

    i    (   Rk   (   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_pquoL  s    c         C  s5   t  |  | | ƒ \ } } | s" | St |  | ƒ ‚ d S(   s\  
    Polynomial pseudo-quotient in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_pexquo(x**2 - 1, 2*x - 2)
    2*x + 2

    >>> R.dup_pexquo(x**2 + 1, 2*x - 4)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]

    N(   Rk   R   (   R   R=   R   Ra   Rb   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_pexquo`  s    c         C  sÜ  | s t  |  | | ƒ St |  | ƒ } t | | ƒ } | d k  rO t d ƒ ‚ n  t | ƒ |  | } } } | | k  r | | f S| | d }	 t | | ƒ }
 xê t rˆt | | ƒ } | | |	 d } }	 t | |
 d | | ƒ } t | | | | | ƒ } t | |
 d | | ƒ } t | | | | | ƒ } t | | | | ƒ } | t | | ƒ } } | | k  rdPqŸ | | k  sŸ t	 |  | | ƒ ‚ qŸ qŸ Wt
 |
 |	 | d | ƒ } t | | d | | ƒ } t | | d | | ƒ } | | f S(   sß   
    Polynomial pseudo-division in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_pdiv(x**2 + x*y, 2*x + 2)
    (2*x + 2*y - 2, -4*y + 4)

    i    s   polynomial divisioni   (   Rk   R   R-   R   R   R^   R&   R   R    R   R`   (   R   R=   R   R   R>   R?   Ra   Rb   Rc   Rd   Re   Rf   RO   Rg   Rh   Ri   Rj   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_pdiv{  s8    
	c         C  su  | s t  |  | | ƒ St |  | ƒ } t | | ƒ } | d k  rO t d ƒ ‚ n  |  | } } | | k  rl | S| | d } t | | ƒ }	 xº t rEt | | ƒ }
 | | | d } } t | |	 d | | ƒ } t | |
 | | | ƒ } t | | | | ƒ } | t | | ƒ } } | | k  r!PqŒ | | k  sŒ t |  | | ƒ ‚ qŒ qŒ Wt |	 | | d | ƒ } t | | d | | ƒ S(   sÏ   
    Polynomial pseudo-remainder in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_prem(x**2 + x*y, 2*x + 2)
    -4*y + 4

    i    s   polynomial divisioni   (	   Rl   R   R-   R   R^   R&   R    R   R`   (   R   R=   R   R   R>   R?   Rb   Rc   Rd   Re   Rf   RO   Rh   Ri   Rj   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_prem´  s0    	c         C  s   t  |  | | | ƒ d S(   s.  
    Polynomial exact pseudo-quotient in ``K[X]``.

    Examples
    ========

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

    >>> f = x**2 + x*y
    >>> g = 2*x + 2*y
    >>> h = 2*x + 2

    >>> R.dmp_pquo(f, g)
    2*x

    >>> R.dmp_pquo(f, h)
    2*x + 2*y - 2

    i    (   Ro   (   R   R=   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_pquoç  s    c         C  sA   t  |  | | | ƒ \ } } t | | ƒ r. | St |  | ƒ ‚ d S(   s  
    Polynomial pseudo-quotient in ``K[X]``.

    Examples
    ========

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

    >>> f = x**2 + x*y
    >>> g = 2*x + 2*y
    >>> h = 2*x + 2

    >>> R.dmp_pexquo(f, g)
    2*x

    >>> R.dmp_pexquo(f, h)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]

    N(   Ro   R
   R   (   R   R=   R   R   Ra   Rb   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dmp_pexquoÿ  s    c         C  s6  t  |  ƒ } t  | ƒ } g  |  | } } } | sA t d ƒ ‚ n | | k  rW | | f St | | ƒ } xÃ t r+t | | ƒ }	 |	 | rŒ Pn  | j |	 | ƒ }
 | | } t | |
 | | ƒ } t | |
 | | ƒ } t | | | ƒ } | t  | ƒ } } | | k  rPqi | | k  si t |  | | ƒ ‚ qi qi W| | f S(   s×   
    Univariate division with remainder over a ring.

    Examples
    ========

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

    >>> R.dup_rr_div(x**2 + 1, 2*x - 4)
    (0, x**2 + 1)

    s   polynomial division(	   R   R-   R   R^   R2   R   R$   RE   R   (   R   R=   R   R>   R?   Ra   Rb   Rc   Re   Rf   R   RO   RC   Rj   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_rr_div  s.    
	

c         C  sƒ  | s t  |  | | ƒ St |  | ƒ } t | | ƒ } | d k  rO t d ƒ ‚ n  t | ƒ |  | } } } | | k  r | | f St | | ƒ | d }	 }
 xÝ t rxt | | ƒ } t | |	 |
 | ƒ \ } } t | |
 ƒ sß Pn  | | } t | | | | | ƒ } t	 | | | | | ƒ } t
 | | | | ƒ } | t | | ƒ } } | | k  rTPqœ | | k  sœ t |  | | ƒ ‚ qœ qœ W| | f S(   sá   
    Multivariate division with remainder over a ring.

    Examples
    ========

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

    >>> R.dmp_rr_div(x**2 + x*y, 2*x + 2)
    (0, x**2 + x*y)

    i    s   polynomial divisioni   (   Rs   R   R-   R   R   R^   t
   dmp_rr_divR
   R   R&   R    R   (   R   R=   R   R   R>   R?   Ra   Rb   Rc   Re   R   Rf   R   Rh   RO   RC   Rj   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRt   O  s2    
	
c         C  s(  t  |  ƒ } t  | ƒ } g  |  | } } } | sA t d ƒ ‚ n | | k  rW | | f St | | ƒ } xµ t rt | | ƒ }	 | j |	 | ƒ }
 | | } t | |
 | | ƒ } t | |
 | | ƒ } t | | | ƒ } | t  | ƒ } } | | k  rù Pqi | | k  si t |  | | ƒ ‚ qi qi W| | f S(   sÙ   
    Polynomial division with remainder over a field.

    Examples
    ========

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

    >>> R.dup_ff_div(x**2 + 1, 2*x - 4)
    (1/2*x + 1, 5)

    s   polynomial division(	   R   R-   R   R^   R2   R   R$   RE   R   (   R   R=   R   R>   R?   Ra   Rb   Rc   Re   Rf   R   RO   RC   Rj   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_ff_div„  s*    
	
c         C  sƒ  | s t  |  | | ƒ St |  | ƒ } t | | ƒ } | d k  rO t d ƒ ‚ n  t | ƒ |  | } } } | | k  r | | f St | | ƒ | d }	 }
 xÝ t rxt | | ƒ } t | |	 |
 | ƒ \ } } t | |
 ƒ sß Pn  | | } t | | | | | ƒ } t	 | | | | | ƒ } t
 | | | | ƒ } | t | | ƒ } } | | k  rTPqœ | | k  sœ t |  | | ƒ ‚ qœ qœ W| | f S(   sî   
    Polynomial division with remainder over a field.

    Examples
    ========

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

    >>> R.dmp_ff_div(x**2 + x*y, 2*x + 2)
    (1/2*x + 1/2*y - 1/2, -y + 1)

    i    s   polynomial divisioni   (   Ru   R   R-   R   R   R^   t
   dmp_ff_divR
   R   R&   R    R   (   R   R=   R   R   R>   R?   Ra   Rb   Rc   Re   R   Rf   R   Rh   RO   RC   Rj   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRv   ²  s2    
	
c         C  s-   | j  r t |  | | ƒ St |  | | ƒ Sd S(   s.  
    Polynomial division with remainder in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x = ring("x", ZZ)
    >>> R.dup_div(x**2 + 1, 2*x - 4)
    (0, x**2 + 1)

    >>> R, x = ring("x", QQ)
    >>> R.dup_div(x**2 + 1, 2*x - 4)
    (1/2*x + 1, 5)

    N(   R.   Ru   Rs   (   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_divç  s    	c         C  s   t  |  | | ƒ d S(   s  
    Returns polynomial remainder in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x = ring("x", ZZ)
    >>> R.dup_rem(x**2 + 1, 2*x - 4)
    x**2 + 1

    >>> R, x = ring("x", QQ)
    >>> R.dup_rem(x**2 + 1, 2*x - 4)
    5

    i   (   Rw   (   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_remÿ  s    c         C  s   t  |  | | ƒ d S(   s  
    Returns exact polynomial quotient in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x = ring("x", ZZ)
    >>> R.dup_quo(x**2 + 1, 2*x - 4)
    0

    >>> R, x = ring("x", QQ)
    >>> R.dup_quo(x**2 + 1, 2*x - 4)
    1/2*x + 1

    i    (   Rw   (   R   R=   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_quo  s    c         C  s5   t  |  | | ƒ \ } } | s" | St |  | ƒ ‚ d S(   sW  
    Returns polynomial quotient in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_exquo(x**2 - 1, x - 1)
    x + 1

    >>> R.dup_exquo(x**2 + 1, 2*x - 4)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]

    N(   Rw   R   (   R   R=   R   Ra   Rb   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt	   dup_exquo)  s    c         C  s3   | j  r t |  | | | ƒ St |  | | | ƒ Sd S(   sK  
    Polynomial division with remainder in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x,y = ring("x,y", ZZ)
    >>> R.dmp_div(x**2 + x*y, 2*x + 2)
    (0, x**2 + x*y)

    >>> R, x,y = ring("x,y", QQ)
    >>> R.dmp_div(x**2 + x*y, 2*x + 2)
    (1/2*x + 1/2*y - 1/2, -y + 1)

    N(   R.   Rv   Rt   (   R   R=   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_divD  s    	c         C  s   t  |  | | | ƒ d S(   s)  
    Returns polynomial remainder in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x,y = ring("x,y", ZZ)
    >>> R.dmp_rem(x**2 + x*y, 2*x + 2)
    x**2 + x*y

    >>> R, x,y = ring("x,y", QQ)
    >>> R.dmp_rem(x**2 + x*y, 2*x + 2)
    -y + 1

    i   (   R{   (   R   R=   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_rem\  s    c         C  s   t  |  | | | ƒ d S(   s2  
    Returns exact polynomial quotient in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ, QQ

    >>> R, x,y = ring("x,y", ZZ)
    >>> R.dmp_quo(x**2 + x*y, 2*x + 2)
    0

    >>> R, x,y = ring("x,y", QQ)
    >>> R.dmp_quo(x**2 + x*y, 2*x + 2)
    1/2*x + 1/2*y - 1/2

    i    (   R{   (   R   R=   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dmp_quoq  s    c         C  sA   t  |  | | | ƒ \ } } t | | ƒ r. | St |  | ƒ ‚ d S(   sˆ  
    Returns polynomial quotient in ``K[X]``.

    Examples
    ========

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

    >>> f = x**2 + x*y
    >>> g = x + y
    >>> h = 2*x + 2

    >>> R.dmp_exquo(f, g)
    x

    >>> R.dmp_exquo(f, h)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]

    N(   R{   R
   R   (   R   R=   R   R   Ra   Rb   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt	   dmp_exquo†  s    c         C  s$   |  s | j  St t |  | ƒ ƒ Sd S(   sÍ   
    Returns maximum norm of a polynomial in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_max_norm(-x**2 + 2*x - 3)
    3

    N(   R   RL   R9   (   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_max_norm¥  s    c         C  sF   | s t  |  | ƒ S| d } t g  |  D] } t | | | ƒ ^ q' ƒ S(   sÏ   
    Returns maximum norm of a polynomial in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_max_norm(2*x*y - x - 3)
    3

    i   (   R   RL   t   dmp_max_norm(   R   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyR€   ¹  s    
c         C  s$   |  s | j  St t |  | ƒ ƒ Sd S(   sË   
    Returns l1 norm of a polynomial in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_l1_norm(2*x**3 - 3*x**2 + 1)
    6

    N(   R   t   sumR9   (   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   dup_l1_normÏ  s    c         C  sF   | s t  |  | ƒ S| d } t g  |  D] } t | | | ƒ ^ q' ƒ S(   sÉ   
    Returns l1 norm of a polynomial in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_l1_norm(2*x*y - x - 3)
    6

    i   (   R‚   R   t   dmp_l1_norm(   R   R   R   R   R   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyRƒ   ã  s    
c         C  sE   |  s | j  g S|  d } x$ |  d D] } t | | | ƒ } q% W| S(   sØ   
    Multiply together several polynomials in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_expand([x**2 - 1, x, 2])
    2*x**3 - 2*x

    i    i   (   R\   RF   (   t   polysR   R   R=   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dup_expandù  s    

c         C  sK   |  s t  | | ƒ S|  d } x' |  d D] } t | | | | ƒ } q( W| S(   sï   
    Multiply together several polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_expand([x**2 + y**2, x + 1])
    x**3 + x**2 + x*y**2 + y**2

    i    i   (   R   R%   (   R„   R   R   R   R=   (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt
   dmp_expand  s    
N(U   t   __doc__t
   __future__R    R   t   sympy.core.compatibilityR   t   sympy.polys.densebasicR   R   R   R   R   R   R	   R
   R   R   R   R   R   t   sympy.polys.polyerrorsR   R   R   R   R   R"   R$   R&   R'   R(   R)   R*   R+   R,   R0   R1   R3   R4   R5   R6   R9   R:   R;   R!   RD   R   RE   R    RG   RH   RI   RJ   RF   R%   RK   RX   R_   R`   Rk   Rl   Rm   Rn   Ro   Rp   Rq   Rr   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R{   R|   R}   R~   R   R€   R‚   Rƒ   R…   R†   (    (    (    s5   lib/python2.7/site-packages/sympy/polys/densearith.pyt   <module>   s„   X		"		"																			#	*	#	*					9	+	(	0	%	(	5	-			9	3			1	5	.	5													