ó
    Š*£h‚h  ã                   ó  • 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JrJrJr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Jr  S S	KJr  S S
KJ r J!r!J"r"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)J*r*  S SK+J,r,  SSS\4S jr-SS jr.\" S5      r/S r0g)é    )Údefaultdict)Úreduce)Úprod)Ú
expand_logÚ	count_opsÚ_coeff_isneg)	ÚsympifyÚBasicÚDummyÚSÚAddÚMulÚPowÚ
expand_mulÚfactor_terms)ÚorderedÚdefault_sort_key)ÚIntegerÚRationalÚequal_valued)Ú_keep_coeff)Ú	Transform)Ú	exp_polarÚexpÚlogÚrootÚpolarifyÚ
unpolarify)ÚMatrixSymbol)ÚlcmÚgcd)ÚmultiplicityFÚallc                 óZ  ^^^^^7^8^9^:^;• UUUU4S jn[        U 5      n [        U [        5      (       a@  [        U [        5      (       d+  U R                  (       d  U [        S5      [        S5      4;   a  U $ T(       d6  U R                  (       d%  U R                  (       aC  [        U R                  ;  a/  U R                  " U R                   Vs/ s H
  oe" U5      PM     sn6 n U R                  (       a  U" U [        -  SS9[        -  $ U R                  (       d  U $ TS;   Gað  [        [        5      n/ n/ n	[        R                  n
U R                   GHO  nUR                   (       a  X«-  n
M  UR                  (       a  [#        U5      nUR$                  (       a‚  UR'                  5       u  pÍT(       a  XÍ4 Vs/ s H
  oå" U5      PM     snu  pÍUR                  (       d  [        U[(        5      (       a  XÍ-  [        R                  pÜX|   R+                  U5        MÊ  U(       am  US   R'                  5       u  nnUR'                  5       u  nnUU:X  a>  UR$                  (       a-  UR$                  (       a  [-        U[/        UU5      5      US'   GM>  UR+                  U5        GMR     [1        [3        UR5                  5       5      5       H²  u  pÍU(       aœ  UR                   (       a‹  [7        S U 5       5      (       dt  U
[        R                  Laa  U[        R                  [        R8                  4;  a=  [;        [=        U5      [=        U
5      5      nU(       a  UR+                  U5        X¬U-  -  n
[/        U6 X|'   M´     U
[        R                  La2  X§;   a  Xz==   [        R                  -  ss'   O[        R                  Xz'   [?        U5      n[        UR5                  5       5      n[A        5       nU Hò  u  pÍUU;   a  M  URB                  =(       d    URD                  nU(       d  M5  SU-  nURF                  (       a%  [I        US5      (       a  [        R                  X|'   Mp  UU:w  d  Mx  UU;   d  M€  URK                  5       S   [        R                  L a   URM                  U5        UU==   U-  ss'   MÄ  URO                  U5        URM                  U5      nX|==   U-  ss'   Mô     [        UR5                  5       5      n[        R8                  nU HÏ  u  pÍURP                  (       d  UR                  (       d  M)  U* U;   d  M2  XÇ;   d  M9  URB                  c  URR                  (       d  MY  URR                  (       d  URT                  (       a  X|* ==   URM                  U5      -  ss'   OURM                  U* 5      nX|==   U-  ss'   UU;   a  UU==   U-  ss'   MË  X×U'   MÑ     UR5                  5        VVs/ s H  u  pÍU(       d  M  XÍ4PM     nnnU94S	 jm;SU94S
 jjm9U8U9U:4S jn0 m:/ n/ m8U HX  u  pÍT9" XÍ5      u  pÍUT:;   a  T:U   U-   T:U'   OUT:U'   US   S:w  d  M1  US   R                  (       d  MG  T8R+                  U5        MZ     T8RW                  [X        S9  T8RW                  TSS9  T8 GH	  nUT:;  a  M  Uu  nnSnSn UnUn / n!/ n"[Z        R\                  " U5       HJ  n#T9" U#5      u  n$n%U$T:;  d	  T:U$   U%:  a  / =n"n!  O+U"R+                  U%T:U$   /5        U!R+                  U$5        ML     U"(       a¤  U"S   S   U"S   S   -  n&[_        S[a        U"5      5       H(  nU"U   S   U"U   S   -  n'U'S:  a    Ob[c        U&U'5      n&M*     [_        [a        U!5      5       H'  nT:U!U   ==   U&U"U   S   -  -  ss'   U" U!U   5        M)     T:U==   U&U -  U-  -  ss'   U(       d&  [a        T:5      S:X  d  [7        S T: 5       5      (       a  Oz[e        [Z        R\                  " U5       V#s/ s H  n#T;" U#5      PM     sn#5      nUS:X  a  O=UU-  nUU -  n[7        U;4S j[Z        R\                  " U5       5       5      (       a  SnGM¿  Uu  nn(UR+                  UT:RM                  U5      [g        SU(5      -  45        GM     UnT:R5                  5        H—  u  u  nn(nUR                  (       d  [        U[(        5      (       aJ  U([        R                  La7  UR(                  R                   (       d  UR'                  5       u  nnUUU(-  -  nO[i        UU(5      nUR+                  XÍ45        M™     [a        U5      n)[?        U5      n[a        U5      U):X  d   eU R                  " X—R5                  5        VVs/ s H  u  pÍ[-        XÍ5      PM     snn-   6 n	TS:X  a  U R                  X�R                  " U6 5      $ U" U R                  " U6 SS9U" U	SS9-  $ TS:X  Gac  / n/ nU R                   HO  nUR$                  (       a*  UR+                  [        UR'                  5       5      5        M>  UR+                  U5        MQ     [_        [a        U5      5       H¥  nX~   u  pÍ[7        S URK                  5        5       5      (       d+  URR                  (       d  T(       d  URD                  (       d  MY  URk                  SS9u  n*n+U*[        R                  Ld  M€  U+[        R                  Ld  M•  [-        UU*5      U+/X~'   M§     [        [        5      n,U H~  u  pÍT(       a  U" U5      nUR                  (       aE  URB                  (       d  URR                  (       a#  [m        U5      n[o        U5      (       a  U* nSU-  nU,U   R+                  U5        M€     A[        [        5      nU, GHM  nU,U   m8[a        T85      S:X  a  T8S   n-GOURR                  (       d  T(       a  U R                  " T86 n-GOñ/ n./ n// n0T8 H€  n#U#RT                  (       a  U0R+                  U#5        M'  U#Rp                  (       a  U/R+                  U#5        MK  U#RD                  (       a  U/R+                  U#5        Mo  U.R+                  U#5        M‚     [a        U.5      S:X  a  U0(       a  [a        U05      S:X  a   U.(       d  U/Rs                  U.U0-   5        / =n.n0O®U0(       a§  Sn1UR                   (       a  Sn1O7URK                  5       u  n2n3U2RR                  (       a  U3RR                  (       a  Sn1U1(       a?  U0 Vs/ s H  of* PM     n0nU.Rs                  [        R8                  /[a        U05      -  5        OU.Rs                  U05        / n0A1U. H  nX|   R+                  U5        M     U R                  " U/U0-   6 n-U74S jm7[u        U-SS9n4[a        [.        R\                  " U45      5      T7" U-5      :  a  [m        U45      n-UU-   R+                  U5        GMP     UR5                  5        VVV5s/ s H  u  pÍU  H  n5[-        UU55      PM     M     n6nnn5U R                  " U6U-   6 $ [w        S5      es  snf s  snf s  snnf s  sn#f s  snnf s  snf s  sn5nnf )a¹	  
Reduce expression by combining powers with similar bases and exponents.

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

If ``deep`` is ``True`` then powsimp() will also simplify arguments of
functions. By default ``deep`` is set to ``False``.

If ``force`` is ``True`` then bases will be combined without checking for
assumptions, e.g. sqrt(x)*sqrt(y) -> sqrt(x*y) which is not true
if x and y are both negative.

You can make powsimp() only combine bases or only combine exponents by
changing combine='base' or combine='exp'.  By default, combine='all',
which does both.  combine='base' will only combine::

     a   a          a                          2x      x
    x * y  =>  (x*y)   as well as things like 2   =>  4

and combine='exp' will only combine
::

     a   b      (a + b)
    x * x  =>  x

combine='exp' will strictly only combine exponents in the way that used
to be automatic.  Also use deep=True if you need the old behavior.

When combine='all', 'exp' is evaluated first.  Consider the first
example below for when there could be an ambiguity relating to this.
This is done so things like the second example can be completely
combined.  If you want 'base' combined first, do something like
powsimp(powsimp(expr, combine='base'), combine='exp').

Examples
========

>>> from sympy import powsimp, exp, log, symbols
>>> from sympy.abc import x, y, z, n
>>> powsimp(x**y*x**z*y**z, combine='all')
x**(y + z)*y**z
>>> powsimp(x**y*x**z*y**z, combine='exp')
x**(y + z)*y**z
>>> powsimp(x**y*x**z*y**z, combine='base', force=True)
x**y*(x*y)**z

>>> powsimp(x**z*x**y*n**z*n**y, combine='all', force=True)
(n*x)**(y + z)
>>> powsimp(x**z*x**y*n**z*n**y, combine='exp')
n**(y + z)*x**(y + z)
>>> powsimp(x**z*x**y*n**z*n**y, combine='base', force=True)
(n*x)**y*(n*x)**z

>>> x, y = symbols('x y', positive=True)
>>> powsimp(log(exp(x)*exp(y)))
log(exp(x)*exp(y))
>>> powsimp(log(exp(x)*exp(y)), deep=True)
x + y

Radicals with Mul bases will be combined if combine='exp'

>>> from sympy import sqrt
>>> x, y = symbols('x y')

Two radicals are automatically joined through Mul:

>>> a=sqrt(x*sqrt(y))
>>> a*a**3 == a**4
True

But if an integer power of that radical has been
autoexpanded then Mul does not join the resulting factors:

>>> a**4 # auto expands to a Mul, no longer a Pow
x**2*y
>>> _*a # so Mul doesn't combine them
x**2*y*sqrt(x*sqrt(y))
>>> powsimp(_) # but powsimp will
(x*sqrt(y))**(5/2)
>>> powsimp(x*y*a) # but won't when doing so would violate assumptions
x*y*sqrt(x*sqrt(y))

c                 ó®   >• UR                  ST5      nUR                  ST5      nUR                  ST5      nUR                  ST	5      n[        XX4U5      $ )NÚdeepÚcombineÚforceÚmeasure)ÚgetÚpowsimp)
ÚargÚkwargsÚ_deepÚ_combineÚ_forceÚ_measurer'   r&   r(   r)   s
         €€€€ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/simplify/powsimp.pyÚrecurseÚpowsimp.<locals>.recurseg   sR   ø€ Ø—
‘
˜6 4Ó(ˆØ—:‘:˜i¨Ó1ˆØ—‘˜G UÓ+ˆØ—:‘:˜i¨Ó1ˆÜ�s 8°XÓ>Ð>ó    r   é   F)r&   )r   r#   éÿÿÿÿc              3   ó8   #   • U  H  oR                   v •  M     g 7f©N)Ú	is_Number)Ú.0Úeis     r2   Ú	<genexpr>Úpowsimp.<locals>.<genexpr>¥   s   é € Ð/IÂqÀ·¶Âqùó   ‚c                 ó    >• T" U 5      S   S   $ )zLReturn Rational part of x's exponent as it appears in the bkey.
            r   r6   © )ÚxÚbkeys    €r2   ÚratqÚpowsimp.<locals>.ratqå   s   ø€ ñ ˜“7˜1‘:˜a‘=Ð r5   c                 ób  >• UGb  UR                   (       a  U [        R                  4U4$ UR                  (       a,  U [	        UR
                  5      4[	        UR                  5      4$ UR                  SS9u  p#U[        R                  Lan  UR                  (       a/  U [	        UR
                  5      4U[	        UR                  5      -  4$ X-  [	        UR
                  5      4[	        UR                  5      4$ X-  [        R                  4[        R                  4$ T" U R                  5       6 $ )zìReturn (b**s, c.q), c.p where e -> c*s. If e is not given then
it will be taken by using as_base_exp() on the input b.
e.g.
    x**3/2 -> (x, 2), 3
    x**y -> (x**y, 1), 1
    x**(2*y/3) -> (x**y, 3), 2
    exp(x/2) -> (exp(a), 2), 1

T©Úrational)
Ú
is_Integerr   ÚOneÚis_Rationalr   ÚqÚpÚas_coeff_MulÚ
is_integerÚas_base_exp)ÚbÚeÚcÚmrC   s       €r2   rC   Úpowsimp.<locals>.bkeyê   sÞ   ø€ ð Š}Ø—<—<ØœqŸu™u˜: q˜=Ð(Ø—]—]Øœw q§s¡s›|Ð,¬g°a·c±c«lÐ:Ð:àŸ>™>°4˜>Ð8‘D�AØ¤§¡’~ØŸ<Ÿ<Ø$%¤w¨q¯s©s£|Ð#4°a¼ÀÇÁ»±nÐ#DÐDØ !¡¤g¨a¯c©c£lÐ3´W¸Q¿S¹S³\ÐAÐAà !¡¤a§e¡e˜}¬a¯e©eÐ3Ð3á˜QŸ]™]›_Ð-Ð-r5   c                 ó2  >• [        TU    U S   5      u  pU(       d{  TR                  U 5        U(       ab  [        R                  " U S   U-  5       HA  nT" U5      u  pU T;  a  STU '   TU ==   U-  ss'   U S   S:w  d  M0  TR	                  U 5        MC     ggg)a  Decide what to do with base, b. If its exponent is now an
integer multiple of the Rational denominator, then remove it
and put the factors of its base in the common_b dictionary or
update the existing bases if necessary. If it has been zeroed
out, simply remove the base.
r6   r   N)ÚdivmodÚpopr   Ú	make_argsÚappend)rQ   ÚneweÚrrT   rR   ÚbasesrC   Úcommon_bs        €€€r2   ÚupdateÚpowsimp.<locals>.update  s‘   ø€ ô ˜X a™[¨!¨A©$Ó/‰GˆDÞØ—‘˜Q”ÞÜ Ÿ]š]¨1¨Q©4°©:Ö6˜Ù# A›w™˜Ø HÓ,Ø*+˜H Q™KØ  › qÑ(›Ø˜Q™4 1�9Ø!ŸL™L¨žOò 7ð ð r5   )ÚkeyT)ra   Úreversec              3   ó0   #   • U  H  oS    S :H  v •  M     g7f©r6   NrA   )r;   Úks     r2   r=   r>   O  s   é € Ð7ªh¨˜Q™4 1ž9ªhùs   ‚c              3   ó:   >#   • U  H  nT" U5      S :H  v •  M     g7frd   rA   )r;   ÚbirD   s     €r2   r=   r>   \  s   øé € Ð@Ò/?¨‘t˜B“x 1–}Ò/?ùs   ƒr   Úbase)r'   c              3   ó8   #   • U  H  oR                   v •  M     g 7fr9   )Úis_nonnegative)r;   rB   s     r2   r=   r>   Œ  s   é € ÐEÒ2D¨Q×(Ö(Ò2Dùr?   rG   c                 óê   >• U R                   (       a  [        U4S jU R                   5       5      $ U R                  (       a,  [	        U R                   Vs/ s H  nT" U5      PM     sn5      $ gs  snf )Nc              3   ó4   >#   • U  H  nT" U5      v •  M     g 7fr9   rA   )r;   ÚaiÚ_termss     €r2   r=   Ú*powsimp.<locals>._terms.<locals>.<genexpr>Ý  s   øé € Ð"?º°"¡6¨"§: :ºùs   ƒr6   )Úis_AddÚsumÚargsÚis_Mulr   )rR   Úmirn   s     €r2   rn   Úpowsimp.<locals>._termsÙ  sS   ø€ ð —x—xÜ"Ô"?¸¿ºÓ"?Ó?Ð?Ø—x—xÜ#¸!¿&º&Ó$Aº&°B¡V¨B¦Z¹&Ñ$AÓBÐBØùò %Bs   ÁA0z.combine must be one of ('all', 'exp', 'base').r9   )<r	   Ú
isinstancer
   r   Úis_Atomr   rp   rs   Ú_yrr   ÚfuncÚis_Powr   Úlistr   rJ   rK   Ú_denest_powÚis_commutativerP   r   rZ   r   r   r   ÚiterÚitemsr#   ÚNegativeOner"   ÚabsÚdictÚsetÚis_positiveÚis_polarÚis_Floatr   Úas_numer_denomrX   ÚaddÚ	is_SymbolrO   Úis_negativeÚsortr   r   rY   ÚrangeÚlenÚminr    r   r   rN   r   r   rj   Úextendr   Ú
ValueError)<Úexprr&   r'   r(   r)   r3   ÚwÚc_powersÚnc_partÚnewexprÚcoeffÚtermrQ   rR   ÚiÚb1Úe1Úb2Úe2rT   ÚbeÚskipÚbposÚbinvÚ_nr_   Údonerh   ÚexponentÚlastÚqlcmÚbstartÚqstartÚbbÚeerg   ÚbibÚbieÚmin1ÚratrL   ÚcheckÚexp_cÚexp_tÚc_expÚnew_baseÚunkÚnonnegÚnegÚisratrM   ÚdÚ	xnew_baser<   Úc_partrn   r]   rC   r^   rD   s<    ````                                                  @@@@@r2   r+   r+      sâ  ÿø€ ÷j?ð ?ô �4‹=€Dä�tœU×#Ñ#¤z°$¼×'EÑ'EØ�L�L˜D¤Y¨q£\´9¸Q³<Ð$@Ó@Øˆæˆt�{�{˜dŸkŸk¬b¸¿	¹	Ó.AØ�yŠy¨t¯yªyÓ9ªy¨!˜7 1ž:©yÑ9Ð:ˆà‡{‡{Ù�tœB‘w UÑ+¬BÑ.Ð.à�;�;Øˆð �.Ô ô œtÓ$ˆØˆØˆÜ—‘ˆØ—I•IˆDØ××Ø‘�ÙØ�{�{Ü" 4Ó(�Ø×"×"Ø×'Ñ'Ó)‘�ÞØ12±Ó7²¨1˜G AžJ±Ñ7‘D�AØ—8—8œz¨!¬S×1Ñ1ð ™4¤§¡�qØ‘×"Ñ" 1Ö%ö Ø$ R™[×4Ñ4Ó6‘F�B˜Ø!×-Ñ-Ó/‘F�B˜Ø˜b›Ø×-×-°"×2C×2CÜ&)¨"¬c°"°b«kÓ&:˜ ™Ú Ø—‘˜t×$ñ3 ô8 œD §¡Ó!1Ó2Ö3‰DˆAö �a—m—m¬CÑ/IÁqÓ/I×,IÑ,IØ¤§¡Ò&ØœaŸe™e¤Q§]¡]Ð3Ó3Ü ¤ Q£¬¨U«Ó4�ÞØ—H‘H˜Q”KØ ™T‘M�EÜ˜q˜'ˆH‹Kñ 4ð œŸ™ÒØÓ Ø“¤1§5¡5Ñ(”ä"#§%¡%�‘ô ˜“>ˆô �(—.‘.Ó"Ó#ˆÜ‹uˆÛ‰DˆAØ�D‹yÙØ—=‘=×. A§J¡JˆDßˆtØ˜‘s�à—:—:¤,¨q°!×"4Ñ"4Ü"#§%¡%�H‘KÙØ˜•9 ¨Õ!1Ø×'Ñ'Ó)¨!Ñ,´·±Ò5Ø Ÿ™ QœØ  ›¨!Ñ+�àŸ™ œØ$ŸL™L¨Ó.˜Ø › qÑ(�ñ# ô( �(—.‘.Ó"Ó#ˆÜ�]‰]ˆÛ‰DˆAØ——˜qŸxŸx™x¨a¨R°8­^ÀÅØ—M‘MÑ-°··±Ø—|—| q§}§}Ø  ›¨¯©°Q«Ñ7œà$ŸL™L¨!¨Ó,˜Ø › qÑ(›Ø˜X“~Ø  ›¨Ñ)�à'( ›ñ ð (0§~¡~Ô'7Ô=Ò'7™t˜q¼1“F�Q“FÑ'7ˆÑ=õ	!÷
	.÷4	,ð* ˆØˆØˆÛ‰DˆAÙ˜“:‰DˆAØ�H‹}Ø& q™k¨A™o�˜’à�˜‘Ø�‰t�q�y˜Q˜q™TŸ[Ÿ[™[Ø—‘˜Q–ñ ð 	�
‰
Ô'ˆ
Ñ(Ø�
‰
�w¨ˆ
Ñ-ÜˆDØ˜8Ó#ÙØ‰KˆAˆxØˆDØˆDØØ�Ø�à�Ø�ÜŸ-š-¨Ö*�BÙ# B›x‘H�C˜Ø (Ó*¨h°s©m¸cÓ.AØ"$˜˜˜RÙØ—I‘I˜s H¨S¡MÐ2Ô3Ø—I‘I˜c–Nñ +ö ð ˜a™5 ™8 R¨¡U¨1¡XÑ-�DÜ" 1¤c¨"£gÖ.˜Ø  ™e A™h¨¨1©¨a©Ñ0˜Ø ›7Ù!Ü" 4¨›~šñ	 /ô "'¤s¨2£w¦˜AØ$ R¨¡U›O¨t°B°q±E¸!±H©}Ñ<›OÙ" 2 a¡5žMñ "0ð ! ›¨$¨v©+°hÑ*>Ñ>›ÞÜ˜8“}¨Ó)ÜÑ7©hÓ7×7Ñ7àô ¬s¯}ª}¸VÔ/DÓEÒ/D¨™D žHÑ/DÑEÓF�Ø˜1“9ØØ˜D‘L�Ø˜‘�ÜÔ@¬s¯}ª}¸QÔ/?Ó@×@Ñ@Ø�Dòc ðh ‰DˆAˆqØ�K‰K˜˜HŸL™L¨Ó.¬x¸¸1«~Ñ=Ð>×?ñw ð| ˆð "Ÿ™Ö)‰I‰FˆQ��AØ——œJ q¬#×.Ñ.ØœQŸU™U’N¨1¯5©5×+<×+<ØŸ™›‘��2Ø˜˜1™‘I‘ä˜˜A“J�Ø�O‰O˜Q˜FÖ#ñ *ô �H“ˆÜ˜“>ˆÜ�8‹} Ó%Ð%Ð%ð —)’)˜g¿~¹~Ô?OÔ(PÒ?O±t°q¬¨Q®Ñ?OÒ(PÑPÐRˆØ�eÓØ—9‘9˜W§i¢i°Ð&9Ó:Ð:á˜4Ÿ9š9 gÐ.¸Ñ?Ù˜¨Ñ0ñ1ð 1ð 
�FÔ	ð ˆØˆØ—I”IˆDØ×"×"Ø—‘¤ T×%5Ñ%5Ó%7Ó 8Ö9à—‘˜tÖ$ñ	 ô ”s˜8“}Ö%ˆAØ‘;‰DˆAÜÑE°!×2BÑ2BÔ2DÓE×EÑEÈÏÏÖY^Ðbc×bl×blÙØŸ>™>°4˜>Ð8‰LˆE�5ØœAŸE™EÔ! e´1·5±5Ô&8Ü" 1 e›}¨eÐ4�“ñ &ô œDÓ!ˆÛ‰DˆAÞÙ˜A“J�Ø�x�x˜QŸ]Ÿ]¨a¯l¯lÜ  “O�Ü —?‘?Ø˜�AØ˜!™�AØ�!‰H�O‰O˜AÖñ ð ô œtÓ$ˆÜˆAØ˜!‘HˆEô �5‹z˜Q‹Ø  ™8’Ø——¦ØŸ9š9 eÐ,’ð �Ø�Ø�Û�BØ—~—~ØŸ
™
 2žØ×*×*ØŸ™ bÖ)ØŸŸØŸ™Øö ð Ÿ
™
 2žñ  ô �s“8˜q“=®´°C³¸A³Æcà—M‘M #¨¡)Ô,Ø "�N�C™#Þð "�EØ—}—}Ø $™à ×/Ñ/Ó1™˜˜1ØŸ<Ÿ<¨A¯L¯LØ$(˜EÞÙ+.Ó/ª3 a›r©3˜Ð/ØŸ
™
¤A§M¡M ?´3°s³8Ñ#;Õ<àŸ
™
 3œØ ˜Øó �AØ‘K×&Ñ& qÖ)ñ ð  Ÿ9š9 v°¡|Ð5�õô ' x°eÑ<�	Ü”s—}’} YÓ/Ó0±6¸(Ó3CÓCÜ+¨IÓ6�Hà�XÑ×%Ñ% a×(ñE ðJ *2¯©Ô)9ÕFÒ)9¡ ÄA¸b”#�a˜–*ÁA‘*Ñ)9ˆÒFð �yŠy˜6 GÑ+Ð-Ð-ô ÐIÓJÐJùòs :ùò2 8ùó^ >ùòt Fùó< )Qùòj 0ùô< Gs0   ÃzÆ6z×8zØ	zà*z
æ3zõz!ù"z&c           	      ó>  ^
• SSK Jn  U(       a¶  U
4S jm
/ nU R                  [        [        5       HT  n[        UR                  [        [        45      (       d  M*  T
" UR                  6 u  pgUSLd  MB  UR                  XW45        MV     U(       a  U R                  U5      n U" U 5      u  p[        U SUS9R                  U5      $ U(       a*  [        U 5      u  p[        [        [        U SS95      U5      $ [        U 5      n	U	R                  [        [         S S	95      $ )
a±	  
Collect exponents on powers as assumptions allow.

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

Given ``(bb**be)**e``, this can be simplified as follows:
    * if ``bb`` is positive, or
    * ``e`` is an integer, or
    * ``|be| < 1`` then this simplifies to ``bb**(be*e)``

Given a product of powers raised to a power, ``(bb1**be1 *
bb2**be2...)**e``, simplification can be done as follows:

- if e is positive, the gcd of all bei can be joined with e;
- all non-negative bb can be separated from those that are negative
  and their gcd can be joined with e; autosimplification already
  handles this separation.
- integer factors from powers that have integers in the denominator
  of the exponent can be removed from any term and the gcd of such
  integers can be joined with e

Setting ``force`` to ``True`` will make symbols that are not explicitly
negative behave as though they are positive, resulting in more
denesting.

Setting ``polar`` to ``True`` will do simplifications on the Riemann surface of
the logarithm, also resulting in more denestings.

When there are sums of logs in exp() then a product of powers may be
obtained e.g. ``exp(3*(log(a) + 2*log(b)))`` - > ``a**3*b**6``.

Examples
========

>>> from sympy.abc import a, b, x, y, z
>>> from sympy import Symbol, exp, log, sqrt, symbols, powdenest

>>> powdenest((x**(2*a/3))**(3*x))
(x**(2*a/3))**(3*x)
>>> powdenest(exp(3*x*log(2)))
2**(3*x)

Assumptions may prevent expansion:

>>> powdenest(sqrt(x**2))
sqrt(x**2)

>>> p = symbols('p', positive=True)
>>> powdenest(sqrt(p**2))
p

No other expansion is done.

>>> i, j = symbols('i,j', integer=True)
>>> powdenest((x**x)**(i + j)) # -X-> (x**x)**i*(x**x)**j
x**(x*(i + j))

But exp() will be denested by moving all non-log terms outside of
the function; this may result in the collapsing of the exp to a power
with a different base:

>>> powdenest(exp(3*y*log(x)))
x**(3*y)
>>> powdenest(exp(y*(log(a) + log(b))))
(a*b)**y
>>> powdenest(exp(3*(log(a) + log(b))))
a**3*b**3

If assumptions allow, symbols can also be moved to the outermost exponent:

>>> i = Symbol('i', integer=True)
>>> powdenest(((x**(2*i))**(3*y))**x)
((x**(2*i))**(3*y))**x
>>> powdenest(((x**(2*i))**(3*y))**x, force=True)
x**(6*i*x*y)

>>> powdenest(((x**(2*a/3))**(3*y/i))**x)
((x**(2*a/3))**(3*y/i))**x
>>> powdenest((x**(2*i)*y**(4*i))**z, force=True)
(x*y**2)**(2*i*z)

>>> n = Symbol('n', negative=True)

>>> powdenest((x**i)**y, force=True)
x**(i*y)
>>> powdenest((n**i)**x, force=True)
(n**i)**x

r   )Úposifyc                 ó¦   >• [        U [        [        45      (       d  U R                  [        XSS94$ T" U R                  U R                  U-  5      $ )NF)Úevaluate)rv   r   r   r„   rh   )rQ   rR   Ú_denests     €r2   r¾   Úpowdenest.<locals>._denestO  sC   ø€ Ü˜a¤#¤s ×,Ñ,Ø—}‘}¤c¨!¸Ñ&?Ð?Ð?Ù˜1Ÿ6™6 1§5¡5¨¡7Ó+Ð+r5   F)r(   ÚpolarT)Úexponents_onlyc                 óH   • U R                   =(       d    [        U [        5      $ r9   )rz   rv   r   )rT   s    r2   Ú<lambda>Úpowdenest.<locals>.<lambda>d  s   €  a§h¡h×&D´*¸QÄÓ2DÐ&Dr5   )Úfilter)Úsympy.simplify.simplifyr»   Úatomsr   r   rv   rh   rr   rZ   ÚsubsÚ	powdenestÚxreplacer   r   r+   r   r|   )Úeqr(   rÀ   r»   ÚrepsrM   ÚokÚdpÚrepÚnewr¾   s             @r2   rÉ   rÉ   ñ  sï   ø€ õv /æõ	,ð ˆØ—‘œ#œsÖ#ˆAÜ˜!Ÿ&™&¤3¬ *×-Ó-Ù  !§&¡&Ð)‘�Ø˜U”?Ø—K‘K  Ö(ñ	 $ö
 Ø—‘˜“ˆBÙ˜"“:‰ˆÜ˜ 5°Ñ6×?Ñ?ÀÓEÐEæÜ˜2“,‰ˆÜœ)¤J¨rÀ$Ñ$GÓHÈ#ÓNÐNä
�"‹+€CØ�<‰<œ	ÜÑDñFó Gð Gr5   Úyc                 óÚ	  • SSK Jn  U R                  5       u  p#UR                  (       d  [	        U[
        5      (       a.  US:w  a(  UR                  U5      nUb  Un UR                  5       u  p#U[        R                  L a   UR                  (       a�  / n/ nUR                   HR  n[        S [        R                  " U5       5       5      (       a  UR                  U5        MA  UR                  U5        MT     U" [        U6 5      n[!        [        U5      [        U6 5      $ UR                  5       u  p‰U	[        R"                  L aE  UR                  (       d4  UR$                  (       a  UR&                  S:w  d  UR(                  (       d  U $ / / pº[        R                  " U5       HF  nUR*                  (       a!  U
R                  UR                  5       5        M5  UR                  U5        MH     [-        U
5      S:X  aG  U
S   S   R                  (       d0  [!        U
S   S   U
S   S   U-  5      [/        [        U6 U-  5      -  $ U
(       a@  [        U
 VVs/ s H  u  pÍ[/        XÍU-  -  5      PM     snn6 [/        [        U6 U-  5      -  $ UR0                  (       aR  [3        [5        U5      5      nUR                  (       a-  UR                  u  pþX?-  nUR                  S   n[!        UU5      $ UR                  (       a+  [        S [        R                  " U5       5       5      (       a  U $ S n[3        [5        U5      5      nUR6                  (       aZ  UR                  n[9        UU5      nUS:w  a<  UR;                  5       u  nn[=        UU[        U Vs/ s H  nUU-  PM
     sn6 -  5      n[	        U[4        5      (       d  UR                  (       d™  UR                  S   R                  (       d"  [	        UR                  S   [
        5      (       aW  [?        UR                  S   5      n[A        UR
                  5      S:  S:X  a#  [!        URB                  UR
                  U-  5      $ U $ / n/ nUR                   H8  nUR6                  (       a  UR                  U5        M'  UR                  U5        M:     [!        [        U" [        U6 5      5      U[        U6 -  5      $ s  snnf s  snf )zb
Denest powers.

This is a helper function for powdenest that performs the actual
transformation.
r   )Ú
logcombiner6   c              3   óB   #   • U  H  n[        U[        5      v •  M     g 7fr9   )rv   r   )r;   rm   s     r2   r=   Ú_denest_pow.<locals>.<genexpr>~  s   é € ÐCÒ1B¨2”:˜b¤#×&Ð&Ò1Bùs   ‚c              3   ó8   #   • U  H  oR                   v •  M     g 7fr9   )rw   )r;   Úss     r2   r=   rÕ   ¥  s   é € Ð?Ò.>¨Ÿ9ž9Ò.>ùr?   c                 ó  • X4 Vs/ s H  o"R                  5       PM     snu  p4[        US   US   5      R                  5       S   n[        US   R	                  SS9S   US   R	                  SS9S   -  6 n[        XV5      $ s  snf )Nr   r6   T)Úcset)rN   r!   r‡   r   Úargs_cncr   )Úaar¨   r˜   ÚarQ   rS   Úgs          r2   Únc_gcdÚ_denest_pow.<locals>.nc_gcd°  s‡   € Ø+-©(Ó3ª( Q—‘Ö ©(Ñ3‰ˆÜ��!‘�a˜‘d‹O×*Ñ*Ó,¨QÑ/ˆÜ�!�A‘$—-‘- T�-Ð*¨1Ñ-°°!±·±À4°Ð0HÈÑ0KÑKÐMˆÜ˜1Ó Ð ùò 4s   †BT)"rÆ   rÓ   rP   rz   rv   r   Ú_eval_powerr   ÚExp1rs   rr   Úanyr   rY   rZ   r   r   rJ   rK   rL   r„   r…   r�   rÉ   rI   r   r   rp   r   rN   r   r|   r�   rh   )rË   rÓ   rQ   rR   rÐ   ÚlogsÚotherr<   Ú_r�   ÚpolarsÚ	nonpolarsr¨   r©   ÚlogbrS   rh   rÞ   Úglogbrr   rÝ   ÚcgÚrgrÜ   rˆ   s                            r2   r|   r|   i  s²  € õ 3à�>‰>Ó�D€AØ‡x‡x”:˜a¤×%Ñ%¨!¨q«&Ø�m‰m˜AÓˆØ‰?ØˆBØ—?‘?Ó$‰DˆAð 	ŒA�F‰F‚{�q—x—xØˆØˆØ—&”&ˆBÜÑC´·²¸rÔ1BÓC×CÑCØ—‘˜B–à—‘˜RÖ ñ	 ñ
 œ#˜t˜*Ó%ˆÜ”3�t“9œc 5˜kÓ*Ð*à�M‰M‹O�E€AØ	ŒQ�U‰U‚{˜AŸHŸHØŸMŸM¨a¯c©c°Q«hØŸMŸMØˆ	ð ˜BˆIÜ�mŠm˜AÖˆØ�;�;Ø�M‰M˜"Ÿ.™.Ó*Ö+à×Ñ˜RÖ ñ	 ô
 ˆ6ƒ{�aÓ  q¡	¨!¡× 3× 3Ü�6˜!‘9˜Q‘< ¨¡¨1¡¨a¡Ó0´¼3À	¸?ÈAÑ;MÓ1NÑNÐNÞ	Ü¹6ÔBº6©x°”Y˜r q¡D™zÖ*¹6ÒBÐCÜ”s˜I�¨Ñ)Ó*ñ+ð 	+ð 	‡|‡|äœ#˜a›&Ó!ˆØ�;�;Ø—i‘i‰GˆAØ‰FˆAØ—9‘9˜Q‘<ˆDÜ�t˜Q“<Ðð �8�8”sÑ?¬c¯mªm¸AÔ.>Ó?×?Ñ?Øˆ	ò!ô ”s˜1“vÓ€EØ‡|‡|Ø�z‰zˆÜ�6˜4Ó ˆØ�‹6Ø—^‘^Ó%‰FˆB�Ü  B¤s¹$Ó,?º$°Q¨Q¨q¬S¹$Ñ,?Ð'@Ñ$@ÓAˆEô �%œ×Ñ U§\§\Ø�:‰:�a‰=××¤:¨e¯j©j¸©m¼S×#AÑ#AÜ §
¡
¨1¡Ó.ˆEÜ�E—I‘I“ Ñ" tÓ+Ü˜5Ÿ:™: u§y¡y°¡{Ó3Ð3Øˆ	ð €CØ€EØ�ZŒZˆØ�8�8Ø�J‰J�qŽMà�L‰L˜ŽOñ	 ô
 Œs‘:œc 3˜iÓ(Ó)¨1¬S°%¨[©=Ó9Ð9ùóm CùòH -@s   ÉS"
ÎS(N)FF)1Úcollectionsr   Ú	functoolsr   Úmathr   Úsympy.core.functionr   r   r   Ú
sympy.corer	   r
   r   r   r   r   r   r   r   Úsympy.core.sortingr   r   Úsympy.core.numbersr   r   r   Úsympy.core.mulr   Úsympy.core.rulesr   Úsympy.functionsr   r   r   r   r   r   Ú"sympy.matrices.expressions.matexprr   Úsympy.polysr    r!   Úsympy.ntheory.factor_r"   r+   rÉ   rx   r|   rA   r5   r2   Ú<module>rù      sg   ðÝ #Ý Ý ç CÑ Cß X× XÕ Xß 8ß >Ñ >Ý &Ý &ß K× KÝ ;ß  Ý .ð  e°5À)ô \Kô~sGñj ˆ3ƒZ€óe:r5   