
    \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       M/var/www/auris/envauris/lib/python3.13/site-packages/sympy/polys/polyroots.pyroots_linearr=   %   sb    	
q	!%%(A
,,.Cq	A
 3J 9A3J    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yyRVV..266A:?		#bggrvvqy12R 	 #
 UAbBd1g:Aw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    llnGA!
,,.C"" 	AFF{!AB2B8 8O7 ^^4 8O3 
affBqD!A!HR$ 8O! qD1Q3q5LaCBqD!A!Aq!$UU== 8O !!/1h7hk!nh7FB8O 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  oUS-  U-  -
  PM     sn$ U R                  5       R                  5       u  pp4U[        R                  L a!  [        S
X#/SS9u  pU[        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OU[        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 )zReturns 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   Tr1   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qSUQT\AadF#q!tVac!eAg1a4	)Bq!tG4qDF1HQJ1a4!AqDAI-!AqD82ad71a4<GEd?B1X		!D!AJ,s4DAJx1~0M+Nq+PSTUWSWX`abdeXfSf+f'ggh ')*r!!AIr** %%'JA!AFF{1y40AFFB 	
qDF
A	aCE	AadF2IAQ3DQ3D	BAFF{;E719MMd1aj[tQB{	
aff1ay40B')1662&67&6sd
&677	
q}}A2a4$q!tAva/00!44d1gIaKE	zUUb!_u$b!_u$aTAaCZq!tVac!e^bd""tBEAb!eGO,,a/335r2,?,B!bd(RT"W$%a',??	Xb!_u$	%B	Xb!_u$	%BAFF{T	29b4i00 
d2g	d2g	d2gD Ke +. 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	AqD2a419	!Q$Aq0	01a4	7BtB{516689E!HES__SSEEHE
A	aB	
2qsA	
QqSA	aeB	aeBGaK"rAsRx!|RWq[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    QqSMsQqSys1u A$4- 01D$

AC!&L!#3d#:; % ! 
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   ^ GGI((*MA!x%A!t<<<
#Quuac1Aa!A#%q) #!Q$+/1%!Q$+/1%R R wT"QJQBqD1Q3J'(sQq!B$r'AaC-01455699Q1I575 %(d3i57FB,.3R*<=*<3C$J*<==995!Q1==A*+,!3C$J!,, (1a6DAb1AAc	AaCE!AqDF*A!QB	 A 8B?"QU*ByyBx 1QAb()D1tA2A8B?"Q&1Q.B##Bx #&d2hR"9;"9B r2a8nr4j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XUS-    n[        [        U5      5      nM      / S[        -  [        -  U-  pU	 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558QUU1Xq13K<DMET* 

Cq5A:D
4<TAX22CC 
Ba4D
		$	
		!4BIIq"gIIr1g	  
 
		!1c"gq)QU|HTN+ *
 1Q3r6!8113xt,eDj((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     'qk=kWQU^uq1ukF=DA		U
  	
ADIIaq!n%&AIAF
&aLa	 &
 GA	ACR[	U
  	DIIaq!n%&A4K7 >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Dc!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;    ,DA1!e_AquuD166QVV	  LMME qDq!a%<ADAJ!Oa<
DEaCF1H"ALLQS67  L d2qk*AMMOA./DAqLL!$$&! 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  ppEpgU(       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-  XS-  -  -   XS-  -  -   X-  -   U-   5      n OXEXg4u  pp[	        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
  oU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.PU  .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'(||~$GbbQw.PQQQ!|%&\\^"BB 77"1$$72a!GQJ,r/172a!GQJ,r/""44q!|C7GGA
2b 007A:b=3DDqRS|TXGXXEEAQ$a4'!#-12R^
a!nG 
++C
??$Q'1:AJOOA&E ( 	QAGE!(E5%		%A
E(CaD1Q4:E!qtEz!IQ4!A$u*Dtad5j H!8afD!|aj(H	E	BQ4D	UFT$Z/47	8B	UFT$Z/47	8B	YJh74?	@B	YJh74?	@BMM%#E%'')O"$$&2446/BDDFRTTVO!DFDaRB 
bhE	!BuH	,r%x	7B	bhE	!BuH	,r%x	7B	bhE	!BuH	,r%x	7B	bhE	!BuH	,r%x	7B$D6!8dVAXvax
8CD6!8dVAXvax$:E 
2	B	2	B	2	B	2	B 
QqT!VB	aB	aB	a"fB	
2B	aB	
2aB	DaLBsBrEBJRURZ2#rBw{2CR"rTUEV
WC		B		B		B		B#1%ajj!RUQr!uW_1E&FGAq	%ajj!RUQr!uW_1E&FGAq	%ajj!RUQr!uW_1E&FGAq	%ajj!RUQr!uW_1E&FGAq		  1a[qAa&)++-E!HQK)#a&)4CF1I   
QB8A;D1X4a#$a--QB  ::eQDAqAeGDGO#&&(HQuWT!W_$'')I 446DNB1X8A;qA Qx{Hd8Q;&hk)99HDGGI1cRRhtQw&$')99IEHHJAsSSVAYVAY  >  	 r'B,
Q	B
U(RX
5
(2e8
3Q	6B
U(RX
5
(2e8
3Q	6B
U(RX
5
(2e8
3Q	6B
U(RX
5
(2e8
3Q	6B"b"b!F %CCCF8 I
  +126ag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  pXU-  -  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   , #tzz|,-NF3< GF#c6"#Fay6":hv&'1I!)&!12!1Aa%!12CR[FCR[F 6{aq	155?+<<q6MHXf-.qr23D4j /LEEz!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  pU(       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<Mq<Mr   Nr   Frh   c                     > UTTU S   -
  -  -  $ )Nr    )rs   r}   basisr   s     r<   funcpreprocess_roots.<locals>.func*  s    ea!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   EEE		I##D#1 >>AD<<>D    S(NDHHOO<M(N%N%N{{}c4;;=)*DIIabM"ay&*fd4j&1JCGQx%)# ED(!UaZVF} & ) "FEyya(v&C ; 2> ::t$Ddoo/55t$A0 ==&DUNE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-
  pU  H  n[        U5      US-
  sX'   nM     [        XS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OU R                  5       S:X  a  U" U"U[c        U 5      S   S5        GOU 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    !&& vvaff" !aff 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    *71:6KLL% 7 %QR[M"5k2e'!Dee$<<#21#5KLL- $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==FF8AHHJ&&88:?xxzQCQ899%a((A66!99EE$quuqy!%%01a 	  HHJ6d3v|A788F  !Vd3vq'9:;;F  __&q))F  !Vk!$//F  !VmA&&F  !VmA&&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     E2DQyy2Dr   )r   as_numer_denomr  s    r<   r   r  n  s    3E!2B2B2D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KE!T9::#Jc!fqjaE QJDGQ  %&	5Q'''Aa&&quu%&BCCA 
AxxzQ1q599;55qvv>S'3;CE ]]3/888#$==?DAq ||| %a1E-F G	 0
 "4s(<(<T%[(I $%VV$% 
%'(vv
%!%#)!%%-%-%-#)&/
% $
% *, 5)3A !-QZZ.34edaQTe4.6 !!)3 5 5 !"NOO	$$$ $N fs166{*6G	aeeWAkkmGDQ!"HE1&&JJL 	||~EE!%%--#$IKF;;;lln|| 0 0XXZVUAq1  XXZ1_Q(:A>XXZ1_+,88:?Iq\VUAq1 " aiik*668JAw7|q QXXZ1_(+A 15 , w<1$A!);||~++03"1v~14QRQ/21vs2w1	%*1XF#)3A!3DK$0Q$O 4E &5Q%7 ,VUAq A &8 ,:!+<K(QG ,= -4(q!0mQUURV1W!XA(1= "Y -4 AEE!2%mmoNK()F5$% . [ '(E)	
	<V$E L%%'D;;4L ( L%%'DT??4L ( LLNDAq#$GAiK  #LLNDAq'(GAO$ # MM%#fmmo&3#J 0 %  	 FODLL$t,- $ G 5 5?   					t  	<1F:;;	<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  pU[        XY-
  U5      /U
-  -   X-   pM     XR                  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    ACr>   )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99s
EFF	q	A!#E#EKKM*DA DN#3A#55quQ + xxz>'1ANN1558$a)02AIIK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 " + 3KCLCJ5Bpy;x7t*Z@gT>BFR g gT #' +r>   