ó
    Š*£h±¢  ã                   ó’  • 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  S SKJrJr  S SKJrJrJr  S SKJrJrJr  S SKJrJrJr  S S	KJr  S S
KJrJ r   S SK!J"r"J#r#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/J0r0J1r1  S#S jr2S r3S$S jr4S r5SS.S jr6S%S jr7S r8S&S jr9S&S jr:S&S jr;S r<S r=S  r>\=r?\>r@\<rAS! rBS" rCg)'é    )Údefaultdict)ÚsympifyÚSÚMulÚ
DerivativeÚPow)Ú_unevaluated_AddÚAdd)Úassumptions)ÚFactorsÚ	gcd_terms)Ú_mexpandÚ
expand_mulÚexpand_power_base)Ú_keep_coeffÚ_unevaluated_MulÚ_mulsort)ÚRationalÚzooÚnan)Úglobal_parameters)ÚorderedÚdefault_sort_key)ÚDummyÚWildÚsymbols)ÚexpÚsqrtÚlog)ÚAbs)Úgcd)Ú
sqrtdenest)ÚiterableÚsiftNTc                 ó  ^^^.^/• [        U 5      n [        T5      (       a  TOT/ Vs/ s H  n[        U5      PM     snmS n[        TUSS9u  p‰U	(       Ga  [        [	        X™ Vs/ s H  n[        S0 [        U5      D6PM     sn5      5      n
T Vs/ s H  oºR                  X»5      PM     snm[        U R                  U
5      TX#TUS9nU
R                  5        VVs0 s H  u  pÞXí_M	     nnn[        U[        5      (       d  UR                  U5      $ UR                  5        VVs0 s H5  u  pÞUR                  XÝ5      R                  U5      UR                  U5      _M7     snn$ Tcå  [        5       n[        R                  " U 5       H�  nUR                   " T6 (       a  UT;   a  M  UR"                  (       d  UT;  a  UR%                  U5        MI  UR&                  " UR(                  " T6 S   6 nUT;  d  Mp  UR%                  U5        Mƒ     [+        U4S jU 5       5      nT[-        [/        U5      5      -   mU(       d  [        U TX#SUS9$ Uc  [0        R2                  nS	 nS
 m.U.4S jm/UU/4S jnU(       aø  U R4                  (       a]  U R7                  5       =(       d    SnU R8                  " U R:                   Vs/ s H  nUU:w  d  M  [        UTUSTU5      PM     sn6 U-   n OŠU R"                  (       a8  U R8                  " U R:                   Vs/ s H  n[        UTUSTU5      PM     sn6 $ U R<                  (       a0  [        U R>                  TUSTU5      n[A        UU RB                  5      $ T Vs/ s H  n[E        USS9PM     snmSnU(       a:  U R7                  5       nUb'  URF                  " T6 (       a  SnOU RI                  5       n [        R                  " U 5       Vs/ s H  n[E        USS9PM     nn[K        [,        5      [L        RN                  nnU GHE  nURQ                  SS9u  nn[-        [/        U5      5      U-   n U  Vs/ s H  nT/" U5      PM     n!nSn"T Hó  n#[        U#[R        5      (       a"  U"(       a  [-        [U        U!5      5      n!U"(       + n"U" U!U#5      n$U$c  MH  U#RV                  (       d  [Y        S5      eU$u  n!n%n&n'U'(       dI  / n(U% H8  n)U)S   c  U)S   n*OU)S   U)S   -  n*U(R[                  [A        U)S   U*5      5        M:     []        U(6 n+OU" U%5      n+[E        U" U!5      SS9n![E        U+SS9n+UU+   R[                  U!5          GM>     UU-  nGMH     UR                  5        VVs0 s H  u  pÞU[        U6 _M     nnnU[L        RN                  La  UU[L        R^                  '   Ub"  UR                  5        H  u  n,n-U-U-   UU,'   M     Ub,  UR                  5        V,V-s0 s H  u  n,n-U,U" U-5      _M     nn,n-U(       a/  [        UR                  5        V,V-s/ s H  u  n,n-U,U--  PM     sn-n,6 $ U$ s  snf s  snf s  snf s  snnf s  snnf s  snf s  snf s  snf s  snf s  snf s  snnf s  sn-n,f s  sn-n,f )a  
Collect additive terms of an expression.

Explanation
===========

This function collects additive terms of an expression with respect
to a list of expression up to powers with rational exponents. By the
term symbol here are meant arbitrary expressions, which can contain
powers, products, sums etc. In other words symbol is a pattern which
will be searched for in the expression's terms.

The input expression is not expanded by :func:`collect`, so user is
expected to provide an expression in an appropriate form. This makes
:func:`collect` more predictable as there is no magic happening behind the
scenes. However, it is important to note, that powers of products are
converted to products of powers using the :func:`~.expand_power_base`
function.

There are two possible types of output. First, if ``evaluate`` flag is
set, this function will return an expression with collected terms or
else it will return a dictionary with expressions up to rational powers
as keys and collected coefficients as values.

Examples
========

>>> from sympy import S, collect, expand, factor, Wild
>>> from sympy.abc import a, b, c, x, y

This function can collect symbolic coefficients in polynomials or
rational expressions. It will manage to find all integer or rational
powers of collection variable::

    >>> collect(a*x**2 + b*x**2 + a*x - b*x + c, x)
    c + x**2*(a + b) + x*(a - b)

The same result can be achieved in dictionary form::

    >>> d = collect(a*x**2 + b*x**2 + a*x - b*x + c, x, evaluate=False)
    >>> d[x**2]
    a + b
    >>> d[x]
    a - b
    >>> d[S.One]
    c

You can also work with multivariate polynomials. However, remember that
this function is greedy so it will care only about a single symbol at time,
in specification order::

    >>> collect(x**2 + y*x**2 + x*y + y + a*y, [x, y])
    x**2*(y + 1) + x*y + y*(a + 1)

Also more complicated expressions can be used as patterns::

    >>> from sympy import sin, log
    >>> collect(a*sin(2*x) + b*sin(2*x), sin(2*x))
    (a + b)*sin(2*x)

    >>> collect(a*x*log(x) + b*(x*log(x)), x*log(x))
    x*(a + b)*log(x)

You can use wildcards in the pattern::

    >>> w = Wild('w1')
    >>> collect(a*x**y - b*x**y, w**y)
    x**y*(a - b)

It is also possible to work with symbolic powers, although it has more
complicated behavior, because in this case power's base and symbolic part
of the exponent are treated as a single symbol::

    >>> collect(a*x**c + b*x**c, x)
    a*x**c + b*x**c
    >>> collect(a*x**c + b*x**c, x**c)
    x**c*(a + b)

However if you incorporate rationals to the exponents, then you will get
well known behavior::

    >>> collect(a*x**(2*c) + b*x**(2*c), x**c)
    x**(2*c)*(a + b)

Note also that all previously stated facts about :func:`collect` function
apply to the exponential function, so you can get::

    >>> from sympy import exp
    >>> collect(a*exp(2*x) + b*exp(2*x), exp(x))
    (a + b)*exp(2*x)

If you are interested only in collecting specific powers of some symbols
then set ``exact`` flag to True::

    >>> collect(a*x**7 + b*x**7, x, exact=True)
    a*x**7 + b*x**7
    >>> collect(a*x**7 + b*x**7, x**7, exact=True)
    x**7*(a + b)

If you want to collect on any object containing symbols, set
``exact`` to None:

    >>> collect(x*exp(x) + sin(x)*y + sin(x)*2 + 3*x, x, exact=None)
    x*exp(x) + 3*x + (y + 2)*sin(x)
    >>> collect(a*x*y + x*y + b*x + x, [x, y], exact=None)
    x*y*(a + 1) + x*(b + 1)

You can also apply this function to differential equations, where
derivatives of arbitrary order can be collected. Note that if you
collect with respect to a function or a derivative of a function, all
derivatives of that function will also be collected. Use
``exact=True`` to prevent this from happening::

    >>> from sympy import Derivative as D, collect, Function
    >>> f = Function('f') (x)

    >>> collect(a*D(f,x) + b*D(f,x), D(f,x))
    (a + b)*Derivative(f(x), x)

    >>> collect(a*D(D(f,x),x) + b*D(D(f,x),x), f)
    (a + b)*Derivative(f(x), (x, 2))

    >>> collect(a*D(D(f,x),x) + b*D(D(f,x),x), D(f,x), exact=True)
    a*Derivative(f(x), (x, 2)) + b*Derivative(f(x), (x, 2))

    >>> collect(a*D(f,x) + b*D(f,x) + a*f + b*f, f)
    (a + b)*f(x) + (a + b)*Derivative(f(x), x)

Or you can even match both derivative order and exponent at the same time::

    >>> collect(a*D(D(f,x),x)**2 + b*D(D(f,x),x)**2, D(f,x))
    (a + b)*Derivative(f(x), (x, 2))**2

Finally, you can apply a function to each of the collected coefficients.
For example you can factorize symbolic coefficients of polynomial::

    >>> f = expand((x + a + 1)**3)

    >>> collect(f, x, factor)
    x**3 + 3*x**2*(a + 1) + 3*x*(a + 1)**2 + (a + 1)**3

.. note:: Arguments are expected to be in expanded form, so you might have
          to call :func:`~.expand` prior to calling this function.

See Also
========

collect_const, collect_sqrt, rcollect
c                 óŒ   • U R                   =(       d2    U * R                   =(       d    [        U R                  [        5      5      $ ©N)Ú	is_SymbolÚboolÚatomsr   ©Úxs    ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/simplify/radsimp.pyÚ<lambda>Úcollect.<locals>.<lambda>°   s1   € �Q—[‘[÷  a R§N¡N÷ ´dØ	�‰”‹ó7ð ó    T)Úbinary)ÚfuncÚevaluateÚexactÚdistribute_order_termNé   c              3   óf   >#   • U  H&  oR                   =(       a    UR                  T;   v •  M(     g 7fr'   )Úis_PowÚbase)Ú.0ÚiÚsymss     €r-   Ú	<genexpr>Úcollect.<locals>.<genexpr>Í   s#   øé € Ð@º%°Q—X‘X×0 !§&¡&¨D¡.Ô0º%ùs   ƒ.1Fc                 ó:  • / nU  HŒ  u  p#pEUb!  Uu  pg[        U5       H  n[        X&5      nM     UcB  U[        R                  L a  UR	                  U5        MS  UR	                  [        X#5      5        Mo  UR	                  [        X#U-  5      5        MŽ     [        U6 $ r'   )Úranger   r   ÚOneÚappendr   r   )	ÚtermsÚproductÚtermÚratÚsymÚderivÚvarÚorderÚ_s	            r-   Úmake_expressionÚ collect.<locals>.make_expression×   sŠ   € Øˆã%*Ñ!ˆD�sØÑ Ø"‘
�Ü˜už�AÜ% dÓ0’Dñ &ð ‰{Øœ!Ÿ%™%’<Ø—N‘N 4Ö(à—N‘N¤3 t£>Ö2à—‘œs 4¨S©Ó1Ö2ñ &+ô �Gˆ}Ðr0   c                 óØ  ^• U R                   U R                  S   Sp2nU R                  SS   H  nXB:X  a  US-  nM  [        S5      e   [        U[        5      (       a€  UR                  S   m[        U4S jUR                   5       5      (       a  [        S5      eTU:X  a$  UR                   U[        UR                  5      -   p1OO[        U[        5      (       a  M€  X[        U5      44$ )Nr   r6   z(Improve MV Derivative support in collectc              3   ó,   >#   • U  H	  oT:g  v •  M     g 7fr'   © )r:   ÚsÚs0s     €r-   r=   Ú4collect.<locals>.parse_derivative.<locals>.<genexpr>ù   s   øé € Ð3¢N˜q˜–7¢Nùs   ƒ)ÚexprÚ	variablesÚNotImplementedErrorÚ
isinstancer   ÚanyÚlenr   )rH   rT   rG   rJ   rQ   rR   s        @r-   Úparse_derivativeÚ!collect.<locals>.parse_derivativeê   sÞ   ø€ ð !Ÿ:™: u§¡°qÑ'9¸1�5ˆà—‘  Ó$ˆAØ‹xØ˜‘
’ä)Ø>ó@ð @ñ	 %ô ˜œz×*Ñ*Ø—‘ Ñ"ˆBäÔ3 D§N¢NÓ3×3Ñ3Ü)Ø>ó@ð @ð �S‹yØ"Ÿi™i¨´°T·^±^Ó1DÑ)D‘eàô ˜œz×*Ó*ð œ8 E›?Ð+Ð+Ð+r0   c                 óÀ  >• [         R                  Sp!U SpCU R                  (       Ga"  [        U R                  [
        5      (       a  T" U R                  5      u  p4OU R                  nU R                  [         R                  :X  a_  U R                  nUR                  (       a  [         R                  UpGO&UR                  (       a  UR                  SS9u  pg[        U5      UpO÷U R                  R                  (       a  U R                  nOÏU R                  R                  5       u  pgUR                  (       a  Xgp!OŸU R                  nO’[        U [        5      (       a^  U R                  nUR                  (       a  [         R                  UpONUR                  (       a  UR                  SS9u  pg[        U5      UpO[        U [
        5      (       a
  T" U 5      u  p4X1X$4$ )aŠ  Parses expression expr and outputs tuple (sexpr, rat_expo,
sym_expo, deriv)
where:
 - sexpr is the base expression
 - rat_expo is the rational exponent that sexpr is raised to
 - sym_expo is the symbolic exponent that sexpr is raised to
 - deriv contains the derivatives of the expression

 For example, the output of x would be (x, 1, None, None)
 the output of 2**x would be (2, 1, x, None).
NT)Úrational)r   rA   r8   rW   r9   r   ÚExp1r   Úis_RationalÚis_MulÚas_coeff_MulÚ	is_Number)	rT   Úrat_expoÚsym_expoÚsexprrH   ÚargÚcoeffÚtailrZ   s	           €r-   Ú
parse_termÚcollect.<locals>.parse_term  sR  ø€ ô ŸU™U D�(Ø˜Tˆuà�;�;ˆ;Ü˜$Ÿ)™)¤Z×0Ñ0Ù/°·	±	Ó:‘��uàŸ	™	�à�y‰yœAŸF™FÓ"Ø—h‘h�Ø—?—?Ü&'§f¡f¨cš8Ø—Z—ZØ"%×"2Ñ"2¸DÐ"2Ð"A‘K�EÜ&)¨$£i°˜8øà—‘×#×#ØŸ8™8‘à"Ÿh™h×3Ñ3Ó5‘�à—?—?Ø).™hà#Ÿx™x‘HÜ˜œc×"Ñ"Ø—(‘(ˆCØ��Ü"#§&¡&¨#‘xØ——Ø!×.Ñ.¸Ð.Ð=‘�Ü"% d£)¨U�xøÜ˜œj×)Ñ)Ù+¨DÓ1‰LˆEà Ð/Ð/r0   c                 ó†  >• [         R                  " U5      n[        U 5      [        U5      :  a  gU Vs/ s H  nT" U5      PM     nnU SS n / SSpTnU HÂ  u  p&pxUR                  (       a  US:X  a  Uc  M"  [	        [        U 5      5       Hˆ  n	X	   c  M
  X	   u  p«pÍUb  SnU
R                  U5      c  M*  XÇ:X  d  Uc  M4  Uc  M9  UR                  U5      c  MM  TSL a  X¶-  nUc  UnOXN:w  a  SnOXk:w  d  X�:w  a  Mp  UR                  X	   5        SX	'     MÀ       g   U  Vs/ s H  oÿ(       d  M  UPM     snX4U4$ s  snf s  snf )z•Parse terms searching for a pattern.
Terms is a list of tuples as returned by parse_terms;
Pattern is an expression treated as a product of factors.
NFr6   T)r   Ú	make_argsrY   rb   r@   ÚmatchrB   )rC   ÚpatternÚelemÚelemsÚcommon_expoÚ	has_derivÚe_ratÚe_symÚe_ordÚjrE   Út_ratÚt_symÚt_ordÚexpoÚ_fr4   ri   s                   €€r-   Úparse_expressionÚ!collect.<locals>.parse_expression6  sc  ø€ ô
 —-’- Ó(ˆäˆu‹:œ˜G›Ó$ð á4;Ó<²G¨D‘z $Ö'±GˆGÐ<à™!�HˆEØ,.°°e 	ˆEã-4Ñ)�˜Uà—>—> e¨q£j°U±]áäœs 5›zÖ*�AØ‘xÑ'Ù à05±Ñ-�D ð
 Ñ(Ø$(˜	àŸ
™
 4Ó(Ó4Ø"›^¨uÓ/@Ø!Ó-Ø!ŸK™K¨Ó.Ó:Ø  Eš>ð $)¡=˜Dà*Ñ2à.2¡ð
 $/Ó#6Ø23 Køð  %›~°³Ù (ð Ÿ™ U¡XÔ.Ø#'˜™âñS +ñZ  ñg .5ñj "'Ó-¢˜2«"—B¡Ñ-¨uÀ9ÐLÐLùòu =ùòt .s   µD9Ä
D>Ä-D>r   )Údeep)Úsplit_1z%Can not collect noncommutative symbolé   rP   )0r   r#   r$   ÚdictÚzipr   r   ÚgetÚcollectÚsubsÚitemsrW   ÚxreplaceÚsetr
   rl   Úhas_freer`   ÚaddÚ_new_rawargsÚas_coeff_mulÚallÚlistr   r   r3   Úis_AddÚgetOr2   Úargsr8   r9   r   r   r   ÚhasÚremoveOr   r   ÚZeroÚargs_cncr   ÚreversedÚis_commutativeÚAttributeErrorrB   r   rA   )0rT   r<   r2   r3   r4   r5   r;   ÚcondrK   ÚnonsymsÚrepsrQ   ÚrvÚkÚvÚurepÚ_symsÚgÚsimplerL   r|   ÚoÚarE   ÚbÚ
order_termÚsummaÚ	collectedÚdislikedrD   ÚcÚncr‘   rC   Úsmall_firstÚsymbolÚresultrp   rq   rr   Úmargsro   ÚeÚindexÚkeyÚvalrZ   ri   s0    `  `                                         @@r-   r„   r„      s  û€ ôl �4‹=€DÜ)1°$¯©¡¸d¸VÐ!CÓEÒ!C˜1ŒG�AŽJÑ!CÑE€Dñ€Dä�d˜D¨Ñ.�J€AßÜ”C˜À7Ó!KÂ7¸a¤%Ñ"9¬+°a«.Ô"9Á7Ñ!KÓLÓMˆÙ(,Ó-ª 1—‘˜–©Ñ-ˆÜ�T—Y‘Y˜t“_ dØ°Ø"7ñ9ˆð "&§¡¤Ô.¢™˜�’¡ˆÑ.Ü˜"œd×#Ñ#Ø—;‘;˜tÓ$Ð$ð !#§¡¤
ô,Ú *™˜ð —H‘H˜Q“N×+Ñ+¨DÓ1°1·:±:¸dÓ3CÒCÙ *ò,ð ,ð �}Ü“ˆÜ—’˜tÖ$ˆAØ—:’:˜tÖ$¨¨T«	ÙØ—8—8 ¨£Ø—	‘	˜!–ð —N’N A§N¢N°DÐ$9¸!Ñ$<Ð=�Ø˜D•=Ø—I‘I˜a–Lñ %ô Ô@¹%Ó@Ó@ˆØ”dœ7 5›>Ó*Ñ*ˆÞÜ˜4 Ø°Ø"7ñ9ð 9ð ÑÜ$×-Ñ-ˆòò&,õ400ödFMöP Ø�;�;Ø—	‘	“× ˜qˆAØ—9’9à!ŸYšYó2â&˜¨!¨q©&ó O”G˜A˜t T¨4°Ð8MÖNÙ&ñ2ð 3à56ñ7‰Dð �[�[Ø—9’9à ŸIšIó'â%�Dô ˜˜d D¨$°Ð7LÖMÙ%ñ'ð (ð (ð �[�[ÜØ—	‘	˜4  t¨UÐ4IóKˆAä�q˜$Ÿ(™(Ó#Ð#á6:Ó;²d°Ô˜a eÔ,±dÑ;€Dà€JæØ—Y‘Y“[ˆ
àÑ!Ø�~Š~˜tÖ$Ø!‘
à—|‘|“~�ä7:·}²}ÀTÔ7JÓKÒ7J°!Ô˜q uÔ-Ñ7J€EÐKä%¤dÓ+¬Q¯V©Vˆx€IÜˆØ× Ñ ¨Ð Ð/‰ˆˆ2Ü”G˜A“JÓ "Ñ$ˆÙ(,Ó-ª 1‘˜A–©ˆÐ-ØˆãˆFÜ˜&¤*×-Ñ-¶+ÜœX e›_Ó-�Ø"-œo�Ù% e¨VÓ4ˆFàÓ!Ø×,×,Ü(Ð)PÓQÐQà7=Ñ4��u˜k¨9ö !Ø�EÛ %˜Ø ™7™?Ø $ Q¡™Aà $ Q¡¨¨Q©¡˜AØŸ™¤S¨¨a©°!£_Ö5ñ !&ô   ˜K‘Eá+¨EÓ2�EÜ)©/¸%Ó*@ÀuÑM�Ü)¨%°eÑ<�Ø˜%Ñ ×'Ñ'¨Ô.Ûñ9 ð> ˜Ñ‹HñK ðN )2¯©Ô(9Ô:Ò(9¡ �”C˜�G’Ñ(9€IÑ:à”q—v‘vÒØ#ˆ	”!—%‘%ÑàÑØ!Ÿ™Ö)‰HˆC�Ø  :Ñ-ˆI�c‹Nñ *ð Ñà+4¯?©?Ô+<ô>Ú+<™x˜s CˆC‘�c“ŠNÑ+<ð 	ñ >ö Ü¨Y¯_©_Ô->Ô?Ò->¡  c�S˜”WÑ->Ò?Ð@Ð@àÐùòO	 Fùò "LùÚ-ùó /ùó,ùòH2ùò'ùò <ùò Lùò .ùóH ;ùó>ùó @sS   §Y	Á%YÂYÃYÄ(<YË
Y$ËY$ÌY)Í9Y.Ï+Y3ÑY8Õ?Y=×8ZØ0Z	
c           	      óþ   • U R                   (       d  U R                  " U6 (       d  U $ U R                  " U R                   Vs/ s H  n[	        U/UQ76 PM     sn6 n U R
                  (       a  [        X5      $ U $ s  snf )a!  
Recursively collect sums in an expression.

Examples
========

>>> from sympy.simplify import rcollect
>>> from sympy.abc import x, y

>>> expr = (x**2*y + x*y + x + y)/(x + y)

>>> rcollect(expr, y)
(x + y*(x**2 + x + 1))/(x + y)

See Also
========

collect, collect_const, collect_sqrt
)Úis_Atomr’   Ú	__class__r‘   Úrcollectr�   r„   )rT   Úvarsrf   s      r-   r·   r·   ×  sb   € ð( ‡|‡|˜4Ÿ8š8 Tž?Øˆà�~Š~ÀÇ	Â	ÓJÂ	¸¤¨Ð 4¨tÕ 4Á	ÑJÐKˆà�;�;Ü˜4Ó&Ð&àˆKùò  Ks   ÁA:c                 óÚ  • Uc  [         R                  nU R                  5       u  p [        5       n[        R
                  " U 5       Hœ  nUR                  5       S    H‚  nUR                  (       d  M  UR                  (       a5  UR                  R                  (       a  UR                  R                  S:X  d  U[        R                  L d  Mq  UR                  U5        M„     Mž     [        U /UQ7SS06nX:g  nU(       dé  Sn[!        [#        [        R
                  " U5      5      5      n	[%        U	5       HŒ  u  p¥UR                  5       u  p¼U Hc  nUR                  (       a5  UR                  R                  (       a  UR                  R                  S:X  d  U[        R                  L d  M^  US-  n  O   Xš==   U-  ss'   MŽ     U(       d  U(       d	  [	        U	6 /n	['        U	5      U4$ X&-  $ )aÐ  Return expr with terms having common square roots collected together.
If ``evaluate`` is False a count indicating the number of sqrt-containing
terms will be returned and, if non-zero, the terms of the Add will be
returned, else the expression itself will be returned as a single term.
If ``evaluate`` is True, the expression with any collected terms will be
returned.

Note: since I = sqrt(-1), it is collected, too.

Examples
========

>>> from sympy import sqrt
>>> from sympy.simplify.radsimp import collect_sqrt
>>> from sympy.abc import a, b

>>> r2, r3, r5 = [sqrt(i) for i in [2, 3, 5]]
>>> collect_sqrt(a*r2 + b*r2)
sqrt(2)*(a + b)
>>> collect_sqrt(a*r2 + b*r2 + a*r3 + b*r3)
sqrt(2)*(a + b) + sqrt(3)*(a + b)
>>> collect_sqrt(a*r2 + b*r2 + a*r3 + b*r5)
sqrt(3)*a + sqrt(5)*b + sqrt(2)*(a + b)

If evaluate is False then the arguments will be sorted and
returned as a list and a count of the number of sqrt-containing
terms will be returned:

>>> collect_sqrt(a*r2 + b*r2 + a*r3 + b*r5, evaluate=False)
((sqrt(3)*a, sqrt(5)*b, sqrt(2)*(a + b)), 3)
>>> collect_sqrt(a*sqrt(2) + b, evaluate=False)
((b, sqrt(2)*a), 1)
>>> collect_sqrt(a + b, evaluate=False)
((a + b,), 0)

See Also
========

collect, collect_const, rcollect
r   r€   ÚNumbersFr6   )r   r3   Úas_content_primitiverˆ   r
   rl   r•   Ú	is_numberr8   r   r_   Úqr   ÚImaginaryUnitrŠ   Úcollect_constrŽ   r   Ú	enumerateÚtuple)rT   r3   rg   r¸   r¤   ÚmÚdÚhitÚnradr‘   r;   rª   r«   Úcis                 r-   Úcollect_sqrtrÇ   ö  sj  € ðR ÑÜ$×-Ñ-ˆð ×+Ñ+Ó-�K€EÜ‹5€DÜ�]Š]˜4Ö ˆØ—‘“˜a”ˆAØ�{�{‰{Ø—H—H §¡×!2×!2°q·u±u·w±wÀ!³|ØœŸ™Ô(Ø—‘˜–ó	 !ñ !ô 	�dÐ1˜TÒ1¨5Ñ1€AØ
‰)€CæØˆä”GœCŸMšM¨!Ó,Ó-Ó.ˆÜ˜d–O‰DˆAØ—J‘J“L‰EˆAÛ�à—9—9 §¡×!3×!3¸¿¹¿¹ÀA»ØœaŸo™oÔ-Ø˜A‘I�DÙñ ð ‹G�uÑ�Gñ $ö –tÜ˜�J�<ˆDÜ�T‹{˜DÐ Ð à‰7€Nr0   c                 ób   ^• S mU R                  S U4S j5      R                  S U4S j5      $ )a$  Return ``expr`` with arguments of multiple Abs in a term collected
under a single instance.

Examples
========

>>> from sympy.simplify.radsimp import collect_abs
>>> from sympy.abc import x
>>> collect_abs(abs(x + 1)/abs(x**2 - 1))
Abs((x + 1)/(x**2 - 1))
>>> collect_abs(abs(1/x))
Abs(1/x)
c                 óŒ  • U R                  5       u  p/ n/ nU HÏ  n[        U[        5      (       a   UR                  UR                  S   5        M8  [        U[
        5      (       aq  [        UR                  [        5      (       aR  UR                  R                  (       a7  UR                  UR                  R                  S   UR                  -  5        M¾  UR                  U5        MÑ     [        U5      S:  a  [        S U 5       5      (       d  U $ [        U6 n[        U5      nU/nUR                  U5        UR                  [        5      (       d  UR                  U5        [        U6 $ [        U[        5      (       d
  [        USS9nXxS'   [        U5        UR                  U5        [        R                  " X‚(       + S9$ )Nr   r€   c              3   ó|   #   • U  H2  n[        U[        5      (       d  M  UR                  R                  v •  M4     g 7fr'   )rW   r   r   Úis_negative)r:   r;   s     r-   r=   Ú,collect_abs.<locals>._abs.<locals>.<genexpr>^  s'   é € Ð!UºQ¸Ä*ÈQÔPS×BTÓ"3 !§%¡%×"3Ö"3ºQùs   ‚<Ÿ<F©r3   )r—   )r•   rW   r    rB   r‘   r   r9   r   Úis_realrY   rX   r   Úextendr’   r   Ú
_from_args)	Úmulrª   r«   r¤   r£   r;   ÚabsargÚAr‘   s	            r-   Ú_absÚcollect_abs.<locals>._absS  sB  € Ø—‘“‰ˆØˆØˆÛˆAÜ˜!œS×!Ñ!Ø—‘˜Ÿ™ ™Ö#Ü˜Aœs×#Ñ#¬
°1·6±6¼3×(?Ñ(?ÀAÇEÁEÇMÇMØ—‘˜Ÿ™Ÿ™ Q™¨¯©Ñ.Ö/à—‘˜–ñ ô ˆq‹6�A‹:œcÑ!U¹QÓ!U×UÑUØˆJÜ�a�ˆÜ�‹KˆØˆsˆØ�‰�AŒØ�u‰u”S�z‰zØ�K‰K˜ŒOÜ˜�:ÐÜ˜!œS×!Ñ!ä�F UÑ+ˆAØˆQ‰Ü�ŒØ�‰�BŒÜ�~Š~˜d´6Ñ:Ð:r0   c                 ó"   • [        U [        5      $ r'   )rW   r   r+   s    r-   r.   Úcollect_abs.<locals>.<lambda>p  s   € ”*˜Q¤Ô$r0   c                 ó   >• T" U 5      $ r'   rP   ©r,   rÔ   s    €r-   r.   r×   q  s	   ø€ ‘$�q”'r0   c                 ó"   • [        U [        5      $ r'   )rW   r   r+   s    r-   r.   r×   r  s   € ”j ¤CÔ(r0   c                 ó   >• T" U 5      $ r'   rP   rÙ   s    €r-   r.   r×   s  s	   ø€ ‘d˜1”gr0   )Úreplace)rT   rÔ   s    @r-   Úcollect_absrÝ   E  s1   ø€ ò;ð8 �<‰<Ù$Üóç"™7Ù(Üóðr0   )rº   c          
      óª  ^^• U R                   (       d  U $ SnU(       da  Sn[        5       nU R                   HD  n[        R                  " U5       H'  nUR
                  (       d  M  UR                  U5        M)     MF     O[        U5      nU(       d$  U Vs/ s H  ofR                  (       a  M  UPM     nn[        [        U5      5      nU GHý  n[        [        5      n[        U5      n[        R                  " U 5       H¸  n[        U5      n	U	R                  U5      u  p«UR                  (       ad  U	R                   R#                  5       mU
R                   m[%        UU4S jT 5       5      (       d#  Xv   R'                  U
R)                  5       5        M–  U[*        R,                     R'                  U5        Mº     / nSnSn[        U5       HÂ  nX   nU[*        R,                  L a  UR/                  U5        M-  [1        U5      S:”  a(  [        U6 nSnU(       a  X`:w  a  UR'                  U5        OUS   nU(       a?  UR                  (       a.  UR                   (       a  UR'                  [3        XöSS95        SnM¯  UR'                  Xö-  5        MÄ     U(       d  GMÑ  U(       a	  [5        U6 n O[        U6 n U R                   (       a  GMý    U $    U $ s  snf )aê  A non-greedy collection of terms with similar number coefficients in
an Add expr. If ``vars`` is given then only those constants will be
targeted. Although any Number can also be targeted, if this is not
desired set ``Numbers=False`` and no Float or Rational will be collected.

Parameters
==========

expr : SymPy expression
    This parameter defines the expression the expression from which
    terms with similar coefficients are to be collected. A non-Add
    expression is returned as it is.

vars : variable length collection of Numbers, optional
    Specifies the constants to target for collection. Can be multiple in
    number.

Numbers : bool
    Specifies to target all instance of
    :class:`sympy.core.numbers.Number` class. If ``Numbers=False``, then
    no Float or Rational will be collected.

Returns
=======

expr : Expr
    Returns an expression with similar coefficient terms collected.

Examples
========

>>> from sympy import sqrt
>>> from sympy.abc import s, x, y, z
>>> from sympy.simplify.radsimp import collect_const
>>> collect_const(sqrt(3) + sqrt(3)*(1 + sqrt(2)))
sqrt(3)*(sqrt(2) + 2)
>>> collect_const(sqrt(3)*s + sqrt(7)*s + sqrt(3) + sqrt(7))
(sqrt(3) + sqrt(7))*(s + 1)
>>> s = sqrt(2) + 2
>>> collect_const(sqrt(3)*s + sqrt(3) + sqrt(7)*s + sqrt(7))
(sqrt(2) + 3)*(sqrt(3) + sqrt(7))
>>> collect_const(sqrt(3)*s + sqrt(3) + sqrt(7)*s + sqrt(7), sqrt(3))
sqrt(7) + sqrt(3)*(sqrt(2) + 3) + sqrt(7)*(sqrt(2) + 2)

The collection is sign-sensitive, giving higher precedence to the
unsigned values:

>>> collect_const(x - y - z)
x - (y + z)
>>> collect_const(-y - z)
-(y + z)
>>> collect_const(2*x - 2*y - 2*z, 2)
2*(x - y - z)
>>> collect_const(2*x - 2*y - 2*z, -2)
2*x - 2*(y + z)

See Also
========

collect, collect_sqrt, rcollect
FTc              3   ó�   >#   • U  H;  nUT;   =(       a*    TU   R                   =(       a    TU   R                   (       + v •  M=     g 7fr'   )Ú
is_Integer)r:   r�   ÚfnowÚfwass     €€r-   r=   Ú collect_const.<locals>.<genexpr>Ó  sJ   øé € ð :Ú48¨qð  ™9÷ +¨¨a©×);Ñ);÷ +Ø˜Q™×*Ñ*ôA+ô +Ú48ùs   ƒAAr6   r   )Úsign)r�   rˆ   r‘   r   rl   r¼   rŠ   r   rb   rŽ   r   r   r   r
   ÚdivÚis_oneÚfactorsÚcopyrX   rB   Úas_exprr   rA   rÏ   rY   r   r	   )rT   rº   r¸   Úrecurser¤   rÂ   rž   rC   ÚFvÚfr½   Úrr‘   rÄ   Úunevalr�   rá   râ   s                   @@r-   r¿   r¿   v  s(  ù€ ð| �;�;Øˆà€GæØˆÜ‹uˆØ—”ˆAÜ—]’] 1Ö%�Ø—;—;‘;Ø—H‘H˜Q–Kó &ò ô
 �t‹}ˆÞÙÓ3š4�a§{¥{—™4ˆÐ3ä”˜“Ó€DÜˆÜœDÓ!ˆÜ�Q‹ZˆÜ—’˜tÖ$ˆAÜ˜“
ˆAØ—5‘5˜“9‰DˆAØ�x�xð
 —y‘y—~‘~Ó'�Ø—y‘y�Üõ :Ù48ó:÷ :ñ :à‘H—O‘O A§I¡I£KÔ0ÙØ”!—%‘%‰L×Ñ Ö"ñ %ð  ˆØˆØˆÜ˜–ˆAØ‘ˆAØ”A—E‘EŠzØ—‘˜A”Ùä�1‹v˜‹zÜ˜�G�Ø�Þ˜q›yØ—K‘K ”Nøà�a‘D�ö
 ˜1Ÿ;Ÿ;¨1¯8¯8Ø—‘œK¨°4Ñ8Ô9Ø’à—‘˜A™CÖ ñ+  ÷. ‰3ÞÜ'¨Ð.‘ä˜D�z�Ø—;—;’;Øà€Kñk ðj €Kùòq 4s   ÂKÂ.Kc                 óª  ^^^^^^^• SSK Jm  SSKJn  [	        S5      mU4S jmSU4S jjmUUUUUU4S jm[        U T5      (       d3  U R                  " U R                   Vs/ s H  n[        UTTS	9PM     sn6 $ U R                  5       u  pPU R                  5       n [        U 5      n[        T" U 5      5      u  pxXgU4:w  Gao  UR                  (       dx  Xx4n	U" USS
9nU" USS
9n[        [        USU-  5      5      n
[        U
R                  R!                  5        VVs/ s H	  u  p¼X¼-  PM     snn6 n
[        U
5      u  pxXgU4:X  a  U	u  px[#        U5      nUR$                  (       d  UR&                  (       a¹  [        [)        [        USU-  5      5      5      u  pÞUR$                  (       d"  UR+                  5       UR+                  5       ::  ac  XÞ4 Vs/ s H
  oó" U5      PM     snu  pxUR,                  (       a7  UR                  S   R$                  (       a  UR                  " UR                  6 nU[        USU-  5      -   $ s  snf s  snnf s  snf )a	  
Rationalize the denominator by removing square roots.

Explanation
===========

The expression returned from radsimp must be used with caution
since if the denominator contains symbols, it will be possible to make
substitutions that violate the assumptions of the simplification process:
that for a denominator matching a + b*sqrt(c), a != +/-b*sqrt(c). (If
there are no symbols, this assumptions is made valid by collecting terms
of sqrt(c) so the match variable ``a`` does not contain ``sqrt(c)``.) If
you do not want the simplification to occur for symbolic denominators, set
``symbolic`` to False.

If there are more than ``max_terms`` radical terms then the expression is
returned unchanged.

Examples
========

>>> from sympy import radsimp, sqrt, Symbol, pprint
>>> from sympy import factor_terms, fraction, signsimp
>>> from sympy.simplify.radsimp import collect_sqrt
>>> from sympy.abc import a, b, c

>>> radsimp(1/(2 + sqrt(2)))
(2 - sqrt(2))/2
>>> x,y = map(Symbol, 'xy')
>>> e = ((2 + 2*sqrt(2))*x + (2 + sqrt(8))*y)/(2 + sqrt(2))
>>> radsimp(e)
sqrt(2)*(x + y)

No simplification beyond removal of the gcd is done. One might
want to polish the result a little, however, by collecting
square root terms:

>>> r2 = sqrt(2)
>>> r5 = sqrt(5)
>>> ans = radsimp(1/(y*r2 + x*r2 + a*r5 + b*r5)); pprint(ans)
    ___       ___       ___       ___
  \/ 5 *a + \/ 5 *b - \/ 2 *x - \/ 2 *y
------------------------------------------
   2               2      2              2
5*a  + 10*a*b + 5*b  - 2*x  - 4*x*y - 2*y

>>> n, d = fraction(ans)
>>> pprint(factor_terms(signsimp(collect_sqrt(n))/d, radical=True))
        ___             ___
      \/ 5 *(a + b) - \/ 2 *(x + y)
------------------------------------------
   2               2      2              2
5*a  + 10*a*b + 5*b  - 2*x  - 4*x*y - 2*y

If radicals in the denominator cannot be removed or there is no denominator,
the original expression will be returned.

>>> radsimp(sqrt(2)*x + sqrt(2))
sqrt(2)*x + sqrt(2)

Results with symbols will not always be valid for all substitutions:

>>> eq = 1/(a + b*sqrt(c))
>>> eq.subs(a, b*sqrt(c))
1/(2*b*sqrt(c))
>>> radsimp(eq).subs(a, b*sqrt(c))
nan

If ``symbolic=False``, symbolic denominators will not be transformed (but
numeric denominators will still be processed):

>>> radsimp(eq, symbolic=False)
1/(a + b*sqrt(c))

r   )ÚExpr)Úsignsimpza:d A:Dc                 ó¸  >• Tu  pp4pVpx[        U 5      S:X  ag  [        [        [        XQXb/U  V	V
s/ s H  o™  H  oªPM     M     sn
n	5      5      5      n[	        U5      U-  [	        U5      U-  -
  R                  U5      $ [        U 5      S:X  a°  [        [        [        XQXbXs/U  V	V
s/ s H  o™  H  oªPM     M     sn
n	5      5      5      n[	        U5      U-  [	        U5      U-  -   [	        U5      U-  -
  S[	        U5      -  [	        U5      -  U-  U-  XQS-  -  -
  XbS-  -  -
  XsS-  -  -   -  R                  U5      $ [        U 5      S:X  GaÖ  [        [        [        XQXbXsX„/U  V	V
s/ s H  o™  H  oªPM     M     sn
n	5      5      5      n[	        U5      U-  [	        U5      U-  -   [	        U5      U-  -
  [	        U5      U-  -
  S[	        U5      -  [	        U5      -  U-  U-  XQS-  -  -
  XbS-  -  -
  S[	        U5      -  [	        U5      -  U-  U-  -
  XsS-  -  -   X„S-  -  -   -  S[	        U5      -  [	        U5      -  [	        U5      -  [	        U5      -  U-  U-  U-  U-  US-  US-  -  -   SU-  U-  US-  -  US-  -  -
  SU-  U-  US-  -  US-  -  -
  SU-  U-  US-  -  US-  -  -
  US-  US-  -  -   SU-  U-  US-  -  US-  -  -
  SU-  U-  US-  -  US-  -  -
  US-  US-  -  -   SU-  U-  US-  -  US-  -  -
  US-  US-  -  -   -  R                  U5      $ [        U 5      S:X  a  [	        U S   S   5      $ [        es  sn
n	f s  sn
n	f s  sn
n	f )Nr€   é   é   iøÿÿÿr6   r   )rY   r�   rŽ   r‚   r   r‡   rV   )Úrtermsr¤   r¥   rª   rÃ   rÓ   ÚBÚCÚDr;   rv   r›   r<   s               €r-   Ú_numÚradsimp.<locals>._numN  sÌ  ø€ ð "&Ñˆˆa�A˜!Üˆv‹;˜!ÓÜœœS !¨ ¹6Ô/Mº6°aË1Àa²É1±¹6Ò/MÓNÓOÓPˆDä�‹G�A‰Iœ˜Q› ™	Ñ!§8¡8¨D£>ð2äˆv‹;˜!ÓÜœœS !¨¨aÐ!3ÁÔ5SÂ¸AÓQRÈA²aÑQR±aÁÒ5SÓTÓUÓVˆDä�!‹W�Q‰Yœ˜a› ™Ñ"¤T¨!£W¨Q¡YÑ.°´4¸³7±¼4À»7Ñ1BÀ1Ñ1DÀQÑ1FÈÈaÉ4ÉÑ1OØ�‰d‰Fñ2Ø˜!‘t‘Vñ2ñ ß&™h t›nð-ô �‹[˜AÔÜœœS !¨¨a°AÐ!9ÁvÔ;YÂvÀ!ÓWXÐRSºAÑWX¹AÁvÒ;YÓZÓ[Ó\ˆDÜ˜!“W˜Q‘Y¤ a£¨¡Ñ*¬T°!«W°Q©YÑ6¼¸a»À¹ÑBÀQÄtÈAÃwÁYÌtÐTUËwÑEVÐWXÑEXÐYZÑEZØ�q‘D‘&ñFØ ™T™6ñF"Ø$%¤d¨1£g¡I¬d°1«gÑ$5°aÑ$7¸Ñ$9ñF:Ø<=À¹d¹FñFCà�Q‘$‘ñFñ àœD ›G™¤D¨£GÑ+¬D°«GÑ3´D¸³GÑ;¸AÑ=¸aÑ?ÀÑAÀ!ÑCÀaÈÁdÈ1ÈaÉ4ÁiÑOØ�!‘�A‘�a˜‘d‘
˜1˜a™4‘ñ Ø"# A¡# a¡%¨¨1©¡*¨Q°©T¡/ñ2Ø45°a±C¸±E¸!¸Q¹$±J¸qÀ!¹t±OñDØFGÈÁdÈ1ÈaÉ4ÁiñPà�!‘�A‘�a˜‘d‘
˜1˜a™4‘ñ à"# A¡# a¡%¨¨1©¡*¨Q°©T¡/ñ2à45°q±D¸¸A¹±Iñ>à@AÀ!ÁÀAÁÀaÈÁdÁ
È1ÈaÉ4ÁñPð �1‘�Q˜‘T‘	ññ÷
 %™H T›Nð+ô �‹[˜AÓÜ˜˜q™	 !™Ó%Ð%ä%Ð%ùó' 0Nùó 6Tùó
 <Zs   ¯M
Â&MÅ'MFc                 óŽ  >• U R                   (       d  gU R                  nUR                  (       a  UR                  S:X  d  T(       a  [	        U5      S:X  a  gU(       ag  SnUR                  (       a  UR                  nO%T(       a  [	        U5      n U R
                  (       a  U nUS:w  a  [        US5      R
                  (       a  gg)NFr€   Tr6   )r8   r   r_   r½   Údenomrà   r   )rÃ   Úlog2r°   r½   Úsymbolics       €r-   Úispow2Úradsimp.<locals>.ispow2h  s�   ø€ Ø�x�xØØ�E‰EˆØ�=�=˜QŸS™S A›X®´e¸A³hÀ!³mØÞØˆAØ�}�}Ø—C‘C‘ÞÜ˜!“H�Ø—<—<Ø�AØ�A‹vœ#˜a ›)×.×.ØØr0   c                 ó^  >• SSK Jn  U R                  (       a  U $ [        U T5      (       d0  U R                  " U R
                   Vs/ s H  nT" U5      PM     sn6 $ [        U 5      u  p4UR                  (       a  UR                  (       a  U $ UR                  (       dE  UR                  " UR
                   Vs/ s H  nT" U5      PM     sn6 n[        UT" SU-  5      5      $ U[        R                  La  [        UT" SU-  5      5      $ UR                  (       a,  [        UR
                   Vs/ s H  nT" SU-  5      PM     sn6 $ T(       d  UR                  (       a  U $ T" U5      (       aE  [        [        UR                  5      5      [        UR                   5      -  nXT:w  a  T" SU-  5      $ OiUR"                  (       aX  UR                   R$                  (       d  UR                  R&                  (       a"  T" SUR                  -  5      UR                   -  $ UR(                  (       d@  T" U5      (       d3  SUR                  " UR
                   Vs/ s H  nT" U5      PM     sn6 -  $ Sn[+        U5      nUR                  (       a  SU-  $ UR,                  (       a4  U" U5      nUR.                  (       a  UR1                  U5      (       a  SU-  $  [3        [4        5      n[6        R8                  " U5       H÷  n	/ n
/ n[:        R8                  " U	5       Hª  nT" USS9(       aV  U
R=                  UR                   [        R>                  L a  UR                  OUR                  SUR                   -  -  5        Me  U[        R@                  L a!  U
R=                  [        RB                  5        M™  UR=                  U5        M¬     U[E        [G        U
5      5         R=                  [;        U6 5        Mù     [5        [G        [5        URI                  5       5      5      5      nU VVs/ s H  u  pÎ[;        U6 [7        U6 4PM     nnn[K        U5      US   S   [        R                  L a  SOS-
  nUS:  a  GO UT:”  a  SnO÷[K        U5      S:”  as  [M        S	 U 5       5      (       aY  [O        [        R                  [6        RP                  " U VVs/ s H  u  nn[        U5      U-  PM     snn5      5      u  nnUU-  nOSnOuSS
K)J*nJ+n  U" T" U5      5      nUU-  nUU-  nU" [+        U5      TS9nURY                  [        RZ                  [\        [^        5      (       a  U $ UR                  (       a  OGM   U(       d  U $ [        USU-  5      $ s  snf s  snf s  snf s  snf s  snnf s  snnf )Nr   )Ú	nsimplifyr6   T)rý   r€   Frô   c              3   ój   #   • U  H)  u  pUR                   =(       a    US -  R                  v •  M+     g7f)r€   N)rà   r_   )r:   r,   Úys      r-   r=   Ú*radsimp.<locals>.handle.<locals>.<genexpr>Ñ  s(   é € ÐNÂv¹t¸q�q—|‘|×:¨¨A©×(:Ñ(:Ô:Âvùs   ‚13)ÚpowsimpÚ	powdenest)Úforce)0Úsympy.simplify.simplifyr  rµ   rW   r2   r‘   Úfractionr   r   rA   r`   Úfree_symbolsr"   r   r9   Únumerr   r8   Ú
is_integerÚis_positiver�   r   r¼   rb   Úequalsr   rŽ   r
   rl   r   rB   ÚHalfr¾   ÚNegativeOnerÁ   r   r†   rY   r�   Úrad_rationalizerÐ   Úsympy.simplify.powsimpr  r  r’   r”   r   r   )rT   r  r¤   ÚnrÃ   Úd2ÚkeepÚ_dr¨   rÂ   Úp2Úotherr;   rõ   rv   rÅ   r,   r  Úndr  r  Únumrð   rù   Úhandlerÿ   Ú	max_termsrþ   s                         €€€€€€r-   r  Úradsimp.<locals>.handlez  sS  ø€ õ 	6à�<�<ØˆKÜ˜D $×'Ñ'Ø—9’9°$·)²)Ó<²)¨Q™v ažy±)Ñ<Ð=Ð=ä˜‹~‰ˆà�9�9˜ŸŸØˆKØ——Ø—’¨A¯FªFÓ3ªF q™ ž©FÑ3Ð4ˆAÜ# A¡v¨a°©c£{Ó3Ð3Ø”a—e‘eŠ^Ü# A¡v¨a°©c£{Ó3Ð3Ø�X�XÜ#¸1¿6º6Ó%Bº6°a¡f¨Q¨q©S¦k¹6Ñ%BÐCÐCö ˜AŸNŸNØˆKá�!�9‰9ÜœD §¡›LÓ)¬5°·±«<Ñ7ˆBØ‹wÙ˜a ™d“|Ð#ð à�X�X˜1Ÿ5™5×+×+¨q¯v©v×/A×/Aá˜!˜AŸF™F™(Ó# Q§U¡UÑ*Ð*à——™F 1ŸI™IØ�Q—V’V°·²Ó8²¨A™f Qži±Ñ8Ð9Ñ9Ð9ð ˆô �Q‹Kˆð �9�9Ø�Q‘3ˆJð �;�;Ù˜1“ˆBØ�|�| §	¡	¨!§¡Ø˜‘t�àä#¤DÓ)ˆIÜ—]’] 1Ö%�Ø�Ø�ÜŸš qÖ)�AÙ˜a d×+ØŸ	™	¨A¯E©E´Q·V±VªO !§&¢&ÀÇÁÈ!ÈAÏEÉEÉ'ÑARÖSØœaŸo™oÒ-ØŸ	™	¤!§-¡-Ö0àŸ™ Qžñ *ð œ%¤¨£Ó,Ñ-×4Ñ4´S¸%°[ÖAñ &ô œ'¤$ y§¡Ó'8Ó"9Ó:Ó;ˆFÙ5;Ô<²V©T¨Q”s˜A�w¤ Q Ó(±VˆFÑ<Ü�v“; v¨a¡y°¡|´q·u±uÒ'<¡!À!ÑDˆDØ�a‹xÙØ˜	Ó!ð �ØÜ�6‹{˜Q‹ô ÑNÁvÓN×NÑNÜ+¬A¯E©E´3·>²>Ù/5Ô6ªv¡t q¨!œ˜a› œ©vÒ6ó48ó 9‘E�B˜à˜‘G‘Að !�DØßAá™$˜v›,Ó'ˆCØ�‰HˆAØ�‰HˆAÙœ( 1›+¨XÑ6ˆAØ�u‰u”Q—V‘VœS¤#×&Ñ&Ø�Ø�y�yØòa öd ØˆKÜ  1 Q¡3Ó'Ð'ùòG =ùò 4ùò
 &Cùò 9ùóF =ùó$ 7s$   ÁVÂ8VÄ/VÉV
Ð'V#ÓV))rþ   r  rÍ   r6   ©F)Úsympy.core.exprrð   r	  rñ   r   rW   r2   r‘   ÚradsimpÚas_coeff_AddÚnormalr
  rµ   r   r   rç   r†   r   rb   r�   r   Ú	count_opsr`   )rT   rþ   r  rñ   r¤   rg   Úoldr  rÃ   ÚwasÚur�   rž   Ún2r  r;   rð   rù   r  rÿ   r<   s    ``             @@@@@r-   r!  r!  þ  sä  þ€ õX %Ý0ä�9Ó€Dõ&÷4÷$l(ò l(ô\ �d˜D×!Ñ!Ø�yŠyÐW[×W`ÒW`ÓaÒW`ÐRSœ7 1¨xÀ9ÔMÑW`ÑaÐbÐbà×#Ñ#Ó%�K€EØ�;‰;‹=€DÜ
�4‹.€CÜ‘F˜4“LÓ!�D€AØ
�!ˆf„}Ø�y�yØ�&ˆCÙ˜ UÑ+ˆAÙ˜ UÑ+ˆAÜÔ(¨¨A¨a©CÓ0Ó1ˆAÜ °A·I±I·O±OÔ4EÔ"FÒ4E©D¨A 1¤4Ñ4EÒ"FÐGˆAÜ˜A“;‰DˆAØ˜!�f‹}Ø‘�Ü�q‹MˆØ�;�;˜!Ÿ(Ÿ(ÜœiÔ(8¸¸A¸a¹CÓ(@ÓAÓB‰FˆBØ�|�| §¡£°!·+±+³-Ó ?Ø.0©XÓ6ªX¨˜ ž©XÑ6‘�Ø—8—8 §¡ q¡	× 3× 3ØŸš §¡˜�AàÔ# A q¨¡sÓ+Ñ+Ð+ùò1 bùó #Gùò 7s   Á#IÄ I

ÇIc                 óÀ   • UR                   (       d  X4$ [        U5      u  p#nU[        U5      -  n[        X4-
  U -  5      n [        US-  US-  -
  5      n[	        X5      $ )a8  
Rationalize ``num/den`` by removing square roots in the denominator;
num and den are sum of terms whose squares are positive rationals.

Examples
========

>>> from sympy import sqrt
>>> from sympy.simplify.radsimp import rad_rationalize
>>> rad_rationalize(sqrt(3), 1 + sqrt(2)/3)
(-sqrt(3) + sqrt(6)/3, -7/9)
r€   )r�   Úsplit_surdsr   r   r  )r  Údenr¡   r¤   r¥   s        r-   r  r    s^   € ð �:�:ØˆxˆÜ˜#Ó�G€Aˆ!Ø	Œ$ˆq‹'‰	€AÜ
�A‘E˜3‘;Ó
€CÜ
�1�a‘4˜!˜Q™$‘;Ó
€CÜ˜3Ó$Ð$r0   c                 ó†  • [        U 5      n / / p2[        R                  " U 5       GHù  nUR                  (       Gag  UR                  (       d  [        U[        5      (       Ga@  UR                  5       u  pVUR                  (       a�  U[        R                  L a  UR                  U5        M†  U(       aE  UR                  5       (       a  UR                  [        XV* 5      5        M¿  UR                  U5        MÒ  UR                  [        XV* 5      5        Mï  UR                  (       a  UR                  U5        GM  U(       dN  UR                  (       a=  UR!                  5       u  pxUS:w  a  UR                  U5        UR                  U5        GMi  UR                  U5        GM}  UR"                  (       aZ  UR$                  (       dI  UR&                  S:w  a  UR                  UR&                  5        UR                  UR(                  5        GMè  UR                  U5        GMü     [        USU(       + 06[        USU(       + 064$ )aÏ  Returns a pair with expression's numerator and denominator.
If the given expression is not a fraction then this function
will return the tuple (expr, 1).

This function will not make any attempt to simplify nested
fractions or to do any term rewriting at all.

If only one of the numerator/denominator pair is needed then
use numer(expr) or denom(expr) functions respectively.

>>> from sympy import fraction, Rational, Symbol
>>> from sympy.abc import x, y

>>> fraction(x/y)
(x, y)
>>> fraction(x)
(x, 1)

>>> fraction(1/y**2)
(1, y**2)

>>> fraction(x*y/2)
(x*y, 2)
>>> fraction(Rational(1, 2))
(1, 2)

This function will also work fine with assumptions:

>>> k = Symbol('k', negative=True)
>>> fraction(x * y**k)
(x, y**(-k))

If we know nothing about sign of some exponent and ``exact``
flag is unset, then the exponent's structure will
be analyzed and pretty fraction will be returned:

>>> from sympy import exp, Mul
>>> fraction(2*x**(-y))
(2, x**y)

>>> fraction(exp(-x))
(1, exp(x))

>>> fraction(exp(-x), exact=True)
(exp(-x), 1)

The ``exact`` flag will also keep any unevaluated Muls from
being evaluated:

>>> u = Mul(2, x + 1, evaluate=False)
>>> fraction(u)
(2*x + 2, 1)
>>> fraction(u, exact=True)
(2*(x  + 1), 1)
r6   r3   )r   r   rl   r—   r8   rW   r   Úas_base_exprË   r   r  rB   Úis_constantr   r  r`   Úas_numer_denomr_   rà   Úpr½   )	rT   r4   r  rü   rE   r¥   Úexr  rÃ   s	            r-   r
  r
    st  € ôp �4‹=€Dà�rˆ5ä—’˜d×#ˆØ××Ð D§K§K´:¸dÄC×3HÒ3HØ×$Ñ$Ó&‰EˆAØ�~�~ØœŸ™Ò&Ø—L‘L –OÞØ—~‘~×'Ñ'ØŸ™¤S¨¨C£[Ö1àŸ™ TÖ*à—L‘L¤ Q¨£Ö-Ø——Ø—‘˜T×"Þ˜rŸyŸyØ×*Ñ*Ó,‘�Ø˜“6Ø—L‘L ”OØ—‘˜Q—à—‘˜T×"Ø×× d§o§oØ�v‰v˜‹{Ø—‘˜TŸV™VÔ$Ø�L‰L˜Ÿ™× à�L‰L˜×ñ7 $ô8 �Ð* E¤	Ñ*¬C°Ð,KÀUÄÑ,KÐKÐKr0   c                 ó   • [        XS9S   $ )N©r4   r   ©r
  ©rT   r4   s     r-   r  r  u  ó   € Ü�DÑ& qÑ)Ð)r0   c                 ó   • [        XS9S   $ )Nr3  r6   r4  r5  s     r-   rü   rü   y  r6  r0   c                 ó*   • U R                   " SSS0UD6$ )NÚfracTrP   )Úexpand)rT   Úhintss     r-   Úfraction_expandr<  }  s   € Ø�;Š;Ñ*˜DÐ* EÑ*Ð*r0   c                 óf   • [        XR                  SS5      S9u  p#UR                  " SSS0UD6U-  $ )Nr4   Fr3  r  TrP   ©r
  rƒ   r:  ©rT   r;  r¤   r¥   s       r-   Únumer_expandr@  �  s5   € ä�D§	¡	¨'°5Ó 9Ñ:�D€AØ�8Š8Ñ(˜$Ð( %Ñ(¨1Ñ,Ð,r0   c                 ód   • [        XR                  SS5      S9u  p#X#R                  " SSS0UD6-  $ )Nr4   Fr3  rü   TrP   r>  r?  s       r-   Údenom_expandrB  ‡  s3   € ä�D§	¡	¨'°5Ó 9Ñ:�D€AØ�xŠxÑ,˜dÐ, eÑ,Ñ,Ð,r0   c                 ó.  • [        U R                  [        S9nU Vs/ s H  o"R                  5       PM     nnU Vs/ s H   o"S   R                  (       d  M  US   S-  PM"     nnUR                  [        S9  [        U6 u  pVnUnU(       dK  [        U5      S:¼  a<  U Vs/ s H  o"U-  PM	     n	nU	 Vs/ s H  o"S:w  d  M
  UPM     n	n[        U	6 u  p©nXZ-  n/ / pËU HŽ  u  pÞUR                  (       ae  UR                  [        R                  :X  aG  UR                  nXö;   a!  UR                  U[        Xø-  5      -  5        Mf  UR                  XÞ-  5        M{  UR                  XÞ-  5        M�     [        U6 n[        U6 nUUU4$ s  snf s  snf s  snf s  snf )a�  
Split an expression with terms whose squares are positive rationals
into a sum of terms whose surds squared have gcd equal to g
and a sum of terms with surds squared prime with g.

Examples
========

>>> from sympy import sqrt
>>> from sympy.simplify.radsimp import split_surds
>>> split_surds(3*sqrt(3) + sqrt(5)/7 + sqrt(6) + sqrt(10) + sqrt(15))
(3, sqrt(2) + sqrt(5) + 3, sqrt(5)/7 + sqrt(10))
)r²   r6   r€   )Úsortedr‘   r   ra   r8   ÚsortÚ
_split_gcdrY   r   r   r  r9   rB   r   r
   )rT   r‘   r,   Ú
coeff_mulsÚsurdsr¡   Úb1Úb2Úg2Úb1nÚg1Úa1vÚa2vrª   rQ   Ús1r¤   r¥   s                     r-   r*  r*  ’  s[  € ô �$—)‘)Ô!1Ñ2€DÙ,0Ó1ªD q—.‘.Ö"©D€JÐ1Ù(Ó8šj˜¨a©D¯K­K‹WˆQˆq‰T�1ŒW™j€EÐ8Ø	‡J�JÔ#€JÑ$Ü˜EÐ"�I€Aˆ2Ø	
€BÞ”#�b“'˜Q“,ÙÓšB�q�Œs™BˆÐÙÓ(š#�Q a¡�q™#ˆÐ(ä  #Ð&‰ˆ�Ø‰TˆØ�2ˆÛ‰ˆØ�8�8˜Ÿ™¤§¡›Ø—‘ˆBØ‹xØ—
‘
˜1œT "¡%›[™=Ö)à—
‘
˜1™3–à�J‰J�q‘sŽOñ ô 	ˆSˆ	€AÜˆSˆ	€AØˆq�!ˆ8€Oùò/ 2ùÚ8ùò
  ùÚ(s"   �F¼FÁFÂFÂ3	FÃ Fc                  ó¤   • U S   nU/n/ nU SS  H:  n[        X5      nUS:X  a  UR                  U5        M'  UnUR                  U5        M<     XU4$ )a<  
Split the list of integers ``a`` into a list of integers, ``a1`` having
``g = gcd(a1)``, and a list ``a2`` whose elements are not divisible by
``g``.  Returns ``g, a1, a2``.

Examples
========

>>> from sympy.simplify.radsimp import _split_gcd
>>> _split_gcd(55, 35, 22, 14, 77, 10)
(5, [55, 35, 10], [22, 14, 77])
r   r6   N)r!   rB   )r¤   r¡   rI  rJ  r,   rM  s         r-   rF  rF  »  s`   € ð 	
ˆ!‰€AØ
ˆ€BØ	€BØˆqˆr‹UˆÜ�‹YˆØ�‹7Ø�I‰I�aŽLàˆAØ�I‰I�aŽLñ ð �"ˆ9Ðr0   )NNFTr'   )Trô   r  )DÚcollectionsr   Ú
sympy.corer   r   r   r   r   Úsympy.core.addr	   r
   Úsympy.core.assumptionsr   Úsympy.core.exprtoolsr   r   Úsympy.core.functionr   r   r   Úsympy.core.mulr   r   r   Úsympy.core.numbersr   r   r   Úsympy.core.parametersr   Úsympy.core.sortingr   r   Úsympy.core.symbolr   r   r   Úsympy.functionsr   r   r   Ú$sympy.functions.elementary.complexesr    Úsympy.polysr!   Úsympy.simplify.sqrtdenestr"   Úsympy.utilities.iterablesr#   r$   r„   r·   rÇ   rÝ   r¿   r!  r  r
  r  rü   r<  r@  rB  Úexpand_numerÚexpand_denomÚexpand_fractionr*  rF  rP   r0   r-   Ú<module>re     sµ   ðÝ #ç 7Õ 7ß 0Ý .ß 3ß GÑ Gß BÑ Bß 1Ñ 1Ý 3ß 8ß 2Ñ 2ß *Ñ *Ý 4Ý Ý 0ß 4ô
~òBô>Lò^.ðb (,õ EôPC,òL%ô,XLôv*ô*ò+ò-ò-ð €Ø€Ø!€ò&óRr0   