
    \h j                       S r SSKJr  SSKJr  SSKJrJr  SSKrSSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJr  SSKJr  SSKJr  SSKJrJr  SSK J!r!J"r"J#r#J$r$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+  SSK,J-r-  SSKJ.r.J/r/  SSK0J1r1   " S S\25      r3SS.S jr4S r5S*S jr6S r7S+S,S jjr8S-S  jr9S+S.S! jjr:S+S,S" jjr;        S/S# jr<S0S$ jr=S1S% jr>S1S& jr?S2S' jr@S( rAS) rBg)3z,Solvers of systems of polynomial equations.     )annotations)Any)SequenceIterableN)Dummy)S)Expr)factor_terms)default_sort_key)Boolean)Polygroebnerroots)ZZ)build_options)parallel_poly_from_exprsqf_part)ComputationFailedPolificationFailedCoercionFailedGeneratorsNeededDomainError)rcollect)	postfixes)cartes)
filldedent)OrAnd)Eqc                      \ rS rSrSrSrg)SolveFailed#   z.Raised when solver's conditions were not met.  N)__name__
__module____qualname____firstlineno____doc____static_attributes__r#       M/var/www/auris/envauris/lib/python3.13/site-packages/sympy/solvers/polysys.pyr!   r!   #   s    8r*   r!   Fstrictc                   [        U /UQ70 UD6u  pE[        U5      [        UR                  5      s=:X  a  S:X  aJ  O  OGUu  px[        S UR                  5       UR                  5       -    5       5      (       a   [        XxU5      $ [        XEUS9$ ! [         a  n[        S[        U 5      U5      eSnAff = f! [         a     N>f = f)aH  
Return a list of solutions for the system of polynomial equations
or else None.

Parameters
==========

seq: a list/tuple/set
    Listing all the equations that are needed to be solved
gens: generators
    generators of the equations in seq for which we want the
    solutions
strict: a boolean (default is False)
    if strict is True, NotImplementedError will be raised if
    the solution is known to be incomplete (which can occur if
    not all solutions are expressible in radicals)
args: Keyword arguments
    Special options for solving the equations.


Returns
=======

List[Tuple]
    a list of tuples with elements being solutions for the
    symbols in the order they were passed as gens
None
    None is returned when the computed basis contains only the ground.

Examples
========

>>> from sympy import solve_poly_system
>>> from sympy.abc import x, y

>>> solve_poly_system([x*y - 2*y, 2*y**2 - x**2], x, y)
[(0, 0), (2, -sqrt(2)), (2, sqrt(2))]

>>> solve_poly_system([x**5 - x + y**3, y**2 - 1], x, y, strict=True)
Traceback (most recent call last):
...
UnsolvableFactorError

solve_poly_systemN   c              3  *   #    U  H	  oS :*  v   M     g7f)r0   Nr#   ).0is     r+   	<genexpr>$solve_poly_system.<locals>.<genexpr>\   s     A@!Av@   r,   )
r   r   r   lengensalldegree_listsolve_biquadraticr!   solve_generic)	seqr-   r8   argspolysoptexcfgs	            r+   r/   r/   '   s    ZD,S@4@4@
 5zS]'a'Aq}}@AAA(s33 F33  D 3SXsCCD  s)   B :B8 
B5B00B58
CCc                   [        X/5      n[        U5      S:X  a  US   R                  (       a  g[        U5      S:w  a  [        eUR                  u  pEUu  pgUR                  U5      R                  (       d  [        e[        XdSS9n[        U5      R                  5        Vs/ s H  n[        X5      PM     n	nUR                  S5      n[        [        U5      R                  5       5      n
[        R                  " X5       VVs/ s H  u  pUR                  X[5      U4PM     nnn[        U[         S9$ s  snf s  snnf )	a
  Solve a system of two bivariate quadratic polynomial equations.

Parameters
==========

f: a single Expr or Poly
    First equation
g: a single Expr or Poly
    Second Equation
opt: an Options object
    For specifying keyword arguments and generators

Returns
=======

List[Tuple]
    a list of tuples with elements being solutions for the
    symbols in the order they were passed as gens
None
    None is returned when the computed basis contains only the ground.

Examples
========

>>> from sympy import Options, Poly
>>> from sympy.abc import x, y
>>> from sympy.solvers.polysys import solve_biquadratic
>>> NewOption = Options((x, y), {'domain': 'ZZ'})

>>> a = Poly(y**2 - 4 + x, y, x, domain='ZZ')
>>> b = Poly(y*2 + 3*x - 7, y, x, domain='ZZ')
>>> solve_biquadratic(a, b, NewOption)
[(1/3, 3), (41/27, 11/9)]

>>> a = Poly(y + x**2 - 3, y, x, domain='ZZ')
>>> b = Poly(-y + x - 4, y, x, domain='ZZ')
>>> solve_biquadratic(a, b, NewOption)
[(7/2 - sqrt(29)/2, -sqrt(29)/2 - 1/2), (sqrt(29)/2 + 7/2, -1/2 +       sqrt(29)/2)]
   r   Nr0   F)expandkey)r   r7   	is_groundr!   r8   gcdr   r   keysr   ltrimlist	itertoolsproductsubssortedr   )rB   rC   r@   Gxypqexprp_rootsq_rootsq_rootp_root	solutionss                 r+   r;   r;   e   s   R 	!A
1v{qt~~
1v{88DADA558Q% A-21X]]_=_Tx _G=	A58==?#G ""7464 7Ef&++a(&14  6 )!122 >
6s   #D6D;c                   ^^^^ S mS mSUUUU4S jjm T" XR                   SS9nUb  [        U[        S9$ g! [         a    [        ef = f)	aN  
Solve a generic system of polynomial equations.

Returns all possible solutions over C[x_1, x_2, ..., x_m] of a
set F = { f_1, f_2, ..., f_n } of polynomial equations, using
Groebner basis approach. For now only zero-dimensional systems
are supported, which means F can have at most a finite number
of solutions. If the basis contains only the ground, None is
returned.

The algorithm works by the fact that, supposing G is the basis
of F with respect to an elimination order (here lexicographic
order is used), G and F generate the same ideal, they have the
same set of solutions. By the elimination property, if G is a
reduced, zero-dimensional Groebner basis, then there exists an
univariate polynomial in G (in its last variable). This can be
solved by computing its roots. Substituting all computed roots
for the last (eliminated) variable in other elements of G, new
polynomial system is generated. Applying the above procedure
recursively, a finite number of solutions can be found.

The ability of finding all solutions by this procedure depends
on the root finding algorithms. If no solutions were found, it
means only that roots() failed, but the system is solvable. To
overcome this difficulty use numerical algorithms instead.

Parameters
==========

polys: a list/tuple/set
    Listing all the polynomial equations that are needed to be solved
opt: an Options object
    For specifying keyword arguments and generators
strict: a boolean
    If strict is True, NotImplementedError will be raised if the solution
    is known to be incomplete

Returns
=======

List[Tuple]
    a list of tuples with elements being solutions for the
    symbols in the order they were passed as gens
None
    None is returned when the computed basis contains only the ground.

References
==========

.. [Buchberger01] B. Buchberger, Groebner Bases: A Short
Introduction for Systems Theorists, In: R. Moreno-Diaz,
B. Buchberger, J.L. Freire, Proceedings of EUROCAST'01,
February, 2001

.. [Cox97] D. Cox, J. Little, D. O'Shea, Ideals, Varieties
and Algorithms, Springer, Second Edition, 1997, pp. 112

Raises
========

NotImplementedError
    If the system is not zero-dimensional (does not have a finite
    number of solutions)

UnsolvableFactorError
    If ``strict`` is True and not all solution components are
    expressible in radicals

Examples
========

>>> from sympy import Poly, Options
>>> from sympy.solvers.polysys import solve_generic
>>> from sympy.abc import x, y
>>> NewOption = Options((x, y), {'domain': 'ZZ'})

>>> a = Poly(x - y + 5, x, y, domain='ZZ')
>>> b = Poly(x + y - 3, x, y, domain='ZZ')
>>> solve_generic([a, b], NewOption)
[(-1, 4)]

>>> a = Poly(x - 2*y + 5, x, y, domain='ZZ')
>>> b = Poly(2*x - y - 3, x, y, domain='ZZ')
>>> solve_generic([a, b], NewOption)
[(11/3, 13/3)]

>>> a = Poly(x**2 + y, x, y, domain='ZZ')
>>> b = Poly(x + y*4, x, y, domain='ZZ')
>>> solve_generic([a, b], NewOption)
[(0, 0), (1/4, -1/16)]

>>> a = Poly(x**5 - x + y**3, x, y, domain='ZZ')
>>> b = Poly(y**2 - 1, x, y, domain='ZZ')
>>> solve_generic([a, b], NewOption, strict=True)
Traceback (most recent call last):
...
UnsolvableFactorError

c                \    U R                  5        H  n[        USS 5      (       d  M    g   g)z8Returns True if 'f' is univariate in its last variable. NrG   FT)monomsany)rB   monoms     r+   _is_univariate%solve_generic.<locals>._is_univariate  s)    XXZE5":   r*   c                r    U R                  X05      nU R                  U5      S:  a  UR                  SS9nU$ )z:Replace generator with a root so that the result is nice. r0   F)deep)as_exprdegreerF   )rB   genzerorV   s       r+   
_subs_root!solve_generic.<locals>._subs_root  s7    IIsk"88C=Ae$Ar*   c                R  > [        U 5      [        U5      s=:X  a  S:X  a>  O  O;[        [        U S   US   TS9R                  5       5      nU Vs/ s H  oD4PM     sn$ [	        XSS9n[        U5      S:X  a  US   R
                  (       a
  U(       d  / $ g[        [        TU5      5      n[        U5      [        U5      :  a  [        [        S5      5      e[        U5      S:X  a  UR                  5       nO[        [        S5      5      eUR                  nUS   n[        [        UR                  U5      TS9R                  5       5      nU(       d  / $ [        U5      S:X  a  U Vs/ s H  oD4PM     sn$ / n	U Hh  n/ n
USS nUSS  H2  nT" XU5      nU[        R                  Ld  M!  U
R                  U5        M4     T" X5       H  nU	R                  X4-   5        M     Mj     U	(       a/  [        U	S   5      [        U5      :w  a  [        [        S5      5      eU	$ s  snf s  snf )	z/Recursively solves reduced polynomial systems. rE   r   rG   r,   Tr?   Nzv
                only zero-dimensional systems supported
                (finite number of solutions)
                )r7   rN   r   rL   r   rJ   filterNotImplementedErrorr   popr8   rM   r   Zeroappend)systemr8   entryzerosrj   basis
univariaterB   ri   r]   
new_systemnew_gensbeqsolutionrc   _solve_reduced_systemrk   r-   s                  r+   r~   ,solve_generic.<locals>._solve_reduced_system  s   v;#d)(q( vay$r(6BGGIJE(-.G..T2u:?uQx11	&78
u:D	!%j 2 '  
 z?a A%j 2 '  
 vv2h U1773<7<<>?Iu:?(-.G..	DJCRyH3BZ-QVV#%%b)	   2*G  G!34 H  Yq\*c$i7%j 2 '   w /J /s   H(H$T)ru   NrH   F)r8   r   rp   rR   r   )r?   r@   r-   resultrc   r~   rk   s     ` @@@r+   r<   r<      sb    HA AF"&uhhdC f"233   "!!"s	   : Ac           	         [        X5      n[        XSS9n[        [        U5      5      nUR	                  SS5      nU(       a  S nO>UR	                  S5      nUb'  [        U5       H  u  pU	R                  U5      XH'   M     S nUS	   R                  S
5      USS pJU
R                  5       nU" U
5      nU(       a$  U Vs1 s H  o4UR                  U5      4iM     nnOU Vs1 s H  o4U4iM	     nn[        USS
 5      n[        USS 5      n[        UU5       GHP  u  nn[        5       nU GH6  u  nn/ [        [        UU5      5      nnU H  n	U4U-   nU	R                  " U6 (       d  M  U	R                  U5      S	:w  d  M6  U(       a*  U	R                  U	R                  R!                  U5      5      n	U	R                  U5      R#                  [%        U5      5      nU	R                  U5      UR                  5       :X  d  M  UR'                  U5        M     [)        US S9nU" U5      nU H3  nX;  a  UR                  U5      nOUnUR+                  U4U-   U45        M5     GM9     UnGMS     [-        S U 5       [.        S9$ s  snf s  snf )a  
Solve a polynomial system using Gianni-Kalkbrenner algorithm.

The algorithm proceeds by computing one Groebner basis in the ground
domain and then by iteratively computing polynomial factorizations in
appropriately constructed algebraic extensions of the ground domain.

Parameters
==========

polys: a list/tuple/set
    Listing all the equations that are needed to be solved
gens: generators
    generators of the equations in polys for which we want the
    solutions
args: Keyword arguments
    Special options for solving the equations

Returns
=======

List[Tuple]
    A List of tuples. Solutions for symbols that satisfy the
    equations listed in polys

Examples
========

>>> from sympy import solve_triangulated
>>> from sympy.abc import x, y, z

>>> F = [x**2 + y + z - 1, x + y**2 + z - 1, x + y + z**2 - 1]

>>> solve_triangulated(F, x, y, z)
[(0, 0, 1), (0, 1, 0), (1, 0, 0)]

Using extension for algebraic solutions.

>>> solve_triangulated(F, x, y, z, extension=True) #doctest: +NORMALIZE_WHITESPACE
[(0, 0, 1), (0, 1, 0), (1, 0, 0),
 (CRootOf(x**2 + 2*x - 1, 0), CRootOf(x**2 + 2*x - 1, 0), CRootOf(x**2 + 2*x - 1, 0)),
 (CRootOf(x**2 + 2*x - 1, 1), CRootOf(x**2 + 2*x - 1, 1), CRootOf(x**2 + 2*x - 1, 1))]

References
==========

1. Patrizia Gianni, Teo Mora, Algebraic Solution of System of
Polynomial Equations using Groebner Bases, AAECC-5 on Applied Algebra,
Algebraic Algorithms and Error-Correcting Codes, LNCS 356 247--257, 1989

Trn   	extensionFc                X    U R                  SSS9 VVs/ s H  u  pUPM	     snn$ s  snnf )NF)multipleradicals)	all_roots)rB   r_s      r+   _solve_univariate-solve_triangulated.<locals>._solve_univariate  s+    "#++uu+"MN"M$!A"MNNNs   &domainNc                P    [        U R                  5       R                  5       5      $ N)rN   ground_rootsrL   )rB   s    r+   r   r     s    (--/00r*   r   rG   rE   c                "    U R                  5       $ r   )rh   )hs    r+   <lambda>$solve_triangulated.<locals>.<lambda>  s
    QXXZr*   rH   c              3  *   #    U  H	  u  pUv   M     g 7fr   r#   )r2   sr   s      r+   r4   %solve_triangulated.<locals>.<genexpr>  s     +1r6   )r   r   rN   reversedget	enumerate
set_domainrM   
get_domainalgebraic_fieldr   zipsethas_only_gensrh   r   unifyevaldictrs   minaddrR   r   )r?   r8   r>   r@   rS   r   r   r   r3   rC   rB   domrv   rj   r]   var_seqvars_seqvarvars
_solutionsvaluesHmapping_varsr   rV   dom_zeros                              r+   solve_triangulatedr   i  sW   h 
#CD)AXa[AU+I	O "!!||F+ %	1 Q4::b>1QR5q
,,.Ca EFKLedgs22489e	L	056gs^	6tCRy!Gab"H(+	TU
$KFCT#dF"34wA??E**qxx}/A LL)<=))$w-8Axx}
2  A/0A%a(E"2248H"H& 0(;< # %2 	9 ,: ++1ABBI M6s    J$Jc           	         [        X40 UD6nU Vs/ s H  n[        U5      (       a  M  UPM     nnU VVs/ s H"  of Vs/ s H  owR                  5       PM     snPM$     nnnU$ s  snf s  snf s  snnf )a  
Factorizes a system of polynomial equations into
irreducible subsystems.

Parameters
==========

eqs : list
    List of expressions to be factored.
    Each expression is assumed to be equal to zero.

gens : list, optional
    Generator(s) of the polynomial ring.
    If not provided, all free symbols will be used.

**kwargs : dict, optional
    Same optional arguments taken by ``factor``

Returns
=======

list[list[Expr]]
    A list of lists of expressions, where each sublist represents
    an irreducible subsystem. When solved, each subsystem gives
    one component of the solution. Only generic solutions are
    returned (cases not requiring parameters to be zero).

Examples
========

>>> from sympy.solvers.polysys import factor_system, factor_system_cond
>>> from sympy.abc import x, y, a, b, c

A simple system with multiple solutions:

>>> factor_system([x**2 - 1, y - 1])
[[x + 1, y - 1], [x - 1, y - 1]]

A system with no solution:

>>> factor_system([x, 1])
[]

A system where any value of the symbol(s) is a solution:

>>> factor_system([x - x, (x + 1)**2 - (x**2 + 2*x + 1)])
[[]]

A system with no generic solution:

>>> factor_system([a*x*(x-1), b*y, c], [x, y])
[]

If c is added to the unknowns then the system has a generic solution:

>>> factor_system([a*x*(x-1), b*y, c], [x, y, c])
[[x - 1, y, c], [x, y, c]]

Alternatively :func:`factor_system_cond` can be used to get degenerate
cases as well:

>>> factor_system_cond([a*x*(x-1), b*y, c], [x, y])
[[x - 1, y, c], [x, y, c], [x - 1, b, c], [x, b, c], [y, a, c], [a, b, c]]

Each of the above cases is only satisfiable in the degenerate case `c = 0`.

The solution set of the original system represented
by eqs is the union of the solution sets of the
factorized systems.

An empty list [] means no generic solution exists.
A list containing an empty list [[]] means any value of
the symbol(s) is a solution.

See Also
========

factor_system_cond : Returns both generic and degenerate solutions
factor_system_bool : Returns a Boolean combination representing all solutions
sympy.polys.polytools.factor : Factors a polynomial into irreducible factors
                               over the rational numbers
)_factor_system_poly_from_expr_is_degeneraterg   )	eqsr8   kwargssystemssyssystems_genericrt   rV   systems_exprs	            r+   factor_systemr     sh    h ,C@@G&-Igs^C5HsgOI@OPf&1&QYY[&1LP J1Ps    A$A$	A.A)A.)A.c                &    [        S U  5       5      $ )z2Helper function to check if a system is degeneratec              3  8   #    U  H  oR                   v   M     g 7fr   )rJ   r2   rV   s     r+   r4   !_is_degenerate.<locals>.<genexpr>9  s     +Fq{{Fs   )ra   )rt   s    r+   r   r   7  s    +F+++r*   c                    [        X40 UD6n[        U VVs/ s H&  n[        U Vs/ s H  n[        US5      PM     sn6 PM(     snn6 $ s  snf s  snnf )a  
Factorizes a system of polynomial equations into irreducible DNF.

The system of expressions(eqs) is taken and a Boolean combination
of equations is returned that represents the same solution set.
The result is in disjunctive normal form (OR of ANDs).

Parameters
==========

eqs : list
   List of expressions to be factored.
   Each expression is assumed to be equal to zero.

gens : list, optional
   Generator(s) of the polynomial ring.
   If not provided, all free symbols will be used.

**kwargs : dict, optional
   Optional keyword arguments


Returns
=======

Boolean:
   A Boolean combination of equations. The result is typically in
   the form of a conjunction (AND) of a disjunctive normal form
   with additional conditions.

Examples
========

>>> from sympy.solvers.polysys import factor_system_bool
>>> from sympy.abc import x, y, a, b, c
>>> factor_system_bool([x**2 - 1])
Eq(x - 1, 0) | Eq(x + 1, 0)

>>> factor_system_bool([x**2 - 1, y - 1])
(Eq(x - 1, 0) & Eq(y - 1, 0)) | (Eq(x + 1, 0) & Eq(y - 1, 0))

>>> eqs = [a * (x - 1), b]
>>> factor_system_bool([a*(x - 1), b])
(Eq(a, 0) & Eq(b, 0)) | (Eq(b, 0) & Eq(x - 1, 0))

>>> factor_system_bool([a*x**2 - a, b*(x + 1), c], [x])
(Eq(c, 0) & Eq(x + 1, 0)) | (Eq(a, 0) & Eq(b, 0) & Eq(c, 0)) | (Eq(b, 0) & Eq(c, 0) & Eq(x - 1, 0))

>>> factor_system_bool([x**2 + 2*x + 1 - (x + 1)**2])
True

The result is logically equivalent to the system of equations
i.e. eqs. The function returns ``True`` when all values of
the symbol(s) is a solution and ``False`` when the system
cannot be solved.

See Also
========

factor_system : Returns factors and solvability condition separately
factor_system_cond : Returns both factors and conditions

r   )factor_system_condr   r   r   )r   r8   r   r   r   r|   s         r+   factor_system_boolr   <  sN    B !5f5G7C7C#.#BbQi#./7CDD.Cs   A
A	A
	A
c           	         [        X40 UD6nU VVs/ s H"  oD Vs/ s H  oUR                  5       PM     snPM$     nnnU$ s  snf s  snnf )a  
Factorizes a polynomial system into irreducible components and returns
both generic and degenerate solutions.

Parameters
==========

eqs : list
    List of expressions to be factored.
    Each expression is assumed to be equal to zero.

gens : list, optional
    Generator(s) of the polynomial ring.
    If not provided, all free symbols will be used.

**kwargs : dict, optional
    Optional keyword arguments.

Returns
=======

list[list[Expr]]
    A list of lists of expressions, where each sublist represents
    an irreducible subsystem. Includes both generic solutions and
    degenerate cases requiring equality conditions on parameters.

Examples
========

>>> from sympy.solvers.polysys import factor_system_cond
>>> from sympy.abc import x, y, a, b, c

>>> factor_system_cond([x**2 - 4, a*y, b], [x, y])
[[x + 2, y, b], [x - 2, y, b], [x + 2, a, b], [x - 2, a, b]]

>>> factor_system_cond([a*x*(x-1), b*y, c], [x, y])
[[x - 1, y, c], [x, y, c], [x - 1, b, c], [x, b, c], [y, a, c], [a, b, c]]

An empty list [] means no solution exists.
A list containing an empty list [[]] means any value of
the symbol(s) is a solution.

See Also
========

factor_system : Returns only generic solutions
factor_system_bool : Returns a Boolean combination representing all solutions
sympy.polys.polytools.factor : Factors a polynomial into irreducible factors
                               over the rational numbers
)r   rg   )r   r8   r   systems_polyrt   rV   r   s          r+   r   r     sH    f 1EfEL;GH<V,V		V,<GHN -Hs   	AA A Ac                    [        U /UQ70 UD6u  p4SnU(       a  [        S U 5       5      (       a  / /$ / $ [        U5      $ ! [        [        4 a5    [        S5      n[        X/40 UD6u  p4US   R                  (       d   eSn Nrf = f)z
Convert expressions to polynomials and factor the system.

Takes a sequence of expressions, converts them to
polynomials, and factors the resulting system. Handles both regular
polynomial systems and purely numerical cases.
Fur   Tc              3  *   #    U  H	  oS :H  v   M     g7f)r   Nr#   r   s     r+   r4   0_factor_system_poly_from_expr.<locals>.<genexpr>  s     15a65r6   )r   r   r   r   is_Numericalr9   factor_system_poly)r   r8   r   r?   optsonly_numbers_us          r+   r   r     s    -cCDCFC 15111t9r9e$$ 01 3Z-c4B6BH~****	s   A ABBc           	       ^
^ [        S U  5       5      (       d  [        S5      eU (       d  / /$ U S   R                  m
U S   R                  m[        U
U4S jU SS  5       5      (       d  [	        S5      e/ nU  H  nUR                  5       u  p4UR                  SL a  M&  UR                  S	L a3  U(       d  / s  $ UR                  U VVs/ s H  u  pVUPM	     snn5        Mh  [        [        U5      R                  5       S   5      n[        UTT
S
9nU VVs/ s H  u  pVUPM	     nnnUR                  U5        UR                  U5        M     U(       d  / /$ [        U5      n	[        U	5      $ s  snnf s  snnf )aT  
Factors a system of polynomial equations into irreducible subsystems

Core implementation that works directly with Poly instances.

Parameters
==========

polys : list[Poly]
    A list of Poly instances to be factored.

Returns
=======

list[list[Poly]]
    A list of lists of polynomials, where each sublist represents
    an irreducible component of the solution. Includes both
    generic and degenerate cases.

Examples
========

>>> from sympy import symbols, Poly, ZZ
>>> from sympy.solvers.polysys import factor_system_poly
>>> a, b, c, x = symbols('a b c x')
>>> p1 = Poly((a - 1)*(x - 2), x, domain=ZZ[a,b,c])
>>> p2 = Poly((b - 3)*(x - 2), x, domain=ZZ[a,b,c])
>>> p3 = Poly(c, x, domain=ZZ[a,b,c])

The equation to be solved for x is ``x - 2 = 0`` provided either
of the two conditions on the parameters ``a`` and ``b`` is nonzero
and the constant parameter ``c`` should be zero.

>>> sys1, sys2 = factor_system_poly([p1, p2, p3])
>>> sys1
[Poly(x - 2, x, domain='ZZ[a,b,c]'),
 Poly(c, x, domain='ZZ[a,b,c]')]
>>> sys2
[Poly(a - 1, x, domain='ZZ[a,b,c]'),
 Poly(b - 3, x, domain='ZZ[a,b,c]'),
 Poly(c, x, domain='ZZ[a,b,c]')]

 An empty list [] when returned means no solution exists.
 Whereas a list containing an empty list [[]] means any value is a solution.

See Also
========

factor_system : Returns only generic solutions
factor_system_bool : Returns a Boolean combination representing the solutions
factor_system_cond : Returns both generic and degenerate solutions
sympy.polys.polytools.factor : Factors a polynomial into irreducible factors
                               over the rational numbers
c              3  B   #    U  H  n[        U[        5      v   M     g 7fr   )
isinstancer   )r2   polys     r+   r4   %factor_system_poly.<locals>.<genexpr>	  s     8%$z$%%%s   z(polys should be a list of Poly instancesr   c              3  l   >#    U  H)  oR                   T:H  =(       a    UR                  T:H  v   M+     g 7fr   )r   r8   )r2   r   base_domain	base_genss     r+   r4   r     s+     [QZ{{k)Ddii9.DDQZs   14rE   Nz8All polynomials must have the same domain and generatorsTF)r   )r9   	TypeErrorr   r8   r   factor_listis_zerors   r   r
   as_coeff_Mulr   _factor_sets_sort_systems)r?   factor_setsr   constantfactors_multrB   r   constpfactorsr   r   r   s             @@r+   r   r     sZ   n 8%888BCCt(//KaI[QVWXWYQZ[[[TUUK!%!1!1!3t#&	l;ldal;<X 6 C C Ea HIH(IkBF%12\TQq\G2NN6"w'   t+&F    < 3s   
E.E4c                   ^ U (       d  [        5       1$ [        U 6  Vs1 s H  n[        U5      iM     nnU V^s1 s H!  m[        U4S jU 5       5      (       a  M  TiM#     sn$ s  snf s  snf )z{
Helper to find the minimal set of factorised subsystems that is
equivalent to the original system.

The result is in DNF.
c              3  .   >#    U  H
  nTU:  v   M     g 7fr   r#   r2   s2s1s     r+   r4   $_factor_sets_slow.<locals>.<genexpr>5  s     /N+BR+   )	frozensetr   ra   )r   r   systems_setr   s      `r+   _factor_sets_slowr   +  sX     }-3S\:\c9S>\K:$O2C/N+/N,NBOO ;Os   A%A*A*c           
       ^ U (       d  [        5       1$ [        U [        S9nU  Vs/ s H  o"ULd  M	  UPM     nnU VVs/ s H   nXC Vs/ s H  o$U;  d  M
  UPM     snU14PM"     nnn[        5       nU(       a  UR	                  5       u  pGnU(       d  UR                  [        U5      5        M=  [        U[        S9n	U Vs/ s H  o"U	Ld  M	  UPM     n
nU	 H4  nU
 Vs/ s H  o+U;  d  M
  UPM     nnX1-  nUR                  XU45        M6     U(       a  M  U V^s1 s H!  m[        U4S jU 5       5      (       a  M  TiM#     sn$ s  snf s  snf s  snnf s  snf s  snf s  snf )z)
Helper that builds factor combinations.
rH   c              3  .   >#    U  H
  nTU:  v   M     g 7fr   r#   r   s     r+   r4   _factor_sets.<locals>.<genexpr>V  s     *DVr27Vr   )r   r   r7   r   rq   r   rs   ra   )r   current_setr   
other_setsfactorstackr   remaining_setscurrent_solutionnext_setnext_remainingnext_factorvalid_remainingnew_solutionr   s                 `r+   r   r   8  sW    }cs#K 9S[$8!SJ9 '(& *@*Qaq*@6(K& 
 ( UF
3899;0 0JJy!123~3/%3I^7H!^I#K*8Q.Qq<Pq.OQ+m;LLL+EF $ %  E2s*DV*D'DBEE- :@ ( J R FsK   E	E	
E		EE
EEE	E,EE# E#Ec           	     h    U  Vs/ s H  n[        U[        SS9PM     nn[        U[        SS9$ s  snf )z$Sorts a list of lists of polynomialsT)rI   reverse)rR   _poly_sort_key_sys_sort_key)r   r   systems_lists      r+   r   r   Y  s4    IPQAF1.$?LQ,M4@@ Rs   /c                    U R                   R                  (       a  U R                  [        5      n U R	                  5       U R
                  R                  5       4$ )zSort key for polynomials)r   is_FFr   r   r:   repto_list)r   s    r+   r   r   _  s>    {{r"txx//111r*   c                @    [        [        [        [        U 5      6 5      $ )z!Sort key for lists of polynomials)rN   r   mapr   )r   s    r+   r   r   f  s    S-.//r*   r   )r#   )r   Sequence[Expr | complex]r8   Sequence[Expr]r   r   returnzlist[list[Expr]])rt   
list[Poly]r  bool)r   r  r8   r  r   r   r  r   )r   r  r8   r  r   r   r  list[list[Poly]])r?   r  r  r  )r   z
list[list]r  zset[frozenset])r   zIterable[Iterable[Poly]]r  r  )Cr(   
__future__r   typingr   collections.abcr   r   rO   sympyr   
sympy.corer   sympy.core.exprr	   sympy.core.exprtoolsr
   sympy.core.sortingr   sympy.logic.boolalgr   sympy.polysr   r   r   sympy.polys.domainsr   sympy.polys.polyoptionsr   sympy.polys.polytoolsr   r   sympy.polys.polyerrorsr   r   r   r   r   sympy.simplifyr   sympy.utilitiesr   sympy.utilities.iterablesr   sympy.utilities.miscr   r   r   sympy.core.relationalr   	Exceptionr!   r/   r;   r<   r   r   r   r   r   r   r   r   r   r   r   r   r#   r*   r+   <module>r     s    2 "  .      - / ' - - " 1 C  $ % , + ' $9) 9 */ ;4|@3F~4BqChWt,
BEJ5p%%%-;%GJ%%2V!r
PFBA20r*   