ó
¡¼™\c           @  s  d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z d d l  m! Z! d d l" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) d d l* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 d d l3 m4 Z4 d d l5 m6 Z6 d d l7 m8 Z8 d d l9 m: Z: d d l; m< Z< m= Z= d d l> m? Z? d „  Z@ d „  ZA d „  ZB eC d „ ZD d „  ZE d „  ZF d „  ZG d eC d  „ ZH d eC d! „ ZI d" „  ZJ eK d# „ ZL d$ „  ZM eK d% „ ZN d& „  ZO d> d' „ ZQ eK d( „ ZR d) „  ZS d* „  ZT d+ „  ZU eK d, „ ZV d eC d- „ ZW d eC d. „ ZX d/ „  ZY d eC d0 „ ZZ d1 „  Z[ d2 „  Z\ e? r”e] e^ e= e@ eA eB eE eF eH eI eJ eL eM eN eQ eR eT eD eU eV eW eX eS eY eZ f ƒ ƒ \ Z@ ZA ZB ZE ZF ZH ZI ZJ ZL ZM ZN ZQ ZR ZT ZD ZU ZV ZW ZX ZS ZY ZZ n  eH e@ f eI e@ f e< g Z_ eQ eH e@ f eI e@ f e@ g f Z` eU eL e@ f eU eL eO e@ f e< g Za eF eO f e< g Zb eF eE eF eR eF eT eF e@ f Zc eF eE eN eF eE eQ f eH eJ eQ eF f ea e_ eM e` eF eM eM eb f e< g Zd d3 „  d4 „ Ze d> eK d5 „ Zf d6 jg ƒ  Zh ei e] ej eh e] e^ ek ƒ  jl eh ƒ ƒ ƒ ƒ ƒ Zm d7 „  Zn d> ao eC d8 „ Zp d9 „  Zq d: „  Zr d; „  Zs d< „  Zt d= „  Zu d> S(?   s¼  
Implementation of the trigsimp algorithm by Fu et al.

The idea behind the ``fu`` algorithm is to use a sequence of rules, applied
in what is heuristically known to be a smart order, to select a simpler
expression that is equivalent to the input.

There are transform rules in which a single rule is applied to the
expression tree. The following are just mnemonic in nature; see the
docstrings for examples.

    TR0 - simplify expression
    TR1 - sec-csc to cos-sin
    TR2 - tan-cot to sin-cos ratio
    TR2i - sin-cos ratio to tan
    TR3 - angle canonicalization
    TR4 - functions at special angles
    TR5 - powers of sin to powers of cos
    TR6 - powers of cos to powers of sin
    TR7 - reduce cos power (increase angle)
    TR8 - expand products of sin-cos to sums
    TR9 - contract sums of sin-cos to products
    TR10 - separate sin-cos arguments
    TR10i - collect sin-cos arguments
    TR11 - reduce double angles
    TR12 - separate tan arguments
    TR12i - collect tan arguments
    TR13 - expand product of tan-cot
    TRmorrie - prod(cos(x*2**i), (i, 0, k - 1)) -> sin(2**k*x)/(2**k*sin(x))
    TR14 - factored powers of sin or cos to cos or sin power
    TR15 - negative powers of sin to cot power
    TR16 - negative powers of cos to tan power
    TR22 - tan-cot powers to negative powers of sec-csc functions
    TR111 - negative sin-cos-tan powers to csc-sec-cot

There are 4 combination transforms (CTR1 - CTR4) in which a sequence of
transformations are applied and the simplest expression is selected from
a few options.

Finally, there are the 2 rule lists (RL1 and RL2), which apply a
sequence of transformations and combined transformations, and the ``fu``
algorithm itself, which applies rules and rule lists and selects the
best expressions. There is also a function ``L`` which counts the number
of trigonometric functions that appear in the expression.

Other than TR0, re-writing of expressions is not done by the transformations.
e.g. TR10i finds pairs of terms in a sum that are in the form like
``cos(x)*cos(y) + sin(x)*sin(y)``. Such expression are targeted in a bottom-up
traversal of the expression, but no manipulation to make them appear is
attempted. For example,

    Set-up for examples below:

    >>> from sympy.simplify.fu import fu, L, TR9, TR10i, TR11
    >>> from sympy import factor, sin, cos, powsimp
    >>> from sympy.abc import x, y, z, a
    >>> from time import time

>>> eq = cos(x + y)/cos(x)
>>> TR10i(eq.expand(trig=True))
-sin(x)*sin(y)/cos(x) + cos(y)

If the expression is put in "normal" form (with a common denominator) then
the transformation is successful:

>>> TR10i(_.normal())
cos(x + y)/cos(x)

TR11's behavior is similar. It rewrites double angles as smaller angles but
doesn't do any simplification of the result.

>>> TR11(sin(2)**a*cos(1)**(-a), 1)
(2*sin(1)*cos(1))**a*cos(1)**(-a)
>>> powsimp(_)
(2*sin(1))**a

The temptation is to try make these TR rules "smarter" but that should really
be done at a higher level; the TR rules should try maintain the "do one thing
well" principle.  There is one exception, however. In TR10i and TR9 terms are
recognized even when they are each multiplied by a common factor:

>>> fu(a*cos(x)*cos(y) + a*sin(x)*sin(y))
a*cos(x - y)

Factoring with ``factor_terms`` is used but it it "JIT"-like, being delayed
until it is deemed necessary. Furthermore, if the factoring does not
help with the simplification, it is not retained, so
``a*cos(x)*cos(y) + a*sin(x)*sin(z)`` does not become the factored
(but unsimplified in the trigonometric sense) expression:

>>> fu(a*cos(x)*cos(y) + a*sin(x)*sin(z))
a*sin(x)*sin(z) + a*cos(x)*cos(y)

In some cases factoring might be a good idea, but the user is left
to make that decision. For example:

>>> expr=((15*sin(2*x) + 19*sin(x + y) + 17*sin(x + z) + 19*cos(x - z) +
... 25)*(20*sin(2*x) + 15*sin(x + y) + sin(y + z) + 14*cos(x - z) +
... 14*cos(y - z))*(9*sin(2*y) + 12*sin(y + z) + 10*cos(x - y) + 2*cos(y -
... z) + 18)).expand(trig=True).expand()

In the expanded state, there are nearly 1000 trig functions:

>>> L(expr)
932

If the expression where factored first, this would take time but the
resulting expression would be transformed very quickly:

>>> def clock(f, n=2):
...    t=time(); f(); return round(time()-t, n)
...
>>> clock(lambda: factor(expr))  # doctest: +SKIP
0.86
>>> clock(lambda: TR10i(expr), 3)  # doctest: +SKIP
0.016

If the unexpanded expression is used, the transformation takes longer but
not as long as it took to factor it and then transform it:

>>> clock(lambda: TR10i(expr), 2)  # doctest: +SKIP
0.28

So neither expansion nor factoring is used in ``TR10i``: if the
expression is already factored (or partially factored) then expansion
with ``trig=True`` would destroy what is already known and take
longer; if the expression is expanded, factoring may take longer than
simply applying the transformation itself.

Although the algorithms should be canonical, always giving the same
result, they may not yield the best result. This, in general, is
the nature of simplification where searching all possible transformation
paths is very expensive. Here is a simple example. There are 6 terms
in the following sum:

>>> expr = (sin(x)**2*cos(y)*cos(z) + sin(x)*sin(y)*cos(x)*cos(z) +
... sin(x)*sin(z)*cos(x)*cos(y) + sin(y)*sin(z)*cos(x)**2 + sin(y)*sin(z) +
... cos(y)*cos(z))
>>> args = expr.args

Serendipitously, fu gives the best result:

>>> fu(expr)
3*cos(y - z)/2 - cos(2*x + y + z)/2

But if different terms were combined, a less-optimal result might be
obtained, requiring some additional work to get better simplification,
but still less than optimal. The following shows an alternative form
of ``expr`` that resists optimal simplification once a given step
is taken since it leads to a dead end:

>>> TR9(-cos(x)**2*cos(y + z) + 3*cos(y - z)/2 +
...     cos(y + z)/2 + cos(-2*x + y + z)/4 - cos(2*x + y + z)/4)
sin(2*x)*sin(y + z)/2 - cos(x)**2*cos(y + z) + 3*cos(y - z)/2 + cos(y + z)/2

Here is a smaller expression that exhibits the same behavior:

>>> a = sin(x)*sin(z)*cos(x)*cos(y) + sin(x)*sin(y)*cos(x)*cos(z)
>>> TR10i(a)
sin(x)*sin(y + z)*cos(x)
>>> newa = _
>>> TR10i(expr - a)  # this combines two more of the remaining terms
sin(x)**2*cos(y)*cos(z) + sin(y)*sin(z)*cos(x)**2 + cos(y - z)
>>> TR10i(_ + newa) == _ + newa  # but now there is no more simplification
True

Without getting lucky or trying all possible pairings of arguments, the
final result may be less than optimal and impossible to find without
better heuristics or brute force trial of all possibilities.

Notes
=====

This work was started by Dimitar Vlahovski at the Technological School
"Electronic systems" (30.11.2011).

References
==========

Fu, Hongguang, Xiuqin Zhong, and Zhenbing Zeng. "Automated and readable
simplification of trigonometric expressions." Mathematical and computer
modelling 44.11 (2006): 1169-1177.
http://rfdz.ph-noe.ac.at/fileadmin/Mathematik_Uploads/ACDCA/DESTIME2006/DES_contribs/Fu/simplification.pdf

http://www.sosmath.com/trig/Trig5/trig5/pdf/pdf.html gives a formula sheet.

iÿÿÿÿ(   t   print_functiont   division(   t   defaultdict(   t   Add(   t   S(   t   orderedt   range(   t   Expr(   t   Factorst	   gcd_termst   factor_terms(   t
   expand_mul(   t   Mul(   t   pit   I(   t   Pow(   t   Dummy(   t   sympify(   t   binomial(   t   cosht   sinht   tanht   cotht   secht   cscht   HyperbolicFunction(   t   cost   sint   tant   cott   sect   csct   sqrtt   TrigonometricFunction(   t   perfect_power(   t   factor(   t	   bottom_up(   t   greedy(   t   identityt   debug(   t   SYMPY_DEBUGc         C  s   |  j  ƒ  j ƒ  j ƒ  S(   s   Simplification of rational polynomials, trying to simplify
    the expression, e.g. combine things like 3*x + 2*x, etc....
    (   t   normalR#   t   expand(   t   rv(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR0Ý   s    c         C  s   d „  } t  |  | ƒ S(   sÎ   Replace sec, csc with 1/cos, 1/sin

    Examples
    ========

    >>> from sympy.simplify.fu import TR1, sec, csc
    >>> from sympy.abc import x
    >>> TR1(2*csc(x) + sec(x))
    1/cos(x) + 2/sin(x)
    c         S  s^   t  |  t ƒ r- |  j d } t j t | ƒ St  |  t ƒ rZ |  j d } t j t | ƒ S|  S(   Ni    (   t
   isinstanceR   t   argsR   t   OneR   R   R   (   R+   t   a(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   fò   s    (   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR1æ   s    		c         C  s   d „  } t  |  | ƒ S(   s@  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         S  sd   t  |  t ƒ r0 |  j d } t | ƒ t | ƒ St  |  t ƒ r` |  j d } t | ƒ t | ƒ S|  S(   Ni    (   R-   R   R.   R   R   R   (   R+   R0   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1     s    (   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR2þ   s    		c           s   ‡  f d †  } t  |  | ƒ S(   sÄ  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)
    (cos(x) + 1)**(-a)*sin(x)**a

    c           sQ  |  j  s |  S|  j ƒ  \ } } | j s1 | j r5 |  S‡ f d †  ‰  | j ƒ  } g  t | j ƒ  ƒ D]. } ˆ  | | | ƒ sc | | j | ƒ f ^ qc } | s¡ |  S| j ƒ  } g  t | j ƒ  ƒ D]. } ˆ  | | | ƒ sÀ | | j | ƒ f ^ qÀ } | sþ |  S‡ ‡  f d †  } | | | ƒ | | | ƒ g  } xQ| D]I} t | t ƒ r-t	 | j
 d d t ƒ} | | k r¼| | | | k r¼| j t | j
 d ƒ | | ƒ d  | | <| | <q€ˆ r€d | }	 |	 | k r*| |	 | | k r*| j t | j
 d d ƒ | | ƒ d  | | <| |	 <q*q€q7t | t	 ƒ r°t | j
 d d t ƒ} | | k r€| | | | k r€| j t | j
 d ƒ | | ƒ d  | | <| | <q€q7ˆ r7| j r7| j
 d t j k r7t | j
 d t	 ƒ r7t | j
 d j
 d d t ƒ} | | k r€| | | | k r€| | j sA| j r€| j t | j
 d d ƒ | | ƒ d  | | <| | <q€q7q7W| rMt | g  | j ƒ  D] \ }
 } | r|
 | ^ qŒ  t g  | j ƒ  D] \ }
 } | rÐ|
 | ^ qÐŒ  }  |  t g  | D] \ }
 } |
 | ^ qŒ  t g  | D] \ }
 } |
 | ^ q)Œ  9}  n  |  S(   Nc           sb   | j  s |  j oa |  j t t f k pa ˆ  oa |  j oa t |  j ƒ d k oa t d „  |  j Dƒ ƒ S(   Ni   c         s  s.   |  ]$ } t  d  „  t j | ƒ Dƒ ƒ Vq d S(   c         s  s6   |  ], } t  | t ƒ p- | j o- | j t k Vq d  S(   N(   R-   R   t   is_Powt   base(   t   .0t   ai(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pys	   <genexpr>G  s   N(   t   anyR   t	   make_args(   R6   R0   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pys	   <genexpr>G  s   (	   t
   is_integert   is_positivet   funcR   R   t   is_Addt   lenR.   R8   (   t   kt   e(   t   half(    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   ok@  s    		c           s   g  } xo |  D]g } | j  r t | j ƒ d k r ˆ  rC t | ƒ n	 t | ƒ } | | k rt | j | | f ƒ qt q q W| rx1 t | ƒ D]# \ } \ } } |  | =| | | <q‹ Wt | Œ  j ƒ  } xO | D]G } |  | | | } ˆ | | ƒ rÿ | |  | <qË | j | | f ƒ qË W~ n  d  S(   Ni   (	   R=   R>   R.   R#   R
   t   appendt	   enumerateR   t   as_powers_dict(   t   dt   ddonet   newkR?   t   knewt   it   v(   RA   RB   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt	   factorizeV  s"    i    t   evaluatei   i   (   t   is_Mult   as_numer_denomt   is_AtomRE   t   listt   keyst   popR-   R   R   R.   t   FalseRC   R   t   NoneR=   R   R/   R:   R;   R   t   items(   R+   t   nRF   R?   t   ndoneRG   RL   t   tR0   t   a1t   bR@   (   RA   (   RB   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   8  s\    	
GG "
 & #% -	'66W(   R$   (   R+   RA   R1   (    (   RA   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR2i  s    Uc           s,   d d l  m ‰  ‡  f d †  } t |  | ƒ S(   sR  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)

    iÿÿÿÿ(   t   signsimpc           sä   t  |  t ƒ s |  S|  j ˆ  |  j d ƒ ƒ }  t  |  t ƒ sB |  S|  j d t j d j t j d |  j d j k oƒ t k n rà i t t	 6t	 t 6t
 t 6t t
 6t t 6t t 6} | |  j t j d |  j d ƒ }  n  |  S(   Ni    i   i   (   R-   R!   R<   R.   R   t   PiR;   t   TrueR   R   R   R   R   R   (   R+   t   fmap(   R]   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   ¬  s    F0((   t   sympy.simplify.simplifyR]   R$   (   R+   R1   (    (   R]   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR3  s    
c         C  s   |  S(   sÆ  Identify values of special angles.

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

    Examples
    ========

    >>> from sympy.simplify.fu import TR4
    >>> 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
    (    (   R+   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR4º  s    c           s(   ‡  ‡ ‡ ‡ ‡ f d †  } t  |  | ƒ S(   s  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)
    sin(x)**3
    >>> 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           s	  |  j  o |  j j ˆ  k s |  S|  j d k  t k r8 |  S|  j ˆ k t k rQ |  S|  j d k r~ ˆ ˆ |  j j d ƒ d ƒ S|  j d k r– d } nM ˆ s½ |  j d r­ |  S|  j d } n& t |  j ƒ } | sÖ |  S|  j d } ˆ ˆ |  j j d ƒ d ƒ | Sd  S(   Ni    i   i   (   R4   R5   R<   t   expR_   R.   R"   (   R+   R@   t   p(   R1   t   gt   ht   maxt   pow(    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   _fð  s&    	(   R$   (   R+   R1   Rf   Rg   Rh   Ri   Rj   (    (   R1   Rf   Rg   Rh   Ri   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   _TR56Ö  s    i   c      	   C  s"   t  |  t t d „  d | d | ƒS(   s  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  s   d |  S(   Ni   (    (   t   x(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   <lambda>!  t    Rh   Ri   (   Rk   R   R   (   R+   Rh   Ri   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR5  s    c      	   C  s"   t  |  t t d „  d | d | ƒS(   s€  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  s   d |  S(   Ni   (    (   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   6  Rn   Rh   Ri   (   Rk   R   R   (   R+   Rh   Ri   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR6$  s    c         C  s   d „  } t  |  | ƒ S(   s  Lowering the degree of cos(x)**2

    Examples
    ========

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

    c         S  sN   |  j  o' |  j j t k o' |  j d k s. |  Sd t d |  j j d ƒ d S(   Ni   i   i    (   R4   R5   R<   R   Rd   R.   (   R+   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   I  s    *(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR79  s    	c           s   ‡  f d †  } t  |  | ƒ S(   sv  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, TR7
    >>> 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           sÚ  |  j  p? |  j o? |  j j t t f k o? |  j j p? |  j j sF |  Sˆ  rg  |  j	 ƒ  D] } t
 | ƒ ^ qY \ } } t | d t ƒ} t | d t ƒ} | | k s³ | | k rt | | ƒ }  |  j  r|  j d j rt |  j ƒ d k r|  j d j rt |  j ƒ  Œ  }  qn  |  Si g  t 6g  t 6g  d  6} xË t t j |  ƒ ƒ D]´ } | j t t f k r‡| | j j | j d ƒ qN| j rñ| j j rñ| j d k rñ| j j t t f k rñ| | j j j | j j d g | j ƒ qN| d  j | ƒ qNW| t } | t }	 | r&|	 pGt | ƒ d k pGt |	 ƒ d k sN|  S| d  } t t | ƒ t |	 ƒ ƒ } xU t | ƒ D]G } |	 j ƒ  }
 | j ƒ  } | j t |
 | ƒ t |
 | ƒ d ƒ q€WxW t | ƒ d k r$| j ƒ  }
 | j ƒ  } | j t |
 | ƒ t |
 | ƒ d ƒ qÎW| rG| j t | j ƒ  ƒ ƒ n  xX t |	 ƒ d k r¡|	 j ƒ  }
 |	 j ƒ  } | j t |
 | ƒ t |
 | ƒ d ƒ qJW|	 rÄ| j t |	 j ƒ  ƒ ƒ n  t t
 t | Œ  ƒ ƒ S(   Nt   firsti    i   i   (   RN   R4   R5   R<   R   R   Rd   R:   R;   RO   R   t   TR8RT   R	   R.   t   is_RationalR>   R=   R   t   as_coeff_MulRU   R   R9   RC   t
   is_Integert   extendt   minR   RS   (   R+   RJ   RW   RF   t   newnt   newdR.   R0   t   ct   sRZ   t   a2(   Rr   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   b  s\    		+%$.

0
--.(   R$   (   R+   Rr   R1   (    (   Rr   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRs   Q  s    7c         C  s   d „  } t  |  | ƒ S(   sb  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
    wasn't changed, the original expression will be returned:

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

    c           s,   |  j  s |  St ‡  f d † ‰  t |  ˆ  ƒ S(   Nc           s}  |  j  s |  St t |  j ƒ ƒ } t | ƒ d k r=t } x¶ t t | ƒ ƒ D]¢ } | | } | d  k ro qM n  x} t | d t | ƒ ƒ D]b } | | } | d  k r« q‰ n  | | } ˆ  | ƒ }	 |	 | k r‰ |	 | | <d  | | <t } Pq‰ q‰ WqM W| r9t	 g  | D] }
 |
 r|
 ^ qŒ  }  |  j  r9ˆ  |  ƒ }  q9n  |  St
 | Œ  } | sS|  S| \ } } } } } } | rõ| | k r­| | d t | | d ƒ t | | d ƒ S| d k  rÉ| | } } n  d | t | | d ƒ t | | d ƒ S| | k r1| | d t | | d ƒ t | | d ƒ S| d k  rM| | } } n  d | t | | d ƒ t | | d ƒ Sd  S(   Ni   i   i    iþÿÿÿ(   R=   RQ   R   R.   R>   RT   R   RU   R_   R   t
   trig_splitR   R   (   R+   Rr   R.   t   hitRJ   R7   t   jt   ajt   wast   newRj   t   splitt   gcdt   n1t   n2R0   R[   t   iscos(   t   do(    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR‰   ·  sP    	
 



%	0,0(   R=   R_   t   process_common_addends(   R+   (    (   R‰   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   ³  s    	>(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR9œ  s    	Dc           s   ‡  f d †  } t  |  | ƒ S(   s§  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           s{  |  j  t t f k r |  S|  j  } |  j d } | j rwˆ  rV t t | j ƒ ƒ } n t | j ƒ } | j ƒ  } t j	 | ƒ } | j r| t k rÕ t | ƒ t
 t | ƒ d t ƒt | ƒ t
 t | ƒ d t ƒSt | ƒ t
 t | ƒ d t ƒt | ƒ t
 t | ƒ d t ƒSqw| t k rLt | ƒ t | ƒ t | ƒ t | ƒ St | ƒ t | ƒ t | ƒ t | ƒ Sn  |  S(   Ni    Rr   (   R<   R   R   R.   R=   RQ   R   RS   R   t
   _from_argst   TR10RT   (   R+   R1   t   argR.   R0   R[   (   Rr   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1     s(    			!$(+(   R$   (   R+   Rr   R1   (    (   Rr   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR   ú  s    c         C  s,   t  d k r t ƒ  n  d „  } t |  | ƒ S(   s§  Sum of products to function of sum.

    Examples
    ========

    >>> from sympy.simplify.fu import TR10i
    >>> from sympy import cos, sin, pi, Add, Mul, sqrt, Symbol
    >>> from sympy.abc import x, y

    >>> 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           sg  |  j  s |  St ‡  f d † ‰  t |  ˆ  d „  ƒ }  x,|  j  rbt t ƒ } x– |  j D]‹ } d } | j rÄ xV | j D]H } | j ru | j t	 j
 k ru | j j ru | | j | ƒ d } Pqu qu Wn  | sV | t	 j j | ƒ qV qV Wg  } x| D]} xt | t g D]ð } | | k r	xÛ t t | | ƒ ƒ D]À } | | | d  k rRq2n  x t t | | ƒ ƒ D]… } | | | d  k r‰qin  t | | | | | | ƒ }	 ˆ  |	 ƒ }
 |
 |	 k ri| j |
 ƒ d  | | | <d  | | | <PqiqiWq2Wq	q	Wqò W| rRt | g  | j ƒ  D]+ } t g  | D] } | r*| ^ q*Œ  ^ qŒ  }  q7 ˆ  |  ƒ }  Pq7 W|  S(   Nc           sï  |  j  s |  St t |  j ƒ ƒ } t | ƒ d k r=t } x¶ t t | ƒ ƒ D]¢ } | | } | d  k ro qM n  x} t | d t | ƒ ƒ D]b } | | } | d  k r« q‰ n  | | } ˆ  | ƒ }	 |	 | k r‰ |	 | | <d  | | <t } Pq‰ q‰ WqM W| r9t	 g  | D] }
 |
 r|
 ^ qŒ  }  |  j  r9ˆ  |  ƒ }  q9n  |  St
 d t | Œ } | sY|  S| \ } } } } } } | r±| | } | | k rŸ| t | | ƒ S| t | | ƒ S| | } | | k rÙ| t | | ƒ S| t | | ƒ Sd  S(   Ni   i   t   two(   R=   RQ   R   R.   R>   RT   R   RU   R_   R   R~   R   R   (   R+   Rr   R.   R   RJ   R7   R€   R   R‚   Rƒ   Rj   R„   R…   R†   R‡   R0   R[   t   same(   R‰   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR‰   D  sL    
	
 



%	

c         S  s   t  t |  j ƒ ƒ S(   N(   t   tupleR   t   free_symbols(   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   }  Rn   i    i   (   R=   R_   RŠ   R   RQ   R.   RN   R4   Rd   R   t   HalfR5   Rv   RC   R/   t   _ROOT3t	   _invROOT3R   R>   RU   R   t   values(   R+   t   byradR0   R   R7   R.   R[   RJ   R€   R‚   Rƒ   RK   Rj   (    (   R‰   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   @  sR    	8	 	BN(   t   _ROOT2RU   t   _rootsR$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR10i*  s    
	kc           s   ‡  f d †  } t  |  | ƒ S(   sn  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           s›  |  j  t t f k r |  Sˆ  rá |  j  } | ˆ  d ƒ } t j } | j r_ | j ƒ  \ } } n  | j  t t f k rx |  S|  j d | j d k rÝ t ˆ  ƒ } t ˆ  ƒ } | t k rÊ | d | d | Sd | | | Sn  |  S|  j d j s—|  j d j d t	 ƒ \ } } | j
 d d k r—| j
 d | | j } t t | ƒ ƒ } t t | ƒ ƒ } |  j  t k rd | | }  q”| d | d }  q—n  |  S(   Ni   i    t   rational(   R<   R   R   R   R/   RN   Ru   R.   t	   is_NumberR_   Re   t   qt   TR11(   R+   R1   RY   t   coR{   R|   t   mRŽ   (   R5   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   Ø  s6    			(   R$   (   R+   R5   R1   (    (   R5   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRž   ®  s    *#c           s   ‡  f d †  } t  |  | ƒ S(   s  Separate sums in ``tan``.

    Examples
    ========

    >>> from sympy.simplify.fu import TR12
    >>> 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           sÅ   |  j  t k s |  S|  j d } | j rÁ ˆ  rG t t | j ƒ ƒ } n t | j ƒ } | j ƒ  } t j | ƒ } | j r• t	 t | ƒ d t
 ƒ} n t | ƒ } t | ƒ | d t | ƒ | S|  S(   Ni    Rr   i   (   R<   R   R.   R=   RQ   R   RS   R   RŒ   t   TR12RT   (   R+   RŽ   R.   R0   R[   t   tb(   Rr   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1     s    		 (   R$   (   R+   Rr   R1   (    (   Rr   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR¡   þ  s    c           s,   d d l  m ‰  ‡  f d †  } t |  | ƒ S(   sJ  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))
    iÿÿÿÿ(   R#   c      	     sU  |  j  p |  j p |  j s |  S|  j ƒ  \ } } | j sE | j rI |  Si  } d „  } t t j | ƒ ƒ } xƒt | ƒ D]u\ } } | | ƒ } | rê | \ }	 }
 t	 g  |
 j D] } | j d ^ q± Œ  } t
 j | | <|	 | | <qz n  | j  r+ˆ  | ƒ } | j rï| j | j ƒ t
 j | | <qïqz | j rz | j j sL| j j rz | | j ƒ } | r·| \ }	 }
 t	 g  |
 j D] } | j d ^ qzŒ  } | j | | <|	 | j | | <qïˆ  | ƒ } | j rï| j | j ƒ t
 j | | <qïqz qz W| sý|  Sd „  } t t j t | ƒ ƒ ƒ } t } xµt | ƒ D]§\ } } | | ƒ } | s@| | ƒ } | rut
 j | | <qM| j  r¹ˆ  | ƒ } | j r4| j | j ƒ t
 j | | <q4q4qM| j r4| j j sÚ| j j r4| | j ƒ } | rÿt
 j | | <q=ˆ  | ƒ } | j r4| j | j ƒ t
 j | | <q4q4qMq4n t
 j | | <t } t	 g  | D] } | j d ^ q]Œ  } | | } | j t
 j ƒ } | d  k	 rÄ| r´| | | <qÄ| j | ƒ n  | | c t | ƒ 9<q4W| rQt | Œ  t | Œ  t g  | j ƒ  D]< \ } } t	 g  | j D] } t | ƒ ^ q!Œ  d | ^ qŒ  }  n  |  S(   Nc         S  sx   t  |  ƒ } | rt | \ } } } | t j k rt | j rt t | j ƒ d k rt t d „  | j Dƒ ƒ rt | | f Sn  d  S(   Ni   c         s  s   |  ] } t  | t ƒ Vq d  S(   N(   R-   R   (   R6   t   fi(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pys	   <genexpr>H  s    (   t   as_f_sign_1R   t   NegativeOneRN   R>   R.   t   all(   t   diR    Rf   R1   R|   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRB   C  s    -i    c         S  s\   |  j  rX t |  j ƒ d k rX |  j \ } } t | t ƒ rX t | t ƒ rX | | f Sn  d  S(   Ni   (   R=   R>   R.   R-   R   (   t   niR0   R[   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRB   h  s    i   (   R=   RN   R4   RO   R.   RQ   R   R9   RD   R   R   R/   Rw   Rd   R:   R5   R;   R
   RT   R¥   R_   t   extract_additivelyRU   RS   R   RV   (   R+   RW   RF   t   dokRB   t   d_argsRJ   R§   R    Rf   RY   t   _R|   t   n_argsR   R¨   t   edt   newedR@   R0   (   R#   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   9  s”    	)
		!)						&
S(   t   sympyR#   R$   (   R+   R1   (    (   R#   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR12i"  s    cc         C  s   d „  } t  |  | ƒ S(   s  Change products of ``tan`` or ``cot``.

    Examples
    ========

    >>> from sympy.simplify.fu import TR13
    >>> from sympy import tan, cot, cos
    >>> 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         S  sü  |  j  s |  Si g  t 6g  t 6g  d  6} xa t t j |  ƒ ƒ D]J } | j t t f k rw | | j j | j	 d ƒ q> | d  j | ƒ q> W| t } | t } t
 | ƒ d k  rÈ t
 | ƒ d k  rÈ |  S| d  } xk t
 | ƒ d k r?| j ƒ  } | j ƒ  } | j d t | ƒ t | | ƒ t | ƒ t | | ƒ ƒ qÕ W| rb| j t | j ƒ  ƒ ƒ n  xk t
 | ƒ d k rÏ| j ƒ  } | j ƒ  } | j d t | ƒ t | | ƒ t | ƒ t | | ƒ ƒ qeW| rò| j t | j ƒ  ƒ ƒ n  t | Œ  S(   Ni    i   i   (   RN   R   R   RU   R   R   R9   R<   RC   R.   R>   RS   (   R+   R.   R0   RY   R{   t   t1t   t2(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   ­  s2    	

$
AA(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR13Ÿ  s    	c         C  s   d „  } t  |  | ƒ S(   sª  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
    ==========

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

    c      	   S  s°  |  j  s |  St t ƒ } i  } g  } x |  j D]t } | j ƒ  \ } } | j r– t | t ƒ r– | j d j ƒ  \ } } | | j	 | ƒ | | | <q/ | j	 | ƒ q/ Wg  }	 x«| D]£} | | } | j
 ƒ  g  }
 xy| rOd } | d } } x$ | | k r| d 7} | d 9} qô W| d k r6t d | | | ƒ d | t | | ƒ } d  } g  } x^ t | ƒ D]P } | d } t | | d t ƒ} | j	 | ƒ t | | | pµ| | ƒ } qkWx` t | ƒ D]R } | j ƒ  } t | | d t ƒ} | | c | 8<| | sÌ| j | ƒ qÌqÌW|	 j	 | | ƒ q× |
 j	 | j d ƒ ƒ q× W|
 | (q´ W|	 r¬t |	 | g  | D]- } | | D] } t | | d t ƒ^ q€qrŒ  }  n  |  S(   Ni    i   i   RM   (   RN   R   RQ   R.   t   as_base_expRv   R-   R   Ru   RC   t   sortR   RU   R   RT   Rx   RS   t   removeR   (   R+   R.   t   cosst   otherR{   R[   R@   RŸ   R0   Rƒ   t   noR?   t   cct   cit   newargt   taket   ccsRJ   t   key(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   	  sZ    	

	
.
!

A(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TRmorrieÎ  s    ;	7c           s   ‡  f d †  } t  |  | ƒ S(   s  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           sc  |  j  s |  Sˆ  r„ |  j ƒ  \ } } | t j k	 r„ t | d t ƒ} t | d t ƒ} | | k sp | | k r} | | }  n  |  Sn  g  } g  } xö |  j D]ë } | j ré | j ƒ  \ } }	 |	 j	 pÊ | j
 sà | j | ƒ qš n  | } n	 t j }	 t | ƒ }
 |
 s|
 d j t t f k rT|	 t j k r=| j | ƒ qš | j | |	 ƒ qš n  |
 \ } } } | j | |	 j |	 | | | f ƒ qš Wt t | ƒ ƒ } t | ƒ } t t d ƒ ƒ } \ } } }	 } } } xl| r=| j d ƒ } | r!| d } | |	 j rd| |	 j rd| | | | k r| | | | k ra| j d ƒ } t | |	 | |	 ƒ } | |	 | k r¯g  | D] } | | ^ qv} | |	 c | 8<| j d | ƒ nP | |	 | k rÿg  | D] } | | ^ qÆ} | |	 c | 8<| j d | ƒ n  t | | t ƒ rt } n t } | j | | | | | | | j d ƒ d | ƒ qÒqaqq!| |	 | |	 k r!| | | | k r| | | | k r| j d ƒ } | |	 } t | | t ƒ rÕt } n t } | j | | | | | | | j d ƒ d | ƒ qÒqqq!n  | j | | | |	 ƒ qÒWt | ƒ | k r_t | Œ  }  n  |  S(   NRr   i   i   i    i   (   RN   RO   R   R/   t   TR14RT   R.   R4   Rµ   R:   R;   RC   R¤   R<   R   R   Rœ   RQ   R   R>   R   RS   Rx   t   insertR-   R   (   R+   RW   RF   Ry   Rz   R¹   t   processR0   R[   R@   R    Rf   R1   t   sit   notherRR   RY   t   At   BR¾   RJ   t   rem(   Rr   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   Y  s†    				 &(	
	7
	7(   R$   (   R+   Rr   R1   (    (   Rr   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRÂ   C  s    `c           s   ‡  ‡ f d †  } t  |  | ƒ S(   s"  Convert sin(x)*-2 to 1 + cot(x)**2.

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

    Examples
    ========

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

    c      	     sl   t  |  t ƒ o t  |  j t ƒ s% |  Sd |  } t | t t d „  d ˆ  d ˆ ƒ} | | k rh | }  n  |  S(   Ni   c         S  s   d |  S(   Ni   (    (   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   Ñ  Rn   Rh   Ri   (   R-   R   R5   R   Rk   R   (   R+   t   iaR0   (   Rh   Ri   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   Ì  s    !
$	(   R$   (   R+   Rh   Ri   R1   (    (   Rh   Ri   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR15¼  s    
c           s   ‡  ‡ f d †  } t  |  | ƒ S(   s"  Convert cos(x)*-2 to 1 + tan(x)**2.

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

    Examples
    ========

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

    c      	     sl   t  |  t ƒ o t  |  j t ƒ s% |  Sd |  } t | t t d „  d ˆ  d ˆ ƒ} | | k rh | }  n  |  S(   Ni   c         S  s   d |  S(   Ni   (    (   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   î  Rn   Rh   Ri   (   R-   R   R5   R   Rk   R   (   R+   RÊ   R0   (   Rh   Ri   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   é  s    !
$	(   R$   (   R+   Rh   Ri   R1   (    (   Rh   Ri   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR16Ù  s    
c         C  s   d „  } t  |  | ƒ S(   sD  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         S  sÅ   t  |  t ƒ o0 |  j j p0 |  j j o0 |  j j s7 |  St  |  j t ƒ re t |  j j	 d ƒ |  j St  |  j t
 ƒ r“ t |  j j	 d ƒ |  j St  |  j t ƒ rÁ t |  j j	 d ƒ |  j S|  S(   Ni    (   R-   R   R5   R;   Rd   R:   t   is_negativeR   R   R.   R   R   R   R   (   R+   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1     s    $(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR111ö  s    	c           s   ‡  ‡ f d †  } t  |  | ƒ S(   sh  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      	     sw   t  |  t ƒ o$ |  j j t t f k s+ |  St |  t t d „  d ˆ  d ˆ ƒ}  t |  t t d „  d ˆ  d ˆ ƒ}  |  S(   Nc         S  s   |  d S(   Ni   (    (   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   ,  Rn   Rh   Ri   c         S  s   |  d S(   Ni   (    (   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   -  Rn   (	   R-   R   R5   R<   R   R   Rk   R   R   (   R+   (   Rh   Ri   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   (  s
    '$$(   R$   (   R+   Rh   Ri   R1   (    (   Rh   Ri   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TR22  s    c         C  s   d „  } t  |  | ƒ S(   s   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
    ==========

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

    c      	   S  s  t  |  t ƒ o$ t  |  j t t f ƒ s+ |  S|  j ƒ  \ } } | j d } | j r{| j r{| j	 rÏ t  | t ƒ rÏ d d | t
 g  t | d d ƒ D]+ } t | | ƒ t | d | | ƒ ^ q— Œ  }  n}| j	 rZt  | t ƒ rZd d | d | d d t
 g  t | d d ƒ D]3 } t | | ƒ d | t | d | | ƒ ^ qŒ  }  nò | j rÉt  | t ƒ rÉd d | t
 g  t | d ƒ D]+ } t | | ƒ t | d | | ƒ ^ q‘Œ  }  nƒ | j rLt  | t ƒ rLd d | d | d t
 g  t | d ƒ D]3 } t | | ƒ d | t | d | | ƒ ^ qŒ  }  n  | j r{|  d | t | | d ƒ 7}  q{n  |  S(   Ni    i   i   iÿÿÿÿ(   R-   R   R5   R   R   Rµ   R.   Rv   R;   t   is_oddR   R   R   t   is_even(   R+   R[   RW   Rl   R?   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   H  s(    'J!RFN	&(   R$   (   R+   R1   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   TRpower3  s    	c         C  s   t  |  j t ƒ ƒ S(   sá   Return count of trigonometric functions in expression.

    Examples
    ========

    >>> from sympy.simplify.fu import L
    >>> from sympy.abc import x
    >>> from sympy import cos, sin
    >>> L(cos(x)+sin(x))
    2
    (   R   t   countR!   (   R+   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   La  s    c         C  s   t  |  ƒ |  j ƒ  f S(   N(   RÔ   t	   count_ops(   Rl   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm   •  Rn   c         C  sG  t  t | ƒ } t  t | ƒ } |  } t |  ƒ }  t |  t ƒ sn |  j g  |  j D] } t | d | ƒ^ qO Œ  St	 |  ƒ }  |  j
 t t ƒ rÝ | |  ƒ } | | ƒ | |  ƒ k  r¹ | }  n  |  j
 t t ƒ rÝ t |  ƒ }  qÝ n  |  j
 t t ƒ r.| |  ƒ } t t | ƒ ƒ } t | |  | | g d | ƒ}  n  t t |  ƒ |  d | ƒS(   s[  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
    ==========
    http://rfdz.ph-noe.ac.at/fileadmin/Mathematik_Uploads/ACDCA/
    DESTIME2006/DES_contribs/Fu/simplification.pdf
    t   measureRÀ   (   R%   t   RL1t   RL2R   R-   R   R<   R.   t   fuR2   t   hasR   R   R3   R   R   Rs   RÁ   Rx   R\   (   R+   RÖ   t   fRL1t   fRL2R‚   R0   t   rv1t   rv2(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRÙ   •  s$    F/	!c         C  sŠ  t  t ƒ } | r xµ |  j D]^ } | j ƒ  \ } } | d k  rQ | } | } n  | | | ri | | ƒ n d f j | ƒ q WnI | r¾ x@ |  j D]& } | t j | | ƒ f j | ƒ q‘ Wn t d ƒ ‚ g  } t } x˜ | D] }	 | |	 }
 |	 \ } } t	 |
 ƒ d k rXt
 d t |
 Œ } | | ƒ } | | k rD| } t } n  | j | | ƒ qÝ | j | |
 d ƒ qÝ W| r†t
 | Œ  }  n  |  S(   s  Apply ``do`` to addends of ``rv`` that (if key1=True) share at least
    a common absolute value of their coefficient and the value of ``key2`` when
    applied to the argument. If ``key1`` is False ``key2`` must be supplied and
    will be the only key applied.
    i    i   s   must have at least one keyRM   (   R   RQ   R.   Ru   RC   R   R/   t
   ValueErrorRT   R>   R   R_   (   R+   R‰   t   key2t   key1t   abscR0   R{   R.   R   R?   RK   R¬   R@   Rƒ   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRŠ   ð  s8    
0'
	s~   
    TR0 TR1 TR2 TR3 TR4 TR5 TR6 TR7 TR8 TR9 TR10 TR10i TR11
    TR12 TR13 L TR2i TRmorrie TR12i
    TR14 TR15 TR16 TR111 TR22c           C  s'   t  d ƒ t  d ƒ a a d t a d  S(   Ni   i   i   (   R    R˜   R”   R•   (    (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR™   !  s    c           s8  t  d k r t ƒ  n  g  |  | f D] } t | ƒ ^ q# \ }  } |  j | ƒ \ } } |  j | ƒ j ƒ  } d } } t j | j	 k r£ | j
 t j ƒ } | } n. t j | j	 k rÑ | j
 t j ƒ } | } n  g  | | f D] } | j ƒ  ^ qÞ \ }  } d „  }	 |	 |  | ƒ }
 |
 d k r$d S|
 \ } } } |	 | | ƒ }
 |
 d k rRd S|
 \ } } } | rn| sƒ| r½t | t ƒ r½| | | | | | f \ } } } } } } | | } } n  | s| pÌ| } | pØ| } t | | j ƒ sñd S| | | | j d | j d t | t ƒ f S| rÛ| rÛ| rÛ| rÛ| rÛ| rÛt | | j ƒ t | | j ƒ k	 rld Sd „  | | f Dƒ ‰  t ‡  f d †  | | f Dƒ ƒ s¨d S| | | | j d | j d t | | j ƒ f Sn  | rç| s)| ró| s)| r-| d k r| d k s)| d k r-| d k r-d S| p6| } | pB| } | j | j k r[d S| smt j } n  | st j } n  | | k r¶| t  9} | | | | j d t d t f S| | t k rõ| d | 9} | | | | j d t d	 t f S| | t k r4| d | 9} | | | | j d t d
 t f Sd S(   s)  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)
    i   c         S  s   d } } t j } |  j rŒ|  j ƒ  \ } }  t |  j ƒ d k sJ | rN d S|  j ri t |  j ƒ } n	 |  g } | j d ƒ }  t	 |  t
 ƒ r™ |  } nD t	 |  t ƒ r± |  } n, |  j rÙ |  j t j k rÙ | |  9} n d S| rj| d } t	 | t
 ƒ r| r| } qg| } qjt	 | t ƒ r;| r2| } qg| } qj| j rc| j t j k rc| | 9} qjd Sn  | t j k	 r| n d | | f St	 |  t
 ƒ r¤|  } n t	 |  t ƒ r¼|  } n  | d k rØ| d k rØd S| t j k	 rí| n d } | | | f S(   s½  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.
        i   i    N(   RU   R   R/   RN   Ru   R>   R.   RQ   RS   R-   R   R   R4   Rd   R“   (   R0   R   R{   R|   RŸ   R.   R[   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   pow_cos_sinj  sN    
						
				"		Ni    c         S  s   h  |  ] } | j  ’ q S(    (   R.   (   R6   R€   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pys	   <setcomp>Ä  s   	 c         3  s   |  ] } | j  ˆ  k Vq d  S(   N(   R.   (   R6   RJ   (   R.   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pys	   <genexpr>Å  s    i   i   i   i   (   R˜   RU   R™   R   R)   R…   t   as_exprR   R¥   t   factorst   quoR-   R   R<   R.   R   R¦   R/   R   RT   R”   R•   (   R0   R[   R   RJ   t   uat   ubR…   R†   R‡   Rã   R    t   coat   cat   sat   cobt   cbt   sbR{   R|   (    (   R.   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR~   (  sv    3
+


+	B"*-$"36
!!c   
      C  sû  |  j  s t |  j ƒ d k r# d S|  j \ } } | t j t j f k r¥ t j } | j r˜ | j d j r˜ | j d d k  r˜ | | } } | } n  | | | f Sg  |  j D] } t | ƒ ^ q¯ \ } } | j	 | ƒ \ } } | j
 | ƒ j ƒ  } t j | j k r*| j t j ƒ } d } d }	 n= t j | j k r]| j t j ƒ } d } d }	 n
 d } }	 g  | | f D] } | j ƒ  ^ qt\ } } | t j k r¾| | } } |	 | } }	 n  | d k rÛ| } |	 }	 n  | t j k r÷| | |	 f Sd S(   sø  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)
    i   Ni    iÿÿÿÿi   (   R=   R>   R.   R   R¥   R/   RN   Rœ   R   R)   R…   Rä   Rå   Ræ   (
   R@   R0   R[   Rf   RJ   Rç   Rè   R…   R†   R‡   (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR¤   Þ  s<    	,
(		
+
c           s   ‡  f d †  } t  |  | ƒ S(   s+  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
    ==========

    https://en.wikipedia.org/wiki/Hyperbolic_function
    c           s  t  |  t ƒ s |  S|  j d } | j s3 | ˆ  n& t j g  | j D] } | ˆ  ^ qC ƒ } t  |  t ƒ ry t t | ƒ St  |  t	 ƒ r’ t
 | ƒ St  |  t ƒ r¯ t t | ƒ St  |  t ƒ rÌ t | ƒ t St  |  t ƒ rå t | ƒ St  |  t ƒ rt | ƒ t St d |  j ƒ ‚ d  S(   Ni    s   unhandled %s(   R-   R   R.   R=   R   RŒ   R   R   R   R   R   R   R   R   R   R   R   R   R   t   NotImplementedErrorR<   (   R+   R0   RJ   (   RF   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   (  s"    <

(   R$   (   R@   RF   R1   (    (   RF   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   _osborne  s    c           s   ‡  f d †  } t  |  | ƒ S(   s*  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
    ==========

    https://en.wikipedia.org/wiki/Hyperbolic_function
    c           s  t  |  t ƒ s |  S|  j d j ˆ  d t ƒ\ } } | j i t j ˆ  6ƒ | t } t  |  t	 ƒ rs t
 | ƒ t St  |  t ƒ rŒ t | ƒ St  |  t ƒ r© t | ƒ t St  |  t ƒ rÆ t | ƒ t St  |  t ƒ rß t | ƒ St  |  t ƒ rü t | ƒ t St d |  j ƒ ‚ d  S(   Ni    t   as_Adds   unhandled %s(   R-   R!   R.   t   as_independentR_   t   xreplaceR   R/   R   R   R   R   R   R   R   R   R   R   R   R   R   Rï   R<   (   R+   t   constRl   R0   (   RF   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyR1   O  s"    "!

(   R$   (   R@   RF   R1   (    (   RF   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt	   _osbornei?  s    c           s¹   d d l  m ‰ d d l m ‰  |  j t ƒ } g  | D] } | t ƒ  f ^ q6 ‰ |  j t ˆ ƒ ƒ } g  ˆ D] \ } } | | f ^ qm ‰ t ƒ  ‰ t	 | ˆ ƒ ‡  ‡ ‡ ‡ f d †  f S(   sÇ  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
    ==========

    https://en.wikipedia.org/wiki/Hyperbolic_function
    iÿÿÿÿ(   R]   (   t   collectc           s.   ˆ  ˆ t  |  ˆ ƒ j t ˆ ƒ ƒ ƒ t j ƒ S(   N(   Rõ   Ró   t   dictR   t   ImaginaryUnit(   Rl   (   Rö   RF   t   repsR]   (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyRm     s   (
   Ra   R]   t   sympy.simplify.radsimpRö   t   atomsR!   R   Ró   R÷   Rð   (   R+   t   trigsRY   t   maskedR?   RK   (    (   Rö   RF   Rù   R]   s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   hyper_as_trigf  s    "%	c         C  s0   |  j  t t ƒ s |  St t t |  ƒ ƒ ƒ Sd S(   sœ  Convert products and powers of sin and cos to sums.

    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)
    N(   RÚ   R   R   Rs   R   RÒ   (   t   expr(    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   sincos_to_sum‘  s    N(v   t   __doc__t
   __future__R    R   t   collectionsR   t   sympy.core.addR   t   sympy.core.basicR   t   sympy.core.compatibilityR   R   t   sympy.core.exprR   t   sympy.core.exprtoolsR   R	   R
   t   sympy.core.functionR   t   sympy.core.mulR   t   sympy.core.numbersR   R   t   sympy.core.powerR   t   sympy.core.symbolR   t   sympy.core.sympifyR   t(   sympy.functions.combinatorial.factorialsR   t%   sympy.functions.elementary.hyperbolicR   R   R   R   R   R   R   t(   sympy.functions.elementary.trigonometricR   R   R   R   R   R   R    R!   t   sympy.ntheory.factor_R"   t   sympy.polys.polytoolsR#   Ra   R$   t   sympy.strategies.treeR%   t   sympy.strategies.coreR&   R'   R°   R(   R,   R2   R3   RT   R\   Rb   Rc   Rk   Ro   Rp   Rq   R_   Rs   R‹   R   Rš   RU   Rž   R¡   R±   R´   RÁ   RÂ   RË   RÌ   RÎ   RÏ   RÒ   RÔ   RQ   t   mapt   CTR1t   CTR2t   CTR3t   CTR4R×   RØ   RÙ   RŠ   R„   t   fufuncsR÷   t   zipt   localst   gett   FUR™   R˜   R~   R¤   Rð   Rõ   Rþ   R   (    (    (    s0   lib/python2.7/site-packages/sympy/simplify/fu.pyt   <module>»   s’   4:				t	*		9	K	^0	„P$	}	/	uy	 	.		*i!$		[-0	¶	9	(	'	+