ó
    Š*£h ó  ã                   ó&  • S SK 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  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  S SK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'J(r(  S SK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1  S SK2J3r3  S SK4J5r5  S SK6J7r7  S SK8J9r9J:r:  S SK;J<r<  S r=S r>S r?S@S jr@S rAS rBS rCSAS jrDSAS jrES  rFSBS! jrGS" rHSBS# jrIS$ rJSCS& jrKS' rLSBS( jrMS) rNS* rOS+ rPSBS, jrQSAS- jrRSAS. jrSS/ rTSAS0 jrUS1 rVS2 rW\<(       a<  \X" \Y" \:\=\>\?\A\B\D\E\F\G\H\I\K\M\O\@\P\Q\R\S\N\T\U45      5      u  r=r>r?rArBrDrErFrGrHrIrKrMrOr@rPrQrRrSrNrTrU\D\=4\E\=4\9/rZ\K\D\=4\E\=4\=/4r[\P\G\=4\P\G\J\=4\9/r\\B\J4\9/r]\B\A\B\M\B\O\B\=4r^\B\A\I\B\A\K4\D\F\K\B4\\\Z\H\[\B\H\H\]4\9/r_S3 4S4 jr`SDS5 jraS6RÅ                  5       rc\d" \X" \e" \c\X" \Y" \f" 5       RÎ                  \c5      5      5      5      5      rh\S7 5       ri\S8 5       rj\S9 5       rkS@S: jrlS; rmS< rnS= roS> rpS? rqg%)Eé    )Údefaultdict)ÚAdd)Úcacheit)ÚExpr)ÚFactorsÚ	gcd_termsÚfactor_terms)Ú
expand_mul)ÚMul)ÚpiÚI)ÚPow)ÚS)Úordered)ÚDummy)Úsympify©Ú	bottom_up)Úbinomial)ÚcoshÚsinhÚtanhÚcothÚsechÚcschÚHyperbolicFunction)ÚcosÚsinÚtanÚcotÚsecÚcscÚsqrtÚTrigonometricFunction)Úperfect_power)Úfactor)Úgreedy)ÚidentityÚdebug)ÚSYMPY_DEBUGc                 óZ   • U R                  5       R                  5       R                  5       $ )zwSimplification of rational polynomials, trying to simplify
the expression, e.g. combine things like 3*x + 2*x, etc....
)Únormalr&   Úexpand©Úrvs    ÚN/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/simplify/fu.pyÚTR0r1       s"   € ð �9‰9‹;×ÑÓ×&Ñ&Ó(Ð(ó    c                 ó   • S n[        X5      $ )z²Replace sec, csc with 1/cos, 1/sin

Examples
========

>>> from sympy.simplify.fu import TR1, sec, csc
>>> from sympy.abc import x
>>> TR1(2*csc(x) + sec(x))
1/cos(x) + 2/sin(x)
c                 ó  • [        U [        5      (       a+  U R                  S   n[        R                  [        U5      -  $ [        U [        5      (       a+  U R                  S   n[        R                  [        U5      -  $ U $ ©Nr   )Ú
isinstancer!   Úargsr   ÚOner   r"   r   ©r/   Úas     r0   ÚfÚTR1.<locals>.f5   s_   € Ü�bœ#×ÑØ—‘˜‘
ˆAÜ—5‘5œ˜Q›‘<ÐÜ˜œC× Ñ Ø—‘˜‘
ˆAÜ—5‘5œ˜Q›‘<ÐØˆ	r2   r   ©r/   r;   s     r0   ÚTR1r>   )   s   € òô �RÓÐr2   c                 ó   • S n[        X5      $ )a  Replace tan and cot with sin/cos and cos/sin

Examples
========

>>> from sympy.simplify.fu import TR2
>>> from sympy.abc import x
>>> from sympy import tan, cot, sin, cos
>>> TR2(tan(x))
sin(x)/cos(x)
>>> TR2(cot(x))
cos(x)/sin(x)
>>> TR2(tan(tan(x) - sin(x)/cos(x)))
0

c                 óò   • [        U [        5      (       a&  U R                  S   n[        U5      [	        U5      -  $ [        U [
        5      (       a&  U R                  S   n[	        U5      [        U5      -  $ U $ r5   )r6   r   r7   r   r   r    r9   s     r0   r;   ÚTR2.<locals>.fS   s_   € Ü�bœ#×ÑØ—‘˜‘
ˆAÜ�q“6œ#˜a›&‘=Ð Ü˜œC× Ñ Ø—‘˜‘
ˆAÜ�q“6œ#˜a›&‘=Ð Øˆ	r2   r   r=   s     r0   ÚTR2rB   A   s   € ò$ô �RÓÐr2   c                 ó&   ^• U4S jn[        X5      $ )ay  Converts ratios involving sin and cos as follows::
    sin(x)/cos(x) -> tan(x)
    sin(x)/(cos(x) + 1) -> tan(x/2) if half=True

Examples
========

>>> from sympy.simplify.fu import TR2i
>>> from sympy.abc import x, a
>>> from sympy import sin, cos
>>> TR2i(sin(x)/cos(x))
tan(x)

Powers of the numerator and denominator are also recognized

>>> TR2i(sin(x)**2/(cos(x) + 1)**2, half=True)
tan(x/2)**2

The transformation does not take place unless assumptions allow
(i.e. the base must be positive or the exponent must be an integer
for both numerator and denominator)

>>> TR2i(sin(x)**a/(cos(x) + 1)**a)
sin(x)**a/(cos(x) + 1)**a

c           
      ó¸  >^• U R                   (       d  U $ U R                  5       u  pUR                  (       d  UR                  (       a  U $ U4S jmUR                  5       n[	        UR                  5       5       Vs/ s H'  nT" X1U   5      (       a  M  X1R                  U5      4PM)     nnU(       d  U $ UR                  5       n[	        UR                  5       5       Vs/ s H'  nT" X2U   5      (       a  M  X2R                  U5      4PM)     nnU(       d  U $ UU4S jnU" X5        U" X%5        / nU GHF  n[        U[        5      (       a¶  [        UR                  S   SS9nX‚;   a@  X(   X   :X  a6  UR                  [        UR                  S   5      X   -  5        S =X'   X('   Mu  T(       aQ  SU-   n	X’;   aE  X)   X   :X  a9  UR                  [        UR                  S   S-  5      X   -  5        S =X'   X)'   MÉ  MË  MÍ  MÏ  [        U[        5      (       ad  [        UR                  S   SS9nX‚;   aE  X(   X   :X  a8  UR                  [        UR                  S   5      X   * -  5        S =X'   X('   GMB  GME  GMH  T(       d  GMR  UR                  (       d  GMf  UR                  S   [        R                  L d  GM‰  [        UR                  S   [        5      (       d  GM®  [        UR                  S   R                  S   SS9nX‚;   d  GMÚ  X(   X   :X  d  GMç  X(   R                   (       d  UR"                  (       d  GM  UR                  [        UR                  S   S-  5      X   * -  5        S =X'   X('   GMI     U(       a±  [%        XqR'                  5        V
Vs/ s H  u  p«U(       d  M  X«-  PM     snn
-   6 [%        UR'                  5        V
Vs/ s H  u  p«U(       d  M  X«-  PM     snn
6 -  n U [%        U V
Vs/ s H	  u  p«X«-  PM     snn
6 [%        U V
Vs/ s H	  u  p«X«-  PM     snn
6 -  -  n U $ s  snf s  snf s  snn
f s  snn
f s  snn
f s  snn
f )Nc                 ó>  >• UR                   =(       d    U R                  =(       aw    U R                  [        [        4;   =(       dW    T=(       aN    U R
                  =(       a;    [        U R                  5      S:¬  =(       a    [        S U R                   5       5      $ )Né   c              3   ón   #   • U  H+  n[        S  [        R                  " U5       5       5      v •  M-     g7f)c              3   óš   #   • U  HA  n[        U[        5      =(       d%    UR                  =(       a    UR                  [        L v •  MC     g 7f©N)r6   r   Úis_PowÚbase)Ú.0Úais     r0   Ú	<genexpr>Ú8TR2i.<locals>.f.<locals>.ok.<locals>.<genexpr>.<genexpr>Š   s7   é € ð ,Ú*�Bô # 2¤sÓ+×K¨r¯y©y×/K¸R¿W¹WÌ¸^ÔKÚ*ùs   ‚A	AN)Úanyr   Ú	make_args)rL   r:   s     r0   rN   Ú.TR2i.<locals>.f.<locals>.ok.<locals>.<genexpr>Š   s7   é € ð =Ú5;°ô ñ ,ÜŸ-š-¨Ô*ó,÷ ,ð ,Ú5;ùs   ‚35)	Ú
is_integerÚis_positiveÚfuncr   r   Úis_AddÚlenr7   rP   )ÚkÚeÚhalfs     €r0   ÚokÚTR2i.<locals>.f.<locals>.okƒ   sx   ø€ ð —‘×. §¡÷ ?Ø—‘œ3¤˜*Ñ$÷ >¨÷ *=Ø—‘÷*=ä�A—F‘F“˜qÑ ÷*=ô ñ =Ø56·V²Vó=ó =ð@r2   c                 óÊ  >• / nU  Hg  nUR                   (       d  M  [        UR                  5      S:”  d  M1  T(       a  [        U5      O
[	        U5      nXC:w  d  MU  UR                  X445        Mi     U(       al  [        U5       H  u  nu  p4X	 XBU'   M     [        U6 R                  5       nU H1  nX   X#   -   nT" X65      (       a  X`U'   M  UR                  X645        M3     Ag g ©Né   )	rV   rW   r7   r&   r	   ÚappendÚ	enumerater   Úas_powers_dict)	ÚdÚddoneÚnewkrX   ÚknewÚiÚvrZ   r[   s	          €€r0   Ú	factorizeÚ"TR2i.<locals>.f.<locals>.factorize™   sÅ   ø€ ØˆDÛ�Ø—8—8‘8¤ A§F¡F£¨a¥Þ(,œ6 !œ9´,¸q³/�DØ•yØŸ™ Q IÖ.ñ	 ö
 Ü$-¨d¦O‘L�A‘y˜Ø˜Ø"˜“Gñ %4ô ˜D�z×0Ñ0Ó2�Û�AØ™˜t™w™�AÙ˜!—x‘xØ ˜!›àŸ™ a VÖ,ñ ñ ð r2   r   F©Úevaluater_   rF   )Úis_MulÚas_numer_denomÚis_Atomrb   ÚlistÚkeysÚpopr6   r   r   r7   r`   r   rV   r   r8   rS   rT   r   Úitems)r/   Únrc   rX   Úndonerd   ri   Útr:   Úa1ÚbrY   r[   rZ   s               @€r0   r;   ÚTR2i.<locals>.f{   st  ù€ Ø�y�yØˆIà× Ñ Ó"‰ˆØ�9�9˜Ÿ	Ÿ	ØˆIõ	@ð ×ÑÓˆÜ(,¨Q¯V©V«X¬ÓJª 1¹bÀÀaÁD¿k“�!—U‘U˜1“X“©ˆÐJÞØˆIà×ÑÓˆÜ(,¨Q¯V©V«X¬ÓJª 1¹bÀÀaÁD¿k“�!—U‘U˜1“X“©ˆÐJÞØˆIö	ñ& 	�!ÔÙ�!Ôð ˆÜˆAÜ˜!œS×!Ñ!Ü˜Ÿ™˜q™	¨EÑ2�Ø“6˜a™d a¡d›lØ—H‘HœS §¡¨¡›^¨Q©TÑ1Ô2Ø"&Ð&�A‘D˜1›4ÞØ˜Q™�BØ“w 1¡5¨A©D£=ØŸ™¤# a§f¡f¨Q¡i°¡kÓ"2°Q±TÑ!9Ô:Ø'+Ð+˜™˜q›uñ $1‘wñ ô
 ˜Aœs×#Ñ#Ü˜Ÿ™˜q™	¨EÑ2�Ø“6˜a™d a¡d›lØ—H‘HœS §¡¨¡›^¨a©d¨UÑ2Ô3Ø"&Ð&�A‘D˜1œ4ò +’6÷ ‘˜!Ÿ(Ÿ(š( q§v¡v¨a¡y´A·E±EÕ'9Ü˜qŸv™v a™y¬#×.Ô.Ü˜Ÿ™˜q™	Ÿ™ qÑ)°EÑ:�Ø–6˜a™d a¡džl°±··ØŸŸšØ—H‘HœS §¡¨¡¨1¡Ó-°±¨uÑ4Ô5Ø"&Ð&�A‘D˜1œ4ñ- ö0 Ü�q¯W©W¬YÔ<ªY¡T Q¼!›D˜AœD©YÒ<Ñ<Ð>Ü q§w¡w¤yÔ6¢y™t˜q´A“d�a”d¡yÒ6Ð7ñ8ˆBà”#©Ô/ª¡ ˜œ©Ò/Ð0´ÉÔ6NÊÁÀ°q´tÉÒ6NÐ1OÑOÑOˆBàˆ	ùòA Kùò
 Kùón =ùÛ6ùÛ/ùÓ6Ns<   Á=P:ÂP:Ã!P?Ã9P?ÎQÎ0QÏQ
Ï'Q
ÐQÐQr   )r/   rZ   r;   s    ` r0   ÚTR2irz   _   s   ø€ õ8Sôj �RÓÐr2   c                 óZ   ^• SSK Jm  U4S jnU R                  S S 5      n [        X5      $ )a  Induced formula: example sin(-a) = -sin(a)

Examples
========

>>> from sympy.simplify.fu import TR3
>>> from sympy.abc import x, y
>>> from sympy import pi
>>> from sympy import cos
>>> TR3(cos(y - x*(y - x)))
cos(x*(x - y) + y)
>>> cos(pi/2 + x)
-sin(x)
>>> cos(30*pi/2 + x)
-cos(x)

r   ©Úsignsimpc                 ó\  >• [        U [        5      (       d  U $ U R                  T" U R                  S   5      5      n [        U [        5      (       d  U $ U R                  S   [        R
                  S-  -
  R                  [        R
                  S-  U R                  S   -
  R                  s=L a  SL aw  O  U $ [        [        [        [        [        [        [        [        [        [        [        [        0nU[        U 5         " [        R
                  S-  U R                  S   -
  5      n U $ )Nr   é   rF   T)r6   r$   rU   r7   r   ÚPirT   r   r   r   r    r!   r"   Útype)r/   Úfmapr}   s     €r0   r;   ÚTR3.<locals>.fï   sÛ   ø€ Ü˜"Ô3×4Ñ4ØˆIØ�W‰W‘X˜bŸg™g a™jÓ)Ó*ˆÜ˜"Ô3×4Ñ4ØˆIØ�G‰G�A‰JœŸ™˜a™Ñ×,Ñ,´·±°a±¸"¿'¹'À!¹*Ñ1D×0QÑ0QÔYÐUYÔYð ˆ	ô œœc¤3¬¬S´#´s¼CÄÄcÌ3ÐOˆDØ”d˜2“h’¤§¡ Q¡¨¯©°©Ñ 3Ó4ˆBØˆ	r2   c                 ó"   • [        U [        5      $ rI   )r6   r$   ©Úxs    r0   Ú<lambda>ÚTR3.<locals>.<lambda>ü   s   € ”*˜QÔ 5Ô6r2   c                 ó*   • U R                  S S 5      $ )Nc                 ó@   • U R                   =(       a    U R                  $ rI   )Ú	is_numberrm   ©rt   s    r0   r‡   Ú'TR3.<locals>.<lambda>.<locals>.<lambda>þ   s   € �a—k‘k×. a§h¡hÐ.r2   c                 ó4   • U R                   " U R                  6 $ rI   ©rU   r7   rŒ   s    r0   r‡   r�   ÿ   s   € �a—f’f˜aŸf™f‘or2   ©Úreplacer…   s    r0   r‡   rˆ   ý   s   € �!—)‘)Ù.Ù%ô'r2   )Úsympy.simplify.simplifyr}   r‘   r   )r/   r;   r}   s     @r0   ÚTR3r“   Ó   s2   ø€ õ$ 1õ	ð 
�‰Ù6ñ	'ó
(€Bô �RÓÐr2   c                 ó*   • U R                  S S 5      $ )aT  Identify values of special angles.

    a=  0   pi/6        pi/4        pi/3        pi/2
----------------------------------------------------
sin(a)  0   1/2         sqrt(2)/2   sqrt(3)/2   1
cos(a)  1   sqrt(3)/2   sqrt(2)/2   1/2         0
tan(a)  0   sqt(3)/3    1           sqrt(3)     --

Examples
========

>>> from sympy import pi
>>> from sympy import cos, sin, tan, cot
>>> for s in (0, pi/6, pi/4, pi/3, pi/2):
...    print('%s %s %s %s' % (cos(s), sin(s), tan(s), cot(s)))
...
1 0 0 zoo
sqrt(3)/2 1/2 sqrt(3)/3 sqrt(3)
sqrt(2)/2 sqrt(2)/2 1 1
1/2 sqrt(3)/2 sqrt(3) sqrt(3)/3
0 1 zoo 0
c                 ó    • [        U [        5      =(       a8    U R                  S   [        -  =nR                  =(       a    UR
                  S;   $ )Nr   )r_   rF   é   r   é   )r6   r$   r7   r   Úis_RationalÚq)r†   Úrs     r0   r‡   ÚTR4.<locals>.<lambda>  sD   € Ü�qÔ/Ó0÷ EØ—‘�q‘	œ"‘ˆ_ˆQ×)Ñ)÷EØ./¯c©c°_Ñ.DðEr2   c                 ó†   • U R                  U R                  S   R                   " U R                  S   R                  6 5      $ r5   r�   r…   s    r0   r‡   r›      s+   € Ø�F‰F�1—6‘6˜!‘9—>’> 1§6¡6¨!¡9§>¡>Ð2Ô3r2   r�   r.   s    r0   ÚTR4r�     s    € ð0 �:‰:ñ	Eñ	4ó	5ð 5r2   c                 ó6   ^^^^^• UUUUU4S jn[        X5      $ )aÛ  Helper for TR5 and TR6 to replace f**2 with h(g**2)

Options
=======

max :   controls size of exponent that can appear on f
        e.g. if max=4 then f**4 will be changed to h(g**2)**2.
pow :   controls whether the exponent must be a perfect power of 2
        e.g. if pow=True (and max >= 6) then f**6 will not be changed
        but f**8 will be changed to h(g**2)**4

>>> from sympy.simplify.fu import _TR56 as T
>>> from sympy.abc import x
>>> from sympy import sin, cos
>>> h = lambda x: 1 - x
>>> T(sin(x)**3, sin, cos, h, 4, False)
(1 - cos(x)**2)*sin(x)
>>> T(sin(x)**6, sin, cos, h, 6, False)
(1 - cos(x)**2)**3
>>> T(sin(x)**6, sin, cos, h, 6, True)
sin(x)**6
>>> T(sin(x)**8, sin, cos, h, 10, True)
(1 - cos(x)**2)**4
c                 óŠ  >• U R                   (       a  U R                  R                  T:X  d  U $ U R                  R                  (       d  U $ U R                  S:  S:X  a  U $ U R                  T:„  S:X  a  U $ U R                  S:X  a  U $ U R                  S:X  a(  T" T" U R                  R
                  S   5      S-  5      $ U R                  S-  S:X  aZ  U R                  S-  nT" U R                  R
                  S   5      T" T" U R                  R
                  S   5      S-  5      U-  -  $ U R                  S:X  a  SnOZT(       d&  U R                  S-  (       a  U $ U R                  S-  nO-[        U R                  5      nU(       d  U $ U R                  S-  nT" T" U R                  R
                  S   5      S-  5      U-  $ )Nr   Tr_   rF   r   )rJ   rK   rU   ÚexpÚis_realr7   r%   )r/   rY   Úpr;   ÚgÚhÚmaxÚpows      €€€€€r0   Ú_fÚ_TR56.<locals>._f>  sg  ø€ ð
 —	—	˜bŸg™gŸl™l¨aÓ/ØˆIØ�v‰v�~�~ØˆIà�F‰F�Q‰J˜4ÓØˆIØ�F‰F�S‰L˜TÓ!ØˆIØ�6‰6�Q‹;ØˆIØ�6‰6�Q‹;Ù‘Q�r—w‘w—|‘| A‘Ó'¨Ñ*Ó+Ð+à�v‰v˜‰z˜Q‹Ø—F‘F˜A‘I�Ù˜Ÿ™Ÿ™ a™Ó)©!©A¨b¯g©g¯l©l¸1©oÓ,>ÀÑ,AÓ*BÀAÑ*EÑEÐEØ—‘˜1“Ø‘ÞØ—6‘6˜A—:Ø�IØ—F‘F˜A‘I‘ä! "§&¡&Ó)�ÞØ�IØ—F‘F˜A‘I�Ù‘Q�r—w‘w—|‘| A‘Ó'¨Ñ*Ó+¨QÑ.Ð.r2   r   )r/   r;   r£   r¤   r¥   r¦   r§   s    ````` r0   Ú_TR56r©   $  s   ü€ ÷4!/ñ !/ôF �RÓÐr2   c           	      ó.   • [        U [        [        S XS9$ )aM  Replacement of sin**2 with 1 - cos(x)**2.

See _TR56 docstring for advanced use of ``max`` and ``pow``.

Examples
========

>>> from sympy.simplify.fu import TR5
>>> from sympy.abc import x
>>> from sympy import sin
>>> TR5(sin(x)**2)
1 - cos(x)**2
>>> TR5(sin(x)**-2)  # unchanged
sin(x)**(-2)
>>> TR5(sin(x)**4)
(1 - cos(x)**2)**2
c                 ó   • SU -
  $ r^   © r…   s    r0   r‡   ÚTR5.<locals>.<lambda>v  ó   € ¨¨Qªr2   ©r¥   r¦   )r©   r   r   ©r/   r¥   r¦   s      r0   ÚTR5r±   d  ó   € ô$ �”Sœ#™°CÑAÐAr2   c           	      ó.   • [        U [        [        S XS9$ )aL  Replacement of cos**2 with 1 - sin(x)**2.

See _TR56 docstring for advanced use of ``max`` and ``pow``.

Examples
========

>>> from sympy.simplify.fu import TR6
>>> from sympy.abc import x
>>> from sympy import cos
>>> TR6(cos(x)**2)
1 - sin(x)**2
>>> TR6(cos(x)**-2)  #unchanged
cos(x)**(-2)
>>> TR6(cos(x)**4)
(1 - sin(x)**2)**2
c                 ó   • SU -
  $ r^   r¬   r…   s    r0   r‡   ÚTR6.<locals>.<lambda>‹  r®   r2   r¯   )r©   r   r   r°   s      r0   ÚTR6r¶   y  r²   r2   c                 ó   • S n[        X5      $ )zßLowering the degree of cos(x)**2.

Examples
========

>>> from sympy.simplify.fu import TR7
>>> from sympy.abc import x
>>> from sympy import cos
>>> TR7(cos(x)**2)
cos(2*x)/2 + 1/2
>>> TR7(cos(x)**2 + 1)
cos(2*x)/2 + 3/2

c                 óÚ   • U R                   (       a.  U R                  R                  [        :X  a  U R                  S:X  d  U $ S[        SU R                  R
                  S   -  5      -   S-  $ )NrF   r_   r   )rJ   rK   rU   r   r    r7   r.   s    r0   r;   ÚTR7.<locals>.fž  sM   € Ø—	—	˜bŸg™gŸl™l¬cÓ1°b·f±fÀ³kØˆIØ”C˜˜"Ÿ'™'Ÿ,™, q™/Ñ)Ó*Ñ*¨AÑ-Ð-r2   r   r=   s     r0   ÚTR7rº   Ž  s   € ò .ô
 �RÓÐr2   c                 ó&   ^• U4S jn[        X5      $ )aA  Converting products of ``cos`` and/or ``sin`` to a sum or
difference of ``cos`` and or ``sin`` terms.

Examples
========

>>> from sympy.simplify.fu import TR8
>>> from sympy import cos, sin
>>> TR8(cos(2)*cos(3))
cos(5)/2 + cos(1)/2
>>> TR8(cos(2)*sin(3))
sin(5)/2 + sin(1)/2
>>> TR8(sin(2)*sin(3))
-cos(5)/2 + cos(1)/2
c                 óZ	  >• U R                   (       dm  U R                  (       aZ  U R                  R                  [        [
        4;   a6  U R                  R                  (       d  U R                  R                  (       d  U $ T(       aÕ  U R                  5        Vs/ s H  n[        U5      PM     snu  p#[        USS9n[        USS9nXB:w  d  XS:w  a‰  [        XE-  5      n U R                   (       ak  U R                  S   R                  (       aM  [        U R                  5      S:X  a4  U R                  S   R                   (       a  [#        U R%                  5       6 n U $ [        / [
        / S / 0n["        R&                  " U 5       GH  nUR                  [        [
        4;   a,  U[)        U5         R+                  UR                  S   5        MJ  UR                  (       a�  UR                  R,                  (       a‚  UR                  S:”  ar  UR                  R                  [        [
        4;   aN  U[)        UR                  5         R/                  UR                  R                  S   /UR                  -  5        Mø  US    R+                  U5        GM     U[           nU[
           n	U(       a  U	(       d   [        U5      S:”  d  [        U	5      S:”  d  U $ US    n[1        [        U5      [        U	5      5      n[3        U5       HP  nU	R5                  5       n
UR5                  5       nUR+                  [        X«-   5      [        X«-
  5      -   S-  5        MR     [        U5      S:”  a^  UR5                  5       n
UR5                  5       nUR+                  [	        X«-   5      [	        X«-
  5      -   S-  5        [        U5      S:”  a  M^  U(       a(  UR+                  [	        UR5                  5       5      5        [        U	5      S:”  a_  U	R5                  5       n
U	R5                  5       nUR+                  [	        X«-   5      * [	        X«-
  5      -   S-  5        [        U	5      S:”  a  M_  U	(       a(  UR+                  [        U	R5                  5       5      5        [        [        [#        U6 5      5      $ s  snf )NF©Úfirstr   rF   r_   )rm   rJ   rK   rU   r   r   r    rS   rT   rn   r
   ÚTR8r   r7   r˜   rW   rV   r   Úas_coeff_MulrQ   r�   r`   Ú
is_IntegerÚextendÚminÚrangerr   )r/   rg   rt   rc   ÚnewnÚnewdr7   r:   ÚcÚsrw   Úa2r¾   s               €r0   r;   ÚTR8.<locals>.f·  s:  ø€ à�I�IØ�I�IØ�G‰G�L‰LœS¤#˜JÓ&Ø�V‰V×× "§'¡'×"5×"5ØˆIæØ+-×+<Ñ+<Ô+>Ó?Ò+> a”J˜q–MÑ+>Ñ?‰DˆAÜ�q Ñ&ˆDÜ�q Ñ&ˆDØ‹y˜D›IÜ˜t™yÓ)�Ø—9—9 §¡¨¡×!7×!7Ü˜BŸG™G›¨Ó)¨b¯g©g°a©j×.?×.?Ü˜bŸo™oÓ/Ð0�BØˆIä�Rœ˜b $¨Ð+ˆÜ—’˜r×"ˆAØ�v‰vœ#œs˜Ó#Ø”T˜!“W‘×$Ñ$ Q§V¡V¨A¡YÖ/Ø—(—(˜qŸu™u×/×/°A·E±E¸A³IØ—F‘F—K‘K¤C¬ :Ó-ð ”T˜!Ÿ&™&“\Ñ"×)Ñ)¨1¯6©6¯;©;°q©>Ð*:¸1¿5¹5Ñ*@ÖAà�T‘
×!Ñ! !×$ñ #ð ”‰IˆØ”‰IˆÞ–aœ3˜q›6 A›:¬¨Q«°!«ØˆIà�D‰zˆÜ”�A“œ˜A›ÓˆÜ�q–ˆAØ—‘“ˆBØ—‘“ˆBØ�K‰Kœ˜R™W›¬¨B©G«Ñ4°aÑ7Ö8ñ ô �!‹f�q‹jØ—‘“ˆBØ—‘“ˆBØ�K‰Kœ˜R™W›¬¨B©G«Ñ4°aÑ7Ô8ô �!‹f�q�jö Ø�K‰Kœ˜AŸE™E›G›Ô%Ü�!‹f�q‹jØ—‘“ˆBØ—‘“ˆBØ�K‰Kœ#˜b™g›,˜¬¨R©W«Ñ5°qÑ8Ô9ô �!‹f�q�jö Ø�K‰Kœ˜AŸE™E›G›Ô%Ü”:œc 4˜jÓ)Ó*Ð*ùòY @s   ÂR(r   ©r/   r¾   r;   s    ` r0   r¿   r¿   ¦  s   ø€ õ"5+ôn �RÓÐr2   c                 ó   • S n[        X5      $ )a'  Sum of ``cos`` or ``sin`` terms as a product of ``cos`` or ``sin``.

Examples
========

>>> from sympy.simplify.fu import TR9
>>> from sympy import cos, sin
>>> TR9(cos(1) + cos(2))
2*cos(1/2)*cos(3/2)
>>> TR9(cos(1) + 2*sin(1) + 2*sin(2))
cos(1) + 4*sin(3/2)*cos(1/2)

If no change is made by TR9, no re-arrangement of the
expression will be made. For example, though factoring
of common term is attempted, if the factored expression
was not changed, the original expression will be returned:

>>> TR9(cos(3) + cos(3)*cos(2))
cos(3) + cos(2)*cos(3)

c                 óR   ^• U R                   (       d  U $ SU4S jjm[        U T5      $ )Nc                 ó¶  >• U R                   (       d  U $ [        [        U R                  5      5      n[	        U5      S:w  a¯  Sn[        [	        U5      5       HR  nX$   nUc  M  [        US-   [	        U5      5       H*  nX&   nUc  M  XW-   nT" U5      n	X˜:w  d  M  X’U'   S X&'   Sn  MP     MT     U(       a:  [        U V
s/ s H  oª(       d  M  U
PM     sn
6 n U R                   (       a  T" U 5      n U $ [        U6 nU(       d  U $ Uu  pÍpïnnU(       ac  XÞ:X  a+  XÍ-  S-  [        UU-   S-  5      -  [        UU-
  S-  5      -  $ US:  a  UUnnSU-  [        UU-   S-  5      -  [        UU-
  S-  5      -  $ XÞ:X  a+  XÍ-  S-  [        UU-   S-  5      -  [        UU-
  S-  5      -  $ US:  a  UUnnSU-  [        UU-   S-  5      -  [        UU-
  S-  5      -  $ s  sn
f )NrF   Fr_   Tr   éþÿÿÿ©
rV   rp   r   r7   rW   rÄ   r   Ú
trig_splitr   r   )r/   r¾   r7   Úhitrg   rM   ÚjÚajÚwasÚnewr§   ÚsplitÚgcdÚn1Ún2r:   rx   ÚiscosÚdos                     €r0   rÜ   ÚTR9.<locals>.f.<locals>.do  sè  ø€ ð —9—9Ø�	äœ §¡Ó(Ó)ˆDÜ�4‹y˜A‹~Ø�Üœs 4›yÖ)�AØ™�BØ‘zÙ Ü" 1 q¡5¬#¨d«)Ö4˜Ø!™W˜Ø™:Ù$Ø ™g˜Ù  ›g˜Ø�:Ø&) ™GØ&*˜D™GØ"&˜CÚ!ó 5ñ	 *ö Ü©DÓ7ªD b³BŸr©DÑ7Ð8�BØ—y—yÙ ›V˜à�	ô  Ð%ˆEÞØ�	Ø',Ñ$ˆC�R˜A˜uö Ø“8Ø™6 !™8¤C¨¨Q©°©	£NÑ2´3¸¸A¹¸q±y³>ÑAÐAØ˜“6Ø˜a�q�AØ˜#‘vœc 1 q¡5¨!¡)›nÑ,¬S°!°a±%¸±«^Ñ;Ð;à“8Ø™6 !™8¤C¨¨Q©°©	£NÑ2´3¸¸A¹¸q±y³>ÑAÐAØ˜“6Ø˜a�q�AØ˜‘uœS ! a¡%¨¡›^Ñ+¬C°°Q±¸±	«NÑ:Ð:ùò1 8s   Â>
GÃG©T)rV   Úprocess_common_addends)r/   rÜ   s    @r0   r;   ÚTR9.<locals>.f  s$   ø€ Ø�y�yØˆI÷<	;ô| & b¨"Ó-Ð-r2   r   r=   s     r0   ÚTR9rá   ñ  s   € ò.B.ôH �RÓÐr2   c                 ó&   ^• U4S jn[        X5      $ )aw  Separate sums in ``cos`` and ``sin``.

Examples
========

>>> from sympy.simplify.fu import TR10
>>> from sympy.abc import a, b, c
>>> from sympy import cos, sin
>>> TR10(cos(a + b))
-sin(a)*sin(b) + cos(a)*cos(b)
>>> TR10(sin(a + b))
sin(a)*cos(b) + sin(b)*cos(a)
>>> TR10(sin(a + b + c))
(-sin(a)*sin(b) + cos(a)*cos(b))*sin(c) +     (sin(a)*cos(b) + sin(b)*cos(a))*cos(c)
c                 ó^  >• U R                   [        [        4;  a  U $ U R                   nU R                  S   nUR                  (       Gab  T(       a  [        [        UR                  5      5      nO[        UR                  5      nUR                  5       n[        R                  " U5      nUR                  (       aˆ  U[        :X  a?  [        U5      [        [        U5      SS9-  [        U5      [        [        U5      SS9-  -   $ [        U5      [        [        U5      SS9-  [        U5      [        [        U5      SS9-  -
  $ U[        :X  a/  [        U5      [        U5      -  [        U5      [        U5      -  -   $ [        U5      [        U5      -  [        U5      [        U5      -  -
  $ U $ )Nr   Fr½   )rU   r   r   r7   rV   rp   r   rr   r   Ú
_from_argsÚTR10)r/   r;   Úargr7   r:   rx   r¾   s         €r0   r;   ÚTR10.<locals>.fa  sG  ø€ Ø�7‰7œ3¤˜*Ó$ØˆIà�G‰GˆØ�g‰g�a‰jˆØ�:�:ˆ:ÞÜœG C§H¡HÓ-Ó.‘ä˜CŸH™H“~�Ø—‘“
ˆAÜ—’˜tÓ$ˆAØ�x�xØœ“8Ü˜q›6¤$¤s¨1£v°UÑ";Ñ;Ü˜A›œt¤C¨£F°%Ñ8Ñ8ñ9ð 9ô ˜q›6¤$¤s¨1£v°UÑ";Ñ;Ü˜A›œt¤C¨£F°%Ñ8Ñ8ñ9ð 9ð œ“8Ü˜q›6¤# a£&™=¬3¨q«6´#°a³&©=Ñ8Ð8ä˜q›6¤# a£&™=¬3¨q«6´#°a³&©=Ñ8Ð8Øˆ	r2   r   rË   s    ` r0   rå   rå   O  s   ø€ õ$ô6 �RÓÐr2   c                 ó   • S n[        X5      $ )a^  Sum of products to function of sum.

Examples
========

>>> from sympy.simplify.fu import TR10i
>>> from sympy import cos, sin, sqrt
>>> from sympy.abc import x

>>> TR10i(cos(1)*cos(3) + sin(1)*sin(3))
cos(2)
>>> TR10i(cos(1)*sin(3) + sin(1)*cos(3) + cos(3))
cos(3) + sin(4)
>>> TR10i(sqrt(2)*cos(x)*x + sqrt(6)*sin(x)*x)
2*sqrt(2)*x*sin(x + pi/6)

c                 ó°  ^• U R                   (       d  U $ SU4S jjm[        U TS 5      n U R                   (       Ga  [        [        5      nU R                   H¸  nSnUR
                  (       aw  UR                   Hg  nUR                  (       d  M  UR                  [        R                  L d  M5  UR                  R                  (       d  MR  X   R                  U5        Sn  O   U(       a  M–  U[        R                     R                  U5        Mº     / nU H½  n[        5       U-  [        5       4 HŸ  nXa;   d  M
  [!        [#        X   5      5       H{  nX   U   c  M  [!        [#        X   5      5       HT  nX   U   c  M  [%        X   U   X   U   -   5      n	T" U	5      n
X©:w  d  M4  UR                  U
5        S X   U'   S X   U'     My     M}     M¡     M¿     U(       aL  [%        UUR'                  5        VVs/ s H$  n[%        U Vs/ s H  oÌ(       d  M  UPM     sn6 PM&     snn-   6 n OT" U 5      n  U $ U R                   (       a  GM  U $ s  snf s  snnf )Nc                 óÜ  >• U R                   (       d  U $ [        [        U R                  5      5      n[	        U5      S:w  a¯  Sn[        [	        U5      5       HR  nX$   nUc  M  [        US-   [	        U5      5       H*  nX&   nUc  M  XW-   nT" U5      n	X˜:w  d  M  X’U'   S X&'   Sn  MP     MT     U(       a:  [        U V
s/ s H  oª(       d  M  U
PM     sn
6 n U R                   (       a  T" U 5      n U $ [        USS06nU(       d  U $ Uu  pÍpïnnU(       a+  XÜ-  nXÞ:X  a  U[        UU-
  5      -  $ U[        UU-   5      -  $ XÜ-  nXÞ:X  a  U[        UU-   5      -  $ U[        UU-
  5      -  $ s  sn
f )NrF   Fr_   TÚtworÐ   )r/   r¾   r7   rÒ   rg   rM   rÓ   rÔ   rÕ   rÖ   r§   r×   rØ   rÙ   rÚ   r:   rx   ÚsamerÜ   s                     €r0   rÜ   ÚTR10i.<locals>.f.<locals>.do•  so  ø€ ð —9—9Ø�	äœ §¡Ó(Ó)ˆDÜ�4‹y˜A‹~Ø�Üœs 4›yÖ)�AØ™�BØ‘zÙ Ü" 1 q¡5¬#¨d«)Ö4˜Ø!™W˜Ø™:Ù$Ø ™g˜Ù  ›g˜Ø�:Ø&) ™GØ&*˜D™GØ"&˜CÚ!ó 5ñ	 *ö Ü©DÓ7ªD b³BŸr©DÑ7Ð8�BØ—y—yÙ ›V˜à�	ô  Ð/¨$Ñ/ˆEÞØ�	Ø&+Ñ#ˆC�R˜A˜tö Ø‘f�Ø“8Øœs 1 q¡5›z™>Ð)Øœ3˜q 1™u›:‘~Ð%à‘f�Ø“8Øœs 1 q¡5›z™>Ð)Øœ3˜q 1™u›:‘~Ð%ùò- 8s   Â>
E)ÃE)c                 ó>   • [        [        U R                  5      5      $ rI   )Útupler   Úfree_symbolsr…   s    r0   r‡   Ú"TR10i.<locals>.f.<locals>.<lambda>Î  s   € œe¤G¨A¯N©NÓ$;Ô<r2   r   r_   rÞ   )rV   rß   r   rp   r7   rm   rJ   r    r   ÚHalfrK   rÁ   r`   r8   Ú_ROOT3Ú	_invROOT3rÄ   rW   r   Úvalues)r/   Úbyradr:   rÒ   rM   r7   rx   rg   rÓ   rÕ   rÖ   rh   r§   rÜ   s                @r0   r;   ÚTR10i.<locals>.f‘  s  ø€ Ø�y�yØˆI÷6	&ôp $Ø�Ñ<ó>ˆð
 �i�iˆiÜ¤Ó%ˆEØ—W”W�Ø�Ø—8—8ØŸfœf˜ØŸ9Ÿ9™9¨¯©´1·6±6Ô)9Ø "§¡× 2× 2Ñ 2Ø!™I×,Ñ,¨QÔ/Ø"#˜CÙ!ñ %÷ �sØœ!Ÿ%™%‘L×'Ñ'¨Ö*ñ ð ˆDÛ�Ü ›( 1™*¤i£kÓ2�AØ•zÜ!&¤s¨5©8£}Ö!5˜AØ$™x¨™{Ñ2Ù (Ü%*¬3¨u©x«=Ö%9 Ø#(¡8¨A¡;Ñ#6Ù$,Ü&)¨%©(°1©+¸¹À¹Ñ*CÓ&D Ù&(¨£g Ø#&¥:Ø$(§K¡K°Ô$4Ø26 E¡H¨Q¡KØ26 E¡H¨Q¡KÚ$)ó &:ó "6ó 3ñ ö  Ü˜4Ø"Ÿ\™\œ^ô#-Ú+˜ô $'±aÓ(>²a°»2¯±aÑ(>Ó#?Ù+ò#-ñ -ð /‘ñ ˜“V�Øàˆ	ðQ �i�iŠiðP ˆ	ùò )?ùó #-s   Ç9IÈ
IÈIÈIÉIr   r=   s     r0   ÚTR10irø     s   € ò$iôV �RÓÐr2   Nc                 ó&   ^• U4S jn[        X5      $ )aö  Function of double angle to product. The ``base`` argument can be used
to indicate what is the un-doubled argument, e.g. if 3*pi/7 is the base
then cosine and sine functions with argument 6*pi/7 will be replaced.

Examples
========

>>> from sympy.simplify.fu import TR11
>>> from sympy import cos, sin, pi
>>> from sympy.abc import x
>>> TR11(sin(2*x))
2*sin(x)*cos(x)
>>> TR11(cos(2*x))
-sin(x)**2 + cos(x)**2
>>> TR11(sin(4*x))
4*(-sin(x)**2 + cos(x)**2)*sin(x)*cos(x)
>>> TR11(sin(4*x/3))
4*(-sin(x/3)**2 + cos(x/3)**2)*sin(x/3)*cos(x/3)

If the arguments are simply integers, no change is made
unless a base is provided:

>>> TR11(cos(2))
cos(2)
>>> TR11(cos(4), 2)
-sin(2)**2 + cos(2)**2

There is a subtle issue here in that autosimplification will convert
some higher angles to lower angles

>>> cos(6*pi/7) + cos(3*pi/7)
-cos(pi/7) + cos(3*pi/7)

The 6*pi/7 angle is now pi/7 but can be targeted with TR11 by supplying
the 3*pi/7 base:

>>> TR11(_, 3*pi/7)
-sin(3*pi/7)**2 + cos(3*pi/7)**2 + cos(3*pi/7)

c                 óL  >• U R                   [        [        4;  a  U $ T(       aÀ  U R                   nU" TS-  5      n[        R                  nUR
                  (       a  UR                  5       u  p2UR                   [        [        4;  a  U $ U R                  S   UR                  S   :X  a8  [        T5      n[        T5      nU[        L a  US-  US-  -
  U-  $ SU-  U-  U-  $ U $ U R                  S   R                  (       d¡  U R                  S   R                  SS9u  pFUR                  S-  S:X  ap  UR                  S-  U-  UR                  -  n[        [        U5      5      n[        [        U5      5      nU R                   [        :X  a
  SU-  U-  n U $ US-  US-  -
  n U $ )NrF   r   T)Úrational)rU   r   r   r   r8   rm   rÀ   r7   Ú	is_Numberr¢   r™   ÚTR11)	r/   r;   rv   ÚcorÇ   rÈ   Úmræ   rK   s	           €r0   r;   ÚTR11.<locals>.f)  sk  ø€ Ø�7‰7œ3¤˜*Ó$ØˆIæØ—‘ˆAÙ�$�q‘&“	ˆAÜ—‘ˆBØ�x�xØŸ™Ó(‘�Ø�v‰vœc¤3˜ZÓ'Ø�	Ø�w‰w�q‰z˜QŸV™V A™YÓ&Ü˜“I�Ü˜“I�Øœ’8Ø˜q™D 1 a¡4™K¨Ñ+Ð+à˜Q™3˜q™5 ™8�OØˆIà—‘˜‘×%×%ð —7‘7˜1‘:×*Ñ*°DÐ*Ð9‰DˆAØ�s‰s�Q‰w˜!‹|Ø—c‘c˜1‘f˜Q‘h˜qŸs™s‘l�Üœ˜S›“N�Üœ˜S›“N�Ø—7‘7œc“>Ø˜1™˜Q™�Bð ˆ	ð ˜A™  1¡™�BØˆ	r2   r   )r/   rK   r;   s    ` r0   rý   rý   ÿ  s   ø€ õT!ôF �RÓÐr2   c                 ó   • S n[        X5      $ )a®  
Helper for TR11 to find half-arguments for sin in factors of
num/den that appear in cos or sin factors in the den/num.

Examples
========

>>> from sympy.simplify.fu import TR11, _TR11
>>> from sympy import cos, sin
>>> from sympy.abc import x
>>> TR11(sin(x/3)/(cos(x/6)))
sin(x/3)/cos(x/6)
>>> _TR11(sin(x/3)/(cos(x/6)))
2*sin(x/6)
>>> TR11(sin(x/6)/(sin(x/3)))
sin(x/6)/sin(x/3)
>>> _TR11(sin(x/6)/(sin(x/3)))
1/(2*cos(x/6))

c                 óš   • [        U [        5      (       d  U $ S n[        XR                  5       5      u  p#S nU" XU5      n U" XU5      n U $ )Nc                 óD  • [        [        5      n[        R                  " U 5       Hv  nUR	                  5       u  p4UR
                  (       d  M(  US:”  d  M0  UR                  [        [        4;   d  ML  U[        U5         R                  UR                  S   5        Mx     U$ r5   )r   Úsetr   rQ   Úas_base_exprÁ   rU   r   r   r�   Úaddr7   )Úflatr7   Úfirx   rY   s        r0   Úsincos_argsÚ%_TR11.<locals>.f.<locals>.sincos_argsh  ss   € ô œsÓ#ˆDÜ—m’m DÖ)�Ø—~‘~Ó'‘�Ø—<—<‘< A¨¥EØ—v‘v¤#¤s Õ+ØœT !›W™×)Ñ)¨!¯&©&°©)Ö4ñ	 *ð
 ˆKr2   c                 ó¼   • U[             HN  nUS-  nXB[           ;   a  [        nOXB[            ;   a  [         nOM0  [        X5      n X%   R                  U5        MP     U $ ©NrF   )r   r   rý   Úremove)r/   Únum_argsÚden_argsÚnargrZ   rU   s         r0   Úhandle_matchÚ&_TR11.<locals>.f.<locals>.handle_matcht  s\   € ð !¤œ�Ø˜A‘v�Ø¤C™=Ó(Ü‘DØ¤c™]Ó*Ü‘DáÜ˜"“^�Ø‘×%Ñ% dÖ+ñ &ð ˆIr2   )r6   r   Úmaprn   )r/   r	  r  r  r  s        r0   r;   Ú_TR11.<locals>.fd  sU   € Ü˜"œd×#Ñ#ØˆIò
	ô ! ×.?Ñ.?Ó.AÓBÑˆò	ñ  ˜"¨Ó1ˆá˜"¨Ó1ˆØˆ	r2   r   r=   s     r0   Ú_TR11r  O  s   € ò*#ôJ �RÓÐr2   c                 ó&   ^• U4S jn[        X5      $ )zÊSeparate sums in ``tan``.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy import tan
>>> from sympy.simplify.fu import TR12
>>> TR12(tan(x + y))
(tan(x) + tan(y))/(-tan(x)*tan(y) + 1)
c                 óÖ  >• U R                   [        :X  d  U $ U R                  S   nUR                  (       a±  T(       a  [	        [        UR                  5      5      nO[	        UR                  5      nUR                  5       n[        R                  " U5      nUR                  (       a  [        [        U5      SS9nO[        U5      n[        U5      U-   S[        U5      U-  -
  -  $ U $ )Nr   Fr½   r_   )
rU   r   r7   rV   rp   r   rr   r   rä   ÚTR12)r/   ræ   r7   r:   rx   Útbr¾   s         €r0   r;   ÚTR12.<locals>.f™  s§   ø€ Ø�w‰wœ#‹~ØˆIà�g‰g�a‰jˆØ�:�:ÞÜœG C§H¡HÓ-Ó.‘ä˜CŸH™H“~�Ø—‘“
ˆAÜ—’˜tÓ$ˆAØ�x�xÜœ#˜a›&¨Ñ.‘ä˜“V�Ü˜“F˜R‘K !¤c¨!£f¨R¡i¡-Ñ0Ð0Øˆ	r2   r   rË   s    ` r0   r  r  Œ  s   ø€ õô& �RÓÐr2   c                 ó   • S n[        X5      $ )a  Combine tan arguments as
(tan(y) + tan(x))/(tan(x)*tan(y) - 1) -> -tan(x + y).

Examples
========

>>> from sympy.simplify.fu import TR12i
>>> from sympy import tan
>>> from sympy.abc import a, b, c
>>> ta, tb, tc = [tan(i) for i in (a, b, c)]
>>> TR12i((ta + tb)/(-ta*tb + 1))
tan(a + b)
>>> TR12i((ta + tb)/(ta*tb - 1))
-tan(a + b)
>>> TR12i((-ta - tb)/(ta*tb - 1))
tan(a + b)
>>> eq = (ta + tb)/(-ta*tb + 1)**2*(-3*ta - 3*tc)/(2*(ta*tc - 1))
>>> TR12i(eq.expand())
-3*tan(a + b)*tan(a + c)/(2*(tan(a) + tan(b) - 1))
c                 óN
  • U R                   (       d$  U R                  (       d  U R                  (       d  U $ U R                  5       u  pUR                  (       a  UR                  (       d  U $ 0 nS n[        [        R                  " U5      5      n[        U5       GHÃ  u  pgU" U5      nU(       aK  Uu  pš[        U
R                   Vs/ s H  o»R                  S   PM     sn6 n[        R                  X<'   X•U'   M`  UR                   (       aM  [        U5      nUR                  (       a/  UR                  UR                  5        [        R                  XV'   M¼  M¾  UR                  (       d  MÑ  UR                  R                  (       d  UR                   R"                  (       d  GM
  U" UR                   5      nU(       aT  Uu  pš[        U
R                   Vs/ s H  o»R                  S   PM     sn6 nUR                  X<'   X—R                  -  XV'   GMw  [        U5      nUR                  (       d  GM–  UR                  UR                  5        [        R                  XV'   GMÆ     U(       d  U $ S n[        [        R                  " [%        U5      5      5      nSn[        U5       GHê  u  poU" U5      nU(       GdB  U" U* 5      nU(       a  [        R&                  XÖ'   GO0UR                   (       aK  [        U5      nUR                  (       a-  UR                  UR                  5        [        R                  XÖ'   M–  UR                  (       a®  UR                  R                  (       d  UR                   R"                  (       ax  U" UR                   5      nU(       a  [        R                  XÖ'   Oa[        U5      nUR                  (       a-  UR                  UR                  5        [        R                  XÖ'   GMU  GMX  [        R                  XÖ'   Sn[        U Vs/ s H  o»R                  S   PM     sn6 nX<   nUR)                  [        R                  5      nUb  U(       a  UX<'   OUR+                  U5        XÖ==   [-        U5      * -  ss'   GMí     U(       ap  [        U6 [        U6 -  [        UR/                  5        VVVs/ s H8  u  nn[        UR                   Vs/ s H  n[-        U5      PM     sn6 S-
  U-  PM:     snnn6 -  n U $ s  snf s  snf s  snf s  snf s  snnnf )Nc                 óü   • [        U 5      nU(       aj  Uu  p#nU[        R                  L aQ  UR                  (       a?  [	        UR
                  5      S:X  a%  [        S UR
                   5       5      (       a  X#4$ g g g g g )NrF   c              3   óB   #   • U  H  n[        U[        5      v •  M     g 7frI   )r6   r   )rL   r  s     r0   rN   Ú/TR12i.<locals>.f.<locals>.ok.<locals>.<genexpr>Ó  s   é € ÐAº&°BœJ r¬3×/Ð/º&ùs   ‚)Úas_f_sign_1r   ÚNegativeOnerm   rW   r7   Úall)Údirÿ   r£   r;   rÈ   s        r0   r[   ÚTR12i.<locals>.f.<locals>.okÎ  sj   € Ü˜B“ˆAÞØ‘��aØœŸ™Ò%¨!¯(¯(´s¸1¿6¹6³{ÀaÓ7GÜÑA¸!¿&º&ÓA×AÑAØ˜4�Kð Bð 8H¨(Ð%ð r2   r   c                 óÔ   • U R                   (       aW  [        U R                  5      S:X  a=  U R                  u  p[        U[        5      (       a  [        U[        5      (       a  X4$ g g g g r  )rV   rW   r7   r6   r   )Únir:   rx   s      r0   r[   r$  ó  sR   € Ø�y�yœS §¡›\¨QÓ.Ø—w‘w‘�Ü˜a¤×%Ñ%¬*°Q¼×*<Ñ*<Ø˜4�Kð +=Ð%ð /ˆyr2   FTr_   )rV   rm   rJ   rn   r7   rp   r   rQ   ra   r   r   r8   r&   rÂ   r    rS   rK   rT   r	   r!  Úextract_additivelyrr   r   rs   )r/   rt   rc   Údokr[   Úd_argsrg   r#  rÿ   r£   rv   Ú_rÈ   Ún_argsrÒ   r&  ÚedÚnewedrY   r:   s                       r0   r;   ÚTR12i.<locals>.fÄ  s³  € Ø—	—	˜RŸYŸY¨"¯)¯)ØˆIà× Ñ Ó"‰ˆØ�v�v˜QŸVŸVØˆIàˆò	 ô ”c—m’m AÓ&Ó'ˆÜ˜v×&‰EˆAÙ�2“ˆAÞØ‘�Ü¨Q¯VªVÓ4ªV¨Ÿ&™& œ)©VÑ4Ð5�ÜŸ™�‘Ø�q‘	ÙØ�y�yÜ˜B“Z�Ø—9—9Ø—M‘M "§'¡'Ô*Ü !§¡�F“Iñ ð ——‘ §¡× 1× 1°R·W±W×5H×5HÒ5HÙ�r—w‘w“K�ÞØ‘D�AÜ°·²Ó8²¨AŸf™f Qœi±Ñ8Ð9�AØŸV™V�C‘FØ !§6¡6¡	�F”Iä ›�BØ—y—y’yØŸ™ b§g¡gÔ.Ü$%§E¡E˜œ	ñ1 'ö2 ØˆIò	 ô
 ”c—m’m¤L°£OÓ4Ó5ˆØˆÜ˜v×&‰EˆAÙ�2“ˆAßÙ˜�s“G�ÞÜ !§¡�F“Ià—y—yÜ# B›Z˜ØŸ9Ÿ9Ø"ŸM™M¨"¯'©'Ô2Ü()¯©˜F™IÙ ØŸŸØŸF™F×-×-°·±×1D×1DÙ˜rŸw™w›K˜ÞÜ()¯©˜FšIä!'¨£˜BØ!ŸyŸyØ &§¡¨b¯g©gÔ 6Ü,-¯E©E ¡	Ú$â äŸE™E�‘	ØˆCÜ©Ó+ª A—f‘f˜Q”i©Ñ+Ð,ˆAØ‘ˆBØ×)Ñ)¬!¯%©%Ó0ˆEØÑ ÞØ"�C’Fà—G‘G˜A”JØ‹Iœ#˜a›&˜Ñ ŽIñK 'öN Ü�f�œc 6˜lÑ*¬3Ø=@¿Y¹Y¼[õ1JÚ=H±T°Q¸ô 36Ø !§¢ó8(Ú &˜1”�A–¡ñ8(ð 3)Ø+,ñ3-Ø/0ô21Ù=Hó1Jð ,Kñ KˆBð ˆ	ùòU 5ùò 9ùò^ ,ùò8(ùô 1Js*   ÃT
ÇT
ÐT
ÓT ÓTÓ4T ÔT r   r=   s     r0   ÚTR12ir/  ¯  s   € ò*aôF �RÓÐr2   c                 ó   • S n[        X5      $ )zöChange products of ``tan`` or ``cot``.

Examples
========

>>> from sympy.simplify.fu import TR13
>>> from sympy import tan, cot
>>> TR13(tan(3)*tan(2))
-tan(2)/tan(5) - tan(3)/tan(5) + 1
>>> TR13(cot(3)*cot(2))
cot(2)*cot(5) + 1 + cot(3)*cot(5)
c           	      ó„  • U R                   (       d  U $ [        / [        / S / 0n[        R                  " U 5       H]  nUR
                  [        [        4;   a,  U[        U5         R                  UR                  S   5        MI  US    R                  U5        M_     U[           nU[           n[        U5      S:  a  [        U5      S:  a  U $ US    n[        U5      S:”  av  UR                  5       nUR                  5       nUR                  S[        U5      [        XV-   5      -  [        U5      [        XV-   5      -  -   -
  5        [        U5      S:”  a  Mv  U(       a(  UR                  [        UR                  5       5      5        [        U5      S:”  av  UR                  5       nUR                  5       nUR                  S[        U5      [        XV-   5      -  -   [        U5      [        XV-   5      -  -   5        [        U5      S:”  a  Mv  U(       a(  UR                  [        UR                  5       5      5        [        U6 $ ©Nr   rF   r_   )rm   r   r    r   rQ   rU   r�   r`   r7   rW   rr   )r/   r7   r:   rv   rÇ   Út1Út2s          r0   r;   ÚTR13.<locals>.f8  s°  € Ø�y�yØˆIô �Rœ˜b $¨Ð+ˆÜ—’˜rÖ"ˆAØ�v‰vœ#œs˜Ó#Ø”T˜!“W‘×$Ñ$ Q§V¡V¨A¡YÖ/à�T‘
×!Ñ! !Ö$ñ	 #ð
 ”‰IˆØ”‰IˆÜˆq‹6�A‹:œ#˜a›& 1›*ØˆIØ�D‰zˆÜ�!‹f�q‹jØ—‘“ˆBØ—‘“ˆBØ�K‰K˜œS ›W¤S¨©£\Ñ1´C¸³G¼CÀÁ»LÑ4HÑHÑIÔJô �!‹f�q�jö Ø�K‰Kœ˜AŸE™E›G›Ô%Ü�!‹f�q‹jØ—‘“ˆBØ—‘“ˆBØ�K‰K˜œC ›G¤C¨©£LÑ0Ñ0´3°r³7¼3¸r¹w»<Ñ3GÑGÔHô �!‹f�q�jö Ø�K‰Kœ˜AŸE™E›G›Ô%Ü�DˆzÐr2   r   r=   s     r0   ÚTR13r6  *  s   € òô< �RÓÐr2   c                 ó,   ^• SU4S jjm[        U T5      $ )a  Returns cos(x)*cos(2*x)*...*cos(2**(k-1)*x) -> sin(2**k*x)/(2**k*sin(x))

Examples
========

>>> from sympy.simplify.fu import TRmorrie, TR8, TR3
>>> from sympy.abc import x
>>> from sympy import Mul, cos, pi
>>> TRmorrie(cos(x)*cos(2*x))
sin(4*x)/(4*sin(x))
>>> TRmorrie(7*Mul(*[cos(x) for x in range(10)]))
7*sin(12)*sin(16)*cos(5)*cos(7)*cos(9)/(64*sin(1)*sin(3))

Sometimes autosimplification will cause a power to be
not recognized. e.g. in the following, cos(4*pi/7) automatically
simplifies to -cos(3*pi/7) so only 2 of the 3 terms are
recognized:

>>> TRmorrie(cos(pi/7)*cos(2*pi/7)*cos(4*pi/7))
-sin(3*pi/7)*cos(3*pi/7)/(4*sin(pi/7))

A touch by TR8 resolves the expression to a Rational

>>> TR8(_)
-1/8

In this case, if eq is unsimplified, the answer is obtained
directly:

>>> eq = cos(pi/9)*cos(2*pi/9)*cos(3*pi/9)*cos(4*pi/9)
>>> TRmorrie(eq)
1/16

But if angles are made canonical with TR3 then the answer
is not simplified without further work:

>>> TR3(eq)
sin(pi/18)*cos(pi/9)*cos(2*pi/9)/2
>>> TRmorrie(_)
sin(pi/18)*sin(4*pi/9)/(8*sin(pi/9))
>>> TR8(_)
cos(7*pi/18)/(16*sin(pi/9))
>>> TR3(_)
1/16

The original expression would have resolve to 1/16 directly with TR8,
however:

>>> TR8(eq)
1/16

References
==========

.. [1] https://en.wikipedia.org/wiki/Morrie%27s_law

c                 ó@  >• U R                   (       d  U $ U(       a%  U R                  5       u  p#T" US5      T" US5      -  $ [        [        5      n0 n/ nU R                   H„  nUR                  5       u  p‰U	R                  (       aM  [        U[        5      (       a8  UR                  S   R                  5       u  p«XK   R                  U
5        X•U'   Ms  UR                  U5        M†     / nU GHj  nXK   nUR                  5         U(       d  M!  SnUS   =pïXç;   a  US-  nUS-  nXç;   a  M  US:”  aè  [        SU-  U-  U-  5      SU-  -  [        Xû-  5      -  nS n/ n[        U5       H@  nUS-  n[        X¾-  SS9nUR                  U5        [        UU   U=(       d    UU   5      nMB     [        U5       HI  nUR                  5       n[        X¾-  SS9nUU==   U-  ss'   UU   (       a  M8  UR!                  U5        MK     UR                  UU-  5        O3[        UR                  S5      U-  5      nUR                  X…U   -  5        U(       a  GMI  GMm     U(       a6  [#        XÆ-   U VVs/ s H  o´U     H  n[        XÛ-  SS9PM     M     snn-   6 n U $ s  snnf )Nr   r_   rF   Frk   )rm   rn   r   rp   r7   r  rÁ   r6   r   rÀ   r`   Úsortr   rÄ   rÃ   rr   r  r   )r/   r¾   rt   rc   r7   ÚcossÚotherrÇ   rx   rY   rþ   r:   rÖ   rX   ÚccÚciÚnewargÚtakeÚccsrg   Úkeyr;   s                        €r0   r;   ÚTRmorrie.<locals>.f”  sj  ø€ Ø�y�yØˆIÞØ×$Ñ$Ó&‰DˆAÙ�Q˜“7™1˜Q ›7‘?Ð"äœ4Ó ˆØˆØˆØ—”ˆAØ—=‘=“?‰DˆAØ�|�|¤
¨1¬c× 2Ñ 2ØŸ™˜q™	×.Ñ.Ó0‘�Ø‘—‘˜rÔ"Ø�Q“à—‘˜Q–ñ ð ˆÜˆAØ‘ˆAØ�F‰FŒHß�!Ø�Ø˜A™$��Ø“gØ˜‘F�AØ˜!‘G�Bð •gð �q“5Ü   A¡ b¡¨¡›^¨A¨q©DÑ0´°R±T³Ñ:�Fà�DØ�CÜ" 1žX˜Ø˜a™˜Ü! !¡$°Ñ7˜ØŸ
™
 2œÜ" 4¨¡9¨d×.?°d¸3±iÓ@šñ	 &ô # 1žX˜Ø ŸW™W›Y˜Ü! !¡$°Ñ7˜Ø˜S›	 TÑ)›	Ø# CŸy™yØŸH™H RžLñ &ð —J‘J˜v t™|Õ,ä˜AŸE™E !›H Q™J›�AØ—L‘L ¨¡G¡Ô,÷5 ”!ñ ö> Ü�s‘{Ù26ô&IÚ26¨QÀQÅ¸1”�A‘C %Ô(ÁÑ(±$ò&Iñ Ið KˆBð ˆ	ùó&Is   É/"JrÞ   r   r=   s    @r0   ÚTRmorrierC  Y  s   ø€ ÷v7ôr �R˜ÓÐr2   c                 ó&   ^• U4S jn[        X5      $ )aÒ  Convert factored powers of sin and cos identities into simpler
expressions.

Examples
========

>>> from sympy.simplify.fu import TR14
>>> from sympy.abc import x, y
>>> from sympy import cos, sin
>>> TR14((cos(x) - 1)*(cos(x) + 1))
-sin(x)**2
>>> TR14((sin(x) - 1)*(sin(x) + 1))
-cos(x)**2
>>> p1 = (cos(x) + 1)*(cos(x) - 1)
>>> p2 = (cos(y) - 1)*2*(cos(y) + 1)
>>> p3 = (3*(cos(y) - 1))*(3*(cos(y) + 1))
>>> TR14(p1*p2*p3*(x - 1))
-18*(x - 1)*sin(x)**2*sin(y)**4

c           	      óö  >• U R                   (       d  U $ T(       aI  U R                  5       u  pU[        R                  La$  [	        USS9n[	        USS9nX1:w  d  XB:w  a  X4-  n U $ / n/ nU R
                   Hú  nUR                  (       aJ  UR                  5       u  p‰U	R                  (       d$  UR                  (       d  UR                  U5        M[  UnO[        R                  n	[        U5      n
U
(       a  U
S   R                  [        [        4;  a:  U	[        R                  L a  UR                  U5        OUR                  Xy-  5        M×  U
u  p¼nUR                  X¹R                  XœX×45        Mü     [!        [#        U5      5      n[%        U5      n[!        ['        S5      5      =nu  nnpœp×U(       Ga#  UR)                  S5      nU(       Gaæ  US   nUU	   R                  (       Ga0  UU	   R                  (       Ga  UU   UU   :X  Ga  UU   UU   :w  Ga   UR)                  S5      n[+        UU	   UU	   5      nUU	   U:w  a5  U Vs/ s H  nUU   PM
     nnUU	==   U-  ss'   UR-                  SU5        O=UU	   U:w  a4  U Vs/ s H  nUU   PM
     nnUU	==   U-  ss'   UR-                  SU5        [/        UU   [        5      (       a  [        nO[        nUR                  UU   * UU   -  U" UU   R
                  S   5      S-  -  U-  5        GMj  OœUU	   UU	   :X  a�  UU   UU   :X  a„  UU   UU   :w  ax  UR)                  S5      nUU	   n[/        UU   [        5      (       a  [        nO[        nUR                  UU   * UU   -  U" UU   R
                  S   5      S-  -  U-  5        GM  UR                  UU   UU	   -  5        U(       a  GM#  [%        U5      U:w  a  [1        U6 n U $ s  snf s  snf )NFr½   r_   r—   r   rF   )rm   rn   r   r8   ÚTR14r7   rJ   r  rS   rT   r`   r   rU   r   r   rü   rp   r   rW   rÄ   rr   rÃ   Úinsertr6   r   )r/   rt   rc   rÅ   rÆ   r;  Úprocessr:   rx   rY   rÿ   r£   r;   ÚsiÚnotherrq   rv   ÚAÚBr?  rg   Úremr¾   s                         €r0   r;   ÚTR14.<locals>.fæ  s}  ø€ Ø�y�yØˆIæð ×$Ñ$Ó&‰DˆAØœŸ™Š~Ü˜A UÑ+�Ü˜A UÑ+�Ø“9 £	Ø™�BØ�	àˆØˆØ—”ˆAØ�x�xØ—}‘}“‘�ØŸŸ¨¯¯Ø—L‘L ”OÙØ‘ä—E‘E�Ü˜A“ˆAÞ˜˜!™Ÿ	™	¬#¬s¨Ó3ØœŸ™’:Ø—L‘L •Oà—L‘L ¡Ô&ÙØ‰HˆA�"Ø�N‰N˜AŸ{™{¨A°"Ð8Ö9ñ# ô( ”w˜wÓ'Ó(ˆô �U“ˆô &*¬%°«(£^Ð3ˆÑ"��1�a˜BçØ—‘˜A“ˆAßØ˜A‘J�à�Q‘4—>—>�> a¨¡d§n§n nà˜‘t˜q ™t”|Ø˜R™5 A b¡Eœ>Ø '§¡¨A£˜AÜ#& q¨¡t¨Q¨q©T£?˜Dð  ! ™t t›|Ù59Ó&:²T° q¨¤t±T Ð&:Ø # A£¨$¡£Ø '§¡¨q°#Õ 6Ø!" 1¡¨£Ù59Ó&:²T° q¨¤t±T Ð&:Ø # A£¨$¡£Ø '§¡¨q°#Ô 6ä)¨!¨A©$´×4Ñ4Ü$'¡ä$' Ø!ŸL™L¨1¨Q©4¨%°°!±©*±Q°q¸±t·y±yÀ±|³_ÀaÑ5GÑ*GÈ$Ñ)NÔOÚ$øà�q‘T˜Q˜q™T“\à˜‘t˜q ™t“|Ø˜R™5 A b¡E›>Ø '§¡¨A£˜AØ#$ Q¡4˜DÜ)¨!¨A©$´×4Ñ4Ü$'¡ä$' Ø!ŸL™L¨1¨Q©4¨%°°!±©*±Q°q¸±t·y±yÀ±|³_ÀaÑ5GÑ*GÈ$Ñ)NÔOÚ$ð �L‰L˜˜1™˜q ™t™Ô$÷Y ‰gô\ ˆu‹:˜ÓÜ�e�ˆBàˆ	ùòE ';ùò ';s   ÉO1ÊO6r   rË   s    ` r0   rF  rF  Ð  s   ø€ õ,^ô@ �RÓÐr2   c                 ó*   ^^• UU4S jn[        X5      $ )zúConvert sin(x)**-2 to 1 + cot(x)**2.

See _TR56 docstring for advanced use of ``max`` and ``pow``.

Examples
========

>>> from sympy.simplify.fu import TR15
>>> from sympy.abc import x
>>> from sympy import sin
>>> TR15(1 - 1/sin(x)**2)
-cot(x)**2

c           	      ó4  >• [        U [        5      (       a  [        U R                  [        5      (       d  U $ U R                  nUS-  S:X  a(  [        U R                  US-   -  5      U R                  -  $ SU -  n[        U[        [        S TTS9nX2:w  a  Un U $ )NrF   r_   c                 ó   • SU -   $ r^   r¬   r…   s    r0   r‡   Ú!TR15.<locals>.f.<locals>.<lambda>b  ó   € ¨!¨aª%r2   r¯   )r6   r   rK   r   r    ÚTR15r©   r    ©r/   rY   Úiar:   r¥   r¦   s       €€r0   r;   ÚTR15.<locals>.fY  ó†   ø€ Ü˜2œs×#Ñ#¬
°2·7±7¼C×(@Ñ(@ØˆIà�F‰FˆØˆq‰5�A‹:Ü˜Ÿ™ ! a¡%Ñ(Ó)¨"¯'©'Ñ1Ð1àˆr‰TˆÜ�"”cœ3¡°S¸cÑBˆØ‹7ØˆBØˆ	r2   r   ©r/   r¥   r¦   r;   s    `` r0   rT  rT  I  ó   ù€ ö ô �RÓÐr2   c                 ó*   ^^• UU4S jn[        X5      $ )zúConvert cos(x)**-2 to 1 + tan(x)**2.

See _TR56 docstring for advanced use of ``max`` and ``pow``.

Examples
========

>>> from sympy.simplify.fu import TR16
>>> from sympy.abc import x
>>> from sympy import cos
>>> TR16(1 - 1/cos(x)**2)
-tan(x)**2

c           	      ó4  >• [        U [        5      (       a  [        U R                  [        5      (       d  U $ U R                  nUS-  S:X  a(  [        U R                  US-   -  5      U R                  -  $ SU -  n[        U[        [        S TTS9nX2:w  a  Un U $ )NrF   r_   c                 ó   • SU -   $ r^   r¬   r…   s    r0   r‡   Ú!TR16.<locals>.f.<locals>.<lambda>ƒ  rS  r2   r¯   )r6   r   rK   r   r    rT  r©   r   rU  s       €€r0   r;   ÚTR16.<locals>.fz  rX  r2   r   rY  s    `` r0   ÚTR16r`  j  rZ  r2   c                 ó   • S n[        X5      $ )a   Convert f(x)**-i to g(x)**i where either ``i`` is an integer
or the base is positive and f, g are: tan, cot; sin, csc; or cos, sec.

Examples
========

>>> from sympy.simplify.fu import TR111
>>> from sympy.abc import x
>>> from sympy import tan
>>> TR111(1 - 1/tan(x)**2)
1 - cot(x)**2

c                 ó°  • [        U [        5      (       aQ  U R                  R                  (       d8  U R                  R
                  (       a  U R                  R                  (       d  U $ [        U R                  [        5      (       a0  [        U R                  R                  S   5      U R                  * -  $ [        U R                  [        5      (       a0  [        U R                  R                  S   5      U R                  * -  $ [        U R                  [        5      (       a0  [        U R                  R                  S   5      U R                  * -  $ U $ r5   )r6   r   rK   rT   r    rS   Úis_negativer   r    r7   r   r"   r   r!   r.   s    r0   r;   ÚTR111.<locals>.fš  s×   € ä�rœ3×ÑØ�W‰W× ×  B§F¡F×$5×$5¸"¿&¹&×:L×:LØˆIä�b—g‘gœs×#Ñ#Ü�r—w‘w—|‘| A‘Ó'¨"¯&©&¨Ñ0Ð0Ü˜Ÿ™¤×%Ñ%Ü�r—w‘w—|‘| A‘Ó'¨"¯&©&¨Ñ0Ð0Ü˜Ÿ™¤×%Ñ%Ü�r—w‘w—|‘| A‘Ó'¨"¯&©&¨Ñ0Ð0Øˆ	r2   r   r=   s     r0   ÚTR111re  ‹  s   € òô �RÓÐr2   c                 ó*   ^^• UU4S jn[        X5      $ )a<  Convert tan(x)**2 to sec(x)**2 - 1 and cot(x)**2 to csc(x)**2 - 1.

See _TR56 docstring for advanced use of ``max`` and ``pow``.

Examples
========

>>> from sympy.simplify.fu import TR22
>>> from sympy.abc import x
>>> from sympy import tan, cot
>>> TR22(1 + tan(x)**2)
sec(x)**2
>>> TR22(1 + cot(x)**2)
csc(x)**2

c           	      óÚ   >• [        U [        5      (       a$  U R                  R                  [        [
        4;   d  U $ [        U [
        [        S TTS9n [        U [        [        S TTS9n U $ )Nc                 ó   • U S-
  $ r^   r¬   r…   s    r0   r‡   Ú!TR22.<locals>.f.<locals>.<lambda>Á  ó   € ¨1¨qª5r2   r¯   c                 ó   • U S-
  $ r^   r¬   r…   s    r0   r‡   ri  Â  rj  r2   )	r6   r   rK   rU   r    r   r©   r!   r"   r°   s    €€r0   r;   ÚTR22.<locals>.f½  sU   ø€ Ü˜2œs×#Ñ#¨¯©¯©¼¼c¸
Ó(BØˆIä�2”sœC¡°c¸sÑCˆÜ�2”sœC¡°c¸sÑCˆØˆ	r2   r   rY  s    `` r0   ÚTR22rm  «  s   ù€ ö$ô �RÓÐr2   c                 ó   • S n[        X5      $ )aÓ  Convert sin(x)**n and cos(x)**n with positive n to sums.

Examples
========

>>> from sympy.simplify.fu import TRpower
>>> from sympy.abc import x
>>> from sympy import cos, sin
>>> TRpower(sin(x)**6)
-15*cos(2*x)/32 + 3*cos(4*x)/16 - cos(6*x)/32 + 5/16
>>> TRpower(sin(x)**3*cos(2*x)**4)
(3*sin(x)/4 - sin(3*x)/4)*(cos(4*x)/2 + cos(8*x)/8 + 3/8)

References
==========

.. [1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Power-reduction_formulae

c                 óÚ  • [        U [        5      (       a%  [        U R                  [        [        45      (       d  U $ U R                  5       u  pUR                  S   nUR                  (       Gag  UR                  (       GaU  UR                  (       af  [        U[        5      (       aQ  SSU-
  -  [        [        US-   S-  5       Vs/ s H#  n[        X$5      [	        USU-  -
  U-  5      -  PM%     sn6 -  n GOµUR                  (       a”  [        U[        5      (       a  SSU-
  -  [        R                  US-
  S-  -  -  [        [        US-   S-  5       Vs/ s H7  n[        X$5      [        R                  U-  -  [        USU-  -
  U-  5      -  PM9     sn6 -  n GOUR                  (       ab  [        U[        5      (       aM  SSU-
  -  [        [        US-  5       Vs/ s H#  n[        X$5      [	        USU-  -
  U-  5      -  PM%     sn6 -  n O�UR                  (       aŒ  [        U[        5      (       aw  SSU-
  -  [        R                  US-  -  -  [        [        US-  5       Vs/ s H7  n[        X$5      [        R                  U-  -  [	        USU-  -
  U-  5      -  PM9     sn6 -  n UR                  (       a  U SU* -  [        X"S-  5      -  -  n U $ s  snf s  snf s  snf s  snf r2  )r6   r   rK   r   r   r  r7   rÁ   rT   Úis_oddr   rÄ   r   r   r!  Úis_even)r/   rx   rt   r†   rX   s        r0   r;   ÚTRpower.<locals>.fÝ  sœ  € Ü˜2œs×#Ñ#¬
°2·7±7¼SÄ#¸J×(GÑ(GØˆIØ�~‰~Ó‰ˆØ�F‰F�1‰IˆØ�<�<ˆ<˜AŸMŸM˜MØ�x�xœJ q¬#×.Ñ.Ø˜˜1™‘XœcÜ" A¨¡E¨1¡9Ô-ó$/Ú-˜ô %-¨Q£N´3¸¸A¸a¹C¹À±{Ó3CÔ$CÙ-ñ$/ð 0ñ 0’à——œj¨¬C×0Ñ0Ø˜˜1™‘XœaŸm™m¨q°©s°A©gÑ6Ñ6´sÜ?DÀaÈ!ÁeÈQÁYÔ?Oó=QÚ?O¸!ô >FÀa»^Ü—M‘M 1Ñ$ñ>%Ü%(¨!¨a°©c©'°1©Ó%5ô>6Ù?Oñ=Qð 8Rñ R’à——œz¨!¬S×1Ñ1Ø˜˜1™‘XœcÜ" 1 Q¡3œZó$)Ú'˜ô %-¨Q£N´3¸¸A¸a¹C¹À±{Ó3CÔ$CÙ'ñ$)ð *ñ *‘à——œz¨!¬S×1Ñ1Ø˜˜1™‘XœaŸm™m¨a°©cÑ2Ñ2´3Ü?DÀQÀqÁS¼zó9KÚ?I¸!ô :BÀ!»Ü—M‘M 1Ñ$ñ:%Ü%(¨!¨a°©c©'°1©Ó%5ô:6Ù?Iñ9Kð 4Lñ L�à�y�yØ�a˜1˜"‘gœh q¨A©#Ó.Ñ.Ñ.�Øˆ	ùò$/ùò=Qùò$)ùò9Ks   Ã*K
Å>K
Ç *K#
É*>K(
r   r=   s     r0   ÚTRpowerrs  È  s   € ò*ô, �RÓÐr2   c                 ó>   • [        U R                  [        5      5      $ )zÁReturn count of trigonometric functions in expression.

Examples
========

>>> from sympy.simplify.fu import L
>>> from sympy.abc import x
>>> from sympy import cos, sin
>>> L(cos(x)+sin(x))
2
)r   Úcountr$   r.   s    r0   ÚLrv  ö  s   € ô ˆR�X‰XÔ+Ó,Ó-Ð-r2   c                 ó8   • [        U 5      U R                  5       4$ rI   )rv  Ú	count_opsr…   s    r0   r‡   r‡   *  s   € œa ›d A§K¡K£MÑ2r2   c           
      ó†  • [        [        U5      n[        [        U5      nU n[        U 5      n [	        U [
        5      (       d1  U R                  " U R                   Vs/ s H  n[        XQS9PM     sn6 $ [        U 5      n U R                  [        [        5      (       aF  U" U 5      nU" U5      U" U 5      :  a  Un U R                  [        [        5      (       a  [        U 5      n U R                  [        [        5      (       a(  U" U 5      n[!        [#        U5      5      n[%        X@Xg/US9n [%        ['        U 5      XS9$ s  snf )a  Attempt to simplify expression by using transformation rules given
in the algorithm by Fu et al.

:func:`fu` will try to minimize the objective function ``measure``.
By default this first minimizes the number of trig terms and then minimizes
the number of total operations.

Examples
========

>>> from sympy.simplify.fu import fu
>>> from sympy import cos, sin, tan, pi, S, sqrt
>>> from sympy.abc import x, y, a, b

>>> fu(sin(50)**2 + cos(50)**2 + sin(pi/6))
3/2
>>> fu(sqrt(6)*cos(x) + sqrt(2)*sin(x))
2*sqrt(2)*sin(x + pi/3)

CTR1 example

>>> eq = sin(x)**4 - cos(y)**2 + sin(y)**2 + 2*cos(x)**2
>>> fu(eq)
cos(x)**4 - 2*cos(y)**2 + 2

CTR2 example

>>> fu(S.Half - cos(2*x)/2)
sin(x)**2

CTR3 example

>>> fu(sin(a)*(cos(b) - sin(b)) + cos(a)*(sin(b) + cos(b)))
sqrt(2)*sin(a + b + pi/4)

CTR4 example

>>> fu(sqrt(3)*cos(x)/2 + sin(x)/2)
sin(x + pi/3)

Example 1

>>> fu(1-sin(2*x)**2/4-sin(y)**2-cos(x)**4)
-cos(x)**2 + cos(y)**2

Example 2

>>> fu(cos(4*pi/9))
sin(pi/18)
>>> fu(cos(pi/9)*cos(2*pi/9)*cos(3*pi/9)*cos(4*pi/9))
1/16

Example 3

>>> fu(tan(7*pi/18)+tan(5*pi/18)-sqrt(3)*tan(5*pi/18)*tan(7*pi/18))
-sqrt(3)

Objective function example

>>> fu(sin(x)/cos(x))  # default objective function
tan(x)
>>> fu(sin(x)/cos(x), measure=lambda x: -x.count_ops()) # maximize op count
sin(x)/cos(x)

References
==========

.. [1] https://www.sciencedirect.com/science/article/pii/S0895717706001609
)Úmeasure)rA  )r'   ÚRL1ÚRL2r   r6   r   rU   r7   Úfur>   Úhasr   r    rB   r   r   r¿   rC  rÃ   rz   )r/   rz  ÚfRL1ÚfRL2rÕ   r:   Úrv1Úrv2s           r0   r}  r}  *  s  € ôL ”#�wÓ€DÜ”#�wÓ€Dà
€CÜ	�‹€BÜ�bœ$×ÑØ�wŠw¸¿ºÓAº°Aœ˜AÔ/¹ÑAÐBÐBÜ	ˆR‹€BØ	‡v�vŒc”3×ÑÙ�2‹hˆÙ�C‹L™7 2›;Ó&ØˆBØ�6‰6”#”s×ÑÜ�R“ˆBØ	‡v�vŒc”3×ÑÙ�2‹hˆÜ”(˜3“-Ó ˆÜ�#˜3Ð$¨'Ñ2ˆÜŒt�B‹x˜Ñ)Ð)ùò Bs   ÁD>c                 ór  • [        [        5      nU(       aV  U R                   HE  nUR                  5       u  peUS:  a  U* nU* nXFU(       a  U" U5      OS4   R	                  U5        MG     OPU(       a>  U R                   H-  nU[
        R                  U" U5      4   R	                  U5        M/     O[        S5      e/ nSnU Ha  n	XI   n
U	u  pk[        U
5      S:”  a1  [        U
SS06nU" U5      nXÜ:w  a  UnSnUR	                  Xl-  5        MK  UR	                  XjS   -  5        Mc     U(       a  [        U6 n U $ )zÿApply ``do`` to addends of ``rv`` that (if ``key1=True``) share at least
a common absolute value of their coefficient and the value of ``key2`` when
applied to the argument. If ``key1`` is False ``key2`` must be supplied and
will be the only key applied.
r   r_   zmust have at least one keyFrl   T)
r   rp   r7   rÀ   r`   r   r8   Ú
ValueErrorrW   r   )r/   rÜ   Úkey2Úkey1Úabscr:   rÇ   r7   rÒ   rX   rh   r*  rY   rÖ   s                 r0   rß   rß   …  s(  € ô ”tÓ€DÞØ—”ˆAØ—>‘>Ó#‰DˆAØ�1‹uØ�B�Ø�B�Ø¦‘T˜!”W¨!Ð,Ñ-×4Ñ4°QÖ7ò ö 
Ø—”ˆAØ”!—%‘%™˜a›Ð!Ñ"×)Ñ)¨!Ö,ò ô Ð5Ó6Ð6à€DØ
€CÛˆØ‰GˆØ‰ˆÜˆq‹6�A‹:Ü�QÐ' Ñ'ˆAÙ�Q“%ˆCØ‹xØ�Ø�Ø�K‰K˜™Öà�K‰K˜˜A™$™Öñ ö Ü�$ˆZˆà€Ir2   z~
    TR0 TR1 TR2 TR3 TR4 TR5 TR6 TR7 TR8 TR9 TR10 TR10i TR11
    TR12 TR13 L TR2i TRmorrie TR12i
    TR14 TR15 TR16 TR111 TR22c                  ó   • [        S5      $ r  ©r#   r¬   r2   r0   Ú_ROOT2rŠ  ¶  ó   € ä�‹7€Nr2   c                  ó   • [        S5      $ )Nr–   r‰  r¬   r2   r0   ró   ró   »  r‹  r2   c                  ó   • S[        S5      -  $ )Nr_   r–   r‰  r¬   r2   r0   rô   rô   À  s   € àŒT�!‹W‰9Ðr2   c           	      óh  ^• X4 Vs/ s H  n[        U5      PM     snu  pU R                  U5      u  pEU R                  U5      R                  5       nS=px[        R
                  UR                  ;   a#  UR                  [        R
                  5      nU* nO@[        R
                  UR                  ;   a"  UR                  [        R
                  5      nU* nXE4 Vs/ s H  o3R                  5       PM     snu  pS n	U	" X5      n
U
c  gU
u  p¼nU	" X5      n
U
c  gU
u  pïnU(       d  U(       d  U(       a"  [        U[        5      (       a  XïUX¼U4u  p¼pÞnnX‡p‡U(       da  U=(       d    UnU=(       d    Un[        UUR                  5      (       d  gXgUUR                  S   UR                  S   [        U[        5      4$ U(       d¾  U(       d·  U(       a°  U(       a©  U(       a¢  U(       a›  [        XÍR                  5      [        UUR                  5      La  gXÍ4 Vs1 s H  nUR                  iM     snm[        U4S jUU4 5       5      (       d  gXgXŒR                  S   UR                  S   [        XÍR                  5      4$ U(       a  U(       d!  U(       a  U(       d  U(       a  Uc  Ub  Uc  Uc  gU=(       d    UnU=(       d    UnUR                  UR                  :w  a  gU(       d  [        R                  nU(       d  [        R                  nX¾L a(  U[        5       -  nXgUUR                  S   [         S-  S4$ X¾-  [#        5       :X  a#  USU-  -  nXgUUR                  S   [         S	-  S4$ X¾-  [%        5       :X  a#  USU-  -  nXgUUR                  S   [         S
-  S4$ gs  snf s  snf s  snf )a�  Return the gcd, s1, s2, a1, a2, bool where

If two is False (default) then::
    a + b = gcd*(s1*f(a1) + s2*f(a2)) where f = cos if bool else sin
else:
    if bool, a + b was +/- cos(a1)*cos(a2) +/- sin(a1)*sin(a2) and equals
        n1*gcd*cos(a - b) if n1 == n2 else
        n1*gcd*cos(a + b)
    else a + b was +/- cos(a1)*sin(a2) +/- sin(a1)*cos(a2) and equals
        n1*gcd*sin(a + b) if n1 = n2 else
        n1*gcd*sin(b - a)

Examples
========

>>> from sympy.simplify.fu import trig_split
>>> from sympy.abc import x, y, z
>>> from sympy import cos, sin, sqrt

>>> trig_split(cos(x), cos(y))
(1, 1, 1, x, y, True)
>>> trig_split(2*cos(x), -2*cos(y))
(2, 1, -1, x, y, True)
>>> trig_split(cos(x)*sin(y), cos(y)*sin(y))
(sin(y), 1, 1, x, y, True)

>>> trig_split(cos(x), -sqrt(3)*sin(x), two=True)
(2, 1, -1, x, pi/6, False)
>>> trig_split(cos(x), sin(x), two=True)
(sqrt(2), 1, 1, x, pi/4, False)
>>> trig_split(cos(x), -sin(x), two=True)
(sqrt(2), 1, -1, x, pi/4, False)
>>> trig_split(sqrt(2)*cos(x), -sqrt(6)*sin(x), two=True)
(2*sqrt(2), 1, -1, x, pi/6, False)
>>> trig_split(-sqrt(6)*cos(x), -sqrt(2)*sin(x), two=True)
(-2*sqrt(2), 1, 1, x, pi/3, False)
>>> trig_split(cos(x)/sqrt(6), sin(x)/sqrt(2), two=True)
(sqrt(6)/3, 1, 1, x, pi/6, False)
>>> trig_split(-sqrt(6)*cos(x)*sin(y), -sqrt(2)*sin(x)*sin(y), two=True)
(-2*sqrt(2)*sin(y), 1, 1, x, pi/3, False)

>>> trig_split(cos(x), sin(x))
>>> trig_split(cos(x), sin(z))
>>> trig_split(2*cos(x), -sin(x))
>>> trig_split(cos(x), -sqrt(3)*sin(x))
>>> trig_split(cos(x)*cos(y), sin(x)*sin(z))
>>> trig_split(cos(x)*cos(y), sin(x)*sin(y))
>>> trig_split(-sqrt(6)*cos(x), sqrt(2)*sin(x)*sin(y), two=True)
r_   c                 óÐ  • S=p#[         R                  nU R                  (       Gaq  U R                  5       u  p@[	        U R
                  5      S:”  d  U(       d  gU R                  (       a  [        U R
                  5      nOU /nUR                  S5      n [        U [        5      (       a  U nOL[        U [        5      (       a  U nO4U R                  (       a"  U R                  [         R                  L a  X@-  nOgU(       a}  US   n[        U[        5      (       a  U(       a  UnOYUnOV[        U[        5      (       a  U(       a  UnO7UnO4UR                  (       a"  UR                  [         R                  L a  XF-  nOgU[         R                  La  XBU4$ SX#4$ [        U [        5      (       a  U nO[        U [        5      (       a  U nUc  Uc  gU[         R                  La  UOSnXBU4$ )aE  Return ``a`` as a tuple (r, c, s) such that
``a = (r or 1)*(c or 1)*(s or 1)``.

Three arguments are returned (radical, c-factor, s-factor) as
long as the conditions set by ``two`` are met; otherwise None is
returned. If ``two`` is True there will be one or two non-None
values in the tuple: c and s or c and r or s and r or s or c with c
being a cosine function (if possible) else a sine, and s being a sine
function (if possible) else oosine. If ``two`` is False then there
will only be a c or s term in the tuple.

``two`` also require that either two cos and/or sin be present (with
the condition that if the functions are the same the arguments are
different or vice versa) or that a single cosine or a single sine
be present with an optional radical.

If the above conditions dictated by ``two`` are not met then None
is returned.
NrF   r   )r   r8   rm   rÀ   rW   r7   rp   rr   r6   r   r   rJ   r    rò   )r:   rë   rÇ   rÈ   rþ   r7   rx   s          r0   Úpow_cos_sinÚtrig_split.<locals>.pow_cos_sin  sr  € ð( ˆˆÜ�U‰UˆØ�8�8ˆ8Ø—N‘NÓ$‰EˆBÜ�1—6‘6‹{˜Q‹¦cØØ�x�xÜ˜AŸF™F“|‘à�s�Ø—‘˜“ˆAÜ˜!œS×!Ñ!Ø‘Ü˜Aœs×#Ñ#Ø‘Ø——˜aŸe™e¤q§v¡všoØ‘‘àÞØ˜‘G�Ü˜a¤×%Ñ%ÞØ™à™Ü ¤3×'Ñ'ÞØ™à™Ø—X—X !§%¡%¬1¯6©6¢/Ø‘G‘BàØ¤1§5¡5š�2°qÐ8Ð8¨d°AÐ8Ð8Ü˜œ3×ÑØ‰AÜ˜œ3×ÑØˆAØ‰9˜™ØØœQŸU™U’?‰R¨ˆØ�aˆxˆr2   Nr   c              3   ó@   >#   • U  H  oR                   T;   v •  M     g 7frI   )r7   )rL   rg   r7   s     €r0   rN   Útrig_split.<locals>.<genexpr>^  s   øé € Ð<²8¨aŸ6™6 Tž>²8ùs   ƒr   FrF   r–   r—   )r   r,   rØ   Úas_exprr   r!  ÚfactorsÚquor6   r   rU   r7   r   r"  r8   rŠ  r   ró   rô   )r:   rx   rë   rg   ÚuaÚubrØ   rÙ   rÚ   r�  rÿ   ÚcoaÚcaÚsaÚcobÚcbÚsbrÇ   rÈ   rÓ   r7   s                       @r0   rÑ   rÑ   Å  s  ø€ ðd "#¡Ó'¢˜1ŒG�AŽJ¡Ñ'�D€AØ�X‰X�a‹[�F€BØ
�%‰%�‹(×
Ñ
Ó
€CØ€K€BÜ‡}�}˜Ÿ
™
Ó"Ø�V‰V”A—M‘MÓ"ˆØˆS‰Ü	
�‰˜"Ÿ*™*Ó	$Ø�V‰V”A—M‘MÓ"ˆØˆSˆØ"$¡Ó*¢˜A�I‰IŽK¡Ñ*�D€Aò?ñD 	�AÓ€AØ�yØØ�K€CˆRÙ�AÓ€AØ�yØØ�K€CˆRö –Bž"¤¨B´×!4Ñ!4Ø#&¨B°¸Ð#;Ñ ˆ�˜"˜bØˆBÞØ�H�"ˆØ�H�"ˆÜ˜!˜QŸV™V×$Ñ$ØØ˜˜AŸF™F 1™I q§v¡v¨a¡y´*¸QÄÓ2DÐDÐDæž3Þ–ržb¦RÜ˜b§'¡'Ó*´*¸RÀÇÁÓ2IÒIØØ)+©Ó1ª 1˜Ÿœ©Ñ1�ÜÔ<°B¸±8Ó<×<Ñ<ØØ §G¡G¨A¡J°·±¸±
¼JÀrÏ7É7Ó<SÐSÐSÞ–"žžrÞ�R‘Z B¡J°"±*ÀÁØØ�H�"ˆØ�H�"ˆØ�6‰6�Q—V‘VÓØÞÜ—%‘%ˆCÞÜ—%‘%ˆCØŠ:Ø”6“8‰OˆCØ˜B §¡ q¡	¬2¨a©4°Ð6Ð6Ø‰Wœ›Ó Ø�1�S‘5‰LˆCØ˜B §¡ q¡	¬2¨a©4°Ð6Ð6Ø‰Wœ	›Ó#Ø�1�S‘5‰LˆCØ˜B §¡ q¡	¬2¨a©4°Ð6Ð6ð $ùòw (ùò +ùòx 2s   ‡N%ÃN*ÈN/c                 ó
  • U R                   (       a  [        U R                  5      S:w  a  gU R                  u  pU[        R                  [        R
                  4;   a^  [        R
                  nUR                  (       a9  UR                  S   R                  (       a  UR                  S   S:  a  U* U* p!U* nX2U4$ U R                   Vs/ s H  n[        U5      PM     snu  pUR                  U5      u  pVUR                  U5      R                  5       n[        R                  UR                  ;   a$  UR                  [        R                  5      nSnSn	OE[        R                  UR                  ;   a$  UR                  [        R                  5      nSnSn	OS=p‰XV4 Vs/ s H  oDR                  5       PM     snu  pU[        R
                  L a  X!p!X˜p˜US:X  a  U* nU	* n	U[        R
                  L a  XqU	4$ gs  snf s  snf )a´  If ``e`` is a sum that can be written as ``g*(a + s)`` where
``s`` is ``+/-1``, return ``g``, ``a``, and ``s`` where ``a`` does
not have a leading negative coefficient.

Examples
========

>>> from sympy.simplify.fu import as_f_sign_1
>>> from sympy.abc import x
>>> as_f_sign_1(x + 1)
(1, x, 1)
>>> as_f_sign_1(x - 1)
(1, x, -1)
>>> as_f_sign_1(-x + 1)
(-1, x, -1)
>>> as_f_sign_1(-x - 1)
(-1, x, 1)
>>> as_f_sign_1(2*x + 2)
(2, x, 1)
rF   Nr   éÿÿÿÿr_   )rV   rW   r7   r   r!  r8   rm   rü   r   r,   rØ   r”  r•  r–  )
rY   r:   rx   r£   rg   r—  r˜  rØ   rÙ   rÚ   s
             r0   r   r   w  s’  € ð* �8�8”s˜1Ÿ6™6“{ aÓ'Øà�6‰6�D€AØŒQ�]‰]œAŸE™EÐ"Ó"Ü�E‰EˆØ�8�8˜Ÿ™˜q™	×+×+°·±°q±	¸A³Ø�2˜�rˆqØ�ˆAØ�Qˆwˆà !§¢Ó'¢˜1ŒG�AŽJ¡Ñ'�D€AØ�X‰X�a‹[�F€BØ
�%‰%�‹(×
Ñ
Ó
€CÜ‡}�}˜Ÿ
™
Ó"Ø�V‰V”A—M‘MÓ"ˆØˆØ‰Ü	
�‰˜"Ÿ*™*Ó	$Ø�V‰V”A—M‘MÓ"ˆØˆØ‰àˆˆØ"$¡Ó*¢˜A�I‰IŽK¡Ñ*�D€AØŒA�E‰E‚zØˆ1ØˆBØ	ˆRƒxØˆdˆØˆSˆàŒA�E‰E‚zØ�rˆzÐð ùò+ (ùò +s   Ã
G;Æ"H c                 ó&   ^• U4S jn[        X5      $ )a  Replace all hyperbolic functions with trig functions using
the Osborne rule.

Notes
=====

``d`` is a dummy variable to prevent automatic evaluation
of trigonometric/hyperbolic functions.


References
==========

.. [1] https://en.wikipedia.org/wiki/Hyperbolic_function
c                 óÔ  >• [        U [        5      (       d  U $ U R                  S   nUR                  (       d  UT-  O2[        R
                  " UR                   Vs/ s H  o"T-  PM	     sn5      n[        U [        5      (       a  [        [        U5      -  $ [        U [        5      (       a  [        U5      $ [        U [        5      (       a  [        [        U5      -  $ [        U [        5      (       a  [        U5      [        -  $ [        U [        5      (       a  [!        U5      $ [        U ["        5      (       a  [%        U5      [        -  $ ['        SU R(                  -  5      es  snf )Nr   úunhandled %s)r6   r   r7   rV   r   rä   r   r   r   r   r   r   r   r   r    r   r!   r   r"   ÚNotImplementedErrorrU   )r/   r:   rg   rc   s      €r0   r;   Ú_osborne.<locals>.fÁ  s   ø€ Ü˜"Ô0×1Ñ1ØˆIØ�G‰G�A‰JˆØ—x—xˆAˆaŠC¤S§^¢^À!Ç&Â&Ó4IÂ&¸Q°q´SÁ&Ñ4IÓ%JˆÜ�bœ$×ÑÜ”S˜“V‘8ˆOÜ˜œD×!Ñ!Ü�q“6ˆMÜ˜œD×!Ñ!Ü”S˜“V‘8ˆOÜ˜œD×!Ñ!Ü�q“6œ!‘8ˆOÜ˜œD×!Ñ!Ü�q“6ˆMÜ˜œD×!Ñ!Ü�q“6œ!‘8ˆOä% n°r·w±wÑ&>Ó?Ð?ùò 5Js   ÁE%r   ©rY   rc   r;   s    ` r0   Ú_osborner§  °  s   ø€ õ"@ô( �Q‹?Ðr2   c                 ó&   ^• U4S jn[        X5      $ )a  Replace all trig functions with hyperbolic functions using
the Osborne rule.

Notes
=====

``d`` is a dummy variable to prevent automatic evaluation
of trigonometric/hyperbolic functions.

References
==========

.. [1] https://en.wikipedia.org/wiki/Hyperbolic_function
c                 ó®  >• [        U [        5      (       d  U $ U R                  S   R                  TSS9u  pUR	                  T[
        R                  05      U[        -  -   n[        U [        5      (       a  [        U5      [        -  $ [        U [        5      (       a  [        U5      $ [        U [        5      (       a  [        U5      [        -  $ [        U [        5      (       a  [        U5      [        -  $ [        U [         5      (       a  [#        U5      $ [        U [$        5      (       a  ['        U5      [        -  $ [)        SU R*                  -  5      e)Nr   T)Úas_Addr£  )r6   r$   r7   Úas_independentÚxreplacer   r8   r   r   r   r   r   r   r   r    r   r!   r   r"   r   r¤  rU   )r/   Úconstr†   r:   rc   s       €r0   r;   Ú_osbornei.<locals>.fè  s   ø€ Ü˜"Ô3×4Ñ4ØˆIØ—7‘7˜1‘:×,Ñ,¨Q°tÐ,Ð<‰ˆØ�J‰J˜œ1Ÿ5™5�zÓ" U¬1¡WÑ,ˆÜ�bœ#×ÑÜ˜“7œ1‘9ÐÜ˜œC× Ñ Ü˜“7ˆNÜ˜œC× Ñ Ü˜“7œ1‘9ÐÜ˜œC× Ñ Ü˜“7œ1‘9ÐÜ˜œC× Ñ Ü˜“7ˆNÜ˜œC× Ñ Ü˜“7œ1‘9Ðä% n°r·w±wÑ&>Ó?Ð?r2   r   r¦  s    ` r0   Ú	_osborneir¯  Ø  s   ø€ õ @ô( �Q‹?Ðr2   c                 ó<  ^^^^	• SSK Jm	  SSKJm  U R	                  [
        5      nU Vs/ s H  o"[        5       4PM     snmU R                  [        T5      5      nT VVs/ s H  u  pEXT4PM
     snnm[        5       m[        UT5      UUUU	4S j4$ s  snf s  snnf )a‚  Return an expression containing hyperbolic functions in terms
of trigonometric functions. Any trigonometric functions initially
present are replaced with Dummy symbols and the function to undo
the masking and the conversion back to hyperbolics is also returned. It
should always be true that::

    t, f = hyper_as_trig(expr)
    expr == f(t)

Examples
========

>>> from sympy.simplify.fu import hyper_as_trig, fu
>>> from sympy.abc import x
>>> from sympy import cosh, sinh
>>> eq = sinh(x)**2 + cosh(x)**2
>>> t, f = hyper_as_trig(eq)
>>> f(fu(t))
cosh(2*x)

References
==========

.. [1] https://en.wikipedia.org/wiki/Hyperbolic_function
r   r|   )Úcollectc           	      ó‚   >• T" T" [        U T5      R                  [        T5      5      5      [        R                  5      $ rI   )r¯  r¬  Údictr   ÚImaginaryUnit)r†   r±  rc   Úrepsr}   s    €€€€r0   r‡   Úhyper_as_trig.<locals>.<lambda>&  s1   ø€ ©'±(Ü�!�Q‹× Ñ ¤ d£Ó,ó3.Ü/0¯©ô+@r2   )
r’   r}   Úsympy.simplify.radsimpr±  Úatomsr$   r   r¬  r³  r§  )
r/   Útrigsrv   ÚmaskedrX   rh   r±  rc   rµ  r}   s
         @@@@r0   Úhyper_as_trigr»  ÿ  s�   û€ õ4 1Ý.ð �H‰HÔ*Ó+€EÙ"'Ó(¢%˜Q”“‹L¡%Ñ(€DØ�[‰[œ˜d›Ó$€Fñ  $Ô$št‘t�qˆQ‹F™tÒ$€Dä‹€Aä�F˜AÓ÷ !@ð @ð @ùò )ùó %s   ªBÁ!Bc                 ó~   • U R                  [        [        5      (       d  U $ [        [	        [        U 5      5      5      $ )a�  Convert products and powers of sin and cos to sums.

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

Applied power reduction TRpower first, then expands products, and
converts products to sums with TR8.

Examples
========

>>> from sympy.simplify.fu import sincos_to_sum
>>> from sympy.abc import x
>>> from sympy import cos, sin
>>> sincos_to_sum(16*sin(x)**3*cos(2*x)**2)
7*sin(x) - 5*sin(3*x) + 3*sin(5*x) - sin(7*x)
)r~  r   r   r¿   r
   rs  )Úexprs    r0   Úsincos_to_sumr¾  *  s.   € ð& �8‰8”Cœ×ÑØˆä”:œg d›mÓ,Ó-Ð-r2   )F)r   FrÞ   rI   )NT)rÚcollectionsr   Úsympy.core.addr   Úsympy.core.cacher   Úsympy.core.exprr   Úsympy.core.exprtoolsr   r   r	   Úsympy.core.functionr
   Úsympy.core.mulr   Úsympy.core.numbersr   r   Úsympy.core.powerr   Úsympy.core.singletonr   Úsympy.core.sortingr   Úsympy.core.symbolr   Úsympy.core.sympifyr   Úsympy.core.traversalr   Ú(sympy.functions.combinatorial.factorialsr   Ú%sympy.functions.elementary.hyperbolicr   r   r   r   r   r   r   Ú(sympy.functions.elementary.trigonometricr   r   r   r    r!   r"   r#   r$   Úsympy.ntheory.factor_r%   Úsympy.polys.polytoolsr&   Úsympy.strategies.treer'   Úsympy.strategies.corer(   r)   Úsympyr*   r1   r>   rB   rz   r“   r�   r©   r±   r¶   rº   r¿   rá   rå   rø   rý   r  r  r/  r6  rC  rF  rT  r`  re  rm  rs  rv  rp   r  ÚCTR1ÚCTR2ÚCTR3ÚCTR4r{  r|  r}  rß   r×   Úfufuncsr³  ÚzipÚlocalsÚgetÚFUrŠ  ró   rô   rÑ   r   r§  r¯  r»  r¾  r¬   r2   r0   Ú<module>rÞ     sÞ  ðÝ #å Ý $Ý  ß AÑ AÝ *Ý ß $Ý  Ý "Ý &Ý #Ý &Ý *Ý =÷<÷ <ñ <÷?÷ ?ó ?å /Ý (Ý (ß 1å ò)òò0ô<qòh.òb5ò@=ô@Bô*Bò*ô0HòV[ô|-ò`}ô@Mò`:ôz òFxòv,ò^tônvôrôBòBô@ò:+ò\.ö" ñ ‰C�Øˆ#ˆs�C˜˜c 3¨¨S°#°t¸TÀ4ÈØˆ(�D˜$  e¨U°Dð:ó;ó <ñ€Sˆ#ˆs�C˜˜c 3¨¨S°#°t¸TÀ4ÈØˆ(�D˜$  e¨U°Dð 
ˆcˆ
�S˜#�J Ð)€à��Sˆz˜C ˜: sÐ+Ð,€à	�3˜Ð˜x¨¨e°SÐ9¸8ÐD€à	ˆeˆ�hÐ€à
ˆC��d˜C  s¨CÐ0€ð 	ˆ#ˆt�S˜#˜tÐ$Øˆ#ˆt�SÐØ	ˆ4��d˜C  c¨4Ð0Øð	€ñ 3ô X*ôv'ðT!÷ "'¡£ð ñ 
‰$‰s�7™D¡¡V£X§\¡\°7Ó!;Ó<Ó=Ó
>Ó?€ð 	ñó 	ðð 	ñó 	ðð 	ñó 	ðôo7òd6òr%òP$òN(@óV.r2   