Ë
    7^(h¡�  ã                   ó  — d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE  ed«      ZFd„ ZGd„ ZHd.d„ZId „ ZJd!„ ZKd"„ ZLd#„ ZMd.d$„ZNd%„ ZOd&„ ZPd'„ ZQd(„ ZReCd)d)dd)dddddd*œ	d+„«       ZSdd,œd-„ZTy)/z8Algorithms for computing symbolic roots of polynomials. é    N)Úreduce)ÚSÚIÚpi)Úfactor_terms)Ú_mexpand)Ú	fuzzy_not)Úexpand_2argÚMul)Úigcd)ÚRationalÚcomp)ÚPow)ÚEq)Úordered)ÚDummyÚSymbolÚsymbols)Úsympify)ÚexpÚimÚcosÚacosÚ	Piecewise)ÚrootÚsqrt)ÚdivisorsÚisprimeÚ	nextprime)ÚEX)ÚPolynomialErrorÚGeneratorsNeededÚDomainErrorÚUnsolvableFactorError)ÚPolyQuintic)ÚPolyÚcancelÚfactorÚgcd_listÚdiscriminant)Útogether)Úcyclotomic_poly)Úpublic)Ú
filldedentÚzc                 óØ   — | j                  d«       | j                  d«      z  }| j                  «       }|j                  s(|j                  rt	        |«      }|gS ddlm}  ||«      }|gS )z/Returns a list of roots of a linear polynomial.r   é   ©Úsimplify)ÚnthÚ
get_domainÚis_NumericalÚis_Compositer(   Úsympy.simplify.simplifyr3   )ÚfÚrÚdomr3   s       úS/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/polyroots.pyÚroots_linearr=   %   sb   € à	
�‰ˆq‹ˆ	�!—%‘%˜“(Ñ€AØ
�,‰,‹.€Cà×ÒØ×ÒÜ�q“	ˆAð
 ˆ3€Jõ 9Ù˜“ˆAàˆ3€Jó    c                 ó²  ‡— | j                  «       \  }}}| j                  «       Šd„ }ˆfd„}|t        j                  u rBt        j                  | |z  }}‰j                  s ||«      }||gS |j
                  r||}}||gS |t        j                  u r+| |z  }‰j                  s ||«      } ||«      }	|	 }|	}||gS |dz  d|z  |z  z
  }
d|z  }| |z  }‰j                  s ||
«      }
 ||«      }t         ||
«      |z  «      }||z
  }||z   }|j
                  r||}}||gS ‰j                  s||fD �cg c]  }t        |«      ‘Œ c}\  }}||gS c c}w )aP  Returns a list of roots of a quadratic polynomial. If the domain is ZZ
    then the roots will be sorted with negatives coming before positives.
    The ordering will be the same for any numerical coefficients as long as
    the assumptions tested are correct, otherwise the ordering will not be
    sorted (but will be canonical).
    c                 ó„  — g }g }t        j                  | «      D ]z  }|j                  r[|j                  j                  rE|j                  dz  dk(  r3|j                  t        |j                  |j                  dz  «      «       Œj|j                  |«       Œ| |rt        |Ž } t        |Ž }|t        | «      z  S t        | «      S )Né   r   )	r   Ú	make_argsÚis_Powr   Ú
is_IntegerÚappendr   Úbaser   )ÚdÚcoÚotherÚdis       r<   Ú_sqrtzroots_quadratic.<locals>._sqrt?   s    € ð ˆØˆÜ—-‘- Ó"ò 	!ˆBØ�yŠy˜RŸV™V×.Ò.°2·6±6¸A±:À²?Ø—	‘	œ#˜bŸg™g r§v¡v¨q¡yÓ1Õ2à—‘˜RÕ ð		!ñ
 Ü�U�ˆAÜ�b�ˆBØ”d˜1“g‘:ÐÜ�A‹wˆr>   c                 óN   •— ‰j                   rt        | «      S ddlm}  || «      S )Nr   r2   )r7   r(   r8   r3   )Úexprr3   r;   s     €r<   Ú	_simplifyz"roots_quadratic.<locals>._simplifyP   s#   ø€ Ø×ÒÜ˜$“<Ðå8Ù˜D“>Ð!r>   rA   é   )Ú
all_coeffsr5   r   ÚZeror6   Úis_negativer   r
   )r9   ÚaÚbÚcrK   rN   Úr0Úr1r:   ÚRrG   ÚAÚBÚDÚir;   s                  @r<   Úroots_quadraticr]   4   s‰  ø€ ð �l‰l‹n�G€A€qˆ!Ø
�,‰,‹.€Còô""ð 	ŒA�F‰F�{Ü—‘˜!˜˜A™ˆBˆà×ÒÙ˜2“ˆBð8 �ˆ8€Oð7 �^Š^Ø˜�ˆBð4 �ˆ8€Oð3 
Œa�f‰f‰ØˆBˆq‰DˆØ×ÒÙ˜!“ˆAá�!‹HˆØˆRˆØˆð$ �ˆ8€Oð! ˆq‰D�1�Q‘3�q‘5‰LˆØˆa‰CˆØˆBˆq‰Dˆà×ÒÙ˜!“ˆAÙ˜!“ˆAä™˜q› !™Ó$ˆØ�‰UˆØ�‰UˆØ�=Š=Ø˜�ˆBð �ˆ8€Oð ×!Ò!Ø/1°2¨hÖ7¨”k !•nÒ7‰FˆB�à�ˆ8€Oùò 8s   Ä8EFc                 ó¦  — |�r8| j                  «       \  }}}}d|z  |z  |dz  z
  d|dz  z  z  }d|dz  z  d|z  |z  |z  z
  d|dz  z  |z  z   d|dz  z  z  }d|z  |z  |z  |z  d|dz  z  |z  z
  |dz  |dz  z  z   d|z  |dz  z  z
  d|dz  z  |dz  z  z
  }|dkD  dk(  ršg }	t        d«      D ]q  }
|	j                  dt        | dz  «      z  t	        t        ||z  t        d	|z  «      z  t        dd«      z  «      dz  |
t        z  t        dd«      z  z
  «      z  «       Œs |	D �cg c]  }||dz  |z  z
  ‘Œ c}S | j                  «       j                  «       \  }}}}|t        j                  u r&t        d
||gd¬«      \  }}|t        j                  |gS ||dz  dz  z
  }|||z  dz  z
  d|dz  z  dz  z   }|dz  }|dz  }d}|t        j                  u r@|t        j                  u r| gdz  S |j                  rt        |d«       nt        | d«      }nŠ|t        j                  u r7t        d
d|gd¬«      \  }}|t        j                  |fD �cg c]  }||z
  ‘Œ	 c}S |j                  r5|j                  r)t        | dz  t        |dz  dz  |dz  z   «      z   d«       }t         t        d«      z  dz  }|€£t        j"                  }t        dd«      |z   }t        dd«      |z
  }|||}}}|dz  d|z  z
  }d|dz  z  d|z  |z  z
  d|z  z   }t        |t        |dz  d|dz  z  z
  «      z   dz  d«      }|||fD �cg c]  }|||z  z   ||z  |z  z    dz  ‘Œ c}S |t        dd«      |z   z  }|t        dd«      |z
  z  }|t        j                  u r||z
  ||z
  ||z
  gS | ||z  z   |z
  | ||z  z   |z
  | ||z  z   |z
  g}|S c c}w c c}w c c}w )zÅReturns a list of roots of a cubic polynomial.

    References
    ==========
    [1] https://en.wikipedia.org/wiki/Cubic_function, General formula for roots,
    (accessed November 17, 2014).
    é   rA   é	   é   é   rO   r   Téýÿÿÿr1   ©ÚmultipleNéÿÿÿÿ)rP   ÚrangerE   r   r   r   r   r   Úmonicr   rQ   ÚrootsÚis_positiver   Úis_realrR   r   ÚOne)r9   ÚtrigrS   rT   rU   rG   ÚpÚqr[   ÚrvÚkr\   Ú_Úx1Úx2Úpon3Úaon3Úu1Úy1Úy2ÚtmpÚcoeffÚu2Úu3ÚD0ÚD1ÚCÚukÚsolns                                r<   Úroots_cubicrƒ   z   sY  € ò Ø—\‘\“^‰
ˆˆ1ˆa�Øˆq‰S�‰U�Q˜‘T‰\˜A˜a ™d™FÑ#ˆØˆq�!‰t‰V�a˜‘c˜!‘e˜A‘gÑ  1 a¡4¡¨¡	Ñ)¨B¨q°!©t©GÑ4ˆØˆq‰D�‰F�1‰H�Q‰J˜˜1˜a™4™ ™Ñ! A q¡D¨¨A©¡IÑ-°°!±°A°q±D±Ñ8¸2¸aÀ¹d¹7À1ÀaÁ4¹<ÑGˆØ�‰E�dŠ?ØˆBÜ˜1“Xò i�Ø—	‘	˜!œD !  A¡›J™,¤s¬4°°!±´D¸¸A¹³J±¼xÈÈ1»~Ñ0MÓ+NÈqÑ+PÐSTÔUWÑSWÔX`ÐabÐdeÓXfÑSfÑ+fÓ'gÑgÕhðià')Ö* !�A˜˜!™˜A™“IÒ*Ð*ð —‘“×%Ñ%Ó'�J€A€qˆ!ˆQàŒA�F‰F�{Ü˜˜1˜a�y¨4Ô0‰ˆˆBØ”A—F‘F˜BÐÐð 	
ˆAˆq‰D�‰F‰
€AØ	ˆAˆa‰C�‰E‰	�A�a˜‘d‘F˜2‘IÑ€AàˆQ‰3€DØˆQ‰3€Dà	€BØŒA�F‰F�{Ø”—‘‰;Ø�E�7˜1‘9ÐØŸMšMŒd�1�a‹j‰[¬t°Q°B¸«{‰Ø	
Œa�f‰f‰Ü˜˜1˜a�y¨4Ô0‰ˆˆBØ')¬1¯6©6°2Ð&6Ö7˜s��d“
Ò7Ð7Ø	
�Š�q—}’}Ü�A�2�a‘4œ$˜q !™t A™v¨¨a©Ñ/Ó0Ñ0°!Ó4Ð4ˆäŒd�1‹g‰I�a‰K€EØ	€zÜ�U‰UˆÜ�b˜!‹_˜uÑ$ˆÜ�b˜!‹_˜uÑ$ˆØ�Q˜ˆaˆ1ˆØ�‰T�A�a‘C‰ZˆØˆq�!‰t‰V�a˜‘c˜!‘e‰^˜b ™dÑ"ˆÜ�"”t˜B ™E A b¨!¡e¡G™OÓ,Ñ,¨aÑ/°Ó3ˆØ35°r¸2°,Ö?¨B�!�b˜‘d‘(˜R ™T "™WÑ$Ð% aÓ'Ò?Ð?à	ŒX�b˜!‹_˜uÑ$Ñ	%€BØ	ŒX�b˜!‹_˜uÑ$Ñ	%€BàŒA�F‰F�{Ø�T‘	˜2 ™9 b¨4¡iÐ0Ð0ð 
ˆˆd�2‰g‰˜ÑØ	ˆˆd�2‰g‰˜ÑØ	ˆˆd�2‰g‰˜Ñð€Dð €Kùòe +ùò. 8ùò @s   Ä'OÉO	Ì<Oc                 óü  — t        d«      }d|dz  z  d| z  |dz  z  z   d| dz  z  d|z  z
  |z  z   |dz  z
  }t        t        t        ||«      d¬	«      j	                  «       «      }|D �cg c]  }|j
                  sŒ|j                  sŒ|‘Œ  }}|sy
t        |«      }t        |«      }	| |	z  d|z  z  }
| | dz  z
  }t        ||
z   «      }t        ||
z
  «      }|	|z
  |z
  |	 |z
  |z
  |	 |z   |z
  |	|z   |z
  gS c c}w )al  
    Descartes-Euler solution of the quartic equation

    Parameters
    ==========

    p, q, r: coefficients of ``x**4 + p*x**2 + q*x + r``
    a: shift of the roots

    Notes
    =====

    This is a helper function for ``roots_quartic``.

    Look for solutions of the form ::

      ``x1 = sqrt(R) - sqrt(A + B*sqrt(R))``
      ``x2 = -sqrt(R) - sqrt(A - B*sqrt(R))``
      ``x3 = -sqrt(R) + sqrt(A - B*sqrt(R))``
      ``x4 = sqrt(R) + sqrt(A + B*sqrt(R))``

    To satisfy the quartic equation one must have
    ``p = -2*(R + A); q = -4*B*R; r = (R - A)**2 - B**2*R``
    so that ``R`` must satisfy the Descartes-Euler resolvent equation
    ``64*R**3 + 32*p*R**2 + (4*p**2 - 16*r)*R - q**2 = 0``

    If the resolvent does not have a rational solution, return None;
    in that case it is likely that the Ferrari method gives a simpler
    solution.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.polys.polyroots import _roots_quartic_euler
    >>> p, q, r = -S(64)/5, -S(512)/125, -S(1024)/3125
    >>> _roots_quartic_euler(p, q, r, S(0))[0]
    -sqrt(32*sqrt(5)/125 + 16/5) + 4*sqrt(5)/5
    Úxé@   r_   é    rA   rO   é   F)ÚcubicsN)	r   Úlistri   r&   ÚkeysÚis_rationalÚ
is_nonzeroÚmaxr   )rn   ro   r:   rS   r…   ÚeqÚxsolsÚsolrX   Úc1rZ   rY   Úc2Úc3s                 r<   Ú_roots_quartic_eulerr•   ¿   s  € ôR 	ˆc‹
€AØ	ˆAˆq‰D‰�2�a‘4˜˜1™‘9Ñ	  ! Q¡$¡¨¨A©¡¨qÑ0Ñ	0°1°a±4Ñ	7€BÜ””t˜B “{¨5Ô1×6Ñ6Ó8Ó9€EØ!ÖH�S S§_£_¸¿»ŠSÐH€EÐHÙØÜˆE‹
€AÜ	ˆa‹€BØ	
ˆˆ2‰ˆq�‰s‰€AØ	
ˆˆQˆq‰S‰€AÜ	ˆa�!‰e‹€BÜ	ˆa�!‰e‹€BØ�‰G�a‰K˜"˜˜r™ A™¨ s¨R¡x°!¡|°R¸"±W¸q±[ÐAÐAùò Is   Á*C9Á<C9Â	C9c                 óö  ‡ ‡‡— ‰ j                  «       j                  «       \  }}}}}|s#t        j                  gt	        d|||gd¬«      z   S ||z  dz  |k(  rˆ‰ j
                  ||z  }}t        |dz  ||z  z   |z   d|z  z
  |«      }t        |«      \  }	}
t        |dz  |	|z  z
  |z   |«      }t        |dz  |
|z  z
  |z   |«      }t        |«      }t        |«      }||z   S |dz  }|d|z  dz  z
  Št        |||dz  |dz  z
  z  z   «      Š |dz  Št        |‰|d|z  dz  |dz  z
  z  |z   z  z
  «      }‰ j                  rCt	        d‰|gd¬«      D �cg c]  }t        |«      ‘Œ c}\  }}| | ||fD �cg c]  }|‰z
  ‘Œ	 c}S |j                  r6t        j                  gt	        dd	‰‰ gd¬«      z   }|D �cg c]  }|‰z
  ‘Œ	 c}S t        ‰‰ |‰«      }|r|S ‰dz   d
z  |z
  }‰dz   dz  ‰|z  dz  z   ‰ dz  dz  z
  }t        dd«      }ˆˆˆ fd„}t        |«      }‰t        dd«      z  ||z  z
  }|j                  r ||«      S t        |dz  dz  |dz  dz  z   «      }| dz  |z   }||z  }‰t        dd«      z  |z   ||z  dz  z
  }t        |j                  «      r ||«      S t         ||«       ||«      «      D ��cg c]  \  }}t        |t!        |d	«      f|df«      ‘Œ! c}}S c c}w c c}w c c}w c c}}w )aÂ  
    Returns a list of roots of a quartic polynomial.

    There are many references for solving quartic expressions available [1-5].
    This reviewer has found that many of them require one to select from among
    2 or more possible sets of solutions and that some solutions work when one
    is searching for real roots but do not work when searching for complex roots
    (though this is not always stated clearly). The following routine has been
    tested and found to be correct for 0, 2 or 4 complex roots.

    The quasisymmetric case solution [6] looks for quartics that have the form
    `x**4 + A*x**3 + B*x**2 + C*x + D = 0` where `(C/A)**2 = D`.

    Although no general solution that is always applicable for all
    coefficients is known to this reviewer, certain conditions are tested
    to determine the simplest 4 expressions that can be returned:

      1) `f = c + a*(a**2/8 - b/2) == 0`
      2) `g = d - a*(a*(3*a**2/256 - b/16) + c/4) = 0`
      3) if `f != 0` and `g != 0` and `p = -d + a*c/4 - b**2/12` then
        a) `p == 0`
        b) `p != 0`

    Examples
    ========

        >>> from sympy import Poly
        >>> from sympy.polys.polyroots import roots_quartic

        >>> r = roots_quartic(Poly('x**4-6*x**3+17*x**2-26*x+20'))

        >>> # 4 complex roots: 1+-I*sqrt(3), 2+-I
        >>> sorted(str(tmp.evalf(n=2)) for tmp in r)
        ['1.0 + 1.7*I', '1.0 - 1.7*I', '2.0 + 1.0*I', '2.0 - 1.0*I']

    References
    ==========

    1. http://mathforum.org/dr.math/faq/faq.cubic.equations.html
    2. https://en.wikipedia.org/wiki/Quartic_function#Summary_of_Ferrari.27s_method
    3. https://planetmath.org/encyclopedia/GaloisTheoreticDerivationOfTheQuarticFormula.html
    4. https://people.bath.ac.uk/masjhd/JHD-CA.pdf
    5. http://www.albmath.org/files/Math_5713.pdf
    6. https://web.archive.org/web/20171002081448/http://www.statemaster.com/encyclopedia/Quartic-equation
    7. https://eqworld.ipmnet.ru/en/solutions/ae/ae0108.pdf
    r1   Trd   rA   r_   é   rO   r†   r   é   él   c                 óÔ   •— t        ‰	d| z  z   «      }d‰	z  d| z  z   }d‰
z  |z  }g }dD ];  }t        |||z  z    «      }dD ]"  }|j                  ||z  ||z  z
  dz  ‰z
  «       Œ$ Œ= |S )NrA   r_   ©rf   r1   )r   rE   )ÚyÚwÚarg1Úarg2ÚansÚsr   ÚtÚaon4Úer9   s           €€€r<   Ú_anszroots_quartic.<locals>._ansP  s“   ø€ Ü˜˜Q˜q™S™“M�Ø˜‘s˜Q˜q™S‘y�Ø˜‘s˜1‘u�Ø�Ø ò <�AÜ $¨¨4©¡-Ð 0Ó1�DØ$ò <˜ØŸ
™
 A a¡C¨!¨D©&¡L°!Ñ#3°dÑ#:Õ;ñ<ð<ð �
r>   éûÿÿÿé   ra   )rh   rP   r   rQ   ri   Úgenr&   r]   r   Úis_zeror   r•   r   r	   Úzipr   r   )r9   rr   rS   rT   rU   rG   r…   ÚmÚgÚz1Úz2Úh1Úh2rW   Úr2Úa2rz   rx   ry   rœ   Úsolsrn   ro   ÚTHr¥   r   r:   ÚuÚa1r£   r¤   s   `                            @@r<   Úroots_quarticr·   ÷   sQ  ú€ ð^ —G‘G“I×(Ñ(Ó*�M€A€qˆ!ˆQ�áÜ—‘ˆxœ%  A q¨! °tÔ<Ñ<Ð<Ø
ˆA‰#�‰�QŠØ�u‰u�a˜‘cˆ1ˆä��A‘˜˜!™‘˜a‘ ! A¡#Ñ% qÓ)ˆä  Ó#‰ˆˆBä�!�Q‘$˜˜A™‘+ ‘/ 1Ó%ˆÜ�!�Q‘$˜˜A™‘+ ‘/ 1Ó%ˆä˜RÓ ˆÜ˜RÓ ˆà�B‰wˆà�‰TˆØ��"‘�Q‘‰JˆÜ�Q˜˜B˜q™D 1 Q¡3™J™Ñ'Ó(ˆØ�‰sˆÜ�Q˜˜q ! B¡$ r¡'¨A¨a©C¡-Ñ0°1Ñ4Ñ5Ñ5Ó6ˆà�9Š9ä˜Q  1˜I°Ô5ö7 C”d˜3•iò 7‰FˆB�à,.¨3°°°R¸Ð*<Ö= 3�C˜$“JÒ=Ð=Ø�9Š9Ü—‘�œ5 ! Q¨¨1 ¸Ô=Ñ=ˆAØ*+Ö, 3�C˜$“JÒ,Ð,ô (¨¨1¨a°Ó6ˆDÙØ�à�A‘��b‘˜1‘ˆAØ�A‘��c‘	˜A˜a™C ™EÑ! A q¡D¨¡FÑ*ˆAÜ˜!˜Q“ˆBö	ô ˜“ˆAð ”8˜B “?Ñ" Q¨¡UÑ*ˆBØ�yŠyÙ˜B“x�ô ˜˜1™˜Q™  A¡ b¡Ñ(Ó)ˆDØ��1‘�t‘ˆAØ�2‘ˆAØ”8˜B “?Ñ" QÑ&¨¨1©¨Q©Ñ.ˆBÜ˜Ÿ™Ô#Ù˜B“x�ô #&¡d¨2£h±°R³Ó"9÷;Ù˜˜Bô ˜r¤2 a¨£8˜n¨r°4¨jÕ9ó ;ð ;ùò_7ùâ=ùò -ùóT;s   ÅK&Å2K+Æ4K0Ê>$K5c                 ól  — | j                  «       }| j                  |«      | j                  d«      }}t        ||z  «       }t        ||«      }|j                  r|j                  d¬«      }|j                  }|dz  dk(  }|r|dk(  r|dz   j                  rd}nd}g }	|dz  }
|r|	j                  |
«       |
dz  }
|s|	j                  d«       t        |
dd«      D ]-  }|r|	j                  || g«       Œ|	j                  | |g«       Œ/ |rJ|	j                  d«       r7t        dt        |	«      d«      D ]  }|	||dz    }t        t        |«      «      }Œ  g dt        z  t        z  |z  }}|	D ]D  }t!        ||z  «      j                  d¬«      }|j                  ||z  j                  d¬«      «       ŒF |S )	aO  Returns a list of roots of a binomial polynomial. If the domain is ZZ
    then the roots will be sorted with negatives coming before positives.
    The ordering will be the same for any numerical coefficients as long as
    the assumptions tested are correct, otherwise the ordering will not be
    sorted (but will be canonical).
    r   T©ÚcomplexrA   r1   Frf   )Ú
power_base)Údegreer4   r'   r   Ú	is_numberÚexpandrR   rj   rE   rg   ÚextendÚlenrŠ   Úreversedr   r   r   )r9   ÚnrS   rT   rF   ÚalphaÚnegÚevenÚbigÚksÚimaxr\   Úpairri   rG   rq   Úzetas                    r<   Úroots_binomialrË   s  s¶  € ð 	
�‰‹
€Aà�5‰5�‹8�Q—U‘U˜1“X€q€AÜ�1�Q‘3‹Kˆ<€DÜ��q‹M€Eà‡‚Ø—‘ T�Ó*ˆð ×
Ñ
€CØˆq‰5�A‰:€DÙ
Ø�4Š<˜T A™X×2Ò2Ø‰CàˆCð 
€BØˆa‰4€DÙØ
�	‰	�$ŒØ�‰	ˆÙØ
�	‰	�!ŒÜ�4˜˜BÓò ˆÙØ�I‰I�q˜1˜"�gÕà�I‰I˜�r˜1�gÕð	ñ
 Ø
�	‰	�!ŒÙÜ˜1œc "›g qÓ)ò ,�Ø˜!˜Q ™U�|�ÜœH T›NÓ+‘ð,ð
 �1”Q‘3”r‘6˜!‘8ˆ1€EØò <ˆÜ�1�Q‘3‹x�‰ tˆÓ,ˆØ�‰�e˜D‘j×(Ñ(°EÐ(Ó:Õ;ð<ð €Lr>   c                 óè  — t        | «      D �cg c]  }t        |dz   «      sŒ|dz   ‘Œ }}d\  }}|D ]  }||z  }||dz
  z  }Œ | }t        t        j                  | t        |«      |z  z  «      «      }dx}}g }||k  r't        |«      }|j                  |«       ||z  }||k  rŒ'||z  }d}|dd D ]
  }||dz
  z  }Œ t        t        j                  | t        |«      |z  z  «      «      }||fS c c}w )zÿ
    Find ``(L, U)`` such that ``L <= phi^-1(m) <= U``.

    Examples
    ========

    >>> from sympy.polys.polyroots import _inv_totient_estimate

    >>> _inv_totient_estimate(192)
    (192, 840)
    >>> _inv_totient_estimate(400)
    (400, 1750)

    r1   )r1   r1   rA   Nrf   )r   r   ÚintÚmathÚceilÚfloatr   rE   )	r«   rG   ÚprimesrS   rT   rn   ÚLÚUÚPs	            r<   Ú_inv_totient_estimaterÕ   ­  s  € ô ' q›kÖ=˜¬W°Q¸±U­^ˆq�1‹uÐ=€FÐ=à�D€A€qàò ˆØ	ˆQ‰ˆØ	ˆQ�‰U‰
‰ðð 	
€AÜŒD�I‰I�aœ˜q› !™‘nÓ%Ó&€Aà€I€AˆØ€Fà
ˆqŠ&Ü�a‹LˆØ�‰�aÔØ	ˆQ‰ˆð ˆq‹&ð
 ˆ!�G€AØ	€Aà�C�Rˆ[ò ˆØ	ˆQ�‰U‰
‰ðô 	ŒD�I‰I�aœ˜q› !™‘nÓ%Ó&€Aàˆaˆ4€Kùò7 >s
   ŽC/¢C/c                 óà  ‡‡— t        | j                  «       «      \  }}t        ||dz   «      D ]5  Št        ‰| j                  d¬«      }| j
                  |j
                  k(  sŒ5 n t        d«      ‚g }|s™‰dz  Št        d‰dz   «      D �cg c]  }t        |‰«      dk(  sŒ|‘Œ }}|j                  ˆˆfd„¬«       dt        z  t        z  ‰z  }t        |«      D ]/  }	|j                  t        |	|z  «      j                  d¬«      «       Œ1 |S t        | t!        d	‰«      ¬
«      }t#        |j%                  «       d   «      D ]%  \  Š}
|j                  ‰j'                  «        «       Œ' |S c c}w )z)Compute roots of cyclotomic polynomials. r1   T)Úpolysz/failed to find index of a cyclotomic polynomialrA   c                 ó6   •— | ‰k  r| dfS t        | ‰z
  «      dfS )Nrf   r1   )Úabs)r…   ÚhrÂ   s    €€r<   ú<lambda>z"roots_cyclotomic.<locals>.<lambda>í  s!   ø€ ¨¨aª˜q "˜g€ ´c¸!¸a¹%³jÀ!°_€ r>   )Úkeyr¹   rf   )Ú	extension)rÕ   r¼   rg   r,   r¨   rM   ÚRuntimeErrorr   Úsortr   r   rÁ   rE   r   r¾   r&   r   r   Úfactor_listÚTC)r9   r(   rÒ   rÓ   r¬   ri   r\   rÇ   rG   rq   rr   rÚ   rÂ   s              @@r<   Úroots_cyclotomicrâ   Ú  sQ  ù€ ä  §¡£Ó,�D€A€qä�1�a˜!‘e‹_ò NˆÜ˜A˜qŸu™u¨DÔ1ˆà�6‰6�Q—V‘VÓÙð	Nô ÐLÓMÐMà€Eáð ˆq‰DˆÜ˜q ! a¡%›Ö<�A¬D°°A«J¸!«OŠaÐ<ˆÐ<Ø
�‰ÔDˆÔEØŒa‰C”‰F�1‰HˆÜ˜"“ò 	8ˆAØ�L‰Lœ˜Q˜q™S›Ÿ™°˜Ó6Õ7ð	8ð €Lô �œd 2 q›kÔ*ˆä˜AŸM™M›O¨AÑ.Ó/ò 	"‰DˆAˆqØ�L‰L˜!Ÿ$™$›&˜Õ!ð	"ð €Lùò =s   ÂE+Â E+c           
      óf  — g }| j                  «       \  }}}}}}t        d„ ||||||fD «       «      s|S |dk7  r%t        | |z  «      } | j                  «       \  }}}}}}|r¶|d|z  |z  dz  z
  }	|d|z  |z  dz  z
  d|dz  z  dz  z   }
|d|z  |z  dz  z
  d|dz  z  |z  dz  z   d|dz  z  dz  z
  }|||z  dz  z
  |dz  |z  dz  z   |dz  |z  dz  z
  d|dz  z  d	z  z   }| j                  }t        |dz  |	|dz  z  z   |
|dz  z  z   ||z  z   |z   «      } n||||f\  }	}
}}t	        | «      }| j
                  s|S |j                  }|j
                  r|S |j                  «       d   D ]'  }|d
   j                  sŒ|d
   j                  d
«      } n t        | «      }t        |«      }|j                  \  }}}}|j                  |«      }t        d«      }|d   |d   |z  z   }|d   |d   |z  z
  }|d   |d   |z  z   }|d   |d   |z  z
  }|dz  d|z  z
  }|dz  d|z  z
  }|j                  |«      } t        d«      }!t!        | t        |«      z   |!z  «      }"t!        | t        |«      z
  |!z  «      }#t!        | t        |«      z   |!z  «      }$t!        | t        |«      z
  |!z  «      }%|j#                  ||«      }&|&|j%                  «       z  |"j%                  «       |#j%                  «       z
  |$j%                  «       |%j%                  «       z
  z  z
  }'t'        |'d
|«      s|%|$}%}$| |"|z  z   |$|z  z   |%|z  z   |#|z  z   }(| |%|z  z   |"|z  z   |#|z  z   |$|z  z   })| |$|z  z   |#|z  z   |"|z  z   |%|z  z   }*| |#|z  z   |%|z  z   |$|z  z   |"|z  z   }+ddgdz  dgdz  dgdz  dgdz  g},ddgdz  dgdz  dgdz  dgdz  g}-t!        |(«      }(t!        |)«      })t!        |*«      }*t!        |+«      }+t(        t        d«      dz  z  }.t        d«      }/t        d«      }0t        d|0z
  «      }1t*        |0z  }2|2t*        z   }3t*        |.z  dz  }4|/t        |0dz   «      z  }5|.|4 |/|1z  |3z
  z  |4|/|1z  |3z   z  |4 |2|5z   t*        z
  z  |4|2 |5z   t*        z   z  g}6|(j-                  «       }(|)j-                  «       })|*j-                  «       }*|+j-                  «       }+t/        |6«      D ]Ý  \  }7}t!        |j1                  t(        |(d
   t*        |(d   z  z   i«      «      |,d   |7<   t!        |j1                  t(        |)d
   t*        |)d   z  z   i«      «      |,d   |7<   t!        |j1                  t(        |*d
   t*        |*d   z  z   i«      «      |,d   |7<   t!        |j1                  t(        |+d
   t*        |+d   z  z   i«      «      |,d   |7<   Œß t3        dd«      D ]E  }7t3        d«      D ]5  }8|,|7   |8   j%                  «       |-|7   |8<   t!        |,|7   |8   «      |,|7   |8<   Œ7 ŒG |,d   d
   }9|-d   d
   }:t3        d«      D ]+  }7t'        t5        |:|-d   |7   z  «      d
|«      sŒ#|,d   |7   }; n |j7                  ||«      \  }<}=|<|=|z  t        d«      z  z   j%                  «       }>|<|=|z  t        d«      z  z
  j%                  «       }?;j%                  «       }@dx}A}Bt3        d«      D ]“  }7|-d   |7   }Ct3        d«      D ]w  }8|-d   |8   }Dt'        |:Cdz  z  @|Ddz  z  z   |>z
  j%                  «       d
|«      sŒ9t'        D|:dz  z  C@dz  z  z   |?z
  j%                  «       d
|«      sŒg|,d   |7   }A|,d   |8   }B n A€Œ“ n g S |9Az   Bz   |;z   dz  }/|9|z  |A|z  z   |B|z  z   |;|z  z   dz  }0|9|z  |A|z  z   |B|z  z   |;|z  z   dz  }1|9|z  |A|z  z   |B|z  z   |;|z  z   dz  }2|9|z  |A|z  z   |B|z  z   |;|z  z   dz  }3|/|0|1|2|3g}t9        «       }E|D ],  }|j%                  d«      }|Ev rg c S Ej;                  |«       Œ. |r|D �cg c]
  }||dz  z
  ‘Œ }}|S c c}w )z£
    Calculate exact roots of a solvable irreducible quintic with rational coefficients.
    Return an empty list if the quintic is reducible or not solvable.
    c              3   ó4   K  — | ]  }|j                   –— Œ y ­w©N©Úis_Rational)Ú.0r{   s     r<   ú	<genexpr>z roots_quintic.<locals>.<genexpr>  s   è ø€ ÒQ Uˆu× Õ ÑQùó   ‚r1   rA   é   r_   rO   é   é}   i5  r   g»½×Ùß|Û=N)rP   Úallr&   r¨   r%   Úis_irreducibleÚf20rà   Ú	is_linearr   r*   r   rÊ   ÚTr   Úl0Ú_quintic_simplifyÚorderrÂ   r   r/   r   Úas_real_imagÚ	enumerateÚxreplacerg   r   ÚuvÚsetÚadd)Fr9   ÚresultÚcoeff_5Úcoeff_4Úp_Úq_Úr_Ús_rr   rn   ro   r:   r¡   r…   Úquinticrð   Ú_factorÚthetarG   ÚdeltaÚzeta1Úzeta2Úzeta3Úzeta4rò   ÚtolrÃ   Ú	alpha_barÚbetaÚbeta_barÚdiscÚdisc_barró   ÚStwoÚl1Úl4Úl2Úl3rõ   ÚtestÚR1ÚR2ÚR3ÚR4ÚResÚRes_nÚx0rs   rt   Úx3Úx4Úx5Úx6Úx7r‘   r\   ÚjrW   Úr1_nÚr4rµ   ÚvÚtestplusÚ	testminusÚr4_nr±   Úr3Úr2temp_nÚr3temp_nÚsawsF                                                                         r<   Úroots_quinticr.  ú  s�	  € ð
 €Fà'(§|¡|£~Ñ$€GˆW�b˜"˜b "äÑQ¨w¸ÀÀRÈÈRÐ.PÔQÔQØˆà�!‚|Ü��W‘ÓˆØ%&§\¡\£^Ñ"ˆˆ7�B˜˜B ñ Ø��7‘˜7Ñ" 1Ñ$Ñ$ˆØ��7‘˜2‘˜a‘Ñ ! G¨Q¡J¡,¨r¡/Ñ1ˆØ��7‘˜2‘˜a‘Ñ ! G¨Q¡J¡,¨r¡/°"Ñ"4Ñ4°q¸À!¹±|ÀCÑ7GÑGˆØ�˜‘˜A‘Ñ ¨¡
¨2¡¨bÑ 0Ñ0°7¸A±:¸b±=ÀÑ3DÑDÀqÈÐRSÉÁ|ÐTXÑGXÑXˆØ�E‰EˆÜ��A‘˜˜!˜Q™$™‘  1 a¡4¡Ñ'¨!¨A©#Ñ-°Ñ1Ó2‰à˜˜R �^‰
ˆˆ1ˆa�ä˜!‹n€Gð ×ÒØˆØ
�+‰+€Cà
×ÒØˆà—?‘?Ó$ QÑ'ò ˆØ�1‰:×ÓØ˜A‘J—O‘O AÓ&ˆEÙðô 	�Q‹€AÜ�‹G€Eà!(§¡Ñ€Eˆ5�%˜Ø�	‰	�%˜Ó€AÜ
ˆE‹(€CØˆa‰D�1�Q‘4˜‘:Ñ€EØ�!‘�q˜‘t˜E‘zÑ!€IØˆQ‰4�!�A‘$�u‘*Ñ€DØ�‰t�a˜‘d˜5‘jÑ €Hà�!‰8�a˜‘fÑ€DØ˜!‰|˜a ™jÑ(€Hà	�‰�EÓ	€BÜˆQ‹4€DÜ	˜U˜F¤T¨$£ZÑ/°4Ñ7Ó	8€BÜ	˜U˜F¤T¨$£ZÑ/°4Ñ7Ó	8€Bä	˜Y˜J¬¨h«Ñ7¸4Ñ?Ó	@€BÜ	˜Y˜J¬¨h«Ñ7¸4Ñ?Ó	@€Bà�M‰M˜% Ó#€EØ�%—'‘'“)‰O "§$¡$£&¨2¯4©4«6¡/°B·D±D³F¸R¿T¹T»V±OÑ!DÑF€Dä��a˜ÔØ�RˆBˆð 
ˆb�‰h‰˜˜E™Ñ	! B u¡HÑ	,¨r°%©xÑ	7€BØ	ˆb�‰h‰˜˜E™Ñ	! B u¡HÑ	,¨r°%©xÑ	7€BØ	ˆb�‰h‰˜˜E™Ñ	! B u¡HÑ	,¨r°%©xÑ	7€BØ	ˆb�‰h‰˜˜E™Ñ	! B u¡HÑ	,¨r°%©xÑ	7€Bà�$�˜‘˜D˜6 !™8 d V¨A¡X°¨v°a©xÐ
8€CØ�D�6˜!‘8˜d˜V A™X¨ v¨a¡x°$°¸±Ð:€Eô 
˜2Ó	€BÜ	˜2Ó	€BÜ	˜2Ó	€BÜ	˜2Ó	€Bô 
ŒQˆq‹T�!‰V‰€BÜ	ˆa‹€BÜ	ˆa‹€BÜ	ˆa�"‰f‹€BÜ	
ˆ2‰€BØ	Œa‰€BÜ	
ˆ2‰ˆa‰€BØ	ŒD��a‘‹L‰€BØ�ˆs�B�r‘E˜B‘JÑ  R¨¡U¨R¡Z¡°2°#°r¸B±wÄ±{Ñ2CÀRÈ"ÈÈrÉÔTUÉÑEVÐ
W€Cà	�‰Ó	€BØ	�‰Ó	€BØ	�‰Ó	€BØ	�‰Ó	€Bä˜#“ò H‰ˆˆ1Ü% a§j¡j´!°R¸±U¼Q¸rÀ!¹u¹W±_Ð1EÓ&FÓGˆˆA‰ˆq‰	Ü% a§j¡j´!°R¸±U¼Q¸rÀ!¹u¹W±_Ð1EÓ&FÓGˆˆA‰ˆq‰	Ü% a§j¡j´!°R¸±U¼Q¸rÀ!¹u¹W±_Ð1EÓ&FÓGˆˆA‰ˆq‰	Ü% a§j¡j´!°R¸±U¼Q¸rÀ!¹u¹W±_Ð1EÓ&FÓGˆˆA‰ˆqŠ	ð	Hô �1�a‹[ò 5ˆÜ�q“ò 	5ˆAØ˜a™& ™)Ÿ+™+›-ˆE�!‰H�Q‰KÜ)¨#¨a©&°©)Ó4ˆC�‰F�1ŠIñ	5ð5ð 
ˆQ‰�‰€BØ�‰8�A‰;€Dä�1‹Xò ˆÜ”�4˜˜a™ ™Ñ#Ó$ a¨Õ-Ø�Q‘˜‘ˆBÙðð �:‰:�e˜QÓ�D€A€qØ�A�e‘GœD ›G‘OÑ#×&Ñ&Ó(€HØ�Q�u‘WœT !›W‘_Ñ$×'Ñ'Ó)€Ið �4‰4‹6€DØ€N€Bˆä�1‹Xò ˆØ˜‘8˜A‘;ˆÜ�q“ò 	ˆAð ˜Q‘x ‘{ˆHÜ�d˜8 Q™;Ñ&¨¨h¸©kÑ)9Ñ9¸HÑD×GÑGÓIÈ1ÈcÕRÜ�h˜t Q™wÑ&¨°$¸±'Ñ)9Ñ9¸IÑE×HÑHÓJÈAÈsÕSØ˜‘V˜A‘Y�Ø˜‘V˜A‘Y�Ùð	ð ‰>Ùðð ˆ	ð ˆr‰'�B‰,˜Ñ
˜QÑ	€BØ
ˆU‰(�R˜‘XÑ
  5¡Ñ
(¨2¨e©8Ñ
3°QÑ	6€BØ
ˆU‰(�R˜‘XÑ
  5¡Ñ
(¨2¨e©8Ñ
3°QÑ	6€BØ
ˆU‰(�R˜‘XÑ
  5¡Ñ
(¨2¨e©8Ñ
3°QÑ	6€BØ
ˆU‰(�R˜‘XÑ
  5¡Ñ
(¨2¨e©8Ñ
3°QÑ	6€BØ�"�b˜"˜bÐ!€Fô ‹%€CØò ˆØ�C‰C�‹FˆØ�‰8ð ŠIØ�‰��
ðñ Ø+1Ö2 a�!�g ‘k“/Ð2ˆÐ2Ø€Mùò 3s   à`.c                 óJ   — ddl m}  || «      } t        | «      } t        | «      S )Nr   )Úpowsimp)r8   r0  r'   r+   )rM   r0  s     r<   rô   rô   ¤  s!   € Ý/Ù�4‹=€DÜ�$‹<€DÜ�D‹>Ðr>   c                 óÈ  — t        t        | j                  «       Ž «      \  }}t        t        |Ž «      \  }t        t        t        |«      «      }|d   |d   k  r5t        t        |«      «      }|d   }t        |«      D �cg c]  }||z
  ‘Œ	 }}ny|dd }|dd }t        |«      dk(  r;t        |d   t        j                  |d   z  «      }|j                  rt        |«      S yt        t        t        |«      «      dd «      }	 t        |«      }	 t        ||«      D ]  \  }}	|	||z  z  dk7  sŒ	 t        |«      } n |S Œ0c c}w # t        $ r Y yw xY w# t        $ r Y  yw xY w)a~  Compute coefficient basis for a polynomial over integers.

    Returns the integer ``div`` such that substituting ``x = div*y``
    ``p(x) = m*q(y)`` where the coefficients of ``q`` are smaller
    than those of ``p``.

    For example ``x**5 + 512*x + 1024 = 0``
    with ``div = 4`` becomes ``y**5 + 2*y + 1 = 0``

    Returns the integer ``div`` or ``None`` if there is no possible scaling.

    Examples
    ========

    >>> from sympy.polys import Poly
    >>> from sympy.abc import x
    >>> from sympy.polys.polyroots import _integer_basis
    >>> p = Poly(x**5 + 512*x + 1024, x, domain='ZZ')
    >>> _integer_basis(p)
    4
    r   rf   Nr1   )rŠ   rª   ÚtermsÚmaprÙ   rÁ   rÀ   r   r   rl   rD   rÍ   r   r)   ÚnextÚStopIteration)
ÚpolyÚmonomsÚcoeffsrÂ   r\   r:   ÚdivsÚdivÚmonomr{   s
             r<   Ú_integer_basisr<  «  s|  € ô, œ#˜tŸz™z›|Ð,Ó-�N€FˆFä”3˜�<Ó �G€FÜ”#”c˜6Ó"Ó#€Fàˆa�y�6˜"‘:ÒÜ”h˜vÓ&Ó'ˆØ�1‰IˆÜ!)¨&Ó!1Ö2˜A�!�a“%Ð2ˆÑ2àà�C�Rˆ[€FØ�C�Rˆ[€Fô ˆ6ƒ{�aÒÜ��q‘	œ1Ÿ5™5 ¨¡™?Ó+ˆØ�<Š<Ü�q“6ˆMàä”HœX fÓ-Ó.¨q¨rÐ2Ó3€DðÜ�4‹jˆð Ü ¨Ó/ò 		‰LˆE�5Ø�s˜E‘zÑ! QÓ&ðÜ˜t›*�Cñ ð		ð ˆJð ùò- 3øô& ò Ùðûô %ò  Úð ús*   Â E ÄE Ä/EÅ	EÅEÅ	E!Å E!c                 ó\  ‡‡— t         j                  }| j                  }	 | j                  d¬«      \  }} | j                  «       d   } | j                  «       } | j                  «       j                  �r1t        d„ | j                  j                  «       D «       «      �r| j                  «       } t        t        | j                  «       Ž «      }t        | j                   dd «      }|d   |dd }}t        t        |«      |«      D ]Œ  \  }}d}	|d   |d   k  rt#        |«      }d}	d}
t        ||«      D ]+  \  }}|s|sŒ|r|s Œ?||z  dk7  r ŒI||z  }|
€|}
Œ%|
|k7  sŒ+ Œ[ |	r|
 }
| j%                  |d«      } |||
 z  z  }|j'                  |«       ŒŽ |r | j(                  |Ž } | j*                  rS| j                  «       j,                  r9t/        | «      Š‰�,| j1                  «       Šˆˆfd	„}| j3                  |«      } |‰z  }t5        | |«      s || «      } || fS # t        $ r || fcY S w xY w)
z7Try to get rid of symbolic coefficients from ``poly``. T)Úconvertr1   c              3   ó4   K  — | ]  }|j                   –— Œ y ­wrå   )Úis_term)rè   rU   s     r<   ré   z#preprocess_roots.<locals>.<genexpr>ú  s   è ø€ Ò(N°q¨¯­Ñ(Nùrê   Nr   Frf   c                 ó    •— |‰‰| d   z
  z  z  S )Nr   © )rq   r{   ÚbasisrÂ   s     €€r<   Úfunczpreprocess_roots.<locals>.func*  s   ø€ Ø˜e a¨!¨A©$¡hÑ/Ñ/Ð/r>   )r   rl   rD  Úclear_denomsr#   Ú	primitiveÚretractr5   Úis_Polyrî   Úrepr8  ÚinjectrŠ   rª   r7  ÚgensrÁ   ÚevalÚremoveÚejectÚis_univariateÚis_ZZr<  r¼   ÚtermwiseÚ
isinstance)r6  r{   Ú	poly_funcrr   ÚstripsrK  rF   r¨   ÚstripÚreverseÚratiorS   rT   Ú_ratiorD  rC  rÂ   s                  @@r<   Úpreprocess_rootsrY  ì  s2  ù€ ä�E‰E€Eà—	‘	€IðØ×#Ñ#¨DÐ#Ó1‰ˆˆ4ð �>‰>Ó˜AÑ€DØ�<‰<‹>€Dð ‡�Ó× Ó ¤SÑ(N¸D¿H¹H¿O¹OÓ<MÔ(NÕ%NØ�{‰{‹}ˆä”c˜4Ÿ;™;›=Ð)Ó*ˆÜ�D—I‘I˜a˜b�MÓ"ˆà˜a‘y &¨¨ *ˆfˆäœd 4›j¨&Ó1ò 	!‰JˆC�ØˆGà�Q‰x˜% ™)Ò#Ü  ›�Ø�àˆEä˜D %Ó(ò !‘��1Ù¡ØÙ¡!ÙØ˜‘U˜a’ZÙà !™V�Fà�}Ø &™Ø &›Ùð!ñ Ø"˜F�Eà—y‘y  aÓ(�Ø˜ ˜v™Ñ&�Ø—‘˜CÕ ð;	!ñ> Ø�4—:‘:˜tÐ$ˆDà×Ò˜dŸo™oÓ/×5Ò5Ü˜tÓ$ˆàÐØ—‘“ˆAõ0ð —=‘= Ó&ˆDØ�U‰NˆEä�d˜IÔ&Ù˜‹ˆØ�$ˆ;Ðøô ò Ø�dˆ{Òðús    H ÈH+È*H+T)	Úautor‰   rm   ÚquarticsÚquinticsre   ÚfilterÚ	predicateÚstrictc       	         óL  ‡‡‡‡‡0— ddl m} t        |«      }t        | t        «      rS|
rt        d«      ‚t        d«      }i t        | «      dz
  }}| D ]  }t        |«      |dz
  c||<   }Œ t        ||d¬«      } �nÞ	 t        | g|
¢­i |¤Ž}t        | t        «      s!|j                  j                  st        d«      ‚|} | j                  «       }| j                  «       d	k(  �r`|d	kD  �rZ | j                  «       j                   | j"                  Ž \  }}| j%                  «        }||k7  �r|}g }t'        j(                  |«      D ]Y  }|j*                  sŒ|j-                  «       \  }}|j.                  sŒ0|j0                  sŒ=|j3                  |t        d¬
«      f«       Œ[ |r¡t5        t        ||z   j7                  t        |«      «      g| j"                  ¢­Ž g|j"                  ¢­|‰‰‰‰|||dœ|¤Ž}|j9                  «       D ��ci c]4  \  }}t;        |j7                  |D ��ci c]  \  }}||“Œ
 c}}«      «      “Œ6 c}}S | j>                  rt        d«      ‚d„ }ˆ0fd„}ˆˆˆˆfd„Š0tA        dt        | j"                  «      z  t        ¬«      }| jC                  | jD                  |«      } | jG                  «       \  \  }} |si }ntH        jJ                  |i}tM        | «      \  }} |r*| jO                  «       jP                  r| jS                  «       } | jO                  «       jT                  r.| jC                  | jD                  jW                  tX        «      «      } d} d}!i }"| jZ                  �s| jO                  «       }#|#j\                  s.|#j^                  r"| ja                  «       D ]  }$ ||"||$d«       Œ �nÄ| j                  «       dk(  r ||"|tc        | «      d   d«       �n˜| j                  «       d	k(  r9| j                  «       d	k(  rtd        ntf        }% |%| «      D ]  }$ ||"||$d«       Œ �nLt        | j                  «       «      ji                  «       \  }&}'t        |'«      dk(  r/| j                  «       d	k(  rte        | «      D ]  }$ ||"||$d«       Œ nåt        |'«      dk(  rŸ|'d   d   dk(  r”| jO                  «       jj                  ra || «      }(|(r>|(d   €	|(d	d \  }!} n
|(d   |(d   } } t5        | «      }"|"sƒ || «      D ]  }) ||"||)d«       Œ nj ‰0| «      D ]  }$ ||"||$d«       Œ nQ || «      D ]  }) ||"||)d«       Œ n8|'D ]3  \  }*} ‰0t        |*| j                  d¬«      «      D ]  }$ ||"||$|«       Œ Œ5 |tH        jl                  ur$|"i }"}+|+j9                  «       D ]  \  })}||"||)z  <   Œ |dvr;d„ d„ d„ d„ dœ},	 |,|   }-t        |"«      jq                  «       D ]  }. |-|.«      rŒ|"|.= Œ |�*t        |"«      jq                  «       D ]  }. ||.«      rŒ|"|.= Œ | r$i }/|"j9                  «       D ]  \  }}||/|| z  <   Œ |/}"|!r$i }/|"j9                  «       D ]  \  }}||/||!z   <   Œ |/}"|"js                  |«       |	r>tu        |"jw                  «       «      | j                  «       k  rty        t{        d«      «      ‚|s|"S g }t}        |"«      D ]  }.|j                  |.g|"|.   z  «       Œ |S c c}}w c c}}w # t<        $ r |rg cY S i cY S w xY w# tn        $ r t        d|z  «      ‚w xY w)a÷  
    Computes symbolic roots of a univariate polynomial.

    Given a univariate polynomial f with symbolic coefficients (or
    a list of the polynomial's coefficients), returns a dictionary
    with its roots and their multiplicities.

    Only roots expressible via radicals will be returned.  To get
    a complete set of roots use RootOf class or numerical methods
    instead. By default cubic and quartic formulas are used in
    the algorithm. To disable them because of unreadable output
    set ``cubics=False`` or ``quartics=False`` respectively. If cubic
    roots are real but are expressed in terms of complex numbers
    (casus irreducibilis [1]) the ``trig`` flag can be set to True to
    have the solutions returned in terms of cosine and inverse cosine
    functions.

    To get roots from a specific domain set the ``filter`` flag with
    one of the following specifiers: Z, Q, R, I, C. By default all
    roots are returned (this is equivalent to setting ``filter='C'``).

    By default a dictionary is returned giving a compact result in
    case of multiple roots.  However to get a list containing all
    those roots set the ``multiple`` flag to True; the list will
    have identical roots appearing next to each other in the result.
    (For a given Poly, the all_roots method will give the roots in
    sorted numerical order.)

    If the ``strict`` flag is True, ``UnsolvableFactorError`` will be
    raised if the roots found are known to be incomplete (because
    some roots are not expressible in radicals).

    Examples
    ========

    >>> from sympy import Poly, roots, degree
    >>> from sympy.abc import x, y

    >>> roots(x**2 - 1, x)
    {-1: 1, 1: 1}

    >>> p = Poly(x**2-1, x)
    >>> roots(p)
    {-1: 1, 1: 1}

    >>> p = Poly(x**2-y, x, y)

    >>> roots(Poly(p, x))
    {-sqrt(y): 1, sqrt(y): 1}

    >>> roots(x**2 - y, x)
    {-sqrt(y): 1, sqrt(y): 1}

    >>> roots([1, 0, -1])
    {-1: 1, 1: 1}

    ``roots`` will only return roots expressible in radicals. If
    the given polynomial has some or all of its roots inexpressible in
    radicals, the result of ``roots`` will be incomplete or empty
    respectively.

    Example where result is incomplete:

    >>> roots((x-1)*(x**5-x+1), x)
    {1: 1}

    In this case, the polynomial has an unsolvable quintic factor
    whose roots cannot be expressed by radicals. The polynomial has a
    rational root (due to the factor `(x-1)`), which is returned since
    ``roots`` always finds all rational roots.

    Example where result is empty:

    >>> roots(x**7-3*x**2+1, x)
    {}

    Here, the polynomial has no roots expressible in radicals, so
    ``roots`` returns an empty dictionary.

    The result produced by ``roots`` is complete if and only if the
    sum of the multiplicity of each root is equal to the degree of
    the polynomial. If strict=True, UnsolvableFactorError will be
    raised if the result is incomplete.

    The result can be be checked for completeness as follows:

    >>> f = x**3-2*x**2+1
    >>> sum(roots(f, x).values()) == degree(f, x)
    True
    >>> f = (x-1)*(x**5-x+1)
    >>> sum(roots(f, x).values()) == degree(f, x)
    False


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Cubic_equation#Trigonometric_and_hyperbolic_solutions

    r   )Úto_rational_coeffszredundant generators givenr…   r1   T)Úfieldzgenerator must be a SymbolrA   )Úpositive)rZ  r‰   rm   r[  r\  re   r]  r^  ú*multivariate polynomials are not supportedc                 óÚ   — |t         j                  k(  rAt         j                  |v r|t         j                  xx   |z  cc<   n||t         j                  <   || v r| |xx   |z  cc<   y || |<   y rå   )r   rQ   )rü   ÚzerosÚcurrentrootrq   s       r<   Ú_update_dictzroots.<locals>._update_dictà  sZ   € Øœ!Ÿ&™&Ò Ü�v‰v˜‰Ø”a—f‘f“ Ñ"”à !�”a—f‘f‘Ø˜&Ñ Ø�;Ó 1Ñ$Ôà"#ˆF�;Òr>   c                 ó  •— | j                  «       g }} ‰|d   «      D ]  }|j                  |«       Œ |dd D ]M  }t        |«      g }}|D ]9  }|t        || j                  «      z
  } ‰|«      D ]  }|j                  |«       Œ Œ; ŒO |S )z+Find roots using functional decomposition. r   r1   N)Ú	decomposerE   rŠ   r&   r¨   )r9   Úfactorsri   rg  ÚcurrentfactorÚpreviousr¬   Ú_try_heuristicss          €r<   Ú_try_decomposezroots.<locals>._try_decomposeë  s¥   ø€ àŸ™›¨�ˆá*¨7°1©:Ó6ò 	&ˆKØ�L‰L˜Õ%ð	&ð % Q R˜[ò 	.ˆMÜ" 5›k¨2�eˆHà'ò .�Ø!¤D¨°a·e±eÓ$<Ñ<�á#2°1Ó#5ò .�KØ—L‘L Õ-ñ.ñ.ð	.ð ˆr>   c           	      óv  •— | j                   rg S | j                  r"t        j                  g| j	                  «       z  S | j                  «       dk(  r@| j	                  «       dk(  r"t        t        t        t        | «      «      «      S t        | «      S g }dD ]X  }| j                  |«      rŒ| j                  t        | j                  |z
  | j                  «      «      } |j                  |«        n | j	                  «       }|dk(  r'|t        t        t        t        | «      «      «      z  }|S |dk(  r'|t        t        t        t!        | «      «      «      z  }|S | j"                  r|t%        | «      z  }|S |dk(  r‰r|t'        | ‰¬«      z  }|S |dk(  r‰r|t)        | «      z  }|S |dk(  r‰r|t+        | «      z  }|S )z+Find roots using formulas and some tricks. rA   r1   r›   r_   )rm   rO   rë   )Ú	is_groundÚis_monomialr   rQ   r¼   ÚlengthrŠ   r3  r'   r=   rË   rL  Úquor&   r¨   rE   r]   Úis_cyclotomicrâ   rƒ   r·   r.  )r9   rü   r\   rÂ   r‰   r[  r\  rm   s       €€€€r<   rn  zroots.<locals>._try_heuristicsý  sš  ø€ à�;Š;ØˆIØ�=Š=Ü—F‘F�8˜AŸH™H›JÑ&Ð&à�8‰8‹:˜Š?Ø�x‰x‹z˜QŠÜœC¤¬°Q«Ó8Ó9Ð9ä% aÓ(Ð(àˆàò 	ˆAØ—6‘6˜!•9Ø—E‘Eœ$˜qŸu™u q™y¨!¯%©%Ó0Ó1�Ø—‘˜aÔ Ùð		ð �H‰H‹Jˆà�Š6Ø”dœ3œv¤|°A£Ó7Ó8Ñ8ˆFð ˆð �!ŠVØ”dœ3œv¤°qÓ'9Ó:Ó;Ñ;ˆFð ˆð �_Š_ØÔ& qÓ)Ñ)ˆFð ˆð �!ŠV™Ø”k !¨$Ô/Ñ/ˆFð ˆð �!ŠV™Ø”m AÓ&Ñ&ˆFð ˆð �!ŠV™Ø”m AÓ&Ñ&ˆFàˆr>   zx:%d)ÚclsNrf   )Nr€   c                 ó   — | j                   S rå   )rD   ©r:   s    r<   rÛ   zroots.<locals>.<lambda>l  s
   € ˜1Ÿ<™<€ r>   c                 ó   — | j                   S rå   ræ   rx  s    r<   rÛ   zroots.<locals>.<lambda>m  s
   € ˜1Ÿ=™=€ r>   c                 óB   — t        d„ | j                  «       D «       «      S )Nc              3   ó4   K  — | ]  }|j                   –— Œ y ­wrå   )rk   )rè   rS   s     r<   ré   z*roots.<locals>.<lambda>.<locals>.<genexpr>n  s   è ø€ ÒE¨Q˜qŸy�yÑEùrê   )rî   Úas_numer_denomrx  s    r<   rÛ   zroots.<locals>.<lambda>n  s   € œ3ÑE°!×2BÑ2BÓ2DÔEÓE€ r>   c                 ó   — | j                   S rå   )Úis_imaginaryrx  s    r<   rÛ   zroots.<locals>.<lambda>o  s
   € ˜1Ÿ>™>€ r>   )ÚZÚQrX   r   zInvalid filter: %sa  
            Strict mode: some factors cannot be solved in radicals, so
            a complete list of solutions cannot be returned. Call
            roots with strict=False to get solutions expressible in
            radicals (if there are any).
            )@Úsympy.polys.polytoolsra  ÚdictrR  rŠ   Ú
ValueErrorr   rÀ   r   r&   r¨   Ú	is_Symbolr!   r¼   rs  Úas_exprÚas_independentrK  r(   r   rB   rC   Úas_base_exprD   Úis_AddrE   ri   rø   Úitemsr   r"   Úis_multivariater   ÚperrI  Ú	terms_gcdr   rQ   rY  r5   Úis_RingÚto_fieldÚis_QQ_Ir>  r    rq  Úis_Exactr6   Únrootsr=   r]   rË   rà   Úis_EXrl   ÚKeyErrorr‹   ÚupdateÚsumÚvaluesr$   r.   r   r¿   )1r9   rZ  r‰   rm   r[  r\  re   r]  r^  r_  rK  Úflagsra  r…   r6  r\   r{   ÚFrÂ   ÚconÚdepÚfconÚbasesrT   r¤   rp   rq   r&  rh  ro  Údumgensrf  Ú	rescale_xÚtranslate_xrü   r;   r:   Ú	roots_funrr   rk  Úresrg  rl  Ú_resultÚhandlersÚqueryÚzeroÚresult1rn  s1     ````                                          @r<   ri   ri   5  s3  ü€ õ` 9Ü�‹K€Eä�!”TÔÙÜÐ9Ó:Ð:ä�#‹Jˆà”c˜!“f˜q‘jˆaˆàò 	/ˆEÜ  ›¨¨Q©ˆJˆD�‰G‘Qð	/ô ��q Ô%Šð&	5Ü�QÐ'˜Ò' Ñ'ˆAÜ˜a¤Ô&¨q¯u©u¯ªÜ%Ð&BÓCÐCØˆAð —‘“
ˆAØ�x‰x‹z˜Q‹ 1 q£5à5˜1Ÿ9™9›;×5Ñ5°q·v±vÐ>‘��SØ˜Ÿ™›Ð'�Ø˜3“;Ø�CØ�EÜ Ÿ]™]¨3Ó/ò H˜ØŸ8›8Ø#$§=¡=£?™D˜A˜qØ Ÿ|›|°·³Ø %§¡¨a´ÀÔ1EÐ-FÕ Gð	Hñ
 Ü"¤4¨¨s©×(<Ñ(<¼TÀ%»[Ó(Ið $%ØŸV™Vò$%ð 
%Ø'(§v¡vñ
%à!%Ø#)Ø!%Ø%-Ø%-Ø%-Ø#)Ø&/ñ
%ð $ñ
%˜ð *,¯©«÷ 5á!%  Aô !-¨Q¯Z©ZØ.3×4¡d a¨˜Q ™TÓ4ó.6ó !àñ!ó  5ð 5ð ×ÒÜ!Ð"NÓOÐOò	$ô÷$$ôN �fœs 1§6¡6›{Ñ*´Ô6€GØ	�‰ˆa�e‰e�WÓ€Aà�k‰k‹m�G�D€Qˆ!áØ‰ä—‘˜�ˆä Ó"�H€Eˆ1á�—‘“×&Ò&Ø�J‰J‹Lˆð 	‡|�|ƒ~×ÒØ�E‰E�!—%‘%—-‘-¤Ó#Ó$ˆà€IØ€Kà€Fà�;‹;Ø�l‰l‹nˆØ�|Š| × 0Ò 0Ø—X‘X“Zò 2�Ù˜V U¨A¨qÕ1ò2à�X‰X‹Z˜1Š_Ù˜ ¬°Q«¸Ñ(:¸AÖ>Ø�X‰X‹Z˜1Š_Ø+,¯8©8«:¸ª?�ÄˆIÙ˜q“\ò 2�Ù˜V U¨A¨qÕ1ò2ô ˜aŸi™i›kÓ*×6Ñ6Ó8‰JˆAˆwÜ�7‹|˜qÒ  Q§X¡X£Z°1¢_Ü(¨Ó+ò 6�AÙ  ¨°°1Õ5ñ6ô �w“< 1Ò$¨°©°A©¸!Ò);Ø—|‘|“~×+Ò+Ù0°Ó3˜ÙØ" 1™v˜~Ø14°Q°R°¡ ©Qà/2°1©v°s¸2±w¨1 	Ü%*¨1£X˜FÙ#)Ù3AÀ!Ó3Dò !P KÙ$0°¸ÀÈQÕ$Oñ!Pñ &5°QÓ%7ò B Ù ,¨V°U¸A¸qÕ AñBñ ,:¸!Ó+<ò H˜KÙ(¨°¸ÀQÕGñHð -4ò >Ñ(˜ qÙ!0´°mÀQÇUÁUÐRVÔ1WÓ!Xò >˜AÙ(¨°¸¸1Õ=ñ>ð>ð ”A—E‘EÑØ! 2�ˆà%Ÿm™m›oò 	*‰NˆK˜Ø()ˆF�5˜Ñ$Ò%ð	*ð �[Ñ á'Ù(ÙEÙ)ñ	
ˆð	<Ø˜VÑ$ˆEô ˜“L×%Ñ%Ó'ò 	!ˆDÙ˜•;Ø˜4‘Lð	!ð ÐÜ˜“L×%Ñ%Ó'ò 	!ˆDÙ˜T•?Ø˜4‘Lð	!ñ ØˆØ—L‘L“Nò 	%‰DˆAˆqØ#$ˆG�A�i‘KÒ ð	%àˆÙØˆØ—L‘L“Nò 	)‰DˆAˆqØ'(ˆG�A˜‘OÒ$ð	)àˆð ‡M�M�%Ôá”#�f—m‘m“oÓ&¨¯©«Ò3Ü#¤Jð 0ó %ó ð 	ñ Øˆàˆä˜F“Oò 	.ˆDØ�L‰L˜$˜  t¡Ñ,Õ-ð	.ð ˆùóG 5ùó 5øô?  ò 	ÙØ’	à’	ð		ûôt ò 	<ÜÐ1°FÑ:Ó;Ð;ð	<ús=   Á;A[4 È[.È![(È.[.× \ Û([.Û4\Ü\Ü\Ü\#©r]  c                ó.  — t        |«      }t        | g|¢­i |¤Ž}|j                  s| gS |j                  rt	        d«      ‚|j
                  d   }t        ||¬«      }|s|g}n€g d}}t        |j                  «       «      D ]   \  }	}
|t        ||	z
  |«      g|
z  z   ||
z   }}Œ" ||j                  «       k  r-t        d„ |«      }|j                  |j                  |«      «       t        | t        «      s|D � cg c]  } | j                  «       ‘Œ }} |S c c} w )zò
    Returns all factors of a univariate polynomial.

    Examples
    ========

    >>> from sympy.abc import x, y
    >>> from sympy.polys.polyroots import root_factors

    >>> root_factors(x**2 - y, x)
    [x - sqrt(y), x + sqrt(y)]

    rd  r   r§  c                 ó   — | |z  S rå   rB  )rn   ro   s     r<   rÛ   zroot_factors.<locals>.<lambda>Å  s
   €  A a¡C€ r>   )r‚  r&   rH  rŠ  rƒ  rK  ri   r   r‰  r¼   r   rE   rt  rR  r…  )r9   r]  rK  Úargsr˜  r…   rf  rk  ÚNr:   rÂ   ÚGs               r<   Úroot_factorsr­     s  € ô �‹:€DäˆQÐ�Ò˜Ñ€Aà�9Š9Øˆsˆ
à×ÒÜÐEÓFÐFà	�‰ˆq‰	€Aä�!˜FÔ#€EáØ�#‰à˜�ˆä˜EŸK™K›MÓ*ò 	=‰DˆAˆqØ ¤D¨¨Q©°£NÐ#3°AÑ#5Ñ5°q¸1±u�Q‰Gð	=ð ˆq�x‰x‹zŠ>ÜÑ'¨Ó1ˆAØ�N‰N˜1Ÿ5™5 ›8Ô$ä�aœÔØ)0Ö2 A�A—I‘I•KÐ2ˆÐ2à€Nùò 3s   Ã7D)F)UÚ__doc__rÎ   Ú	functoolsr   Ú
sympy.corer   r   r   Úsympy.core.exprtoolsr   Úsympy.core.functionr   Úsympy.core.logicr	   Úsympy.core.mulr
   r   Úsympy.core.intfuncr   Úsympy.core.numbersr   r   Úsympy.core.powerr   Úsympy.core.relationalr   Úsympy.core.sortingr   Úsympy.core.symbolr   r   r   Úsympy.core.sympifyr   Úsympy.functionsr   r   r   r   r   Ú(sympy.functions.elementary.miscellaneousr   r   Úsympy.ntheoryr   r   r   Úsympy.polys.domainsr    Úsympy.polys.polyerrorsr!   r"   r#   r$   Úsympy.polys.polyquinticconstr%   r�  r&   r'   r(   r)   r*   Úsympy.polys.rationaltoolsr+   Úsympy.polys.specialpolysr,   Úsympy.utilitiesr-   Úsympy.utilities.miscr.   r/   r=   r]   rƒ   r•   r·   rË   rÕ   râ   r.  rô   r<  rY  ri   r­  rB  r>   r<   ú<module>rÆ     sþ   ðÙ >ó Ý ç Ñ Ý -Ý (Ý &ß +Ý #ß -Ý  Ý $Ý &ß 4Ñ 4Ý &ß 9Õ 9ß ?ß 6Ñ 6Ý "÷(ó (å 4ß NÕ NÝ .Ý 4Ý "Ý +ñ ˆ3ƒK€òòCóLCòJ5Bòpy;òx7òt*óZò@gòTò>òBFðR àØØØØØØØØógó ðgðT #'õ +r>   