
\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	 d d l
 m Z m Z m Z m Z m Z m Z 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 d d l m Z d d l m  Z  m! Z! d d	 l" m# Z# m$ Z$ d
   Z% d   Z& d   Z' d   Z( d   Z) e* d  Z+ dN dN dN e* e* d  Z- dN dN dN e* d  Z. dN dN dN e* d  Z/ dN e* d  Z0 d   Z1 dN dN dN e* e* d  Z2 dN dN dN e* e* d  Z3 e* e* d  Z4 dN dN dN e* e* d  Z5 dN dN dN e* e* d  Z6 dN dN dN e* e* e* d  Z7 e* d  Z8 dN dN dN e* e* e* d  Z9 dN dN d  Z: d Z; d Z< d  Z= d! Z> d" Z? d# Z@ d$ ZA d% ZB d& ZC i d' e< e< f 6d' e= e= f 6d' e> e> f 6d' e? e? f 6d( e@ e< f 6d( eA e= f 6d( eB e> f 6d( eC e? f 6d) e@ e? f 6d) eA e< f 6d) eB e= f 6d) eC e> f 6d* e< eA f 6d* e= eB f 6d* e> eC f 6d* e? e@ f 6d+ e< e@ f 6d+ e= eA f 6d+ e> eB f 6d+ e? eC f 6d, 
e< e= f 6d, 
e= e> f 6d, 
e> e? f 6d, 
e? e< f 6d- e< e? f 6d- e= e< f 6d- e> e= f 6d- e? e> f 6ZD i` d e@ e; e< f 6d eA e; e= f 6d eB e; e> f 6d eC e; e? f 6d. e@ e; e? f 6d. eA e; e< f 6d. eB e; e= f 6d. eC e; e> f 6d/ e< e; eA f 6d/ e= e; eB f 6d/ e> e; eC f 6d/ e? e; e@ f 6d0 e< e; e@ f 6d0 e= e; eA f 6d0 e> e; eB f 6d0 e? e; eC f 6d1 e@ eB f 6d1 eA eC f 6d1 eB e@ f 6d1 eC eA f 6d1 e@ e; eB f 6d1 eA e; eC f 6d1 eB e; e@ f 6d1 eC e; eA f 6d2 e< e> f 6d2 e= e? f 6d2 e> e< f 6d2 e? e= f 6d2 e< e; e> f 6d2 e= e; e? f 6d2 e> e; e< f 6d2 e? e; e= f 6d3 e@ eA f 6d3 eA eB f 6d3 eB eC f 6d3 eC e@ f 6d3 e@ e; eA f 6d3 eA e; eB f 6d3 eB e; eC f 6d3 eC e; e@ f 6d4 e@ eC f 6d4 eA e@ f 6d4 eB eA f 6d4 eC eB f 6d4 e@ e; eC f 6d4 eA e; e@ f 6d4 eB e; eA f 6d4 eC e; eB f 6d5 e< eB f 6d5 e= eC f 6d5 e> e@ f 6d5 e? eA f 6d5 e< e; eB f 6d5 e= e; eC f 6d5 e> e; e@ f 6d5 e? e; eA f 6d6 e< eC f 6d6 e= e@ f 6d6 e> eA f 6d6 e? eB f 6d6 e< e; eC f 6d6 e= e; e@ f 6d6 e> e; eA f 6d6 e? e; eB f 6d7 e@ e> f 6d7 eA e? f 6d7 eB e< f 6d7 eC e= f 6d7 e@ e; e> f 6d7 eA e; e? f 6d7 eB e; e< f 6d7 eC e; e= f 6d8 e@ e= f 6d8 eA e> f 6d8 eB e? f 6d8 eC e< f 6d8 e@ e; e= f 6d8 eA e; e> f 6d8 eB e; e? f 6d8 eC e; e< f 6d9 e< e; e= f 6d9 e= e; e> f 6d9 e> e; e? f 6d9 e? e; e< f 6d: e< e; e? f 6d: e= e; e< f 6d: e> e; e= f 6d: e? e; e> f 6d; e@ e; e@ f 6d; eA e; eA f 6d; eB e; eB f 6d; eC e; eC f 6d< e< e; e< f 6d< e= e; e= f 6d< e> e; e> f 6d< e? e; e? f 6ZE i dO g d' 6d( 
d+ f g d( 6dP g d) 6d( 
d+ f g d* 6dQ g d+ 6d3 
d+ f d( 
d+ f g d 6d1 
d+ f dR g d. 6d3 
d+ f d( 
d+ f g d/ 6d1 
d+ f dS g d0 6d( 
d) f g d, 
6dT g d- 6d( 
d( f dU g d1 6d( 
d( f dV g d2 6d( 
d) f dW g d3 6d* 
d) f dX g d4 6d* 
d+ f dY g d5 6d, 
d+ f dZ g d6 6d, 
d+ f d[ g d7 6d* 
d+ f d\ g d8 6d( 
d) f d] g d9 6d* 
d) f d^ g d: 6d) 
d( f d_ g d; 6d) 
d( f d` g d< 6ZF d=   ZG d>   ZH dN d?  ZI d@   ZJ dA   ZK dN dN dN dB  ZL dC   ZM dD   ZN dE   ZO dF   ZP dN dN dN e* dG  ZQ dN dN dN e* e* dH  ZR dN dN dN e* dI  ZS dJ eT f dK     YZU dL eT f dM     YZV dN S(a   s;   Real and complex root isolation and refinement algorithms. i(   t   print_functiont   division(   t   range(   t   dup_negt
   dup_rshiftt   dup_rem(   t   dup_LCt   dup_TCt
   dup_degreet	   dup_stript   dup_reverset   dup_convertt   dup_terms_gcd(
   t   dup_clear_denomst
   dup_mirrort	   dup_scalet	   dup_shiftt   dup_transformt   dup_difft   dup_evalt   dmp_eval_int   dup_sign_variationst   dup_real_imag(   t   dup_factor_list(   t   RefinementFailedt   DomainError(   t   dup_sqf_partt   dup_sqf_listc         C  s   | j  s t d |   n  t |  |  }  |  t |  d |  g } x> | d r t | d | d |  } | j t | |   qF W| d  S(   s   
    Computes the Sturm sequence of ``f`` in ``F[x]``.

    Given a univariate, square-free polynomial ``f(x)`` returns the
    associated Sturm sequence ``f_0(x), ..., f_n(x)`` defined by::

       f_0(x), f_1(x) = f(x), f'(x)
       f_n = -rem(f_{n-2}(x), f_{n-1}(x))

    Examples
    ========

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

    >>> R.dup_sturm(x**3 - 2*x**2 + x - 3)
    [x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2/9*x + 25/9, -2079/4]

    References
    ==========

    .. [1] [Davenport88]_

    s$   can't compute Sturm sequence over %si   ii(   t   is_FieldR   R   R   R   t   appendR   (   t   ft   Kt   sturmt   s(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt	   dup_sturm   s    	c   
      C  s  t  |   g  } } | | j g } t |  |  d k  rJ t |  |  }  n  t t |    }  x t d |  D] } |  | d k r ql n  | j |  | d  g  } } xn t | d |  D]Y } |  | d k r q n  | | | | j |  | d  }	 | j |	 | | | g  q W| s#ql n  t	 |  }	 | |	 d d | |	 d <| j |	 d  ql W| shd S| j   d  t |  d Sd S(   s  Compute the LMQ upper bound for the positive roots of `f`;
       LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.

    References
    ==========
    .. [1] Alkiviadis G. Akritas: "Linear and Quadratic Complexity Bounds on the
        Values of the Positive Roots of Polynomials"
        Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.
    i    i   i   N(   t   lent   oneR   R   t   listt   reversedR   t   logR   t   mint   Nonet	   get_fieldt   max(
   R   R   t   nt   Pt   tt   it   at   QLt   jt   q(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_root_upper_boundD   s,    
"c         C  s1   t  t |   |  } | d k	 r) d | Sd Sd S(   s  Compute the LMQ lower bound for the positive roots of `f`;
       LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.

       References
       ==========
       .. [1] Alkiviadis G. Akritas: "Linear and Quadratic Complexity Bounds on the
              Values of the Positive Roots of Polynomials"
              Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.
    i   N(   R4   R
   R)   (   R   R   t   bound(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_root_lower_boundp   s    
c         C  sZ   |  \ } } | j  |  | j |  } } | j  |  | j |  } } | | | | f S(   s0   Convert an open interval to a Mobius transform. (   t   numert   denom(   t   It   fieldR!   R.   R0   t   ct   bt   d(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _mobius_from_interval   s    c         C  sU   |  \ } } } } | | |  | | |  } } | | k rG | | f S| | f Sd S(   s0   Convert a Mobius transform to an open interval. N(    (   t   MR:   R0   R<   R;   R=   R!   R.   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _mobius_to_interval   s
    
c         C  sU  | \ } } } } | | k r@ | | k r@ |  | | | | f f St  |  |  } | d k	 rp | t |   } n	 | j } | r | d k r t |  | |  }  | | | | | j } } } n  | | j k r+t |  | |  }  | | | | | | } } t |  | j |  s+|  | | | | f f Sn  t |  | j |  |  }  }	 | | | | | | f \ }
 } } } t |  | j |  s|  | | | | f f St |  |  } | d k r|
 | | | f \ } } } } nk t t	 |	  | j |  }  t |  | j |  st
 |  d |  }  n  | | | | | | f \ } } } } |  | | | | f f S(   s5   One step of positive real root refinement algorithm. i   i   N(   R6   R)   t   intt   zeroR   R$   R   R   R   R
   R   (   R   R?   R   t   fastR0   R<   R;   R=   t   At   gt   a1t   b1t   c1t   d1t   k(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_step_refine_real_root   s6    	"&!&c         C  s  | j    } t |  d k r< t | |  \ }	 }
 } } n | \ }	 }
 } } x@ | s t |  |	 |
 | | f | d | \ }  \ }	 }
 } } qQ W| d k	 r(| d k	 r(xOt d |  D]h } t | |	 |  | |
 |   | k r t |  |	 |
 | | f | d | \ }  \ }	 }
 } } q Pq Wn | d k	 rxe t | |	 |  | |
 |   | k rt |  |	 |
 | | f | d | \ }  \ }	 }
 } } q7Wn  | d k	 rxP t d |  D]< } t |  |	 |
 | | f | d | \ }  \ }	 }
 } } qWn  | d k	 rx t rt |	 |
 | | f |  \ } } | | k sI| | k rMPq
t |  |	 |
 | | f | d | \ }  \ }	 }
 } } q
Wn  | st |	 |
 | | f |  S|  |	 |
 | | f f Sd S(   sG   Refine a positive root of `f` given a Mobius transform or an interval. i   RC   i    N(	   R*   R#   R>   RK   R)   R   t   abst   TrueR@   (   R   R?   R   t   epst   stepst   disjointRC   t   mobiust   FR0   R<   R;   R=   R/   t   ut   v(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_inner_refine_real_root   s6    	+(9+==	!=c         C  s   t  | | f | j    \ } }	 }
 } t |  t | |	 g  t |
 | g  |  }  t |  |  d k r t d | | f   n  t |  | |	 |
 | f | d | d | d | d | S(   s:   Refine a positive root of `f` given an interval `(s, t)`. i   s5   there should be exactly one root in (%s, %s) intervalRN   RO   RP   RC   (   R>   R*   R   R	   R   R   RU   (   R   R!   R.   R   RN   RO   RP   RC   R0   R<   R;   R=   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_outer_refine_real_root   s    'c   
      C  si  | j  r4 t |  | d t | j   \ } }  } n | j sP t d |   n  | | k rf | | f S| | k r | | } } n  t }	 | d k  r | d k r t |  |  | | t f \ }  } } }	 q t d | | f   n  |	 r| d	 k	 r| d k  r| } qd	 } n  t
 |  | | | d | d | d | d | \ } } |	 r[| | f S| | f Sd	 S(
   sB   Refine real root's approximating interval to the given precision. t   converts*   real root refinement not supported over %si    s$   can't refine a real root in (%s, %s)RN   RO   RP   RC   N(   t   is_QQR   RM   t   get_ringt   is_ZZR   t   FalseR   t
   ValueErrorR)   RV   (
   R   R!   R.   R   RN   RO   RP   RC   t   _t   negative(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_refine_real_root   s,    	+	
,
	0c         C  sa  | j  | j | j | j  f \ } } } } t |  |  } | d k rI g  S| d k r t |  | | | | f | d | d | d t g }	 ng  | | | | |  | f g }	 }
 x|
 r\|
 j   \ } } } } }  } t |  |  } | d k	 r| t |   } n	 | j } | rS| d k rSt	 |  | |  }  | | | | | j  } } } n  | | j  k rAt
 |  | |  }  | | | | | | } } t |  |  s|	 j |  | | | | f f  t |  d |  }  n  t |  |  } | d k rq n  | d k rA|	 j t |  | | | | f | d | d | d t  q qAn  t
 |  | j  |  } | | | | | | d f \ } } } } } t | |  s|	 j | | | | | f f  t | d |  d } } n  t | |  } | | | } | | | | | | f \ } } } } | d k rlt
 t |   | j  |  } t | |  sZt | d |  } n  t | |  } n d } | | k  r| | | | f \ } } } } | | | | f \ } } } } | | | | f \ } } } } n  | sq n  | d k r5t
 t |   | j  |  } t | |  s5t | d |  } q5n  | d k r{|	 j t | | | | | f | d | d | d t  n |
 j | | | | | | f  | sq n  | d k rt
 t |   | j  |  } t | |  st | d |  } qn  | d k r:|	 j t | | | | | f | d | d | d t  q |
 j | | | | | | f  q W|	 S(   sN  Internal function for isolation positive roots up to given precision.

       References
       ==========
           1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root
           Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
           2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the
           Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear
           Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.
    i    i   RN   RC   RQ   i   N(   R$   RB   R   RU   RM   t   popR6   R)   RA   R   R   R   R   R   R
   (   R   R   RN   RC   R0   R<   R;   R=   RJ   t   rootst   stackRD   t   f1RF   RG   RH   RI   t   rt   k1t   k2t   a2t   b2t   c2t   d2t   f2(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_inner_isolate_real_roots  s    *3"		"	.	,&!	1	1#c         C  s   | j    } x t r t | |  \ }	 }
 | rB |
 |	 }	 }
 n  | d k sZ |	 | k r | d k sr |
 | k r | s |	 |
 f S|  | f Sq | d k	 r |	 | k s | d k	 r |
 | k  r d St |  | | d | \ }  } q Wd S(   s9   Discard an isolating interval if outside ``(inf, sup)``. RC   N(   R*   RM   R@   R)   RK   (   R   R?   t   inft   supR   R^   RC   RQ   RR   RS   RT   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _discard_if_outside_interval  s    	0
0c      
   C  s  | d k	 r | d k  r g  St |  | d | d | } | j   g  } }	 | d k	 sb | d k	 r x | D]I \ }  }
 t |  |
 | | | t | |  } | d k	 ri |	 j |  qi qi WnN | sxE | D]4 \ }  }
 t |
 |  \ } } |	 j | | f  q Wn | }	 |	 S(   s@   Iteratively compute disjoint positive root isolation intervals. i    RN   RC   N(   R)   Rl   R*   Ro   R[   R   R@   (   R   R   RN   Rm   Rn   RC   RQ   Ra   RR   t   resultsR?   t   resultRS   RT   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt    dup_inner_isolate_positive_roots  s    !c      
   C  s  | d k	 r | d k r g  St t |  |  | d | d | } | j   g  } }	 | d k	 sk | d k	 r x | D]I \ }  }
 t |  |
 | | | t | |  } | d k	 rr |	 j |  qr qr WnP | sxG | D]6 \ }  }
 t |
 |  \ } } |	 j | | f  q Wn | }	 |	 S(   s@   Iteratively compute disjoint negative root isolation intervals. i    RN   RC   N(   R)   Rl   R   R*   Ro   RM   R   R@   (   R   R   Rm   Rn   RN   RC   RQ   Ra   RR   Rp   R?   Rq   RS   RT   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt    dup_inner_isolate_negative_roots  s    $!c         C  s   t  |  |  \ } }  | d k r | j   } | d k sE | d k r | d k s] d | k r | s | s | j | j f | f g |  f S| j | j f | | j | j g f g |  f Sq | j | j f g |  f Sq n  g  |  f S(   s?   Handle special case of CF algorithm when ``f`` is homogeneous. i    N(   R   R*   R)   RB   R$   (   R   R   Rm   Rn   t   basist   sqfR2   RR   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _isolate_zero  s    01c         C  s,  | j  r4 t |  | d t | j   \ } }  } n | j sP t d |   n  t |   d k rf g  St |  | | | d t d t \ } }  t	 |  | d | d | d | d	 | }	 t
 |  | d | d | d | d	 | }
 t |	 | |
  } | s | Sg  | D]$ \ } } t | | f |  |  ^ q Sd
 S(   s  Isolate real roots of a square-free polynomial using the Vincent-Akritas-Strzebonski (VAS) CF approach.

       References
       ==========
       .. [1] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative
              Study of Two Real Root Isolation Methods. Nonlinear Analysis:
              Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
       .. [2] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S.
              Vigklas: Improving the Performance of the Continued Fractions
              Method Using New Bounds of Positive Roots. Nonlinear Analysis:
              Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

    RW   s-   isolation of real roots not supported over %si    Rt   Ru   RN   Rm   Rn   RC   N(   RX   R   RM   RY   RZ   R   R   Rv   R[   Rs   Rr   t   sortedt   RealInterval(   R   R   RN   Rm   Rn   RC   t   blackboxR]   t   I_zerot   I_negt   I_posRa   R0   R<   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_real_roots_sqf  s    	+	'''c         C  s  | j  r4 t |  | d t | j   \ } }  } n | j sP t d |   n  t |   d k rf g  St |  | | | d | d t \ } }  t	 |  |  \ } }	 t
 |	  d k rj|	 \ \ }  }
 t |  | d | d | d	 | d
 | } t |  | d | d | d	 | d
 | } g  | D] \ } } | | f |
 f ^ q} g  | D] \ } } | | f |
 f ^ qC} n3 t |	 | d | d | d	 | d | d
 | \ } } t | | |  S(   s  Isolate real roots using Vincent-Akritas-Strzebonski (VAS) continued fractions approach.

       References
       ==========

       .. [1] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative
              Study of Two Real Root Isolation Methods. Nonlinear Analysis:
              Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
       .. [2] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S.
              Vigklas: Improving the Performance of the Continued Fractions
              Method Using New Bounds of Positive Roots.
              Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

    RW   s-   isolation of real roots not supported over %si    Rt   Ru   i   RN   Rm   Rn   RC   (   RX   R   RM   RY   RZ   R   R   Rv   R[   R   R#   Rs   Rr   t   _real_isolate_and_disjoinRw   (   R   R   RN   Rm   Rn   Rt   RC   R]   Rz   t   factorsRJ   R{   R|   RS   RT   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_real_roots  s"    	+	'''+.'c         C  st  | j  rd | j   | |  } } }  xY t |   D], \ }	 }
 t |
 | | d t d |  |	 <q1 Wn | j s t d |   n  t i  } } | d k s | d k r | d k s d | k r t i  } } n  x t |   D] \ }	 }
 t	 |
 |  \ } }
 | r| d k r| | |	 <n  x[ t
 |
 |  d D]F \ } } t |  } | | k rfi | |	 6| | <q.| | | |	 <q.Wq Wg  } x3 | j   D]% \ } } | j t |  | f  qWt | | d | d | d | d | d	 | d
 | \ } } | j   } | s| rg  } nN | s8| j | j f | f g } n* | j | j f | | j | j g f g } t | | |  S(   s  Isolate real roots of a list of square-free polynomial using Vincent-Akritas-Strzebonski (VAS) CF approach.

       References
       ==========

       .. [1] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative
              Study of Two Real Root Isolation Methods. Nonlinear Analysis:
              Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
       .. [2] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S.
              Vigklas: Improving the Performance of the Continued Fractions
              Method Using New Bounds of Positive Roots.
              Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

    RW   i   s-   isolation of real roots not supported over %si    RN   Rm   Rn   t   strictRt   RC   N(   RX   RY   t	   enumerateR   RM   RZ   R   R[   R)   R   R   t   tuplet   itemsR   R%   R~   R*   RB   R$   Rw   (   t   polysR   RN   Rm   Rn   R   Rt   RC   RR   R/   t   pt   zerost   factors_dictt   zero_indicesR2   R   RJ   t   factors_listt   indicesR{   R|   Rz   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_real_roots_list/  s<    	'	0 '	*c         C  s  |  \ } } } } | \ } } }	 }
 | | | | } } | |
 | |	 } } | | k rj | | k rj t  S| | k r | | | | f \ } } } } n  | | k r | |
 | |	 f \ } }	 } }
 n  | s | | |	 | k p | | |
 | k S| | |	 | k p| | |
 | k  Sd S(   s6   Check if Mobius transforms define disjoint intervals. N(   RM   (   R?   t   NR   RF   RG   RH   RI   Rg   Rh   Ri   Rj   t   a1d1t   b1c1t   a2d2t   b2c2(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _disjoint_pm  s    !!&c         C  sZ  g  g  } }	 x t  |   D] \ }
 \ } } xT t | | d | d | d | d | d t D]% \ } } | j | | | | f  qZ WxT t | | d | d | d | d | d t D]% \ } } |	 j | | | | f  q Wq Wx t  |  D] \ }
 \ } } } } x t  | |
 d  D] \ } \ } } } } xm t | | d | st | | | d d d | d t \ } } t | | | d d d | d t \ } } q3W| | | | f | |
 | d <qW| | | | f | |
 <q Wx t  |	  D] \ }
 \ } } } } x t  |	 |
 d  D] \ } \ } } } } xm t | | d | st | | | d d d | d t \ } } t | | | d d d | d t \ } } q1W| | | | f |	 |
 | d <qW| | | | f |	 |
 <qW| rx t  |	  D]w \ }
 \ } } } } | d	 sx8 | d	 sIt | | | d d d | d t \ } } qW| | | | f |	 |
 <PqqWx t  |  D]w \ } \ } } } } | d	 sux8 | d	 st | | | d d d | d t \ } } qW| | | | f | | <PququWn  | j   } g  |	 D]* \ } } } } t | |  | | f ^ q}	 g  | D]* \ } } } } t | |  | | f ^ q=} | sg  |	 D]) \ \ } } } } | | f | f ^ qz}	 g  | D]' \ \ } } } } | | f | f ^ q} np g  |	 D], \ \ } } } } | | f | | f ^ q}	 g  | D]* \ \ } } } } | | f | | f ^ q } |	 | f S(
   sC   Isolate real roots of a list of polynomials and disjoin intervals. RN   Rm   Rn   RC   RQ   i   R   RO   i    (	   R   Rr   RM   R   Rs   R   RU   R*   R@   (   R   R   RN   Rm   Rn   R   Rt   RC   R|   R{   R/   R   RJ   RR   R?   t   GR   R2   RE   t   mR:   R]   RS   RT   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR~     sT    ::!%-*."%-*."%
.%
.776797c   
      C  st  t  |   d k r d S| j sG | | j   } } t |  | |  }  n  t |  |  } | d k r t g  | D]# } t | |  d t  |  ^ ql |  } n. t g  | D] } t | | |  ^ q |  } | d k rt g  | D] } t | |  ^ q |  } n. t g  | D] } t | | |  ^ q|  } t	 | |  }	 | d k	 rpt |  | |  rp|	 d 7}	 n  |	 S(   sF   Returns the number of distinct real roots of ``f`` in ``[inf, sup]``. i    ii   N(
   R   R   R*   R   R"   R)   R   R   R   RL   (
   R   R   Rm   Rn   t   RR    R!   t	   signs_inft	   signs_supt   count(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_count_real_roots  s     	<...t   OOt   Q1t   Q2t   Q3t   Q4t   A1t   A2t   A3t   A4i    i   i   i   i   i   iiiii   i   i	   i
   i   i   i   i   i   i   i   i   c         C  sP   |  r | r t  S|  s/ | d k r( t St Sn | sL |  d k rE t St Sn  d S(   sE   Return the half-axis (or origin) on which (re, im) point is located. i    N(   R   R   R   R   R   (   t   ret   im(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _classify_point  s    c         C  s  |  s
 g  Sg  } | s|  d \ \ } } }	 }	 | | k oF | k n rt  |   d k r t | | |  d k r t t g St t g SqJ|  d \ \ } }	 }	 }	 t | | | d |  d k r | j t t g  d 
}
 n | j t t g  d }
 |  d }  nB t | | |  d k r7| j t  d 
}
 n | j t  d }
 x |  D]x \ \ } }	 } }	 | j t  | d d d k r|
 }
 n  | | k rQ|
 d k r| j t  q| j t  qQqQW| S| s|  d \ \ } } }	 }	 | | k o| k n rt  |   d k rMt | | |  d k r@t t g St t g Sq|  d \ \ } }	 }	 }	 t | | | d |  d k r| j t t g  d 
} n | j t t g  d } |  d }  nB t | | |  d k r| j t  d 
} n | j t  d } x |  D]x \ \ } }	 } }	 | j t  | d d d k rR| } n  | | k r| d k rz| j t  q| j t  qqW| St | | |  } t | | |  } | s| rm| j t	 | |   t  |   d k rt | | |  } t | | |  } nM |  d \ \ } }	 }	 }	 t | | | d |  } t | | | d |  } |  d }  n  | d k rd 
} n d } | d k rd 
}
 n d }
 i t
 d 
d 
f 6t d d 
f 6t d 6t d 
d f 6} | j | | |
 f  x|  D] \ \ } } } }	 | | k rnt | | |  } t | | |  } t	 | |  } | d k	 rn| j |  qnn  d | k r| d d d k r| } qn  d | k r| d d d k r|
 }
 qn  | | k o| | k s| j | | |
 f  qqW| S(   sJ   Generate a sequence of extended quadrants from a list of critical points. i    i   i   i(   iiN(   R#   R   R   R   R   t   extendR   R   R   R   R   R   R   R   R)   (   t	   intervalsRc   Rk   R!   R.   RR   t   QR0   R<   R]   t   f2_sgnR   t   f1_sgnR   R   t   sgnt   cls(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _intervals_to_quadrants  s    
 



 




c         C  sH  | t  k rC d d d d g } i d d 6d d 6d d 6d d 6} n4 d d d d g } i d d 6d d 6d d 6d d 6} | d k	 r0| t  k	 r0t |  } x? t d d d d g  D]% \ } } | | k r d | | <q q WxP t d	 d
 d d g  D]3 \ } }	 |	 | k r d | | d d | f <q q Wn  |  | | | g g  }
 } xt |
  D]\ } } | snqVn  | d t k r| d  } n  | d t k r| d d | d } } |
 | d t | d f } | t k r| j t | | | | f f  qt d t |    n  | d d } } x| t	 |  k  r?| | | d } } | t k r| | f } | t
 k r| j t
 | d f  q2| t k r| j t | | | f  q2t d t |    n^ | | | | f | d } } | t k r| j t | | | f  n t d t |    | d } q,WqVW| S(   s9   Transform sequences of quadrants to a sequence of rules. i   i    i   i   t   St   ER   t   Wt   SWt   SEt   NEt   NWi   iis   3 element rule (corner): s   2 element rule (inside): s   3 element rule (edge): (   i    i   (   i   i   (   i   i   (   i   i    (   i    i   (   i   i   (   i   i   (   i   i    N(   RM   R)   t   setR   R   t   _rules_ambiguousR   t   NotImplementedErrort   strR#   t   _rules_simple(   t   Q_L1t   Q_L2t   Q_L3t   Q_L4t   excludet   edgest   cornersR/   t   edget   cornert   QQt   rulesR   R2   t   qqt   q1RJ   t   q2(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _traverse_quadrants_  sb    
%%"$c         C  s;   g  t  |   D]* \ \ } } } } | | f | | f ^ q S(   sK   Reverse intervals for traversal from right to left and from top to bottom. (   R&   (   R   R0   R<   R   R   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _reverse_intervals  s    c         C  sA   t  t g  |  D]  \ } } | t | |   ^ q  | d   S(   sN   Compute the winding number of the input polynomial, i.e. the number of roots. i   (   RA   t   sumt   _values(   t   TR:   R.   R/   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _winding_number  s    c   .      C  s  | j  r' | j r' t d |   n  | j  rF | | j   } } n | j   | } } t |  | |  }  | d k s | d k r t |   t t	 |  |   } } d t
 g  |  D] }	 | j t |	  |  ^ q  }
 n  | d k r |
 |
 } } n | \ } } | d k r%|
 
|
 
} } n | \ } } t |  |  \ } } t | | d d |  } t | | d d |  } t | | | d t \ } } t | | | d t \ } } t | | d d |  } t | | d d |  } t | | | d t \ } } t | | | d t \ } } t | | d d |  } t | | d d |  } t | | | d t \ } } t | | | d t \ } } t | | d d |  } t | | d d |  } t | | | d t \ } } t | | | d t \ } }  | | g }! | | g }" | | g }# | |  g }$ t |! | d | d | d t d	 t d
 t }% t |" | d | d | d t d	 t d
 t }& t |# | d | d | d t d	 t d
 t }' t |$ | d | d | d t d	 t d
 t }( t |'  }' t |(  }( t |% | | | | |  }) t |& | | | | |  }* t |' | | | | |  }+ t |( | | | | |  }, t |) |* |+ |, d | }- t |- |  S(   sR   Count all roots in [u + v*I, s + t*I] rectangle using Collins-Krandick algorithm. s.   complex root counting is not supported over %si   i   RW   i    Rm   Rn   RC   Rt   R   R   N(   RZ   RX   R   R*   RY   R   R)   R   RL   R   R+   t   quoR   R   R   RM   R   R   R   R   R   (.   R   R   Rm   Rn   R   R   RR   R]   t   lcR;   t   BRS   RT   R!   R.   Rc   Rk   t   f1L1Ft   f2L1Ft   f1L1Rt   f2L1Rt   f1L2Ft   f2L2Ft   f1L2Rt   f2L2Rt   f1L3Ft   f2L3Ft   f1L3Rt   f2L3Rt   f1L4Ft   f2L4Ft   f1L4Rt   f2L4Rt   S_L1t   S_L2t   S_L3t   S_L4t   I_L1t   I_L2t   I_L3t   I_L4R   R   R   R   R   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_count_complex_roots  s`    	"8----c
   D      C  s  | | \ }
 } \ } } | \ } } } } | \ } } } } | \ } } } } | \ } } } } |
 | d } t  | | d d |	  } t  | | d d |	  }  t | |  g |	 d | d | d t d t d t }! g  g  }" }# |! | }$ }% g  g  }& }' | t |!  }( }) x?| D]7} | \ \ } } }* }+ | | k r| | k rc|" j |  |# j |  qJ| | k  r|" j |  qJ|# j |  q| | k r|" j |  q| | k r|# j |  qt |+ | | |	 j   d	 | d t \ } } | | k r|" j | | f |* |+ f  n  | | k r|# j | | f |* |+ f  qqWx?| D]7} | \ \ } } }* }+ | | k r| | k r|& j |  |' j |  q| | k  r|& j |  q|' j |  qU| | k r|& j |  qU| | k r	|' j |  qUt |+ | | |	 j   d	 | d t \ } } | | k ra|& j | | f |* |+ f  n  | | k rU|' j | | f |* |+ f  qUqUWt |" | | |
 | |	  }, t |$ | |  | | |	  }- t |& | | | |
 |	  }. | }/ t |# | | | | |	  }0 | }1 t |' | | | | |	  }2 t |) | |  | | |	  }3 t |, |- |. |/ d
 t }4 t |0 |1 |2 |3 d
 t }5 t	 |4 |	  }6 t	 |5 |	  }7 |" |$ |& |( f }8 |, |- |. |/ f }9 |# |% |' |) f }: |0 |1 |2 |3 f }; | | | | f }< | |  | | f }= | | | | f }> | | | |  f }? |
 | f | | f } } | | f | | f }@ }A |6 | | |8 |9 |< |= f }B |7 |@ |A |: |; |> |? f }C |B |C f S(   sF   Vertical bisection step in Collins-Krandick root isolation algorithm. i   i    i   Rm   Rn   RC   R   Rt   RP   R   (
   R   R   RM   R   R   R_   RY   R   R   R   (D   R   R0   R<   R9   R   t   F1t   F2Rc   Rk   RR   RS   RT   R!   R.   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   xt   f1Vt   f2Vt   I_Vt   I_L1_Lt   I_L1_Rt   I_L2_Lt   I_L2_Rt   I_L3_Lt   I_L3_Rt   I_L4_Lt   I_L4_RR   t   ht   Q_L1_Lt   Q_L2_Lt   Q_L3_Lt   Q_L4_Lt   Q_L1_Rt   Q_L2_Rt   Q_L3_Rt   Q_L4_Rt   T_Lt   T_Rt   N_Lt   N_Rt   I_Lt   Q_Lt   I_Rt   Q_Rt   F1_Lt   F2_Lt   F1_Rt   F2_RR;   R=   t   D_Lt   D_R(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _vertical_bisection  s    3-#-#c
   D      C  s  | | \ }
 } \ } } | \ } } } } | \ } } } } | \ } } } } | \ } } } } | | d } t  | | d d |	  } t  | | d d |	  }  t | |  g |	 d |
 d | d t d t d t }! | |! }" }# g  g  }$ }% t |!  | }& }' g  g  }( }) x?| D]7} | \ \ } } }* }+ | | k r| | k rc|$ j |  |% j |  qJ| | k  r|$ j |  qJ|% j |  q| | k r|$ j |  q| | k r|% j |  qt |+ | | |	 j   d | d t \ } } | | k r|$ j | | f |* |+ f  n  | | k r|% j | | f |* |+ f  qqWx?| D]7} | \ \ } } }* }+ | | k r| | k r|( j |  |) j |  q| | k  r|( j |  q|) j |  qU| | k r|( j |  qU| | k r	|) j |  qUt |+ | | |	 j   d | d t \ } } | | k ra|( j | | f |* |+ f  n  | | k rU|) j | | f |* |+ f  qUqUW| }, t |$ | | | | |	  }- t |& | |  | |
 |	  }. t |( | | | | |	  }/ t |# | |  |
 | |	  }0 t |% | | | | |	  }1 | }2 t |) | | | | |	  }3 t |, |- |. |/ d	 t }4 t |0 |1 |2 |3 d	 t }5 t	 |4 |	  }6 t	 |5 |	  }7 |" |$ |& |( f }8 |, |- |. |/ f }9 |# |% |' |) f }: |0 |1 |2 |3 f }; | | | | f }< | | |  | f }= | | | | f }> |  | | | f }? |
 | f | | f } } |
 | f | | f }@ }A |6 | | |8 |9 |< |= f }B |7 |@ |A |: |; |> |? f }C |B |C f S(
   sH   Horizontal bisection step in Collins-Krandick root isolation algorithm. i   i   Rm   Rn   RC   R   Rt   RP   R   (
   R   R   RM   R   R   R_   RY   R   R   R   (D   R   R0   R<   R9   R   R   R   Rc   Rk   RR   RS   RT   R!   R.   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   yt   f1Ht   f2Ht   I_Ht   I_L1_Bt   I_L1_Ut   I_L2_Bt   I_L2_Ut   I_L3_Bt   I_L3_Ut   I_L4_Bt   I_L4_UR   R   t   Q_L1_Bt   Q_L2_Bt   Q_L3_Bt   Q_L4_Bt   Q_L1_Ut   Q_L2_Ut   Q_L3_Ut   Q_L4_Ut   T_Bt   T_Ut   N_Bt   N_Ut   I_Bt   Q_Bt   I_Ut   Q_Ut   F1_Bt   F2_Bt   F1_Ut   F2_UR;   R=   t   D_Bt   D_U(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _horizontal_bisectiong  s    3-#-#c   
      C  s   d \ } } xu t |   D]g \ } \ } \ } } \ } } } } } } | | | | }	 | d k sp |	 | k  r |	 | } } q q W|  j |  S(   s0   Find a rectangle of minimum area for bisection. N(   NN(   R)   R   R`   (
   t
   rectanglest   min_areaR2   R/   R]   RS   RT   R!   R.   t   area(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _depth_first_select  s    :c         C  sK   |  | \ } } \ } } | d k	 rC | | | k  oB | | | k  St Sd S(   s8   Return ``True`` if the given rectangle is small enough. N(   R)   RM   (   R0   R<   RN   RS   RT   R!   R.   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _rectangle_small_p  s    c   J      C  sa  | j  r' | j r' t d |   n  t |   d k r= g  S| j  rU | j   } n | } t |  | |  }  t t |  |   } d t g  |  D] } | j	 t |  |  ^ q  }	 |	 | j
 f |	 |	 f \ }
 } \ } } | d k	 r | }
 n  | d k	 r
| } n  | d k  s.| | k s.| |
 k r=t d   n  t |  |  \ } } t | | d d |  } t | | d d |  } t | | d d |  } t | | d d |  } t | | d d |  } t | | d d |  } t | |
 d d |  } t | |
 d d |  } | | g } | | g } | | g } | | g } t | | d |
 d | d t d	 t d
 t } t | | d | d | d t d	 t d
 t } t | | d |
 d | d t d	 t d
 t } t | | d | d | d t d	 t d
 t } t |  } t |  } t | | | |
 | |  }  t | | | | | |  }! t | | | | |
 |  }" t | | | | | |  }# t |  |! |" |#  }$ t |$ |  }% |% sg  S| | | | f }& |  |! |" |# f }' | | | | f }( | | | | f }) |% |
 | f | | f |& |' |( |) f g g  }* }+ x|* rt |*  \ }% \ }
 } \ } } }& }' }( }) | |
 | | k rt |% |
 | f | | f |& |' |( |) | | | 
 \ }, }- |, \ }. }/ }0 }1 }2 }3 }4 |- \ }5 } }6 }7 }8 }9 }: |. d k rB|. d k r2t |/ |0 |  r2|+ j t |/ |0 |1 |2 |3 |4 | | | 	  qB|* j |,  n  |5 d k r|5 d k rt | |6 |  r|+ j t | |6 |7 |8 |9 |: | | | 	  q|* j |-  qq$t |% |
 | f | | f |& |' |( |) | | | 
 \ }; }< |; \ }= }/ }0 }> }? }@ }A |< \ }B } }6 }C }D }E }F |= d k r|= d k rtt |/ |0 |  rt|+ j t |/ |0 |> |? |@ |A | | | 	  q|* j |;  n  |B d k r$|B d k rt | |6 |  r|+ j t | |6 |C |D |E |F | | | 	  q|* j |<  q$q$Wt |+ d d   g  }G }+ x' |G D] }H |+ j |H j   |H g  qW| r@|+ Sg  |+ D] }I |I j   ^ qGSd S(   sT   Isolate complex roots of a square-free polynomial using Collins-Krandick algorithm. s3   isolation of complex roots is not supported over %si    i   s'   not a valid complex isolation rectanglei   Rm   Rn   RC   R   Rt   t   keyc         S  s   |  j  |  j f S(   N(   t   axt   ay(   Rd   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   <lambda>Y  t    N(   RZ   RX   R   R   R*   R   RL   R   R+   R   RB   R)   R\   R   R   R   RM   R   R   R   R   R6  R  R7  R   t   ComplexIntervalR2  Rw   R   t	   conjugatet   as_tuple(J   R   R   RN   Rm   Rn   Ry   RR   R   R;   R   RS   RT   R!   R.   Rc   Rk   t   f1L1t   f2L1t   f1L2t   f2L2t   f1L3t   f2L3t   f1L4t   f2L4R   R   R   R   R   R   R   R   R   R   R   R   R   R   R9   R   R   R   R3  Ra   R  R  R  R0   R<   R  R  R	  R
  R  R=   R  R  R  R  R0  R1  R&  R(  R)  R,  R-  R'  R*  R+  R.  R/  t   _rootst   rootRd   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_complex_roots_sqf  s    	5)		$----1	-9..9	%	%c         C  sR   t  |  | d | d | d | d | d | t |  | d | d | d | d | f S(   sB   Isolate real and complex roots of a square-free polynomial ``f``. RN   Rm   Rn   RC   Ry   (   R}   RJ  (   R   R   RN   Rm   Rn   RC   Ry   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_all_roots_sqfc  s    *c         C  s   | j  r' | j r' t d |   n  t |  |  \ } } t |  d k r | \ \ }  } t |  | d | d | d | d | \ }	 }
 g  |	 D] \ } } | | f | f ^ q }	 g  |
 D] \ } } | | f | f ^ q }
 |	 |
 f St d   d S(	   sF   Isolate real and complex roots of a non-square-free polynomial ``f``. s<   isolation of real and complex roots is not supported over %si   RN   Rm   Rn   RC   s2   only trivial square-free polynomials are supportedN(   RZ   RX   R   R   R#   RK  R   (   R   R   RN   Rm   Rn   RC   R]   R   RJ   t	   real_partt   complex_partR0   R<   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dup_isolate_all_rootsi  s    *++
Rx   c           B  s   e  Z d  Z d   Z e d    Z e d    Z d   Z e d    Z e d    Z	 e d    Z
 e d    Z d	   Z d
   Z d   Z d   Z d   Z d   Z d d  Z d   Z RS(   s?   A fully qualified representation of a real isolation interval. c   
      C  s$  t  |  d k r | \ } } t |  _ | d k  r | d k rn t | |  | | t f \ } } } |  _ q t d | | f   n  t | | f | j    \ } } } }	 t | t	 | | g  t	 | |	 g  |  } | | | |	 f |  _
 n | d  |  _
 | d |  _ | | |  _ |  _ d S(   s8   Initialize new real interval with complete information. i   i    s$   can't refine a real root in (%s, %s)iN(   R#   R[   t   negR   RM   R\   R>   R*   R   R	   RQ   R   t   dom(
   t   selft   dataR   RP  R!   R.   R0   R<   R;   R=   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   __init__  s    	/'c         C  s   t  S(   N(   Rx   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   func  s    c         C  s&   |  } | j  | j f | j | j f S(   N(   RQ   RO  R   RP  (   RQ  R/   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   args  s    c         C  s,   t  |  t  |   k r t S|  j | j k S(   N(   t   typeR[   RU  (   RQ  t   other(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   __eq__  s    c         C  s   |  j  j   } |  j \ } } } } |  j s[ | | | | k  rN | | |  S| | |  S| | | | k r} | | |  S| | |  Sd S(   s%   Return the position of the left end. N(   RP  R*   RQ   RO  (   RQ  R:   R0   R<   R;   R=   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR0     s    	c         C  s*   |  j  } | |  _  |  j } | |  _  | S(   s&   Return the position of the right end. (   RO  R0   (   RQ  t   wast   rv(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR<     s
    	

	c         C  s   |  j  |  j S(   s-   Return width of the real isolating interval. (   R<   R0   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dx  s    c         C  s   |  j  |  j d S(   s2   Return the center of the real isolating interval. i   (   R0   R<   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   center  s    c         C  s   |  j  |  j f S(   s8   Return tuple representation of real isolating interval. (   R0   R<   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR?    s    c         C  s   d |  j  |  j f S(   Ns   (%s, %s)(   R0   R<   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   __repr__  s    c         C  s~   t  | t  r1 |  j | j k p0 | j |  j k St  | t  sF t  |  j | j k p} | j |  j k p} | j | j	 d k S(   s9   Return ``True`` if two isolation intervals are disjoint. i    (
   t
   isinstanceRx   R<   R0   R=  t   AssertionErrorR9  t   bxR:  t   by(   RQ  RW  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   is_disjoint  s
    "$c         C  s]   |  j  d k r |  St |  j |  j  |  j d d d t \ } } t | |  j f | |  j  S(   s2   Internal one step real root refinement procedure. RO   i   RQ   N(   RQ   R)   RU   R   RP  RM   Rx   RO  (   RQ  R   RQ   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   _inner_refine  s
    *c         C  s?   |  } x, | j  |  s4 | j   | j   } } q	 W| | f S(   sD   Refine an isolating interval until it is disjoint with another one. (   Rb  Rc  (   RQ  RW  t   expr(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   refine_disjoint  s    c         C  s,   |  } x | j  | k  s' | j   } q	 W| S(   sE   Refine an isolating interval until it is of sufficiently small size. (   R[  Rc  (   RQ  R[  Rd  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   refine_size  s    i   c         C  s-   |  } x  t  |  D] } | j   } q W| S(   s9   Perform several steps of real root refinement algorithm. (   R   Rc  (   RQ  RO   Rd  R]   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   refine_step  s    c         C  s
   |  j    S(   s4   Perform one step of real root refinement algorithm. (   Rc  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   refine  s    (   t   __name__t
   __module__t   __doc__RS  t   propertyRT  RU  RX  R0   R<   R[  R\  R?  R]  Rb  Rc  Re  Rf  Rg  Rh  (    (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRx   }  s"   							
		R=  c           B  s  e  Z d  Z e d  Z e d    Z e 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 d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d d  Z d   Z RS(   s  A fully qualified representation of a complex isolation interval.
    The printed form is shown as (ax, bx) x (ay, by) where (ax, ay)
    and (bx, by) are the coordinates of the southwest and northeast
    corners of the interval's rectangle, respectively.

    Examples
    ========

    >>> from sympy import CRootOf, Rational, S
    >>> from sympy.abc import x
    >>> CRootOf.clear_cache()  # for doctest reproducibility
    >>> root = CRootOf(x**10 - 2*x + 3, 9)
    >>> i = root._get_interval(); i
    (3/64, 3/32) x (9/8, 75/64)

    The real part of the root lies within the range [0, 3/4] while
    the imaginary part lies within the range [9/8, 3/2]:

    >>> root.n(3)
    0.0766 + 1.14*I

    The width of the ranges in the x and y directions on the complex
    plane are:

    >>> i.dx, i.dy
    (3/64, 3/64)

    The center of the range is

    >>> i.center
    (9/128, 147/128)

    The northeast coordinate of the rectangle bounding the root in the
    complex plane is given by attribute b and the x and y components
    are accessed by bx and by:

    >>> i.b, i.bx, i.by
    ((3/32, 75/64), 3/32, 75/64)

    The southwest coordinate is similarly given by i.a

    >>> i.a, i.ax, i.ay
    ((3/64, 9/8), 3/64, 9/8)

    Although the interval prints to show only the real and imaginary
    range of the root, all the information of the underlying root
    is contained as properties of the interval.

    For example, an interval with a nonpositive imaginary range is
    considered to be the conjugate. Since the y values of y are in the
    range [0, 1/4] it is not the conjugate:

    >>> i.conj
    False

    The conjugate's interval is

    >>> ic = i.conjugate(); ic
    (3/64, 3/32) x (-75/64, -9/8)

        NOTE: the values printed still represent the x and y range
        in which the root -- conjugate, in this case -- is located,
        but the underlying a and b values of a root and its conjugate
        are the same:

        >>> assert i.a == ic.a and i.b == ic.b

        What changes are the reported coordinates of the bounding rectangle:

        >>> (i.ax, i.ay), (i.bx, i.by)
        ((3/64, 9/8), (3/32, 75/64))
        >>> (ic.ax, ic.ay), (ic.bx, ic.by)
        ((3/64, -75/64), (3/32, -9/8))

    The interval can be refined once:

    >>> i  # for reference, this is the current interval
    (3/64, 3/32) x (9/8, 75/64)

    >>> i.refine()
    (3/64, 3/32) x (9/8, 147/128)

    Several refinement steps can be taken:

    >>> i.refine_step(2)  # 2 steps
    (9/128, 3/32) x (9/8, 147/128)

    It is also possible to refine to a given tolerance:

    >>> tol = min(i.dx, i.dy)/2
    >>> i.refine_size(tol)
    (9/128, 21/256) x (9/8, 291/256)

    A disjoint interval is one whose bounding rectangle does not
    overlap with another. An interval, necessarily, is not disjoint with
    itself, but any interval is disjoint with a conjugate since the
    conjugate rectangle will always be in the lower half of the complex
    plane and the non-conjugate in the upper half:

    >>> i.is_disjoint(i), i.is_disjoint(i.conjugate())
    (False, True)

    The following interval j is not disjoint from i:

    >>> close = CRootOf(x**10 - 2*x + 300/S(101), 9)
    >>> j = close._get_interval(); j
    (75/1616, 75/808) x (225/202, 1875/1616)
    >>> i.is_disjoint(j)
    False

    The two can be made disjoint, however:

    >>> newi, newj = i.refine_disjoint(j)
    >>> newi
    (39/512, 159/2048) x (2325/2048, 4653/4096)
    >>> newj
    (3975/51712, 2025/25856) x (29325/25856, 117375/103424)

    Even though the real ranges overlap, the imaginary do not, so
    the roots have been resolved as distinct. Intervals are disjoint
    when either the real or imaginary component of the intervals is
    distinct. In the case above, the real components have not been
    resolved (so we don't know, yet, which root has the smaller real
    part) but the imaginary part of ``close`` is larger than ``root``:

    >>> close.n(3)
    0.0771 + 1.13*I
    >>> root.n(3)
    0.0766 + 1.14*I
    c         C  sb   | | |  _  |  _ | | |  _ |  _ | | |  _ |  _ | | |  _ |  _ |	 |  _ |
 |  _	 d S(   s;   Initialize new complex interval with complete information. N(
   R0   R<   R9   R   Rc   R   Rk   R   RP  t   conj(   RQ  R0   R<   R9   R   R   R   Rc   Rk   RP  Rm  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRS    s    	c         C  s   t  S(   N(   R=  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRT    s    c      
   C  sF   |  } | j  | j | j | j | j | j | j | j | j | j	 f
 S(   N(
   R0   R<   R9   R   R   R   Rc   Rk   RP  Rm  (   RQ  R/   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRU    s    c         C  s,   t  |  t  |   k r t S|  j | j k S(   N(   RV  R[   RU  (   RQ  RW  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRX    s    c         C  s   |  j  d S(   s1   Return ``x`` coordinate of south-western corner. i    (   R0   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR9    s    c         C  s$   |  j  s |  j d S|  j d Sd S(   s1   Return ``y`` coordinate of south-western corner. i   N(   Rm  R0   R<   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR:    s    	c         C  s   |  j  d S(   s1   Return ``x`` coordinate of north-eastern corner. i    (   R<   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR`    s    c         C  s$   |  j  s |  j d S|  j d Sd S(   s1   Return ``y`` coordinate of north-eastern corner. i   N(   Rm  R<   R0   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRa    s    	c         C  s   |  j  d |  j d S(   s0   Return width of the complex isolating interval. i    (   R<   R0   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR[    s    c         C  s   |  j  d |  j d S(   s1   Return height of the complex isolating interval. i   (   R<   R0   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   dy  s    c         C  s&   |  j  |  j d |  j |  j d f S(   s5   Return the center of the complex isolating interval. i   (   R9  R`  R:  Ra  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR\    s    c         C  s"   |  j  |  j f |  j |  j f f S(   si   Return tuple representation of the complex isolating
        interval's SW and NE corners, respectively. (   R9  R:  R`  Ra  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR?    s    c         C  s    d |  j  |  j |  j |  j f S(   Ns   (%s, %s) x (%s, %s)(   R9  R`  R:  Ra  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR]    s    c         C  sC   t  |  j |  j |  j |  j |  j |  j |  j |  j |  j	 d t
 	S(   s=   This complex interval really is located in lower half-plane. Rm  (   R=  R0   R<   R9   R   R   R   Rc   Rk   RP  RM   (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR>    s    c         C  s   t  | t  r | j |   S|  j | j k r2 t S|  j | j k pS | j |  j k } | r` t S|  j | j k p | j |  j k } | S(   s9   Return ``True`` if two isolation intervals are disjoint. (	   R^  Rx   Rb  Rm  RM   R`  R9  Ra  R:  (   RQ  RW  t   re_distinctt   im_distinct(    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRb    s    $$c         C  s  |  j  |  j \ } } \ } } |  j |  j } } |  j |  j } } |  j |  j }	 }
 |  j } | | | | k r t	 d | | f | | f | | | |
 | |	 | 
 \ } } | d d k r | \ } } } } } } }
 q|| \ } } } } } } }
 n t
 d | | f | | f | | | |
 | |	 | 
 \ } } | d d k ra| \ } } } } } } }
 n | \ } } } } } } }
 t | | | | | |
 | |	 | |  j 
 S(   s5   Internal one step complex root refinement procedure. i   i    (   R0   R<   R9   R   Rc   R   Rk   R   RP  R  R2  R=  Rm  (   RQ  RS   RT   R!   R.   R9   R   Rc   R   Rk   R   RP  R  R  R]   R0   R<   R0  R1  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRc    s    	99c         C  s?   |  } x, | j  |  s4 | j   | j   } } q	 W| | f S(   sD   Refine an isolating interval until it is disjoint with another one. (   Rb  Rc  (   RQ  RW  Rd  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRe    s    c         C  sP   | d k r | } n  |  } x. | j | k  o9 | j | k  sK | j   } q W| S(   sE   Refine an isolating interval until it is of sufficiently small size. N(   R)   R[  Rn  Rc  (   RQ  R[  Rn  Rd  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRf    s    	!i   c         C  s-   |  } x  t  |  D] } | j   } q W| S(   s<   Perform several steps of complex root refinement algorithm. (   R   Rc  (   RQ  RO   Rd  R]   (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRg    s    c         C  s
   |  j    S(   s7   Perform one step of complex root refinement algorithm. (   Rc  (   RQ  (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyRh    s    N(   Ri  Rj  Rk  R[   RS  Rl  RT  RU  RX  R9  R:  R`  Ra  R[  Rn  R\  R?  R]  R>  Rb  Rc  Re  R)   Rf  Rg  Rh  (    (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyR=    s*   							
N(   i    i   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   ii   (   i    i   (   i    i   (W   Rk  t
   __future__R    R   t   sympy.core.compatibilityR   t   sympy.polys.densearithR   R   R   t   sympy.polys.densebasicR   R   R   R	   R
   R   R   t   sympy.polys.densetoolsR   R   R   R   R   R   R   R   R   R   t   sympy.polys.factortoolsR   t   sympy.polys.polyerrorsR   R   t   sympy.polys.sqfreetoolsR   R   R"   R4   R6   R>   R@   R[   RK   R)   RU   RV   R_   Rl   Ro   Rr   Rs   Rv   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  R6  R7  RJ  RK  RN  t   objectRx   R=  (    (    (    s8   lib/python2.7/site-packages/sympy/polys/rootisolation.pyt   <module>   s  4F	&	,				.*#r	")>>



		L		J	j	j			}