�
H�g� � �R � d dl mZ ddlmZ edd�� � Ze dd
�� � Zd S )
� )�xrange� )�defunFc � � |s| j S | � |d � � }| j }|dd� D ]}|r|||z z }|||z z }�|r||fS |S )a�
Given coefficients `[c_n, \ldots, c_2, c_1, c_0]` and a number `x`,
:func:`~mpmath.polyval` evaluates the polynomial
.. math ::
P(x) = c_n x^n + \ldots + c_2 x^2 + c_1 x + c_0.
If *derivative=True* is set, :func:`~mpmath.polyval` simultaneously
evaluates `P(x)` with the derivative, `P'(x)`, and returns the
tuple `(P(x), P'(x))`.
>>> from mpmath import *
>>> mp.pretty = True
>>> polyval([3, 0, 2], 0.5)
2.75
>>> polyval([3, 0, 2], 0.5, derivative=True)
(2.75, 3.0)
The coefficients and the evaluation point may be any combination
of real or complex numbers.
� r N)�zero�convert)�ctx�coeffs�x�
derivative�p�q�cs �k/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mpmath/calculus/polynomials.py�polyvalr s� � �0 � ��x�����F�1�I���A���A�
�A�B�B�Z� � ��� ��A�a�C��A�
��!��G���� ��!�t���� �2 T�
Nc �� � ��� t �� � dk r�r�d st d� � �g S � j }� j
}� � |� � 5 t �� � dz
} � � �d � � ��dk r� fd��D � � �n�fd��D � � ��� fd�}
|�� fd�t
| � � D � � }n`dg| z }t | t |� � � � }t |d|� � � |d|�<