� ��g���,�ddlmZddlmZddlmZmZmZmZm Z m Z m Z m Z ddl mZddlmZmZmZmZmZmZmZddlmZmZddlmZddlmZdd lmZm Z m!Z!dd l"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-dd l$m.Z.dd l/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGgdddfd�ZHe2e0fZId�ZJd0d�ZKd�ZLdd�d �ZMd!�ZNd"aOd#�ZPd$�ZQd%�ZRd&�ZSd'�ZTd(�ZUd0d)�ZVed0d*���ZWdd+�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�����fd�}td���|�tj���}�tjfg}t |�����\}� t |�g��\\}} } n#t$r|cYSwxYwtd| j ��|| j |��\} ��td| ��td�dt�����td �dt������s|St| ��t� ���td t���dt�����d d lm���r�| jt#����| j ����r�t'|��z���j��}g} |���D�]E\} }t#t |�g��dj ���d}|r�d}| D]�}t'|��}��|j ��s]|jt#|j �������s.d}��|���j ����|���fd��D��}�fd��jD��}| �t9d�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}ggg}}}|D]��t�ttf��r�}�!t�t��r|�����Lt ���r�|��d�dd�f��|�t�fd��dd�D���dt�dd����gz��dj ����|������||||fS)z-Split hints into (n, funcs, iterables, gens).�rNc�2��g|]}�d|����S�r�)�.0�x�es ��g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/simplify/trigsimp.py� <listcomp>z:trigsimp_groebner.<locals>.parse_hints.<locals>.<listcomp>�s%���,�,�,��T�Q�q�T�!�W�W�,�,�,�) � isinstancerrr�appendr3�extendr,r �gens)�hints�n�funcs� iterablesrEr>s @r?� parse_hintsz&trigsimp_groebner.<locals>.parse_hints�s6��� ��!#�R��$�y��� � �A��!�j�'�2�3�3� �����A�}�-�-� �� � �Q������!��� �� � �!�A�$��!�"�"���/�/�/�� � �3�,�,�,�,�a����e�,�,�,���!��S�!�A�B�B�%�[�0A�0A�/B�B�D�D�DE�G�GK�M�M�M�M�� � �A������%��D�(�(rAc ���g}td��}|D�]=\}}tttt|��dzt|��dzzdz gtt t t |��dzt |��dzz dz gfD]�\}}}} |dkr|||fvr|j| ���$||kr;|j|||z��|||z��z|||z��z ���e|||fvrU|||z���d���� ||��} |j|||z��| z ������?tt|����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�r8T��trig) rrrr#r r"r!rCr�subs�list�set) r=�termsrrL�fn�coeff�c�s�t�rel�cns r?� build_idealz&trigsimp_groebner.<locals>.build_ideal�s��� �� �#�J�J��� /� /�I�B���#�s�C��F�F�A�I��A���� �$9�A�$=�>��4��t�A�w�w��z�D��G�G�Q�J�'>��'B�C�!E� /� /� ��1�a���A�:�:�"��A��,�,��A�H�S�M�M�M�M��1�W�W��A�H�Q�Q�u�Q�w�Z�Z���%��'� � �2�Q�Q�u�Q�w�Z�Z�?�@�@�@�@��A�q�6�\�\���E�!�G���+�+��+�6�6�;�;�A�q�A�A�B��A�H�R�R��a��[�[�2�-�.�.�.�� /��C��F�F�|�|�rAc �� �������"|��\}}}}td|||f��t|��}|�|��tt|����}tt|����}tt|����}tt t ttth��fd�|D��}�fd�|D��}g}i} |D]3\\} } } | � | g��� | | f���4g} | � ��D�]g\}}d�|D��}d�|D��}tt|����fd�t||��D��}t||z���t tt gtttgfD]N\}}}t!�fd�|||fD����r*��|����|���O�D]/} t%d|dz��D]}|� | |f����0g}|D]�\} }| t kr8|� t|f��|� t |f��| tt fvr%t �vr|� t |f��| tkr8|� t|f��|� t|f��| ttfvr%t�vr|� t|f����|�|���t'|�z�� �|��}| �|��|��fd �|D������i|D�] \} }| t kr&|�t|ft |fg���7| tkr&|�t|ft|fg���ht)d t+|��zt,� ��}| t/|����d � ���tt||������}| � | t/|���|z ���� �!|vrE| � �!dzdz��|��!��|� �!��| ||fS)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� |jd���|jf��2Sr:)�func�args� as_coeff_mul�r<�g�allfuncss �r?r@z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>sH���,�,�,�A���(�*�*��f�Q�i�,�,�.�.���7�*�*�*rAc�&��g|] }|j�v� |��Sr;)r^ras �r?r@z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>s%���>�>�>�!�q�v�X�'=�'=�A�'=�'=�'=rAc��g|] }|d�� S)r8r;�r<r=s r?r@z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>0���%�%�%�A�1�Q�4�%�%�%rAc��g|] }|d�� Sr:r;rfs r?r@z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>1rgrAc�$��g|] \}}||�z f�� Sr;r;)r<rT�v�gcds �r?r@z;trigsimp_groebner.<locals>.analyse_gens.<locals>.<listcomp>3s%���>�>�>�W�b�!�b�!�C�%�[�>�>�>rAc3� �K�|]}|�vV�� dS�Nr;)r<r=�fss �r?� <genexpr>z:trigsimp_groebner.<locals>.analyse_gens.<locals>.<genexpr>6s'�����2�2�1�q�B�w�2�2�2�2�2�2rAr8c�2��h|]\}}||�z����Sr;r;)r<rTrjr=s �r?� <setcomp>z:trigsimp_groebner.<locals>.analyse_gens.<locals>.<setcomp>Ls)���7�7�7���A�B�B�q��s�G�G�7�7�7rAzd:%i��clsTrNrM)r4rQrDrRrrr#r"r r!� setdefaultrC�itemsrr�zip�any�add�ranger r�lenrr rrP�remove)#rErFrGrHrI� extragens� trigterms�freegens�newgens�trigdictrU�varrT�res�key�val�fnsrSrVrWrX�k�extrarj�rr_�dummys�exprrcrnrkr=r[�myIrJs# @@@@���r?� analyse_gensz'trigsimp_groebner.<locals>.analyse_gens�s�������*5��U�);�);�&��5�)�Y� �A��i��+� -� -� -��D�z�z�� � � �I�����S��Z�Z� � ����Y���(�(� ��C��I�I������c�4��t�4��,�,�,�,��,�,�,� �?�>�>�>�t�>�>�>������ )� =� =� �L�U�C�"� � � ��R� (� (� /� /��� � <� <� <� <��� ���(�(�- 9�- 9�H�C��"&�%��%�%�%�C�%�%��%�%�%�C���s�#�#�C�>�>�>�>��C�� � �>�>�>�E��U�S�[�!�!�B� �#�s�O�d�D�$�-?�@� � ���1�a��2�2�2�2��A�q� �2�2�2�2�2���F�F�1�I�I�I��F�F�1�I�I�I��� *� *���q�!�a�%���*�*�A��L�L�"�a��)�)�)�)�*��E�� ,� ,���A���9�9��L�L�#�q��*�*�*��L�L�#�q��*�*�*��#�s��#�#��r� � ��L�L�#�q��*�*�*���:�:��L�L�$���+�+�+��L�L�$���+�+�+��$���%�%�$�"�*�*��L�L�$���+�+�+�� �L�L�� � � ��C��I� �A�� �A�u�%�%�A� �J�J�q�M�M�M� �N�N�7�7�7�7��7�7�7� 8� 8� 8� 8�"� 2� 2�H�B���S�y�y�� � �3��+��T�{�!;�<�<�<�<��t���� � �4��,��t� �!=�>�>�>�>� ��#�d�)�)�!3��?�?�?���r�3��<�(�(�/�/�T�/�:�:�?�?��S��QU�EV�EV�@W�@W�X�X��� � �2�2�c�4�j�>�>�D�0�1�1�1�1� �$�;�;� �J�J�s�A�v��z� "� "� "� �O�O�C� � � � �N�N�3� � � ��H�g�%�%rArz initial gens:zideal:z new gens:z -- lenz free gens:)�orderrE�domainzgroebner basis:r)�ratsimpmodprime)rEr8TFc���g|]}|�v�|�� Sr;r;)r<r=�ourgenss �r?r@z%trigsimp_groebner.<locals>.<listcomp>�s���8�8�8�a�1��<�<��<�<�<rAc�|��g|]8}|j��|j����$|�����9Sr;)� has_only_gens� intersectionrE�as_expr)r<rbr�s �r?r@z%trigsimp_groebner.<locals>.<listcomp>�sU���D�D�D�A�#�A�O�W�%9�%9�!�&�%A�%A�B�D�A�I�I�K�K�D�D�DrAc��g|] \}}||z�� Sr;r;)r<�a�bs r?r@z%trigsimp_groebner.<locals>.<listcomp>�s ��C�C�C�d�a��Q��T�C�C�CrA)r�rE�quickr�� polynomial)rrPr� ImaginaryUnitr+�as_numer_denomr,r.r4rErzr/r-rQ�sympy.simplify.ratsimpr�r�rRr�r)�ejectrS� issuperset� difference�update�exclude�polysrCr rvr )r�rFr�r�r�r�rP�num�pnum�pdenom�opt�idealr��monomrU�changed�p�realgens�ourG�Gr[�denomr~rEr�r�rJr�s `` @@@@@@@@@r?�trigsimp_groebnerr�s��������������f)�)�)�(���0e&�e&�e&�e&�e&�e&�e&�N ��*�*�C� �9�9�Q�_�c� *� *�D� �!�/� "� #�D�����,�,�.�.�J�C���5�s�E�l�C�C����v���� ����� � � ����� �/�3�8�$�$�$�(�L���5�9�9��E�8�T� �(�E���� �+�t�Y��D� � �2�2�2� �,��)�S��Y�Y�7�7�7� ��� ���e�$�r�:�:�:�A� � �T�!�W�W�i��Q���8�8�8� 7�6�6�6�6�6��,F�(�F�(�#�d�)�)�*@�*@���*M�*M�N�,F�1�d�3�T�(�]�+�+�+�1�4�8�����I�I�K�K� J� J�L�E�5��1�5�%�.�A�A�!�D�I�J�J�G��G�� 9����9�9�A��Q���A�"�-�-�a�f�5�5�9�*�1�?�C���K�K�,B�,B�7�,K�,K�L�9�"&�����q�y�y�{�{�'7�8�8�8��� 9�9�8�8�8�4�8�8�8�H�D�D�D�D���D�D�D�D� �J�J�s�C�C�c�(�E�.B�.B�C�C�C�D�&��u�U�{�D��,4�E�"�2<�>�>�>�>B�d�4�j�j�I� J� J� J� J��C�y���� �$�q�'�'��X�d�]���z�;�;�;�;?�4��:�:� Fs�<B� B#�"B#c�8���d����fd��t|���S)Nc�^� |jd|jdkS#t$rYdSwxYw)NrF)r_� IndexError)r=rLs r?� check_argsz%_trigsimp_inverse.<locals>.check_args�s@�� ��6�!�9���q� �)� )��� � � ��5�5� ���s �� ,�,c���t|dd��}|�at|jd|����r>t|��d��t��r|jdjdSt|t��r�|j\}}t |��r�t | |���� St |��r't j�t || ����z S�||��r~t|t��r"t|t��r |jdSt|t��r2t|t��rt jdz |jdz S|S)N�inverserr8rM) �getattrrBr_r(r&rr�Pirr)�rvrbrLr=r��fs ��r?r�z_trigsimp_inverse.<locals>.f�s^��� �B� �4� (� (�� �M�j�����Q�Q�S�S�9�9�M��3�1�1�3�3�q�6�6�#8�9�9� ��7�1�:�?�1�%� %� �b�%� � � 0��7�D�A�q��A��� .���%���A�,�,���'�'��a��� .��t�a�a��a�!�� � �o�o�-�-��z�!�Q��� 0��a��%�%�%�*�Q��*<�*<�%��6�!�9�$��a��%�%�0�*�Q��*<�*<�0��4�!�8�a�f�Q�i�/�/�� rA)r )r�r�r�s @@r?�_trigsimp_inverser��sC������� ������. �R�� � �rAc ���� �ddlm�t|��}t|dd��}|�|di���S��dd��}|sC��dd����dd����d d ��}nd}d �� ��fd �d �� �fd�� fd��fd�d�|}||��}|rt |��}|S)a6Returns 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�����fd���|��}t|t��s|St|fi���S)Nc���|jr|S�fd�|jD��}|js|jr�fd�|D��}|j|�S)Nc�&��g|] }�|����Sr;r;�r<r=�traverses �r?r@zDtrigsimp.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>#�!���0�0�0�A�H�H�Q�K�K�0�0�0rAc�*��g|]}t|fi�����Sr;�r��r<r=�optss �r?r@zDtrigsimp.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>%�*���C�C�C��)�!�4�4�t�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�0�D��}� D��� D�C�C�C�C�d�C�C�C���1�6�4�=� rA)rBrr�)�exr��newr�s ` @r?� groebnersimpztrigsimp.<locals>.groebnersimps^���� !� !� !� !� !� !��h�r�l�l���#�t�$�$� ��J� ��-�-��-�-�-rAc����|fi���Srmr;)r=r�r�s ��r?�<lambda>ztrigsimp.<locals>.<lambda>-s�����A������rAc� �t|��Srm)�futrig�r=s r?r�ztrigsimp.<locals>.<lambda>.s ��v�a�y�y�rAc����|fi���Srmr;)r=r�r�s ��r?r�ztrigsimp.<locals>.<lambda>/s���|�|�A�6�6��6�6�rAc�H��t�|ddtg�����S�NTrM)r�rF)r�r#)r=r�s �r?r�ztrigsimp.<locals>.<lambda>0s4���v�l�l�1�*.�q�#�h�'@�'@�'@� A� A�rAc���t|fi���Srm)� trigsimp_old)r=r�s �r?r�ztrigsimp.<locals>.<lambda>2s����a�0�0�4�0�0�rA)r�r�r/�combinedr�r;)�sympy.simplify.fur�rr��popr�) r�r�r�r�r�r�� trigsimpfunc�expr_simplifiedr�r�s ` @@r?�trigsimpr��sK�����~%�$�$�$�$�$� �4�=�=�D��T�#3�T�:�:�N��!��~�%�%��%�%�%� �(�(�5�%� � �C� �� �������� ����d�#�#�#����(�J�/�/����� .� .� .�'�&�&�&�&�(�(�6�6�6�6�6�A�A�A�A�0�0�0�0� ����L�#�l�4�(�(�O��=�+�O�<�<�� �rAc���ddlm}m}d�}t||��}�fd��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}|jt�r-|�|�t����|�|�t ����t |dti�S)Nr�)�has�_trigsrC�rewriterr�minr)r>�choicess r?�exp_trigzexptrigsimp.<locals>.exp_trigMsf���#�� �1�5�&�>� +� �N�N�1�9�9�S�>�>� *� *� *����q�y�y��~�~�&�&�&��G�+��+�+�+rAc��� � �|js|S|���\}}t|��dkr� t|���t|�zS|���}|���� t jf� fd� � |t j}|D�]�}|j �r�t|j ��dk�r||j d}� |j d|z ��\}}|s�P||} � |xx| zcc<|| | zdz krp� t jxx|zcc<d}|dkr'� d|zt|dz ��zxx| z cc<��� d|zt|dz ��zxx| z cc<�� d|t j|zzz | krh� d|t j|zzz =|dkr&� | t|dz ��z xx| z cc<��G� | t|dz ��zxx| z cc<��m� d|t j|zzzxx| z cc<� |xx| z cc<���t� fd�� D���S)Nr8c���|tjur|tjfSt|t��s|jr|jtjkr ||jfS|tjur�| tj ���SdS)N)�sign)NN)r�Exp1�OnerBrr��base)r�r��signlogs �r?r�z'exptrigsimp.<locals>.f.<locals>.signlogcsz����q�v�~�~��Q�U�{�"��D�#�&�&� "�4�;� "�4�9���;N�;N��T�X�~�%�������w��u�A�E�6�2�2�2�2�!�zrArMr�����c�&��g|] }|�|z��Sr;r;)r<r��newds �r?r@z*exptrigsimp.<locals>.f.<locals>.<listcomp>�s!���.�.�.�A�Q��Q��Z�.�.�.rA)�is_Mul�args_cncrzr �as_powers_dict�copyrr�r��is_Addr_r r"r!) r��commutative_part�noncommutative_part�rvd�eer�rVr�r=�mr�r�r�s @@�r?r�zexptrigsimp.<locals>.fWs�������y� ��I�02� � � � �-��-� �#� $� $�q� (� (��1�S�*�+�,�,�S�2E�-F�F� F����!�!���x�x�z�z�� �u� "� "� "� "� "� "����[��� !� !�A��x� !�C���K�K�1�,�,��F�1�I��!�'�!�&��)�A�+�.�.���a������F���Q����1� �����!��A��a��<�<����L�L�L�B�&�L�L�L��B��q�y�y��Q�q�S��a��c���]�+�+�+�q�0�+�+�+�+��R��T�$�q��s�)�)�^�,�,�,��1�,�,�,�,��!�d�1�6�1�9�n�,�-�!��3�3��Q��a�f�a�i��/�0��q�y�y��a�R��Q�q�S� � �\�*�*�*�a�/�*�*�*�*��a�R��Q�q�S� � �\�*�*�*�a�/�*�*�*�*���T�!�&�!�)�^�+�,�,�,��1�,�,�,���G�G�G�q�L�G�G�G���.�.�.�.��.�.�.�/�/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�30�30�30�30�30�h���#�#�G��{�{�%�&�&���}�W�%�%���1��!�D�D��G�G�*�*���{�{�(�)�)� ��$�w�-�-�� �K�K��N�N��4�8�8�A�;�;���� �KrAT)�firstc �d���|}|�r|jt�s|St��jd�|jt�D���}t |��dkr�ddlm}||��}|jr||d���p|}t|t��rLd}|� ��D]2}|}t|��}d�d<t|fi���} | |kr|} || z}�3|}nF|jr?|D]:} |�| ��\} } | rd�d<| t| fi���z}|jsn�;|}��d d��} ��d d��}��d d ��}d ��d���fd��fd�d�|}| rgt#|��\}}||d|��}t%|��D]0}|�|d|d��}|||��}�1|}n |||��}��dd��r%t+|��}||krt-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�� Sr;)� free_symbols)r<rXs r?r@z trigsimp_old.<locals>.<listcomp>�s�� M� M� M�A��� M� M� MrAr8r)� separatevarsT)�dictFrr�r�r�r�c�F�����fd��|r �|��}t|fi���S)Nc���|jr|S�fd�|jD��}|js|jr�fd�|D��}|j|�S)Nc�&��g|] }�|����Sr;r;r�s �r?r@zHtrigsimp_old.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>r�rAc�*��g|]}t|fi�����Sr;r�r�s �r?r@zHtrigsimp_old.<locals>.groebnersimp.<locals>.traverse.<locals>.<listcomp>r�rAr�r�s ��r?r�z4trigsimp_old.<locals>.groebnersimp.<locals>.traverse�r�rAr�)r�r�r�r�s `@r?r�z"trigsimp_old.<locals>.groebnersimp�sO���� !� !� !� !� !� !� � ���"���B� ��,�,�t�,�,�,rAc�"�t||��Srm�� _trigsimp)r=�ds r?r�ztrigsimp_old.<locals>.<lambda> s��)�A�q�/�/�rAc����||fi���Srmr;)r=rr�r�s ��r?r�ztrigsimp_old.<locals>.<lambda> s���,�,�q�!�"<�"<�t�"<�"<�rAc �L��t�||ddtg���|��Sr�)rr#)r=rr�s �r?r�ztrigsimp_old.<locals>.<lambda> s7���)�L�L��'(�T�!�S��-K�-K�-K�#$�#&�#&�rA)r�r/r��comparez futrig:)r�r�rR�union�atomsrz�sympy.simplify.simplifyr r�rBr �valuesrr�r�as_independentr�r0�reversedrP�getr��print)r�rr�r��trigsymsr rrj�was�vnewrWr�r>r�r�r�r��wrb�sub�resultr�r�s ` @r?r�r��s�����t �C� � ��t�x�� � ��K��3�5�5�;� M� M����V�9L� M� M� M�N�� �x�=�=�1� � � <� <� <� <� <� <�� �T�"�"�A��x� 4� �L���.�.�.�3�!���!�T�"�"� ��������!�!�A��C�"�1� � �A�$)�D��M�#�A�.�.��.�.�D��q�y�y�"���D�L�D�D�����8��%�&�&��#�2�2�1�5�5���1��&�,1�D��M�#$�x��':�':�T�':�':�#:�D�#'�;�&� %����C�����e�,�,�I� �8�8�F�E� "� "�D� �X�X�h� � +� +�F� -� -� -�2�1�<�<�<�<�<�&�&�&�&��� � �L�� *��4�y�y���1� �L��1��t� $� $���A�;�;� &� &�C����s�1�v�s�1�v�&�&�A�� �Q��%�%�A�A������d�D�)�)�� �x�x� �5�!�!�"� �3�K�K�� ��;�;� �+�q� !� !� !� �MrAc���|j|jkog|�t��r|�t��p3|�t��o|�t��S)z�Helper 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�� �6�Q�V� � A� ���#�$�$�E����/D�)E�)E� @� ��� �!�!�?�a�e�e�,>�&?�&?�ArANc�L�tdt���\}}}tdd���}|t|��|zzt|��|zz |t |��|zzt|��t|��f|t |��|zzt|��|zz|t|��|zzt|��t|��f|t |��|zzt|��|zz|t|��|zzt|��t|��f|t |��|zzt|��|zz |t|��|zz t|��t|��f|t |��|zzt|��|zz |t|��|zz t|��t|��f|t |��|zzt |��|zz|t|��t|��f|t|��dz|zzt|��dz |zz|t|��dz |zzt|��dzt|��dz f|t|��dz|zzt|��dz |zz|t|��dz |zzt|��dzt|��dz f|t |��|zzt|��|zz |t|��|zztj tj f|t|��|zzt|��|zz|t |��|zztj tj f|t|��|zzt |��|zz|t|��|zztj tj f|t|��|zzt |��|zz |t|��|zz tj tj f|t|��|zzt|��|zz |t |��|zz tj tj f|t|��|zzt|��|zz|tj tj f|t|��t|��zzdt|��t|��zzz t||z��|ztj tj ff}|t|��zt|��z|t|��zt|��zz|zt||z��|z|zf|t|��zt|��z|t|��zt|��zz |zt||z��|z|zf|t|��zt|��z|t|��zt|��zz |zt||z ��|z|zf|t|��zt|��z|t|��zt|��zz|zt||z ��|z|zf|t |��zt|��z|t |��zt|��zz|zt ||z��|z|zf|t|��zt|��z|t |��zt |��zz|zt||z��|z|zff}|t|��dzz||t|��dzzz f|t |��dzz|dt|��z dzz|z f|t |��dzz|dt|��z dzz|z f|t||z��z|t|��t|��zt|��t|��zzzf|t||z��z|t|��t|��zt|��t|��zz zf|t ||z��z|t |��t |��zdt |��t |��zz z zf|t |��dzz|t|��dzz|z f|t|��dzz||dt|��z dzzz f|t|��dzz||dt |��z dzzzf|t ||z��z|t |��t|��zt |��t|��zzzf|t||z��z|t|��t|��zt |��t |��zzzf|t||z��z|t|��t|��zdt|��t|��zzz zff }||t|��dzzz |z|t|��dzz|ztf||dt|��z dzzz |z| t |��dzz|ztf||dt|��z dzzz |z| t |��dzz|ztf||t|��dzzz |z| t |��dzz|ztf||dt|��z dzzz |z|t|��dzz|ztf||dt |��z dzzz|z|t|��dzz|zt f||z||zt|��dzzz |z||zt|��dzz|ztf||z||zdt|��z dzzz |z| |zt |��dzz|ztf||z||zdt|��z dzzz |z| |zt |��dzz|ztf||z||zt|��dzzz |z| |zt |��dzz|ztf||z||zdt|��z dzzz |z||zt|��dzz|ztf||z||zdt |��z dzzz|z||zt|��dzz|zt ff }||||||||fa tS)Nza b crrrF)� commutativer8rM) rrrrr#r$r"r r!rr�r%�_trigpat)r�r�rVr�matchers_division� matchers_add�matchers_identity� artifactss r?� _trigpatsr0-s� ���g�4�(�(�(�G�A�q�!� �S�e�$�$�$�A� �3�q�6�6�1�9��S��V�V�Q�Y� ��#�a�&�&�!�)� �S��V�V�S��V�V�<� �3�q�6�6�1�9��S��V�V�Q�Y� ��#�a�&�&�!�)� �S��V�V�S��V�V�<� �3�q�6�6�1�9��S��V�V�Q�Y� ��#�a�&�&�!�)� �S��V�V�S��V�V�<� �3�q�6�6�1�9��S��V�V�Q�Y� ��#�a�&�&�!�)� �S��V�V�S��V�V�<� �3�q�6�6�1�9��S��V�V�Q�Y� ��#�a�&�&�!�)� �S��V�V�S��V�V�<� �3�q�6�6�1�9��S��V�V�Q�Y� ��3�q�6�6�3�q�6�6�2� �C��F�F�Q�J��?� �C��F�F�Q�J��?� *� ��A���� �z�A�o� �s�1�v�v��z�3�q�6�6�A�:� 7� �C��F�F�Q�J��?� �C��F�F�Q�J��?� *� ��A���� �z�A�o� �s�1�v�v��z�3�q�6�6�A�:� 7� �4��7�7�A�:��d�1�g�g�q�j� �!�D��G�G�Q�J�,���q�u�=� �4��7�7�A�:��d�1�g�g�q�j� �!�D��G�G�Q�J�,���q�u�=� �4��7�7�A�:��d�1�g�g�q�j� �!�D��G�G�Q�J�,���q�u�=� �4��7�7�A�:��d�1�g�g�q�j� �!�D��G�G�Q�J�,���q�u�=� �4��7�7�A�:��d�1�g�g�q�j� �!�D��G�G�Q�J�,���q�u�=� �4��7�7�A�:��d�1�g�g�q�j� �!�Q�U�A�E�2� �D��G�G�d�1�g�g� � ��D��G�G�D��G�G�O� 3� 4� ��Q��K�K��M�1�5�!�%� )�'��0 �3�q�6�6��#�a�&�&��1�S��V�V�8�C��F�F�?� *�Q� .��A��E� � �1� �q�0@�A� �3�q�6�6��#�a�&�&��1�S��V�V�8�C��F�F�?� *�Q� .��A��E� � �1� �q�0@�A� �3�q�6�6��#�a�&�&��1�S��V�V�8�C��F�F�?� *�Q� .��A��E� � �1� �q�0@�A� �3�q�6�6��#�a�&�&��1�S��V�V�8�C��F�F�?� *�Q� .��A��E� � �1� �q�0@�A� �4��7�7��4��7�7� �Q�t�A�w�w�Y�t�A�w�w�.� .�� 2�D��Q��K�K��M�A�4E�F� �4��7�7��4��7�7� �Q�t�A�w�w�Y�t�A�w�w�.� .�� 2�D��Q��K�K��M�A�4E�F� �L� �3�q�6�6�1�9��a�!�C��F�F�A�I�+�o�&� �3�q�6�6�1�9��a��3�q�6�6��A� �o��)�*� �3�q�6�6�1�9��a��3�q�6�6��A� �o��)�*� �3�q�1�u�:�:��q�#�a�&�&��Q���-�#�a�&�&��Q���-�7�8�9� �3�q�1�u�:�:��q�#�a�&�&��Q���-�#�a�&�&��Q���-�7�8�9� �3�q�1�u�:�:��q�3�q�6�6�C��F�F�?�Q��Q����A����->�?�@�A� �4��7�7�A�:��q��a���!��|�a�'�(� �4��7�7�A�:��q�1�a��Q���i�!�^�+�+�,� �4��7�7�A�:��q�1�a��Q���i�!�^�+�+�,� �4��A��;�;���4��7�7�4��7�7�?�T�!�W�W�T�!�W�W�_�<�=�>� �4��A��;�;���4��7�7�4��7�7�?�T�!�W�W�T�!�W�W�_�<�=�>� �4��A��;�;���D��G�G�d�1�g�g�-��D��G�G�D��G�G�O�0C�D�E�F���( �Q�s�1�v�v�q�y�[��1� �a��A���� �k�A�o�s�3� �Q��#�a�&�&��1�}�_� �q� �1�"�S��V�V�Q�Y�,��"2�C�8� �Q��#�a�&�&��1�}�_� �q� �1�"�S��V�V�Q�Y�,��"2�C�8� �Q�t�A�w�w��z�\� �A� ��r�$�q�'�'�1�*�}�q�0�$�7� �Q��$�q�'�'� �A�~� � �� !�1�T�!�W�W�a�Z�<�!�#3�T�:� �Q��$�q�'�'� �A�~� � �� !�1�T�!�W�W�a�Z�<�!�#3�T�:� �1��q��s�3�q�6�6�1�9�}� �q� �!�A�#�c�!�f�f�a�i�-�!�"3�S�9� �1��q��s�A�c�!�f�f�H�q�=� � �1� $�q�b��d�3�q�6�6�1�9�n�q�&8�#�>� �1��q��s�A�c�!�f�f�H�q�=� � �1� $�q�b��d�3�q�6�6�1�9�n�q�&8�#�>� �1��q��s�4��7�7�A�:�~� �� !�A�2�a�4��Q���� �?�Q�#6��=� �1��q��s�A�d�1�g�g�I��>�!� !�A� %�q��s�4��7�7�A�:�~��'9�4�@� �1��q��s�A�d�1�g�g�I��>�!� !�A� %�q��s�4��7�7�A�:�~��'9�4�@�!�I�&�1�a��-�|��9�&�H� �OrAc���tt��}tt��}g}|jD]�} | js | j||fvrs| ���\} } | js| jrN| j|kr|| jdxx| z cc<�`| j|kr|| jdxx| z cc<��|�| ����t|��t|��z} d} | r�| � ��}|� |��}|� |��}|||��kr-|�||��||��z��d} n |||<|||<| ��| s|S|r:|� ��\}} |�||��| z��|�:|r:|� ��\}} |�||��| z��|�:t|�S)z�Helper 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. rFT) r�intr_r�r^� as_base_exp� is_positive� is_integerrCrRr��popitemr )r�r�rb�rexp�h�rexph�fargs�gargsr_r=r�r>�common�hitr��fe�ges r?�_replace_mul_fpowxgpowr@�s+�� �� � �E� �� � �E� �D� �Y� � �� �8� �q�v�!�Q��'�'��=�=�?�?�D�A�q��}� �� � ��6�Q�;�;��!�&��)�$�$�$��)�$�$�$���V�q�[�[��!�&��)�$�$�$��)�$�$�$�� � � �A����� ��Z�Z�#�e�*�*� $�F� �C� � ��j�j�l�l�� �Y�Y�s�^�^�� �Y�Y�s�^�^�� ���b���>�>� �K�K���#�����b� � �)� *� *� *��C�C��E�#�J��E�#�J� � � ��� � ���������Q� � � �A�A�c�F�F�A�I���� �� ���������Q� � � �A�A�c�F�F�A�I���� �� ��:�rAc��|Srmr;r�s r?r�r��s���rAc��| Srmr;r�s r?r�r��s��1�"�rAc��tjSrm)rr�r�s r?r�r��s����rAc���|dkr/t|ttttt ��}�nD|dkr/t|ttt tt ��}�n|dkr/t|t tt tt ��}�n�|dkr/t|ttttt��}�n�|dkr/t|t tttt��}�np|dkr/t|t tt tt ��}�n;|dkr/t|ttttt ��}�n|dkr.t|ttt tt ��}n�|d kr.t|ttt tt ��}n�|d kr.t|ttttt��}nj|d kr.t|ttttt��}n6|d kr.t|ttt tt ��}nd S|S)zhelper for __trigsimprr8rM����� � � � � N) r@rr�_midnr#�_idnr$�_oner"r r!r%)r��is r?�_match_div_rewriterR�s����A�v�v�%�d�C�� �3������ �a���%�d�C�� �#�t����� �a���%�d�C�� �#�t����� �a���%�d�C�� �3������ �a���%�d�C�� �3������ �a���%�d�C�� �$������ �a���%�d�D�$� �4������ �a���%�d�D�$� �$������ �b���%�d�D�$� �$������ �b���%�d�D�$� �4�� � ��� �b���%�d�D�$� �4�� � ��� �b���%�d�D�$� �$�������t� �KrAc�D�|jt�rt||��S|Srm)r�r�� __trigsimp)r�r�s r?rr�s*���t�x���&��$��%�%�%� �KrAc� �����ddlm}t�t��t\��}}}}}}|j�rm|jsP|���\} } ttj | �����tj | ��z}�nt|��D�]\} \} } }}t|| ��s�t|| ��}|� ||kr|}nό9|� | ����r���|d��r��|js:|����}|js��|����}|js��t%��fd����t(t*��D����r��| ����}n��|j�r�g}|jD]�}|js@|���\} } tj | ��} tj | ��}n t0j} t|���}|D]3\} }|� | �����|����}n�4|�|| z����||jkr-t7|�}t9|t;|��t<���}|jr�|D]�\} }t|| ��s�||��}|�t*��rx|� | �����I��vrE��vrAt%���fd��|�t(t*��D����r��|����}n��|D�]$\} }}t|| ��s�tAd|g���}| ��|��} |��|��}|� | ��}d}|r�||kr�|}||dks+|| ||jvs||||zdkrnu||vr||||z||zdkrnR|�|��}|� | ��}|�!|t0j"��|r||k����&n2|js|j#s �r"|jr|j$�fd �|jD���} |jtJ�stL�|�tN��}|�(tN�� ��}||krtL�tS|��}||kr%t9|tS|��gt<���}|�tN��|z s|}n#tL$rYnwxYw|S) zrecursive helper for trigsimpr)�TR10iNc3�F�K�|]}|jd��kV��dS�rN�r_)r<r$r�r�s ��r?roz__trigsimp.<locals>.<genexpr> sJ�����H�H�1�1�6�!�9��A��.�H�H�H�H�H�HrA)r�c3�R�K�|]!}|jd����fvV��"dSrXrY)r<r$r�r�r�s ���r?roz__trigsimp.<locals>.<genexpr>1s\�����IH�IH�:;���q� �c�!�f�c�!�f�%5�5�IH�IH�IH�IH�IH�IHrAr�)r�c�0��g|]}t|�����Sr;r)r<r�r�s �r?r@z__trigsimp.<locals>.<listcomp>Rs#���A�A�A�!�9�Q��-�-�A�A�ArA)r�)*r�rVr+r0r��is_commutativer�rr � _from_args� enumerater(rR�matchrr5rPr4rwrr(r'rr_rr�rCr r�rrr�rrt�Zeror�r^r�� TypeErrorrr�r*)r�r�rVrVrr,r-r.r/�com�ncrQ�pattern�simp�ok1�ok2r�okr_�termr&r��a_trr"r>r��fnewr�r�r�s ` @@@r?rTrT�sP������(�'�'�'�'�'���� � � �#+�!�A�q�!�Q�!�<��y� �{�#��"�! ��m�m�o�o�G�C���S�^�C�0�0�$�7�7���r�8J�8J�J�D�D�09�:K�0L�0L� � �,��,�G�T�3���t�W�-�-���,�T�1�5�5���&��$���&���� ��j�j��)�)����3�7�7�1�a�=�=���q�6�,�%� �X�X�c�]�]��!�~�%�$� �X�X�c�]�]��!�~�%�$��H�H�H�H�H��A�� � �1�3E�9G�9G�H�H�H�H�H�!� ��9�9�S�>�>�D��E�� �{�>C����I� !� !�D��&� ��-�-�/�/���R��^�B�'�'���~�c�*�*����U���T�4�(�(�D�#4� � �����j�j��)�)���?�!�;�;�s�+�+�D��E�#� �K�K��R�� � � � � �4�9� � ���:�D��t�V�D�\�\�y�9�9�9�D� �;� �#/� � �����t�W�-�-����u�T�{�{���8�8�.�/�/� ��*�*�W�-�-�C��{�1��8�8��S���S�IH�IH�IH�IH�IH�IH�?B�1�v�|�|�1�3E�@G�@G�IH�IH�IH�FH�FH��!�!�;�;�s�+�+�D��E� �$-� (� (� �G�V�R��4��)�)� ���s�R�D�)�)�)�C��l�l�1�c�*�*�G��[�[��C�(�(�F�� � �7�#�#�A��C�� (��t� � ����S�6�Q�;�;��3���1�Q�4�9�,�,��#���1�� ��0B�0B����6�6�a��f�Q�q�T�k�A�a�D�0�A�5�5���{�{�1�~�~���J�J�w�'�'��� � �Q���'�'�'�� (��t� � �� (�. ��C�� �C�t�C�� �C��t�y�A�A�A�A�t�y�A�A�A�B�� ��t�x�� � ��O� �J�J�s�O�O���l�l�3�T�l�*�*�� �!�8�8��O��c�{�{�� �3�;�;��s�F�3�K�K�(�i�8�8�8�C�� � �#����"� ��D��� � � � � �� ���� �Ks�;B2U.�. U;�:U;)�hyperc ��ddlm}t|��}t|t��s|S|js|S|}t |t��}|rF|�t��r,||��\}}|t |t����}||kr4|j r-|jdj rt|� ���}|S)aReturn 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�rrBrr_r �_futrigr�r'r�� is_Rationalr � as_coeff_Mul)r>rl�kwargsr�r�r�s r?r�r�hs���(0�/�/�/�/�/��� � �A� �a�� � ���� �6���� �C��!�W���A� �%����)�*�*�%��}�Q�����1� �A�i��7�#�#� $� $���C�x�x�A�H�x�����!6�x� ����!�!� "�� �HrAc!�T�����������ddlm}m�m}m�m}m�m}m}m �m �m �m }m �m}m}m} m} m�m�|�t*��s|S|jr|�t*��\} }nd} �fd�} d��t0||��fd��t0�fd�g��fd�| �||| ��fd �| t0�fd �g||t0|gt0��fd �g��fd ���fd �g��fd���fd�g|t0�gt0��fd�g|��t0��fd�gfg} t3| | ���|��}| �| |z}|S)zHelper for futrig.r)�TR1�TR2�TR3r��TR10�LrV�TR8�TR6�TR15�TR16�TR111�TR5�TRmorrie�TR11�_TR11�TR14�TR22�TR12Nc����|��|���t|��t|j��|jfSrm)rrrzr_r)r=rws �r?r�z_futrig.<locals>.<lambda>�s2���a�a��d�d�A�K�K�M�M�6�!�9�9�c�!�&�k�k�1�8�L�rAc�6�|�t��Srm)r�r(r�s r?r�z_futrig.<locals>.<lambda>�s��a�e�e�1�2�2�rAc�0��tt|���Srm��_eapplyr*�r=�trigss �r?r�z_futrig.<locals>.<lambda>�����'�&�!�U�+�+�rAc�0��tt|���Srm�r�rr�s �r?r�z_futrig.<locals>.<lambda>�����W�X�q�%�8�8�rAc�(��td�|���S)Nc�D�t|�����Srm)r*�normal)rQs r?r�z+_futrig.<locals>.<lambda>.<locals>.<lambda>�s��F�1�8�8�:�:�$6�$6�rA�r�r�s �r?r�z_futrig.<locals>.<lambda>�s���'�6�6��5�A�A�rAc�0��tt|���Srmr�r�s �r?r�z_futrig.<locals>.<lambda>�r�rAc�0��tt|���Srmr�r�s �r?r�z_futrig.<locals>.<lambda>�r�rAc�,����|����Srmr;)r=rtr�s ��r?r�z_futrig.<locals>.<lambda>�s���T�T�#�#�a�&�&�\�\�rAc�B��tt�|�����Srm�r�r)r=r}r�s ��r?r�z_futrig.<locals>.<lambda>�s���g�j�#�#�a�&�&�%�8�8�rAc�B��tt�|�����Srmr�)r=rzr�s ��r?r�z_futrig.<locals>.<lambda>�s ���g��D�D��G�G�U�,�,�rAc�B��tt�|�����Srmr�)r=ryr�s ��r?r�z_futrig.<locals>.<lambda>�s���w�z�3�3�q�6�6�5�9�9�rAc�B��tt�|�����Srmr�)r=r{r�s ��r?r�z_futrig.<locals>.<lambda>�s ���w��D�D��G�G�U�,�,�rAc�B��tt�|�����Srmr�)r=r�r�s ��r?r�z_futrig.<locals>.<lambda>�s ���W� ���Q����(�(�rAc�B��tt�|�����Srm)r�r )r=r�r�s ��r?r�z_futrig.<locals>.<lambda>�s ���W� �$�$�q�'�'�5�*�*�rA)� objective)r�rsrtrur�rvrwrVrxryrzr{r|r}r~rr�r�r�r�r�r(r�rr1r2)r>rsrurvrVrxr|r~rr�r�rU�Lops�treerwr�rzr{rtr�r�r}ryr�s @@@@@@@@@@r?rnrn�s������������������������������������������������������� �5�5�&� '� '�����x���#�#�$9�:�:���q�q��� L� L� L� L�D� 2� 2�E� � � � �+�+�+�+� � �8�8�8�8�9� �A�A�A�A� � � � �e�S�+�+�+�+� � �8�8�8�8�9� �� �3�� �)�)�)�)�)�*� 8� 8� 8� 8� 8� ,� ,� ,� ,� ,� -� :� 9� 9� 9� 9� ,� ,� ,� ,� ,� -� � �4�� �(�(�(�(�(� )� �S�$� �*�*�*�*�*� +�C# �$ �D�J %��t�t�$�$�$�Q�'�'�A� �� �A�I�� �HrAc��t|t��rt|j��St|t��sdSt d�|jD����S)zD_eapply helper to tell whether ``e`` and all its args are Exprs.Fc3�4K�|]}t|��V��dSrm)�_is_Expr)r<rQs r?roz_is_Expr.<locals>.<genexpr>�s(����+�+�q�x��{�{�+�+�+�+�+�+rA)rBrr�r�r�allr_)r>s r?r�r��s\���!�Z� � � ������� �a�� � ���u� �+�+�A�F�+�+�+� +� +�+rAc����t|t��s|St|��s|js �|��S|j��fd�|jD���S)zdApply ``func`` to ``e`` if all args are Exprs else only apply it to those args that *are* Exprs.c�N��g|]!}�� �|��rt�|��n|��"Srmr�)r<�ei�condr^s ��r?r@z_eapply.<locals>.<listcomp>�sH������ �#�l�d�d�2�h�h�l���b����R���rA)rBrr�r_r^)r^r>r�s` `r?r�r��s���� �a�� � ������{�{��!�&���t�A�w�w�� �1�6�������&���� �rA)Frm)\� collectionsr� functoolsr� sympy.corerrrrr r r r �sympy.core.cacher �sympy.core.functionrrrrrrr�sympy.core.numbersrr�sympy.core.intfuncr�sympy.core.sortingr�sympy.core.symbolrrr�sympy.external.gmpyr�sympy.functionsrrrr 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.miscr4r�r�r�r�rr�r(r+r0r@rOrNrPrRrrTr�rnr�r�r;rAr?�<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��!&�LF�LF�LF�LF�^ �!3� 4�����Di�i�i�i�X[�[�[�~!%�E�E�E�E�E�PA�A�A� ��Q�Q�Q�h)�)�)�X�{��� �����)�)�)�X���� �~�~�~� ��~�D�( �( �( �( �( �V< �< �< �~,�,�,� � � � � � rA
Memory