� ��g+2����ddlmZddlmZmZmZmZmZmZm Z ddl m Z ddl m Z mZddlmZddlmZmZmZmZddlmZmZddlmZdd lmZmZdd lmZd d l m Z dd�Z!d�Z"Gd�de��Z#dS)�)� AccumBounds)�S�Symbol�Add�sympify�Expr� PoleError�Mul)� factor_terms)�Float�_illegal)� factorial)�Abs�sign�arg�re)�exp�log)�gamma)�PolynomialError�factor)�Order�)�gruntz�+c�N�t||||���d���S)aQComputes the limit of ``e(z)`` at the point ``z0``. Parameters ========== e : expression, the limit of which is to be taken z : symbol representing the variable in the limit. Other symbols are treated as constants. Multivariate limits are not supported. z0 : the value toward which ``z`` tends. Can be any expression, including ``oo`` and ``-oo``. dir : string, optional (default: "+") The limit is bi-directional if ``dir="+-"``, from the right (z->z0+) if ``dir="+"``, and from the left (z->z0-) if ``dir="-"``. For infinite ``z0`` (``oo`` or ``-oo``), the ``dir`` argument is determined from the direction of the infinity (i.e., ``dir="-"`` for ``oo``). Examples ======== >>> from sympy import limit, sin, oo >>> from sympy.abc import x >>> limit(sin(x)/x, x, 0) 1 >>> limit(1/x, x, 0) # default dir='+' oo >>> limit(1/x, x, 0, dir="-") -oo >>> limit(1/x, x, 0, dir='+-') zoo >>> limit(1/x, x, oo) 0 Notes ===== First we try some heuristics for easy and frequent cases like "x", "1/x", "x**2" and similar, so that it's fast. For all other cases, we use the Gruntz algorithm (see the gruntz() function). See Also ======== limit_seq : returns the limit of a sequence. F)�deep)�Limit�doit)�e�z�z0�dirs �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/series/limits.py�limitr% s*��f ��A�r�3� � � $� $�%� $� 0� 0�0�c���d}|tjurLt|�|d|z ��|tjd��}t |t ��rdS�n�|js|js|j s|j �rfg}ddl m }|j D�]}t||||��}|�tj��r�|j��t |t ��rt#|��} t | t$��s || ��} t | t$��st'|��} t | t$��rt)| |||��cSdSdSt |t ��rdS|tjurdS|�|����|�rB|j|�}|tjur�|jr�t1d�|D����r�g} g} t3|��D]P\} } t | t4��r| �| ���0| �|j | ���Qt7| ��dkr9t%| ����}t||||��}|t%| �z}|tjurL ddlm}||��}n#t>$rYdSwxYw|tjus||krdSt||||��S|S)a+Computes the limit of an expression term-wise. Parameters are the same as for the ``limit`` function. Works with the arguments of expression ``e`` one by one, computing the limit of each and then combining the results. This approach works only for simple limits, but it is fast. Nrrr)�togetherc3�@K�|]}t|t��V��dS�N)� isinstancer)�.0�rrs r$� <genexpr>zheuristics.<locals>.<genexpr>hs-����/X�/X�PR� �2�{�0K�0K�/X�/X�/X�/X�/X�/Xr&)�ratsimp) r�Infinityr%�subs�Zeror+r�is_Mul�is_Add�is_Pow� is_Function�sympy.simplify.simplifyr(�args�has� is_finiterr r r� heuristics�NaN�append�func�any� enumerater�len�simplify�sympy.simplify.ratsimpr/r)r r!r"r#�rv�rr(�a�l�m�r2�e2�ii�rval�e3r/�rat_es r$r;r;Cs�� �B� �Q�Z��� �1�6�6�!�Q�q�S�>�>�1�a�f�c� 2� 2�� �b�%� � � � �F� � ��.0�Q�X�.0���.0�Q�]�.0� ��4�4�4�4�4�4��� � �A��a��B��$�$�A��u�u�Q�Z� � � �Q�[�%8��a��%�%��$�Q���A�%�a��-�-�(�$�H�Q�K�K��%�a��-�-�&�"�1�I�I��!�!�S�)�)�9�)�!�Q��C�8�8�8�8�8��F�F�����A�u�%�%� �����a�e���������� � � � � � 0������B��Q�U�{�{�q�x�{�C�/X�/X�VW�/X�/X�/X�,X�,X�{����� )�!� � �.�.�H�B��!�$� �4�4�.�� � �$������ � �!�&��*�-�-�-�-��r�7�7�Q�;�;��b��*�*�,�,�B��b�!�R��-�-�A��S�"�X��B��Q�U�{�{��>�>�>�>�>�>�#�G�A�J�J�E�E��&�����F�F������A�E�>�>�U�a�Z�Z��F��U�A�r�3�/�/�/� �Is�J'�' J5�4J5c�<�eZdZdZdd�Zed���Zd�Zd�ZdS) raRepresents an unevaluated limit. Examples ======== >>> from sympy import Limit, sin >>> from sympy.abc import x >>> Limit(sin(x)/x, x, 0) Limit(sin(x)/x, x, 0, dir='+') >>> Limit(1/x, x, 0, dir="-") Limit(1/x, x, 0, dir='-') rc��t|��}t|��}t|��}|tjtjtjzfvrd}n)|tjtjtjzfvrd}|�|��rt d|�d|�d����t|t��rt|��}n4t|t��stdt|��z���t|��dvrtd|z���tj|��}||||f|_|S) N�-rz7Limits approaching a variable point are not supported (z -> �)z6direction must be of type basestring or Symbol, not %s)rrQ�+-z1direction must be one of '+', '-' or '+-', not %s)rrr0� ImaginaryUnit�NegativeInfinityr9�NotImplementedErrorr+�strr� TypeError�type� ValueErrorr�__new__�_args)�clsr r!r"r#�objs r$r[z Limit.__new__�sL�� �A�J�J�� �A�J�J�� �R�[�[�� �!�*�a�o�a�j�8�9� 9� 9��C�C� �A�&����8J�(J�K� K� K��C� �6�6�!�9�9� ;�%�%�34�1�1�b�b�b�':�;�;� ;� �c�3� � � 2���+�+�C�C��C��(�(� 2��%�'+�C�y�y�1�2�2� 2� �s�8�8�+� +� +��&�(+�,�-�-� -��l�3������2�s�O�� �� r&c���|jd}|j}|�|jdj��|�|jdj��|S)Nrr�)r8� free_symbols�difference_update�update)�selfr �isymss r$razLimit.free_symbols�sQ�� �I�a�L����� ���� �!� � 9�:�:�:� � � �T�Y�q�\�.�/�/�/�� r&c���|j\}}}}|j|j}}|�|��s0t |t |��z||��}t|��St |||��}t |||��} | t jur@|t jt j fvr&t ||dz z||��}t|��S| t j ur|t jurt j SdSdS)Nr) r8�baserr9r%rr�Oner0rU�ComplexInfinity) rdr �_r!r"�b1�e1�res�ex_lim�base_lims r$�pow_heuristicszLimit.pow_heuristics�s����i� ��1�b�!�����B���v�v�a�y�y� ���3�r�7�7� �A�r�*�*�C��s�8�8�O��r�1�b�!�!����Q��#�#�� �q�u� � ��!�*�a�&8�9�9�9��B��Q��K��B�/�/���3�x�x�� �q�)� )� )�f�� �.B�.B��$� $� *� )�.B�.Br&c �� � � � ��|j\}� �� t� ��dkr�t|� �d���}t|� �d���}t|t��r3t|t��r|jd|jdkr|S||kr|S|jr|jr t jStd|�d|������t jurtd����jrHt���}|t|��z }|� � |� z��}d� t j �|�d d ��r'|jdi|��}� jdi|��� �jdi|���|� kr�S|�� ��s|S�t jur t jS|jt$�r|S|jr.t)t|j� ���g|jd d ��R�Sd}t� ��dkrd }nt� ��dkrd }� � � �fd�� |�t,��rddlm}||��}� |��}|�� ���r�t j ur|� � d � z ��}| }n|� � � �z��} |�� |���\}} | dkr t jS| dkr|S|d kst9| ��d zst j t|��zS|d krt jt|��zSt jS#t$rYnwxYw�t j ur3|jrt?|��}|� � d � z ��}| }n|� � � �z��} |�� |���\}} t|t@��r| t jkr|S|�t j t jt jt j��r|S|�� ��s�| j!r t jS| dkr|S| j"rm|d krt j t|��zS|d kr9t jt|��zt j#t j$| zzzSt jStd| z���n�#tttJf$r�ddl&m'} | |��}|j(r|�)|��}|�|cYS |�*� |���}||krc|�tV��s|�t j,��r*t[|� dt]|��j"rdnd��cYSn#tttJf$rYnwxYwYnwxYw�j/r |�0tbtd��}d } t[|� �� ��}|t jus|t jurtK���n2#tJtf$r|��tg|� �� ��}|�|cYSYnwxYw|S)aPEvaluates the limit. Parameters ========== deep : bool, optional (default: True) Invoke the ``doit`` method of the expressions involved before taking the limit. hints : optional keyword arguments To be passed to ``doit`` methods; only used if deep is True. rSr)r#rQrz1The limit does not exist since left hand limit = z and right hand limit = z.Limits at complex infinity are not implementedrTrN�����c�r��|js|St�fd�|jD����}||jkr |j|�}t|t��}t|t ��}t|t ��}|s|s|r�t|jd�� ���}|jr td|jdz �� ���}|j rg|dkdkr*|r|jd n|r tj n tj S|dkdkr)|r |jdn|r tj n tjS|S)Nc3�.�K�|]}�|��V��dSr*�)r,r� set_signss �r$r.z0Limit.doit.<locals>.set_signs.<locals>.<genexpr> s+�����@�@�s�I�I�c�N�N�@�@�@�@�@�@r&rrT)r8�tupler>r+rrrr%�is_zero�is_extended_realr� NegativeOne�Pirhr2) �expr�newargs�abs_flag�arg_flag� sign_flag�sigr#rvr!r"s ����r$rvzLimit.doit.<locals>.set_signs sY����9� �� ��@�@�@�@�d�i�@�@�@�@�@�G��$�)�#�#� �t�y�'�*��!�$��,�,�H�!�$��,�,�H�"�4��.�.�I�� @�9� @�� @��D�I�a�L�!�R��5�5���;�<���$�)�A�,���2�s�;�;�C��'�@��a��D�(�(�19�!E���1�� � �1:� D�� � ���F���'�d�*�*�08�!?�� �!� � �)2� >������@��Kr&)� nsimplify)�cdirzNot sure of sign of %s)�powsimpru)4r8rWr%r+r� is_infiniterrirZrVr�absr1r0�getrr9r<r �is_Orderrr|r r7r��is_meromorphic�leadtermr2�intrUr3r r� is_positive� is_negativerzrhr �sympy.simplify.powsimpr�r5rp�as_leading_termr�Exp1rr�is_extended_positive�rewriterrr;)rd�hintsr rErGr�r��newe�coeff�exr�r#rvr!r"s @@@@r$rz Limit.doit�s ������� � ��1�b�#� �s�8�8�t� � ��a��B�C�(�(�(�A��a��B�C�(�(�(�A��!�U�#�#� � �1�e�(<�(<� ��6�!�9���q� �)�)��K��A�v�v����}� )��� )��(�(��*� !���1�1�&�'�'� '� ��"� "� "�%�'C�D�D� D� �>� ���8�8�D���D� � �>�D����q�$�q�&�!�!�A��C���B� �9�9�V�T� "� "� "���������A���������A����!�!�5�!�!�B� ��6�6��I��u�u�Q�x�x� ��H� ���;�;��5�L� �1�5�(� � ��K� �:� <���q�v�q�"�-�-�;���q�r�r� �;�;�;� ;��� �s�8�8�s�?�?��D�D� ��X�X��_�_��D� � � � � � � � �, �5�5��<�<� � :� 9� 9� 9� 9� 9�� �!� � �A� �I�a�L�L�� � � �A�r� "� "� -��Q�Z����v�v�a��1��~�~���u����v�v�a��R��(�(�� -� �M�M�!�$�M�7�7� ��r���6�6��6�M��1�W�W� �L��1�9�9�C��G�G�a�K�9��:�d�5�k�k�1�1��R�Z�Z��-�d�5�k�k�9�9��,�,��� � � ��� ���� ��� � ��x� $� ��O�O���6�6�!�Q�q�S�>�>�D��5�D�D��6�6�!�Q��V�$�$�D�" M�� � �a�d� �3�3�I�E�2� �%��-�-� �"���,�,�� ��y�y���Q�%7��9J�A�E�R�R� �� ��9�9�Q�<�<� M��>� M��6�M��1�W�W� �L��^�M��q�y�y� �z�$�u�+�+�5�5����� �1�$�u�+�+�=�a�m�a�e�VX�j�>Y�Y�Y� �0�0�-�.F��.K�L�L�L� M��'�/��;� � � � 6� 6� 6� 6� 6� 6���� � �A��x� ��'�'��*�*���=��H�H�H� ��,�,�Q�T�,�:�:���D�=�=�e�i�i��n�n�=�� � �!�&�8I�8I�=�!�%��A�b��h�h�6J�/S�s�s�PS�T�T�T�T�T���� 3�Y�?� � � ��� ������ ����L � "� ,�� � �)�U�+�+�A� �� ��q�!�R��%�%�A��A�E�z�z�Q�!�%�Z�Z��k�k�!�(���:�&� � � ��}���1�a��S�)�)�A��y�� � � ��y�  �����sb�7M � M�M�8S2�2AW�=A=V>�:W�=W�>W�W�W�W�W� <Y�*Y7�6Y7N�r) �__name__� __module__� __qualname__�__doc__r[�propertyrarprrur&r$rr�sp������ � �����6����X��%�%�%�$z�z�z�z�zr&rNr�)$�!sympy.calculus.accumulationboundsr� sympy.corerrrrrr r �sympy.core.exprtoolsr �sympy.core.numbersr r �(sympy.functions.combinatorial.factorialsr�$sympy.functions.elementary.complexesrrrr�&sympy.functions.elementary.exponentialrr�'sympy.functions.special.gamma_functionsr� sympy.polysrr�sympy.series.orderrrr%r;rrur&r$�<module>r�sv��9�9�9�9�9�9�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�-�-�-�-�-�-�.�.�.�.�.�.�.�.�>�>�>�>�>�>�E�E�E�E�E�E�E�E�E�E�E�E�=�=�=�=�=�=�=�=�9�9�9�9�9�9�/�/�/�/�/�/�/�/�$�$�$�$�$�$�������31�31�31�31�l<�<�<�~�����D�����r&
Memory