+
    i;                         R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHt ^ RIHt  ! R R4      t ! R R4      tR# )a  
This module contains functions for two multivariate resultants. These
are:

- Dixon's resultant.
- Macaulay's resultant.

Multivariate resultants are used to identify whether a multivariate
system has common roots. That is when the resultant is equal to zero.
)prod)Mul)Matrixdiag)Polydegree_listrem)simplify)IndexedBase)itermonomialsmonomial_deg)monomial_key)poly_from_exprtotal_degree)binomial)combinations_with_replacement)sympy_deprecation_warningc                   j   a  ] tR t^t o RtR t]R 4       tR tR t	R t
R tR tR	 tR
 tR tRtV tR# )DixonResultanta  
A class for retrieving the Dixon's resultant of a multivariate
system.

Examples
========

>>> from sympy import symbols

>>> from sympy.polys.multivariate_resultants import DixonResultant
>>> x, y = symbols('x, y')

>>> p = x + y
>>> q = x ** 2 + y ** 3
>>> h = x ** 2 + y

>>> dixon = DixonResultant(variables=[x, y], polynomials=[p, q, h])
>>> poly = dixon.get_dixon_polynomial()
>>> matrix = dixon.get_dixon_matrix(polynomial=poly)
>>> matrix
Matrix([
[ 0,  0, -1,  0, -1],
[ 0, -1,  0, -1,  0],
[-1,  0,  1,  0,  0],
[ 0, -1,  0,  0,  1],
[-1,  0,  0,  1,  0]])
>>> matrix.det()
0

See Also
========

Notebook in examples: sympy/example/notebooks.

References
==========

.. [1] [Kapur1994]_
.. [2] [Palancz08]_

c                  a Wn         W n        \        V P                  4      V n        \        V P                   4      V n        \        R4      p\        V P                  4       Uu. uF  qCV,          NK  	  upV n        \        V P                  4       Uau. uF"  o\        V3R lV P                    4       4      NK$  	  upV n	        R# u upi u upi )a  
A class that takes two lists, a list of polynomials and list of
variables. Returns the Dixon matrix of the multivariate system.

Parameters
----------
polynomials : list of polynomials
    A  list of m n-degree polynomials
variables: list
    A list of all n variables
alphac              3   H   <"   T F  p\        V4      S,          x  K  	  R # 5i)N)r   ).0polyis   & ڃ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/multivariate_resultants.py	<genexpr>*DixonResultant.__init__.<locals>.<genexpr>[   s       SBR$T!21!5!5BRs   "N)
polynomials	variableslennmr
   rangedummy_variablesmax_max_degrees)selfr   r   ar   s   &&& `r   __init__DixonResultant.__init__D   s     '"T^^$T%%& .3DFFm<m!m< 466]$" ! S$BRBR SS"$  =$s   $C(Cc                6    \        R RRR7       V P                  # )zS
            The max_degrees property of DixonResultant is deprecated.
            1.5$deprecated-dixonresultant-propertiesdeprecated_since_versionactive_deprecations_target)r   r&   r'   s   &r   max_degreesDixonResultant.max_degrees^   s%    ! &+'M	
        c           	        V P                   V P                  ^,           8w  d   \        R4      hV P                  .p\	        V P
                  4      p\        V P                  4       Fp  pV P                  V,          W#&   \        \        V P
                  V4      4      pTP                  V P                   Uu. uF  qUP                  V4      NK  	  up4       Kr  	  \        V4      p\        V P
                  V P                  4      p\        V UU	u. uF  w  rW,
          NK  	  up	p!  p
VP                  4       V
,          P                  4       p\!        WP                  4      ^ ,          # u upi u up	pi )ab  
Returns
=======

dixon_polynomial: polynomial
    Dixon's polynomial is calculated as:

    delta = Delta(A) / ((x_1 - a_1) ... (x_n - a_n)) where,

    A =  |p_1(x_1,... x_n), ..., p_n(x_1,... x_n)|
         |p_1(a_1,... x_n), ..., p_n(a_1,... x_n)|
         |...             , ...,              ...|
         |p_1(a_1,... a_n), ..., p_n(a_1,... a_n)|
z%Method invalid for given combination.)r"   r!   
ValueErrorr   listr   r#   r$   dictzipappendsubsr   r   detfactorr   )r'   rowstempidxsubstitutionfAtermsr(   bproduct_of_differencesdixon_polynomials   &           r   get_dixon_polynomial#DixonResultant.get_dixon_polynomiali   s$    66dffqj!DEE   !DNN#=C,,S1DIDNND 9:LKKt7G7GH7G!-7GHI !
 4LDNND$8$89!$&?quu&?!@EEG&<<DDF.0D0DEaHH I
 '@s   5E(
E-
c                   \        R RRR7       \        V P                  4       Uu. uF.  pV P                  V,          V P                  V,          ,          NK0  	  pp\        V4      p\        V4      P                  4       p\        V!  # u upi )z
            The get_upper_degree() method of DixonResultant is deprecated. Use
            get_max_degrees() instead.
            r,   r-   r.   )	r   r#   r!   r   r&   r   r   monomsr   )r'   r   list_of_productsproducts   &   r   get_upper_degreeDixonResultant.get_upper_degree   s    ! &+'M	
 &+466]4%2 !NN1-1B1B11EEE%2 	 4'(w-&&(W%%4s   4B	c           	         VP                  4        Uu. uF!  p\        \        W P                  4      4      NK#  	  pp\	        V!   Uu. uF  p\        V4      NK  	  ppV# u upi u upi )z
Returns a list of the maximum degree of each variable appearing
in the coefficients of the Dixon polynomial. The coefficients are
viewed as polys in $x_1, x_2, \dots, x_n$.
)coeffsr   r   r   r9   r%   )r'   
polynomialr   	deg_listsdegsr2   s   &&    r   get_max_degreesDixonResultant.get_max_degrees   si     ",!2!2!46!4 !dNN!;<!4 	 6 .1)_=_Ts4y_=6 >s   'AA$c                   V P                  V4      p\        V P                  V4      p\        VR\	        RV P                  4      R7      p\        VP                  4        UUu. uF9  pV Uu. uF)  p\        V.V P                  O5!  P                  V4      NK+  	  upNK;  	  upp4      pVP                  ^ ,          VP                  ^,          8w  d   \        VP                  R,          4       Uu. uFS  p\        ;QJ d%    R VRV3,           4       F  '       g   K   RM	  RM! R VRV3,           4       4      '       g   KQ  VNKU  	  ppVRV3,          pV# u upi u uppi u upi )z
Construct the Dixon matrix from the coefficients of polynomial
\alpha. Each coefficient is viewed as a polynomial of x_1, ...,
x_n.
Tlexreversekeyc              3   *   "   T F	  q^ 8g  x  K  	  R# 5i    N )r   elements   & r   r   2DixonResultant.get_dixon_matrix.<locals>.<genexpr>   s      42 -4a<2s   NNNF)rU   r   r   sortedr   r   rQ   r   coeff_monomialshaper#   any)	r'   rR   r2   	monomialscr"   dixon_matrixcolumnkeeps	   &&       r   get_dixon_matrixDixonResultant.get_dixon_matrix   sT    **:6 "$..+>	9d+E4>>BD	 )3):):)<>)<A *3 4)2A !%Q 8 8 G G J)2 4)<> ?
 a L$6$6q$99).|/A/A"/E)F 5)Fvs 4'6	24sss 4'6	24 4 F)FD 5 (40L 4 >5s0   "	E
+/EE
0E# E#!E#E#E
c           	       aa SP                   '       d   R# SP                  w  r#\        SP                  4       ^ ,          4      o\	        V4       Uau. uF[  o\
        ;QJ d)    VV3R l\	        V4       4       F  '       g   K   RM	  RM! VV3R l\	        V4       4       4      '       g   KY  SNK]  	  ppSVR3,          o\        ^ .V^,
          ,          ^.,           .4      pSR,          V8X  d   R# R# u upi )aw  
Test for the validity of the Kapur-Saxena-Yang precondition.

The precondition requires that the column corresponding to the
monomial 1 = x_1 ^ 0 * x_2 ^ 0 * ... * x_n ^ 0 is not a linear
combination of the remaining ones. In SymPy notation this is
the last column. For the precondition to hold the last non-zero
row of the rref matrix should be of the form [0, 0, ..., 1].
Fc              3   @   <"   T F  pSSV3,          ^ 8g  x  K  	  R# 5ir]   r_   )r   jr   matrixs   & r   r   2DixonResultant.KSY_precondition.<locals>.<genexpr>   s     *Oh6!Q$<1+<hs   Trb   )rc   rb   )is_zero_matrixrf   r	   rrefr#   rg   r   )r'   rr   r"   r!   r   r>   	conditions   &f  `  r   KSY_preconditionDixonResultant.KSY_precondition   s        || &++-*+ 8P8ass*OeAh*Osss*OeAh*O'O8PQQC1IO,-	$<9$ Qs   C6#C6%C6.C6c                B   \        VP                  4       Uu. uF'  q!P                  V4      P                  '       d   K%  VNK)  	  pp\        VP                  4       Uu. uF'  qAP                  V4      P                  '       d   K%  VNK)  	  ppWV3,          # u upi u upi )z/Remove the zero rows and columns of the matrix.)r#   r>   rowrt   colscol)r'   rr   r   r>   rq   r{   s   &&    r   delete_zero_rows_and_columns+DixonResultant.delete_zero_rows_and_columns   s     V[[)O)!A1M1MAA) 	 O V[[)O)!A1M1MAA) 	 O Dj!!OOs   "BB"BBc                    ^p\        VP                  4       F-  pVP                  V4       F  pV^ 8w  g   K  W$,          p K+  	  K/  	  V# )z;Calculate the product of the leading entries of the matrix.)r#   r>   rz   )r'   rr   resrz   els   &&   r   product_leading_entries&DixonResultant.product_leading_entries   sD    %Cjjo7(C & &
 
r4   c                    V P                  V4      pVP                  4       w  r#pV P                  \        V4      4      pV P                  V4      # )z@Calculate the Kapur-Saxena-Yang approach to the Dixon Resultant.)r}   LUdecompositionr	   r   )r'   rr   _Us   &&  r   get_KSY_Dixon_resultant&DixonResultant.get_KSY_Dixon_resultant   sI    226:((*a228A;?++F33r4   )r&   r$   r"   r!   r   r   N)__name__
__module____qualname____firstlineno____doc__r)   propertyr2   rH   rN   rU   rm   rw   r}   r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      sS     (T$4 ! !"IH& 86"4 4r4   r   c                   T   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
tV tR# )MacaulayResultanta  
A class for calculating the Macaulay resultant. Note that the
polynomials must be homogenized and their coefficients must be
given as symbols.

Examples
========

>>> from sympy import symbols

>>> from sympy.polys.multivariate_resultants import MacaulayResultant
>>> x, y, z = symbols('x, y, z')

>>> a_0, a_1, a_2 = symbols('a_0, a_1, a_2')
>>> b_0, b_1, b_2 = symbols('b_0, b_1, b_2')
>>> c_0, c_1, c_2,c_3, c_4 = symbols('c_0, c_1, c_2, c_3, c_4')

>>> f = a_0 * y -  a_1 * x + a_2 * z
>>> g = b_1 * x ** 2 + b_0 * y ** 2 - b_2 * z ** 2
>>> h = c_0 * y * z ** 2 - c_1 * x ** 3 + c_2 * x ** 2 * z - c_3 * x * z ** 2 + c_4 * z ** 3

>>> mac = MacaulayResultant(polynomials=[f, g, h], variables=[x, y, z])
>>> mac.monomial_set
[x**4, x**3*y, x**3*z, x**2*y**2, x**2*y*z, x**2*z**2, x*y**3,
x*y**2*z, x*y*z**2, x*z**3, y**4, y**3*z, y**2*z**2, y*z**3, z**4]
>>> matrix = mac.get_matrix()
>>> submatrix = mac.get_submatrix(matrix)
>>> submatrix
Matrix([
[-a_1,  a_0,  a_2,    0],
[   0, -a_1,    0,    0],
[   0,    0, -a_1,    0],
[   0,    0,    0, -a_1]])

See Also
========

Notebook in examples: sympy/example/notebooks.

References
==========

.. [1] [Bruce97]_
.. [2] [Stiller96]_

c                H   Wn         W n        \        V4      V n        V P                    Uu. uF  p\	        V.V P                  O5!  NK  	  upV n        V P                  4       V n        V P                  4       V n	        V P                  V P                  4      V n        R# u upi )z
Parameters
==========

variables: list
    A list of all n variables
polynomials : list of SymPy polynomials
    A  list of m n-degree polynomials
N)r   r   r    r!   r   degrees_get_degree_mdegree_mget_sizemonomials_sizeget_monomials_of_certain_degreemonomial_set)r'   r   r   r   s   &&& r   r)   MacaulayResultant.__init__+  s     '"Y  ++-+ AET;DNN;+- **,"mmo !@@O-s    Bc                H    ^\        R V P                   4       4      ,           # )z
Returns
=======

degree_m: int
    The degree_m is calculated as  1 + \sum_1 ^ n (d_i - 1),
    where d_i is the degree of the i polynomial
c              3   2   "   T F  q^,
          x  K  	  R# 5i)   Nr_   )r   ds   & r   r   2MacaulayResultant._get_degree_m.<locals>.<genexpr>L  s     3l1uuls   )sumr   r1   s   &r   r   MacaulayResultant._get_degree_mC  s     33dll3333r4   c                    \        V P                  V P                  ,           ^,
          V P                  ^,
          4      # )z
Returns
=======

size: int
    The size of set T. Set T is the set of all possible
    monomials of the n variables for degree equal to the
    degree_m
)r   r   r!   r1   s   &r   r   MacaulayResultant.get_sizeN  s+     .2DFFQJ??r4   c                    \        V P                  V4       Uu. uF  p\        V!  NK  	  pp\        VR\	        RV P                  4      R7      # u upi )zO
Returns
=======

monomials: list
    A list of monomials of a certain degree.
TrX   rY   )r   r   r   rd   r   )r'   degreemonomialrh   s   &&  r   r   1MacaulayResultant.get_monomials_of_certain_degreeZ  s`     6dnn6<>?> )1S(^> 	 ? i&udnn=? 	?	?s   Ac                   . p. p\        V P                  4       EF  pV^ 8X  dI   V P                  V P                  V,          ,
          pV P	                  V4      pVP                  V4       KS  VP                  V P                  V^,
          ,          V P                  V^,
          ,          ,          4       V P                  V P                  V,          ,
          pV P	                  V4      pV F7  pV F.  p\        W4      ^ 8X  g   K  V U	u. uF  p	W8w  g   K  V	NK  	  pp	K0  	  K9  	  VP                  V4       EK!  	  V# u up	i )zW
Returns
=======

row_coefficients: list
    The row coefficients of Macaulay's matrix
)r#   r!   r   r   r   r:   r   r   )
r'   row_coefficients	divisibler   r   r   	poss_rowsdivpitems
   &         r   get_row_coefficients&MacaulayResultant.get_row_coefficientsi  s    	tvvAAva8??G ''1  A!6!%a!e!4"5 6a8 @@H	$C&q;!+:C )7)$,0I *.)I )7I ' %
 !''	2    )7s   
D?
D?
c                   . pV P                  4       p\        V P                  4       F  pW#,           Fx  p. p\        V P                  V,          V,          .V P
                  O5!  pV P                   F#  pVP                  VP                  V4      4       K%  	  VP                  V4       Kz  	  K  	  \        V4      pV# )zL
Returns
=======

macaulay_matrix: Matrix
    The Macaulay numerator matrix
)
r   r#   r!   r   r   r   r   r:   re   r   )	r'   r>   r   r   
multipliercoefficientsr   monomacaulay_matrixs	   &        r   
get_matrixMacaulayResultant.get_matrix  s     446tvvA.11
!D,,Q/*< -!^^- !--D ''(;(;D(AB .L) 2  !,r4   c           
        . pV P                    Fk  p. p\        V P                  4       F<  w  rEVP                  \	        \        W%4      V P                  V,          8  4      4       K>  	  VP                  V4       Km  	  \        V4       UUu. uF*  w  rF\        V4      V P                  ^,
          8  g   K(  VNK,  	  ppp\        V4       UUu. uF*  w  rF\        V4      V P                  ^,
          8  g   K(  VNK,  	  pppWx3# u uppi u uppi )ak  
Returns
=======

reduced: list
    A list of the reduced monomials
non_reduced: list
    A list of the monomials that are not reduced

Definition
==========

A polynomial is said to be reduced in x_i, if its degree (the
maximum degree of its monomials) in x_i is less than d_i. A
polynomial that is reduced in all variables but one is said
simply to be reduced.
)	r   	enumerater   r:   boolr   r   r   r!   )	r'   r   r"   r?   r   vrreducednon_reduceds	   &        r   get_reduced_nonreduced(MacaulayResultant.get_reduced_nonreduced  s    $ 	""AD!$..1Da!3t||A!FGH 2T"	 #
 "+9!5 +!5!ftvvz) 1!5 +%.y%9 /%9TQa&DFFAI- q%9 / ##+/s   %D6D%D	7D	c                N   V P                  4       w  r#V. 8X  d   \        ^.4      # \        V P                  4       UUu. uF  w  rEWPP                  V,          ,          NK   	  ppp\        V P                  4       Uu. uF+  pV P                  V,          P                  Wd,          4      NK-  	  ppVRV3,          p. p	\        VP                  4       F8  p
V Uu. uF  qWR3,          9   NK  	  ppRV9  g   K'  V	P                  V
4       K:  	  WV3,          # u uppi u upi u upi )z
Returns
=======

macaulay_submatrix: Matrix
    The Macaulay denominator matrix. Columns that are non reduced are kept.
    The row which contains one of the a_{i}s is dropped. a_{i}s
    are the coefficients of x_i ^ {d_i}.
rb   T)r   r   r   r   r   r#   r!   r   coeffr>   r:   )r'   rr   r   r   r   r   reduction_setaisreduced_matrixrl   rz   aichecks   &&           r   get_submatrixMacaulayResultant.get_submatrix  s$     $::< b=9 &dnn575 37!ll1o--5 	 7 dff'%1 "(()9:% 	 '  7
+,,-C<?@Cb>q&11CE@5 C  .
 K'((7' As   $D<1DD")r   r   r   r   r!   r   r   N)r   r   r   r   r   r)   r   r   r   r   r   r   r   r   r   r   s   @r   r   r      s:     -\P0	4
@? 8.$>) )r4   r   N)r   mathr   sympy.core.mulr   sympy.matrices.denser   r   sympy.polys.polytoolsr   r   r   sympy.simplify.simplifyr	   sympy.tensor.indexedr
   sympy.polys.monomialsr   r   sympy.polys.orderingsr   r   r   (sympy.functions.combinatorial.factorialsr   	itertoolsr   sympy.utilities.exceptionsr   r   r   r_   r4   r   <module>r      sL   	   / : : , , = . > = 3 @a4 a4F]) ])r4   