
    \h                     f   S r SSK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JrJr  SSKJrJr  SSK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!J"r"  SSK#J$r$  SSK%J&r&J'r'  SSK(J)r)J*r*  SSK+J,r,  S r-S r.S r/SS jr0S r1S r2S\Rf                  S4S jr4S r5S S jr6S r7/ 4S jr8g)!z<Tools for solving inequalities and systems of inequalities.     N)continuous_domainperiodicityfunction_range)sympify)factor_terms)
RelationalLtGeEq)SymbolDummy)Interval	FiniteSetUnionIntersection)S)
expand_mul)Abs)And)PolyPolynomialErrorparallel_poly_from_expr)_nsort)solvifysolveset)siftiterable)
filldedentc           
         [        U [        5      (       d  [        S5      eU R                  5       R                  (       aq  [        U R                  5       SU5      nU[        R                  L a  [        R                  /$ U[        R                  L a  [        R                  /$ [        SU-  5      eU R                  SS9/ pCUS:X  a)  U H!  u  pV[        XU5      nUR                  U5        M#     U$ US:X  aQ  [        R                  nU[        R                   S4/-    H%  u  p[        XS	S	5      nUR                  U5        U	nM'     U$ U R#                  5       S:  a  Sn
OS
n
Su  pUS:X  a  SnO-US:X  a  S
nO$US:X  a  Su  pOUS:X  a  Su  pO[        SU-  5      e[        R                   S	p[%        U5       H  u  pUS-  (       a3  X:X  a"  UR'                  S[        XU(       + U5      5        U
* X(       + pn
MB  X:X  a)  U(       d"  UR'                  S[        XS	U5      5        US	pMp  X:w  d  Mw  U(       d  M  UR'                  S[        X5      5        M     X:X  a,  UR'                  S[        [        R                  U	S	U5      5        U$ )a  Solve a polynomial inequality with rational coefficients.

Examples
========

>>> from sympy import solve_poly_inequality, Poly
>>> from sympy.abc import x

>>> solve_poly_inequality(Poly(x, x, domain='ZZ'), '==')
[{0}]

>>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '!=')
[Interval.open(-oo, -1), Interval.open(-1, 1), Interval.open(1, oo)]

>>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '==')
[{-1}, {1}]

See Also
========
solve_poly_inequalities
z8For efficiency reasons, `poly` should be a Poly instancer   %could not determine truth value of %sF)multiple==!=   T)NF><>=)r$   T<=)r%   Tz'%s' is not a valid relation   )
isinstancer   
ValueErroras_expr	is_numberr   r   trueRealsfalseEmptySetNotImplementedError
real_rootsr   appendNegativeInfinityInfinityLCreversedinsert)polyreltreals	intervalsroot_intervalleftrightsigneq_signequal
right_openmultiplicitys                  R/var/www/auris/envauris/lib/python3.13/site-packages/sympy/solvers/inequalities.pysolve_poly_inequalityrK      sl   , dD!!FH 	H||~t||~q#.;GG9!''\JJ<%7!;= = 69
d{GD+HX& d _ 
!!!**a 11HET48HX&D 2X O 779q=DD$#:GCZGD[%NGUD[%NGU;cABBJJz"*5/Da?$$8DUJGI ,0%yZZ?5$$8DzBD(,d:_$$Q(<= #2 ?8A..tZHJ     c           	      b    [        U  VVs/ s H  n[        U6   H  o"PM     M     snn6 $ s  snnf )au  Solve polynomial inequalities with rational coefficients.

Examples
========

>>> from sympy import Poly
>>> from sympy.solvers.inequalities import solve_poly_inequalities
>>> from sympy.abc import x
>>> solve_poly_inequalities(((
... Poly(x**2 - 3), ">"), (
... Poly(-x**2 + 1), ">")))
Union(Interval.open(-oo, -sqrt(3)), Interval.open(-1, 1), Interval.open(sqrt(3), oo))
)r   rK   )polyspss      rJ   solve_poly_inequalitiesrQ   q   s0     eGe-BA-F1-F1eGHHGs   +
c                 j   [         R                  nU  GH  nU(       d  M  [        [         R                  [         R                  5      /nU H  u  u  pEn[        XE-  U5      n[        US5      n/ n	[        R                  " Xs5       H<  u  pU
R                  U5      nU[         R                  Ld  M+  U	R                  U5        M>     U	n/ n	U H6  nU H  nX-  nM	     U[         R                  Ld  M%  U	R                  U5        M8     U	nU(       a  M    O   U H  nUR                  U5      nM     GM     U$ )a  Solve a system of rational inequalities with rational coefficients.

Examples
========

>>> from sympy.abc import x
>>> from sympy import solve_rational_inequalities, Poly

>>> solve_rational_inequalities([[
... ((Poly(-x + 1), Poly(1, x)), '>='),
... ((Poly(-x + 1), Poly(1, x)), '<=')]])
{1}

>>> solve_rational_inequalities([[
... ((Poly(x), Poly(1, x)), '!='),
... ((Poly(-x + 1), Poly(1, x)), '>=')]])
Union(Interval.open(-oo, 0), Interval.Lopen(0, 1))

See Also
========
solve_poly_inequality
r"   )r   r2   r   r6   r7   rK   	itertoolsproduct	intersectr5   union)eqsresult_eqsglobal_intervalsnumerdenomr<   numer_intervalsdenom_intervalsr?   numer_intervalglobal_intervalrB   denom_intervals                 rJ   solve_rational_inequalitiesrb      s%   . ZZF$Q%7%7DE#'NUC3EKEO3E4@OI3<3D3D#47/)33OD1::-$$X.47  )I#3&5N#5O '6 #!**4$$_5 $4  )##7 $(: )H\\(+F )G L MrL   Tc                 v   Sn/ n[         R                  nU  GH=  nU(       d  M  / n[         R                  nU GH  n	[        U	[        5      (       a  U	u  pO8U	R
                  (       a%  U	R                  U	R                  -
  U	R                  pOSn
U	[         R                  L a"  [         R                  [         R                  SpnOUU	[         R                  L a"  [         R                  [         R                  SpnO U	R                  5       R                  5       u  p [        X4U5      u  u  pnUR$                  R&                  (       d!  UR)                  5       UR)                  5       Sp<nUR$                  R+                  5       nUR,                  (       d2  UR.                  (       d!  X-  n	[1        U	SU
5      n	U[3        XSS9-  nGM  UR5                  X4U
45        GM     U(       al  U[7        U/5      -  n[7        U VVVVs/ s H:  o  H1  u  u  nnnUR9                  U5      (       d  M!  UUR:                  4S4PM3     M<     snnnn/5      nUU-  nXX-  nGM@     U(       d  U(       a  UR=                  5       nU(       a  UR?                  U5      nU$ ! [          a    [!        [#        S5      5      ef = fs  snnnnf )a  Reduce a system of rational inequalities with rational coefficients.

Examples
========

>>> from sympy import Symbol
>>> from sympy.solvers.inequalities import reduce_rational_inequalities

>>> x = Symbol('x', real=True)

>>> reduce_rational_inequalities([[x**2 <= 0]], x)
Eq(x, 0)

>>> reduce_rational_inequalities([[x + 2 > 0]], x)
-2 < x
>>> reduce_rational_inequalities([[(x + 2, ">")]], x)
-2 < x
>>> reduce_rational_inequalities([[x + 2]], x)
Eq(x, -2)

This function find the non-infinite solution set so if the unknown symbol
is declared as extended real rather than real then the result may include
finiteness conditions:

>>> y = Symbol('y', extended_real=True)
>>> reduce_rational_inequalities([[y + 2 > 0]], y)
(-2 < y) & (y < oo)
Tr"   z
                    only polynomials and rational functions are
                    supported in this context.
                    Fr   )
relational) r   r2   r0   r+   tupleis_Relationallhsrhsrel_opr/   ZeroOner1   togetheras_numer_denomr   r   r   domainis_Exactto_exact	get_exactis_ZZis_QQr   solve_univariate_inequalityr5   rb   hasoneevalfas_relational)exprsgenrd   exactrW   solution_exprsrY   _solexprr<   r[   r\   optrn   indrA   excludes                       rJ   reduce_rational_inequalitiesr      sS   : E
CzzHwwD$&& 	c%% $488 3T[[#Cqvv~$%FFAEE4cc$%EE155$cc#}}==?&=NC')# ::&&&+nn&68H%eZZ))+FLLFLL{!$3/3D%PPe^S12G J /77D14AA&1a!QUU3Z 5GaZ4F01 5G4A 3B CGGODa d X>>#))#.OA # %j 2 '  (4As   J?%J3(J3J0c                 (  ^ UR                   SL a  [        [        S5      5      eU4S jmSSS.n/ nT" U 5       HK  u  pXR                  5       ;  a  [	        U SU5      n O[	        U * SX1   5      n UR                  U /U-   5        MM     [        XB5      $ )a]  Reduce an inequality with nested absolute values.

Examples
========

>>> from sympy import reduce_abs_inequality, Abs, Symbol
>>> x = Symbol('x', real=True)

>>> reduce_abs_inequality(Abs(x - 5) - 3, '<', x)
(2 < x) & (x < 8)

>>> reduce_abs_inequality(Abs(x + 2)*3 - 13, '<', x)
(-19/3 < x) & (x < 7/3)

See Also
========

reduce_abs_inequalities
Fzs
            Cannot solve inequalities with absolute values containing
            non-real variables.
            c                   >^ / nU R                   (       d  U R                  (       aq  U R                  nU R                   HS  nT	" U5      nU(       d  UnM  [        R
                  " X5       V VVVs/ s H  u  u  pu  pgU" X5      XW-   4PM     nnnn nMU     U$ U R                  (       aU  U R                  mTR                  (       d  [        S5      eUR                  U4S jT	" U R                  5       5       5        U$ [        U [        5      (       ad  T	" U R                  S   5      nU HG  u  pUR                  X[        U S5      /-   45        UR                  U * U[!        U S5      /-   45        MI     U$ U / 4/nU$ s  snnnn f )Nz'Only Integer Powers are allowed on Abs.c              3   6   >#    U  H  u  pUT-  U4v   M     g 7fN ).0r   condsr   s      rJ   	<genexpr>Areduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<genexpr>L  s     X=Wkd$'5)=Ws   r   )is_Addis_MulfuncargsrS   rT   is_Powexp
is_Integerr,   extendbaser+   r   r5   r
   r	   )
r   ry   opargr}   r   _expr_condsr   _bottom_up_scans
           @rJ   r   .reduce_abs_inequality.<locals>._bottom_up_scan9  sY   ;;$++Byy(-"E &--e<>< Db=DRaSXbou~><  >E !.  [[A<< !JKKLLX_TYY=WXX  c""$TYYq\2F%tbqk]%:;<teUbqk]%:;<  &  BZLE#>s   0E>r&   r(   r'   r)   r   )is_extended_real	TypeErrorr   keysr   r5   r   )r   r<   rz   mappinginequalitiesr   r   s         @rJ   reduce_abs_inequalityr     s    ( u$
 $   	
> t$GL&t,lln$tQ,DteQ5DTFUN+ - (::rL   c                 \    [        U  VVs/ s H  u  p#[        X#U5      PM     snn6 $ s  snnf )a  Reduce a system of inequalities with nested absolute values.

Examples
========

>>> from sympy import reduce_abs_inequalities, Abs, Symbol
>>> x = Symbol('x', extended_real=True)

>>> reduce_abs_inequalities([(Abs(3*x - 5) - 7, '<'),
... (Abs(x + 25) - 13, '>')], x)
(-2/3 < x) & (x < 4) & (((-oo < x) & (x < -38)) | ((-12 < x) & (x < oo)))

>>> reduce_abs_inequalities([(Abs(x - 4) + Abs(3*x - 5) - 7, '<')], x)
(1/2 < x) & (x < 4)

See Also
========

reduce_abs_inequality
)r   r   )ry   rz   r   r<   s       rJ   reduce_abs_inequalitiesr   f  s:    * !ID (37! " " !s   (
Fc                   ^ ^^) SSK Jn  UR                  [        R                  5      SL a  [        [        S5      5      eU[        R                  La5  [        T TSUS9R                  U5      nU(       a  UR                  T5      nU$  TnUnTR                  SL a*  [        R                  nU(       d  U$ UR                  U5      $ TR                  c  [        SSS	9m T R                  UT05      m SnT [        R                  L a  UnGOT [        R                   L a  [        R                  nGOiT R"                  T R$                  -
  n	['        U	T5      n
U
[        R(                  :X  aY  [+        U	5      n	T R-                  U	S5      nU[        R                  L a  UnGODU[        R                   L a  [        R                  nGOU
Gb  [/        U	TU5      nT R0                  nUS;   aV  T R-                  UR2                  S5      (       a  UnOT R-                  UR4                  S5      (       d  [        R                  nO[US;   aU  T R-                  UR4                  S5      (       a  UnO1T R-                  UR2                  S5      (       d  [        R                  nUR4                  UR2                  pX-
  [        R6                  L a  [9        SU
SS5      R;                  U5      nUnUGc  U	R=                  5       u  nn TUR>                  ;  a  [A        U	R>                  5      S:  a  [B        e[E        U	TU5      nUc  [B        e [+        U	5      m)U)U U4S jn/ nU" T T5       H  nURK                  [E        UTU5      5        M!     U(       d  [M        T)TU5      nST R0                  ;   =(       a    T R0                  S:g  n [O        URP                  [S        UR4                  UR2                  5      -
  5      n[S        UU-   [U        U5      -   6 R                  [9        UR4                  UR2                  UR4                  U;  UR2                  U;  5      5      n[W        S U 5       5      (       a  [Y        USS9S   nO=[[        US 5      nUS   (       a  [
        e US   n[A        U5      S:  a  []        U5      n[        R                  nT)R_                  [        R`                  5      =n[        R(                  :w  Ga  Sn[S        5       n [c        UTU5      n[e        U[8        5      (       dC  U H;  nUU;  d  M  U" U5      (       d  M  UR                  (       d  M-  U[S        U5      -  nM=     GOUR4                  UR2                  n!n [Y        U[S        U!5      -   5       H  nU" U 5      n"U U!:w  a  U" U5      n#[g        U U5      n$U$U;  a  U$R                  (       a  U" U$5      (       a|  U"(       a  U#(       a  U[9        U U5      -  nO^U"(       a  U[8        Rh                  " U U5      -  nO<U#(       a  U[8        Rj                  " U U5      -  nOU[8        Rl                  " U U5      -  nUn M     U H  n%U[S        U%5      -  nM      U[        R                  L a-  [C        [        ST RG                  TU5      < SU< S35      5      eUR;                  U5      n[        R                  /n&UR4                  n U U;   a8  U" U 5      (       a+  U Rn                  (       a  U&Rq                  [S        U 5      5        U H  n'U'n!U" [g        U U!5      5      (       a  U&Rq                  [9        U U!SS5      5        U'U;   a  URs                  U'5        OCU'U;   a  URs                  U'5        U" U'5      n(OUn(U((       a  U&Rq                  [S        U'5      5        U!n M     UR2                  n!U!U;   a8  U" U!5      (       a+  U!Rn                  (       a  U&Rq                  [S        U!5      5        U" [g        U U!5      5      (       a&  U&Rq                  [8        Rl                  " U U!5      5        U[        R(                  :w  a  W(       a  UR;                  U5      nO#[u        [w        U&6 UU5      RG                  TU5      nU(       d  U$ UR                  U5      $ ! [         a    [        [        S
5      5      ef = f! [B        [
        4 a1    [        [        ST RG                  T[I        S5      5      -  5      5      ef = f! [         a    [
        ef = f! [
         a    [        S5      ef = f! [         a    [        R                  nSn GNf = f)a  Solves a real univariate inequality.

Parameters
==========

expr : Relational
    The target inequality
gen : Symbol
    The variable for which the inequality is solved
relational : bool
    A Relational type output is expected or not
domain : Set
    The domain over which the equation is solved
continuous: bool
    True if expr is known to be continuous over the given domain
    (and so continuous_domain() does not need to be called on it)

Raises
======

NotImplementedError
    The solution of the inequality cannot be determined due to limitation
    in :func:`sympy.solvers.solveset.solvify`.

Notes
=====

Currently, we cannot solve all the inequalities due to limitations in
:func:`sympy.solvers.solveset.solvify`. Also, the solution returned for trigonometric inequalities
are restricted in its periodic interval.

See Also
========

sympy.solvers.solveset.solvify: solver returning solveset solutions with solve's output API

Examples
========

>>> from sympy import solve_univariate_inequality, Symbol, sin, Interval, S
>>> x = Symbol('x')

>>> solve_univariate_inequality(x**2 >= 4, x)
((2 <= x) & (x < oo)) | ((-oo < x) & (x <= -2))

>>> solve_univariate_inequality(x**2 >= 4, x, relational=False)
Union(Interval(-oo, -2), Interval(2, oo))

>>> domain = Interval(0, S.Infinity)
>>> solve_univariate_inequality(x**2 >= 4, x, False, domain)
Interval(2, oo)

>>> solve_univariate_inequality(sin(x) > 0, x, relational=False)
Interval.open(0, pi)

r   denomsFz|
        Inequalities in the complex domain are
        not supported. Try the real domain by
        setting domain=S.Reals)rd   
continuousNrz   Textended_realz
                When gen is real, the relational has a complex part
                which leads to an invalid comparison like I < 0.
                r   )r&   r(   r$   z
                    The inequality, %s, cannot be solved using
                    solve_univariate_inequality.
                    xc                   > TR                  T[        U 5      5      n TR                  US5      nU[        R                  [        R
                  4;   a  U$ UR                  SL a  [        R
                  $ UR                  S5      nUR                  (       a  TR                  US5      $ [        SU-  5      e! [         a    [        R
                  n Nf = f)Nr   Fr*   z!relationship did not evaluate: %s)subsr   r   r   r   r1   r/   r   r   is_comparabler3   )r   vr
expanded_er   rz   s      rJ   valid*solve_univariate_inequality.<locals>.valid  s     OOCA7 		!QA ))H%%.77NAA#yyA.-;a?A A !  A s   B7 7CC=r#   c              3   8   #    U  H  oR                   v   M     g 7fr   )r.   )r   r   s     rJ   r   .solve_univariate_inequality.<locals>.<genexpr>@  s     <Oq{{Os   )	separatedc                     U R                   $ r   r   )r   s    rJ   <lambda>-solve_univariate_inequality.<locals>.<lambda>C  s
    Q=O=OrL   z'sorting of these roots is not supportedz
                        zZ contains imaginary parts which cannot be
                        made 0 for any value of zm satisfying the
                        inequality, leading to relations like I < 0.
                        )<sympy.solvers.solversr   	is_subsetr   r0   r3   r   rt   intersectionrx   r   r2   r   xreplacer   r/   r1   rg   rh   r   rj   r   r   r   ri   supinfr7   r   rU   rm   free_symbolslenr,   r   r   r   r   r   setboundaryr   listallr   r   sortedcoeffImaginaryUnitr   r+   _ptRopenLopenopen	is_finiter5   remover   r   )*r   rz   rd   rn   r   r   rv_gen_domaineperiodconstfranger<   r   r   r   r   solnsr   singularities	include_xdiscontinuitiescritical_pointsr>   sifted	make_realcoeffIcheckim_solazstartendvalid_startvalid_zptrP   sol_setsr   _validr   s*   ``                                       @rJ   rt   rt     s   r - E)!* ." ## $ 	$ 
qww	(ce
<<HL<P 	!!#&B	
 DG
u$ZZ#r?)9)9$)??				%E.	==$-D 
Bqvv~	ZZ HHtxxQ$QVV1AIIaOE!''!ZZ#AsF3F++Ck!99VZZ++B6::q11B#99VZZ++B6::q11Bzz6::yAJJ&!!VUD9CCGL :##%DAq8ann,Q^^1Dq1H$$  3/=$$ ! $AJA6 MD#&$$WQV%<= '*:sFCt{{*Bt{{d/BIU"%foofjj&**5'6 #7 #,em.Cd#G% /% #''3|VZZJJf,fjj.FH(I   <O<<<"?dCAFE!/3OPFd| 212 &tu:>$*5ME I$**1??;;F"" f5A%a22!"A 5%((qGYGYGY &)A, 6 "# &'UUAEEs!')C.(H!IA*/,K$|*/(%(]#%]#:r?R?RW\]_W`W`'2w(.(5!2D(D)4(.(..2J(J)0(.(..2J(J(.(--q2I(I$%E "J "/A"il2F "/ QZZ'$Z !%		#t 4d	1< &= > > &//7	

|HJJE5<<EOO	% 01UC))OOHUCt$DE%!((+O+'..q1!&q!* 	!5# & **Cf}s	#/S_%%eS 9:E**73!H%	7<<@DdO   2;R%5%5d%;;_  	J (   	p  34 8 ** 6 ))C566 +7 8 88@ % 2112& U)*STTUD " "WWF!E"sj   b2 8Ac 9B:d, 4d, d +e 1e  e e 'De 2cAdd))d, ,ee%$e%c                 4   U R                   (       d  UR                   (       d	  X-   S-  nU$ U R                   (       a#  UR                   (       a  [        R                  nU$ U R                   (       a  U R                  b  UR                   (       a  UR                  c  [	        S5      eUR                   (       a  UR
                  (       d"  U R                   (       a  U R                  (       a  XpUR                   (       aF  U R                  (       a  U S-  nU$ U R
                  (       a  U [        R                  -  nU$ U S-   n U$ U R                   (       aC  UR                  (       a  U[        R                  -  nU$ UR
                  (       a  US-  nU$ US-
  nW$ )z$Return a point between start and endr*   z,cannot proceed with unsigned infinite valuesr$   )is_infiniter   rj   is_extended_positiver,   is_extended_negativeHalf)r   r   r   s      rJ   r   r     sC   S__k1_6 I5 
		sVV2 I/ %"<"<"DC$<$<$DKLLOO 8 8!!e&@&@3 ??))1W I ++166\ I QY I ''Z
 I	 ))U I 1WIrL   c                    SSK Jn  XR                  ;  a  U $ U R                  U:X  a  U R                  n U R
                  U:X  a  XR                  R                  ;  a  U $ S nSn[        R                  nU R
                  U R                  -
  n [        Xq5      nUR                  5       S:X  a!  U R                  UR                  5       S5      nO!U(       d  UR                  5       S:  a  [        e/ nUGc  WR                  5       nSnUR)                  USS9u  pX-  nX-  n[+        U5      nUR)                  USS9u  nnUR,                  S:w  d2  UR.                  UR0                  s=:X  a   c%  O  O"U R2                  S	;  a  Un[        R4                  nUU-  nUR0                  (       a  U R                  X5      nOU R                  R                  X5      nU" U R
                  5      U" U R                  5      -  nU" U5      nUU-
   Hx  n[7        [9        US5      XS
9n[;        U[8        5      (       d  M.  UR
                  U:X  d  M@  U" XQUR                  5      [        R                   L d  Mf  UR=                  U) 5        Mz     U* U4 HY  nU" XQU5      [        R                   L d  M  U" XU5      [        R                   Ld  M;  UR=                  UUL a  UU:  OUU:  5        M[     UR=                  U5        ['        U6 $ ! [        [        4 GaC    U(       Gd,   [        U //U5      nO! [         a    [        X5      n Of = fU" XU5      n	U	[        R                   L a.  U" XQU5      [        R"                  L a  UR%                  X:  S5      nU" XU* 5      n
U
[        R                   L aF  U" XQU* 5      [        R"                  L a+  UR%                  U* U:  S5      nUR%                  X* :  S5      nU[        R                   L a>  U	[        R                   L a  X:*  OX:  nU
[        R                   La  ['        U* U:  U5      n GNU[        U5      n GNcf = f)a  Return the inequality with s isolated on the left, if possible.
If the relationship is non-linear, a solution involving And or Or
may be returned. False or True are returned if the relationship
is never True or always True, respectively.

If `linear` is True (default is False) an `s`-dependent expression
will be isolated on the left, if possible
but it will not be solved for `s` unless the expression is linear
in `s`. Furthermore, only "safe" operations which do not change the
sense of the relationship are applied: no division by an unsigned
value is attempted unless the relationship involves Eq or Ne and
no division by a value not known to be nonzero is ever attempted.

Examples
========

>>> from sympy import Eq, Symbol
>>> from sympy.solvers.inequalities import _solve_inequality as f
>>> from sympy.abc import x, y

For linear expressions, the symbol can be isolated:

>>> f(x - 2 < 0, x)
x < 2
>>> f(-x - 6 < x, x)
x > -3

Sometimes nonlinear relationships will be False

>>> f(x**2 + 4 < 0, x)
False

Or they may involve more than one region of values:

>>> f(x**2 - 4 < 0, x)
(-2 < x) & (x < 2)

To restrict the solution to a relational, set linear=True
and only the x-dependent portion will be isolated on the left:

>>> f(x**2 - 4 < 0, x, linear=True)
x**2 < 4

Division of only nonzero quantities is allowed, so x cannot
be isolated by dividing by y:

>>> y.is_nonzero is None  # it is unknown whether it is 0 or not
True
>>> f(x*y < 1, x)
x*y < 1

And while an equality (or inequality) still holds after dividing by a
non-zero quantity

>>> nz = Symbol('nz', nonzero=True)
>>> f(Eq(x*nz, 1), x)
Eq(x, 1/nz)

the sign must be known for other inequalities involving > or <:

>>> f(x*nz <= 1, x)
nz*x <= 1
>>> p = Symbol('p', positive=True)
>>> f(x*p <= 1, x)
x <= 1/p

When there are denominators in the original expression that
are removed by expansion, conditions for them will be returned
as part of the result:

>>> f(x < x*(2/x - 1), x)
(x < 1) & Ne(x, 0)
r   r   c                      U R                  X5      nU[        R                  L a  U$ US;  a  g U$ ! [         a    [        R                  s $ f = f)NTF)r   r   NaNr   )ierP   r   r   s       rJ   classify#_solve_inequality.<locals>.classify  sL    	AAEEz-'H 	55L	s   %1 1 1 AANr$   T)as_AddF)r#   r"   )linear)r   r   r   rh   r9   rg   r   r7   r   degreer   r-   r3   r   r   rt   r/   r1   r   r   as_independentr   is_zerois_negativeis_positiveri   rk   _solve_inequalityr   r+   r5   )r   rP   r   r   r   r   oor   rO   okoooknoor   r   rh   baxefr   beginning_denomscurrent_denomsr   cr   s                          rJ   r   r     s   T -		vv{[[	vv{q 3 33	 
B	
B66BFF?DM88:?a(BAHHJN%%0 E	zIIK
   4 0	!_  5 11II&!%&		-AAq==B!!!)B ""&&>F266N:!N2A!"Q(A=A!R  QUUaZB155)QVV3LL!$ 3 #rA"aff,RA&aff4a2gQU1q59 
 
LL;A 01 81B4&!<" 8078 B2&Dqvv~(2""5"@WWQVT*RRC(ERRC(AGG3WWbS1Wd+WWQWd+QVV|"&!&&.agqv&bS1Wb)BT
A+sC   ?K? !K? ?QL('Q(M =Q?M  DQQQc           
        ^ 0 0 p2/ nU  GHr  nUR                   UR                  pvUR                  [        5      n[	        U5      S:X  a  UR                  5       mOjUR                  U-  n	[	        U	5      S:X  a8  U	R                  5       mUR                  [        [        USU5      T5      5        M  [        [        S5      5      eUR                  T5      (       a$  UR                  T/ 5      R                  Xg45        M  UR                  U4S j5      n
U
(       a<  [        S U
 5       5      (       a%  UR                  T/ 5      R                  Xg45        GML  UR                  [        [        USU5      T5      5        GMu     UR!                  5        VVs/ s H  u  p[#        U/U5      PM     nnnUR!                  5        VVs/ s H  u  p[%        X5      PM     nnn['        X-   U-   6 $ s  snnf s  snnf )Nr$   r   zZ
                    inequality has more than one symbol of interest.
                    c                    > U R                  T5      =(       aA    U R                  =(       d.    U R                  =(       a    U R                  R                  (       + $ r   )ru   is_Functionr   r   r   )urz   s    rJ   r   &_reduce_inequalities.<locals>.<lambda>  s<    c
 DB!B!%%2B2B.BDrL   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r+   r   r   r   s     rJ   r   '_reduce_inequalities.<locals>.<genexpr>  s     !Ij*Q"4"4js   )rg   ri   atomsr   r   popr   r5   r   r   r3   r   is_polynomial
setdefaultfindr   itemsr   r   r   )r   symbols	poly_partabs_partother
inequalityr   r<   genscommon
componentsrz   ry   poly_reducedabs_reduceds              `   rJ   _reduce_inequalitiesr"  t  s    bxE"
NNJ$5$5c
 zz&!t9>((*C&&0F6{ajjl.z$3/GMN)* 6 +   c""  b)00$= $D EJ c!Ij!III##C,33TK@.z$3/GMN? #B R[Q`Q`QbcQb:30%#>QbLcIQIYZIY:3*56IYKZ+e355 dZs   G)G/c           	         [        U 5      (       d  U /n U  Vs/ s H  n[        U5      PM     n n[        5       R                  " U  Vs/ s H  o"R                  PM     sn6 n[        U5      (       d  U/n[        U5      =(       d    UU-  n[        S U 5       5      (       a  [        [        S5      5      eU Vs0 s H&  o"R                  b  M  U[        UR                  SS9_M(     nnU  Vs/ s H  o"R                  U5      PM     n nU Vs1 s H  o"R                  U5      iM     nn/ nU  H  n[        U[        5      (       aF  UR                  UR                  R!                  5       UR"                  R!                  5       -
  S5      nOUS;  a  [%        US5      nUS:X  a  Mx  US:X  a  [&        R(                  s  $ UR                  R*                  (       a  [-        SU-  5      eUR/                  U5        M     Un A[1        X5      nUR                  UR3                  5        VVs0 s H  u  pxX_M	     snn5      $ s  snf s  snf s  snf s  snf s  snf s  snnf )	a!  Reduce a system of inequalities with rational coefficients.

Examples
========

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

>>> reduce_inequalities(0 <= x + 3, [])
(-3 <= x) & (x < oo)

>>> reduce_inequalities(0 <= x + y*2 - 1, [x])
(x < oo) & (x >= 1 - 2*y)
c              3   <   #    U  H  oR                   S L v   M     g7f)FNr   r  s     rJ   r   &reduce_inequalities.<locals>.<genexpr>  s     
81&s   zP
            inequalities cannot contain symbols that are not real.
            Tr   r   r   Fr    )r   r   r   rV   r   anyr   r   r   r   namer   r+   r   r   rg   r-   rh   r   r   r1   r.   r3   r5   r"  r  )	r   r  r   r  recastkeepr   kr   s	            rJ   reduce_inequalitiesr+    s    L!!$~(451GAJL55;;>A>?DG)7|#tt+G

8
888
 $   	 5A++ 3aqvvT22  50<=1JJv&L=+237azz&!7G3 Da$$quu}}8!<Am#1aA9%Z77N55??%7!;= =A  L 
l	4B ;;8899Q 6>5=30 9s)   H<I9II,II&I
)T)F)9__doc__rS   sympy.calculus.utilr   r   r   
sympy.corer   sympy.core.exprtoolsr   sympy.core.relationalr   r	   r
   r   sympy.core.symbolr   r   sympy.sets.setsr   r   r   r   sympy.core.singletonr   sympy.core.functionr   $sympy.functions.elementary.complexesr   sympy.logicr   sympy.polysr   r   r   sympy.polys.polyutilsr   sympy.solvers.solvesetr   r   sympy.utilities.iterablesr   r   sympy.utilities.miscr   rK   rQ   rb   r   r   r   r0   rt   r   r   r"  r+  r   rL   rJ   <module>r<     s    B    - 8 8 + D D " * 4  F F ( 4 4 +XvI"?DXvD;N"2 7;177W\ d<N	BjZ*6Z /1 9:rL   