� ��g�����ddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZddlmZddlmZmZmZmZmZmZddl m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'dd l(m)Z)dd l*m+Z+dd l,m-Z-dd l.m/Z0m1Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9ddl:m;Z;ddl<m=Z=m>Z>m?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGmHZHmIZIddlJmKZKddlLmMZMmNZNmOZOmPZPmQZQmRZRddlSmTZTddlUmVZVddlWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^m_Z_m`Z`ddlambZbmcZcddldmeZeddlfmgZgmhZhddlimjZjddlkmlZldd lmmnZnmoZompZpdd!lqmrZrdd"lsmtZtmuZudd#lvmwZwdd$lxmyZymzZzm{Z{m|Z|dd%l}m~Z~dd&lZgd'd'fd(�Z�d)�Z�d*�Z�d+�Z�d,�Z�d-�Z�dLd.�Z�d/ed'd'd0fd1�Z�d2�Z�d3�Z�dMd4�Z�dNd5�Z�d6�Z�dNd7�Z�d8�Z�dOd9�Z�d:�Z�d;�Z�d<�Z�dPd?�Z� dQdB�Z�dRdC�Z�ej�fdD�Z�dSdE�Z�dOdF�Z�ewdGdHdI�J��e0��Z/ewdKdHdI�J��e2��Z1d&S)T�)� defaultdict)�Product)�Sum)�Basic�S�Add�Mul�Pow�Symbol�sympify� expand_func�Function�Dummy�Expr� factor_terms�expand_power_exp�Eq)� factor_nc)�global_parameters)� expand_log� count_ops�_mexpand�nfloat� expand_mul�expand)�Float�I�pi�Rational� equal_valued)� Relational)� Transform)�ordered)�_sympify)� bottom_up�walk)�gamma�exp�sqrt�log� exp_polar�re)�CombinatorialFunction)� unpolarify�Abs�sign)�ExpBase)�HyperbolicFunction)�ceiling)� Piecewise�piecewise_fold�piecewise_simplify)�TrigonometricFunction)� BesselBase�besselj�besseli�besselk�bessely�jn)�KroneckerDelta)�Integral)� MatrixExpr�MatAdd�MatMul�MatPow� MatrixSymbol)�together�cancel�factor)� _is_sum_surds�_minimal_polynomial_sq)�combsimp)�sub_pre�sub_post)� hyperexpand)�powsimp)�radsimp�fraction� collect_abs)� sqrtdenest)�trigsimp� exptrigsimp)� deprecated)� has_variety�sift�subsets�iterable)�as_intNFc��t|��}|rtt||��|��St||��S)a� Separates variables in an expression, if possible. By default, it separates with respect to all symbols in an expression and collects constant coefficients that are independent of symbols. Explanation =========== If ``dict=True`` then the separated terms will be returned in a dictionary keyed to their corresponding symbols. By default, all symbols in the expression will appear as keys; if symbols are provided, then all those symbols will be used as keys, and any terms in the expression containing other symbols or non-symbols will be returned keyed to the string 'coeff'. (Passing None for symbols will return the expression in a dictionary keyed to 'coeff'.) If ``force=True``, then bases of powers will be separated regardless of assumptions on the symbols involved. Notes ===== The order of the factors is determined by Mul, so that the separated expressions may not necessarily be grouped together. Although factoring is necessary to separate variables in some expressions, it is not necessary in all cases, so one should not count on the returned factors being factored. Examples ======== >>> from sympy.abc import x, y, z, alpha >>> from sympy import separatevars, sin >>> separatevars((x*y)**y) (x*y)**y >>> separatevars((x*y)**y, force=True) x**y*y**y >>> e = 2*x**2*z*sin(y)+2*z*x**2 >>> separatevars(e) 2*x**2*z*(sin(y) + 1) >>> separatevars(e, symbols=(x, y), dict=True) {'coeff': 2*z, x: x**2, y: sin(y) + 1} >>> separatevars(e, [x, y, alpha], dict=True) {'coeff': 2*z, alpha: 1, x: x**2, y: sin(y) + 1} If the expression is not really separable, or is only partially separable, separatevars will do the best it can to separate it by using factoring. >>> separatevars(x + x*y - 3*x**2) -x*(3*x - y - 1) If the expression is not separable then expr is returned unchanged or (if dict=True) then None is returned. >>> eq = 2*x + y*sin(x) >>> separatevars(eq) == eq True >>> separatevars(2*x + y*sin(x), symbols=(x, y), dict=True) is None True )r �_separatevars_dict� _separatevars)�expr�symbols�dict�forces �g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/simplify/simplify.py� separatevarsrc1sB��F �4�=�=�D� �*�!�-��e�"<�"<�g�F�F�F��T�5�)�)�)�c���t|t��r_|jd}|jrK|jsDt |d|���}|�.t t|j|� �����S|St|j ��dkr|S|jrZt|j��}d}t|��D]&\}}t ||��||<|p |||k}�'|r |j|�}|S|jr>|jt jkr)t%t |j|���|j��}|�dd|���}|rt+|��n|if\}} t-|���| ��}|js|St|j��}|d�dd���d} |d d�D]"}| |�dd���dz} �#t | �} | ���d } | �dd���d} t|��D]:\}}|�dd���\} } | | z } t | �t | �z||<�;t7|�}t|j ��d krE|}|rt+|��n|if\}} t-|���| ��}|js|}| |zS) NrT)r`ra�F�ra)�mul� multinomialra)�cset�warn�)� isinstancer/�args�is_Mul� is_numberrcr �map�func�values�len� free_symbols�list� enumerate�is_Pow�baser�Exp1r r(r�posifyrG�subs�is_Add�args_cnc� as_coeff_Mulr)r^ra�arg�srn�changed�i�a�_expr�reps�commonc� commonc_set�c�nc�nonsepars rbr]r]{s���$������i��l�� �:� �c�m� ��S�t�5�9�9�9�A��}��C�� �1�8�8�:�:�6�6�7�7�� � �4� ����!�!�� � �{���D�I�������d�O�O� .� .�D�A�q�"�1�e�,�,�D��G��-��a��A��G�G� � $��4�9�d�#�D�� � �{�C�t�y�A�F�*�*��<�� ��7�7�7���B�B�� �;�;�5�e�5�;� A� A�D�"'�7�&��,�,�,�d�B�Z�K�E�4� �%�=�=� � �d� #� #�D� �;��� � �� �?�?�D��1�g���D�u��5�5�a�8�G� �!�"�"�X�8�8���1�:�:�4�e�:�4�4�Q�7�7����7�m�G��"�"�$�$�Q�'�G��"�"��5�"�9�9�!�<�K��$���#�#���1�� � ��5� �1�1���2� � �O���q�'�#�r�(�"��Q����D�z�H� �8� �!�!�A�%�%���',�=�f�U�m�m�m�5�"�+� ��t�����$�$�T�*�*���|� ��H� �8� �rdc��|r8td�|D����std���t|��}n|�d|iSt|j��}|sdSd�|dgzD��}t j|��D]�}|j}t |���|��}t|��dkrdSt|��dkr|d� |���p||� ��� |����|� ��D]\}}t |�||<�|S)Nc3�$K�|] }|jV�� dS�N)�is_Atom)�.0�ts rb� <genexpr>z%_separatevars_dict.<locals>.<genexpr>�s$����.�.��1�9�.�.�.�.�.�.rdzsymbols must be Atoms.�coeffc��i|]}|g��S�r��r�r�s rb� <dictcomp>z&_separatevars_dict.<locals>.<dictcomp>�s�� .� .� .�Q�1�b� .� .� .rdrlr) �all� ValueErrorrvrur � make_args�set� intersectionrt�append�pop�items)r^r_�retr��expsymr��k�vs rbr\r\�se��� ��.�.�g�.�.�.�.�.� 7��5�6�6� 6��w�-�-��� �������t�(�)�)��� ��4� .� .�'�W�I�-� .� .� .�C� �]�4� � � .� .������7�|�|�0�0��8�8� � �|� � �q� � ��4�4� �|� � �� !� !� ��L� � �� "� "� "� "� � � � �"�"� #� *� *�1� -� -� -� -�� � � � �����1��a���A��� �Jrdc���t|��}t|��r�t|��}t|��}t ��}|D]/}|�|�t����}�0i}|D]F}|�d�t|��d� ��D�����Gt|��D]\}}|� |��||<�||��d�|� ��D��fSd�|j D��}|� |��}|d�|� ��D��fS)a^Return ``eq`` (with generic symbols made positive) and a dictionary containing the mapping between the old and new symbols. Explanation =========== Any symbol that has positive=None will be replaced with a positive dummy symbol having the same name. This replacement will allow more symbolic processing of expressions, especially those involving powers and logarithms. A dictionary that can be sent to subs to restore ``eq`` to its original symbols is also returned. >>> from sympy import posify, Symbol, log, solve >>> from sympy.abc import x >>> posify(x + Symbol('p', positive=True) + Symbol('n', negative=True)) (_x + n + p, {_x: x}) >>> eq = 1/x >>> log(eq).expand() log(1/x) >>> log(posify(eq)[0]).expand() -log(_x) >>> p, rep = posify(eq) >>> log(p).expand().subs(rep) -log(x) It is possible to apply the same transformations to an iterable of expressions: >>> eq = x**2 - 4 >>> solve(eq, x) [-2, 2] >>> eq_x, reps = posify([eq, x]); eq_x [_x**2 - 4, _x] >>> solve(*eq_x) [2] c��i|]\}}||�� Sr�r�)r�r�r�s rbr�zposify.<locals>.<dictcomp> s��?�?�?�$�!�Q��A�?�?�?rdrlc��i|]\}}||�� Sr�r��r�r��rs rbr�zposify.<locals>.<dictcomp>s��5�5�5���1�q�!�5�5�5rdc�P�i|]#}|j� |t|jfddi|j����$S)N�positiveT)� is_positiver�name� assumptions0)r�r�s rbr�zposify.<locals>.<dictcomp>sG�� D� D� D��Q�]�-B� �u�Q�V�=�=�d�=�a�n�=�=�-B�-B�-Brdc��i|]\}}||�� Sr�r�r�s rbr�zposify.<locals>.<dictcomp>s��.�.�.���A��1�.�.�.rd)r rY�typervr��union�atomsr �updater{r�rwr|ru)�eq�f�syms�er�r�r�s rbr{r{�sg��R ����B���|�|� 6� ��H�H�� �"�X�X���u�u��� /� /�A��:�:�a�g�g�f�o�o�.�.�D�D���� A� A�A� �K�K�?�?�&��)�)�A�,�*<�*<�*>�*>�?�?�?� @� @� @� @��b�M�M� !� !�D�A�q��F�F�4�L�L�B�q�E�E��q��u�u�5�5�� � � � �5�5�5�5�5� D� D��/� D� D� D�D� ������B� �.�.������.�.�.� .�.rdc��t|��}|�||dz��|z }|�t��}|�t ��r"t |��}|jdd}t|��}t|dd���}|� |��rt|tj ���SdS) a9Given combinatorial term f(k) simplify its consecutive term ratio i.e. f(k+1)/f(k). The input term can be composed of functions and integer sequences which have equivalent representation in terms of gamma special function. Explanation =========== The algorithm performs three basic steps: 1. Rewrite all functions in terms of gamma, if possible. 2. Rewrite all occurrences of gamma in terms of products of gamma and rising factorial with integer, absolute constant exponent. 3. Perform simplification of nested fractions, powers and if the resulting expression is a quotient of polynomials, reduce their total degree. If f(k) is hypergeometric then as result we arrive with a quotient of polynomials of minimal degree. Otherwise None is returned. For more information on the implemented algorithm refer to: 1. W. Koepf, Algorithms for m-fold Hypergeometric Summation, Journal of Symbolic Computation (1995) 20, 399-417 rl�����rTr()�deep�combine)�ratioN)r r|�rewriter'�hasr4r5rnr rN�is_rational_function�simplifyr�Infinity)r�r��gs rb� hypersimpr�s���< �� � �A� ���q�!�a�%���1��A� � � �%���A��u�u�Y���� �1� � �� �F�2�J�q�M���A���A����e�,�,�,�A����a� � ������,�,�,�,��trdc���ttt||f����\}}||z �t��}|�dd���}|�|��S)a; Returns True if ``f`` and ``g`` are hyper-similar. Explanation =========== Similarity in hypergeometric sense means that a quotient of f(k) and g(k) is a rational function in ``k``. This procedure is useful in solving recurrence relations. For more information see hypersimp(). TF)rr�basic)rvrqr r�r'rr�)r�r�r��hs rb� hypersimilarr�Gsa�� ��G�a��V�$�$� %� %�D�A�q� �1�� � �e���A� ���d�%��(�(�A� � !� !�!� $� $�$rdc�D�|� tj}t|��}t|tt f��r|jr|S|�d�d���}tt|����}t|tt f��r|jr|S|j rc|j d�|j D���}|sFt|t��r1|���rtt j| d���S|S|r|�d�d���}|S) a�Make all Add sub-expressions canonical wrt sign. Explanation =========== If an Add subexpression, ``a``, can have a sign extracted, as determined by could_extract_minus_sign, it is replaced with Mul(-1, a, evaluate=False). This allows signs to be extracted from powers and products. Examples ======== >>> from sympy import signsimp, exp, symbols >>> from sympy.abc import x, y >>> i = symbols('i', odd=True) >>> n = -1 + 1/x >>> n/x/(-n)**2 - 1/n/x (-1 + 1/x)/(x*(1 - 1/x)**2) - 1/(x*(-1 + 1/x)) >>> signsimp(_) 0 >>> x*n + x*-n x*(-1 + 1/x) + x*(1 - 1/x) >>> signsimp(_) 0 Since powers automatically handle leading signs >>> (-2)**i -2**i signsimp can be used to put the base of a power with an integer exponent into canonical form: >>> n**i (-1 + 1/x)**i By default, signsimp does not leave behind any hollow simplification: if making an Add canonical wrt sign didn't change the expression, the original Add is restored. If this is not desired then the keyword ``evaluate`` can be set to False: >>> e = exp(y - x) >>> signsimp(e) == e True >>> signsimp(e, evaluate=False) exp(-(x - y)) Nc� �|jo| |kSr��ro��xs rb�<lambda>zsignsimp.<locals>.<lambda>�s��q�x�6�q�b�E�Q�J�rdc� �| Sr�r�r�s rbr�zsignsimp.<locals>.<lambda>�s ��Q�B�%�rdc�,�g|]}t|����Sr�)�signsimp�r�r�s rb� <listcomp>zsignsimp.<locals>.<listcomp>�s��2�2�2�a�h�q�k�k�2�2�2rdF��evaluatec� �|jo| |kSr�r�r�s rbr�zsignsimp.<locals>.<lambda>�s���� 7��r�U�a�Z�rdc� �| Sr�r�r�s rbr�zsignsimp.<locals>.<lambda>�s ��a�R�5�rd)rr�r rmrr!r��replacerLrKr}rrrnr�could_extract_minus_signr r� NegativeOne)r^r�r��rvs rbr�r�]s3��d��$�-�� �4�=�=�D� �d�T�:�.� /� /��4�<��� � � � �6�6���H�H�A��������A� �a�$� �+� ,� ,��� �����x�� �Q�V�2�2�1�6�2�2�2� 3��� ;�J�r�3��� ;��1�1�3�3� ;��q�}�r�c�E�:�:�:� :�� ��J� �I�I�7�7��� I� I�� �Hrdg333333�?Tc ���������fd����fd�}t||���}��d|����d�����d|����d|����d���d ��t|t��r|jr|js t jn|St|d d ��}|�|d i���Stt|����x} }t|t��r|j s|S|r2|� t��rt|��}|j s|St t"t$t&f�|��fd ��fd �d���}t|���s ||��S|jst-|��}d} |dur-|� t.��rd} t1|d���}t3|d���}t#t5|������}t9|��} �| t;| �������} �t=|d���t=| d�����} |t jur| }n �| | |��}t|t��s|StA|d���}|� tB��r|�"tF��}|� tH��r�tK|��}||��}|� tH��r�tK|��}|� tL��rtO|��}|� tH��rGtQ|dd���}|� tH��r�|tA|����}|StS|��}|� tL��rtO|��}|� tT��rtW|��}|� tXtZ��rt]|d���}|� t^��r(�ta|d���tc|����}|� tdtf��rti|��}|� tj��r tm|fi���}|� tn��r7|�8d�|�9tn��D����}|� tt��r tw|fi���}ddl<m=}|� |��rddl>m?}||��}�t5|dd���t5|��|��}�|t9|����}�|tA|��t�t�|������}|� tXtZt&t���rt�|��}t�d�d���}|�8|��}|�E��\}}|jFrMt�t�d|z dd�����\}}|t jIur||z�J��|z }|�K��r,t�|��\}}|dkrt| | z ��}�|��|�| ��zkr| }| r|�t�|d���}||��S)!a�Simplifies the given expression. Explanation =========== Simplification is not a well defined term and the exact strategies this function tries can change in the future versions of SymPy. If your algorithm relies on "simplification" (whatever it is), try to determine what you need exactly - is it powsimp()?, radsimp()?, together()?, logcombine()?, or something else? And use this particular function directly, because those are well defined and thus your algorithm will be robust. Nonetheless, especially for interactive use, or when you do not know anything about the structure of the expression, simplify() tries to apply intelligent heuristics to make the input expression "simpler". For example: >>> from sympy import simplify, cos, sin >>> from sympy.abc import x, y >>> a = (x + x**2)/(x*sin(y)**2 + x*cos(y)**2) >>> a (x**2 + x)/(x*sin(y)**2 + x*cos(y)**2) >>> simplify(a) x + 1 Note that we could have obtained the same result by using specific simplification functions: >>> from sympy import trigsimp, cancel >>> trigsimp(a) (x**2 + x)/x >>> cancel(_) x + 1 In some cases, applying :func:`simplify` may actually result in some more complicated expression. The default ``ratio=1.7`` prevents more extreme cases: if (result length)/(input length) > ratio, then input is returned unmodified. The ``measure`` parameter lets you specify the function used to determine how complex an expression is. The function should take a single argument as an expression and return a number such that if expression ``a`` is more complex than expression ``b``, then ``measure(a) > measure(b)``. The default measure function is :func:`~.count_ops`, which returns the total number of operations in the expression. For example, if ``ratio=1``, ``simplify`` output cannot be longer than input. :: >>> from sympy import sqrt, simplify, count_ops, oo >>> root = 1/(sqrt(2)+3) Since ``simplify(root)`` would result in a slightly longer expression, root is returned unchanged instead:: >>> simplify(root, ratio=1) == root True If ``ratio=oo``, simplify will be applied anyway:: >>> count_ops(simplify(root, ratio=oo)) > count_ops(root) True Note that the shortest expression is not necessary the simplest, so setting ``ratio`` to 1 may not be a good idea. Heuristically, the default value ``ratio=1.7`` seems like a reasonable choice. You can easily define your own measure function based on what you feel should represent the "size" or "complexity" of the input expression. Note that some choices, such as ``lambda expr: len(str(expr))`` may appear to be good metrics, but have other problems (in this case, the measure function may slow down simplify too much for very large expressions). If you do not know what a good metric would be, the default, ``count_ops``, is a good one. For example: >>> from sympy import symbols, log >>> a, b = symbols('a b', positive=True) >>> g = log(a) + log(b) + log(a)*log(1/b) >>> h = simplify(g) >>> h log(a*b**(1 - log(a))) >>> count_ops(g) 8 >>> count_ops(h) 5 So you can see that ``h`` is simpler than ``g`` using the count_ops metric. However, we may not like how ``simplify`` (in this case, using ``logcombine``) has created the ``b**(log(1/a) + 1)`` term. A simple way to reduce this would be to give more weight to powers as operations in ``count_ops``. We can do this by using the ``visual=True`` option: >>> print(count_ops(g, visual=True)) 2*ADD + DIV + 4*LOG + MUL >>> print(count_ops(h, visual=True)) 2*LOG + MUL + POW + SUB >>> from sympy import Symbol, S >>> def my_measure(expr): ... POW = Symbol('POW') ... # Discourage powers by giving POW a weight of 10 ... count = count_ops(expr, visual=True).subs(POW, 10) ... # Every other operation gets a weight of 1 (the default) ... count = count.replace(Symbol, type(S.One)) ... return count >>> my_measure(g) 8 >>> my_measure(h) 14 >>> 15./8 > 1.7 # 1.7 is the default ratio True >>> simplify(g, measure=my_measure) -log(a)*log(b) + log(a) + log(b) Note that because ``simplify()`` internally tries many different simplification strategies and then compares them using the measure function, we get a completely different result that is still different from the input expression by doing this. If ``rational=True``, Floats will be recast as Rationals before simplification. If ``rational=None``, Floats will be recast as Rationals but the result will be recast as Floats. If rational=False(default) then nothing will be done to the Floats. 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. Note that ``simplify()`` automatically calls ``doit()`` on the final expression. You can avoid this behavior by passing ``doit=False`` as an argument. Also, it should be noted that simplifying a boolean expression is not well defined. If the expression prefers automatic evaluation (such as :obj:`~.Eq()` or :obj:`~.Or()`), simplification will return ``True`` or ``False`` if truth value can be determined. If the expression is not evaluated by default (such as :obj:`~.Predicate()`), simplification will not reduce it and you should use :func:`~.refine` or :func:`~.ask` function. This inconsistency will be resolved in future version. See Also ======== sympy.assumptions.refine.refine : Simplification using assumptions. sympy.assumptions.ask.ask : Query for boolean expressions using assumptions. c�T��t|��s|dSt|����S)z Return the choice that has the fewest ops. In case of a tie, the expression listed first is selected. r��key)rV�min)�choices�measures �rb�shorterzsimplify.<locals>.shorter?s2��� �7�#�#� ��1�:� ��7��(�(�(�(rdc�f���r|���n|}�|t|����Sr�)�doitrQ)r�r�r�r�s ��rb�donezsimplify.<locals>.doneHs1���� $�Q�V�V�X�X�X�1���w�r�;�r�?�?�+�+�+rd��rationalr�r�r��inverser�)r�r�r�r�r��_eval_simplifyNc�^��t|t��o|jot|��� Sr�)rmrrn)r��handleds �rbr�zsimplify.<locals>.<lambda>ms5���*�Q��%�%��!�&��� �w�:�:�6�rdc�:��|j�fd�|jD���S)Nc�*��g|]}t|fi�����Sr�)r�)r�r��kwargss �rbr�z.simplify.<locals>.<lambda>.<locals>.<listcomp>os)���A�A�A�Q�8�A�0�0��0�0�A�A�Ard)rrrn)r�r�s �rbr�zsimplify.<locals>.<lambda>os'���&�!�&�A�A�A�A�!�&�A�A�A�B�rdF�� simultaneousTc�<��t�d�fd�����S)N�normalc����Sr�r���ws�rbr�z,simplify.<locals>.<lambda>.<locals>.<lambda>�s���1�rd)�getattrr�s`rbr�zsimplify.<locals>.<lambda>�s"���&E�g�a��9�9�9�9�&E�&E�&G�&G�rd�r�)r0)r�r�c�.�i|]}|t|����Sr�)rr�s rbr�zsimplify.<locals>.<dictcomp>�s-��>�>�>�#$�A�|�A���>�>�>rdr)�Quantity)�quantity_simplifyr()r�r�c��t|j�Sr�)r rnr�s rbr�zsimplify.<locals>.<lambda>�s ��#�q�v�,�rdc��|joBt|j��dko*|jdjo|jdjo|jS)Nrfrrl)rortrn� is_Numberr}�is_commutativer�s rbr�zsimplify.<locals>.<lambda>�sR�� �� � �A�F� � �q�� � ��q� �� � ��q� �� � �� rdrl)�symbolic� max_terms)�exponentr�)Mr �getrmr�is_zeror�r�Zeror�rQr�rrnr�r�inversecombinerr r r1r�r�� nc_simplifyr� nsimplify� _bottom_uprN�as_content_primitiverFrrEr�rr0r�r/r4r5r>� kroneckersimpr6rMr8� besselsimpr7r2rSr*r� logcombiner-r'rJr� sum_simplifyr?�xreplacer�r�product_simplify�sympy.physics.unitsr��sympy.physics.units.utilr�rrr(rTr"�as_numer_denomr}rPrO�Onerr�r)r^r�r�r�r�r�r�r�r�� original_expr�floats�_e�expr1�expr2r�r��short� hollow_mul�numer�denom�n�dr�r�s ` `` @@rbr�r��s��������v)�)�)�)�)�,�,�,�,�,�,� �4�(� +� +� +�D����G�U�+�+��:�:�i��1�1��J�J�z�8�4�4��:�:�i��1�1�� � �6�4�(�(� *�*�F��$����6�$�,�6�!�^�5�q�v�v��5��T�#3�T�:�:�N��!��~�'�'��'�'�'�&�x��~�~�6�6�6�M�D� �d�E� "� "��$�)��� ���4�8�8�H�%�%���d�#�#���y� ��K��3��W�$�G� �<�<�  � � � �B�B�B�B�� � � �D� �d�G� $� $���t�D�z�z�� � �!��4� � ���F��u������%���������-�-�-�� �d�G�G� H� H�D� ��� � �2�2�4�4� 5�D� ����B� �G�B��� � �+�+�-�-� .� .�E� �G�H�T��-�-�-�x��D�/I�/I�/I� J� J�E� �� �������w�u�e�T�*�*�� �d�E� "� "��� � ��5� )� )� )�D� �x�x��~�~�!��|�|�C� � �� �x�x� ��� ��d�#�#���t�D�z�z�� �8�8�I� � � �"�$�'�'�D��x�x��'�'� +�$�T�*�*���x�x� �"�"� �*�$�T��F�F�F���8�8�I�&�&� �"�7�4��d�);�);�<�<�D� �K� �t� � �D� �x�x����#��T�"�"�� �x�x� ��� ��$���� �x�x�%�'9�:�:�)���4�(�(�(�� �x�x��}�}�F��w�z�$�T�2�2�2�J�t�4D�4D�E�E�� �x�x�%�u�-�-����~�~�� �x�x��}�}�,��D�+�+�F�+�+�� �x�x����?��}�}�>�>�(,� � �8�(<�(<�>�>�>�?�?�� �x�x����0���/�/��/�/��,�,�,�,�,�,� �x�x����'�>�>�>�>�>�>� � ��&�&�� �G�G�D�%�d�;�;�;�W�T�]�]�D� Q� Q�E� �G�E�6�%�=�=� )� )�E� �G�E�<��.�.�0@��E�AR�AR�0S�0S� T� T�E� �y�y�&�(:�G�S�I�I�#��E�"�"����� � ���J� �>�>�*� %� %�D��&�&�(�(�L�E�5� �|�(����%��%�1�E�E�E�F�F���1� �A�E�>�>��!�G�#�#�%�%�a�'�D� �$�$�&�&�%���~�~���1� ��6�6��Q�B���G�$�$�D��w�t�}�}�u�W�W�]�3�3�3�3�3����,�(�"��d�U�+�+�+�� �4��:�:�rdc �.��t|t��s9|��fd�|�t��D����}t |��}t|t��s|S|j}g}g}|D]w}t tj|��d�d���\}}|s|� |���Bt|�g}|� t|�fd�|D��z����xtt|��g|�R�}|S)z$Main function for Sum simplificationc�`��i|]*}|�t���|t|fi�����+Sr�)r�rr )r�r�r�s �rbr�z sum_simplify.<locals>.<dictcomp>�sI���1�1�1��Q�U�U�3�Z�Z�1��<��4�4�V�4�4�1�1�1rdc�,�t|t��Sr��rmr)r�s rbr�zsum_simplify.<locals>.<lambda> s��j��C�(�(�rdT)�binaryc�*��g|]}|jdi�����S)r�)r�)r�r�r�s �rbr�z sum_simplify.<locals>.<listcomp>s-���!P�!P�!P��"2�!�"2�"<�"<�V�"<�"<�!P�!P�!Prd) rmrr r�rrnrWr r�r�� sum_combine) r�r��terms�s_t�o_t�term� sum_terms�other�results ` rbr r �sG��� �a�� � �2� �J�J�1�1�1�1��W�W�S�\�\�1�1�1� 2� 2���q� � �A� �a�� � ���� �F�E� �C� �C��T�T���� �d� 3� 3� (� (��7�7�7�� �5�� � �J�J�t� � � � ��e�� �� � � �3��!P�!P�!P�!P�i�!P�!P�!P�P�R�S�S�S�S� ��S�!�!� (�C� (� (� (�F� �Mrdc���dgt|��z}td��D]�}t|��D]o\}}||sbt|��D]R\}}||sE||kr?t|||��}t |t t f��r|||<||}d||<�S�p��tj}t|��D]\}} ||st|| ��}�|S)z�Helper function for Sum simplification Attempts to simplify a list of sums, by combining limits / sum function's returns the simplified sum FrfT) rt�rangerw�sum_addrmrr rrr) r&�used�methodr��s_term1�j�s_term2�tempr+�s_terms rbr$r$s �� �7�S��X�X� �D���(�(� +� +��#�C�.�.� +� +�J�A�w���7� +�"+�C�.�.�+�+�J�A�w���7�+�q�A�v�v�&�w���@�@��%�d�S�#�J�7�7�+�%)�C��F�&)�!�f�G�&*�D��G��� +��V�F��s�^�^�)�)� ��6��A�w� )����(�(�F�� �Mrdc�L�||||d�}|r t|g|�R�n|}t|fi|��S)a�Return Sum with constant factors extracted. If ``limits`` is specified then ``self`` is the summand; the other keywords are passed to ``factor_terms``. Examples ======== >>> from sympy import Sum >>> from sympy.abc import x, y >>> from sympy.simplify.simplify import factor_sum >>> s = Sum(x*y, (x, 1, 3)) >>> factor_sum(s) y*Sum(x, (x, 1, 3)) >>> factor_sum(s.function, s.limits) y*Sum(x, (x, 1, 3)) )�radical�clearrPr0)rr)�self�limitsr7r8rPr0r�r^s rb� factor_sumr;1sO��&!�5��d�,�,�F�!'� 1�3�t� �f� � � � �T�D� �� '� '�� '� '�'rdc���d�}t|t��r ||��}n|}t|t��r ||��}n|}t|��t|��u�rt|dkr>|j|jkr,t t |j|jzg|j�R���S�n0|dk�r)t|j|jz ��dk�rt|j��t|j��cxkrdkr�nn�|jdd}|jdd}|jdd}|jdd} |jdd} |jdd} || kr\| |dzkr%t t |j||| f����S|| dzkr%t t |j|| |f����St||��S)z&Helper function for Sum simplificationc���tj|��}td�|D�����t�fd�|D���}t|�jzg�j�R�S)Nc3�DK�|]}t|t���|V��dSr�r!�r�r�s rbr�z.sum_add.<locals>.__refactor.<locals>.<genexpr>Qs1����:�:�!�z�!�S�'9�'9�:�A�:�:�:�:�:�:rdc� ��g|] }|�k�|�� Sr�r�)r�r��sumvs �rbr�z/sum_add.<locals>.__refactor.<locals>.<listcomp>Rs���6�6�6�q�A��I�I��I�I�Ird)r r��nextr�functionr:)�valrn�constantrAs @rb� __refactorzsum_add.<locals>.__refactorOsl����}�S�!�!���:�:�t�:�:�:�:�:���6�6�6�6�D�6�6�6�7���8�d�m�+�:�d�k�:�:�:�:rdrrlrf) rmr r�r:r;rrCr�rtr) r9r*r0rF�rself�rotherr��x1�y1r2�x2�y2s rbr.r.Js��� ;�;�;� �$������ �4� � ������%�������E�"�"����� �E�{�{�d�6�l�l�"�"� �Q�;�;��|�v�}�,�,�!�#�e�n�v��&F�"V���"V�"V�"V�W�W�W�-� �q�[�[������8�9�9�Q�>�>��u�|�$�$��F�M�(:�(:�?�?�?�?�a�?�?�?�?�?�� �Q���*�A���a���+�B���a���+�B�� �a�(��+�A���q�)�!�,�B���q�)�!�,�B��A�v�v���a��<�<�#-�c�%�.�1�b�"�+�.N�.N�#O�#O�O��2��6�\�\�#-�c�%�.�1�b�"�+�.N�.N�#O�#O�O� �t�U� � �rdc ���tj|��}g}g}|�dd��}|D]z}t|t��rN|r6|�t |jjdi|��g|j�R����O|�|���e|�|���{dgt|��z}td��D]r}t|��D]`\} } || sSt|��D]C\} } || s6| | kr0t| | |��} t| t��r | || <d|| <�D�a�st|�}t|��D]\} }|| st||��}�|S)z(Main function for Product simplificationr�TFrfr�) r r�rrmrr�rCr�r:rtr-rw� product_mul)r�r�r%�p_tr'r�r(r/r0r��p_term1r2�p_term2�tmp_prodr+�p_terms rbrrvs��� �M�!� � �E� �C� �C� �:�:�f�d� #� #�D����� �d�G� $� $� �� !�� � �7�#9�4�=�#9�#C�#C�F�#C�#C�1�$(�K�1�1�1�2�2�2�2�� � �4� � � � � �J�J�t� � � � � �7�S��X�X� �D���(�(�+�+��#�C�.�.� +� +�J�A�w���7� +�"+�C�.�.�+�+�J�A�w���7�+�q�A�v�v�#.�w���#H�#H��%�h��8�8�+�%-�C��F�&*�D��G��� +��#�Y�F��s�^�^�)�)� ��6��A�w� )����(�(�F�� �Mrdc���t|��t|��u�rL|dkr1|j|jkrt|j|jzg|j�R�S�n|dk�rt |j|jz ��dkr�t |j��t |j��cxkrdkr�nn�|jdd}|jdd}|jdd}|jdd}|jdd}|jdd}||krB||dzkrt|j|||f��S||dzkrt|j|||f��St ||��S)z*Helper function for Product simplificationrrlrf)r�r:rrCr�rtr ) r9r*r0r�rIrJr2rKrLs rbrNrN�su�� �D�z�z�T�%�[�[� � � �Q�;�;��{�e�l�*�*��t�}�u�~�=�L�� �L�L�L�L�+� �q�[�[��� ���6�7�7�1�<�<��t�{�#�#�s�5�<�'8�'8�=�=�=�=�A�=�=�=�=�=�� �A��q�)�A���Q���*�B���Q���*�B�� �Q���*�A���a���+�B���a���+�B��A�v�v���a��<�<�#*�4�=�1�b�"�+�#F�#F�F��2��6�\�\�#*�4�=�1�b�"�+�#F�#F�F� �t�U� � �rdc���ddlm}|dzdkr*tt|����}|dz}|dzdk�*|dkr|S|t d|��z}t d��}t |||��}|�dS|||��}|D]Y}t||z �����dd|zz kr)t|��}t||z��|kr|cS�ZdS) zm helper function for ``nthroot`` It denests ``p**Rational(1, n)`` using its minimal polynomial r)�solverfrlr�Ng�?� ) � sympy.solversrVrRr)rr rI�absrr) �pr�precrV�pnr�r��sols�sols rb�_nthroot_solver_�s�� $�#�#�#�#�#� �a�%�1�*�*� �t�A�w�w� � �� ��F�� �a�%�1�*�*� �A�v�v��� �H�Q��N�N� �B��s� � �A��q�!�Q�'�'�A��y��t� �5��A�;�;�D����� �s�R�x�=�=�?�?� � �r�"�d�(�{� *� *��S�/�/�C���Q����1�$�$�� � � �� �rdc�.���fd�}t||��S)a� Takes logarithms and combines them using the following rules: - log(x) + log(y) == log(x*y) if both are positive - a*log(x) == log(x**a) if x is positive and a is real If ``force`` is ``True`` then the assumptions above will be assumed to hold if there is no assumption already in place on a quantity. For example, if ``a`` is imaginary or the argument negative, force will not perform a combination but if ``a`` is a symbol with no assumptions the change will take place. Examples ======== >>> from sympy import Symbol, symbols, log, logcombine, I >>> from sympy.abc import a, x, y, z >>> logcombine(a*log(x) + log(y) - log(z)) a*log(x) + log(y) - log(z) >>> logcombine(a*log(x) + log(y) - log(z), force=True) log(x**a*y/z) >>> x,y,z = symbols('x,y,z', positive=True) >>> a = Symbol('a', real=True) >>> logcombine(a*log(x) + log(y) - log(z)) log(x**a*y/z) The transformation is limited to factors and/or terms that contain logs, so the result depends on the initial state of expansion: >>> eq = (2 + 3*I)*log(x) >>> logcombine(eq, force=True) == eq True >>> logcombine(eq.expand(), force=True) log(x**2) + I*log(x**3) See Also ======== posify: replace all symbols with symbols having positive assumptions sympy.core.function.expand_log: expand the logarithms of products and powers; the opposite of logcombine c �| ���|js |js|S�fd�}�fd�}g}g}tt���t j|��D�]�}t |t��r)||��r�d�g|f���A|js|�|���^g}g}g}|j D]�} | j r<| dkr6|�tj ��|�| ���Et | t��r!|| ��r|�| ���{|| ��r|�| ����|�| ����t|��dkr|�|||f����J|r2�t|���||df����~|�|�����t|��dkrJt |dt��r/�d�g|���f��|st!�fd��D����r|S|D]�\} } } tt#| ����} t| �d��j dt%| �z��} | r4| �d��} t| j d| z��} | �4t%| �| } }t | t��r�|f�g| f����|�|| z����t������D]P}tt)t%d���|��D�������d � ���t%|�<�Qt#t��������D]�}|�vr�| �vr�|| }}|���|���kr||}}|�|t��|��j d��|��j dz d � ��z����|�|��|��z����t |�S) Nc�D��|tjuo|jp �o|jduS)NF)rr��is_extended_real)r�ras �rb�goodaz$logcombine.<locals>.f.<locals>.gooda�s3����Q�]�*�R��#�P�u�'P��1C�5�1P� Srdc�B��|jd}|jp �o|jduS)NrF)rnr��is_nonpositive)�lr�ras �rb�goodlogz&logcombine.<locals>.f.<locals>.goodlogs(�����q� �A��=�K�E�$K�a�.>�e�.K� Krdr�rrlc3�n�K�|]/}t�|��dko�|dgkV��0dS)rlrN)rt)r�r��log1s �rbr�z(logcombine.<locals>.f.<locals>.<genexpr>-sD�����Q�Q�q�C��Q��L�L�A�-�B�$�q�'�!�*��2B�Q�Q�Q�Q�Q�Qrdc�B�g|]\}}|jdt|�z��S�r)rnr )r�r�rgs rbr�z)logcombine.<locals>.f.<locals>.<listcomp>Ds8��1<�1<�1<�'+�q�!���q� �3��7�"�1<�1<�1<rdrgFr�)r}rorrvrr�rmr*r�rn� is_Rationalrr�rt�tupler�r�r#r �keysr r)r�rdrhr*�logsr��ot�co�lo�ai�or�rg�lir�r��num�denrjras @�rbr�zlogcombine.<locals>.f�s������ � �R�Y� ��I� S� S� S� S� S�  L� L� L� L� L� �����4� � ����r�"�"� $� $�A��!�S�!�!� $�g�g�a�j�j� $��R�����Q��(�(�(�(��X� $�� � �Q������������&� &� &�B��~�&�"�q�&�&�� � �!�-�0�0�0�� � �2�#�����#�B��,�,�&������&�� � �"� � � � ���r���&�� � �"� � � � �� � �"� � � � ��r�7�7�Q�;�;��K�K��R�� �-�-�-�-��$���r���O�*�*�B��1��;�7�7�7�7��L�L��O�O�O�O� �u�:�:��?�?�z�%��(�C�8�8�?� ��H�O�O�R������-� .� .� .�� ��Q�Q�Q�Q�D�Q�Q�Q�Q�Q� ��I�� "� "�G�A�q�!��W�Q�Z�Z� � �A��A�E�E�!�H�H�M�!�$�c�1�g�-�.�.�A�� '��U�U�1�X�X������ �A� �&�&��� '���7�A�q�A��!�S�!�!� "��a�T� �!�!�2�q�'�*�*�*�*�� � �Q�q�S�!�!�!�!��d�i�i�k�k�"�"� .� .�A�� �3�1<�1<�/3�x�x��{�{�1<�1<�1<�,=��!�!�!�',�.�.�.�D��a��M�M� ��d�i�i�k�k�*�*�+�+� ,� ,�A���}�}���r�T�z�z��q�b�S���=�=�?�?�S�]�]�_�_�4�4�"�C��C�� � ���D�H�H�S�M�M�.�q�1�$�(�(�3�-�-�2D�Q�2G�G�%*�,�,�,�,�-�-�-�-�� � �Q�t�x�x��{�{�]�+�+�+�+��E�{�rd�r)r^rar�s ` rbr r �s5���\]�]�]�]�]�~ �d�A� � �rdc�(�d�}t||��S)a Simplify the composition of a function and its inverse. Explanation =========== No attention is paid to whether the inverse is a left inverse or a right inverse; thus, the result will in general not be equivalent to the original expression. Examples ======== >>> from sympy.simplify.simplify import inversecombine >>> from sympy import asin, sin, log, exp >>> from sympy.abc import x >>> inversecombine(asin(sin(x))) x >>> inversecombine(2*log(exp(3*x))) 6*x c��t|t��ret|jdt��s2|jdjr2|jdjt jkr|jdj}n�|jr�t|d��r�t|j��dkrjt|jdj��dkrGt|jd|� d�����r|jdjd}|jrA|jt jkr,t|jt��r|jjd}|S)Nrr�rl)�argindex) rmr*rnr(rxryrrz� is_Function�hasattrrtr�)r�s rbr�zinversecombine.<locals>.fss�� �b�#� � � (��"�'�!�*�c�*�*� $�r�w�q�z�/@� $�R�W�Q�Z�_�XY�X^�E^�E^��W�Q�Z�^��� �^� (���I� 6� 6� (��B�G� � ��!�!�c�"�'�!�*�/�&:�&:�a�&?�&?��"�'�!�*�b�j�j�!�j�&<�&<�=�=�'@��W�Q�Z�_�Q�'�� �9� $���A�F�*�*��"�&�#�&�&� $��V�[��^��� rdry)r^r�s rbrr]s#��, � � � �d�A� � �rdc� ��d���fd�}|�t��s|S|�t��r|�t��}|}d}||kr|}|�d�|��}||k�|S)aQ Simplify expressions with KroneckerDelta. The only simplification currently attempted is to identify multiplicative cancellation: Examples ======== >>> from sympy import KroneckerDelta, kroneckersimp >>> from sympy.abc import i >>> kroneckersimp(1 + KroneckerDelta(0, i) * KroneckerDelta(1, i)) 1 c��td��D]|}td��D]j}||}||}||dzdz}||dzdz}t||��tjur t||��tjurdS�k�}dS)NrfrlTF)r-rr�true�false)�args1�args2�i1�i2�a1�a2�a3�a4s rb� args_cancelz"kroneckersimp.<locals>.args_cancel�s�����(�(� � �B��A�h�h� � ���2�Y���2�Y���B��F�a�<�(���B��F�a�<�(���b�"�:�:���'�'�B�r�2�J�J�!�'�,A�,A��4�4�4��  ��urdc���|j}d�|D��}t|d��D]0\}}|j}|j}�||��rtj|zcS�1|S)Nc�<�g|]}t|t���|��Sr�)rmr>r�s rbr�z?kroneckersimp.<locals>.cancel_kronecker_mul.<locals>.<listcomp>�s'��C�C�C��Z��>�%B�%B�C�!�C�C�Crdrf)rnrXrr)�mrn�deltas�delta1�delta2r�r�r�s �rb�cancel_kronecker_mulz+kroneckersimp.<locals>.cancel_kronecker_mul�sx����v��C�C�T�C�C�C��%�f�a�0�0� "� "�N�F�F��K�E��K�E��{�5�%�(�(� "��v��z�!�!�!� "��rdNc�,�t|t��Sr�)rmr )r�s rbr�zkroneckersimp.<locals>.<lambda>�s���A�s�);�);�rd)r�r>r4r�r�)r^r��newexprr�s @rbr r �s���� � � ������ �8�8�N� #� #��� � �x�x� ���,��|�|�N�+�+���G� �D� �T�/�/����,�,�;�;�=Q�R�R�� �T�/�/� �Krdc �� �d�}d�}d�}|}ttttzdz ��tt tzdz ��g}|�t|t|tt ��|����}|�t |t |t t��|����}dtttz��g}|�t|t|t��|����}|�t |t |t ��|����}t d��� � fd�}|�t|t����}|�t|t����}|�t |t ����}|�t|t����}d�}||��}||kr|� ��}|S) a@ Simplify bessel-type functions. Explanation =========== This routine tries to simplify bessel-type functions. Currently it only works on the Bessel J and I functions, however. It works by looking at all such functions in turn, and eliminating factors of "I" and "-1" (actually their polar equivalents) in front of the argument. Then, functions of half-integer order are rewritten using trigonometric functions and functions of integer order (> 1) are rewritten using functions of low order. Finally, if the expression was changed, compute factorization of the result with factor(). >>> from sympy import besselj, besseli, besselsimp, polar_lift, I, S >>> from sympy.abc import z, nu >>> besselsimp(besselj(nu, z*polar_lift(-1))) exp(I*pi*nu)*besselj(nu, z) >>> besselsimp(besseli(nu, z*polar_lift(-I))) exp(-I*pi*nu/2)*besselj(nu, z) >>> besselsimp(besseli(S(-1)/2, z)) sqrt(2)*cosh(z)/(sqrt(pi)*sqrt(z)) >>> besselsimp(z*besseli(0, z) + z*(besseli(2, z))/2 + besseli(1, z)) 3*z*besseli(0, z)/2 c�8����t�������fd�}|S)Nc�����tj|����r �||��S�||��Sr�)r�r r�)�nu�z�factors�fro�tos ���rb�replz*besselsimp.<locals>.replacer.<locals>.repl�sC����#�#�C�M�!�$4�$4�5�5� !��r�"�a�y�y� ��3�r�1�:�:� rd)r�)r�r�r�r�s``` rb�replacerzbesselsimp.<locals>.replacer�s:������g�,�,�� � � � � � � �� rdc������fd�}|S)Nc�B���||������Sr�)r�)r�r�r�r�s ��rb�tofuncz-besselsimp.<locals>.torewrite.<locals>.tofunc�s!����3�r�1�:�:�%�%�b�)�)� )rdr�)r�r�r�s`` rb� torewritezbesselsimp.<locals>.torewrite�s'���� *� *� *� *� *� *�� rdc����fd�}|S)Nc���tttz|z���|tt tz��|z��zSr�)r(rrr+)r�r�r�s �rbr�z+besselsimp.<locals>.tominus.<locals>.tofunc�s;����q��t�B�w�<�<���B� �1�"�R�%�(8�(8��(:� ;� ;�;� ;rdr�)r�r�s` rb�tominuszbesselsimp.<locals>.tominus�s!��� <� <� <� <� <�� rdrfr�r�c������fd�}|S)Nc ���|dztjkr�ttt �|����t ���t���d������ �|������S|j r&|dkr �||���d���S�||��S)NrlT)rr) r�Halfr�rSr.r�r9r=rr|� is_Integer)r�r�r��z0s ��rbr�z*besselsimp.<locals>.expander.<locals>.repl�s�����Q��1�6�!�!������B�� � �+�+�G�4�4�<�<�R�@�@�G�G�!%�H�'�'�*(�*(�(,��R�� � �!5�!5�6�6�6��� 4�2��6�6��s�2�q�z�z�(�(�d�(�3�3�3��3�r�1�:�:� rdr�)r�r�r�s` �rb�expanderzbesselsimp.<locals>.expander�s)���� � � � � � �� rdc��d�}|�t��r|t|��}|�t��r|t|��}|S)Nc��� |��fd���} t|d����D]{}|j\}}�|dz|��}�|dz|��}|�|��r<|�|��r'|�|d|dzz|z |z|z ��}n�||Sn#t t f$r|cYSwxYw��)NTc�$��t|���Sr�)rm)r��bessels �rbr�zTbesselsimp.<locals>._bessel_simp_recursion.<locals>._use_recursion.<locals>.<lambda>s���j��F�.C�.C�rdc�6�t|jd��S)Nr)r,rnr�s rbr�zTbesselsimp.<locals>._bessel_simp_recursion.<locals>._use_recursion.<locals>.<lambda>s��B�q�v�a�y�M�M�rdr�rlrf)�find�sortedrnr�r|r�� TypeError)r�r^�bessels�bar�r��bap1�bap2s` rb�_use_recursionzBbesselsimp.<locals>._bessel_simp_recursion.<locals>._use_recursion s��� ��)�)�$C�$C�$C�$C�D�D��  �$�W�2I�2I�J�J�J�$�$��!�w���1�%�v�a��c�1�~�~��%�v�a��c�1�~�~���8�8�D�>�>�"�d�h�h�t�n�n�"�#'�9�9�R��A�a�C����4��$�1F�#G�#G�D�!�E��#� �"��#�I�.� � � ��K�K�K� ���� s�BB-�-C�C)r�r9r<)r^r�s rb�_bessel_simp_recursionz*besselsimp.<locals>._bessel_simp_recursion sb�� � � � �8�8�G� � � 1�!�>�'�4�0�0�D� �8�8�G� � � 1�!�>�'�4�0�0�D�� rd) rr+rr�r9r:rr<r;rG) r^r�r�r�� orig_expr�ifactors� minusfactorsr�r�r�s @rbr r �s*���@������ ��� �I��9�Q�r�T�!�V�$�$�i���2��a��&8�&8�9�H� �<�<����'�� �'�7�#�#�X�/�/� 0� 0�D� �<�<����'�� �'�7�#�#�X�/�/� 0� 0�D�� �!�B�$���(�L� �<�<����'�7�7�7�#3�#3�\�B�B� D� D�D� �<�<����'�7�7�7�#3�#3�\�B�B� D� D�D� �s���B� � � � � � �<�<����'�!2�!2� 3� 3�D� �<�<����'�!2�!2� 3� 3�D� �<�<����'�!2�!2� 3� 3�D� �<�<����'�!2�!2� 3� 3�D����. "� !�$� '� '�D� �y����{�{�}�}�� �Krd��c�n�t|��}t|��}|td|��z}|js|St|��s|Sg}d�|jD��}|D]`\}}|js|cS|t jur�|jr!|j t j kr |j js|cS|� |���a|� ��|d|�}|dkrY|dzdkrP| td|��z}t||���} t| |z��t| ��kr| n|} | St||���} t| ��t|��ur2t| |z��t|��krt| ��St!|||��}|�|S|S)a" Compute a real nth-root of a sum of surds. Parameters ========== expr : sum of surds n : integer max_len : maximum number of surds passed as constants to ``nsimplify`` Algorithm ========= First ``nsimplify`` is used to get a candidate root; if it is not a root the minimal polynomial is computed; the answer is one of its roots. Examples ======== >>> from sympy.simplify.simplify import nthroot >>> from sympy import sqrt >>> nthroot(90 + 34*sqrt(7), 3) sqrt(7) + 3 rlc�6�g|]}|�����Sr�)rr?s rbr�znthroot.<locals>.<listcomp>Ls"��6�6�6�q�!�.�.�"�"�6�6�6rdNrrf)� constants)r r� is_integerrHrn� is_rationalrrrxr(r�ryr��sortrrr_) r^r�max_lenr[rZ�surds� coeff_mulsr��yr��ress rb�nthrootr�)s���6 �4�=�=�D��� � �A� �h�q�!�n�n��A� �<���� �� � ���� �E�6�6�D�I�6�6�6�J������1��}� ��H�H�H� ���:�:� ��� �Q�U�a�f�_�_���1B�_��H�H�H� � � �Q����� �J�J�L�L�L� �(�7�(�O�E� �a�x�x�A��E�Q�J�J��U�X�a��^�^� #�� �a�5� )� )� )���A�q�D�>�>�X�t�e�_�_�4�4�a�a�!���t� ��!�u�%�%�%�A���{�{�(�1�+�+�%�%�(�1�a�4�.�.�H�T�N�N�*J�*J���{�{�� �$��4� (� (�D� �|��� �Krdr��base10c�h��� ��� tt|����S#ttf$rYnwxYwt|���t d��t jt d��t ji��}|t jus|t jur|S|s|j rt|�|��S��9dtdgd�|� t ��D��z�� z�d�t�dz��� i�|D]a}t|��}|����}|jstd ���|�� ���t#|��<�b|��d � ��}|���\} } | jr| js|S� ����fd �} | r | | ��} | r | | ��} n'#t$r|�t||� ��cYS|cYSwxYw| | t jzz} | |ks|dur| St||� ��S)a  Find a simple representation for a number or, if there are free symbols or if ``rational=True``, then replace Floats with their Rational equivalents. If no change is made and rational is not False then Floats will at least be converted to Rationals. Explanation =========== For numerical expressions, a simple formula that numerically matches the given numerical expression is sought (and the input should be possible to evalf to a precision of at least 30 digits). Optionally, a list of (rationally independent) constants to include in the formula may be given. A lower tolerance may be set to find less exact matches. If no tolerance is given then the least precise value will set the tolerance (e.g. Floats default to 15 digits of precision, so would be tolerance=10**-15). With ``full=True``, a more extensive search is performed (this is useful to find simpler numbers when the tolerance is set low). When converting to rational, if rational_conversion='base10' (the default), then convert floats to rationals using their base-10 (string) representation. When rational_conversion='exact' it uses the exact, base-2 representation. Examples ======== >>> from sympy import nsimplify, sqrt, GoldenRatio, exp, I, pi >>> nsimplify(4/(1+sqrt(5)), [GoldenRatio]) -2 + 2*GoldenRatio >>> nsimplify((1/(exp(3*pi*I/5)+1))) 1/2 - I*sqrt(sqrt(5)/10 + 1/4) >>> nsimplify(I**I, [pi]) exp(-pi/2) >>> nsimplify(pi, tolerance=0.01) 22/7 >>> nsimplify(0.333333333333333, rational=True, rational_conversion='exact') 6004799503160655/18014398509481984 >>> nsimplify(0.333333333333333, rational=True) 1/3 See Also ======== sympy.core.function.nfloat �infz-infNrWr�c�`�g|]+}tjj�|j����,Sr�)�mpmath�libmp�libmpf� prec_to_dps�_prec)r�rs rbr�znsimplify.<locals>.<listcomp>�s=��)�)�)���l�!�-�-�a�g�6�6�)�)�)rd�g�p= ף @zconstants must be real-valuedT)�chopc���tjj}|����} � ss�sqdtj_tj|dg��}|�Ht t |d�� t |d����|tj_S� tj_tj|�� ����}|st��r|d}t|��}|r |st�|j dur!|tj tj fvrt�||tj_S#|tj_wxYw)Nr�rlr)r��tol�fullF) r��mp�dps� _to_mpmath�pslqr�int�identifyr�r � is_finiter��ninf) r��orig�xv�ratr�r^�bprec�constants_dictr�r[� tolerances �����rb�nsimplify_realz!nsimplify.<locals>.nsimplify_real�s8����y�}�� �\�\�%� � �� !�� ?�� ?� "�� � ��k�2�q�'�*�*���?�#�S��Q��[�[�L�#�c�!�f�+�+�>�>�"!�F�I�M�M�!!�F�I�M��o�b�N��D�*�*�*�G�� !� � �� %�!�!�*���7�#�#�D�� !�� !� � ��~��&�&�2�f�j�&�+�5N�+N�+N� � ��!�F�I�M�M��D�F�I�M� � � � s�A#D1�BD1�1E)�rational_conversionF)r rZr�r�r rrr��NegativeInfinityru�_real_to_rationalr�r�r��evalf�is_Floatr��str� as_real_imagr�� ImaginaryUnit)r^r�r�r�r�r�rEr��exprvalr,�imr�r�r�r�r[s `` @@@rbrres��������l ��v�d�|�|�$�$�$�� �z� "� � � � �� ���� �4�=�=� !� !� �e� � �a�j� �f� � �q�)�# � � �D� �q�z���T�Q�%7�7�7�� ��G�4�$�G� ��y�2E�F�F�F� ����b�T�)�)��j�j��'�'�)�)�)�)�*�*�*�*� � �D� ��T� �N�N�E��N��<�<���8�$�$�� �N�N�4� � ���z� >��<�=�=� =�()� � �U�(;�(;��s�8�}�}�%�%��j�j��D�j�)�)�G� � !� !� #� #�F�B�� �L��R�\��� �!�!�!�!�!�!�!�!�!�6� � $����#�#�B� � $����#�#�B��� ���� � �$�T�?R�S�S�S� S� S� S�� � � ����� �b��� � �B� �T�z�z�X��&�&�� � �T�7J� K� K� K�Ks$�#�7�7�G�H�=H�Hc ��t|��}td��}|}i}d}|�|dkrtd|z ��}|�t��D�]�}|}|�$t |���|��} �n�|�S|dkrM|jdurDt |t||z ��z���t|����} �n[|dkrt |��} | ||<��|dkrtd���t|d���} |r| st |��} �n| j s�||| fvr tj } n�|d krk| }td ttj|��tjd ��z ����} t t#|| z ���� | z} ny|d krgtd ttj|��tjd ��z ����} t t#|| z ����| z} n tj} | ||<���|�|d � ��S) a) Replace all reals in expr with rationals. Examples ======== >>> from sympy.simplify.simplify import _real_to_rational >>> from sympy.abc import x >>> _real_to_rational(.76 + .1*x**.5) sqrt(x)/10 + 19/25 If rational_conversion='base10', this uses the base-10 string. If rational_conversion='exact', the exact, base-2 representation is used. >>> _real_to_rational(0.333333333333333, rational_conversion='exact') 6004799503160655/18014398509481984 >>> _real_to_rational(0.333333333333333) 1/3 r�NrlF�exactr�z/rational_conversion must be 'base10' or 'exact'r�rrWTr�)r$rr3r�r�limit_denominatorr��roundr�r�rrmr�ComplexInfinityr r�r*r�rr|) r^r�r�r�rZr�� reduce_num�flr�r�rs rbr�r��sF��, �D�>�>�D� ��,�,�C� �A� �D��J����Q����Q�y�[�)�)� ��g�g�e�n�n� � ���� � !��� � �.�.�z�:�:�A�A��#� �Q���� ��&�&���5��I��#6�#6�6���#�#�C� �N�N�3�3� �A�#�g�-�-��R�L�L����S� ��$��0�0� �!R�S�S�S��"�u�-�-�-�A�� �!� ��R�L�L����]� ��#��t��$�$��)�A�A��!�V�V���B��B��F�J�r�N�N�6�:�b�>�>�$A� B� B�C�C�A�!�#�b��d�)�)�,�,�,�Q�.�A�A��!�V�V��B��F�J�r�N�N�6�:�b�>�>�$A� B� B�C�C�A� ��R��T���+�+�A�-�A�A���A���S� � � �6�6�$�T�6� *� *�*rdc��d}|j}|jrtj||z fS|ro||kri|}|r|���n"t |���d���\}}||z}|�d���\}}||z}|r||k�it|d���}|� ��r| }| }||fS)ahReturn `p, r` where `p` is the expression obtained when Rational additive and multiplicative coefficients of `expr` have been stripped away in a naive fashion (i.e. without simplification). The operations needed to remove the coefficients will be applied to `rhs` and returned as `r`. Examples ======== >>> from sympy.simplify.simplify import clear_coefficients >>> from sympy.abc import x, y >>> from sympy import Dummy >>> expr = 4*y*(6*x + 3) >>> clear_coefficients(expr - 2) (y*(2*x + 1), 1/6) When solving 2 or more expressions like `expr = a`, `expr = b`, etc..., it is advantageous to provide a Dummy symbol for `rhs` and simply replace it with `a`, `b`, etc... in `r`. >>> rhs = Dummy('rhs') >>> clear_coefficients(expr, rhs) (y*(2*x + 1), _rhs/12) >>> _[1].subs(rhs, 2) 1/6 NTr�Fr�) rurmrrrrr� as_coeff_Addr�r�)r^�rhs�was�freer�r�s rb�clear_coefficientsr�1s��6 �C� � �D� ��$����d� �#�#� ��3�$�;�;���� ;�D� %� %� '� '� '� �� � � +� +�T� +� :� :� ��4� �q����#�#�T�#�2�2���4� �q��� ��3�$�;�;� �D�U� +� +� +�D� �$�$�&�&���u���d�� ��9�rdc�Z��"�#�$�%�t|t��r6|�d���}ttt t f\�"�#�$}nttttf\�"�#�$}d�}�#�$fd�}�"�#�$�%fd��%�%fd�}t|�"�#�$f��r|j r|S|j dd�}t|�$��r;�r7�$t|d��|d �����S|St|�"��r#�"�fd �|D������S|���\}}t|�}t|d ��s|t||z �� ��zS||��\} }d} | t!|��d z krd } d�|ddd�D��}�rt#d�|D����}||��} i} d } d }d}d}t%d t!|����D�]�}d}d}d}|t!|��d z kr| |d}|}|d z}|t!|��d z ks|dgkr�t||�$��r�t||j d|��sc||j dj }t!|��}|||z |�|kr |d z }||z}||d z|d z|z�|kr |d z }||z }|r|||j d z }n#��|d}||d z z}|||�}d }||z }|| vr| ||kr��9|t!|��kr�|| |d z dvr |d z }||z }nOt||�$��r8||j dj |kr|||j d z }|d z }nn|t!|��k��d}d }||z dkr�|||z d z|�|d d�kr�t|d�$��r'|dj d}|dj d }n |d}d }t|||z �$��r>|||z j d|kr$|||z j d |z }||z}|d z }n|||z |krd |z }||z}|d z }d}d }||zd z t!|��kr�||||zd z �|dd�kr�t|d�$��r'|dj d}|dj d }n |d}d }t|||zd z �$��rD|||zd z j d|kr'|||zd z j d |z }||z }|d z }n!|||zd z |krd |z }||z }|d z }|r�|d zdkr�|dkr�|d z }d }d }t||d z �$��r9||d z j d|kr||z}||d z j d |z }n||d z |kr ||z}d |z }|dks|dkr%|s|d z}|}|}|}||zf|dd�z||zfz}|||z z }|r|d z}|r|d z}|| |<||kr|}|�#|�|||f}||z}||z} ���|r��$t|d �� ��|d ��}t�#|d|d��|z�� ��}| t�#||dd���� ��z} ||z| z}|d ks| d krt|d� ��}n�#|�}| r �$|d��}t|t��s3t'|��} | |krt| �� ��}!|||!��}n|�d���}|S)a� Simplify a non-commutative expression composed of multiplication and raising to a power by grouping repeated subterms into one power. Priority is given to simplifications that give the fewest number of arguments in the end (for example, in a*b*a*b*c*a*b*c simplifying to (a*b)**2*c*a*b*c gives 5 arguments while a*b*(a*b*c)**2 has 3). If ``expr`` is a sum of such terms, the sum of the simplified terms is returned. Keyword argument ``deep`` controls whether or not subexpressions nested deeper inside the main expression are simplified. See examples below. Setting `deep` to `False` can save time on nested expressions that do not need simplifying on all levels. Examples ======== >>> from sympy import symbols >>> from sympy.simplify.simplify import nc_simplify >>> a, b, c = symbols("a b c", commutative=False) >>> nc_simplify(a*b*a*b*c*a*b*c) a*b*(a*b*c)**2 >>> expr = a**2*b*a**4*b*a**4 >>> nc_simplify(expr) a**2*(b*a**4)**2 >>> nc_simplify(a*b*a*b*c**2*(a*b)**2*c**2) ((a*b)**2*c**2)**2 >>> nc_simplify(a*b*a*b + 2*a*c*a**2*c*a**2*c*a) (a*b)**2 + 2*(a*c*a)**3 >>> nc_simplify(b**-1*a**-1*(a*b)**2) a*b >>> nc_simplify(a**-1*b**-1*c*a) (b*a)**(-1)*c*a >>> expr = (a*b*a*b)**2*a*c*a*c >>> nc_simplify(expr) (a*b)**4*(a*c)**2 >>> nc_simplify(expr, deep=False) (a*b*a*b)**2*(a*c)**2 F)� inv_expandc�����fd��dd�D��g}tdt�����D]�}g}d}tt���|z dz ��D]�}g}||dz |dzD]Q}||zdz|zt���kr3�|�||zdz|zkr|�|dz���R|dgz }|�|����|�|����|S)Nc�6��g|]}|�dkrddgndg��S)rrlr�)r�r�rns �rbr�z2nc_simplify.<locals>._overlaps.<locals>.<listcomp>�s/��� B� B� B�A��d�1�g����1�v�v�A�3� B� B� Brdrlr)r-rtr�)rnr�r��overlapsr2�overlapr�s` rb� _overlapsznc_simplify.<locals>._overlaps�s)���C� B� B� B��a�b�b�� B� B� B� C���q�#�d�)�)�$�$� � �A��H��A��3�t�9�9�q�=�1�,�-�-� )� )�����1�Q�3���!���.�.�A��1�u�q�y�1�}�s�4�y�y�0�0�T�!�W��Q�q�S��U�1�W� �5M�5M����q�1�u�-�-�-���A�3�������(�(�(�(� �H�H�X� � � � ��rdc�6��d}g}g}|D]�}t|���r!|jdjr|dzg|z}|dz }�3t|��dkr|�|ddz��nJt|��dkr7|���|�d����|t|��dz z}g}|�|����|r7|���|�d����|t|��dz z}|t |��fS)Nrrlr�)rmrn�is_extended_negativertr�rn)�_args�inv_tot�inversesrnr��_Mul�_Pows ��rb�_reduce_inversesz%nc_simplify.<locals>._reduce_inverses�sD��� ������� !� !�C��#�t�$�$� !���!��)I� !���G�9�x�/���1� ����x�=�=�A�%�%��K�K��� �R��0�0�0�0���]�]�Q�&�&��K�K���T�T�8�_�b� 9� 9�:�:�:��s�8�}�}�q�0�0�G���� � �C� � � � � � )� �K�K���T�T�8�_�b�1�1� 2� 2� 2� �s�8�}�}�q�(� (�G���d� � �#�#rdc���t|���r�|jd��St|��f��r t�fd�|jD����SdS)Nrc3�.�K�|]}�|��V��dSr�r�)r�r�� get_scores �rbr�z1nc_simplify.<locals>.get_score.<locals>.<genexpr>�s+�����4�4��y�y��|�|�4�4�4�4�4�4rdrl)rmrn�sum)r��_Addr r rs ����rbrznc_simplify.<locals>.get_score�sm��� �a�� � � 5��9�Q�V�A�Y�'�'� '� ��D�$�<� (� (� 5��4�4�4�4�Q�V�4�4�4�4�4� 4��qrdc�H��||kr�|���|��kr|S|Sr�r�)r��alt_srs �rb�compareznc_simplify.<locals>.compare�s4��� ��:�:�)�)�E�*�*�Y�Y�q�\�\�9�9��L��rdNrrlc�2��g|]}t|������S)r��r)r�r�r�s �rbr�znc_simplify.<locals>.<listcomp>�s&���>�>�>�A�k�!�$�/�/�/�>�>�>rdr�rfTc��g|]}|dz��S)r�r�r�s rbr�znc_simplify.<locals>.<listcomp>�s��*�*�*�!��2��*�*�*rdr�c3�4K�|]}t|��V��dSr�rr�s rbr�znc_simplify.<locals>.<genexpr>�s(����2�2��[��^�^�2�2�2�2�2�2rd�)rmr@r�rArBrCrDrr r r r�rnrr~r rtrnr-r)&r^r��_Symbolrr rrn�c_args� com_coeffr �invertr��simps�post�pre�max_simp_coeff�simpr�� simp_coeffrgrZ�rep�start�end�subterm�pre_exp�pre_argr(�post_exp�post_arg�_pre_exp� _post_exp�f_expr�alt_simprr r rs& ` @@@@rbrr_s� �������R�$� �#�#�:��y�y�E�y�*�*��$*�F�F�L�$H�!��d�D�'�'�$'��c�6�$9�!��d�D�'����0$�$�$�$�$�$�4������������� �d�T�4��.� /� /��4�3F��� � �9�Q�Q�Q�<�D��$���� D� � ��4� �D��G�,�,�d�1�g�6�6�;�;�=�=� =��K� �D�$� � �D��t�>�>�>�>��>�>�>�?�D�D�F�F�F��}�}��� �����L� ��I�q�)�)� D��[��i��d�C�C�C�C� C�$�$�T�*�*�M�G�T��F���T���1������*�*�t�D�D�b�D�z�*�*�*�� �3��2�2�T�2�2�2�2�2��� �$���A� �E� �D� �C��N� �D� �1�c�$�i�i� � �F&�F&��� � �� �� �s�4�y�y�1�}� � ��A�$�q�'�C�����c�� ��D� � �!� � � �s�q�c�z�z��4��7�D�)�)� � *�4��7�<��?�G� D� D� ��q�'�,�q�/�.����L�L����!��A��;�'�)�)���F�A��Q�J�E���!��A�a�C��E� �?�g�-�-���F�A��1�H�C�� ��T�!�W�\�!�_�$�����A��A� �Q��U�N�E��5��9�o�G��A� �1�H�C� �e� � ��g��%� 7� 7� ��C��I�I�o�o��A�c�!�e�H�Q�K����Q����q�����D��I�t�,�,� ��c����1B�1G�7�1R�1R��T�#�Y�^�A�&�&���q������C��I�I�o�o����� �1�9��>�>�d�5��7�1�9�U�?�3�w�q�r�r�{�B�B��'�!�*�d�+�+� �!�!�*�/�!�,���a�j�o�a�(���!�!�*�����$�u�Q�w�-��.�.� �4��a��=�3E�a�3H�G�3S�3S��u�Q�w�-�,�Q�/�#�5���� ���Q�����e�A�g��'�)�)��c�'���� ���Q������� ��7�Q�;��T��� "� "�t�C��A��a��K�'8�G�C�R�C�L�'H�'H��'�"�+�t�,�,� �"�2�;�+�A�.���b�k�&�q�)���"�2�;�����$�s�1�u�Q�w�-��.�.� �4��A��a��=�3E�a�3H�H�3T�3T���A��a��=�-�a�0�3�6���q����Q�����c�!�e�A�g��(�*�*��s�7���q����Q��� � M��a��1� � ������a�%�C��H��I��$�u�Q�w�-��.�.� #�4��a��=�3E�a�3H�H�3T�3T�$�s�N� ���a��=�-�a�0�3�6����e�A�g��(�*�*�$�s�N� ��s�7���1�}�}� �Q������Q�J�E�$��"��"��#�S�=�*�W�S�b�S�\�9�X�s�]�<L�L���c�%�i�� � � � �!�O�J� � � �!�O�J���g�� �� &� &�'�N��4�4��>�1�c�1�5�D��7�"�C��X�%�D�� � ��$�{�4��7��6�6�6��Q��@�@���$�$��X�d�1�g�X��/��3�$�?�?�?���K���d�4��7�8�8�n� 5�D�A�A�A�A���7�{�4��� �!�8�8�t�q�y�y��t�%�0�0�0�D���t�T�{�� ���t�D�"�~�~�� �d�J� '� '�+��4���� �T�>�>�"�6��5�5�5�H��7�4��*�*�D���y�y�E�y�*�*�� �Krdc �� �d�}� fd�� d}t|t���r�|js|js|j�r�|�dddddddd���}||kr|}d}||��\}}|dkrr|roi}� ||��}||us||��ddkrHt |��}||kr3|�d �|���D����}d}n�|d kr�|jr�|j djr�|j d jr�|j dj d jr�|j d j d jr}|j dj d j tj urT|j d j d j tj ur+t|��}||��d} | |kr|}d}nd}|r||fn|S) a�Simplification for a sum of products targeted at the kind of blowup that occurs during summation of products. Intended to reduce expression blowup during matrix multiplication or other similar operations. Only works with algebraic expressions and does not recurse into non. Parameters ========== withsimp : bool, optional Specifies whether a flag should be returned along with the expression to indicate roughly whether simplification was successful. It is used in ``MatrixArithmetic._eval_pow_by_recursion`` to avoid attempting to simplify an expression repetitively which does not simplify. c�~�d}|g}d}|�r0|���}t|t��s�-|jrD|tjur4|t |jdk��t |jdk��zz }�n�|j �r|� ��r<|dz }|j dtj ur|� ��d}n| }t|��\}}|jr0|dt |dk��zz }|�|���n|tjur9|js|�|��d}|dz }|�|��n�|t#|j ��dz z }|�|j ��n�|jr^t#|j ��}d}|j D]3} | � ��r|dz }| } |�| ���4||||kz z }n6|jr/|dz }|�|j��|s|jjdu}|��0||fS)ajOptimized count algebraic operations with no recursion into non-algebraic args that ``core.function.count_ops`` does. Also returns whether rational functions may be present according to negative exponents of powers or non-number fractions. Returns ======= ops, ratfunc : int, bool ``ops`` is the number of algebraic operations starting at the top level expression (not recursing into non-alg children). ``ratfunc`` specifies whether the expression MAY contain rational functions which ``cancel`` MIGHT optimize. rFrlT)r�rmrrmrr�boolrZ�qror�rnr�� as_two_termsrPr�r�rt�extendr}rxryr(� is_negative) r^�opsrn�ratfuncr�rr�laargs�negsrts rb� count_ops_algz"dotprodsimp.<locals>.count_ops_alg�sU�� ���&�����5 =���� � �A��a��'�'� ���}�/ =��A�E�>�>��4���q��>�>�D�!�#��(�O�O�;�;�C����+ =��-�-�/�/���1�H�C��v�a�y�A�M�1�1��N�N�,�,�Q�/����B����{�{���1��<�(��1�t�Q��U�|�|�+�+�C��K�K��N�N�N�N��a�e�^�^��<�%�� � �A���� $���1�H�C��K�K��N�N�N�N��3�q�v�;�;��?�*�C��K�K���'�'�'�'��� =��Q�V�������&�$�$�B��2�2�4�4�$��� ��!#����K�K��O�O�O�O��v����0�0����� =��q���� � �A�F�#�#�#��=��e�/�u�<�G�k�5 =�n�G�|�rdc�0��|js|S|js|js|jrVd}t |j��D]1\}}�||��}||ur�|�t |j��}|||<�2|�|S|j|�S|�|t����S)z�Substitute dummy variables for non-algebraic expressions to avoid evaluation of non-algebraic terms that ``polys.polytools.cancel`` does. N) rnr}rorxrwrvrr� setdefaultr)r^�dummiesrnr�r�r��nonalg_subs_dummiess �rbr@z(dotprodsimp.<locals>.nonalg_subs_dummiess���� �y� ��K� �;� $�$�+� $��� $��D�!�$�)�,�,� � ���1�'�'��7�3�3����6�6���<��� �?�?�D���Q����|�� ��4�9�d�#� #��!�!�$����0�0�0rdFTN)r��modulus� power_base� power_exprhr*rir��rc��g|] \}}||f�� Sr�r�)r�r�rs rbr�zdotprodsimp.<locals>.<listcomp>6s ��0T�0T�0T�D�A�q�!�Q��0T�0T�0Trd�rlr�)rmrr}rorxrrFr|r�rnr(rr�rE) r^�withsimpr<� simplifiedr�expropsr9r?�expr3�expr2opsr@s @rb� dotprodsimprL�s3��� K�K�K�Z1�1�1�1�1�:�J��$����%�D�K�%�4�;�%�$�+�%�� � ��t����5�d�%��Q�Q�� �D�=�=��D��J�(�=��.�.���� �a�<�<�� *���-�-�d�G�<�<���D�=�=�M�M�%�$8�$8��$;�q�$@�$@�"�5�M�M�E���~�~�%*�Z�Z�0T�0T�G�M�M�O�O�0T�0T�0T�%U�%U��%)� ����l�l�t�{�l�t�y�!�}�/C�l�� �1� �$��)-��A��);�R�)@�)G��� �1� �"�B�'�.��� �1� �"�B�'�+�q�}�<�<�� �1� �"�B�'�+�q�}�<�<�����E�$�}�U�+�+�A�.�H��'�!�!�"��!� ���J�!)� 3�D�*� � �t�3rdz� Using bottom_up from the sympy.simplify.simplify submodule is deprecated. Instead, use bottom_up from the top-level sympy namespace, like sympy.bottom_up z1.10z$deprecated-traversal-functions-moved)�deprecated_since_version�active_deprecations_targetz� Using walk from the sympy.simplify.simplify submodule is deprecated. Instead, use walk from sympy.core.traversal.walk r�)NFFFTrl)F)r�r�)r�NFNr�)Nr�)T)�� collectionsr�sympy.concrete.productsr�sympy.concrete.summationsr� sympy.corerrrr r r r r rrrrrr�sympy.core.exprtoolsr�sympy.core.parametersr�sympy.core.functionrrrrrr�sympy.core.numbersrrrrr �sympy.core.relationalr!�sympy.core.rulesr"�sympy.core.sortingr#�sympy.core.sympifyr$�sympy.core.traversalr%rr&�_walk�sympy.functionsr'r(r)r*r+r,�(sympy.functions.combinatorial.factorialsr-�$sympy.functions.elementary.complexesr.r/r0�&sympy.functions.elementary.exponentialr1�%sympy.functions.elementary.hyperbolicr2�#sympy.functions.elementary.integersr3�$sympy.functions.elementary.piecewiser4r5r6�(sympy.functions.elementary.trigonometricr7�sympy.functions.special.besselr8r9r:r;r<r=�(sympy.functions.special.tensor_functionsr>�sympy.integrals.integralsr?�sympy.matrices.expressionsr@rArBrCrD� sympy.polysrErFrG� sympy.polys.numberfields.minpolyrHrI�sympy.simplify.combsimprJ�sympy.simplify.cse_optsrKrL�sympy.simplify.hyperexpandrM�sympy.simplify.powsimprN�sympy.simplify.radsimprOrPrQ�sympy.simplify.sqrtdenestrR�sympy.simplify.trigsimprSrT�sympy.utilities.decoratorrU�sympy.utilities.iterablesrVrWrXrY�sympy.utilities.miscrZr�rcr]r\r{r�r�r�r�r r$r;r.rrNr_r rr r r�rr�rr�rrLr�rdrb�<module>rus:��#�#�#�#�#�#�+�+�+�+�+�+�)�)�)�)�)�)�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�+�*�*�*�*�*�3�3�3�3�3�3� � � � � � � � � � � � � � � � �C�C�C�C�C�C�C�C�C�C�C�C�C�C�,�,�,�,�,�,�&�&�&�&�&�&�&�&�&�&�&�&�'�'�'�'�'�'�G�G�G�G�G�G�G�G�@�@�@�@�@�@�@�@�@�@�@�@�@�@�@�@�J�J�J�J�J�J�F�F�F�F�F�F�F�F�F�F�:�:�:�:�:�:�D�D�D�D�D�D�7�7�7�7�7�7�F�F�F�F�F�F�F�F�F�F�J�J�J�J�J�J�B�B�B�B�B�B�B�B�B�B�B�B�B�B�B�B�C�C�C�C�C�C�.�.�.�.�.�.�B�B�B�B�B�B�B�B�B�B�B�B�B�B�0�0�0�0�0�0�0�0�0�0�R�R�R�R�R�R�R�R�,�,�,�,�,�,�5�5�5�5�5�5�5�5�2�2�2�2�2�2�*�*�*�*�*�*�A�A�A�A�A�A�A�A�A�A�0�0�0�0�0�0�9�9�9�9�9�9�9�9�0�0�0�0�0�0�J�J�J�J�J�J�J�J�J�J�J�J�'�'�'�'�'�'� � � � � "��U�G*�G*�G*�G*�T=�=�=�@���@:/�:/�:/�z,�,�,�^%�%�%�,D �D �D �D �N�i�%��UY�T�T�T�T�n ���6���6(�(�(�(�2)�)�)�)�X#�#�#�L����2���0M�M�M�M�`#�#�#�L0�0�0�fp�p�p�f9�9�9�9�xHL� �HL�HL�HL�HL�V>+�>+�>+�>+�B"#��,�,�,�,�\E�E�E�E�P c4�c4�c4�c4�L �J�J��$�E� � � � � � � � �z�z�� $�E� � � ��  �  ���rd
Memory