
    Xh	                     ,   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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 d dl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%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl$m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZC d dlDmEZE d dlFmGZG g dddfdZHe2e0fZId ZJd0dZKd ZLddd ZMd! ZNd"aOd# ZPd$ ZQd% ZRd& ZSd' ZTd( ZUd0d)ZVed0d*            ZWdd+d,ZXd- ZYd. ZZd1d/Z[d"S )2    )defaultdict)reduce)sympifyBasicSExprfactor_termsMulAdd	bottom_up)cacheit)	count_ops_mexpandFunctionClassexpand
expand_mul_coeff_isneg
Derivative)IInteger)igcd)_nodes)DummysymbolsWild)
SYMPY_INTS)	sincosexpcoshtanhsinhtancotcoth)atan2)HyperbolicFunction)TrigonometricFunction)Polyfactorcancelparallel_poly_from_expr)ZZ)PolificationFailed)groebner)cse)identity)greedy)iterable)debugFgrlexc                    d d fd}t          d          |                     t          j                  } t          j        fg}t	          |                                           \  }	 t          |g          \  \  }}	}
n# t          $ r | cY S w xY wt          d|
j	                    ||
j	        |          \  }t          d|           t          ddt                               t          d	dt                               s| S t          |t          
          t          dt                    dt                               ddlm r |	j        t#                                        |	j	                   r t'          |z             j         }g }|                                D ]E\  }}t#          t          |g          d         j	                  d}|rd}|D ]}t'          |          }                    |j	                  s] |j        t#          |j	                                                 s.d}                    |                                j	                   |fdD             }fdj        D             }|                    t9          d t;          |          D               |z  ||t          |                              |          z             Gt=          | S  | t                    z   t          |                              |          S )a   
    Simplify trigonometric expressions using a groebner basis algorithm.

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

    This routine takes a fraction involving trigonometric or hyperbolic
    expressions, and tries to simplify it. The primary metric is the
    total degree. Some attempts are made to choose the simplest possible
    expression of the minimal degree, but this is non-rigorous, and also
    very slow (see the ``quick=True`` option).

    If ``polynomial`` is set to True, instead of simplifying numerator and
    denominator together, this function just brings numerator and denominator
    into a canonical form. This is much faster, but has potentially worse
    results. However, if the input is a polynomial, then the result is
    guaranteed to be an equivalent polynomial of minimal degree.

    The most important option is hints. Its entries can be any of the
    following:

    - a natural number
    - a function
    - an iterable of the form (func, var1, var2, ...)
    - anything else, interpreted as a generator

    A number is used to indicate that the search space should be increased.
    A function is used to indicate that said function is likely to occur in a
    simplified expression.
    An iterable is used indicate that func(var1 + var2 + ...) is likely to
    occur in a simplified .
    An additional generator also indicates that it is likely to occur.
    (See examples below).

    This routine carries out various computationally intensive algorithms.
    The option ``quick=True`` can be used to suppress one particularly slow
    step (at the expense of potentially more complicated results, but never at
    the expense of increased total degree).

    Examples
    ========

    >>> from sympy.abc import x, y
    >>> from sympy import sin, tan, cos, sinh, cosh, tanh
    >>> from sympy.simplify.trigsimp import trigsimp_groebner

    Suppose you want to simplify ``sin(x)*cos(x)``. Naively, nothing happens:

    >>> ex = sin(x)*cos(x)
    >>> trigsimp_groebner(ex)
    sin(x)*cos(x)

    This is because ``trigsimp_groebner`` only looks for a simplification
    involving just ``sin(x)`` and ``cos(x)``. You can tell it to also try
    ``2*x`` by passing ``hints=[2]``:

    >>> trigsimp_groebner(ex, hints=[2])
    sin(2*x)/2
    >>> trigsimp_groebner(sin(x)**2 - cos(x)**2, hints=[2])
    -cos(2*x)

    Increasing the search space this way can quickly become expensive. A much
    faster way is to give a specific expression that is likely to occur:

    >>> trigsimp_groebner(ex, hints=[sin(2*x)])
    sin(2*x)/2

    Hyperbolic expressions are similarly supported:

    >>> trigsimp_groebner(sinh(2*x)/sinh(x))
    2*cosh(x)

    Note how no hints had to be passed, since the expression already involved
    ``2*x``.

    The tangent function is also supported. You can either pass ``tan`` in the
    hints, to indicate that tan should be tried whenever cosine or sine are,
    or you can pass a specific generator:

    >>> trigsimp_groebner(sin(x)/cos(x), hints=[tan])
    tan(x)
    >>> trigsimp_groebner(sinh(x)/cosh(x), hints=[tanh(x)])
    tanh(x)

    Finally, you can use the iterable form to suggest that angle sum formulae
    should be tried:

    >>> ex = (tan(x) + tan(y))/(1 - tan(x)*tan(y))
    >>> trigsimp_groebner(ex, hints=[(tan, x, y)])
    tan(x + y)
    c                    d}g g g }}}| D ]t          t          t          f          r}!t          t                    r|                               Lt                    r|                    d         dd         f           |                    t          fddd         D              d         t          dd                    gz             d         j	                   |                               ||||fS )z-Split hints into (n, funcs, iterables, gens).   r   Nc                 2    g | ]} d          |          S r    ).0xes     i/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/simplify/trigsimp.py
<listcomp>z:trigsimp_groebner.<locals>.parse_hints.<locals>.<listcomp>   s%    ,,,TQqT!WW,,,    )

isinstancer   r   r   appendr3   extendr,   r   gens)hintsnfuncs	iterablesrE   r>   s        @r?   parse_hintsz&trigsimp_groebner.<locals>.parse_hints   s6   !#R$y 	 	A!j'233 A}-- 
Q!   !A$!""/// 3,,,,ae,,,!S!ABB%[0A0A/BBD DDEGGKM M M M A%D((rA   c           	         g }t          d          }|D ]=\  }}t          t          t          t          |           dz  t          |           dz  z   dz
  gt          t
          t          t	          |           dz  t          |           dz  z
  dz
  gfD ]\  }}}}	|dk    r|||fv r |j        |	           $||k    r; |j         ||| z             ||| z            z   ||| z            z
             e|||fv rU |||z                                d          	                    ||           }
 |j         ||| z            |
z
             ?t          t          |                    S )av  
        Build generators for our ideal. ``Terms`` is an iterable with elements of
        the form (fn, coeff), indicating that we have a generator fn(coeff*x).

        If any of the terms is trigonometric, sin(x) and cos(x) are guaranteed
        to appear in terms. Similarly for hyperbolic functions. For tan(n*x),
        sin(n*x) and cos(n*x) are guaranteed.
        y   r8   Ttrig)r   r   r   r#   r    r"   r!   rC   r   subslistset)r=   termsr   rL   fncoeffcstrelcns              r?   build_idealz&trigsimp_groebner.<locals>.build_ideal   s    #JJ 
	/ 
	/IB#sCFFAIA	$9A$=>4tAwwzDGGQJ'>'BC!E 	/ 	/1a A::"A,,AHSMMMM1WWAHQQuQwZZ%'

2QQuQwZZ?@@@@Aq6\\E!G+++66;;AqAABAHRRa[[2-...	/ CFF||rA   c           
      	    !|          \  }}}}t          d|||f           t          |           } |                     |           t          t          |                    }t          t          |                    }t          t          |                     } t          t
          t          t          t          t          hfd| D             }fd| D             }g }i }	|D ]3\  \  }
}|	
                    |g                               |
f           4g }|	                                D ]l\  }}d |D             }d |D             }t          t          |          fdt          ||          D             }t          ||z             t
          t          t          gt          t          t          gfD ]N\  }}}t!          fd|||fD                       r*                    |                               |           OD ]4|                    fdt%          d	|d	z             D                        5g }|D ]\  }t          k    r8|                    t          |f           |                    t
          |f           t          t
          fv r%t          v r|                    t          |f           t          k    r8|                    t          |f           |                    t          |f           t          t          fv r%t          v r|                    t          |f           |                    |           t'          | z   |          }|                    |           |                    fd
|D                        n|D ]
\  }t          k    r&|                    t          |ft
          |fg           7t          k    r&|                    t          |ft          |fg           ht)          dt+          |          z  t,                    } t/          |                               d                              t          t          ||                              }|                     t/          |           |z
              | v rE|                     dz  d	z              |                                |                                |||fS )z
        Analyse the generators ``gens``, using the hints ``hints``.

        The meaning of ``hints`` is described in the main docstring.
        Return a new list of generators, and also the ideal we should
        work with.
        z1n=%s   funcs: %s   iterables: %s    extragens: %sc                 n    g | ]1}|j         v |j        d                                          |j         f2S r:   )funcargsas_coeff_mulr<   gallfuncss     r?   r@   z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>  sH     , , ,A(** fQi,,..7***rA   c                 &    g | ]}|j         v|S r;   )r^   ra   s     r?   r@   z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>  s%    >>>!qvX'='=A'='='=rA   c                     g | ]
}|d          S )r8   r;   r<   r=   s     r?   r@   z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>0      %%%A1Q4%%%rA   c                     g | ]
}|d          S r:   r;   rf   s     r?   r@   z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>1  rg   rA   c                 $    g | ]\  }}||z  fS r;   r;   )r<   rT   vgcds      r?   r@   z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>3  s%    >>>Wb!b!C%[>>>rA   c              3       K   | ]}|v V  	d S Nr;   )r<   r=   fss     r?   	<genexpr>z:trigsimp_groebner.<locals>.analyse_gens.<locals>.<genexpr>6  s'      221qBw222222rA   c              3       K   | ]}|fV  	d S rm   r;   )r<   krT   s     r?   ro   z:trigsimp_groebner.<locals>.analyse_gens.<locals>.<genexpr>:  s'      >>b!W>>>>>>rA   r8   c                 2    h | ]\  }} ||z            S r;   r;   )r<   rT   rj   r=   s      r?   	<setcomp>z:trigsimp_groebner.<locals>.analyse_gens.<locals>.<setcomp>K  s)    777ABBqsGG777rA   zd:%iclsTrN   rM   )r4   rQ   rD   rR   r   r   r#   r"   r    r!   
setdefaultrC   itemsr   r   zipanyaddranger
   r   lenr   r   r   rP   remove)"rE   rF   rG   rH   rI   	extragens	trigtermsfreegensnewgenstrigdictrU   varreskeyvalfnsrS   rV   rW   rX   extrarj   rr_   dummysexprrc   rT   rn   rk   r=   r[   myIrJ   s"                             @@@@@r?   analyse_gensz'trigsimp_groebner.<locals>.analyse_gens   s    *5U););&5)YAi+	- 	- 	- DzzI SZZ  Y((	CII c4t4, , , , , , ,	 ?>>>t>>> ) 	= 	=LUC"R((//<<<< (( ,	9 ,	9HC" &%%%%C%%%%%Cs##C>>>>C>>>EUS[!!B #sOdD$-?@  1a2222Aq	22222 FF1IIIFF1III ? ?>>>>eAq1uoo>>>>>>>E 
, 
,A99LL#q***LL#q***#s##r		LL#q***::LL$+++LL$+++$%%$"**LL$+++LLCIAAu%%AJJqMMMNN77777778888 " 
	2 
	2HBSyy  3+T{!;<<<<t  4,t!=>>>> #d))!3???r3<((//T/::??SQUEVEV@W@WXX

22c4j>>D01111$;;JJsAvz"""OOC   NN3Hg%%rA   r   zinitial gens:zideal:z	new gens:z -- lenz
free gens:)orderrE   domainzgroebner basis:r   )ratsimpmodprime)rE   r8   TFc                     g | ]}|v |	S r;   r;   )r<   r=   ourgenss     r?   r@   z%trigsimp_groebner.<locals>.<listcomp>  s    888a1<<<<<rA   c                 |    g | ]8} |j                             |j                   $|                                9S r;   )has_only_gensintersectionrE   as_expr)r<   rb   r   s     r?   r@   z%trigsimp_groebner.<locals>.<listcomp>  sU     D D DA#AOW%9%9!&%A%ABDAIIKK D D DrA   c                     g | ]
\  }}||z  S r;   r;   )r<   abs      r?   r@   z%trigsimp_groebner.<locals>.<listcomp>  s     CCCdaQTCCCrA   )r   rE   quickr   
polynomial)r   rP   r   ImaginaryUnitr+   as_numer_denomr,   r.   r4   rE   r|   r/   r-   rQ   sympy.simplify.ratsimpr   r   rR   r   r)   ejectrS   
issuperset
differenceupdateexcludepolysrC   r
   rx   r   )r   rF   r   r   r   r   rP   numpnumpdenomoptidealr   monomrU   changedprealgensourGGr[   denomr   rE   r   r   rJ   r   s     ``               @@@@@@@@@r?   trigsimp_groebnerr      s   f) ) )(  0d& d& d& d& d& d& d&L **C99Q_c**D!/"#D,,..JC5sElCCv   	/38$$$(L599E8T	(E	+tYD		222	,)SYY777  e$r:::A	
T!WWiQ888
 766666 ,F(F(#d))*@*@*M*MN ,F1d3T(]+++148IIKK 	J 	JLE515%.AA!DIJJG G 9 9 9AQA"--af55 9*1?CKK,B,B7,K,KL9"&qyy{{'7888  9 98884888HD D D D D D DDJJsCCc(E.B.BCCCD&uU{D,4E"2<> > >>Bd4jjI J J J J Cy $q''Xd]z; ; ;;?4::	Fs   <B B#"B#c                 8    d fdt          |           S )Nc                 ^    	 | j         d         |j         d         k    S # t          $ r Y dS w xY w)Nr   F)r_   
IndexError)r=   rL   s     r?   
check_argsz%_trigsimp_inverse.<locals>.check_args  s@    	6!9q	)) 	 	 	55	s    
,,c                    t          | dd           }|at          | j        d          |                      r>t            |            d          t                    r| j        d         j        d         S t          | t                    r| j        \  }}t          |          r t	          | |                     S t          |          r't          j         t	          ||                     z
  S  ||          r~t          |t                    r"t          |t                    r|j        d         S t          |t                    r2t          |t                    rt          j        dz  |j        d         z
  S | S )Ninverser   r8   rM   )
getattrrB   r_   r(   r&   r   r   Pir   r   )rvrb   rL   r=   r   fs       r?   r   z_trigsimp_inverse.<locals>.f  s^   B	4((MjQQSS99M31133q66#899 71:?1%% b%   	07DAqA .%A,,''a .taaa!oo--z!Q 0a%% %*Q*<*< %6!9$a%% 0*Q*<*< 04!8afQi//	rA   )r   )r   r   r   s    @@r?   _trigsimp_inverser     sC           . RrA   c                   	 ddl m t          |           } t          | dd          }| |di S                     dd          }|sC                    dd                               dd                               d	d
          }nd}d 	fdd 	fd	fdfdd|         } ||           }|rt          |          }|S )a6  Returns a reduced expression by using known trig identities.

    Parameters
    ==========

    inverse : bool, optional
        If ``inverse=True``, it will be assumed that a composition of inverse
        functions, such as sin and asin, can be cancelled in any order.
        For example, ``asin(sin(x))`` will yield ``x`` without checking whether
        x belongs to the set where this relation is true. The default is False.
        Default : True

    method : string, optional
        Specifies the method to use. Valid choices are:

        - ``'matching'``, default
        - ``'groebner'``
        - ``'combined'``
        - ``'fu'``
        - ``'old'``

        If ``'matching'``, simplify the expression recursively by targeting
        common patterns. If ``'groebner'``, apply an experimental groebner
        basis algorithm. In this case further options are forwarded to
        ``trigsimp_groebner``, please refer to
        its docstring. If ``'combined'``, it first runs the groebner basis
        algorithm with small default parameters, then runs the ``'matching'``
        algorithm. If ``'fu'``, run the collection of trigonometric
        transformations described by Fu, et al. (see the
        :py:func:`~sympy.simplify.fu.fu` docstring). If ``'old'``, the original
        SymPy trig simplification function is run.
    opts :
        Optional keyword arguments passed to the method. See each method's
        function docstring for details.

    Examples
    ========

    >>> from sympy import trigsimp, sin, cos, log
    >>> from sympy.abc import x
    >>> e = 2*sin(x)**2 + 2*cos(x)**2
    >>> trigsimp(e)
    2

    Simplification occurs wherever trigonometric functions are located.

    >>> trigsimp(log(e))
    log(2)

    Using ``method='groebner'`` (or ``method='combined'``) might lead to
    greater simplification.

    The old trigsimp routine can be accessed as with method ``method='old'``.

    >>> from sympy import coth, tanh
    >>> t = 3*tanh(x)**7 - 2/coth(x)**7
    >>> trigsimp(t, method='old') == t
    True
    >>> trigsimp(t)
    tanh(x)**7

    r   )fu_eval_trigsimpNoldFdeep	recursivemethodmatchingc                 p    fd |           }t          |t                    s|S t          |fi S )Nc                     | j         r| S fd| j        D             }| j        s| j        rfd|D             } | j        | S )Nc                 &    g | ]} |          S r;   r;   r<   r=   traverses     r?   r@   zDtrigsimp.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>"  !    000AHHQKK000rA   c                 *    g | ]}t          |fi S r;   r   r<   r=   optss     r?   r@   zDtrigsimp.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>$  *    CCC)!44t44CCCrA   is_Atomr_   is_Functionis_Powr^   r>   r_   r   r   s     r?   r   z0trigsimp.<locals>.groebnersimp.<locals>.traverse  i    y 0000000D} D DCCCCdCCC164= rA   )rB   r   r   )exr   newr   s    ` @r?   groebnersimpztrigsimp.<locals>.groebnersimp  s^    	! 	! 	! 	! 	! 	! hrll#t$$ 	J -----rA   c                      | fi S rm   r;   )r=   r   r   s    r?   <lambda>ztrigsimp.<locals>.<lambda>,  s    A rA   c                      t          |           S rm   )futrigr=   s    r?   r   ztrigsimp.<locals>.<lambda>-  s    vayy rA   c                      | fi S rm   r;   )r=   r   r   s    r?   r   ztrigsimp.<locals>.<lambda>.  s    ||A6666 rA   c                 H    t           | ddt          g                    S NTrM   )r   rF   )r   r#   )r=   r   s    r?   r   ztrigsimp.<locals>.<lambda>/  s4    vll1*.q#h'@ '@ '@  A  A rA   c                     t          | fi S rm   )trigsimp_old)r=   r   s    r?   r   ztrigsimp.<locals>.<lambda>1  s    a00400 rA   )r   r   r/   combinedr   r;   )sympy.simplify.fur   r   r   popr   )
r   r   r   r   r   r   trigsimpfuncexpr_simplifiedr   r   s
     `     @@r?   trigsimpr     sK   ~ %$$$$$4==DT#3T::N!~%%%%%
((5%
 
 C d###(J//. . . '&&&&((66666A A A A0000  L #l4((O =+O<<rA   c                    ddl m}m} d }t          | |          }fdt          |          }|                    t
                    r" ||          \  }  ||                    }|                    t                    r ||          }|                    t                    r|                     t                    r|} | S )a#  
    Simplifies exponential / trigonometric / hyperbolic functions.

    Examples
    ========

    >>> from sympy import exptrigsimp, exp, cosh, sinh
    >>> from sympy.abc import z

    >>> exptrigsimp(exp(z) + exp(-z))
    2*cosh(z)
    >>> exptrigsimp(cosh(z) - sinh(z))
    exp(-z)
    r   )hyper_as_trigTR2ic                     | g} | j         t           r-|                    |                     t                               |                    |                     t
                               t          |dt          iS )Nr   )has_trigsrC   rewriter   r   minr   )r>   choicess     r?   exp_trigzexptrigsimp.<locals>.exp_trigL  sf     #15&> 	+NN199S>>***qyy~~&&&G++++rA   c                   
 | j         s| S |                                 \  }}t          |          dk    r t          |           t          | z  S |                                 }|                                
t          j        ffd	|t          j                 }|D ]}|j	        rt          |j
                  dk    r||j
        d         } |j
        d         |z            \  }}|sP||         }	
|xx         |	z  cc<   || |	z  dz  k    rp
t          j        xx         |z  cc<   d}|dk    r'
d|z  t          |dz            z  xx         |	z  cc<   
d|z  t          |dz            z  xx         |	z  cc<   
d|t          j        |z  z  z
           |	 k    rh
d|t          j        |z  z  z
  = |dk    r&
| t          |dz            z  xx         |	z  cc<   G
| t          |dz            z  xx         |	z  cc<   m
d|t          j        |z  z  z   xx         |	z  cc<   
|xx         |	z  cc<   t          
fd
D              S )Nr8   c                    | t           j        u r|t           j        fS t          | t                    s| j        r| j        t           j        k    r	|| j        fS |t           j        u r |  t           j                   S dS )N)sign)NN)r   Exp1OnerB   r   r   base)r   r   signlogs     r?   r   z'exptrigsimp.<locals>.f.<locals>.signlogb  sz    qv~~QU{"D#&& "4; "49;N;NTX~%wuAE62222!zrA   rM   r   c                 &    g | ]}||         z  S r;   r;   )r<   rq   newds     r?   r@   z*exptrigsimp.<locals>.f.<locals>.<listcomp>  s!    ...AQQZ...rA   )is_Mulargs_cncr|   r
   as_powers_dictcopyr   r   r   is_Addr_   r    r"   r!   )r   commutative_partnoncommutative_partrvdeerq   rV   r   r=   mr   r   r   s             @@r?   r   zexptrigsimp.<locals>.fV  s   y 	I02-- #$$q((1S*+,,S2E-FFF!!xxzz u 	" 	" 	" 	" 	" 	" [ 	! 	!Ax !CKK1,,F1I!'!&)A+..a FQ1!Aa<<LLLB&LLLBqyyQqSac]+++q0++++RT$qs))^,,,1,,,,!d1619n,-!33Qafai/0qyyaRQqS		\***a/****aRQqS		\***a/****T!&!)^+,,,1,,,GGGqLGGG.......//rA   )r   r   r   r   r   r'   r(   r   )r   r   r   r   newexprr>   r   s         @r?   exptrigsimpr  ;  s     65555555, , , h''G30 30 30 30 30h ##G {{%&& }W%%1!DDGG**{{())  $w-- KKNN 488A;; KrA   T)firstc                d   | }|r | j         t           s| S  t                      j        d  | j        t           D              }t          |          dk    rddlm}  ||           }|j        r ||d          p|}t          |t                    rLd} |                                D ]2}|}t          |          }dd<   t          |fi }	|	|k    r|}	| |	z  } 3| }nF|j        r?|D ]:}
|                     |
          \  }}|rdd<   |t          |fi z   } | j        s n;| }                    d	d          }                    d
d          }                    dd          }d d fdfdd|         }|rgt#          |           \  }} ||d         |          }t%          |          D ]0}|                    |d         |d                   } |||          }1|}n || |          }                    dd          r%t+          |          }||k    rt-          d|           |S )aC  
    Reduces expression by using known trig identities.

    Notes
    =====

    deep:
    - Apply trigsimp inside all objects with arguments

    recursive:
    - Use common subexpression elimination (cse()) and apply
    trigsimp recursively (this is quite expensive if the
    expression is large)

    method:
    - Determine the method to use. Valid choices are 'matching' (default),
    'groebner', 'combined', 'fu' and 'futrig'. If 'matching', simplify the
    expression recursively by pattern matching. If 'groebner', apply an
    experimental groebner basis algorithm. In this case further options
    are forwarded to ``trigsimp_groebner``, please refer to its docstring.
    If 'combined', first run the groebner basis algorithm with small
    default parameters, then run the 'matching' algorithm. 'fu' runs the
    collection of trigonometric transformations described by Fu, et al.
    (see the `fu` docstring) while `futrig` runs a subset of Fu-transforms
    that mimic the behavior of `trigsimp`.

    compare:
    - show input and output from `trigsimp` and `futrig` when different,
    but returns the `trigsimp` value.

    Examples
    ========

    >>> from sympy import trigsimp, sin, cos, log, cot
    >>> from sympy.abc import x
    >>> e = 2*sin(x)**2 + 2*cos(x)**2
    >>> trigsimp(e, old=True)
    2
    >>> trigsimp(log(e), old=True)
    log(2*sin(x)**2 + 2*cos(x)**2)
    >>> trigsimp(log(e), deep=True, old=True)
    log(2)

    Using `method="groebner"` (or `"combined"`) can sometimes lead to a lot
    more simplification:

    >>> e = (-sin(x) + 1)/cos(x) + cos(x)/(-sin(x) + 1)
    >>> trigsimp(e, old=True)
    (1 - sin(x))/cos(x) + cos(x)/(1 - sin(x))
    >>> trigsimp(e, method="groebner", old=True)
    2/cos(x)

    >>> trigsimp(1/cot(x)**2, compare=True, old=True)
          futrig: tan(x)**2
    cot(x)**(-2)

    c                     g | ]	}|j         
S r;   )free_symbols)r<   rX   s     r?   r@   z trigsimp_old.<locals>.<listcomp>  s     M M MA M M MrA   r8   r   )separatevarsT)dictFr	  r   r   r   r   c                 F    fd|r |           } t          | fi S )Nc                     | j         r| S fd| j        D             }| j        s| j        rfd|D             } | j        | S )Nc                 &    g | ]} |          S r;   r;   r   s     r?   r@   zHtrigsimp_old.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>  r   rA   c                 *    g | ]}t          |fi S r;   r   r   s     r?   r@   zHtrigsimp_old.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>  r   rA   r   r   s     r?   r   z4trigsimp_old.<locals>.groebnersimp.<locals>.traverse  r   rA   r   )r   r   r   r   s     `@r?   r   z"trigsimp_old.<locals>.groebnersimp  sO    	! 	! 	! 	! 	! 	!  	"B ,,t,,,rA   c                 "    t          | |          S rm   	_trigsimp)r=   ds     r?   r   ztrigsimp_old.<locals>.<lambda>  s    )Aq// rA   c                      | |fi S rm   r;   )r=   r  r   r   s     r?   r   ztrigsimp_old.<locals>.<lambda>	  s    ,,q!"<"<t"<"< rA   c           	      L    t           | |ddt          g          |          S r   )r  r#   )r=   r  r   s     r?   r   ztrigsimp_old.<locals>.<lambda>
  s7    )LL'(T!S-K -K -K#$#& #& rA   )r   r/   r   comparez	futrig:)r   r   rR   unionatomsr|   sympy.simplify.simplifyr  r   rB   r  valuesr   r   r  as_independentr   r0   reversedrP   getr   print)r   r	  r   r   trigsymsr  r  rj   wasvnewrW   r   r>   r   r   r   r   wrb   subresultr   r   s     `                   @r?   r   r     s   t C  tx  	K355; M MV9L M M MNx==1<<<<<<T""Ax 4 L...3!!T""  ! !AC"1A$)DM#A....Dqyy"DLDD8 % & &#221551 &,1DM#$x':':T':':#:D#'; & %Ce,,I88FE""DXXh
++F
- 
- 
- 21<<<<<& & & &  L  	*4yy1L1t$$A;; 	& 	&Cs1vs1v&&AQ%%AAdD))xx	5!! "3KK;;+q!!!MrA   c                     | j         |j         k    og|                     t                    r|                    t                    p3|                     t                    o|                    t                    S )zHelper to tell whether ``a`` and ``b`` have the same sorts
    of symbols in them -- no need to test hyperbolic patterns against
    expressions that have no hyperbolics in them.)r^   r   r(   r'   )r   r   s     r?   _dotrigr)  "  sf     6QV A	#$$E/D)E)E 	@	 !!?aee,>&?&?ArA   Nc                  L   t          dt                    \  } }}t          dd          }| t          |          |z  z  t          |          |z  z  | t	          |          |z  z  t          |          t          |          f| t	          |          |z  z  t          |          |z  z  | t          |          |z  z  t          |          t          |          f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          |          t          |          f| t	          |          |z  z  t          |          |z  z  | t          |          |z  z  t          |          t          |          f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          |          t          |          f| t          |          |z  z  t	          |          |z  z  | t          |          t          |          f| t          |          dz   |z  z  t          |          dz
  |z  z  | t          |          dz   |z  z  t          |          dz   t          |          dz
  f| t          |          dz   |z  z  t          |          dz
  |z  z  | t          |          dz   |z  z  t          |          dz   t          |          dz
  f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          j
        t          j
        f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          j
        t          j
        f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          j
        t          j
        f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          j
        t          j
        f| t          |          |z  z  t          |          |z  z  | t          |          |z  z  t          j
        t          j
        f| t          |          |z  z  t          |          |z  z  | t          j
        t          j
        f|t          |           t          |          z   z  dt          |           t          |          z  z   z  t          | |z             |z  t          j
        t          j
        ff}|t          |           z  t          |          z  |t          |           z  t          |          z  z   |z   t          | |z             |z  |z   f|t          |           z  t          |          z  |t          |           z  t          |          z  z
  |z   t          | |z             |z  |z   f|t          |           z  t          |          z  |t          |           z  t          |          z  z
  |z   t          | |z
            |z  |z   f|t          |           z  t          |          z  |t          |           z  t          |          z  z   |z   t          | |z
            |z  |z   f|t          |           z  t          |          z  |t          |          z  t          |           z  z   |z   t          | |z             |z  |z   f|t          |           z  t          |          z  |t          |           z  t          |          z  z   |z   t          | |z             |z  |z   ff}| t          |          dz  z  | | t          |          dz  z  z
  f| t	          |          dz  z  | dt          |          z  dz  z  | z
  f| t          |          dz  z  | dt          |          z  dz  z  | z
  f| t          ||z             z  | t          |          t          |          z  t          |          t          |          z  z   z  f| t          ||z             z  | t          |          t          |          z  t          |          t          |          z  z
  z  f| t	          ||z             z  | t	          |          t	          |          z   dt	          |          t	          |          z  z
  z  z  f| t          |          dz  z  | t          |          dz  z  | z
  f| t          |          dz  z  | | dt          |          z  dz  z  z
  f| t          |          dz  z  | | dt          |          z  dz  z  z   f| t          ||z             z  | t          |          t          |          z  t          |          t          |          z  z   z  f| t          ||z             z  | t          |          t          |          z  t          |          t          |          z  z   z  f| t          ||z             z  | t          |          t          |          z   dt          |          t          |          z  z   z  z  ff}| | t          |          dz  z  z
  |z   | t          |          dz  z  |z   t          f| | dt          |          z  dz  z  z
  |z   |  t	          |          dz  z  |z   t          f| | dt          |          z  dz  z  z
  |z   |  t          |          dz  z  |z   t          f| | t          |          dz  z  z
  |z   |  t          |          dz  z  |z   t          f| | dt          |          z  dz  z  z
  |z   | t          |          dz  z  |z   t          f| | dt          |          z  dz  z  z   |z   | t          |          dz  z  |z   t          f| |z  | |z  t          |          dz  z  z
  |z   | |z  t          |          dz  z  |z   t          f| |z  | |z  dt          |          z  dz  z  z
  |z   |  |z  t	          |          dz  z  |z   t          f| |z  | |z  dt          |          z  dz  z  z
  |z   |  |z  t          |          dz  z  |z   t          f| |z  | |z  t          |          dz  z  z
  |z   |  |z  t          |          dz  z  |z   t          f| |z  | |z  dt          |          z  dz  z  z
  |z   | |z  t          |          dz  z  |z   t          f| |z  | |z  dt          |          z  dz  z  z   |z   | |z  t          |          dz  z  |z   t          ff}| |||||||fat          S )Nza b crt   r  F)commutativer8   rM   )r   r   r   r   r#   r$   r"   r    r!   r   r   r%   _trigpat)r   r   rV   r  matchers_divisionmatchers_addmatchers_identity	artifactss           r?   	_trigpatsr1  ,  s   g4(((GAq!Se$$$A 
3q6619SVVQY	#a&&!)SVVSVV<	
3q6619SVVQY	#a&&!)SVVSVV<	
3q6619SVVQY	#a&&!)SVVSVV<	
3q6619SVVQY	#a&&!)SVVSVV<	
3q6619SVVQY	#a&&!)SVVSVV<	
3q6619SVVQY	3q663q662	
CFFQJ?	CFFQJ?	*A	zAos1vvz3q66A:	7	
CFFQJ?	CFFQJ?	*A	zAos1vvz3q66A:	7 
477A:d1ggqj	 !DGGQJ,qu=	
477A:d1ggqj	 !DGGQJ,qu=	
477A:d1ggqj	 !DGGQJ,qu=	
477A:d1ggqj	 !DGGQJ,qu=	
477A:d1ggqj	 !DGGQJ,qu=	
477A:d1ggqj	 !QUAE2	
DGGd1gg	DGGDGGO 3	4QKKM15!%	)'0 
3q66#a&&1SVV8CFF?	*Q	.AE

1q0@A	
3q66#a&&1SVV8CFF?	*Q	.AE

1q0@A	
3q66#a&&1SVV8CFF?	*Q	.AE

1q0@A	
3q66#a&&1SVV8CFF?	*Q	.AE

1q0@A	
477477	QtAwwYtAww.	.	2DQKKMA4EF	
477477	QtAwwYtAww.	.	2DQKKMA4EFL 
3q6619a!CFFAI+o&	
3q6619a3q66Ao)*	
3q6619a3q66Ao)*	
3q1u::q#a&&Q-#a&&Q-789	
3q1u::q#a&&Q-#a&&Q-789	
3q1u::q3q66CFF?QQA->?@A	
477A:qa!|a'(	
477A:q1aQi!^++,	
477A:q1aQi!^++,	
4A;;477477?T!WWT!WW_<=>	
4A;;477477?T!WWT!WW_<=>	
4A;;DGGd1gg-DGGDGGO0CDEF( 
Qs1vvqy[1	aA	kAos3	
Q#a&&1}_	q	 1"SVVQY,"2C8	
Q#a&&1}_	q	 1"SVVQY,"2C8	
QtAwwz\	A	r$q''1*}q0$7	
Q$q''	A~		!1T!WWaZ<!#3T:	
Q$q''	A~		!1T!WWaZ<!#3T: 
1qs3q6619}	q	 !A#c!ffai-!"3S9	
1qsAc!ffHq= 	 1	$qbd3q6619nq&8#>	
1qsAc!ffHq= 	 1	$qbd3q6619nq&8#>	
1qs477A:~		!A2a4Q
?Q#6=	
1qsAd1ggI>!	!A	%qs477A:~'94@	
1qsAd1ggI>!	!A	%qs477A:~'94@!I& 1a-|9&HOrA   c                    t          t                    }t          t                    }g }| j        D ]}	|	j        s|	j        ||fv rs|	                                \  }
}|
j        s|j        rN|
j        |k    r||
j        d         xx         |z  cc<   `|
j        |k    r||
j        d         xx         |z  cc<   |                    |	           t          |          t          |          z  }d}|r|
                                }|
                    |          }|
                    |          }| ||          k    r-|                     ||           ||          z             d}n
|||<   |||<   ||s| S |r:|                                \  }}|                     ||          |z             |:|r:|                                \  }}|                     ||          |z             |:t          | S )zHelper for _match_div_rewrite.

    Replace f(b_)**c_*g(b_)**(rexp(c_)) with h(b)**rexph(c) if f(b_)
    and g(b_) are both positive or if c_ is an integer.
    r   FT)r   intr_   r   r^   as_base_expis_positive
is_integerrC   rR   r   popitemr
   )r   r   rb   rexphrexphfargsgargsr_   r=   r   r>   commonhitr   feges                    r?   _replace_mul_fpowxgpowrA    s+    EEDY 
 
8 	qv!Q''==??DAq}  6Q;;!&)$$$)$$$Vq[[!&)$$$)$$$AZZ#e**$F
C
 	jjllYYs^^YYs^^b>>KK#b		)***CCE#JE#J  	  
 QAAcFFAI    QAAcFFAI   :rA   c                     | S rm   r;   r   s    r?   r   r     s     rA   c                     |  S rm   r;   r   s    r?   r   r     s    1" rA   c                     t           j        S rm   )r   r   r   s    r?   r   r     s     rA   c                    |dk    r/t          | t          t          t          t          t
                    } nD|dk    r/t          | t          t          t
          t          t
                    } n|dk    r/t          | t          t          t
          t          t
                    } n|dk    r/t          | t          t          t          t          t                    } n|dk    r/t          | t          t          t          t          t                    } np|dk    r/t          | t          t          t
          t          t
                    } n;|dk    r/t          | t          t          t          t          t
                    } n|dk    r.t          | t          t          t
          t          t
                    } n|d	k    r.t          | t          t          t
          t          t
                    } n|d
k    r.t          | t          t          t          t          t                    } nj|dk    r.t          | t          t          t          t          t                    } n6|dk    r.t          | t          t          t
          t          t
                    } ndS | S )zhelper for __trigsimpr   r8   rM               	   
            N)rA  r   r   _midnr#   _idnr$   _oner"   r    r!   r%   )r   is     r?   _match_div_rewriterS    s   Avv%dC3 	
a%dC#t 	
a%dC#t 	
a%dC3 	
a%dC3 	
a%dC$  
a%dD$4 	
a%dD$$ 	
b%dD$$ 	
b%dD$4   	
b%dD$4   	
b%dD$$  tKrA   c                 D     | j         t           rt          | |          S | S rm   )r   r   
__trigsimp)r   r   s     r?   r  r    s*     tx &$%%%KrA   c                     ddl m} t          t                       t          \  }}}}}}| j        rm| j        sP|                                 \  }	}
t          t          j	        |	                    t          j	        |
          z  } nt          |          D ]\  }\  }}}}t          | |          st          | |          }||| k    r|}  nό9|                     |          r                    |d          r|         j        s:|                              }|j        s|                              }|j        st%          fd                             t(          t*                    D                       r|                              }  n| j        rg }| j        D ]}|j        s@|                                \  }	}
t          j	        |
          }
t          j	        |	          }nt0          j        }
t          |          }|D ]3\  }}|                    |          |                              } n4|                    ||
z             || j        k    r-t7          | } t9          | t;          |           t<                    } | j        r|D ]\  }}t          | |          s ||           } |                     t*                    rx|                     |          Iv rEv rAt%          fd|                             t(          t*                    D                       r|                              }  n|D ]$\  }}}t          | |          stA          d|g          }|                    |          }|                    |          }|                     |          }d}|r|| k    r| }||         dk    s+||          ||         j        v s||         ||         z   dk    rnu||v r||         ||         z  ||         z   dk    rnR|                    |          } |                     |          }|!                    |t0          j"                   |r|| k    &n2| j        s| j#        s	r"| j        r | j$        fd	| j        D              } 	  | j        tJ           stL          |                     tN                    }| (                    tN          
          }||k    rtL          tS          |          }||k    r%t9          |tS          |          gt<                    }|                    tN                    |z
  s|} n# tL          $ r Y nw xY w| S )zrecursive helper for trigsimpr   )TR10iNc              3   F   K   | ]}|j         d                   k    V  dS r   Nr_   )r<   r%  r   r   s     r?   ro   z__trigsimp.<locals>.<genexpr>  sJ       H H116!9A. H H H H H HrA   )r   c              3   R   K   | ]!}|j         d                            fv V  "dS rY  rZ  )r<   r%  r   r   r   s     r?   ro   z__trigsimp.<locals>.<genexpr>0  s\       IH IH:;q	c!fc!f%55IH IH IH IH IH IHrA   r   )r   c                 0    g | ]}t          |          S r;   r  )r<   r   r   s     r?   r@   z__trigsimp.<locals>.<listcomp>Q  s#    AAA!9Q--AAArA   )r   )*r   rW  r,  r1  r   is_commutativer   r  r
   
_from_args	enumerater)  rS  matchr   r6  rP   r5  ry   r  r(   r'   r  r_   r   r   rC   r   r   r   r   r   r   rv   Zeror   r^   r   	TypeErrorr   r   r*   )r   r   rW  rV   r  r-  r.  r/  r0  comncrR  patternsimpok1ok2r  okr_   termr'  r   a_tr  r#  r>   r   fnewr   r   r   s    `                          @@@r?   rU  rU    sP    ('''''#+!Aq!Q!<y{ #" !	mmooGCS^C00$77r8J8JJDD09:K0L0L  ,,GT3tW-- ,T155&$&  jj)) 3771a== q6, % XXc]]!~ %$ XXc]]!~ %$  H H H H HA13E9G 9G H H H H H ! 99S>>DE{ >CI 	! 	!D& --//R^B''~c**UT4((D#4  jj))?!;;s++DE # KKR    49:DtVD\\y999D; 	#/  tW-- uT{{88.// 
**W--C {188SS IH IH IH IH IH IH?B1v||13E@G @GIH IH IH FH FH !!;;s++DE
 $- 	( 	(GVR4))  sRD)))Cll1c**G[[C((F

7##AC 	(tS6Q;;31Q49,,#10B0B66afQqTkAaD0A55{{1~~JJw''Q'''  	(t	(. 
 C Ct C	 CtyAAAAtyAAABtx  	OJJsOOll3Tl**!88Oc{{3;;sF3KK(i888C		#" 	D    Ks   ;B2U. .
U;:U;)hyperc                   ddl m} t          |           } t          | t                    s| S | j        s| S | }t          | t                    } |rF|                     t                    r, ||           \  } } |t          | t                              } | |k    r4| j
        r-| j        d         j        rt          |                                  } | S )a  Return simplified ``e`` using Fu-like transformations.
    This is not the "Fu" algorithm. This is called by default
    from ``trigsimp``. By default, hyperbolics subexpressions
    will be simplified, but this can be disabled by setting
    ``hyper=False``.

    Examples
    ========

    >>> from sympy import trigsimp, tan, sinh, tanh
    >>> from sympy.simplify.trigsimp import futrig
    >>> from sympy.abc import x
    >>> trigsimp(1/tan(x)**2)
    tan(x)**(-2)

    >>> futrig(sinh(x)/tanh(x))
    cosh(x)

    r   )r   )r   r   r   rB   r   r_   r   _futrigr   r'   r   is_Rationalr
   as_coeff_Mul)r>   rm  kwargsr   r   r   s         r?   r   r   g  s    ( 0/////

Aa 6 
C!WA %)** %}Q1Ai7##$$CxxAHx!6x!!"HrA   c           !      T   ddl m}mm}mm}mm}m}m	m
mm}mm}m}m}	m}
mm |                     t*                    s| S | j        r|                     t*                    \  }} nd}fd}d t0          ||fdt0          fdgfd|
|||	fd	|
t0          fd
g||t0          |gt0          fdgfdfdgfdfdg|t0          gt0          fdg|t0          fdgfg} t3          ||          |           } ||| z  } | S )zHelper for futrig.r   )TR1TR2TR3r   TR10LrW  TR8TR6TR15TR16TR111TR5TRmorrieTR11_TR11TR14TR22TR12Nc                      |           |                                  t          |           t          | j                  | j        fS rm   )r   r   r|   r_   r  )r=   rx  s    r?   r   z_futrig.<locals>.<lambda>  s2    aaddAKKMM6!99c!&kk18L rA   c                 6    |                      t                    S rm   )r   r(   r   s    r?   r   z_futrig.<locals>.<lambda>  s    aee122 rA   c                 0    t          t          |           S rm   _eapplyr*   r=   trigss    r?   r   z_futrig.<locals>.<lambda>      '&!U++ rA   c                 0    t          t          |           S rm   r  r   r  s    r?   r   z_futrig.<locals>.<lambda>      WXq%88 rA   c                 (    t          d |           S )Nc                 D    t          |                                           S rm   )r*   normal)rR  s    r?   r   z+_futrig.<locals>.<lambda>.<locals>.<lambda>  s    F188::$6$6 rA   r  r  s    r?   r   z_futrig.<locals>.<lambda>  s    '665AA rA   c                 0    t          t          |           S rm   r  r  s    r?   r   z_futrig.<locals>.<lambda>  r  rA   c                 0    t          t          |           S rm   r  r  s    r?   r   z_futrig.<locals>.<lambda>  r  rA   c                 ,      |                     S rm   r;   )r=   ru  r   s    r?   r   z_futrig.<locals>.<lambda>  s    TT##a&&\\ rA   c                 B    t          t           |                     S rm   r  r   )r=   r~  r  s    r?   r   z_futrig.<locals>.<lambda>  s    gj##a&&%88 rA   c                 B    t          t           |                     S rm   r  )r=   r{  r  s    r?   r   z_futrig.<locals>.<lambda>  s     gDDGGU, , rA   c                 B    t          t           |                     S rm   r  )r=   rz  r  s    r?   r   z_futrig.<locals>.<lambda>  s    wz33q66599 rA   c                 B    t          t           |                     S rm   r  )r=   r|  r  s    r?   r   z_futrig.<locals>.<lambda>  s     wDDGGU, , rA   c                 B    t          t           |                     S rm   r  )r=   r  r  s    r?   r   z_futrig.<locals>.<lambda>  s     WQ( ( rA   c                 B    t          t           |                     S rm   )r  r	   )r=   r  r  s    r?   r   z_futrig.<locals>.<lambda>  s     W$$q''5* * rA   )	objective)r   rt  ru  rv  r   rw  rx  rW  ry  rz  r{  r|  r}  r~  r  r  r  r  r  r  r   r(   r   r  r1   r2   )r>   rt  rv  rw  rW  ry  r}  r  r  r  r  rU   Lopstreerx  r  r{  r|  ru  r  r   r~  rz  r  s                 @@@@@@@@@@r?   ro  ro    s                                            
 55&'' x ##$9::qqLLLLD22E++++	88889AAAAeS++++	88889	3	)))))*88888, , , , ,	-
 :9999, , , , ,	- 		4	 ( ( ( ( ( 	)S$	 * * * * * 	+C#	
$DJ 	%tt$$$Q''AAIHrA   c                     t          | t                    rt          | j                  S t          | t                    sdS t          d | j        D                       S )zD_eapply helper to tell whether ``e`` and all its args
    are Exprs.Fc              3   4   K   | ]}t          |          V  d S rm   )_is_Expr)r<   rR  s     r?   ro   z_is_Expr.<locals>.<genexpr>  s(      ++qx{{++++++rA   )rB   r   r  r   r   allr_   )r>   s    r?   r  r    s\     !Z    a u++AF++++++rA   c                      t          |t                    s|S t          |          s|j        s  |          S  |j         fd|j        D              S )zdApply ``func`` to ``e`` if all args are Exprs else only
    apply it to those args that *are* Exprs.c                 N    g | ]!} |          rt          |          n|"S rm   r  )r<   eicondr^   s     r?   r@   z_eapply.<locals>.<listcomp>  sH        #ldd2hhlbR  rA   )rB   r   r  r_   r^   )r^   r>   r  s   ` `r?   r  r    s     a {{ !& tAww16     &    rA   )Frm   )\collectionsr   	functoolsr   
sympy.corer   r   r   r   r	   r
   r   r   sympy.core.cacher   sympy.core.functionr   r   r   r   r   r   r   sympy.core.numbersr   r   sympy.core.intfuncr   sympy.core.sortingr   sympy.core.symbolr   r   r   sympy.external.gmpyr   sympy.functionsr   r   r   r    r!   r"   r#   r$   r%   r&   %sympy.functions.elementary.hyperbolicr'   (sympy.functions.elementary.trigonometricr(   sympy.polysr)   r*   r+   r,   sympy.polys.domainsr-   sympy.polys.polyerrorsr.   sympy.polys.polytoolsr/   sympy.simplify.cse_mainr0   sympy.strategies.corer1   sympy.strategies.treer2   sympy.utilities.iterablesr3   sympy.utilities.miscr4   r   r   r   r   r  r   r)  r,  r1  rA  rP  rO  rQ  rS  r  rU  r   ro  r  r  r;   rA   r?   <module>r     s/   # # # # # #      - - - - - - - - - - - - - - - - - - - - $ $ $ $ $ $G G G G G G G G G G G G G G G G G G ) ) ) ) ) ) ) ) # # # # # # % % % % % % 2 2 2 2 2 2 2 2 2 2 * * * * * * K K K K K K K K K K K K K K K K K K K K K K ! ! ! ! ! ! D D D D D D J J J J J J E E E E E E E E E E E E " " " " " " 5 5 5 5 5 5 * * * * * * ' ' ' ' ' ' * * * * * * ( ( ( ( ( ( . . . . . . & & & & & &"$E!&KF KF KF KF\  !3	4  Di i i iX[ [ [~ !% E E E E EPA A A Q Q Qh) ) )X {) ) )X    	~ ~ ~ 	~D  ( ( ( ( (V< < <~, , ,	 	 	 	 	 	rA   