ó
    Š*£h¡�  ã                   ó  • S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SSK J!r!  SSK"J#r#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*  SSK+J,r,J-r-J.r.  SSK/J0r0  SSK1J2r2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;J<r<J=r=  SSK>J?r?  SSK@JArA  SSKBJCrC  SSKDJErE  \" S5      rFS rGS rHS.S jrIS  rJS! rKS" rLS# rMS.S$ jrNS% rOS& rPS' rQS( rR\CS)S)SS)SSSSSS*.	S+ j5       rSSS,.S- jrTg)/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                 óì   • U R                  S5      * U R                  S5      -  nU R                  5       nUR                  (       d-  UR                  (       a  [	        U5      nU/$ SSKJn  U" U5      nU/$ )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       ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/polys/polyroots.pyÚroots_linearr=   %   sb   € à	
�‰ˆq‹ˆ	�!—%‘%˜“(Ñ€AØ
�,‰,‹.€Cà××Ø××Ü�q“	ˆAð
 ˆ3€Jõ 9Ù˜“ˆAàˆ3€Jó    c                 óÜ  ^• U R                  5       u  pnU R                  5       mS nU4S jnU[        R                  L aG  [        R                  U* U-  pvTR                  (       d  U" U5      nXg/$ UR
                  (       a  XvpvXg/$ U[        R                  L a/  U* U-  nTR                  (       d  U" U5      nU" U5      n	U	* nU	nXg/$ US-  SU-  U-  -
  n
SU-  nU* U-  nTR                  (       d  U" U
5      n
U" U5      n[        U" U
5      U-  5      nXÍ-
  nXÍ-   nUR
                  (       a  XvpvXg/$ TR                  (       d  Xg4 Vs/ s H  n[        U5      PM     snu  pgXg/$ s  snf )a<  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                 ó¬  • / n/ n[         R                  " U 5       H‡  nUR                  (       ab  UR                  R                  (       aG  UR                  S-  S:X  a4  UR                  [        UR                  UR                  S-  5      5        Mv  UR                  U5        M‰     U(       a  [        U6 n [        U6 nU[        U 5      -  $ [        U 5      $ )Né   r   )	r   Ú	make_argsÚis_Powr   Ú
is_IntegerÚappendr   Úbaser   )ÚdÚcoÚotherÚdis       r<   Ú_sqrtÚ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                 óX   >• TR                   (       a  [        U 5      $ SSKJn  U" U 5      $ )Nr   r2   )r7   r(   r8   r3   )Úexprr3   r;   s     €r<   Ú	_simplifyÚ"roots_quadratic.<locals>._simplifyP   s#   ø€ Ø××Ü˜$“<Ðå8Ù˜D“>Ð!r>   rA   é   )Ú
all_coeffsr5   r   ÚZeror6   Úis_negativer   r
   )r9   ÚaÚbÚcrK   rO   Úr0Úr1r:   ÚRrG   ÚAÚBÚDÚir;   s                  @r<   Úroots_quadraticr_   4   so  ø€ ð �l‰l‹n�G€Aˆ!Ø
�,‰,‹.€Còõ""ð 	ŒA�F‰F‚{Ü—‘˜!˜˜A™ˆBà××Ù˜2“ˆBð8 ˆ8€Oð7 �^�^Ø�ð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ˆØ�=�=Ø�ð ˆ8€Oð ×!×!Ø/1©hÓ7ªh¨”k !–n©hÑ7‰FˆBàˆ8€Oùò 8s   ÅE)Fc                 óÎ  • U(       Ga:  U R                  5       u  p#pESU-  U-  US-  -
  SUS-  -  -  nSUS-  -  SU-  U-  U-  -
  SUS-  -  U-  -   SUS-  -  -  nSU-  U-  U-  U-  SUS-  -  U-  -
  US-  US-  -  -   SU-  US-  -  -
  SUS-  -  US-  -  -
  nUS:„  S:X  a�  / n	[        S5       Hq  n
U	R                  S[        U* S-  5      -  [	        [        Xv-  [        S	U-  5      -  [        SS5      -  5      S-  U
[        -  [        SS5      -  -
  5      -  5        Ms     U	 Vs/ s H  o»US-  U-  -
  PM     sn$ U R                  5       R                  5       u  pÂp4U[        R                  L a!  [        S
X#/SS9u  pÞU[        R                  U/$ X2S-  S-  -
  nXBU-  S-  -
  SUS-  -  S-  -   nUS-  nUS-  nSnU[        R                  L aF  U[        R                  L a  U* /S-  $ UR                  (       a  [        US5      * O[        U* S5      nO•U[        R                  L a7  [        S
SU/SS9u  nnU[        R                  U4 Vs/ s H  nUU-
  PM
     sn$ UR                  (       a:  UR                  (       a)  [        U* S-  [        US-  S-  US-  -   5      -   S5      * n[         [        S5      -  S-  nUc¤  [        R"                  n[        SS5      U-   n[        SS5      U-
  nX#UpTnUS-  SU-  -
  nSUS-  -  SU-  U-  -
  SU-  -   n[        U[        US-  SUS-  -  -
  5      -   S-  S5      nUUU4 Vs/ s H  nUUU-  -   UU-  U-  -   * S-  PM     sn$ U[        SS5      U-   -  nU[        SS5      U-
  -  nU[        R                  L a  UU-
  UU-
  UU-
  /$ U* UU-  -   U-
  U* UU-  -   U-
  U* UU-  -   U-
  /nU$ s  snf s  snf s  snf )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   é	   é   é   rQ   r   Téýÿÿÿr1   ©ÚmultipleNéÿÿÿÿ)rR   ÚrangerE   r   r   r   r   r   Úmonicr   rS   ÚrootsÚis_positiver   Úis_realrT   r   ÚOne)r9   ÚtrigrU   rV   rW   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   sH  € ÷ Ø—\‘\“^‰
ˆˆ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�Ø—	‘	˜!œ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ñ á')Ó*¢r !˜˜!™˜A™”I¡rÑ*Ð*ð —‘“×%Ñ%Ó'�J€Aˆ!àŒA�F‰F‚{Ü˜˜1�y¨4Ñ0‰ˆØ”A—F‘F˜BÐÐð 	
ˆq‰D�‰F‰
€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Ò&6˜s��d”
Ñ&6Ñ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Ñ$ˆØ˜ˆaˆØ�‰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                 ó  • [        S5      nSUS-  -  SU -  US-  -  -   SU S-  -  SU-  -
  U-  -   US-  -
  n[        [        [        XT5      SS	9R	                  5       5      nU Vs/ s H*  owR
                  (       d  M  UR                  (       d  M(  UPM,     nnU(       d  g
[        U5      n[        U5      n	U* U	-  SU-  -  n
U* U S-  -
  n[        Xº-   5      n[        Xº-
  5      nXœ-
  U-
  U	* U-
  U-
  U	* U-   U-
  Xœ-   U-
  /$ s  snf )aü  
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é@   ra   é    rA   rQ   é   F)ÚcubicsN)	r   Úlistrk   r&   ÚkeysÚis_rationalÚ
is_nonzeroÚmaxr   )rp   rq   r:   rU   r‡   ÚeqÚxsolsÚsolrZ   Úc1r\   r[   Ú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šE�S§_¥_‹S¸¿½�S™E€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   Á&DÁ>DÂDc                 ó$  ^ ^^• T R                  5       R                  5       u  pp4nU(       d  [        R                  /[	        SX#U/SS9-   $ XB-  S-  U:X  a�  T R
                  XB-  pv[        US-  X&-  -   U-   SU-  -
  U5      n[        U5      u  pš[        US-  X–-  -
  U-   U5      n[        US-  X¦-  -
  U-   U5      n[        U5      n[        U5      nXÞ-   $ US-  nUSU-  S-  -
  m[        XBUS-  US-  -
  -  -   5      m US-  m[        UTUSU-  S-  US-  -
  -  U-   -  -
  5      nT R                  (       aF  [	        STU/SS9 Vs/ s H  n[        U5      PM     snu  nnU* U* UU4 Vs/ s H  nUT-
  PM
     sn$ UR                  (       a6  [        R                  /[	        SS	TT /SS9-   nU Vs/ s H  nUT-
  PM
     sn$ [        TT UT5      nU(       a  U$ TS-  * S
-  U-
  nTS-  * S-  TU-  S-  -   T S-  S-  -
  n[        SS5      nUUU 4S jn[        U5      nT[        SS5      -  UU-  -
  nUR                  (       a  U" U5      $ [        US-  S-  US-  S-  -   5      nU* S-  U-   nUU-  nT[        SS5      -  U-   UU-  S-  -
  n[        UR                  5      (       a  U" U5      $ [        U" U5      U" U5      5       VVs/ s H   u  nn[        U[!        US	5      4US45      PM"     snn$ s  snf s  snf s  snf s  snnf )a6  
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   Trf   rA   ra   é   rQ   rˆ   r   é   él   c                 óÖ   >• [        T	SU -  -   5      nST	-  SU -  -   nST
-  U-  n/ nS H;  n[        X%U-  -   * 5      nS H!  nUR                  XQ-  Xv-  -
  S-  T-
  5        M#     M=     U$ )NrA   ra   ©rh   r1   )r   rE   )ÚyÚwÚarg1Úarg2ÚansÚsr   ÚtÚaon4Úer9   s           €€€r<   Ú_ansÚroots_quartic.<locals>._ansP  sƒ   ø€ Ü˜˜Q˜q™S™“M�Ø˜‘s˜Q˜q™S‘y�Ø˜‘s˜1‘u�Ø�Û �AÜ $¨4©¡-Ð 0Ó1�DÛ$˜ØŸ
™
 A¡C¨!©&¡L°!Ñ#3°dÑ#:Ö;ó %ñ !ð �
r>   éûÿÿÿé   rc   )rj   rR   r   rS   rk   Úgenr&   r_   r   Úis_zeror   r—   r   r	   Úzipr   r   )r9   rt   rU   rV   rW   rG   r‡   ÚmÚgÚz1Úz2Úh1Úh2rY   Úr2Úa2r|   rz   r{   rž   Úsolsrp   rq   ÚTHr§   r   r:   ÚuÚa1r¥   r¦   s   `                            @@r<   Úroots_quarticrº   ÷   sT  ú€ ð^ —G‘G“I×(Ñ(Ó*�M€Aˆ!�æÜ—‘ˆxœ%  A¨! °tÑ<Ñ<Ð<Ø
‰#�‰�Q‹Ø�u‰u�a‘cˆ1ä��A‘˜™‘˜a‘ ! A¡#Ñ% qÓ)ˆä  Ó#‰ˆä�!�Q‘$˜™‘+ ‘/ 1Ó%ˆÜ�!�Q‘$˜™‘+ ‘/ 1Ó%ˆä˜RÓ ˆÜ˜RÓ ˆà‰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Ú5ð %(”d˜3–iÙ5ñ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ô;Ú"9™˜˜Bô ˜r¤2 a¨£8˜n¨r°4¨jÖ9Ù"9ò;ð ;ùò_7ùâ=ùò -ùóT;s   Å	K=Å.LÆ5LË'Lc                 ó¬  • U R                  5       nU R                  U5      U R                  S5      p2[        X2-  5      * n[        XA5      nUR                  (       a  UR                  SS9nUR                  nUS-  S:H  nU(       a  US:X  a  US-   R                  (       a  SnOSn/ n	US-  n
U(       a  U	R                  U
5        U
S-  n
U(       d  U	R                  S5        [        U
SS5       H3  nU(       a  U	R                  X»* /5        M  U	R                  U* U/5        M5     U(       aP  U	R                  S5        W(       a8  [        S[        U	5      S5       H  nX›US-    n[        [        U5      5      nM      / S[        -  [        -  U-  píU	 H>  n[!        Xþ-  5      R                  SS9nUR                  UU-  R                  SS95        M@     U$ )	a;  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   Frh   )Ú
power_base)Údegreer4   r'   r   Ú	is_numberÚexpandrT   rl   rE   ri   ÚextendÚlenrŒ   Úreversedr   r   r   )r9   ÚnrU   rV   rF   ÚalphaÚnegÚevenÚbigÚksÚimaxr^   Úpairrk   rG   rs   Úzetas                    r<   Úroots_binomialrÎ   s  s™  € ð 	
�‰‹
€Aà�5‰5�‹8�Q—U‘U˜1“X€qÜ�1‘3‹Kˆ<€DÜ�‹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˜"�gÖà�I‰I˜�r˜1�gÖñ	  ö
 Ø
�	‰	�!ŒÞÜ˜1œc "›g qÖ)�Ø˜Q ™U�|�ÜœH T›NÓ+’ñ *ð
 �1”Q‘3”r‘6˜!‘8ˆ1ÛˆÜ�1‘3‹x�‰ tˆÐ,ˆØ�‰�e˜D‘j×(Ñ(°EÐ(Ð:Ö;ñ ð €Lr>   c                 óø  • [        U 5       Vs/ s H  n[        US-   5      (       d  M  US-   PM     nnSu  p4U H  nX5-  nXES-
  -  nM     U n[        [        R                  " U [        U5      U-  -  5      5      nS=p…/ nX‡::  a'  [        U5      nUR                  U5        X…-  nX‡::  a  M'  X…-  nSnUSS  H
  nXES-
  -  nM     [        [        R                  " U [        U5      U-  -  5      5      nXg4$ s  snf )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   Nrh   )r   r   ÚintÚmathÚceilÚfloatr   rE   )	r®   rG   ÚprimesrU   rV   rp   ÚLÚUÚPs	            r<   Ú_inv_totient_estimaterØ   ­  sÿ   € ô ' qœkÓ=šk˜¬W°Q¸±U¯^‹uˆq�1Œu™k€FÐ=à�D€AãˆØ	‰ˆØ	�‰U‰
Šñ ð 	
€AÜŒD�IŠI�aœ˜q› !™‘nÓ%Ó&€Aà€I€AØ€Fà
‹&Ü�a‹LˆØ�‰�aÔØ	‰ˆð �&ð
 �G€AØ	€Aà�C�R‹[ˆØ	�‰U‰
Šñ ô 	ŒD�IŠI�aœ˜q› !™‘nÓ%Ó&€Aàˆ4€Kùò7 >s
   ŽC7©	C7c                 óæ  ^^• [        U R                  5       5      u  p#[        X#S-   5       H4  m[        TU R                  SS9nU R
                  UR
                  :X  d  M4    O   [        S5      e/ nU(       dš  TS-  m[        STS-   5       Vs/ s H  n[        UT5      S:X  d  M  UPM     nnUR                  UU4S jS9  S[        -  [        -  T-  n[        U5       H,  n	UR                  [        X˜-  5      R                  SS95        M.     U$ [        U [!        S	T5      S
9n[#        UR%                  5       S   5       H&  u  mn
UR                  TR'                  5       * 5        M(     U$ s  snf )z)Compute roots of cyclotomic polynomials. r1   T)Úpolysz/failed to find index of a cyclotomic polynomialrA   c                 ó8   >• U T::  a  U S4$ [        U T-
  5      S4$ )Nrh   r1   )Úabs)r‡   ÚhrÅ   s    €€r<   Ú<lambda>Ú"roots_cyclotomic.<locals>.<lambda>í  s#   ø€ ¨¨a«˜q "˜gÐD´c¸!¸a¹%³jÀ!°_ÐDr>   )Úkeyr¼   rh   )Ú	extension)rØ   r¿   ri   r,   r«   rN   ÚRuntimeErrorr   Úsortr   r   rÄ   rE   r   rÁ   r&   r   r   Úfactor_listÚTC)r9   r(   rÕ   rÖ   r¯   rk   r^   rÊ   rG   rs   rt   rÝ   rÅ   s              @@r<   Úroots_cyclotomicræ   Ú  s;  ù€ ä  §¡£Ó,�D€Aä�1˜!‘eŽ_ˆÜ˜A˜qŸu™u¨DÑ1ˆà�6‰6�Q—V‘VÕÙñ	 ô ÐLÓMÐMà€Eæð ˆq‰DˆÜ˜q ! a¡%œÓ<š�A¬D°°A«J¸!©O�a™ˆÐ<Ø
�‰ÕDˆÑEØŒa‰C”‰F�1‰HˆÜ˜"–ˆAØ�L‰Lœ˜Q™S›Ÿ™°˜Ð6Ö7ñ ð €Lô �œd 2 q›kÑ*ˆä˜AŸM™M›O¨AÑ.Ö/‰DˆAˆqØ�L‰L˜!Ÿ$™$›&˜Ö!ñ 0ð €Lùò =s   ÂE.Â&E.c           
      óÔ  • / nU R                  5       u  p#pEpg[        S X#XEXg4 5       5      (       d  U$ US:w  a!  [        X-  5      n U R                  5       u  pƒpEpgU(       a²  USU-  U-  S-  -
  n	USU-  U-  S-  -
  SUS-  -  S-  -   n
USU-  U-  S-  -
  SUS-  -  U-  S-  -   SUS-  -  S-  -
  nXsU-  S-  -
  US-  U-  S-  -   US-  U-  S-  -
  SUS-  -  S	-  -   nU R                  n[        US-  X�S-  -  -   X­S-  -  -   X½-  -   U-   5      n OXEXg4u  pšp¼[	        U 5      nU R
                  (       d  U$ UR                  nUR
                  (       a  U$ UR                  5       S    H-  nUS
   R                  (       d  M  US
   R                  S
5      n  O   [        U 5      n[        U5      nUR                  u  nnnnUR                  WU5      n[        S5      nUS   US   U-  -   nUS   US   U-  -
  nUS   US   U-  -   nUS   US   U-  -
  nUS-  SU-  -
  nUS-  SU-  -
  nUR                  U5      n [        S5      n![!        U* [        U5      -   U!-  5      n"[!        U* [        U5      -
  U!-  5      n#[!        U* [        U5      -   U!-  5      n$[!        U* [        U5      -
  U!-  5      n%UR#                  UU5      n&U&UR%                  5       -  U"R%                  5       U#R%                  5       -
  U$R%                  5       U%R%                  5       -
  -  -
  n'['        U'S
U5      (       d  U%U$n%n$U U"U-  -   U$U-  -   U%U-  -   U#U-  -   n(U U%U-  -   U"U-  -   U#U-  -   U$U-  -   n)U U$U-  -   U#U-  -   U"U-  -   U%U-  -   n*U U#U-  -   U%U-  -   U$U-  -   U"U-  -   n+SS/S-  S/S-  S/S-  S/S-  /n,SS/S-  S/S-  S/S-  S/S-  /n-[!        U(5      n([!        U)5      n)[!        U*5      n*[!        U+5      n+[(        [        S5      S-  -  n.[        S5      n/[        S5      n0[        SU0-
  5      n1[*        U0-  n2U2[*        -   n3[*        U.-  S-  n4U/[        U0S-   5      -  n5U.U4* U/U1-  U3-
  -  U4U/U1-  U3-   -  U4* U2U5-   [*        -
  -  U4U2* U5-   [*        -   -  /n6U(R-                  5       n(U)R-                  5       n)U*R-                  5       n*U+R-                  5       n+[/        U65       HÞ  u  n7n[!        UR1                  [(        U(S
   [*        U(S   -  -   05      5      U,S   U7'   [!        UR1                  [(        U)S
   [*        U)S   -  -   05      5      U,S   U7'   [!        UR1                  [(        U*S
   [*        U*S   -  -   05      5      U,S   U7'   [!        UR1                  [(        U+S
   [*        U+S   -  -   05      5      U,S   U7'   Mà     [3        SS5       HH  n7[3        S5       H6  n8U,U7   U8   R%                  5       U-U7   U8'   [!        U,U7   U8   5      U,U7   U8'   M8     MJ     U,S   S
   n9U-S   S
   n:[3        S5       H1  n7['        [5        U:U-S   U7   -  5      S
U5      (       d  M)  U,S   U7   n;  O   UR7                  UU5      u  n<n=U<U=U-  [        S5      -  -   R%                  5       n>U<U=U-  [        S5      -  -
  R%                  5       n?W;R%                  5       n@S=nAnB[3        S5       H¢  n7U-S   U7   nC[3        S5       Hƒ  n8U-S   U8   nD['        U:WCS-  -  W@UDS-  -  -   U>-
  R%                  5       S
U5      (       d  M?  ['        WDU:S-  -  WCW@S-  -  -   U?-
  R%                  5       S
U5      (       d  Ms  U,S   U7   nAU,S   U8   nB  O   WAc  M¢    O   / $ U9WA-   WB-   U;-   S-  n/U9U-  UAU-  -   UBU-  -   U;U-  -   S-  n0U9U-  UAU-  -   UBU-  -   U;U-  -   S-  n1U9U-  UAU-  -   UBU-  -   U;U-  -   S-  n2U9U-  UAU-  -   UBU-  -   U;U-  -   S-  n3U/U0U1U2U3/n[9        5       nEU H/  nUR%                  S5      nUWE;   a  / s  $ WER;                  U5        M1     U(       a  U Vs/ s H
  oÝUS-  -
  PM     nnU$ s  snf )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   ó8   #   • U  H  oR                   v •  M     g 7f©N©Úis_Rational)Ú.0r}   s     r<   Ú	<genexpr>Ú roots_quintic.<locals>.<genexpr>  s   é € ÐQÒ.P U× Ö Ò.Pùó   ‚r1   rA   é   ra   rQ   é   é}   i5  r   g»½×Ùß|Û=N)rR   Úallr&   r«   r%   Úis_irreducibleÚf20rä   Ú	is_linearr   r*   r   rÍ   ÚTr   Úl0Ú_quintic_simplifyÚorderrÅ   r   r/   r   Úas_real_imagÚ	enumerateÚxreplaceri   r   ÚuvÚsetÚadd)Fr9   ÚresultÚcoeff_5Úcoeff_4Úp_Úq_Úr_Ús_rt   rp   rq   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Úx0ru   rv   Úx3Úx4Úx5Úx6Úx7r“   r^   ÚjrY   Úr1_nÚr4r¸   ÚvÚtestplusÚ	testminusÚr4_nr´   Úr3Úr2temp_nÚr3temp_nÚsawsF                                                                         r<   Úroots_quinticr3  ú  sS	  € ð
 €Fà'(§|¡|£~Ñ$€G�b˜bäÑQ¨wÀÈÑ.PÓQ×QÑQØˆà�!ƒ|Ü�‘ÓˆØ%&§\¡\£^Ñ"ˆ�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™$™‘  a¡4¡Ñ'¨!©#Ñ-°Ñ1Ó2‰à˜R�^‰
ˆˆ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ä˜#–‰ˆˆ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‹	ñ	 ô �1�aŽ[ˆÜ�q–ˆAØ˜a™& ™)Ÿ+™+›-ˆE�!‰H�Q‰KÜ)¨#¨a©&°©)Ó4ˆC�‰F�1‹Ió ñ ð 
ˆ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ÓRÜ�h˜t Q™wÑ&¨°$¸±'Ñ)9Ñ9¸IÑE×HÑHÓJÈAÈs×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ª6 a�g ‘k”/©6ˆÐ2Ø€Mùò 3s   áa%c                 óJ   • SSK Jn  U" U 5      n [        U 5      n [        U 5      $ )Nr   )Úpowsimp)r8   r5  r'   r+   )rN   r5  s     r<   rù   rù   ¤  s!   € Ý/Ù�4‹=€DÜ�$‹<€DÜ�D‹>Ðr>   c                 óÞ  • [        [        U R                  5       6 5      u  p[        [        U6 5      u  n[        [        [        U5      5      nUS   US   :  a7  [        [        U5      5      nUS   n[        U5       Vs/ s H  oCU-
  PM	     nnOgUSS nUSS n[        U5      S:X  a@  [        US   [        R                  US   -  5      nUR                  (       a  [        U5      $ g[        [        [        U5      5      SS 5      n [        U5      n [        X5       H  u  p‰X—U-  -  S:w  d  M   [        U5      n  O   U$ M1  s  snf ! [         a     gf = f! [         a       gf = f)aB  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   rh   Nr1   )rŒ   r­   ÚtermsÚmaprÜ   rÄ   rÃ   r   r   rn   rD   rÐ   r   r)   ÚnextÚStopIteration)
ÚpolyÚmonomsÚcoeffsrÅ   r^   r:   ÚdivsÚdivÚmonomr}   s
             r<   Ú_integer_basisrA  «  sr  € ô, œ#˜tŸz™z›|Ð,Ó-�N€Fä”3˜�<Ó �G€FÜ”#”c˜6Ó"Ó#€Fàˆa�y�6˜"‘:ÓÜ”h˜vÓ&Ó'ˆØ�1‰IˆÜ!)¨&Ô!1Ó2Ò!1˜A�a”%Ñ!1ˆÐ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Ø˜E‘zÑ! QÕ&ðÜ˜t›*�Cñ ñ 0ð ˆJñ ùò- 3øô& ó Ùðûô %ó  Úð ús*   Â E	ÄE Ä6EÅ
EÅEÅ
E,Å+E,c                 óÌ  ^^• [         R                  nU R                  n U R                  SS9u  p0U R                  5       S   n U R                  5       n U R                  5       R                  (       GaY  [        S U R                  R                  5        5       5      (       Ga)  U R                  5       n [        [        U R                  5       6 5      n[        U R                   SS 5      nUS   USS pF[        [        U5      U5       Hª  u  pxSn	US   US   :  a  [#        U5      nSn	Sn
[        Xh5       HD  u  p¼U(       d	  U(       d  M  U(       a  U(       d    MS  XË-  S:w  a    M^  XË-  nU
c  Un
M<  X­:w  d  MC    Ms     U	(       a  U
* n
U R%                  US5      n XU
* -  -  nUR'                  U5        M¬     U(       a  U R(                  " U6 n U R*                  (       aZ  U R                  5       R,                  (       a;  [/        U 5      mTb-  U R1                  5       mUU4S	 jnU R3                  U5      n UT-  n[5        X5      (       d  U" U 5      n X4$ ! [         a    X4s $ f = f)
z7Try to get rid of symbolic coefficients from ``poly``. T)Úconvertr1   c              3   ó8   #   • U  H  oR                   v •  M     g 7fré   )Úis_term)rì   rW   s     r<   rí   Ú#preprocess_roots.<locals>.<genexpr>ú  s   é € Ð(NÒ<M°q¯®Ò<Mùrï   Nr   Frh   c                 ó    >• UTTU S   -
  -  -  $ )Nr   © )rs   r}   ÚbasisrÅ   s     €€r<   ÚfuncÚpreprocess_roots.<locals>.func*  s   ø€ Ø˜e a¨!¨A©$¡hÑ/Ñ/Ð/r>   )r   rn   rJ  Úclear_denomsr#   Ú	primitiveÚretractr5   Úis_Polyró   Úrepr=  ÚinjectrŒ   r­   r<  ÚgensrÄ   ÚevalÚremoveÚejectÚis_univariateÚis_ZZrA  r¿   ÚtermwiseÚ
isinstance)r;  r}   Ú	poly_funcrt   ÚstripsrR  rF   r«   ÚstripÚreverseÚratiorU   rV   Ú_ratiorJ  rI  rÅ   s                  @@r<   Úpreprocess_rootsr`  ì  s  ù€ ä�E‰E€Eà—	‘	€IðØ×#Ñ#¨DÐ#Ð1‰ˆð �>‰>Ó˜AÑ€DØ�<‰<‹>€Dð ‡�Ó× × Ð ¤SÑ(N¸D¿H¹H¿O¹OÔ<MÓ(N×%NÒ%NØ�{‰{‹}ˆä”c˜4Ÿ;™;›=Ð)Ó*ˆÜ�D—I‘I˜a˜b�MÓ"ˆà˜a‘y &¨¨ *ˆfäœd 4›j¨&Ö1‰JˆCØˆGà�Q‰x˜% ™)Ó#Ü  ›�Ø�àˆEä˜DÖ(‘�Þ¦ÙÞ¦!ÚØ‘U˜a“ZÚà™V�Fà‘}Ø &šØ�Úñ )ö Ø"˜F�Eà—y‘y  aÓ(�Ø ˜v™Ñ&�Ø—‘˜CÖ ñ; 2ö> Ø—:’:˜tÐ$ˆDà××˜dŸo™oÓ/×5×5Ü˜tÓ$ˆàÑØ—‘“ˆAö0ð —=‘= Ó&ˆDØ�U‰NˆEä�d×&Ñ&Ù˜‹ˆØˆ;Ðøô ó Øˆ{Òðús    I ÉI#É"I#T)	Úautor‹   ro   ÚquarticsÚquinticsrg   ÚfilterÚ	predicateÚstrictc       	         ó²  ^^^^^0• SSK Jn  [        U5      n[        U [        5      (       aT  U
(       a  [        S5      e[        S5      n0 [        U 5      S-
  pþU  H  n[        U5      US-
  sXï'   nM     [        XíSS9n GO [        U /U
Q70 UD6n[        U [        5      (       d&  UR                  R                  (       d  [        S5      eUn U R                  5       nU R                  5       S	:X  Ga  US	:”  Gax  U R                  5       R                   " U R"                  6 u  nnU* R%                  5       * nUU:w  Ga5  Un/ n[&        R(                  " U5       Hi  nUR*                  (       d  M  UR-                  5       u  nnUR.                  (       d  M<  UR0                  (       d  MO  UR3                  U[        SS
945        Mk     U(       a§  [5        [        UU-   R7                  [        U5      5      /U R"                  Q76 /UR"                  Q7UTTTTUUUS.UD6nUR9                  5        VVs0 s H8  u  nn[;        UR7                  U VVs0 s H	  u  nnUU_M     snn5      5      W_M:     snn$ U R>                  (       a  [        S5      eS nU04S jnUUUU4S jm0[A        S[        U R"                  5      -  [        S9nU RC                  U RD                  U5      n U RG                  5       u  u  nn U(       d  0 nO[H        RJ                  U0n[M        U 5      u  nn U(       a/  U RO                  5       RP                  (       a  U RS                  5       n U RO                  5       RT                  (       a.  U RC                  U RD                  RW                  [X        5      5      n Sn Sn!0 n"U RZ                  (       Gd<  U RO                  5       n#U#R\                  (       d5  U#R^                  (       a$  U Ra                  5        H  n$U" U"UU$S5        M     GOæU R                  5       S:X  a  U" U"U[c        U 5      S   S5        GO¹U R                  5       S	:X  a<  U R                  5       S	:X  a  [d        O[f        n%U%" U 5       H  n$U" U"UU$S5        M     GOi[        U R                  5       5      Ri                  5       u  n&n'[        U'5      S:X  a2  U R                  5       S	:X  a  [e        U 5       H  n$U" U"UU$S5        M     Oþ[        U'5      S:X  a¶  U'S   S   S:X  aª  U RO                  5       Rj                  (       ap  U" U 5      n(U((       aF  U(S   c	  U(S	S u  n!n O
U(S   U(S   n n [5        U 5      n"U"(       d  U" U 5       H  n)U" U"UU)S5        M     OoT0" U 5       H  n$U" U"UU$S5        M     OTU" U 5       H  n)U" U"UU)S5        M     O9U' H3  u  n*nT0" [        U*U R                  SS95       H  n$U" U"UU$U5        M     M5     U[H        Rl                  La&  U"0 n"n+U+R9                  5        H  u  n)nUU"UU)-  '   M     US;  aC  S S S S S.n, U,U   n-[        U"5      Rq                  5        H  n.U-" U.5      (       a  M  U"U.	 M     Ub2  [        U"5      Rq                  5        H  n.U" U.5      (       a  M  U"U.	 M     U (       a&  0 n/U"R9                  5        H  u  nnUU/UU -  '   M     U/n"U!(       a&  0 n/U"R9                  5        H  u  nnUU/UU!-   '   M     U/n"U"Rs                  U5        U	(       a?  [u        U"Rw                  5       5      U R                  5       :  a  [y        [{        S5      5      eU(       d  U"$ / n[}        U"5       H  n.UR                  U./U"U.   -  5        M     U$ s  snnf s  snnf ! [<         a    U(       a  / s $ 0 s $ f = f! [n         a    [        SU-  5      ef = f)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)ra  r‹   ro   rb  rc  rg   rd  re  ú*multivariate polynomials are not supportedc                 óÜ   • U[         R                  :X  aB  [         R                  U;   a  U[         R                  ==   U-  ss'   OX1[         R                  '   X ;   a  X==   U-  ss'   g X0U'   g ré   )r   rS   )r  ÚzerosÚcurrentrootrs   s       r<   Ú_update_dictÚroots.<locals>._update_dictà  sR   € Øœ!Ÿ&™&Ó Ü�v‰v˜‹Ø”a—f‘f“ Ñ"”à !”a—f‘f‘ØÓ ØÓ 1Ñ$Ôà"#�;Òr>   c                 ó"  >• U R                  5       / p!T" US   5       H  nUR                  U5        M     USS  HP  n[        U5      / p%U H;  nU[        X0R                  5      -
  nT" U5       H  nUR                  U5        M     M=     MR     U$ )z+Find roots using functional decomposition. r   r1   N)Ú	decomposerE   rŒ   r&   r«   )r9   Úfactorsrk   rn  ÚcurrentfactorÚpreviousr¯   Ú_try_heuristicss          €r<   Ú_try_decomposeÚroots.<locals>._try_decomposeë  s‹   ø€ àŸ™›¨�á*¨7°1©:Ö6ˆKØ�L‰L˜Ö%ñ 7ð % Q R›[ˆMÜ" 5›k¨2�eã'�Ø!¤D¨·e±eÓ$<Ñ<�á#2°1Ö#5�KØ—L‘L Ö-ó $6ó  (ñ )ð ˆr>   c           	      óÈ  >• U R                   (       a  / $ U R                  (       a"  [        R                  /U R	                  5       -  $ U R                  5       S:X  aA  U R	                  5       S:X  a"  [        [        [        [        U 5      5      5      $ [        U 5      $ / nS H^  nU R                  U5      (       a  M  U R                  [        U R                  U-
  U R                  5      5      n UR                  U5          O   U R	                  5       nUS:X  a'  U[        [        [        [        U 5      5      5      -  nU$ US:X  a'  U[        [        [        [!        U 5      5      5      -  nU$ U R"                  (       a  U[%        U 5      -  nU$ US:X  a  T(       a  U['        U TS9-  nU$ US:X  a  T(       a  U[)        U 5      -  nU$ US:X  a  T(       a  U[+        U 5      -  nU$ )z+Find roots using formulas and some tricks. rA   r1   r�   ra   )ro   rQ   rð   )Ú	is_groundÚis_monomialr   rS   r¿   ÚlengthrŒ   r8  r'   r=   rÎ   rS  Úquor&   r«   rE   r_   Úis_cyclotomicræ   r…   rº   r3  )r9   r  r^   rÅ   r‹   rb  rc  ro   s       €€€€r<   rv  Ú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“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)ÚclsNrh   )Nr‚   c                 ó   • U R                   $ ré   )rD   ©r:   s    r<   rÞ   Úroots.<locals>.<lambda>l  s   € ˜1Ÿ<š<r>   c                 ó   • U R                   $ ré   rê   r‚  s    r<   rÞ   rƒ  m  s   € ˜1Ÿ=š=r>   c                 óB   • [        S U R                  5        5       5      $ )Nc              3   ó8   #   • U  H  oR                   v •  M     g 7fré   )rm   )rì   rU   s     r<   rí   Ú*roots.<locals>.<lambda>.<locals>.<genexpr>n  s   é € ÐEÒ2D¨QŸyžyÒ2Dùrï   )ró   Úas_numer_denomr‚  s    r<   rÞ   rƒ  n  s   € œ3ÑE°!×2BÑ2BÔ2DÓEÔEr>   c                 ó   • U R                   $ ré   )Úis_imaginaryr‚  s    r<   rÞ   rƒ  o  s   € ˜1Ÿ>š>r>   )ÚZÚQrZ   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.polytoolsrh  ÚdictrY  rŒ   Ú
ValueErrorr   rÃ   r   r&   r«   Ú	is_Symbolr!   r¿   r|  Úas_exprÚas_independentrR  r(   r   rB   rC   Úas_base_exprD   Úis_AddrE   rk   rý   Úitemsr   r"   Úis_multivariater   ÚperrP  Ú	terms_gcdr   rS   r`  r5   Úis_RingÚto_fieldÚis_QQ_IrC  r    rz  Úis_Exactr6   Únrootsr=   r_   rÎ   rä   Úis_EXrn   ÚKeyErrorr�   ÚupdateÚsumÚvaluesr$   r.   r   rÂ   )1r9   ra  r‹   ro   rb  rc  rg   rd  re  rf  rR  Úflagsrh  r‡   r;  r^   r}   ÚFrÅ   ÚconÚdepÚfconÚbasesrV   r¦   rr   rs   r+  ro  rw  Údumgensrm  Ú	rescale_xÚtranslate_xr  r;   r:   Ú	roots_funrt   rs  Úresrn  rt  Ú_resultÚhandlersÚqueryÚzeroÚresult1rv  s1     ````                                          @r<   rk   rk   5  sö  ü€ õ` 9Ü�‹K€Eä�!”T×ÑÞÜÐ9Ó:Ð:ä�#‹Jˆà”c˜!“f˜q‘jˆaãˆEÜ  ›¨¨Q©ˆJˆD‰G’Qñ ô � Ñ%Šð&	5Ü�QÐ'˜Ò' Ñ'ˆAÜ˜a¤×&Ñ&¨q¯u©u¯¯Ü%Ð&BÓCÐCØˆAð —‘“
ˆAØ�x‰x‹z˜QŒ 1 q¤5àŸ9™9›;×5Ò5°q·v±vÐ>‘��SØ˜Ÿ™›Ð'�Ø˜3”;Ø�CØ�EÜ Ÿ]š]¨3Ö/˜ØŸ8Ÿ8™8Ø#$§=¡=£?™D˜A˜qØ Ÿ|Ÿ|™|°··±Ø %§¡¨a´ÀÑ1EÐ-FÖ Gñ	 0ö
 Ü"¤4¨¨s©×(<Ñ(<¼TÀ%»[Ó(Ið $%ØŸV™Vò$%ð 
%Ø'(§v¡vñ
%à!%Ø#)Ø!%Ø%-Ø%-Ø%-Ø#)Ø&/ñ
%ð $ñ
%˜ð *,¯©¬ô 5â)3¡  Aô !-¨Q¯Z©ZÙ.3Ô4ªe¡d a¨˜Q šT©eÒ4ó.6ó !àò!á)3ò 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�Ù˜V U¨A¨qÖ1ó  à�X‰X‹Z˜1‹_Ù˜ ¬°Q«¸Ñ(:¸AÖ>Ø�X‰X‹Z˜1‹_Ø+,¯8©8«:¸«?�ÄˆIÙ˜q–\�Ù˜V U¨A¨qÖ1ó "ô ˜aŸi™i›kÓ*×6Ñ6Ó8‰JˆAˆwÜ�7‹|˜qÓ  Q§X¡X£Z°1£_Ü(¨Ö+�AÙ  ¨°°1Ö5ò ,ô �w“< 1Ó$¨°©°A©¸!Ó);Ø—|‘|“~×+×+Ù0°Ó3˜ÞØ" 1™v™~Ø14°Q°R°¡ ©Qà/2°1©v°s¸2±w¨1 	Ü%*¨1£X˜FÞ#)Ù3AÀ!Ö3D KÙ$0°¸ÀÈQÖ$Oñ 4Eøñ &5°QÖ%7 Ù ,¨V°U¸A¸qÖ Aò &8ñ ,:¸!Ö+<˜KÙ(¨°¸ÀQÖGò ,=ó -4Ñ(˜ qÙ!0´°mÀQÇUÁUÐRVÑ1WÖ!X˜AÙ(¨°¸¸1Ö=ó "Yñ -4ð ”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^  È.^É^É^Ù ^= Þ^Þ ^:Þ5^:Þ9^:Þ=_©rd  c                óL  • [        U5      n[        U /UQ70 UD6nUR                  (       d  U /$ UR                  (       a  [	        S5      eUR
                  S   n[        XAS9nU(       d  U/nO}/ Sp‡[        UR                  5       5       H  u  pšU[        XY-
  U5      /U
-  -   XŠ-   p‡M     X„R                  5       :  a-  [        S U5      nUR                  UR                  U5      5        [        U [        5      (       d  U V s/ s H  o R                  5       PM     nn U$ s  sn f )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)]

rk  r   r³  c                 ó
   • X-  $ ré   rH  )rp   rq   s     r<   rÞ   Úroot_factors.<locals>.<lambda>Å  s   €  A¢Cr>   )rŽ  r&   rO  r–  r�  rR  rk   r   r•  r¿   r   rE   r}  rY  r‘  )r9   rd  rR  Úargsr¤  r‡   rm  rs  ÚNr:   rÅ   ÚGs               r<   Úroot_factorsrº     sþ   € ô �‹:€DäˆQÐ�Ò˜Ñ€Aà�9�9Øˆsˆ
à××ÜÐEÓFÐFà	�‰ˆq‰	€Aä�!Ñ#€EæØ�#‰à˜�ä˜EŸK™K›MÖ*‰DˆAØ ¤D¨©°£NÐ#3°AÑ#5Ñ5°q±u’Qñ +ð �x‰x‹z‹>ÜÑ'¨Ó1ˆAØ�N‰N˜1Ÿ5™5 ›8Ô$ä�aœ×ÑÙ)0Ó2ª A—I‘I–K©ˆÐ2à€Nùò 3s   Ä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æ   r3  rù   rA  r`  rk   rº  rH  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>   