� ��gH����dZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZmZdd lmZdd lmZdd lmZmZddlmZmZddlmZdd�Z d�Z!d�Z"d�Z#dd�Z$dS)zLimits of sequences�)�AccumulationBounds)�Add)� PoleError)�Pow)�S)�Dummy)�sympify)� fibonacci)� factorial� subfactorial)�gamma)�Abs)�Max�Min)�cos�sin)�LimitN�c���t|��}|�`|j}t|��dkr|���}n1t|��dkr tjSt d|z���t|��}|jdus |jdurt d���t|d��r|� ||��}|r|S|� |||z��|z S)a�Difference Operator. Explanation =========== Discrete analog of differential operator. Given a sequence x[n], returns the sequence x[n + step] - x[n]. Examples ======== >>> from sympy import difference_delta as dd >>> from sympy.abc import n >>> dd(n*(n + 1), n) 2*n + 2 >>> dd(n*(n + 1), n, 2) 4*n + 6 References ========== .. [1] https://reference.wolfram.com/language/ref/DifferenceDelta.html NrrzqSince there is more than one variable in the expression, a variable must be supplied to take the difference of %sFzStep should be a finite number.�_eval_difference_delta) r � free_symbols�len�popr�Zero� ValueError� is_number� is_finite�hasattrr�subs)�expr�n�step�f�results �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/series/limitseq.py�difference_deltar&s���0 �4�=�=�D��y� � �� �q�6�6�Q�;�;������A�A� ��V�V�q�[�[��6�M��:�<@�A�B�B� B� �4�=�=�D� �~����$�.�E�"9�"9��:�;�;�;��t�-�.�.���,�,�Q��5�5�� � ��M� �9�9�Q��D�� !� !�D� (�(�c��tj|�d�����}|d}|g}|dd�D]�}||z }|���}||kr|���}t ||��}|�dS|jr|}|g}�W|tjtj fvr|� |����t|��dkrdS|S)a�Finds the dominant term in a sum, that is a term that dominates every other term. Explanation =========== If limit(a/b, n, oo) is oo then a dominates b. If limit(a/b, n, oo) is 0 then b dominates a. Otherwise, a and b are comparable. If there is no unique dominant term, then returns ``None``. Examples ======== >>> from sympy import Sum >>> from sympy.series.limitseq import dominant >>> from sympy.abc import n, k >>> dominant(5*n**3 + 4*n**2 + n + 1, n) 5*n**3 >>> dominant(2**n + Sum(k, (k, 0, n)), n) 2**n See Also ======== sympy.series.limitseq.dominant T)�func�����Nr) r� make_args�expand� gammasimp�factor� limit_seq�is_zeror�Infinity�NegativeInfinity�appendr) r r!�terms�term0�comp�t�r�e�ls r%�dominantr;Cs���: �M�$�+�+�4�+�0�0� 1� 1�E� �"�I�E� �7�D� �3�B�3�Z� � �� �!�G�� �K�K�M�M�� ��6�6���� � �A� �a��O�O�� �9��4�4� �Y� ��E��7�D�D� �q�z�1�#5�6� 6� 6� �K�K��N�N�N�� �4�y�y�1�}�}��t� �Lr'c�� t||tj���d���S#tt f$rYdSwxYw)NF)�deep)rrr1�doit�NotImplementedErrorr)r r!s r%� _limit_infr@usS����T�1�a�j�)�)�.�.�E�.�:�:�:�� �� +�����t�t����s�.1�A�Ac����ddlm}t|��D�]G}|�|��st |���}|�|cS|���\}}|����r|����s+t |������}|�|cSdS�fd�||fD��\}}||z ���}|�|��st |���}|�|cS|���\}}t|���}|�dSt|���}|�dS||z ���}��IdS)Nr��Sumc3�\�K�|]&}t|������V��'dS�N)r&r,)�.0r7r!s �r%� <genexpr>z_limit_seq.<locals>.<genexpr>�s6�����H�H��$�Q�X�X�Z�Z��3�3�H�H�H�H�H�Hr') �sympy.concrete.summationsrC�range�hasr@�as_numer_denomr>r-r;)r r!�trialsrC�ir$�num�dens ` r%� _limit_seqrP|s����-�-�-�-�-�-� �6�]�]�'�'���x�x��}�}� ���a�(�(�F��!�� � � ��&�&�(�(���S��w�w�q�z�z� ������� ��� � � � �Q�/�/�F��!�� � � ��4�4�H�H�H�H�c�3�Z�H�H�H���S��c� �$�$�&�&���x�x��}�}� ���a�(�(�F��!�� � � ��&�&�(�(���S��s�A���� �;��4�4��s�A���� �;��4�4��c� �$�$�&�&���?'�'r'�c�*���ddlm}��B|j}t|��dkr|����n|s|St d����|jvr|S|�ttj ��}|�ttt��}tddd���}tddd� ��}tddd� ��}d �|�t��D��}t!�fd �|D����s |�t$t&��r�t)|��|i��|���} | �ht)|��|i��|���} | | kr<| jr3| jr,t/t1| | ��t3| | ����SdSn&t)|��|i��|���} | �| S|jr8��fd �|jD��} t!d�| D����rdSt9| �S|�|��sHt)t;|��|i����|���} | �| jrtjSdSdSdS)a�Finds the limit of a sequence as index ``n`` tends to infinity. Parameters ========== expr : Expr SymPy expression for the ``n-th`` term of the sequence n : Symbol, optional The index of the sequence, an integer that tends to positive infinity. If None, inferred from the expression unless it has multiple symbols. trials: int, optional The algorithm is highly recursive. ``trials`` is a safeguard from infinite recursion in case the limit is not easily computed by the algorithm. Try increasing ``trials`` if the algorithm returns ``None``. Admissible Terms ================ The algorithm is designed for sequences built from rational functions, indefinite sums, and indefinite products over an indeterminate n. Terms of alternating sign are also allowed, but more complex oscillatory behavior is not supported. Examples ======== >>> from sympy import limit_seq, Sum, binomial >>> from sympy.abc import n, k, m >>> limit_seq((5*n**3 + 3*n**2 + 4) / (3*n**3 + 4*n - 5), n) 5/3 >>> limit_seq(binomial(2*n, n) / Sum(binomial(2*k, k), (k, 1, n)), n) 3/4 >>> limit_seq(Sum(k**2 * Sum(2**m/m, (m, 1, k)), (k, 1, n)) / (2**n*n), n) 4 See Also ======== sympy.series.limitseq.dominant References ========== .. [1] Computing Limits of Sequences - Manuel Kauers rrBNrzAExpression has more than one variable. Please specify a variable.r!T)�integer�positive)�oddrT)�evenrTc3�>K�|]}|���V��dSrE)� as_base_exp)rF�ps r%rGzlimit_seq.<locals>.<genexpr>�s*���� 7� 7�!�a�m�m�o�o� 7� 7� 7� 7� 7� 7r'c3�V�K�|]#\}}|jo|����V��$dSrE)� is_negativerJ)rF�br9r!s �r%rGzlimit_seq.<locals>.<genexpr>�s8����� :� :�4�1�a�A�M� &�a�e�e�A�h�h� :� :� :� :� :� :r'c�2��g|]}t|������S�)r/)rF�termr!rLs ��r%� <listcomp>zlimit_seq.<locals>.<listcomp>�s%���G�G�G�T�i��a��0�0�G�G�Gr'c3�K�|]}|duV�� dSrEr^)rFr$s r%rGzlimit_seq.<locals>.<genexpr>�s&����7�7�f�6�T�>�7�7�7�7�7�7r') rHrCrrrr�rewriter r� GoldenRatior r r r�atomsr�anyrJrrrP�xreplace� is_comparablerrr�is_Add�argsrrr0r) r r!rLrC�free�n_�n1�n2�powers�L1�L2�limits�lims `` r%r/r/�s�����`.�-�-�-�-�-��y�� �� �t�9�9��>�>���� � �A�A�� ;��K��:�;�;� ;� �$�#� #� #�� � �<�<� �1�=� 1� 1�D� �<�<� �<�� 7� 7�D� �s�D�4� 0� 0� 0�B� �s��t� ,� ,� ,�B� �s��� -� -� -�B�8� 7�t�z�z�#��� 7� 7� 7�F� � :� :� :� :�6� :� :� :�:�:� <� �H�H�S�#� � � <� �� � �q�"�g�.�.��F� ;� ;�� �>��D�M�M�1�b�'�2�2�B��?�?�B��R�x�x��#� ��(8� �-�c�"�b�k�k�3�r�2�;�;�G�G�G��4�� �� � �q�"�g�.�.��F� ;� ;�� �~�� � �;� �G�G�G�G�G�T�Y�G�G�G�F��7�7��7�7�7�7�7� $��t��F�|�#����#��� ��S�����2�w�!7�!7�8�8�"�f�E�E�C���3�;���v� � � ����r')Nr)NrQ)%�__doc__�!sympy.calculus.accumulationboundsr�sympy.core.addr�sympy.core.functionr�sympy.core.powerr�sympy.core.singletonr�sympy.core.symbolr�sympy.core.sympifyr �%sympy.functions.combinatorial.numbersr �(sympy.functions.combinatorial.factorialsr r �'sympy.functions.special.gamma_functionsr �$sympy.functions.elementary.complexesr�(sympy.functions.elementary.miscellaneousrr�(sympy.functions.elementary.trigonometricrr�sympy.series.limitsrr&r;r@rPr/r^r'r%�<module>r�s�����@�@�@�@�@�@�������)�)�)�)�)�)� � � � � � �"�"�"�"�"�"�#�#�#�#�#�#�&�&�&�&�&�&�;�;�;�;�;�;�L�L�L�L�L�L�L�L�9�9�9�9�9�9�4�4�4�4�4�4�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�%�%�%�%�%�%�-)�-)�-)�-)�`/�/�/�d���"'�"'�"'�J`�`�`�`�`�`r'
Memory