�
I�gU� � � � d Z ddlZddlmZ ddlmZ ddlmZmZmZmZm Z m
Z
ddlmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: e
d k rd
Z;ndZ;dZ<e
d k rdZ=nd
Z=dZ>i Z?dZ@i ZAdZBdZCi ZDdZEdZFdZGi ZHddgZI ed eeB� � dz � � D ]!ZJeI eKdeJz eB� � dz gdeJdz
z z z
ZI�"d� ZLd� ZMd� ZNd� ZOdXd�ZPeLd� � � ZQeLd� � � ZR ed� � ZS ed � � ZT ed!� � ZU ed"� � ZVd#� ZWeLdYd$�� � ZXd%� ZYd&� ZZeLd'� � � Z[eLd(� � � Z\ eMe\� � Z] eMeX� � Z^ eMe[� � Z_ eMeY� � Z` eMeQ� � Za eMeR� � ZbeLd)� � � ZceLd*� � � Zd eMed� � Ze eMec� � Zfefd+�Zgd,� Zhd-� Ziefd.�Zjefd/�ZkdZd0�Zld1� Zmd2� Znd[d3�Zod4� Zpefd5�Zqd6� Zrd7� Zsd8� Ztd9� Zud:� Zvefd;�Zwefd<�Zxefd=�Zyefd>�Zzefd?�Z{efd@�Z|efdA�Z}efdB�Z~d[dC�ZdD� Z�dE� Z�dF� Z�efdG�Z�edfdH�Z�dI� Z�eddfdJ�Z�efdK�Z�efdL�Z�efdM�Z�efdN�Z�efdO�Z�efdP�Z�efdQ�Z�efdR�Z�efdS�Z�dZdT�Z�dZdU�Z�e
dVk rg ddl�m�c m�c m�Z� e�j4 Z4e�j� Z�e�jq Zqe�j� Z�e�j� Z�e�jg Zge�j� Z�e�j� Z�e�jl ZldS # e�e�f$ r e�dW� � Y dS w xY wdS )\a(
This module implements computation of elementary transcendental
functions (powers, logarithms, trigonometric and hyperbolic
functions, inverse trigonometric and hyperbolic) for real
floating-point numbers.
For complex and interval implementations of the same functions,
see libmpc and libmpi.
� N)�bisect� )�xrange)�MPZ�MPZ_ZERO�MPZ_ONE�MPZ_TWO�MPZ_FIVE�BACKEND)-�round_floor�
round_ceiling�
round_down�round_up�
round_nearest�
round_fast�
ComplexResult�bitcount�bctable�lshift�rshift�giant_steps�
sqrt_fixed�from_int�to_int�from_man_exp�to_fixed�to_float�
from_float�
from_rational� normalize�fzero�fone�fnone�fhalf�finf�fninf�fnan�mpf_cmp�mpf_sign�mpf_abs�mpf_pos�mpf_neg�mpf_add�mpf_sub�mpf_mul�mpf_div� mpf_shift�mpf_rdiv_int�mpf_pow_int�mpf_sqrt�reciprocal_rnd�negative_rnd�mpf_perturb�
isqrt_fast)�ifib�python�X i� i� �� � i� i� � � i� � � � c �^ � � d� _ d� _ � fd�}� j |_ � j |_ |S )z�
Decorator for caching computed values of mathematical
constants. This decorator should be applied to a
function taking a single argument prec as input and
returning a fixed-point value with the given precision.
�����Nc � �� �j }| |k r
�j || z
z S t | dz dz � � } �|fi |���_ |�_ �j || z
z S )Ng�������?�
)� memo_prec�memo_val�int)�prec�kwargsrG �newprec�fs ��f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mpmath/libmp/libelefun.py�gzconstant_memo.<locals>.g^ sl �� ��K� ��9����:�)�D�.�1�1��d�4�i��l�#�#���Q�w�)�)�&�)�)��
�����z�g�d�l�+�+� )rG rH �__name__�__doc__)rM rO s ` rN �
constant_memorS U sE �� � �A�K��A�J�,� ,� ,� ,� ,� ��A�J�� �A�I��HrP c �8 � � t f� fd� }� j |_ |S )z�
Create a function that computes the mpf value for a mathematical
constant, given a function that computes the fixed-point value.
Assumptions: the constant is positive and has magnitude ~= 1;
the fixed-point function rounds to floor.
c � �� | dz } �|� � }|t t fv r|dz
}t d|| t |� � | |� � S )Nr? r r )r r
r r )rJ �rnd�wp�v�fixeds �rN rM zdef_mpf_constant.<locals>.fr sR �� �
�B�Y���E�"�I�I���8�]�+�+�+�
��F�A���A��s�H�Q�K�K��s�;�;�;rP )r rR )rY rM s ` rN �def_mpf_constantrZ j s6 �� � � <� <� <� <� <� <� �
�A�I��HrP c � � ||z
dk r=t d|z dz � � }|s|dz rt || dz z |fS t || dz z |fS ||z dz }t | |||� � \ }}}t | |||� � \ } }
}|
|z || z z ||
z ||z fS )Nr rB � )r r �bsp_acot)�q�a�b�
hyperbolic�a1�m�p1�q1�r1�p2�q2�r2s rN r] r] { s� � ��1�u��z�z�
��1��q��\�\��� +��1�� +��B��A��I�r�)�)��8�R�!�Q�$�Y��*�*�
�1��q��A��!�Q��:�.�.�J�B��B��!�Q��:�.�.�J�B��B�
�b�5�2�b�5�=�"�R�%��B��&�&rP c � � t d|z t j | � � z dz � � }t | d||� � \ }}}||z |z || z z S )z�
Compute acot(a) or acoth(a) for an integer a with binary splitting; see
http://numbers.computation.free.fr/Constants/Algorithms/splitting.html
�ffffff�?r? r )rI �math�logr] )r_ rJ ra �N�pr^ �rs rN �
acot_fixedrq � sW � �
�D�4�K������#�b�(�)�)�A��q�!�A�z�*�*�G�A�q�!�
�q�S�4�K�1�Q�3��rP Fc � � d}t }| D ]9\ }}|t |� � t t |� � ||z |� � z z
}�:||z S )z�
Evaluate a Machin-like formula, i.e., a linear combination of
acot(n) or acoth(n) for specific integer values of n, using fixed-
point arithmetic. The input should be a list [(c, n), ...], giving
c*acot[h](n) + ...
rF )r r rq )�coefsrJ ra � extraprec�sr_ r` s rN �machinrv � sZ � � �I��A�� E� E���1� �S��V�V�j��Q����i���D�D�
D�D���
��N�rP c �( � t g d�| d� � S )zz
Computes ln(2). This is done with a hyperbolic Machin-type formula,
with binary splitting at high precision.
))� � )�����i� )r= i-"