§
    OŠtjc!  ã                   ó  — 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dS )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                 óp  ‡— t          |ddg¦  «         d}t          | d¦  «        sd}| g} t          | g|¢R i |¤Ž\  }} |j        }t	          ||¦  «        }|j        Šˆfd„t          t          |¦  «        ¦  «        D ¦   «         Šg }| D ]A}|                     ¦   «         \  }}	}
|                      |j	        ‰Ž  |	j	        |Ž f¦  «         ŒBd„ t          ‰|
¦  «        D ¦   «         }|j        s2t          |¦  «        D ]"\  }\  }}|                     |¦  «        |f||<   Œ#|s|\  }|j        s|S |r||fS ||fz   S )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__Fc                 ó.   •— g | ]}t          ‰¦  «        ‘ŒS © )Únext)Ú.0Úir   s     €úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/polys/polyfuncs.pyú
<listcomp>zsymmetrize.<locals>.<listcomp>=   s   ø€ Ð7Ð7Ð7 �t�G‰}Œ}Ð7Ð7Ð7ó    c                 óF   — g | ]\  }\  }}||                      ¦   «         f‘ŒS r   )Úas_expr)r   ÚsÚ_Úgs       r   r   zsymmetrize.<locals>.<listcomp>E   s-   € Ð?Ð?Ð?¡) !¡V a¨ˆa�—’‘”ÐÐ?Ð?Ð?r   )r   Úhasattrr   r   r   ÚrangeÚlenÚ
symmetrizeÚappendr!   Úzipr   Ú	enumerateÚsubs)ÚFÚgensÚargsÚiterableÚRÚoptÚresultÚfÚpÚrÚmÚpolysr   ÚsymÚnon_symr   s                  @r   r(   r(      s’  ø€ õB �$˜ 9Ð-Ñ.Ô.Ð.à€Hå�1�jÑ!Ô!ð ØˆØˆCˆå�Ð"�TÐ"Ð"Ð"˜TÐ"Ð"�D€A€qØŒ9€Då
˜˜dÑ
#Ô
#€CØŒk€GØ7Ð7Ð7Ð7¥e­C°©I¬IÑ&6Ô&6Ð7Ñ7Ô7€Gà€Fàð ?ð ?ˆØ—,’,‘.”.‰ˆˆ1ˆaØ�Š�y�q”y 'Ð*¨I¨A¬I°tÐ,<Ð=Ñ>Ô>Ð>Ð>à?Ð?­s°7¸A©¬Ð?Ñ?Ô?€EàŒ:ð 3Ý!*¨6Ñ!2Ô!2ð 	3ð 	3ÑˆA‰~��WØŸš %™œ¨'Ð2ˆF�1‰IˆIàð Ø‰ˆàŒ:ð %Øˆàð 	%Ø˜5�=Ð à˜U˜HÑ$Ð$r   c                 óŽ  — t          |g ¦  «         	 t          | g|¢R i |¤Ž\  }}n# t          $ r}|j        cY d}~S d}~ww xY wt          j        |j        }}|j        r |                     ¦   «         D ]
}||z  |z   }ŒnGt          ||¦  «        |dd…         }}|                     ¦   «         D ]}||z  t          |g|¢R i |¤Žz   }Œ|S )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)	r4   r.   r/   r-   r2   ÚexcÚformr?   Úcoeffs	            r   rB   rB   W   s  € õB �$˜ÑÔÐðÝ Ð1 DÐ1Ð1Ð1¨DÐ1Ð1‰ˆˆ3ˆ3øÝð ð ð ØŒxˆˆˆˆˆˆøøøøðøøøõ ”˜œˆ#€Dà„ð ;Ø—\’\‘^”^ð 	$ð 	$ˆEØ˜‘8˜eÑ#ˆDˆDð	$õ �q˜#‘,”,  Q R R¤ˆ4ˆà—\’\‘^”^ð 	;ð 	;ˆEØ˜‘8�f UÐ:¨TÐ:Ð:Ð:°TÐ:Ð:Ñ:ˆDˆDà€Ks   ’& ¦
A°<¶A¼Ac                 óD  — t          | ¦  «        }t          | t          ¦  «        rE|| v rt          | |         ¦  «        S t	          t          |                      ¦   «         Ž ¦  «        \  }}n½t          | d         t          ¦  «        rFt	          t          | Ž ¦  «        \  }}||v r(t          ||                     |¦  «                 ¦  «        S n\|t          d|dz   ¦  «        v rt          | |dz
           ¦  «        S t	          | ¦  «        }t	          t          d|dz   ¦  «        ¦  «        }	 t          ||||¦  «                             ¦   «         S # t          $ rI t          ¦   «         }t          ||||¦  «                             ¦   «                              ||¦  «        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   r<   )r'   Ú
isinstanceÚdictr   Úlistr*   ÚitemsÚtupleÚindexr&   r   ÚexpandÚ
ValueErrorr   r,   )ÚdataÚxÚnÚXÚYÚds         r   ÚinterpolaterU   �   s…  € õT 	ˆD‰	Œ	€Aå�$�ÑÔð &Ø�ˆ9ˆ9Ý�T˜!”W‘:”:ÐÝ•C˜Ÿš™œÐ&Ñ'Ô'‰ˆˆ1ˆ1å�d˜1”g�uÑ%Ô%ð 	&Ý�˜T˜
Ñ#Ô#‰DˆAˆqØ�AˆvˆvÝ˜˜1Ÿ7š7 1™:œ:œÑ'Ô'Ð'ð ð •E˜!˜Q ™U‘O”OÐ#Ð#Ý˜˜a !™eœ‘~”~Ð%Ý�T‘
”
ˆAÝ•U˜1˜a !™e‘_”_Ñ%Ô%ˆAðBÝ! ! Q¨¨1Ñ-Ô-×4Ò4Ñ6Ô6Ð6øÝð Bð Bð BÝ‰GŒGˆÝ! ! Q¨¨1Ñ-Ô-×4Ò4Ñ6Ô6×;Ò;¸A¸qÑAÔAÐAÐAÐAðBøøøs   Ä(#E ÅAFÆFrP   c                 óü  ‡‡‡
— ddl m} t          t          | Ž ¦  «        \  }}t	          |¦  «        ‰z
  dz
  }|dk     rt          d¦  «        ‚ |‰|z   dz   ‰|z   dz   ¦  «        }t          t          ‰|¦  «        ¦  «        D ]5}t          ‰|z   dz   ¦  «        D ]}	||	|f         ||	         z  ||	|dz   f<   ŒŒ6t          |dz   ¦  «        D ]?}t          ‰|z   dz   ¦  «        D ]'}	||	||z
  f          ||	         z  ||	‰|z   dz   |z
  f<   Œ(Œ@|                     ¦   «         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   )Úonesr<   z'Too few values for the required degree.é   c              3   ó4   •K  — | ]}‰|         ‰|z  z  V — Œd S ©Nr   )r   r   rR   r6   s     €€r   ú	<genexpr>z'rational_interpolate.<locals>.<genexpr>  s/   øè è € Ð7Ð7 ��!”�q˜!‘t‘Ð7Ð7Ð7Ð7Ð7Ð7r   c              3   ó@   •K  — | ]}‰|‰z   d z            ‰|z  z  V — ŒdS )r<   Nr   )r   r   rR   Údegnumr6   s     €€€r   r[   z'rational_interpolate.<locals>.<genexpr>  s9   øè è € ÐAÐA¨q�!�A˜‘J ‘NÔ# a¨¡dÑ*ÐAÐAÐAÐAÐAÐAr   )
Úsympy.matrices.denserW   rI   r*   r'   r
   r&   ÚmaxÚ	nullspaceÚsum)rO   r]   rR   rW   ÚxdataÚydataÚkÚcÚjr   r6   s    ``       @r   Úrational_interpolaterg   Ï   sÔ  øøø€ ðR *Ð)Ð)Ð)Ð)Ð)å�˜T˜
Ñ#Ô#�L€Eˆ5åˆE‰
Œ
�VÑ˜aÑ€AØˆ1‚u€uÝÐCÑDÔDÐDØˆˆV�a‰Z˜!‰^˜V a™Z¨!™^Ñ,Ô,€AÝ•3�v˜q‘>”>Ñ"Ô"ð +ð +ˆÝ�v ‘z A‘~Ñ&Ô&ð 	+ð 	+ˆAØ˜A˜q˜Dœ' %¨¤(Ñ*ˆAˆa��Q‘ˆh‰KˆKð	+å�1�q‘5‰\Œ\ð =ð =ˆÝ�v ‘z A‘~Ñ&Ô&ð 	=ð 	=ˆAØ()¨!¨Q°©U¨(¬ |°E¸!´HÑ'<ˆAˆa�˜!‘˜a‘ !Ñ#Ð#Ñ$Ð$ð	=à	�Š‰Œ�aÔ€AÝÐ7Ð7Ð7Ð7Ð7¥U¨6°A©:Ñ%6Ô%6Ð7Ñ7Ô7Ñ7Ô7ÝÐAÐAÐAÐAÐAÐAµE¸!¸a¹%±L´LÐAÑAÔAÑAÔAñBð Cr   Nc                 óú  — t          |g ¦  «         t          |t          ¦  «        r|f|z   d}}	 t          | g|¢R i |¤Ž\  } }n## t          $ r}t          dd|¦  «        ‚d}~ww xY w| j        rt          d¦  «        ‚|                      ¦   «         }|dk     rt          d¦  «        ‚|€t          dd¬¦  «        }t          ||¦  «        }|t          |¦  «        k    r"t          d|›d	t          |¦  «        ›�¦  «        ‚|                      ¦   «         |                      ¦   «         }}g d
}
}	t          |dd…         ¦  «        D ]:\  }}t!          |dz   |¦  «        }|
||z  z  }|	                     ||f¦  «         |
 }
Œ;|	S )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Úvieter<   z(multivariate polynomials are not allowedz8Cannot derive Viete's formulas for a constant polynomialr6   )Ústartz	required z roots, got éÿÿÿÿ)r   rG   r   r   r   r   Úis_multivariater	   ÚdegreerN   r   r   r'   ÚLCrA   r+   r   r)   )r4   Úrootsr.   r/   r2   rC   rQ   ÚlcÚcoeffsr3   Úsignr   rE   Úpolys                 r   ri   ri     s¿  € õ" �$˜ÑÔÐå�%�ÑÔð ,Ø�h ‘o tˆeˆð1Ý Ð1 DÐ1Ð1Ð1¨DÐ1Ð1‰ˆˆ3ˆ3øÝð 1ð 1ð 1Ý ¨¨CÑ0Ô0Ð0øøøøð1øøøð 	Ôð 8Ý)Ø6ñ8ô 8ð 	8ð 	
�Š‰
Œ
€Aàˆ1‚u€uÝØFñHô Hð 	Hð €}Ý  ¨AÐ.Ñ.Ô.ˆå�˜‰NŒN€Eà�C�‰JŒJ‚€Ýˆj¸¸¸½3¸u¹:¼:¸:ÐFÑGÔGÐGà—’‘”˜Ÿš™œˆ€BØ�rˆD€Få˜f Q R RœjÑ)Ô)ð ð ‰ˆˆ5Ý˜a !™e UÑ+Ô+ˆØ�e˜B‘h‘ˆØ�Š�t˜U�mÑ$Ô$Ð$Øˆuˆˆà€Ms   ¯A Á
A#ÁAÁA#rZ   )Ú__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(   rB   rU   rg   ri   r   r   r   ú<module>r|      sª  ðØ 5Ð 5ð 0Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /ð.ð .ð .ð .ð .ð .ð .ð .ð .ð .ð .ð .ð AÐ @Ð @Ð @Ð @Ð @Ð @Ð @Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6ð(ð (ð (ð (ð (ð (ð (ð (à #Ð #Ð #Ð #Ð #Ð #Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :àðD%ð D%ñ „ðD%ðN ð2ð 2ñ „ð2ðj ð>Bð >Bñ „ð>BðB Ø)0¨°©¬ð 8Cð 8Cð 8Cñ „ð8Cðv ð5ð 5ð 5ñ „ð5ð 5ð 5r   