� H�gq>���ddlmZmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlm Z Gd�de!��Z"Gd�de"eee e eeeeeeeee��Z#dS)�)�gt�lt�)�xrange)�SpecialFunctions)�RSCache)�QuadratureMethods)� LaplaceTransformInversionMethods)�CalculusMethods)�OptimizationMethods)� ODEMethods)� MatrixMethods)�MatrixCalculusMethods)�LinearAlgebraMethods)�Eigen)�IdentificationMethods)�VisualizationMethods)�libmpc��eZdZdS)�ContextN)�__name__� __module__� __qualname__���_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mpmath/ctx_base.pyrrs�������Drrc��eZdZejZejZd�Zd�ZdZdZ d�Z d�Z d�Z d�Z d�Zd �Zd �Zd �Zd �Zd �Zd"d�Zd#d�Zd�Zd$d�Zd%d�Zd&d�Zd�Zd�Zd�Zd�Zd�Zeej ��Z!eej"��Z"eej#��Z#eej$��Z$eej%��Z%eej&��Z'eej(��Z)eej*��Z+eej,��Z-d'd�Z.d'd�Z/d�Z0d�Z1d �Z2d!�Z3dS)(�StandardBaseContextc��i|_tj|��tj|��t j|��t j|��t j|��tj|��dS�N)�_aliasesr�__init__rr r r r)�ctxs rr"zStandardBaseContext.__init__*su���� ��!�#�&�&�&��������"�3�'�'�'�(�1�#�6�6�6�� ��%�%�%���s�#�#�#�#�#rc ��|j���D]5\}} t||t||�����&#t$rY�2wxYwdSr )r!�items�setattr�getattr�AttributeError)r#�alias�values r� _init_aliasesz!StandardBaseContext._init_aliases4sq���L�.�.�0�0� � �L�E�5� ���U�G�C��$7�$7�8�8�8�8��!� � � ��� ���� � s�A� A � A Fc�&�td|��dS)NzWarning:)�print�r#�msgs r�warnzStandardBaseContext.warn@s�� �j�#�����rc� �t|���r )� ValueErrorr.s r� bad_domainzStandardBaseContext.bad_domainCs����o�o�rc�4�t|d��r|jS|S)N�real)�hasattrr5�r#�xs r�_rezStandardBaseContext._reFs �� �1�f� � � ��6�M��rc�>�t|d��r|jS|jS)N�imag)r6r;�zeror7s r�_imzStandardBaseContext._imKs"�� �1�f� � � ��6�M��x�rc��|Sr rr7s r� _as_pointszStandardBaseContext._as_pointsPs���rc �.�|�|�� Sr ��convert)r#r8�kwargss r�fnegzStandardBaseContext.fnegSs��� � �A����rc �X�|�|��|�|��zSr rA�r#r8�yrCs r�faddzStandardBaseContext.faddV�!���{�{�1�~�~�c�k�k�!�n�n�,�,rc �X�|�|��|�|��z Sr rArFs r�fsubzStandardBaseContext.fsubYrIrc �X�|�|��|�|��zSr rArFs r�fmulzStandardBaseContext.fmul\rIrc �X�|�|��|�|��z Sr rArFs r�fdivzStandardBaseContext.fdiv_rIrc���|r@|rtd�|D��|j��Std�|D��|j��S|rtd�|D��|j��St||j��S)Nc3�:K�|]}t|��dzV��dS��N��abs��.0r8s r� <genexpr>z+StandardBaseContext.fsum.<locals>.<genexpr>es,����4�4�!�C��F�F�A�I�4�4�4�4�4�4rc3�4K�|]}t|��V��dSr rTrVs rrXz+StandardBaseContext.fsum.<locals>.<genexpr>fs(����-�-�1��A���-�-�-�-�-�-rc3� K�|] }|dzV�� dSrRrrVs rrXz+StandardBaseContext.fsum.<locals>.<genexpr>hs&����+�+���1��+�+�+�+�+�+r)�sumr<)r#�args�absolute�squareds r�fsumzStandardBaseContext.fsumbs��� � 9�� @��4�4�t�4�4�4�c�h�?�?�?��-�-��-�-�-�s�x�8�8� 8� � 7��+�+�d�+�+�+�S�X�6�6� 6��4���"�"�"rNc���|�t||��}|r(|j�t�fd�|D��|j��Std�|D��|j��S)Nc3�:�K�|]\}}|�|��zV��dSr r)rWr8rG�cfs �rrXz+StandardBaseContext.fdot.<locals>.<genexpr>ps3�����0�0�E�Q�q��"�"�Q�%�%��0�0�0�0�0�0rc3�&K�|] \}}||zV�� dSr r)rWr8rGs rrXz+StandardBaseContext.fdot.<locals>.<genexpr>rs*����,�,���1��!��,�,�,�,�,�,r)�zip�conjr[r<)r#�xs�ys� conjugaterbs @r�fdotzStandardBaseContext.fdotksl��� �>��R����B� � 8���B��0�0�0�0�R�0�0�0�#�(�;�;� ;��,�,��,�,�,�c�h�7�7� 7rc�(�|j}|D]}||z}�|Sr )�one)r#r\�prod�args r�fprodzStandardBaseContext.fprodts(���w��� � �C� �C�K�D�D�� r�c �>�t|j||fi|����dS)z6 Equivalent to ``print(nstr(x, n))``. N)r-�nstr)r#r8�nrCs r�nprintzStandardBaseContext.nprintzs.�� �h�c�h�q�!�&�&�v�&�&�'�'�'�'�'rc�X����� d�jz� ��|��}t|��}t|���kr�jS��|��ret �|�z��}t|j��|kr|jSt|j��|kr��d|j��Sna#t$rTt|�j ��r|� ��fd���cYSt|d��r��fd�|D��cYSYnwxYw|S)a� Chops off small real or imaginary parts, or converts numbers close to zero to exact zeros. The input can be a single number or an iterable:: >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> chop(5+1e-10j, tol=1e-9) mpf('5.0') >>> nprint(chop([1.0, 1e-20, 3+1e-18j, -4, 2])) [1.0, 0.0, 3.0, -4.0, 2.0] The tolerance defaults to ``100*eps``. N�drc�0����|���Sr ��chop)�ar#�tols ��r�<lambda>z*StandardBaseContext.chop.<locals>.<lambda>�s������!�S�)9�)9�r�__iter__c�<��g|]}��|�����Srrw)rWryr#rzs ��r� <listcomp>z,StandardBaseContext.chop.<locals>.<listcomp>�s'���4�4�4�Q�����C�(�(�4�4�4r)�epsrBrUr<�_is_complex_type�maxr;r5�mpc� TypeError� isinstance�matrix�applyr6)r#r8rz�absx�part_tols` ` rrxzStandardBaseContext.chop�sR���� �;��c�g�+�C� 5�� � �A���A��q�6�6�D��1�v�v��|�|��x���#�#�A�&�&� .��s�D��H�-�-���q�v�;�;��)�)��6�M��q�v�;�;��)�)��7�7�1�a�f�-�-�-���� 5� 5� 5��!�S�Z�(�(� ;��w�w�9�9�9�9�9�:�:�:�:�:��q�*�%�%� 5�4�4�4�4�4�!�4�4�4�4�4�4� 5� 5� 5���� �s$�=C �AC �2C � 8D'�D'�&D'c�&�|�|��}|�#|�!|�d|j dz��x}}|�|}n|�|}t||z ��}||krdSt|��}t|��}||kr||z }n||z }||kS)a� Determine whether the difference between `s` and `t` is smaller than a given epsilon, either relatively or absolutely. Both a maximum relative difference and a maximum difference ('epsilons') may be specified. The absolute difference is defined as `|s-t|` and the relative difference is defined as `|s-t|/\max(|s|, |t|)`. If only one epsilon is given, both are set to the same value. If none is given, both epsilons are set to `2^{-p+m}` where `p` is the current working precision and `m` is a small integer. The default setting typically allows :func:`~mpmath.almosteq` to be used to check for mathematical equality in the presence of small rounding errors. **Examples** >>> from mpmath import * >>> mp.dps = 15 >>> almosteq(3.141592653589793, 3.141592653589790) True >>> almosteq(3.141592653589793, 3.141592653589700) False >>> almosteq(3.141592653589793, 3.141592653589700, 1e-10) True >>> almosteq(1e-20, 2e-20) True >>> almosteq(1e-20, 2e-20, rel_eps=0, abs_eps=0) False Nr�T)rB�ldexp�precrU) r#�s�t�rel_eps�abs_eps�diff�abss�abst�errs r�almosteqzStandardBaseContext.almosteq�s���B �K�K��N�N�� �?�w�� #� � �!�c�h�Y�q�[� 9� 9� 9�G�g� �?��G�G� �_��G��1�Q�3�x�x�� �7�?�?��4��1�v�v���1�v�v�� �$�;�;��t�)�C�C��t�)�C��g�~�rc���t|��dkstdt|��z���t|��dkstdt|��z���d}d}t|��dkr |d}n#t|��dkr|d}|d}t|��dkr|d}|�|��|�|��|�|��}}}||z|ks Jd���||kr|dkrgSt}n|dkrgSt}g}d}|} |||zz}|dz }|||��r|�|��nn�1|S)aa This is a generalized version of Python's :func:`~mpmath.range` function that accepts fractional endpoints and step sizes and returns a list of ``mpf`` instances. Like :func:`~mpmath.range`, :func:`~mpmath.arange` can be called with 1, 2 or 3 arguments: ``arange(b)`` `[0, 1, 2, \ldots, x]` ``arange(a, b)`` `[a, a+1, a+2, \ldots, x]` ``arange(a, b, h)`` `[a, a+h, a+h, \ldots, x]` where `b-1 \le x < b` (in the third case, `b-h \le x < b`). Like Python's :func:`~mpmath.range`, the endpoint is not included. To produce ranges where the endpoint is included, :func:`~mpmath.linspace` is more convenient. **Examples** >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> arange(4) [mpf('0.0'), mpf('1.0'), mpf('2.0'), mpf('3.0')] >>> arange(1, 2, 0.25) [mpf('1.0'), mpf('1.25'), mpf('1.5'), mpf('1.75')] >>> arange(1, -1, -0.75) [mpf('1.0'), mpf('0.25'), mpf('-0.5')] �z+arange expected at most 3 arguments, got %irz+arange expected at least 1 argument, got %irrSz0dt is too small and would cause an infinite loop)�lenr��mpfrr�append) r#r\ry�dt�b�op�result�ir�s r�arangezStandardBaseContext.arange�s���@�4�y�y�A�~�~��I�!�$�i�i�(�)�)� )��4�y�y�A�~�~��I�!�$�i�i�(�)�)� )� �� �� �t�9�9��>�>��Q��A�A� ��Y�Y�!�^�^��Q��A��Q��A� �t�9�9��>�>��a��B��7�7�1�:�:�s�w�w�q�z�z�3�7�7�2�;�;�b�1���2�v��{�{�{�N�{�{�{� �q�5�5��A�v�v�� ��B�B��A�v�v�� ��B��� �� �� ��B�q�D��A� ��F�A��r�!�Q�x�x� �� � �a� � � � ��  �� rc�$���t|��dkrL|�|d���|�|d��}t|d��}nzt|��dkrHt|dd��sJ�|dj�|dj}t|d��}nt dt|��z���|dkrtd���d|vs|dr\|dkr|����gS|�z |�|dz ��z ���fd �t|��D��}||d <n7|�z |�|��z ���fd �t|��D��}|S) a� ``linspace(a, b, n)`` returns a list of `n` evenly spaced samples from `a` to `b`. The syntax ``linspace(mpi(a,b), n)`` is also valid. This function is often more convenient than :func:`~mpmath.arange` for partitioning an interval into subintervals, since the endpoint is included:: >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> linspace(1, 4, 4) [mpf('1.0'), mpf('2.0'), mpf('3.0'), mpf('4.0')] You may also provide the keyword argument ``endpoint=False``:: >>> linspace(1, 4, 4, endpoint=False) [mpf('1.0'), mpf('1.75'), mpf('2.5'), mpf('3.25')] r�rrrS�_mpi_z*linspace expected 2 or 3 arguments, got %izn must be greater than 0�endpointc� ��g|] }|�z�z�� Srr�rWr�ry�steps ��rr~z0StandardBaseContext.linspace.<locals>.<listcomp>G�!���/�/�/���4��!��/�/�/r�����c� ��g|] }|�z�z�� Srrr�s ��rr~z0StandardBaseContext.linspace.<locals>.<listcomp>Kr�r) r�r��intr6ryr�r�r2r)r#r\rCr�rrrGryr�s @@r�linspacezStandardBaseContext.linspace s�����* �t�9�9��>�>�����Q�� � �A�����Q�� � �A��D��G� � �A�A� ��Y�Y�!�^�^��4��7�G�,�,� ,� ,�,��Q�� �A��Q�� �A��D��G� � �A�A��H�!�$�i�i�(�)�)� )� �q�5�5��7�8�8� 8��V�#�#�v�j�'9�#��A�v�v����� � �|�#���E�S�W�W�Q��U�^�^�+�D�/�/�/�/�/�V�A�Y�Y�/�/�/�A��A�b�E�E���E�S�W�W�Q�Z�Z�'�D�/�/�/�/�/�V�A�Y�Y�/�/�/�A��rc �:�|j|fi|��|j|fi|��fSr )�cos�sin�r#�zrCs r�cos_sinzStandardBaseContext.cos_sinNs5���s�w�q�#�#�F�#�#�W�S�W�Q�%9�%9�&�%9�%9�9�9rc �:�|j|fi|��|j|fi|��fSr )�cospi�sinpir�s r� cospi_sinpizStandardBaseContext.cospi_sinpiQs5���s�y��%�%�f�%�%�y�s�y��'=�'=�f�'=�'=�=�=rc�8�td|dzzd|zz��S)Ni�g�?r�)r�)r#�ps r�_default_hyper_maxprecz*StandardBaseContext._default_hyper_maxprecTs!���4�!�T�'�>�A�a�C�'�(�(�(rrc��|j} d} ||zdz|_|j}|j}d}|��D]]}||z }||zsL|rJ|�|��} t || ��}|�|��} | | z |jkrn|dz }�^|| z } | | krn'| |ks|jrn|t |j| ��z }��|||_S#||_wxYw�N� r�r)r��ninfr<�magr��_fixed_precision�min) r#�terms� check_stepr�� extraprec�max_magr��k�term�term_mag�sum_mag� cancellations r�sum_accuratelyz"StandardBaseContext.sum_accuratelyas"���x�� ��I� 9��)�+�a�/����(���H����!�E�G�G���D���I�A�� �N�"��"�#&�7�7�4�=�=��"%�g�x�"8�"8��"%�'�'�!�*�*��"�X�-���8�8�!�E���F�A�A�&��0� ��<�/�/���)�+�+�s�/C�+���S���<�8�8�8� �' 9�(��C�H�H��t�C�H�O�O�O�Os �B<C � Cc��|j} d} ||zdz|_|j}|j}|}d}|��D]a} || z}| |z } ||zsK|�| ��} t || ��}|�||z ��} | |jkrn|dz }�b|| z } | | krn'| |ks|jrn|t |j| ��z }��|||_S#||_wxYwr�)r�r�rkr�r�r�r�)r#�factorsr�r�r�r�rkr�r��factorr�r�r�r�s r�mul_accuratelyz"StandardBaseContext.mul_accurately}s,���x�� ��I� 9��)�+�a�/����(���g������%�g�i�i� � �F���K�A�!�C�<�D�� �N�"�#&�7�7�4�=�=��"%�g�x�"8�"8��"%�'�'�!�C�%�.�.��%�9�s�x�/�/�!�E���F�A�A�&��0� ��<�/�/���)�+�+�s�/C�+���S���<�8�8�8� �/ 9�0��C�H�H��t�C�H�O�O�O�Os �CC� Cc�X�|�|��|�|��zS)aConverts `x` and `y` to mpmath numbers and evaluates `x^y = \exp(y \log(x))`:: >>> from mpmath import * >>> mp.dps = 30; mp.pretty = True >>> power(2, 0.5) 1.41421356237309504880168872421 This shows the leading few digits of a large Mersenne prime (performing the exact calculation ``2**43112609-1`` and displaying the result in Python would be very slow):: >>> power(2, 43112609)-1 3.16470269330255923143453723949e+12978188 rA)r#r8rGs r�powerzStandardBaseContext.power�s#�� �{�{�1�~�~����Q���/�/rc�,�|�|��Sr )�zeta)r#rrs r� _zeta_intzStandardBaseContext._zeta_int�s���x�x��{�{�rc�$�����dg�����fd�}|S)a� Return a wrapped copy of *f* that raises ``NoConvergence`` when *f* has been called more than *N* times:: >>> from mpmath import * >>> mp.dps = 15 >>> f = maxcalls(sin, 10) >>> print(sum(f(n) for n in range(10))) 1.95520948210738 >>> f(10) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... NoConvergence: maxcalls: function evaluated 10 times rc�|���dxxdz cc<�d�kr��d�z����|i|��S)Nrrz%maxcalls: function evaluated %i times)� NoConvergence)r\rC�N�counterr#�fs ����r�f_maxcalls_wrappedz8StandardBaseContext.maxcalls.<locals>.f_maxcalls_wrapped�sU��� �A�J�J�J�!�O�J�J�J��q�z�A�~�~��'�'�(O�RS�(S�T�T�T��1�d�%�f�%�%� %rr)r#r�r�r�r�s``` @r�maxcallszStandardBaseContext.maxcalls�s?������ �#�� &� &� &� &� &� &� &� &� "�!rc�N����i����fd�}�j|_�j|_|S)a� Return a wrapped copy of *f* that caches computed values, i.e. a memoized copy of *f*. Values are only reused if the cached precision is equal to or higher than the working precision:: >>> from mpmath import * >>> mp.dps = 15; mp.pretty = True >>> f = memoize(maxcalls(sin, 1)) >>> f(2) 0.909297426825682 >>> f(2) 0.909297426825682 >>> mp.dps = 25 >>> f(2) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... NoConvergence: maxcalls: function evaluated 1 times c���|r$|t|�����f}n|}�j}|� vr� |\}}||kr| S�|i|��}||f� |<|Sr )�tupler%r�) r\rC�keyr��cprec�cvaluer*r#r��f_caches ���r�f_cachedz-StandardBaseContext.memoize.<locals>.f_cached�s���� ��E�&�,�,�.�.�1�1�1������8�D��g�~�~� '�� � ��v��D�=�=�"�7�N��A�t�&�v�&�&�E� �%�=�G�C�L��Lr)r�__doc__)r#r�r�r�s`` @r�memoizezStandardBaseContext.memoize�sJ�����(�� � � � � � � ��J����9����r)FF)NF)ror )NN)r)4rrrrr�� ComplexResultr"r+r��verboser0r3r9r=r?rDrHrKrMrOr_rirnrsrxr�r�r�r�r�r�� staticmethod�gcd�_gcd� list_primes�isprime�bernfrac�moebius�ifac�_ifac�eulernum� _eulernum� stirling1� _stirling1� stirling2� _stirling2r�r�r�r�r�r�rrrrrs��������'�M��'�M�$�$�$�������G���������� ��� ������-�-�-�-�-�-�-�-�-�-�-�-�#�#�#�#�8�8�8�8���� (�(�(�(� "�"�"�"�H1�1�1�1�fG�G�G�R,�,�,�\:�:�:�>�>�>�)�)�)� �<�� � "� "�D��,�u�0�1�1�K��l�5�=�)�)�G��|�E�N�+�+�H��l�5�=�)�)�G� �L��� $� $�E�� �U�^�,�,�I���e�o�.�.�J���e�o�.�.�J�����8����@0�0�0�$���"�"�"�0$�$�$�$�$rrN)$�operatorrr� libmp.backendr�functions.functionsr�functions.rszetar�calculus.quadraturer �calculus.inverselaplacer �calculus.calculusr �calculus.optimizationr � calculus.odesr �matrices.matricesr�matrices.calculusr�matrices.linalgr�matrices.eigenr�identificationr� visualizationr�r�objectrrrrr�<module>rs�����������!�!�!�!�!�!�1�1�1�1�1�1�%�%�%�%�%�%�2�2�2�2�2�2�E�E�E�E�E�E�.�.�.�.�.�.�6�6�6�6�6�6�%�%�%�%�%�%�,�,�,�,�,�,�4�4�4�4�4�4�1�1�1�1�1�1�!�!�!�!�!�!�1�1�1�1�1�1�/�/�/�/�/�/������� � � � � �f� � � �V�V�V�V�V�'�� ��$����� �����V�V�V�V�Vr
Memory