
    \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    I/var/www/auris/envauris/lib/python3.13/site-packages/sympy/simplify/fu.pyTR0r1       s"     99;&&((    c                     S n[        X5      $ )zReplace 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55Q<C  
A55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q6#a&= C  
Aq6#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  pU(       d  M  X-  PM     snn
-   6 [%        UR'                  5        V
Vs/ s H  u  pU(       d  M  X-  PM     snn
6 -  n U [%        U V
Vs/ s H	  u  pX-  PM     snn
6 [%        U V
Vs/ s H	  u  pX-  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 #2s+Kryy/KRWW^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*$ > *=*=AFFq *=  =56VV= =@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888AFFa(,6!9,q/DyQI.	 
 $-dOLAy"G %4 Dz002AtwA!xx !aV,   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   yyI  "99		I	@ (,QVVXJ1baDk!UU1XJI(,QVVXJ1baDk!UU1XJI	& 	!! A!S!!q	E26adadlHHS^QT12"&&AD14QBw15AD=#affQik"2QT!9:'++qu $1w 
 As##q	E26adadlHHS^adU23"&&AD14 +6 !(((qvvayAEE'9qvvay#..q	q)E:6adadlHHS1-u45"&&AD14- 0 qWWY<YTQ!DADY<<>qwwy6ytqAdady678B#//06Nqt6N1OOOB	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WWXbggaj)*"344IGGAJa,,a"''!*1D0Q0QYUYY 	 c3S#sCc3ODd2hQ 34B	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    akk.ahh.r2   c                 4    U R                   " U R                  6 $ rI   rU   r7   r   s    r0   r   r      s    affaffor2   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./cc_.DEr2   c                     U R                  U R                  S   R                   " U R                  S   R                  6 5      $ r5   r   r   s    r0   r   r      s+    FF166!9>>166!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   
 		bgglla/Ivv~~IFFQJ4IFFSLT!I66Q;I66Q;Qrww||A'*++vvzQFFAIa)!Abggll1o,>,A*BA*EEE166A:IFFAI!"&&)IFFAIQrww||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      $ )zLowering 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    		bggllc1bff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:   IIIIGGLLS#J&VV"''"5"5I+-+<+<+>?+>aJqM+>?DAq&Dq&DyDIty)99!7!7BGG)bggaj.?.?boo/0BIRb$+r"Avv#s#T!W$$QVVAY/((quu//AEEAIFFKKC:- T!&&\"))166;;q>*:155*@AT
!!!$ # IIa3q6A:Q!IDzAAqABBKKRWBG4a78  !fqjBBKKRWBG4a78 !fqj KKAEEG%!fqjBBKK#bg,RW5q89 !fqj KKAEEG%:c4j)**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  XU'   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  ppn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    99	()D4yA~s4y)ABz "1q5#d)4!W:$ g g:&)G&*DG"&C! 5	 * D7DbBrD78ByyV	 %E	',$CRAu 86!8CQ	N23Aqy>AA6aqA#vc1q5!)n,S!a%^;;86!8CQ	N23Aqy>AA6aqAuS!a%^+CQ	N::1 8s   >
GGT)rV   process_common_addends)r/   r   s    @r0   r;   TR9.<locals>.f  s$    yy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   773*$IGGggaj:::GCHH-.CHH~
At$Axx8q6$s1vU";;AtCF%889 9 q6$s1vU";;AtCF%889 9 8q6#a&=3q6#a&=88q6#a&=3q6#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  XU'   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  ppn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    99	()D4yA~s4y)ABz "1q5#d)4!W:$ g g:&)G&*DG"&C! 5	 * D7DbBrD78ByyV	 /$/E	&+#CRAt f8s1q5z>)3q1u:~%f8s1q5z>)3q1u:~%- 8s   >
E)E)c                 >    [        [        U R                  5      5      $ rI   )tupler   free_symbolsr   s    r0   r   "TR10i.<locals>.f.<locals>.<lambda>  s    eGANN$;<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   yyI6	&p $<>
 iii%EWW88ff999166)9 " 2 2 2!I,,Q/"#C! % s!%%L''*  D (1*ik2Az!&s58}!5A$x{2 (%*3ux=%9#(8A;#6$,&)%(1+*C&D&(g#&:$(KK$426EHQK26EHQK$) &: "6 3   4"\\^#-+ $'a(>a2a(>#?+#- - / V	Q iiiP 	 )? #-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   773*$IA$q&	ABxx(vvc3Z'	wwqzQVVAY&II8qD1a4K++Q3q58OI%% 771:**D*9DAssQw!|cc1fQhqsslSNSN77c>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mmD)~~'<<<AEvv#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\     !Av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      $ )zSeparate 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    ww#~Iggaj::GCHH-.CHH~
At$Axx#a&.VFRK!c!fRi-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  oR                  S   PM     sn6 n[        R                  X<'   XU'   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  oR                  S   PM     sn6 nUR                  X<'   XR                  -  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  oR                  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&BJr3//&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%!((s166{a7GA!&&AAA4K 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    yyS\Q.wwa%%*Q*<*<4K +=% /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   		RYY"))I  "vvQVVI	  cmmA&'v&EA2AQVV4V&&)V45q	yyBZ99MM"''* !FI   1 1RWW5H5H5HrwwKDA8AffQi89AVVCF !66	FIByyybgg.$%EE	1 '2 I	 
 cmmLO45v&EA2AsG !FIyy#BZ99"MM"''2()FI FF--1D1DrwwK()FI!'B!yy &bgg 6,-EE	$ EE	C+AffQi+,AB))!%%0E "CFGGAJI#a& IK 'N fc6l*3=@YY[1J=HTQ 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      $ )zChange 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   yyI Rb$+r"Avv#s#T!W$$QVVAY/T
!!!$	 #
 IIq6A:#a&1*IDz!fqjBBKKSWS\1CGCL4HHIJ !fqj KKAEEG%!fqjBBKKCGCL003r73rw<3GGH !fqj KKAEEG%Dz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  pU	R                  (       aM  [        U[        5      (       a8  UR                  S   R                  5       u  pXK   R                  U
5        XU'   Ms  UR                  U5        M     / nU GHj  nXK   nUR                  5         U(       d  M!  SnUS   =pX;   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                  XU   -  5        U(       a  GMI  GMm     U(       a6  [#        X-   U VVs/ s H  oU     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   yyI$$&DAQ71Q7?"4 A==?DA||
1c 2 2q	..0r"QQ  AAFFH!A$gFA!GB g q5 Ab^AqD0RT:FDC"1Xa!!$7

2"49d.?d3i@	 & #1X WWY!!$7S	T)	#CyyHHRL & JJvt|,AEE!HQJALLG,5 ! > s{26&I26QQ1AC%(($&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  pU	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  pnUR                  XR                  XX45        M     [!        [#        U5      5      n[%        U5      n[!        ['        S5      5      =nu  nnppU(       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  OU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}   yyI $$&DA~AU+AU+9	B	Axx}}LLOEEAA!		#s3:LLOLL&HA"NNA{{A"89# ( ww'( U &*%(^3"1aBAAAJQ4>>>adnnntqt|R5AbE> 'AA#&qtQqT?D  !tt|59&:TqtT&: #A$ 'q# 6!"159&:TqtT&: #A$ 'q# 6)!A$44$'$'!LL1Q4%!*Qqtyy|_a5G*G$)NO$qTQqT\tqt|R5AbE> 'AA#$Q4D)!A$44$'$'!LL1Q4%!*Qqtyy|_a5G*G$)NO$ LL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      $ )zConvert 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      2s##
277C(@(@IFFq5A:!a%()"''11rT"c3Sc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      $ )zConvert 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    r3WW  BFF$5$5"&&:L:LIbggs##rww||A'"&&00%%rww||A'"&&00%%rww||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>      1q5r2   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    2s##c
(BI2sCcsC2sCcs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OU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 OU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   2s##
277S#J(G(GI~~FF1I<<<AMMMxxJq#..1Xc"AE19-$/- %-QN3AaC{3C$C-$/ 0 0jC001XammqsAg66s?Da!eQY?O=Q?O! >Fa^MM1$>%%(!ac'1%5>6?O=Q 8R Rz!S111Xc"1Q3Z$)' %-QN3AaC{3C$C'$) * *z!S111Xammac223?DQqSz9K?I! :B!MM1$:%%(!ac'1%5:6?I9K 4L Lyya1"ghqA#...	$/=Q$)9Ks   *K
>K
 *K#
*>K(
r   r=   s     r0   TRpowerrs    s    *, Rr2   c                 >    [        U R                  [        5      5      $ )zReturn 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     RXX+,--r2   c                 8    [        U 5      U R                  5       4$ rI   )rv  	count_opsr   s    r0   r   r   *  s    adAKKM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$wwAAA/ABB	RB	vvc32hCL72;&B66#sRB	vvc32h(3- #3$'2tBx)) 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 $ )zApply ``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>>#DA1uBBT!W!,-44Q7  
A!%%a!"))!,  566D
CGq6A:Q''AQ%CxKKKK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        7Nr2   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!W9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  pnU	" X5      n
U
c  gU
u  pnU(       d  U(       d  U(       a"  [        U[        5      (       a  XUXU4u  ppnnXpU(       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  [        XR                  5      [        UUR                  5      La  gX4 Vs1 s H  nUR                  iM     snm[        U4S jUU4 5       5      (       d  gXgXR                  S   UR                  S   [        XR                  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XL 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   ( UU888NN$EB166{QcxxAFF|sA!S!!As##aeeqvvoGa%%3''XX!%%166/GB1552q88dA883A3A9QUU?Rax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     <8a66T>8s   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 "#'1GAJ'DAXXa[FB
%%(


CKB}}

"VVAMM"S	
"**	$VVAMM"S"$*AIIK*DA?D 	AAyKCRAAyKCR B"B!4!4#&B#; "bBH"H"!QVV$$AFF1Iqvvay*Q2DDD3rbRb''**R2II)+111<B8<<<GGAJ
Jr77<SSS"rRZBJ"*H"H"66QVV%%C%%C:68OCBq	2a466W 1S5LCBq	2a466W	#1S5LCBq	2a4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=pXV4 Vs/ s H  oDR                  5       PM     snu  pU[        R
                  L a  X!p!XpU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   * 88s166{a'66DAQ]]AEE""EE88q	++q	A2rqAQw !'1GAJ'DAXXa[FB
%%(


C}}

"VVAMM"	
"**	$VVAMM""$*AIIK*DAAEEz1B	RxdSAEEzrz + ( +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GGAJxxAaCS^^!&&4I&QqS&4I%Jb$SV8OD!!q6MD!!SV8OD!!q6!8OD!!q6MD!!q6!8O%nrww&>?? 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771:,,Qt,<JJ155z"U1W,b#719C  7NC  719C  719C  7NC  719%nrww&>??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. HH*+E"'(%QL%(D[[d$F  $$ttqQFt$DAFA !@ @ @ ) %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.    & 88C:gdm,--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#sCc3S#tT4(D$eUD:; <S#sCc3S#tT4(D$eUD 
c
S#J)SzC:s+,	3xeS98D	eh
CdCsC0 	#tS#t$#tS	4dCc40	 3 X*v'T! "'  
$s7DVX\\7!;<=
>? 	 	 	 	 	 	o7d6r%P$N(@V.r2   