+
    i                      *   ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIH t  ^ RI!H"t"H#t#H$t$H%t%H&t&H't'H(t( ^ RI)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1 ^ RI2H3t3 ^ RI4H5t5 ^ RI6H7t7 ^ RI8H9t9H:t: ^ RI;H<t< R t=R t>R t?R@R lt@R tAR tBR tCRAR ltDRAR ltER  tFRBR! ltGR" tHRBR# ltIR$ tJRCR& ltKR' tLRBR( ltMR) tNR* tOR+ tPRBR, ltQRAR- ltRRAR. ltSR/ tTRAR0 ltUR1 tVR2 tW]<'       d=   ]X! ]Y! ]:]=]>]?]A]B]D]E]F]G]H]I]K]M]O]@]P]Q]R]S]N]T]U34      4      w  t=t>t?tAtBtDtEtFtGtHtItKtMtOt@tPtQtRtStNtTtU]D]=3]E]=3]9.tZ]K]D]=3]E]=3]=.3t[]P]G]=3]P]G]J]=3]9.t\]B]J3]9.t]]B]A]B]M]B]O]B]=3t^]B]A]I]B]A]K3]D]F]K]B3]\]Z]H][]B]H]H]]3]9.t_R3 3R4 lt`RDR5 ltaR6P                  4       tc]d! ]X! ]e! ]c]X! ]Y! ]f! 4       P                  ]c4      4      4      4      4      th]R7 4       ti]R8 4       tj]R9 4       tkR@R: ltlR; tmR< tnR= toR> tpR? tqR%# )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    V P                  4       P                  4       P                  4       # )zwSimplification of rational polynomials, trying to simplify
the expression, e.g. combine things like 3*x + 2*x, etc....
)normalr&   expandrvs   &q/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/simplify/fu.pyTR0r1       s"     99;&&((    c                    R p\        W4      # )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                 *   \        V \        4      '       d4   V P                  ^ ,          p\        P                  \        V4      ,          # \        V \        4      '       d4   V P                  ^ ,          p\        P                  \        V4      ,          # V # r   )
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                    R p\        W4      # )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                    \        V \        4      '       d/   V P                  ^ ,          p\        V4      \	        V4      ,          # \        V \
        4      '       d/   V P                  ^ ,          p\	        V4      \        V4      ,          # V # 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                &   a V3R lp\        W4      # )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           
      D
  <a V P                   '       g   V # V P                  4       w  rVP                  '       g   VP                  '       d   V # V3R  loVP                  4       p\	        VP                  4       4       Uu. uF,  pS! W1V,          4      '       d   K  W1P                  V4      3NK.  	  ppV'       g   V # VP                  4       p\	        VP                  4       4       Uu. uF,  pS! W2V,          4      '       d   K  W2P                  V4      3NK.  	  ppV'       g   V # VV3R lpV! W4       V! W%4       . pV EF  p\        V\        4      '       d   \        VP                  ^ ,          RR7      pW9   dV   W(,          W,          8X  dC   VP                  \        VP                  ^ ,          4      W,          ,          4       R;W&   W(&   K  S'       ds   ^V,           p	W9   da   W),          W,          8X  dK   VP                  \        VP                  ^ ,          ^,          4      W,          ,          4       R;W&   W)&   EK  EK
  EK  EK  \        V\        4      '       d   \        VP                  ^ ,          RR7      pW9   d[   W(,          W,          8X  dE   VP                  \        VP                  ^ ,          4      W,          ) ,          4       R;W&   W(&   EK  EK  EK  S'       g   EK  VP                  '       g   EK  VP                  ^ ,          \        P                  J g   EK  \        VP                  ^,          \        4      '       g   EK  \        VP                  ^,          P                  ^ ,          RR7      pW9   g   EKQ  W(,          W,          8X  g   EKg  W(,          P                   '       g   VP"                  '       g   EK  VP                  \        VP                  ^ ,          ^,          4      W,          ) ,          4       R;W&   W(&   EK  	  V'       d   \%        YqP'                  4        U
Uu. uF  w  rV'       g   K  W,          NK  	  upp
,           !  \%        VP'                  4        U
Uu. uF  w  rV'       g   K  W,          NK  	  upp
!  ,          p T \%        V U
Uu. uF  w  rW,          NK  	  upp
!  \%        V U
Uu. uF  w  rW,          NK  	  upp
!  ,          ,          p V # u upi u upi u upp
i u upp
i u upp
i u upp
i )c                   < VP                   ;'       g    V P                  ;'       d    V P                  \        \        39   ;'       g    S;'       d}    V P
                  ;'       di    \        V P                  4      ^8  ;'       dI    \        ;QJ d&    R V P                   4       F  '       g   K   R# 	  R# ! R V P                   4       4      # )   c              3      "   T Fa  p\         ;QJ d0    R  \        P                  ! V4       4       F  '       g   K   RM%	  RM!! R  \        P                  ! V4       4       4      x  Kc  	  R# 5i)c              3      "   T FC  p\        V\        4      ;'       g'    VP                  ;'       d    VP                  \        J x  KE  	  R # 5iN)r6   r   is_Powbase).0ais   & r0   	<genexpr>8TR2i.<locals>.f.<locals>.ok.<locals>.<genexpr>.<genexpr>   s=      ,*B #2s+KKryy/K/KRWW^K*s   AAATFN)anyr   	make_args)rL   r:   s   & r0   rN   .TR2i.<locals>.f.<locals>.ok.<locals>.<genexpr>   sU      =5; C ,--*,CCC ,--*, , ,5;s   A+%A+1A+TF)	
is_integeris_positivefuncr   r   is_Addlenr7   rP   )kehalfs   &&r0   okTR2i.<locals>.f.<locals>.ok   s     .. ? ?3*$ > > *= *=*= *=AFFq *= *=  =56VV=@
 @
  =56VV= =@r2   c                   < . pV  Fk  pVP                   '       g   K  \        VP                  4      ^8  g   K3  S'       d   \        V4      M
\	        V4      pWC8w  g   KY  VP                  W434       Km  	  V'       d|   \        V4       F  w  pw  r4W WBV&   K  	  \        V!  P                  4       pV F>  pW,          W#,          ,           pS! W64      '       d   W`V&   K,  VP                  W634       K@  	  ?R# R# )   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   FevaluateN)is_Mulas_numer_denomis_Atomra   listkeyspopr6   r   r   r7   r_   r   rV   r   r8   rS   rT   r   items)r/   nrb   rX   ndonerc   rh   tr:   a1brY   r[   rZ   s   &           @r0   r;   TR2i.<locals>.f{   s   yyyI  "999			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!DADDY<<>qwwy6ytqAdaddy678B#//06Nqtt6N1OOOB	A K
 Kn =6/6Ns<    T T )TTT
T
TT7TTr   )r/   rZ   r;   s   &f r0   TR2iry   _   s    8Sj Rr2   c                Z   a ^ RI Ho V3R lpV P                  R R 4      p \        W4      # )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)

signsimpc                   < \        V \        4      '       g   V # V P                  S! V P                  ^ ,          4      4      p \        V \        4      '       g   V # V P                  ^ ,          \        P
                  ^,          ,
          P                  \        P
                  ^,          V P                  ^ ,          ,
          P                  u;J d   RJ d   M V # \        \        \        \        \        \        \        \        \        \        \        \        /pV\        V 4      ,          ! \        P
                  ^,          V P                  ^ ,          ,
          4      p V # r   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                 "    \        V \        4      # rI   )r6   r$   xs   &r0   <lambda>TR3.<locals>.<lambda>   s    *Q 56r2   c                 *    V P                  R  R 4      # )c                 B    V P                   ;'       d    V P                  # rI   )	is_numberrl   rs   s   &r0   r   'TR3.<locals>.<lambda>.<locals>.<lambda>   s    akk..ahh.r2   c                 6    V P                   ! V P                  !  # 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                *    V P                  R R 4      # )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                     \        V \        4      ;'       dB    V P                  ^ ,          \        ,          ;pP                  ;'       d    VP
                  R9   # )r   )r^   rF            )r6   r$   r7   r   is_Rationalq)r   rs   & r0   r   TR4.<locals>.<lambda>  sP    q/0 E Eq	"_Q))E E./cc_.DEr2   c                     V P                  V P                  ^ ,          P                   ! V P                  ^ ,          P                  !  4      # 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   aaaaa VVVVV3R lp\        W4      # )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                   < V P                   '       d   V P                  P                  S8X  g   V # V P                  P                  '       g   V # V P                  ^ 8  R8X  d   V # V P                  S8  R8X  d   V # V P                  ^8X  d   V # V P                  ^8X  d1   S! S! V P                  P
                  ^ ,          4      ^,          4      # V P                  ^,          ^8X  ds   V P                  ^,          pS! V P                  P
                  ^ ,          4      S! S! V P                  P
                  ^ ,          4      ^,          4      V,          ,          # V P                  ^8X  d   ^pMiS'       g0   V P                  ^,          '       d   V # V P                  ^,          pM2\        V P                  4      pV'       g   V # V P                  ^,          pS! S! V P                  P
                  ^ ,          4      ^,          4      V,          # r~   )rJ   rK   rU   expis_realr7   r%   )r/   rY   pr;   ghmaxpows   &  r0   _f_TR56.<locals>._f>  sm   
 			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   &fffff r0   _TR56r   $  s    4!/ !/F Rr2   c           	     4    \        V \        \        R WR7      # )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                     ^V ,
          # 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           	     4    \        V \        \        R WR7      # )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                     ^V ,
          # r   r   r   s   &r0   r   TR6.<locals>.<lambda>  r   r2   r   )r   r   r   r   s   &&&r0   TR6r   y  r   r2   c                    R p\        W4      # )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                     V P                   '       d1   V P                  P                  \        8X  d   V P                  ^8X  g   V # ^\        ^V P                  P
                  ^ ,          ,          4      ,           ^,          # rF   )rJ   rK   rU   r   r   r7   r.   s   &r0   r;   TR7.<locals>.f  sO    			bggllc1bffkIC"'',,q/)**A--r2   r   r=   s   & r0   TR7r     s     .
 Rr2   c                &   a V3R lp\        W4      # )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                  
  < V P                   '       gr   V P                  '       d^   V P                  P                  \        \
        39   d9   V P                  P                  '       g   V P                  P                  '       g   V # S'       d   V P                  4        Uu. uF  p\        V4      NK  	  upw  r#\        VR R7      p\        VR R7      pWB8w  g   WS8w  d   \        WE,          4      p V P                   '       dx   V P                  ^ ,          P                  '       dU   \        V P                  4      ^8X  d;   V P                  ^,          P                   '       d   \#        V P%                  4       !  p V # \        . \
        . R. /p\"        P&                  ! V 4       EF*  pVP                  \        \
        39   d5   V\)        V4      ,          P+                  VP                  ^ ,          4       KS  VP                  '       d   VP                  P,                  '       d   VP                  ^ 8  d   VP                  P                  \        \
        39   d\   V\)        VP                  4      ,          P/                  VP                  P                  ^ ,          .VP                  ,          4       EK  VR,          P+                  V4       EK-  	  V\        ,          pV\
        ,          p	V'       d	   V	'       g#   \        V4      ^8  g   \        V	4      ^8  g   V # VR,          p\1        \        V4      \        V	4      4      p\3        V4       F`  pV	P5                  4       p
VP5                  4       pVP+                  \        W,           4      \        W,
          4      ,           ^,          4       Kb  	  \        V4      ^8  d`   VP5                  4       p
VP5                  4       pVP+                  \	        W,           4      \	        W,
          4      ,           ^,          4       Ko  V'       d)   VP+                  \	        VP5                  4       4      4       \        V	4      ^8  da   V	P5                  4       p
V	P5                  4       pVP+                  \	        W,           4      ) \	        W,
          4      ,           ^,          4       Kp  V	'       d)   VP+                  \        V	P5                  4       4      4       \        \        \#        V!  4      4      # u upi )FfirstN)rl   rJ   rK   rU   r   r   r   rS   rT   rm   r
   TR8r   r7   r   rW   rV   r   as_coeff_MulrQ   r   r_   
is_Integerextendminrangerq   )r/   rf   rs   rb   newnnewdr7   r:   csrv   a2r   s   &           r0   r;   TR8.<locals>.f  s3   IIIIIIGGLLS#J&VV"''"5"5"5I+-+<+<+>?+>aJqM+>?DAq&Dq&DyDIty)999!7!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KKAEEG%!fqjBBKK#bg,RW5q89KKAEEG%:c4j)**Y @s   Tr   r/   r   r;   s   &f r0   r   r     s    "5+n Rr2   c                    R p\        W4      # )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                 T   a V P                   '       g   V # RV3R llo\        V S4      # )Tc                   < V P                   '       g   V # \        \        V P                  4      4      p\	        V4      ^8w  d   Rp\        \	        V4      4       Fe  pW$,          pVf   K  \        V^,           \	        V4      4       F4  pW&,          pVf   K  WW,           pS! V4      p	W8w  g   K)  WV&   RW&&   Rp Kc  	  Kg  	  V'       d=   \        V U
u. uF  q'       g   K  V
NK  	  up
!  p V P                   '       d	   S! V 4      p V # \        V!  pV'       g   V # Vw  rrppV'       d   W8X  dL   W,          ^,          \        VV,           ^,          4      ,          \        VV,
          ^,          4      ,          # V^ 8  d   TTppRV,          \        VV,           ^,          4      ,          \        VV,
          ^,          4      ,          # W8X  dL   W,          ^,          \        VV,           ^,          4      ,          \        VV,
          ^,          4      ,          # V^ 8  d   TTpp^V,          \        VV,           ^,          4      ,          \        VV,
          ^,          4      ,          # u up
i )rF   FNT
rV   ro   r   r7   rW   r   r   
trig_splitr   r   )r/   r   r7   hitrf   rM   jajwasnewr   splitgcdn1n2r:   rw   iscosdos   &&                r0   r   TR9.<locals>.f.<locals>.do  s    999	()D4yA~s4y)ABz "1q5#d)4!W:$ g g:&)G&*DG"&C! 5	 * D7DbBrrD78Byyy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   	I-"I-T)rV   process_common_addends)r/   r   s   &@r0   r;   TR9.<locals>.f  s&    yyyI<	;| &b"--r2   r   r=   s   & r0   TR9r     s    .B.H Rr2   c                &   a V3R lp\        W4      # )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                   < V P                   \        \        39  d   V # V P                   pV P                  ^ ,          pVP                  '       Ed   S'       d    \        \        VP                  4      4      pM\        VP                  4      pVP                  4       p\        P                  ! V4      pVP                  '       d   V\        8X  dR   \        V4      \        \        V4      RR7      ,          \        V4      \        \        V4      RR7      ,          ,           # \        V4      \        \        V4      RR7      ,          \        V4      \        \        V4      RR7      ,          ,
          # V\        8X  d<   \        V4      \        V4      ,          \        V4      \        V4      ,          ,           # \        V4      \        V4      ,          \        V4      \        V4      ,          ,
          # V # r   Fr   )rU   r   r   r7   rV   ro   r   rq   r   
_from_argsTR10)r/   r;   argr7   r:   rw   r   s   &     r0   r;   TR10.<locals>.fa  sI   773*$IGGggaj:::GCHH-.CHH~
At$Axxx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   &f r0   r   r   O  s    $6 Rr2   c                    R p\        W4      # )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                 .  a V P                   '       g   V # RV3R llo\        V SR 4      p V P                   '       EdL   \        \        4      pV P                   F  p^ pVP
                  '       d   VP                   Fn  pVP                  '       g   K  VP                  \        P                  J g   K7  VP                  P                  '       g   KU  W,          P                  V4       ^p M	  V'       d   K  V\        P                  ,          P                  V4       K  	  . pV F  p\        4       V,          \        4       3 F  pWa9   g   K  \!        \#        W,          4      4       F  pW,          V,          f   K  \!        \#        W,          4      4       Fz  pW,          V,          f   K  \%        W,          V,          W,          V,          ,           4      p	S! V	4      p
W8w  g   KR  VP                  V
4       RW,          V&   RW,          V&    K  	  K  	  K  	  K  	  V'       dT   \%        TVP'                  4        UUu. uF%  p\%        V Uu. uF  q'       g   K  VNK  	  up!  NK'  	  upp,           !  p EKS  S! V 4      p  V # V # u upi u uppi )Tc                 d  < V P                   '       g   V # \        \        V P                  4      4      p\	        V4      ^8w  d   Rp\        \	        V4      4       Fe  pW$,          pVf   K  \        V^,           \	        V4      4       F4  pW&,          pVf   K  WW,           pS! V4      p	W8w  g   K)  WV&   RW&&   Rp Kc  	  Kg  	  V'       d=   \        V U
u. uF  q'       g   K  V
NK  	  up
!  p V P                   '       d	   S! V 4      p V # \        VRR/ pV'       g   V # Vw  rrppV'       dA   W,          pW8X  d   V\        VV,
          4      ,          # V\        VV,           4      ,          # W,          pW8X  d   V\        VV,           4      ,          # V\        VV,
          4      ,          # u up
i )rF   FNTtwor   )r/   r   r7   r   rf   rM   r   r   r   r   r   r   r   r   r   r:   rw   samer   s   &&                r0   r   TR10i.<locals>.f.<locals>.do  su    999	()D4yA~s4y)ABz "1q5#d)4!W:$ g g:&)G&*DG"&C! 5	 * D7DbBrrD78ByyyV	 /$/E	&+#CRAt f8s1q5z>)3q1u:~%f8s1q5z>)3q1u:~%- 8s   	F-"F-c                 >    \        \        V P                  4      4      # rI   )tupler   free_symbolsr   s   &r0   r   "TR10i.<locals>.f.<locals>.<lambda>  s    eGANN$;<r2   Nr   )rV   r   r   ro   r7   rl   rJ   r   r   HalfrK   r   r_   r8   _ROOT3	_invROOT3r   rW   r   values)r/   byradr:   r   rM   r7   rw   rf   r   r   r   rg   r   r   s   &            @r0   r;   TR10i.<locals>.f  s   yyyI6	&p $<>
 iii%EWW888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	r	 )? #-s   J	J!J'	JJr   r=   s   & r0   TR10ir     s    $iV Rr2   Nc                &   a V3R lp\        W4      # )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                   < V P                   \        \        39  d   V # S'       d   V P                   pV! S^,          4      p\        P                  pVP
                  '       d   VP                  4       w  r2VP                   \        \        39  d   V # V P                  ^ ,          VP                  ^ ,          8X  dV   \        S4      p\        S4      pV\        J d   V^,          V^,          ,
          V,          # ^V,          V,          V,          # V # V P                  ^ ,          P                  '       g   V P                  ^ ,          P                  RR7      w  rFVP                  ^,          ^ 8X  d   VP                  ^,          V,          VP                  ,          p\        \        V4      4      p\        \        V4      4      pV P                   \        8X  d   ^V,          V,          p V # V^,          V^,          ,
          p V # )rF   T)rational)rU   r   r   r   r8   rl   r   r7   	is_Numberr   r   TR11)	r/   r;   ru   cor   r   mr   rK   s	   &       r0   r;   TR11.<locals>.f)  sp   773*$IA$q&	ABxxx(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   &f r0   r   r     s    T!F Rr2   c                    R p\        W4      # )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                     \        V \        4      '       g   V # R  p\        WP                  4       4      w  r#R pV! WV4      p V! WV4      p V # )c                 Z   \        \        4      p\        P                  ! V 4       F  pVP	                  4       w  r4VP
                  '       g   K)  V^ 8  g   K2  VP                  \        \        39   g   KO  V\        V4      ,          P                  VP                  ^ ,          4       K  	  V# r5   )r   setr   rQ   as_base_expr   rU   r   r   r   addr7   )flatr7   firw   rY   s   &    r0   sincos_args%_TR11.<locals>.f.<locals>.sincos_argsh  ss     s#DmmD)~~'<<<AEvv#s+T!W))!&&)4	 *
 Kr2   c                     V\         ,           F`  pV^,          pWB\        ,          9   d   \        pMWB\         ,          9   d   \         pMK>  \        W4      p W%,          P                  V4       Kb  	  V # r   )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   maprm   )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                &   a V3R lp\        W4      # )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                   < V P                   \        8X  g   V # V P                  ^ ,          pVP                  '       d   S'       d    \	        \        VP                  4      4      pM\	        VP                  4      pVP                  4       p\        P                  ! V4      pVP                  '       d   \        \        V4      RR7      pM\        V4      p\        V4      V,           ^\        V4      V,          ,
          ,          # V # r   )
rU   r   r7   rV   ro   r   rq   r   r   TR12)r/   r   r7   r:   rw   tbr   s   &     r0   r;   TR12.<locals>.f  s    ww#~Iggaj:::GCHH-.CHH~
At$Axxx#a&.VFRK!c!fRi-00	r2   r   r   s   &f r0   r  r    s    & Rr2   c                    R p\        W4      # )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                 
   V P                   '       g'   V P                  '       g   V P                  '       g   V # V P                  4       w  rVP                  '       d   VP                  '       g   V # / pR  p\        \        P                  ! V4      4      p\        V4       EF  w  rgV! V4      pV'       dP   Vw  r\        V
P                   Uu. uF  qP                  ^ ,          NK  	  up!  p\        P                  W<&   WV&   Ke  VP                   '       dO   \        V4      pVP                  '       d0   VP                  VP                  4       \        P                  WV&   K  K  VP                  '       g   K  VP                  P                  '       g    VP                   P"                  '       g   EK  V! VP                   4      pV'       d]   Vw  r\        V
P                   Uu. uF  qP                  ^ ,          NK  	  up!  pVP                  W<&   WP                  ,          WV&   EK  \        V4      pVP                  '       g   EK  VP                  VP                  4       \        P                  WV&   EK  	  V'       g   V # R p\        \        P                  ! \%        V4      4      4      pRp\        V4       EF  w  roV! V4      pV'       EgK   V! V) 4      pV'       d   \        P&                  W&   EM7VP                   '       dM   \        V4      pVP                  '       d.   VP                  VP                  4       \        P                  W&   K  VP                  '       d   VP                  P                  '       g   VP                   P"                  '       d{   V! VP                   4      pV'       d   \        P                  W&   Mb\        V4      pVP                  '       d.   VP                  VP                  4       \        P                  W&   EK^  EKa  \        P                  W&   Rp\        V Uu. uF  qP                  ^ ,          NK  	  up!  pW<,          pVP)                  \        P                  4      pVe   V'       d   VW<&   MVP+                  V4       W;;,          \-        V4      ) ,          uu&   EK  	  V'       d   \        V!  \        V!  ,          \        VP/                  4        UUUu. uF@  w  pp\        VP                   Uu. uF  p\-        V4      NK  	  up!  ^,
          V,          NKB  	  uppp!  ,          p V # u upi u upi u upi u upi u upppi )c                 h   \        V 4      pV'       d   Vw  r#pV\        P                  J d   VP                  '       dp   \	        VP
                  4      ^8X  dT   \        ;QJ d&    R VP
                   4       F  '       d   K   RM	  RM! R VP
                   4       4      '       d   W#3# R# R# R# R# R# )rF   c              3   B   "   T F  p\        V\        4      x  K  	  R # 5irI   )r6   r   )rL   r  s   & r0   rN   /TR12i.<locals>.f.<locals>.ok.<locals>.<genexpr>  s     A&BJr3//&s   FTN)as_f_sign_1r   NegativeOnerl   rW   r7   all)dir  r   r;   r   s   &    r0   r[   TR12i.<locals>.f.<locals>.ok  s    BAa%!(((s166{a7GA!&&AA!&&AAA4K B 8H(% r2   c                     V P                   '       d^   \        V P                  4      ^8X  dB   V P                  w  r\        V\        4      '       d   \        V\        4      '       d   W3# R# R# R# R# )rF   N)rV   rW   r7   r6   r   )nir:   rw   s   &  r0   r[   r&    sT    yyyS\Q.wwa%%*Q*<*<4K +=% /yr2   FT)rV   rl   rJ   rm   r7   ro   r   rQ   r`   r   r   r8   r&   r   r   rS   rK   rT   r	   r#  extract_additivelyrq   r   rr   )r/   rs   rb   dokr[   d_argsrf   r%  r  r   ru   _r   n_argsr   r(  ednewedrY   r:   s   &                   r0   r;   TR12i.<locals>.f  s   			RYYY")))I  "vvvQVVVI	  cmmA&'v&EA2AQVV4V&&))V45q	yyyBZ999MM"''* !FI   1 1 1RWW5H5H5HrwwKDA8AffQii89AVVCF !66	FIByyybgg.$%EE	1 '2 I	 
 cmmLO45v&EA2A1sG !FIyyy#BZ999"MM"''2()FI FF---1D1D1DrwwK()FI!'B!yyy &bgg 6,-EE	$ EE	C+AffQii+,AB))!%%0E "CFGGAJI#a& IK 'N fc6l*3=@YY[1J=HTQ 36 !8( &1A8( 3)+,3-/021 21=H1J ,K KB 	U 5 9^ ,8( 1Js*   U
%U
<U
?U(U#.U(#U(r   r=   s   & r0   TR12ir1    s    *aF Rr2   c                    R p\        W4      # )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           	         V P                   '       g   V # \        . \        . R . /p\        P                  ! V 4       Fj  pVP
                  \        \        39   d5   V\        V4      ,          P                  VP                  ^ ,          4       KR  VR ,          P                  V4       Kl  	  V\        ,          pV\        ,          p\        V4      ^8  d   \        V4      ^8  d   V # VR ,          p\        V4      ^8  d   VP                  4       pVP                  4       pVP                  ^\        V4      \        WV,           4      ,          \        V4      \        WV,           4      ,          ,           ,
          4       K  V'       d)   VP                  \        VP                  4       4      4       \        V4      ^8  d   VP                  4       pVP                  4       pVP                  ^\        V4      \        WV,           4      ,          ,           \        V4      \        WV,           4      ,          ,           4       K  V'       d)   VP                  \        VP                  4       4      4       \        V!  # rI   )rl   r   r    r   rQ   rU   r   r_   r7   rW   rq   )r/   r7   r:   ru   r   t1t2s   &      r0   r;   TR13.<locals>.f8  s   yyy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KKAEEG%!fqjBBKKCGCL003r73rw<3GGHKKAEEG%Dzr2   r   r=   s   & r0   TR13r7  *  s    < Rr2   c                ,   a RV3R llo\        V S4      # )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                 <  < V P                   '       g   V # V'       d*   V P                  4       w  r#S! V^ 4      S! V^ 4      ,          # \        \        4      p/ p. pV P                   F  pVP                  4       w  rV	P                  '       dW   \        V\        4      '       dA   VP                  ^ ,          P                  4       w  rWK,          P                  V
4       WV&   K}  VP                  V4       K  	  . pV EF  pWK,          pVP                  4        V'       g   K&  ^ pV^ ,          ;rW9   d   V^,          pV^,          pK  V^8  Ed3   \        ^V,          V,          V,          4      ^V,          ,          \        W,          4      ,          pRp. p\        V4       FT  pV^,          p\        W,          RR7      pVP                  V4       \        VV,          T;'       g
    VV,          4      pKV  	  \        V4       F]  pVP                  4       p\        W,          RR7      pVV;;,          V,          uu&   VV,          '       d   KL  VP!                  V4       K_  	  VP                  VV,          4       EKj  \        VP                  ^ 4      V,          4      pVP                  WV,          ,          4       EK  	  V'       dI   \#        W,           V UUu. uF%  qV,           F  p\        W,          RR7      NK  	  K'  	  upp,           !  p V # u uppi )r   NFrj   )rl   rm   r   ro   r7   r  r   r6   r   r   r_   sortr   r   r   rq   r  r   )r/   r   rs   rb   r7   cossotherr   rw   rY   r  r:   r   rX   cccinewargtakeccsrf   keyr;   s   &&                   r0   r;   TRmorrie.<locals>.f  sc   yyyI$$&DAQ71Q7?"4 A==?DA|||
1c 2 2q	..0r"QQ  AAFFH!A$gFA!GB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,; > s{26&I26QQ1AC%(($&I I KB 	&Is   +Lr   r   r=   s   &@r0   TRmorrierD  Y  s    v7r Rr2   c                &   a V3R lp\        W4      # )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           	      	  < V P                   '       g   V # S'       dW   V P                  4       w  rV\        P                  Jd1   \	        VR R7      p\	        VR R7      pW18w  g   WB8w  d	   W4,          p V # . p. pV P
                   EF	  pVP                  '       dM   VP                  4       w  rV	P                  '       g&   VP                  '       g   VP                  V4       K_  TpM\        P                  p	\        V4      p
V
'       d#   V
^,          P                  \        \        39  d@   V	\        P                  J d   VP                  V4       MVP                  Wy,          4       K  V
w  rpVP                  WP                  WW34       EK  	  \!        \#        V4      4      p\%        V4      p\!        \'        ^4      4      ;pw  pprrV'       Ed   VP)                  ^ 4      pV'       Ed   V^ ,          pVV	,          P                  '       Ed   VV	,          P                  '       Ed{   VV,          VV,          8X  Edd   VV,          VV,          8w  EdN   VP)                  ^ 4      p\+        VV	,          VV	,          4      pVV	,          V8w  dA   V Uu. uF  pVV,          NK  	  ppVV	;;,          V,          uu&   VP-                  ^ V4       MMVV	,          V8w  d@   V Uu. uF  pVV,          NK  	  ppVV	;;,          V,          uu&   VP-                  ^ V4       \/        VV,          \        4      '       d   \        pM\        pVP                  VV,          ) VV,          ,          V! VV,          P
                  ^ ,          4      ^,          ,          V,          4       EK  MVV	,          VV	,          8X  d   VV,          VV,          8X  d   VV,          VV,          8w  d   VP)                  ^ 4      pVV	,          p\/        VV,          \        4      '       d   \        pM\        pVP                  VV,          ) VV,          ,          V! VV,          P
                  ^ ,          4      ^,          ,          V,          4       EK  VP                  VV,          VV	,          ,          4       EK  \%        V4      V8w  d
   \1        V!  p V # u upi u upi )Fr   )rl   rm   r   r8   TR14r7   rJ   r  rS   rT   r_   r"  rU   r   r   r   ro   r   rW   r   rq   r   insertr6   r   )r/   rs   rb   r   r   r<  processr:   rw   rY   r  r   r;   sinotherrp   ru   ABr@  rf   remr   s   &                     r0   r;   TR14.<locals>.f  s   yyyI $$&DA~AU+AU+9	B	Axxx}}LLOEEAA!		#s3:LLOLL&HA"NNA{{A"89# ( ww'( U &*%(^3"1aBgAAwAJQ4>>>adnnntqt|R5AbE> 'AA#&qtQqT?D  !tt|59&:TqttT&: #A$ 'q# 6!"159&:TqttT&: #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$u:eB	E '; ';s   S
#Sr   r   s   &f r0   rG  rG    s    ,^@ Rr2   c                *   aa VV3R lp\        W4      # )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           	      j  < \        V \        4      '       d!   \        V P                  \        4      '       g   V # V P                  pV^,          ^8X  d5   \        V P                  V^,           ,          4      V P                  ,          # ^V ,          p\        V\        \        R SSR7      pW28w  d   Tp V # )rF   c                     ^V ,           # 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   &ff r0   rU  rU  I        Rr2   c                *   aa VV3R lp\        W4      # )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           	      j  < \        V \        4      '       d!   \        V P                  \        4      '       g   V # V P                  pV^,          ^8X  d5   \        V P                  V^,           ,          4      V P                  ,          # ^V ,          p\        V\        \        R SSR7      pW28w  d   Tp V # )rF   c                     ^V ,           # r   r   r   s   &r0   r   !TR16.<locals>.f.<locals>.<lambda>  rT  r2   r   )r6   r   rK   r   r   rU  r   r   rV  s   &   r0   r;   TR16.<locals>.fz  rY  r2   r   rZ  s   &ff r0   TR16ra  j  r[  r2   c                    R p\        W4      # )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                    \        V \        4      '       dU   V P                  P                  '       g;   V P                  P
                  '       d   V P                  P                  '       g   V # \        V P                  \        4      '       d9   \        V P                  P                  ^ ,          4      V P                  ) ,          # \        V P                  \        4      '       d9   \        V P                  P                  ^ ,          4      V P                  ) ,          # \        V P                  \        4      '       d9   \        V P                  P                  ^ ,          4      V P                  ) ,          # V # 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$5"&&:L:L:LIbggs##rww||A'"&&00%%rww||A'"&&00%%rww||A'"&&00	r2   r   r=   s   & r0   TR111rf    s     Rr2   c                *   aa VV3R lp\        W4      # )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           	         < \        V \        4      '       d&   V P                  P                  \        \
        39   g   V # \        V \
        \        R  SSR7      p \        V \        \        R SSR7      p V # )c                     V ^,
          # r   r   r   s   &r0   r   !TR22.<locals>.f.<locals>.<lambda>      1q5r2   r   c                     V ^,
          # r   r   r   s   &r0   r   rj    rk  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   rZ  s   &ff r0   TR22rn    s    $ Rr2   c                    R p\        W4      # )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                    \        V \        4      '       d'   \        V P                  \        \        34      '       g   V # V P                  4       w  rVP                  ^ ,          pVP                  '       Ed6   VP                  '       Ed#   VP                  '       d   \        V\        4      '       dv   ^^V,
          ,          \        \        V^,           ^,          4       Uu. uF3  p\        W$4      \	        V^V,          ,
          V,          4      ,          NK5  	  up!  ,          p EMKVP                  '       d   \        V\        4      '       d   ^^V,
          ,          \        P                  V^,
          ^,          ,          ,          \        \        V^,           ^,          4       Uu. uFO  p\        W$4      \        P                  V,          ,          \        V^V,          ,
          V,          4      ,          NKQ  	  up!  ,          p EMhVP                  '       d   \        V\        4      '       dn   ^^V,
          ,          \        \        V^,          4       Uu. uF3  p\        W$4      \	        V^V,          ,
          V,          4      ,          NK5  	  up!  ,          p MVP                  '       d   \        V\        4      '       d   ^^V,
          ,          \        P                  V^,          ,          ,          \        \        V^,          4       Uu. uFO  p\        W$4      \        P                  V,          ,          \	        V^V,          ,
          V,          4      ,          NKQ  	  up!  ,          p VP                  '       d)   V ^V) ,          \        W"^,          4      ,          ,          p V # u upi u upi u upi u upi r5   )r6   r   rK   r   r   r  r7   r   rT   is_oddr   r   r   r   r#  is_even)r/   rw   rs   r   rX   s   &    r0   r;   TRpower.<locals>.f  s   2s##
277S#J(G(GI~~FF1I<<<AMMMxxxJq#..1Xc"AE19-$/- %-QN3AaC{3C$C$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 >6?O=Q 8R Rz!S111Xc"1Q3Z$)' %-QN3AaC{3C$C$C'$) * *z!S111Xammac223?DQqSz9K?I! :B!MM1$:%%(!ac'1%5:6 :6?I9K 4L Lyyya1"ghqA#...	$/=Q$)9Ks   !9N.
(AN3
9N8
AN=
r   r=   s   & r0   TRpowerrt    s    *, Rr2   c                >    \        V P                  \        4      4      # )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   Lrw    s     RXX+,--r2   c                 8    \        V 4      V P                  4       3# rI   )rw  	count_opsr   s   &r0   r   r   *  s    adAKKM2r2   c           
        \        \        V4      p\        \        V4      pT p\        V 4      p \	        V \
        4      '       g5   V P                  ! V P                   Uu. uF  p\        WQR7      NK  	  up!  # \        V 4      p V P                  \        \        4      '       dI   V! V 4      pV! V4      V! V 4      8  d   Tp V P                  \        \        4      '       d   \        V 4      p V P                  \        \        4      '       d,   V! V 4      p\!        \#        V4      4      p\%        W@Wg.VR7      p \%        \'        V 4      WR7      # u upi )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)rB  )r'   RL1RL2r   r6   r   rU   r7   fur>   hasr   r    rB   r   r   r   rD  r   ry   )r/   r{  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   Ec                   \        \        4      pV'       d]   V P                   FK  pVP                  4       w  reV^ 8  d   V) pV) pYFV'       d	   V! V4      M^3,          P	                  V4       KM  	  MUV'       dC   V P                   F1  pV\
        P                  V! V4      3,          P	                  V4       K3  	  M\        R4      h. pRpV Fs  p	WI,          p
V	w  rk\        V
4      ^8  d7   \        V
RR/ pV! V4      pW8w  d   TpRpVP	                  Wl,          4       KU  VP	                  Wj^ ,          ,          4       Ku  	  V'       d
   \        V!  p V # )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.
zmust have at least one keyFrk   T)
r   ro   r7   r   r_   r   r8   
ValueErrorrW   r   )r/   r   key2key1abscr:   r   r7   r   rX   rg   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                      \        ^4      # r   r#   r   r2   r0   _ROOT2r        7Nr2   c                      \        ^4      # )r   r  r   r2   r0   r   r     r  r2   c                  &    ^\        ^4      ,          # r   r  r   r2   r0   r   r     s    T!W9r2   c           	       a W3 Uu. uF  p\        V4      NK  	  upw  rV P                  V4      w  rEV P                  V4      P                  4       p^;rx\        P
                  VP                  9   d$   VP                  \        P
                  4      pV) pMA\        P
                  VP                  9   d#   VP                  \        P
                  4      pV) pWE3 Uu. uF  q3P                  4       NK  	  upw  rR p	V	! W4      p
V
f   R# V
w  rpV	! W4      p
V
f   R# V
w  rpV'       g	   V'       g   V'       d$   \        V\        4      '       d   WVWV3w  rrppYrV'       gn   T;'       g    TpT;'       g    Tp\        VVP                  4      '       g   R# WgVVP                  ^ ,          VP                  ^ ,          \        V\        4      3# V'       g   V'       g   V'       d   V'       d   V'       d   V'       d   \        WP                  4      \        VVP                  4      Jd   R# W3 Uu0 uF  pVP                  kK  	  upo\        ;QJ d!    V3R lVV3 4       F  '       d   K   RM	  RM! V3R lVV3 4       4      '       g   R# WgWP                  ^ ,          VP                  ^ ,          \        WP                  4      3# V'       d	   V'       g)   V'       d	   V'       g   V'       d   Vf   Ve	   Vf   Vf   R# T;'       g    TpT;'       g    TpVP                  VP                  8w  d   R# V'       g   \        P                  pV'       g   \        P                  pWJ d5   V\        4       ,          pWgVVP                  ^ ,          \         ^,          R3# W,          \#        4       8X  d4   V^V,          ,          pWgVVP                  ^ ,          \         ^,          R3# W,          \%        4       8X  d4   V^V,          ,          pWgVVP                  ^ ,          \         ^,          R3# R# u upi u upi u upi )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)
c                   R;r#\         P                  pV P                  '       Ed   V P                  4       w  r@\	        V P
                  4      ^8  g	   V'       g   R# V P                  '       d   \        V P
                  4      pMV .pVP                  ^ 4      p \        V \        4      '       d   T pMT\        V \        4      '       d   T pM;V P                  '       d(   V P                  \         P                  J d
   W@,          pMR# V'       d   V^ ,          p\        V\        4      '       d   V'       d   TpMbTpM_\        V\        4      '       d   V'       d   TpM>TpM;VP                  '       d(   VP                  \         P                  J d
   WF,          pMR# V\         P                  Jd   WBV3# RW#3# \        V \        4      '       d   T pM\        V \        4      '       d   T pVf   Vf   R# V\         P                  Jd   TMRpWBV3# )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.
N)r   r8   rl   r   rW   r7   ro   rq   r6   r   r   rJ   r   r   )r:   r   r   r   r  r7   rw   s   &&     r0   pow_cos_sintrig_split.<locals>.pow_cos_sin  sx   ( UU888NN$EB166{QcxxxAFF|sA!S!!As##aeeqvvoGa%%3''XXX!%%166/GB1552q88dA883A3A9QUU?Raxr2   Nc              3   @   <"   T F  qP                   S9   x  K  	  R # 5irI   )r7   )rL   rf   r7   s   & r0   rN   trig_split.<locals>.<genexpr>^  s     <8a66T>8s   FT)r   r,   r   as_exprr   r#  factorsquor6   r   rU   r7   r   r$  r8   r  r   r   r   )r:   rw   r   rf   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HH"HH"!QVV$$AFF1Iqvvay*Q2DDD3rbRb''**R2II)+111s<B8<sss<B8<<<GGAJ
Jr77<SSS"rRZBJ"*HH"HH"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   P:P?7Qc                0   V P                   '       d   \        V P                  4      ^8w  d   R# V P                  w  rV\        P                  \        P
                  39   dj   \        P
                  pVP                  '       dD   VP                  ^ ,          P                  '       d!   VP                  ^ ,          ^ 8  d	   V) V) r!V) pW2V3# V P                   Uu. uF  p\        V4      NK  	  upw  rVP                  V4      w  rVVP                  V4      P                  4       p\        P                  VP                  9   d%   VP                  \        P                  4      pRp^p	MF\        P                  VP                  9   d%   VP                  \        P                  4      p^pRp	M^;rWV3 Uu. uF  qDP                  4       NK  	  upw  rV\        P
                  J d   Y!r!YrVR8X  d   V) pV	) p	V\        P
                  J d   WqV	3# R# u upi u upi )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)
N)rV   rW   r7   r   r#  r8   rl   r   r   r,   r   r  r  r  )
rY   r:   rw   r   rf   r  r  r   r   r   s
   &         r0   r"  r"  w  s   * 888s166{a'66DAQ]]AEE""EE888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   H2Hc                &   a V3R lp\        W4      # )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                 "  < \        V \        4      '       g   V # V P                  ^ ,          pVP                  '       g
   VS,          M5\        P
                  ! VP                   Uu. uF  q"S,          NK  	  up4      p\        V \        4      '       d   \        \        V4      ,          # \        V \        4      '       d   \        V4      # \        V \        4      '       d   \        \        V4      ,          # \        V \        4      '       d   \        V4      \        ,          # \        V \        4      '       d   \!        V4      # \        V \"        4      '       d   \%        V4      \        ,          # \'        RV P(                  ,          4      hu upi )r   unhandled %s)r6   r   r7   rV   r   r   r   r   r   r   r   r   r   r   r    r   r!   r   r"   NotImplementedErrorrU   )r/   r:   rf   rb   s   &  r0   r;   _osborne.<locals>.f  s   "011IGGAJxxxAaCS^^!&&4I&QqSS&4I%Jb$SV8OD!!q6MD!!SV8OD!!q6!8OD!!q6MD!!q6!8O%nrww&>?? 5Js   &Fr   rY   rb   r;   s   &f r0   _osborner    s    "@( Q?r2   c                &   a V3R lp\        W4      # )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                   < \        V \        4      '       g   V # V P                  ^ ,          P                  SRR7      w  rVP	                  S\
        P                  /4      V\        ,          ,           p\        V \        4      '       d   \        V4      \        ,          # \        V \        4      '       d   \        V4      # \        V \        4      '       d   \        V4      \        ,          # \        V \        4      '       d   \        V4      \        ,          # \        V \         4      '       d   \#        V4      # \        V \$        4      '       d   \'        V4      \        ,          # \)        RV P*                  ,          4      h)r   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:   rb   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   &f r0   	_osborneir    s     @( Q?r2   c                8  aaaa	 ^ RI Ho	 ^ RIHo V P	                  \
        4      pV Uu. uF  q"\        4       3NK  	  upoV P                  \        S4      4      pS UUu. uF  w  rEWT3NK
  	  uppo\        4       o\        VS4      VVVV	3R l3# u upi u uppi )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{   )collectc           	         < S! S! \        V S4      P                  \        S4      4      4      \        P                  4      # rI   )r  r  dictr   ImaginaryUnit)r   r  rb   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/   trigsru   maskedrX   rg   r  rb   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                    V P                  \        \        4      '       g   V # \        \	        \        V 4      4      4      # )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
   rt  )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   ry   r   r   r   r   r   r   r   r   r   r   r   r  r  r1  r7  rD  rG  rU  ra  rf  rn  rt  rw  ro   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   