� ��g�,���dZddlmZddlmZddlmZddlmZm Z m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZmZmZd �Zd �Zdd�Zd�Zd�ZdS)zAThis module implements tools for integrating rational functions. �)�Lambda)�I)�S)�Dummy�Symbol�symbols)�log)�atan)�roots)�cancel)�RootSum)�Poly� resultant�ZZc �l�t|t��r|\}}n|���\}}t||dd���t||dd���}}|�|��\}}}|�|��\}}|�|�����}|jr||zSt|||��\}} | ���\} } t| |��} t| |��} | �| ��\}} |||�|�����zz }| j�s�|� dd��} t| t��st| ��}n| � ��}t| | ||��}|� d��}|�nt|t��r/|\}}|���|���z}n|���}||hz D] }|jsd}n�d}t"j}|se|D]a\} }| ���\}} |t)|t+||t-| �����z��d���z }�bn~|D]{\} }| ���\}} t/| |||��}|�||z }�6|t)|t+||t-| �����z��d���z }�|||z }||zS) aa Performs indefinite integration of rational functions. Explanation =========== Given a field :math:`K` and a rational function :math:`f = p/q`, where :math:`p` and :math:`q` are polynomials in :math:`K[x]`, returns a function :math:`g` such that :math:`f = g'`. Examples ======== >>> from sympy.integrals.rationaltools import ratint >>> from sympy.abc import x >>> ratint(36/(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2), x) (12*x + 6)/(x**2 - 1) + 4*log(x - 2) - 4*log(x + 1) References ========== .. [1] M. Bronstein, Symbolic Integration I: Transcendental Functions, Second Edition, Springer-Verlag, 2005, pp. 35-70 See Also ======== sympy.integrals.integrals.Integral.doit sympy.integrals.rationaltools.ratint_logpart sympy.integrals.rationaltools.ratint_ratpart FT)� composite�field�symbol�t�realN)� quadratic)� isinstance�tuple�as_numer_denomrr �div� integrate�as_expr�is_zero�ratint_ratpart�getrr�as_dummy�ratint_logpart�atoms�is_extended_realr�Zero� primitiver rr � log_to_real)�f�x�flags�p�q�coeff�poly�result�g�h�P�Q�rrr�Lrr#�elt�eps�_�Rs �m/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/integrals/rationaltools.py�ratintr;sP��D�!�U���"����1�1����!�!���1� ��1��T� 2� 2� 2�D��A��VZ�4[�4[�4[�q�A��(�(�1�+�+�K�E�1�a��e�e�A�h�h�G�D�!� �^�^�A� � � &� &� (� (�F��y���V�|�� �!�Q�� "� "�D�A�q� � � � � �D�A�q� �Q�� � �A� �Q�� � �A� �5�5��8�8�D�A�q� �a�!�+�+�a�.�.�(�(�*�*�*�*�F� �9�,����8�S�)�)���&�&�)�)� "��f� � �A�A����!�!�A� �1�a��A� &� &���y�y�� � �� �<��!�U�#�#� "����1���� � �A�G�G�I�I�-������ � ����s�{� � ���+�� �D��E�����f��� J�� F� F���1��{�{�}�}���1��w��v�a��3�q�y�y�{�{�#3�#3�!3�4�4��F�F�F�F��� F� � J� J���1��{�{�}�}���1���1�a��+�+���=��1�H�C�C��7��6�!�Q�s�1�9�9�;�;�'7�'7�%7�8�8�D�J�J�J�J�C�C� �#� �� ��<��c�����ddlm}t||��}t||��}|�|�����\}}}|����|�����fd�t d���D��}�fd�t d���D��}||z} t||t| ���} t||t| ���} || ���|zz | |���|z�|��zz| |zz } || � ��| ��} | � ��� | ��} | � ��� | ��} t| |� ��z |��}t| |� ��z |��}||fS)a� Horowitz-Ostrogradsky algorithm. Explanation =========== Given a field K and polynomials f and g in K[x], such that f and g are coprime and deg(f) < deg(g), returns fractions A and B in K(x), such that f/g = A' + B and B has square-free denominator. Examples ======== >>> from sympy.integrals.rationaltools import ratint_ratpart >>> from sympy.abc import x, y >>> from sympy import Poly >>> ratint_ratpart(Poly(1, x, domain='ZZ'), ... Poly(x + 1, x, domain='ZZ'), x) (0, 1/(x + 1)) >>> ratint_ratpart(Poly(1, x, domain='EX'), ... Poly(x**2 + y**2, x, domain='EX'), x) (0, 1/(x**2 + y**2)) >>> ratint_ratpart(Poly(36, x, domain='ZZ'), ... Poly(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2, x, domain='ZZ'), x) ((12*x + 6)/(x**2 - 1), 12/(x**2 - x - 2)) See Also ======== ratint, ratint_logpart r)�solvec �T��g|]$}tdt�|z ��z����%S)�a�r�str)�.0�i�ns �r:� <listcomp>z"ratint_ratpart.<locals>.<listcomp>��0���?�?�?�Q��s�S��Q��Z�Z�'�(�(�?�?�?r<c �T��g|]$}tdt�|z ��z����%S)�brA)rCrD�ms �r:rFz"ratint_ratpart.<locals>.<listcomp>�rGr<)�domain) �sympy.solvers.solversr>r� cofactors�diff�degree�ranger�quo�coeffsr�subsr )r(r0r)r>�u�vr8�A_coeffs�B_coeffs�C_coeffs�A�B�Hr/�rat_part�log_partrJrEs @@r:rr|s�����@,�+�+�+�+�+� �Q�� � �A� �Q�� � �A��k�k�!�&�&�(�(�#�#�G�A�q�!� ��� � �A� ��� � �A�?�?�?�?�%��1�+�+�?�?�?�H�?�?�?�?�%��1�+�+�?�?�?�H��(�"�H� �X�q��H��.�.�.�A� �X�q��H��.�.�.�A� �A�F�F�H�H�Q�J���A�F�F�H�H�Q�J�+�+�A�.�.�.�.��1��4�A� �U�1�8�8�:�:�x� (� (�F� � � � � ���� � �A� � � � � ���� � �A��a�� � � � �m�Q�'�'�H��a�� � � � �m�Q�'�'�H� �X� �r<Nc �x�t||��t||��}}|ptd��}|||���t||��zz }}t||d���\}}t||d���}|sJd|�d|�d����ig} }|D]} | || ���<�d �} |���\} } | | | ��| D�]�\}}|���\}}|���|kr| �||f���M||}t|���|d� ��}|�d� ��\}}| ||��|D]>\}}|� t|� |��|z|����}�?|� |��tj g}}|���d d �D][}|�|j��}||z�|��}|�|������\tt't)t+|���|������|��}| �||f�����| S)an Lazard-Rioboo-Trager algorithm. Explanation =========== Given a field K and polynomials f and g in K[x], such that f and g are coprime, deg(f) < deg(g) and g is square-free, returns a list of tuples (s_i, q_i) of polynomials, for i = 1..n, such that s_i in K[t, x] and q_i in K[t], and:: ___ ___ d f d \ ` \ ` -- - = -- ) ) a log(s_i(a, x)) dx g dx /__, /__, i=1..n a | q_i(a) = 0 Examples ======== >>> from sympy.integrals.rationaltools import ratint_logpart >>> from sympy.abc import x >>> from sympy import Poly >>> ratint_logpart(Poly(1, x, domain='ZZ'), ... Poly(x**2 + x + 1, x, domain='ZZ'), x) [(Poly(x + 3*_t/2 + 1/2, x, domain='QQ[_t]'), ...Poly(3*_t**2 + 1, _t, domain='ZZ'))] >>> ratint_logpart(Poly(12, x, domain='ZZ'), ... Poly(x**2 - x - 2, x, domain='ZZ'), x) [(Poly(x - 3*_t/8 - 1/2, x, domain='QQ[_t]'), ...Poly(-_t**2 + 16, _t, domain='ZZ'))] See Also ======== ratint, ratint_ratpart rT)� includePRSF)rzBUG: resultant(z, z) cannot be zeroc��|jr;|dkdkr3|d\}}|�|j��}||z|f|d<dSdSdS)NrT)r$�as_poly�gens)�c�sqfr1�k�c_polys r:� _include_signz%ratint_logpart.<locals>._include_sign�s\�� � � !�1�q�5�T�/�/��q�6�D�A�q��Y�Y�q�v�&�&�F��v�X�q�[�C��F�F�F� !� !�/�/r<)r)�all�N)rrrNrrO�sqf_listr&�append�LCrQ�gcd�invertr�OnerRrarb�remr�dict�list�zip�monoms)r(r0r)rr@rI�resr9�R_mapr[r4rg�C�res_sqfr,rDr8r1�h_lcrc�h_lc_sqf�j�invrRr-�Ts r:r"r"�s���L ��1�:�:�t�A�q�z�z�q�A� ��U�3�Z�Z�A� �a�!�&�&�(�(�4��1�:�:�%�%�q�A� �q�!�� -� -� -�F�C�� �s�A�� '� '� '�C� �@�@�@�1�1�1�a�a�a�@�@�@�3��2�1�E� ������a�h�h�j�j���!�!�!� �����J�A�w��M�!�W���������1��{�{�}�}���1� �8�8�:�:��?�?� �H�H�a��V� � � � ��a��A���������.�.�.�D��-�-�D�-�1�1�K�A�x� �M�!�X� &� &� &� � 0� 0���1��E�E�$�q�u�u�Q�x�x��{�A�.�.�/�/����+�+�a�.�.�1�5�'��C������A�B�B�� +� +��� � �c�h�/�/����Y�O�O�A�&�&��� � �a�i�i�k�k�*�*�*�*��T�$�s�1�8�8�:�:�v�6�6�7�7�8�8�!�<�<�A� �H�H�a��V� � � � � �Hr<c��|���|���kr| |}}|���}|���}|�|��\}}|jr$dt |�����zS|�| ��\}}}||z||zz�|��}dt |�����z}|t||��zS)a0 Convert complex logarithms to real arctangents. Explanation =========== Given a real field K and polynomials f and g in K[x], with g != 0, returns a sum h of arctangents of polynomials in K[x], such that: dh d f + I g -- = -- I log( ------- ) dx dx f - I g Examples ======== >>> from sympy.integrals.rationaltools import log_to_atan >>> from sympy.abc import x >>> from sympy import Poly, sqrt, S >>> log_to_atan(Poly(x, x, domain='ZZ'), Poly(1, x, domain='ZZ')) 2*atan(x) >>> log_to_atan(Poly(x + S(1)/2, x, domain='QQ'), ... Poly(sqrt(3)/2, x, domain='EX')) 2*atan(2*sqrt(3)*x/3 + sqrt(3)/3) See Also ======== log_to_real �) rO�to_fieldrrr r�gcdexrQ� log_to_atan) r(r0r+r,�srr1rTrYs r:r�r�s���> �x�x�z�z�A�H�H�J�J����r�1�1�� � � � � �A� � � � � �A� �5�5��8�8�D�A�q��y�%���a�i�i�k�k�"�"�"�"��'�'�1�"�+�+���1�a� �q�S�1�Q�3�Y�O�O�A� � �� �d�1�9�9�;�;��� ���;�q�!�$�$�$�$r<c �h�ddlm}tdt���\}}|����||t |zzi�����}|����||t |zzi�����}||t d���} ||t d���} | �tj tj ��| �t tj ��} } | �tj tj ��| �t tj ��}} tt| ||��|��}t|d���}t|��|���krd Stj }|���D�]�}t| �||i��|��}|s1t|�||i��|��}tj }t|d���}t|��|���krd Sg}|D]Y}||vrS| |vrN|js|���r|�| ���=|js|�|���Z|D]�}|�||||i��}|�d � ��dkr�6t| �||||i��|��}t| �||||i��|��}|d z|d zz���}||t/|��z|t1||��zzz }�ː��t|d���}t|��|���krd S|���D]=}||t/|����||����zz }�>|S) aw Convert complex logarithms to real functions. Explanation =========== Given real field K and polynomials h in K[t,x] and q in K[t], returns real function f such that: ___ df d \ ` -- = -- ) a log(h(a, x)) dx dx /__, a | q(a) = 0 Examples ======== >>> from sympy.integrals.rationaltools import log_to_real >>> from sympy.abc import x, y >>> from sympy import Poly, S >>> log_to_real(Poly(x + 3*y/2 + S(1)/2, x, domain='QQ[y]'), ... Poly(3*y**2 + 1, y, domain='ZZ'), x, y) 2*sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3 >>> log_to_real(Poly(x**2 - 1, x, domain='ZZ'), ... Poly(-2*y + 1, y, domain='ZZ'), x, y) log(x**2 - 1)/2 See Also ======== log_to_atan r)�collectzu,v)�clsF)�evaluater9)�filterNT)�chopr)�sympy.simplify.radsimpr�rrr�xreplacer�expandr rror%rrr �len� count_roots�keys� is_negative�could_extract_minus_signrkr�evalfr r�rS)r1r,r)rr�rTrUr[r3�H_map�Q_mapr@rIrc�dr9�R_ur/�r_urw�R_v� R_v_paired�r_v�DrYrZ�AB�R_qr4s r:r'r'Gs���B/�.�.�.�.�.� �5�e� $� $� $�D�A�q� � � � � ���a��Q�q�S��\�*�*�1�1�3�3�A� � � � � ���a��Q�q�S��\�*�*�1�1�3�3�A� �G�A�q�5� )� )� )�E� �G�A�q�5� )� )� )�E� �9�9�Q�U�A�F� #� #�U�Y�Y�q�!�&�%9�%9�q�A� �9�9�Q�U�A�F� #� #�U�Y�Y�q�!�&�%9�%9�q�A� �Y�q�!�Q� � ��#�#�A� ��#� � � �C� �3�x�x�1�=�=�?�?�"�"��t� �V�F��x�x�z�z�&:�&:�� ����Q��H�%�%�q� )� )��� ��Q�Z�Z��C��)�)�1�-�-�A� ��A��A�c�"�"�"�� �s�8�8�q�}�}��� &� &��4�4�� �� +� +�C��*�$�$�#��Z�)?�)?��?�+�c�&B�&B�&D�&D�+��%�%�s�d�+�+�+�+���+��%�%�c�*�*�*��� :� :�C�� � �A�s�A�s�+�,�,�A��w�w�D�w�!�!�Q�&�&���Q�Z�Z��C��C� 0�1�1�1�5�5�A��Q�Z�Z��C��C� 0�1�1�1�5�5�A��Q�$��A��+�&�&�(�(�B� �c�#�b�'�'�k�C� �A�q�(9�(9�$9�9� 9�F�F� :� ��#� � � �C� �3�x�x�1�=�=�?�?�"�"��t� �X�X�Z�Z�0�0���!�C�� � � � �(�(��A�.�.�/�/�/�/��� �Mr<)N)�__doc__�sympy.core.functionr�sympy.core.numbersr�sympy.core.singletonr�sympy.core.symbolrrr�&sympy.functions.elementary.exponentialr �(sympy.functions.elementary.trigonometricr �sympy.polys.polyrootsr �sympy.polys.polytoolsr �sympy.polys.rootoftoolsr � sympy.polysrrrr;rr"r�r'�r<r:�<module>r�sA��G�G�&�&�&�&�&�&� � � � � � �"�"�"�"�"�"�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�9�9�9�9�9�9�'�'�'�'�'�'�(�(�(�(�(�(�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�+�j�j�j�Z<�<�<�~X �X �X �X �v.%�.%�.%�bf�f�f�f�fr<
Memory