
    wgCU                         d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd dZ d dZ!d Z"d dZ#d dZ$d Z%d!dZ&y)"a  
Sparse distributed elements of free modules over multivariate (generalized)
polynomial rings.

This code and its data structures are very much like the distributed
polynomials, except that the first "exponent" of the monomial is
a module generator index. That is, the multi-exponent ``(i, e_1, ..., e_n)``
represents the "monomial" `x_1^{e_1} \cdots x_n^{e_n} f_i` of the free module
`F` generated by `f_1, \ldots, f_r` over (a localization of) the ring
`K[x_1, \ldots, x_n]`. A module element is simply stored as a list of terms
ordered by the monomial order. Here a term is a pair of a multi-exponent and a
coefficient. In general, this coefficient should never be zero (since it can
then be omitted). The zero module element is stored as an empty list.

The main routines are ``sdm_nf_mora`` and ``sdm_groebner`` which can be used
to compute, respectively, weak normal forms and standard bases. They work with
arbitrary (not necessarily global) monomial orders.

In general, product orders have to be used to construct valid monomial orders
for modules. However, ``lex`` can be used as-is.

Note that the "level" (number of variables, i.e. parameter u+1 in
distributedpolys.py) is never needed in this code.

The main reference for this file is [SCA],
"A Singular Introduction to Commutative Algebra".
    )permutations)monomial_mulmonomial_lcmmonomial_divmonomial_deg)Poly)parallel_dict_from_expr)S)sympifyc                 .    | d   ft        || dd       z   S )aN  
    Multiply tuple ``X`` representing a monomial of `K[X]` into the tuple
    ``M`` representing a monomial of `F`.

    Examples
    ========

    Multiplying `xy^3` into `x f_1` yields `x^2 y^3 f_1`:

    >>> from sympy.polys.distributedmodules import sdm_monomial_mul
    >>> sdm_monomial_mul((1, 1, 0), (1, 3))
    (1, 2, 3)
    r      N)r   )MXs     c/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/polys/distributedmodules.pysdm_monomial_mulr   ,   s"     aD7\!QqrU+++    c                     t        | dd       S )z
    Return the total degree of ``M``.

    Examples
    ========

    For example, the total degree of `x^2 y f_5` is 3:

    >>> from sympy.polys.distributedmodules import sdm_monomial_deg
    >>> sdm_monomial_deg((5, 2, 1))
    3
    r   N)r   )r   s    r   sdm_monomial_degr   =   s     !"r   c                 4    | d   ft        | dd |dd       z   S )a  
    Return the "least common multiple" of ``A`` and ``B``.

    IF `A = M e_j` and `B = N e_j`, where `M` and `N` are polynomial monomials,
    this returns `\lcm(M, N) e_j`. Note that ``A`` and ``B`` involve distinct
    monomials.

    Otherwise the result is undefined.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_monomial_lcm
    >>> sdm_monomial_lcm((1, 2, 3), (1, 0, 5))
    (1, 2, 5)
    r   r   N)r   ABs     r   sdm_monomial_lcmr   M   s(    " aD7\!AB%12///r   c           	      `    | d   |d   k(  xr" t        d t        | dd |dd       D              S )a  
    Does there exist a (polynomial) monomial X such that XA = B?

    Examples
    ========

    Positive examples:

    In the following examples, the monomial is given in terms of x, y and the
    generator(s), f_1, f_2 etc. The tuple form of that monomial is used in
    the call to sdm_monomial_divides.
    Note: the generator appears last in the expression but first in the tuple
    and other factors appear in the same order that they appear in the monomial
    expression.

    `A = f_1` divides `B = f_1`

    >>> from sympy.polys.distributedmodules import sdm_monomial_divides
    >>> sdm_monomial_divides((1, 0, 0), (1, 0, 0))
    True

    `A = f_1` divides `B = x^2 y f_1`

    >>> sdm_monomial_divides((1, 0, 0), (1, 2, 1))
    True

    `A = xy f_5` divides `B = x^2 y f_5`

    >>> sdm_monomial_divides((5, 1, 1), (5, 2, 1))
    True

    Negative examples:

    `A = f_1` does not divide `B = f_2`

    >>> sdm_monomial_divides((1, 0, 0), (2, 0, 0))
    False

    `A = x f_1` does not divide `B = f_1`

    >>> sdm_monomial_divides((1, 1, 0), (1, 0, 0))
    False

    `A = xy^2 f_5` does not divide `B = y f_5`

    >>> sdm_monomial_divides((5, 1, 2), (5, 0, 1))
    False
    r   c              3   ,   K   | ]  \  }}||k    y wN ).0abs      r   	<genexpr>z'sdm_monomial_divides.<locals>.<genexpr>   s     E41aQEs   r   N)allzipr   s     r   sdm_monomial_dividesr$   a   s:    b Q41Q4<ECE3quae3DEEEr   c                 .    | s|j                   S | d   d   S )z*Returns the leading coefficient of ``f``. r   r   )zero)fKs     r   sdm_LCr)      s    vvtAwr   c                     t        |       S )z1Make a dictionary from a distributed polynomial. )dictr'   s    r   sdm_to_dictr-      s    7Nr   c                 Z    t        t        t        | j                               |            S )ag  
    Create an sdm from a dictionary.

    Here ``O`` is the monomial order to use.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_from_dict
    >>> from sympy.polys import QQ, lex
    >>> dic = {(1, 1, 0): QQ(1), (1, 0, 0): QQ(2), (0, 1, 0): QQ(0)}
    >>> sdm_from_dict(dic, lex)
    [((1, 1, 0), 1), ((1, 0, 0), 2)]
    )	sdm_stripsdm_sortlistitems)dOs     r   sdm_from_dictr5      s      Xd1779oq122r   c                 &    t        | fdd      S )z:Sort terms in ``f`` using the given monomial order ``O``. c                      | d         S Nr   r   )termr4   s    r   <lambda>zsdm_sort.<locals>.<lambda>   s    aQj r   Tkeyreverse)sorted)r'   r4   s    `r   r0   r0      s    !0$??r   c                 B    | D cg c]  \  }}|s	||f c}}S c c}}w )z<Remove terms with zero coefficients from ``f`` in ``K[X]``. r   )r'   monomcoeffs      r   r/   r/      s     01<uUeU^<<<s   
c                 ~    t        |       }|D ]"  \  }}||v r||   |z   }|s||= |||<   |||<   $ t        ||      S )aB  
    Add two module elements ``f``, ``g``.

    Addition is done over the ground field ``K``, monomials are ordered
    according to ``O``.

    Examples
    ========

    All examples use lexicographic order.

    `(xy f_1) + (f_2) = f_2 + xy f_1`

    >>> from sympy.polys.distributedmodules import sdm_add
    >>> from sympy.polys import lex, QQ
    >>> sdm_add([((1, 1, 1), QQ(1))], [((2, 0, 0), QQ(1))], lex, QQ)
    [((2, 0, 0), 1), ((1, 1, 1), 1)]

    `(xy f_1) + (-xy f_1)` = 0`

    >>> sdm_add([((1, 1, 1), QQ(1))], [((1, 1, 1), QQ(-1))], lex, QQ)
    []

    `(f_1) + (2f_1) = 3f_1`

    >>> sdm_add([((1, 0, 0), QQ(1))], [((1, 0, 0), QQ(2))], lex, QQ)
    [((1, 0, 0), 3)]

    `(yf_1) + (xf_1) = xf_1 + yf_1`

    >>> sdm_add([((1, 0, 1), QQ(1))], [((1, 1, 0), QQ(1))], lex, QQ)
    [((1, 1, 0), 1), ((1, 0, 1), 1)]
    )r+   r5   )r'   gr4   r(   hr@   crA   s           r   sdm_addrF      s`    D 	QA 	qA:eHqLEeH %AeH	 Ar   c                     | d   d   S )aV  
    Returns the leading monomial of ``f``.

    Only valid if `f \ne 0`.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_LM, sdm_from_dict
    >>> from sympy.polys import QQ, lex
    >>> dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(1), (4, 0, 1): QQ(1)}
    >>> sdm_LM(sdm_from_dict(dic, lex))
    (4, 0, 1)
    r   r   r,   s    r   sdm_LMrH      s     Q47Nr   c                     | d   S )aW  
    Returns the leading term of ``f``.

    Only valid if `f \ne 0`.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_LT, sdm_from_dict
    >>> from sympy.polys import QQ, lex
    >>> dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(2), (4, 0, 1): QQ(3)}
    >>> sdm_LT(sdm_from_dict(dic, lex))
    ((4, 0, 1), 3)
    r   r   r,   s    r   sdm_LTrJ     s     Q4Kr   c                     |\  }}| r|sg S |j                  |      r!| D cg c]  \  }}t        ||      |f c}}S | D cg c]  \  }}t        ||      ||z  f c}}S c c}}w c c}}w )a3  
    Multiply a distributed module element ``f`` by a (polynomial) term ``term``.

    Multiplication of coefficients is done over the ground field ``K``, and
    monomials are ordered according to ``O``.

    Examples
    ========

    `0 f_1 = 0`

    >>> from sympy.polys.distributedmodules import sdm_mul_term
    >>> from sympy.polys import lex, QQ
    >>> sdm_mul_term([((1, 0, 0), QQ(1))], ((0, 0), QQ(0)), lex, QQ)
    []

    `x 0 = 0`

    >>> sdm_mul_term([], ((1, 0), QQ(1)), lex, QQ)
    []

    `(x) (f_1) = xf_1`

    >>> sdm_mul_term([((1, 0, 0), QQ(1))], ((1, 0), QQ(1)), lex, QQ)
    [((1, 1, 0), 1)]

    `(2xy) (3x f_1 + 4y f_2) = 8xy^2 f_2 + 6x^2y f_1`

    >>> f = [((2, 0, 1), QQ(4)), ((1, 1, 0), QQ(3))]
    >>> sdm_mul_term(f, ((1, 1), QQ(2)), lex, QQ)
    [((2, 1, 2), 8), ((1, 2, 1), 6)]
    )is_oner   )r'   r9   r4   r(   r   rE   f_Mf_cs           r   sdm_mul_termrO     st    B DAqA	88A;EFHc&sA.4HHIJLXS#&sA.a8LL ILs   A"A(c                      g S )zReturn the zero module element.r   r   r   r   sdm_zerorQ   B  s    Ir   c                 &    t        d | D              S )a  
    Degree of ``f``.

    This is the maximum of the degrees of all its monomials.
    Invalid if ``f`` is zero.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_deg
    >>> sdm_deg([((1, 2, 3), 1), ((10, 0, 1), 1), ((2, 3, 4), 4)])
    7
    c              3   8   K   | ]  }t        |d            ywr   N)r   )r   r   s     r   r!   zsdm_deg.<locals>.<genexpr>U  s     1!!%1s   )maxr,   s    r   sdm_degrV   G  s     1q111r   c                     t        t        |       fi |\  }}i }t        |      D ]5  \  }}|j                         D ]  \  }	}
|j	                  |
      ||f|	z   <    7 t        ||      S )a>  
    Create an sdm from an iterable of expressions.

    Coefficients are created in the ground field ``K``, and terms are ordered
    according to monomial order ``O``. Named arguments are passed on to the
    polys conversion code and can be used to specify for example generators.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_from_vector
    >>> from sympy.abc import x, y, z
    >>> from sympy.polys import QQ, lex
    >>> sdm_from_vector([x**2+y**2, 2*z], lex, QQ)
    [((1, 0, 0, 1), 2), ((0, 2, 0, 0), 1), ((0, 0, 2, 0), 1)]
    )r	   r   	enumerater2   convertr5   )vecr4   r(   optsdicsgensdicir3   kvs              r   sdm_from_vectorrb   Z  sv    " )>>JD$
C$ )1GGI 	)DAqIIaLCqM	)) a  r   Nc           	         t        |       }i }|j                         D ].  \  }}|j                  |d   g       j                  |dd |f       0 |xs t	        |      }g }t        |      D ]]  }||v r8|j                  t        t        ||         ||      j                                ?|j                  t        j                         _ |S )a*  
    Convert sdm ``f`` into a list of polynomial expressions.

    The generators for the polynomial ring are specified via ``gens``. The rank
    of the module is guessed, or passed via ``n``. The ground field is assumed
    to be ``K``.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_to_vector
    >>> from sympy.abc import x, y, z
    >>> from sympy.polys import QQ
    >>> f = [((1, 0, 0, 1), QQ(2)), ((0, 2, 0, 0), QQ(1)), ((0, 0, 2, 0), QQ(1))]
    >>> sdm_to_vector(f, [x, y, z], QQ)
    [x**2 + y**2, 2*z]
    r   r   N)r]   domain)r-   r2   
setdefaultappendlenranger   r+   as_exprr
   Zero)	r'   r]   r(   nr^   r\   r`   ra   ress	            r   sdm_to_vectorrm   s  s    $ a.CD		 51!b!((!AB%45	SYA
C1X 9JJtDaMQ?GGIJJJqvv	
 Jr   c           	      
   | r|s
t               S t        |       }t        |      }|d   |d   k7  r
t               S |dd }|dd }t        ||      }t        ||      }t        ||      }	|j	                  t        | |       t        ||            }
t        t        | ||j                  f||      t        ||	|
f||      ||      }||S t        t        |d   ||j                  f||      t        |d   |	|
f||      ||      }||fS )a  
    Compute the generalized s-polynomial of ``f`` and ``g``.

    The ground field is assumed to be ``K``, and monomials ordered according to
    ``O``.

    This is invalid if either of ``f`` or ``g`` is zero.

    If the leading terms of `f` and `g` involve different basis elements of
    `F`, their s-poly is defined to be zero. Otherwise it is a certain linear
    combination of `f` and `g` in which the leading terms cancel.
    See [SCA, defn 2.3.6] for details.

    If ``phantom`` is not ``None``, it should be a pair of module elements on
    which to perform the same operation(s) as on ``f`` and ``g``. The in this
    case both results are returned.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_spoly
    >>> from sympy.polys import QQ, lex
    >>> f = [((2, 1, 1), QQ(1)), ((1, 0, 1), QQ(1))]
    >>> g = [((2, 3, 0), QQ(1))]
    >>> h = [((1, 2, 3), QQ(1))]
    >>> sdm_spoly(f, h, lex, QQ)
    []
    >>> sdm_spoly(f, g, lex, QQ)
    [((1, 2, 1), 1)]
    r   r   N)	rQ   rH   r   r   quor)   rF   rO   one)r'   rC   r4   r(   phantomLM1LM2lcmm1m2rE   r1r2s                r   	sdm_spolyry     s   > Az
)C
)C
1vQz
ab'C
ab'C
sC
 C	c3	B	c3	B	va|mVAq\*A	a"aeea3a"a!Q/A
7B		gaj2quu+q!<gaj2q'1a8!Q
@Br6Mr   c                 B    t        |       t        t        |             z
  S )a  
    Compute the ecart of ``f``.

    This is defined to be the difference of the total degree of `f` and the
    total degree of the leading monomial of `f` [SCA, defn 2.3.7].

    Invalid if f is zero.

    Examples
    ========

    >>> from sympy.polys.distributedmodules import sdm_ecart
    >>> sdm_ecart([((1, 2, 3), 1), ((1, 0, 1), 1)])
    0
    >>> sdm_ecart([((2, 2, 1), 1), ((1, 5, 1), 1)])
    3
    )rV   r   rH   r,   s    r   	sdm_ecartr{     s    $ 1:(333r   c           
         ddl m} | }t        |      }||d   }t        |d         }	d}n
 |g       }	d}|rt        ||	      D 
cg c]1  \  }
}t	        t        |
      t        |            r|
t        |
      |f3 }}
}|snvt        |d       \  }
}}t        |
      t        |      kD  r$|j                  |       |r|	j                         |rt        ||
|||f      \  }}nt        ||
||      }|r|r|fS |S c c}}
w )	a6  
    Compute a weak normal form of ``f`` with respect to ``G`` and order ``O``.

    The ground field is assumed to be ``K``, and monomials ordered according to
    ``O``.

    Weak normal forms are defined in [SCA, defn 2.3.3]. They are not unique.
    This function deterministically computes a weak normal form, depending on
    the order of `G`.

    The most important property of a weak normal form is the following: if
    `R` is the ring associated with the monomial ordering (if the ordering is
    global, we just have `R = K[x_1, \ldots, x_n]`, otherwise it is a certain
    localization thereof), `I` any ideal of `R` and `G` a standard basis for
    `I`, then for any `f \in R`, we have `f \in I` if and only if
    `NF(f | G) = 0`.

    This is the generalized Mora algorithm for computing weak normal forms with
    respect to arbitrary monomial orders [SCA, algorithm 2.3.9].

    If ``phantom`` is not ``None``, it should be a pair of "phantom" arguments
    on which to perform the same computations as on ``f``, ``G``, both results
    are then returned.
    r   repeatr   TFc                     | d   S )Nr   r   )xs    r   r:   zsdm_nf_mora.<locals>.<lambda>  s
    1 r   r<   rq   )
	itertoolsr~   r1   r#   r$   rH   r{   minrf   ry   )r'   Gr4   r(   rq   r~   rD   ThpTprC   gpTh_s                 r   sdm_nf_morar     s   2 !	AQAQZ'!*BZ
14Q =2%fQi; )A,# = =r~.1bQ<)A,&HHQK		"aAq2r(;EAr!Q1%A  "uH=s   6Dc                 6   ddl m} | t        |      }||d   }t        |d         }d}n
 |g       }d}rK	 t        fdt	        ||      D              \  }	}
|rt        |	|||
f      \  }nt        |	||      rK|rfS S # t
        $ r Y w xY w)a  
    Compute a weak normal form of ``f`` with respect to ``G`` and order ``O``.

    The ground field is assumed to be ``K``, and monomials ordered according to
    ``O``.

    This is the standard Buchberger algorithm for computing weak normal forms with
    respect to *global* monomial orders [SCA, algorithm 1.6.10].

    If ``phantom`` is not ``None``, it should be a pair of "phantom" arguments
    on which to perform the same computations as on ``f``, ``G``, both results
    are then returned.
    r   r}   r   TFc              3   h   K   | ])  \  }}t        t        |      t                    r||f + y wr   )r$   rH   )r   rC   r   rD   s      r   r!   z$sdm_nf_buchberger.<locals>.<genexpr>1  s4      HUQ0F1IF R Hs   /2r   )r   r~   r1   nextr#   StopIterationry   )r'   r   r4   r(   rq   r~   r   r   r   rC   r   rD   s              @r   sdm_nf_buchbergerr     s     !	AQAQZ'!*BZ
	 Hc!Rj H HEAr aAq2r(;EAr!Q1%A  "uH  		s   !B 	BBc                     t               }| }|r0t        ||||      }|rt        |t        |      g||      }|dd }|r0|S )aN  
    Compute a reduced normal form of ``f`` with respect to ``G`` and order ``O``.

    The ground field is assumed to be ``K``, and monomials ordered according to
    ``O``.

    In contrast to weak normal forms, reduced normal forms *are* unique, but
    their computation is more expensive.

    This is the standard Buchberger algorithm for computing reduced normal forms
    with respect to *global* monomial orders [SCA, algorithm 1.6.11].

    The ``pantom`` option is not supported, so this normal form cannot be used
    as a normal form for the "extended" groebner algorithm.
    r   N)rQ   r   rF   rJ   )r'   r   r4   r(   rD   rC   s         r   sdm_nf_buchberger_reducedr   >  sS      	
A	A
aAq)F1I;1-A!"A	 
 Hr   c           	      D    g }g g fdfd  fd}	 t        t        d | D              d         dz
  }g }t        |       D ]H  \  }	}
 ||
t	        |
      |      }|s|
s|j                  t        |	fd|z  z    |d      i             J |r|j                         \  }	}}}|	   |   }}
|rAt        |
||||	   ||   f      \  }} |||||f      \  }}|r)|j                  |       n |t        |
||      |      } || |	|      |      }|rt              D 	
ch c]  \  }	}
t        |
      |	f c}
}	t        d	      D ]P  \  \  }}\  }}t        |      }t        |      }t        ||      s/||fv s6||fv s= j                  ||f       R t        d
 D        fdd      }|D cg c]  }|d   	 }}|r||D 	cg c]
  \  }}	||	    c}	}fS |S # t        $ r |rg g fcY S g cY S w xY wc c}
}	w c c}w c c}	}w )a  
    Compute a minimal standard basis of ``G`` with respect to order ``O``.

    The algorithm uses a normal form ``NF``, for example ``sdm_nf_mora``.
    The ground field is assumed to be ``K``, and monomials ordered according
    to ``O``.

    Let `N` denote the submodule generated by elements of `G`. A standard
    basis for `N` is a subset `S` of `N`, such that `in(S) = in(N)`, where for
    any subset `X` of `F`, `in(X)` denotes the submodule generated by the
    initial forms of elements of `X`. [SCA, defn 2.3.2]

    A standard basis is called minimal if no subset of it is a standard basis.

    One may show that standard bases are always generating sets.

    Minimal standard bases are not unique. This algorithm computes a
    deterministic result, depending on the particular order of `G`.

    If ``extended=True``, also compute the transition matrix from the initial
    generators to the groebner basis. That is, return a list of coefficient
    vectors, expressing the elements of the groebner basis in terms of the
    elements of ``G``.

    This functions implements the "sugar" strategy, see

    Giovini et al: "One sugar cube, please" OR Selection strategies in
    Buchberger algorithm.
    c                     t        |          }t        |         }t        |    t        |      z
  |   t        |      z
        t        t        ||            z   S )z8Compute the sugar of the S-poly corresponding to (i, j).)rH   rU   r   r   )r_   jLMiLMjr
   Sugarss       r   Ssugarzsdm_groebner.<locals>.Ssugar  sb    QqTlQqTl6!9/44!9/446/S9:; 	;r   c                 ,    | d    | d         | d   fS )N      r   r   pr4   s    r   r:   zsdm_groebner.<locals>.<lambda>  s    !a!gqt, r   c                   
 | s|S t              } j                  |        j                  |       t        |       

fd}|D cg c]  } ||      r| }}t        |      D cg c]<  }
d   t        |         d   k(  r#|| ||      t	        
t        |               f> }}|j                         t               }t        |      D ]I  \  }}t        |dz   t        |            D ])  }	t        |d   ||	   d         s|j                  |	       + K |j                  t        t        |      D cg c]  \  }}||vs| c}}             |j                  d       |S c c}w c c}w c c}}w )z*Add f with sugar ``sugar`` to S, update P.c                     | \  }}}}d   |d   k7  ryt        t        |               }t        t        |               }||k7  xr! ||k7  xr t        ||      xr t        ||      S )Nr   F)r   rH   r$   )	pairr_   r   sttiktjkLMfr
   s	          r   
removethisz0sdm_groebner.<locals>.update.<locals>.removethis  s    JAq!Q1v1~"3qt5C"3qt5C!8 -q --A#q-I -$S!,-r   r   r   r   r   Tr;   )rg   rf   rH   rh   r   sortsetrX   r$   addextendreversed)r'   sugarPr`   r   r   r_   Nremover   r   r
   r   r   ourkeys             @r   updatezsdm_groebner.<locals>.update  sm   HFeQi	- /1AQ// Ah=#a&F1Q4LO"; F1aL"23qt"EF = = 	
6aL 	"DAq1q5#a&) "'!ad1g6JJqM"	" 	
1IA&1IJK	64(# 0= Js   
E1E1+AE6?E;E;c              3   ,   K   | ]  }|s|d      ywrT   r   )r   r   s     r   r!   zsdm_groebner.<locals>.<genexpr>  s     0Aa1Q40s   
r   r   )r   r   r   c              3   <   K   | ]  \  }}t        |      |f  y wr   )r1   )r   r'   r_   s      r   r!   zsdm_groebner.<locals>.<genexpr>  s     +Aa!+s   c                 ,     t        | d               S r8   )rH   r   s    r   r:   zsdm_groebner.<locals>.<lambda>  s    1VAaD\? r   Tr;   )rg   r   r   rX   rV   rf   r5   popry   tupler   rH   r$   r   r>   )!r   NFr4   r(   extendedr   r   numgenscoefficientsr_   r'   r   r   r   rC   sprA   rD   hcoeffr   air    bir   r   Lr   rl   r   r
   r   r   r   s!     `                          @@@@r   sdm_groebnerr   X  sr   F 	A 	AF; -F$N	 d00034q8 L ! O11gaj!$td7l/BAaD.I1 MNO UUW
1atQqT1!!Q1+7?LO*LNIB2q!Q0EFIAv##F+9Q1a(!Q2A1fQlA&  $-Q<041a%(A0A(A. B!R1I1I1%1b'Q,Ar7a<AHHaW	 	++1J	A
A1Q4
C
3A\!_333JY  r6M		@ 	1 3s)   !G8 6HH"H8H	HHr   )F)'__doc__r   r   sympy.polys.monomialsr   r   r   r   sympy.polys.polytoolsr   sympy.polys.polyutilsr	   sympy.core.singletonr
   sympy.core.sympifyr   r   r   r   r$   r)   r-   r5   r0   r/   rF   rH   rJ   rO   rQ   rV   rb   rm   ry   r{   r   r   r   r   r   r   r   <module>r      s   : #  ' 9 " &
," 0(1Fl
3$@
=
/d$$)MX
2&!2D1h4*5p%P4Kr   