Ë
    7^(hc!  ã                   óê   — d Z ddlmZmZmZmZ ddlmZmZm	Z	m
Z
 ddlmZmZ ddlmZmZ ddlmZmZ ddlmZ ddlmZmZmZ ed	„ «       Zed
„ «       Zed„ «       Ze ed«      fd„«       Zedd„«       Zy)z/High-level polynomials manipulation functions. é    )ÚSÚBasicÚsymbolsÚDummy)ÚPolificationFailedÚComputationFailedÚMultivariatePolynomialErrorÚOptionError)Úallowed_flagsÚbuild_options)Úpoly_from_exprÚPoly)Úsymmetric_polyÚinterpolating_poly)Úsring)Únumbered_symbolsÚtakeÚpublicc                 óÆ  — t        |ddg«       d}t        | d«      sd}| g} t        | g|¢­i |¤Ž\  }} |j                  }t	        ||«      }|j                  }t        t        |«      «      D �cg c]  }t        |«      ‘Œ }}g }| D ]C  }	|	j                  «       \  }
}}|j                   |
j                  |Ž  |j                  |Ž f«       ŒE t        |«      D ���cg c]  \  }\  }}||j                  «       f‘Œ }}}}|j                  s,t        |«      D ]  \  }\  }}|j                  |«      |f||<   Œ  |s|\  }|j                  s|S |r||fS ||fz   S c c}w c c}}}w )a²  
    Rewrite a polynomial in terms of elementary symmetric polynomials.

    A symmetric polynomial is a multivariate polynomial that remains invariant
    under any variable permutation, i.e., if `f = f(x_1, x_2, \dots, x_n)`,
    then `f = f(x_{i_1}, x_{i_2}, \dots, x_{i_n})`, where
    `(i_1, i_2, \dots, i_n)` is a permutation of `(1, 2, \dots, n)` (an
    element of the group `S_n`).

    Returns a tuple of symmetric polynomials ``(f1, f2, ..., fn)`` such that
    ``f = f1 + f2 + ... + fn``.

    Examples
    ========

    >>> from sympy.polys.polyfuncs import symmetrize
    >>> from sympy.abc import x, y

    >>> symmetrize(x**2 + y**2)
    (-2*x*y + (x + y)**2, 0)

    >>> symmetrize(x**2 + y**2, formal=True)
    (s1**2 - 2*s2, 0, [(s1, x + y), (s2, x*y)])

    >>> symmetrize(x**2 - y**2)
    (-2*x*y + (x + y)**2, -2*y**2)

    >>> symmetrize(x**2 - y**2, formal=True)
    (s1**2 - 2*s2, -2*y**2, [(s1, x + y), (s2, x*y)])

    Úformalr   TÚ__iter__F)r   Úhasattrr   r   r   ÚrangeÚlenÚnextÚ
symmetrizeÚappendÚas_exprÚzipr   Ú	enumerateÚsubs)ÚFÚgensÚargsÚiterableÚRÚoptr   ÚiÚresultÚfÚpÚrÚmÚsÚ_ÚgÚpolysÚsymÚnon_syms                      úS/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/polyfuncs.pyr   r      sy  € ôB �$˜ 9Ð-Ô.à€Hä�1�jÔ!ØˆØˆCˆä�Ð"�TÒ"˜TÑ"�D€A€qØ�9‰9€Dä
˜˜dÓ
#€CØ�k‰k€GÜ&+¬C°«IÓ&6Ö7 Œt�G�}Ð7€GÐ7à€Fàò ?ˆØ—,‘,“.‰ˆˆ1ˆaØ�‰�y�q—y‘y 'Ð*¨I¨A¯I©I°tÐ,<Ð=Õ>ð?ô 03°7¸A«×?Ð?¡) !¡V a¨ˆa�—‘“ÒÐ?€EÒ?à�:Š:Ü!*¨6Ó!2ò 	3ÑˆA‰~��WØŸ™ %›¨'Ð2ˆF�1ŠIð	3ñ Ø‰ˆà�:Š:ØˆáØ˜5�=Ð à˜U˜HÑ$Ð$ùò/ 8ùô @s   Á.EÃEc                 óŒ  — t        |g «       	 t        | g|¢­i |¤Ž\  }}t        j
                  |j                  }}|j                  r|j                  «       D ]
  }||z  |z   }Œ |S t        ||«      |dd }}|j                  «       D ]  }||z  t        |g|¢­i |¤Žz   }Œ |S # t        $ r}|j                  cY d}~S d}~ww xY w)aê  
    Rewrite a polynomial in Horner form.

    Among other applications, evaluation of a polynomial at a point is optimal
    when it is applied using the Horner scheme ([1]).

    Examples
    ========

    >>> from sympy.polys.polyfuncs import horner
    >>> from sympy.abc import x, y, a, b, c, d, e

    >>> horner(9*x**4 + 8*x**3 + 7*x**2 + 6*x + 5)
    x*(x*(x*(9*x + 8) + 7) + 6) + 5

    >>> horner(a*x**4 + b*x**3 + c*x**2 + d*x + e)
    e + x*(d + x*(c + x*(a*x + b)))

    >>> f = 4*x**2*y**2 + 2*x**2*y + 2*x*y**2 + x*y

    >>> horner(f, wrt=x)
    x*(x*y*(4*y + 2) + y*(2*y + 1))

    >>> horner(f, wrt=y)
    y*(x*y*(4*x + 2) + x*(2*x + 1))

    References
    ==========
    [1] - https://en.wikipedia.org/wiki/Horner_scheme

    Né   )r   r   r   Úexprr   ÚZeroÚgenÚis_univariateÚ
all_coeffsr   Úhorner)	r*   r#   r$   r"   r'   ÚexcÚformr9   Úcoeffs	            r4   r<   r<   W   sÛ   € ôB �$˜ÔðÜ Ð1 DÒ1¨DÑ1‰ˆˆ3ô —‘˜Ÿ™ˆ#€Dà‡‚Ø—\‘\“^ò 	$ˆEØ˜‘8˜eÑ#‰Dð	$ð €Kô �q˜#“,  Q R ˆ4ˆà—\‘\“^ò 	;ˆEØ˜‘8œf UÐ:¨TÒ:°TÑ:Ñ:‰Dð	;ð €Køô ò Ø�x‰x�ûðús   ŽB$ Â$	CÂ-B>Â8CÂ>Cc                 ó€  — t        | «      }t        | t        «      r5|| v rt        | |   «      S t	        t        | j                  «       Ž «      \  }}n�t        | d   t        «      r5t	        t        | Ž «      \  }}||v rbt        ||j                  |«         «      S |t        d|dz   «      v rt        | |dz
     «      S t	        | «      }t	        t        d|dz   «      «      }	 t        ||||«      j                  «       S # t        $ r9 t        «       }t        ||||«      j                  «       j                  ||«      cY S w xY w)a)  
    Construct an interpolating polynomial for the data points
    evaluated at point x (which can be symbolic or numeric).

    Examples
    ========

    >>> from sympy.polys.polyfuncs import interpolate
    >>> from sympy.abc import a, b, x

    A list is interpreted as though it were paired with a range starting
    from 1:

    >>> interpolate([1, 4, 9, 16], x)
    x**2

    This can be made explicit by giving a list of coordinates:

    >>> interpolate([(1, 1), (2, 4), (3, 9)], x)
    x**2

    The (x, y) coordinates can also be given as keys and values of a
    dictionary (and the points need not be equispaced):

    >>> interpolate([(-1, 2), (1, 2), (2, 5)], x)
    x**2 + 1
    >>> interpolate({-1: 2, 1: 2, 2: 5}, x)
    x**2 + 1

    If the interpolation is going to be used only once then the
    value of interest can be passed instead of passing a symbol:

    >>> interpolate([1, 4, 9], 5)
    25

    Symbolic coordinates are also supported:

    >>> [(i,interpolate((a, b), i)) for i in range(1, 4)]
    [(1, a), (2, b), (3, -a + 2*b)]
    r   r6   )r   Ú
isinstanceÚdictr   Úlistr   ÚitemsÚtupleÚindexr   r   ÚexpandÚ
ValueErrorr   r!   )ÚdataÚxÚnÚXÚYÚds         r4   ÚinterpolaterO   �   s$  € ôT 	ˆD‹	€Aä�$œÔØ�‰9Ü�T˜!‘W“:ÐÜ”C˜Ÿ™›Ð&Ó'‰ˆ‰1ä�d˜1‘gœuÔ%Üœ˜T˜
Ó#‰DˆAˆqØ�A‰vÜ˜˜1Ÿ7™7 1›:™Ó'Ð'à”E˜!˜Q ™U“OÑ#Ü˜˜a !™e™“~Ð%Ü�T“
ˆAÜ”U˜1˜a !™e“_Ó%ˆAðBÜ! ! Q¨¨1Ó-×4Ñ4Ó6Ð6øÜò BÜ‹GˆÜ! ! Q¨¨1Ó-×4Ñ4Ó6×;Ñ;¸A¸qÓAÒAðBús   ÃC; Ã;?D=Ä<D=rJ   c                 óp  ‡‡‡
— ddl m} t        t        | Ž «      \  }}t	        |«      ‰z
  dz
  }|dk  rt        d«      ‚ |‰|z   dz   ‰|z   dz   «      }t        t        ‰|«      «      D ]-  }t        ‰|z   dz   «      D ]  }	||	|f   ||	   z  ||	|dz   f<   Œ Œ/ t        |dz   «      D ]7  }t        ‰|z   dz   «      D ]!  }	||	||z
  f    ||	   z  ||	‰|z   dz   |z
  f<   Œ# Œ9 |j                  «       d   Š
t        ˆˆ
fd„t        ‰dz   «      D «       «      t        ˆˆˆ
fd„t        |dz   «      D «       «      z  S )aŒ  
    Returns a rational interpolation, where the data points are element of
    any integral domain.

    The first argument  contains the data (as a list of coordinates). The
    ``degnum`` argument is the degree in the numerator of the rational
    function. Setting it too high will decrease the maximal degree in the
    denominator for the same amount of data.

    Examples
    ========

    >>> from sympy.polys.polyfuncs import rational_interpolate

    >>> data = [(1, -210), (2, -35), (3, 105), (4, 231), (5, 350), (6, 465)]
    >>> rational_interpolate(data, 2)
    (105*x**2 - 525)/(x + 1)

    Values do not need to be integers:

    >>> from sympy import sympify
    >>> x = [1, 2, 3, 4, 5, 6]
    >>> y = sympify("[-1, 0, 2, 22/5, 7, 68/7]")
    >>> rational_interpolate(zip(x, y), 2)
    (3*x**2 - 7*x + 2)/(x + 1)

    The symbol for the variable can be changed if needed:
    >>> from sympy import symbols
    >>> z = symbols('z')
    >>> rational_interpolate(data, 2, X=z)
    (105*z**2 - 525)/(z + 1)

    References
    ==========

    .. [1] Algorithm is adapted from:
           http://axiom-wiki.newsynthesis.org/RationalInterpolation

    r   )Úonesr6   z'Too few values for the required degree.é   c              3   ó4   •K  — | ]  }‰|   ‰|z  z  –— Œ y ­w©N© )Ú.0r(   rL   r,   s     €€r4   ú	<genexpr>z'rational_interpolate.<locals>.<genexpr>  s   øè ø€ Ò7 ��!‘�q˜!‘t•Ñ7ùs   ƒc              3   ó@   •K  — | ]  }‰|‰z   d z      ‰|z  z  –— Œ y­w)r6   NrU   )rV   r(   rL   Údegnumr,   s     €€€r4   rW   z'rational_interpolate.<locals>.<genexpr>  s'   øè ø€ ÒA¨q�!�A˜‘J ‘NÑ# a¨¡dÕ*ÑAùs   ƒ)
Úsympy.matrices.denserQ   rC   r   r   r
   r   ÚmaxÚ	nullspaceÚsum)rI   rY   rL   rQ   ÚxdataÚydataÚkÚcÚjr(   r,   s    ``       @r4   Úrational_interpolaterc   Ï   sh  ú€ õR *äœ˜T˜
Ó#�L€Eˆ5äˆE‹
�VÑ˜aÑ€AØˆ1‚uÜÐCÓDÐDÙˆV�a‰Z˜!‰^˜V a™Z¨!™^Ó,€AÜ”3�v˜q“>Ó"ò +ˆÜ�v ‘z A‘~Ó&ò 	+ˆAØ˜A˜q˜D™' %¨¡(Ñ*ˆAˆa��Q‘ˆhŠKñ	+ð+ô �1�q‘5‹\ò =ˆÜ�v ‘z A‘~Ó&ò 	=ˆAØ()¨!¨Q°©U¨(© |°E¸!±HÑ'<ˆAˆa�˜!‘˜a‘ !Ñ#Ð#Ò$ñ	=ð=ð 	
�‰‹�aÑ€AÜÔ7¤U¨6°A©:Ó%6Ô7Ó7ÜÕA´E¸!¸a¹%³LÔAÓAñBð Có    Nc                 ór  — t        |g «       t        |t        «      r|f|z   d}}	 t        | g|¢­i |¤Ž\  } }| j                  rt        d«      ‚| j                  «       }|dk  rt        d«      ‚|€t        dd¬«      }t        ||«      }|t        |«      k7  rt        d|›d	t        |«      ›�«      ‚| j                  «       | j                  «       }}g d
}
}	t        |dd «      D ]2  \  }}t!        |dz   |«      }|
||z  z  }|	j#                  ||f«       |
 }
Œ4 |	S # t        $ r}t        dd|«      ‚d}~ww xY w)a#  
    Generate Viete's formulas for ``f``.

    Examples
    ========

    >>> from sympy.polys.polyfuncs import viete
    >>> from sympy import symbols

    >>> x, a, b, c, r1, r2 = symbols('x,a:c,r1:3')

    >>> viete(a*x**2 + b*x + c, [r1, r2], x)
    [(r1 + r2, -b/a), (r1*r2, c/a)]

    NÚvieter6   z(multivariate polynomials are not allowedz8Cannot derive Viete's formulas for a constant polynomialr,   )Ústartz	required z roots, got éÿÿÿÿ)r   rA   r   r   r   r   Úis_multivariater	   ÚdegreerH   r   r   r   ÚLCr;   r    r   r   )r*   Úrootsr#   r$   r'   r=   rK   ÚlcÚcoeffsr)   Úsignr(   r?   Úpolys                 r4   rf   rf     sZ  € ô" �$˜Ôä�%œÔØ�h ‘o tˆeˆð1Ü Ð1 DÒ1¨DÑ1‰ˆˆ3ð 	×ÒÜ)Ø6ó8ð 	8ð 	
�‰‹
€Aàˆ1‚uÜØFóHð 	Hð €}Ü  ¨AÔ.ˆä�˜‹N€EàŒC�‹J‚Ýº¼3¸u¼:ÐFÓGÐGà—‘“˜Ÿ™›ˆ€BØ�rˆD€Fä˜f Q R˜jÓ)ò ‰ˆˆ5Ü˜a !™e UÓ+ˆØ�e˜B‘h‘ˆØ�‰�t˜U�mÔ$Øˆu‰ð	ð €Møô= ò 1Ü ¨¨CÓ0Ð0ûð1ús   ¦D Ä	D6Ä$D1Ä1D6rT   )Ú__doc__Ú
sympy.corer   r   r   r   Úsympy.polys.polyerrorsr   r   r	   r
   Úsympy.polys.polyoptionsr   r   Úsympy.polys.polytoolsr   r   Úsympy.polys.specialpolysr   r   Úsympy.polys.ringsr   Úsympy.utilitiesr   r   r   r   r<   rO   rc   rf   rU   rd   r4   ú<module>ry      s¤   ðÙ 5÷ 0Ó /÷.ó .÷ Aß 6÷(å #ß :Ñ :àñD%ó ðD%ðN ñ2ó ð2ðj ñ>Bó ð>BðB Ù)0°«ò 8Có ð8Cðv ò5ó ñ5rd   