
    wg                     ^   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZmZ ddlmZmZ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dlm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z, d Z-d Z.d Z/ddZ0d Z1d Z2dejf                  dfdZ4d Z5d dZ6d Z7g fdZ8y)!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           
         t        | t              st        d      | j                         j                  rot        | j                         d|      }|t        j                  u rt        j                  gS |t        j                  u rt        j                  gS t        d|z        | j                  d      g }}|dk(  r)|D ]"  \  }}t        ||      }|j                  |       $ |S |dk(  rQt        j                  }|t        j                   dfgz   D ]&  \  }	}t        ||	d	d	      }|j                  |       |	}( |S | j#                         dkD  rd}
nd
}
d\  }}|dk(  rd}n,|dk(  rd
}n$|dk(  rd\  }}n|dk(  rd\  }}nt        d|z        t        j                   d	}}	t%        |      D ]  \  }}|dz  r-|
|k(  r|j'                  dt        ||	| |             |
 || }}	}
8|
|k(  r%|s#|j'                  dt        ||	d	|             |d	}}	b|
|k7  sh|sk|j'                  dt        ||              |
|k(  r,|j'                  dt        t        j                  |	d	|             |S )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                  _/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/solvers/inequalities.pysolve_poly_inequalityrK      s   , dD!FH 	H||~t||~q#.;GG9!''\JJ<%7!;= = 69E
d{ 	'GD!d+HX&	'd _ 
!!!**a 11 	HE1eT48HX&D	X O 779q=DD$#:GCZGD[%NGUD[%NGU;cABBJJz"*5/ 	>D,a7?$$8D%UJGI ,0%5yZe7?5$$8D%zBD(,d:EW_$$Qt(<=	> 7?8A..tZHJ     c           	      X    t        | D cg c]  }t        | D ]  }|  c}} S c c}}w )a  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   s/     eG-BA-FG1G1GHHGs   &
c                 <   t         j                  }| D ]  }|st        t         j                  t         j                        g}|D ]  \  \  }}}t        ||z  |      }t        |d      }g }	t        j                  ||      D ]:  \  }
}|
j                  |      }|t         j                  us*|	j                  |       < |	}g }	|D ]2  }|D ]  }||z  }	 |t         j                  us"|	j                  |       4 |	}|r n |D ]  }|j                  |      }  |S )a3  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      sK   . ZZF $,$Q%7%7DE#' 	NUEC3E%KEO3E4@OI3<3D3D#%547 //)33OD1::-$$X./  )I#3 6&5 6N#~5O6 #!**4$$_56  )#7	: ) 	,H\\(+F	,G$,L MrL   Tc                 
   d}g }t         j                  }| D ]  }|sg }t         j                  }|D ]  }	t        |	t              r|	\  }	}
n6|	j
                  r&|	j                  |	j                  z
  |	j                  }
}	n|	d}
}	|	t         j                  u r#t         j                  t         j                  d}
}}nV|	t         j                  u r#t         j                  t         j                  d}
}}n!|	j                         j                         \  }}	 t        ||f|      \  \  }}}|j$                  j&                  s"|j)                         |j)                         d}}}|j$                  j+                         }|j,                  s1|j.                  s%||z  }	t1        |	d|
      }	|t3        |	|d      z  }|j5                  ||f|
f        |r`|t7        |g      z  }t7        |D cg c]0  }|D ])  \  \  }}}|j9                  |      r||j:                  fdf+ 2 c}}}}g      }||z  }||z  } |s|r|j=                         }|r|j?                  |      }|S # t         $ r t!        t#        d            w xY wc c}}}}w )a8  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      su   : E
CzzH 0ww #	3D$& 	c%% $488 3T[[#D $d#Dqvv~$%FFAEE4cu$%EE155$cu#}}==?u&=ENC')# ::&&&+nn&68H%euZZ))+FLLFLLU{!$3/3D#%PPeU^S12G#	3J /77D14A 4A4A!,&1a!QUU3Z 78Z4F 4A4F 4A 3B CGGODDa0d X>>#))#.OA # %j 2 '  (4As   I&5I=I:c                 $   |j                   du rt        t        d            fdddd}g } |       D ]K  \  } }||j                         vrt	        | d|      } nt	        |  d||         } |j                  | g|z          M t        ||      S )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                    g }| j                   s| j                  rj| j                  }| j                  D ]M  } 	|      }|s|}t	        j
                  ||      D  cg c]  \  \  } }\  }} || |      ||z   f }}}} }O |S | j                  rO| j                  j                  st        d      |j                  fd 	| j                        D               |S t        | t              rd 	| j                  d         }|D ]H  \  } }|j                  | |t        | d      gz   f       |j                  |  |t!        | d      gz   f       J |S | g fg}|S c c}}}} w )Nz'Only Integer Powers are allowed on Abs.c              3   2   K   | ]  \  }}|z  |f  y wN ).0r   condsr   s      rJ   	<genexpr>zAreduce_abs_inequality.<locals>._bottom_up_scan.<locals>.<genexpr>L  s     XkdE$'5)Xs   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   z.reduce_abs_inequality.<locals>._bottom_up_scan9  sj   ;;$++Byy >(-"E &--eV<> >Ca=D%RaSXZ`buouv~> >E >>.  [[A<< !JKKLLX_TYY=WXX  c"$TYYq\2F% =etUbqk]%:;<teUbqk]%:;<=  BZLE#>s    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, ,eglln$tQ,DteQ5DTFUN+, (c::rL   c                 Z    t        | D cg c]  \  }}t        |||       c}} S c c}}w )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  s9    * !D# (c37 ! " " !s   '
Fc                 J   ) ddl m} |j                  t        j                        du rt        t        d            |t        j                  ur3t         d|      j                  |      }|r|j                        }|S 	 }|}j                  du r%t        j                  }|s|S |j                  |      S j                  !t        dd	      	  j                  |i       d} t        j                  u r|}nމ t        j                   u rt        j                  }n j"                   j$                  z
  }	t'        |	      }
|
t        j(                  k(  rXt+        |	      }	 j-                  |	d      }|t        j                  u r|}n,|t        j                   u rt        j                  }n|
t/        |	|      } j0                  }|dv rL j-                  |j2                  d      r|}n| j-                  |j4                  d      s`t        j                  }nO|dv rK j-                  |j4                  d      r|}n, j-                  |j2                  d      st        j                  }|j4                  |j2                  }}||z
  t        j6                  u rt9        d|
dd      j;                  |      }|}| |	j=                         \  }}	 |j>                  vrtA        |	j>                        dkD  rtB        tE        |	|      }|tB        	 t+        |	      )) fd}g } |       D ]  }|jK                  tE        ||               |stM        )|      }d j0                  v xr  j0                  dk7  }	 tO        |jP                  tS        |j4                  |j2                        z
        }tS        ||z   tU        |      z    j                  t9        |j4                  |j2                  |j4                  |v|j2                  |v            }tW        d |D              rtY        |d      d   }n7t[        |d       }|d   rt
        	 |d   }tA        |      dkD  rt]        |      }t        j                  })j_                  t        j`                        x}t        j(                  k7  rd}tS               }	 tc        ||      }te        |t8              s1|D ]+  }||vs ||      s|j                  s|tS        |      z  }- n|j4                  |j2                  }!} tY        |tS        |!      z         D ]  } ||       }"| |!k7  r ||      }#tg        | |      }$|$|vry|$j                  rm ||$      re|"r|#r|t9        | |      z  }nQ|"r|t9        jh                  | |      z  }n5|#r|t9        jj                  | |      z  }n|t9        jl                  | |      z  }|}  |D ]  }%|tS        |%      z  } |t        j                  u r+tC        t        d jG                  |      d|d            |j;                  |      }t        j                  g}&|j4                  } | |v r. ||       r&| jn                  r|&jq                  tS        |              |D ]  }'|'}! |tg        | |!            r|&jq                  t9        | |!dd             |'|v r|js                  |'       n<|'|v r|js                  |'        ||'      }(n|}(|(r|&jq                  tS        |'             |!}  |j2                  }!|!|v r. ||!      r&|!jn                  r|&jq                  tS        |!              |tg        | |!            r%|&jq                  t9        jl                  | |!             |t        j(                  k7  rr|j;                  |      }n#tu        tw        |& ||      jG                  |      }|s|S |j                  |      S # t        $ r t        t        d
            w xY w# tB        t
        f$ r1 t        t        d jG                  tI        d            z              w xY w# t        $ r t
        w xY w# t
        $ r t        d      w xY w# t        $ r t        j                  }d}Y w xY w)aT  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                    j                  t        |             }	 j                  |d      }|t        j                  t        j
                  fv r|S |j                  du rt        j
                  S |j                  d      }|j                  rj                  |d      S t        d|z        # t        $ r t        j
                  }Y w xY w)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   validz*solve_univariate_inequality.<locals>.valid  s     OOCA7 		!QA ))H%%.77NAA#yyA.-;a?A A !  A s   B/ /C
C=r#   c              3   4   K   | ]  }|j                     y wr   )r.   )r   r   s     rJ   r   z.solve_univariate_inequality.<locals>.<genexpr>@  s     <qq{{<s   )	separatedc                     | j                   S r   r   )r   s    rJ   <lambda>z-solve_univariate_inequality.<locals>.<lambda>C  s    Q=O=O rL   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B#99VZZ+B6::q1Bzz6::CSyAJJ&!!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!" 7A 5%(qGYGY &)A, 67 &'UUAEEs!')C.(H!I &A*/,K$|*/(%(]#%]#:r?R?RW\]_W`'2w(.(5!2D(D)4(.(..2J(J)0(.(..2J(J(.(--q2I(I$%E& "/ 3A"il2F3 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"s^   _4 A` Ca+ a  &b 'b 0b =C:b 4`A aa((a+ +b b"!b"c                    | j                   s|j                   s
| |z   dz  }|S | j                   r|j                   rt        j                  }|S | j                   r| j                  |j                   r|j                  t	        d      |j                   r|j
                  s| j                   r| j                  r|| }} |j                   r;| j                  r| dz  }|S | j
                  r| t        j                  z  }|S | dz   }|S | j                   r9|j                  r|t        j                  z  }|S |j
                  r|dz  }|S |dz
  }S )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     sI   S__ck1_6 I5 
		sVV2 I/ %"<"<"DC$<$<$DKLLOO 8 8!!e&@&@e3E ??))1W I ++166\ I QY I ''Z
 I	 ))U I 1WIrL   c                 r   ddl m} || j                  vr| S | j                  |k(  r| j                  } | j
                  |k(  r|| j                  j                  vr| S d }d}t        j                  }| j
                  | j                  z
  }	 t        ||      }|j                         dk(  r!| j                  |j                         d      }n|s|j                         dkD  rt        g }|j                         }d}|j)                  |d      \  }}||z  }||z  }t+        |      }|j)                  |d      \  }}|j,                  dk7  s.|j.                  |j0                  cxk(  r	 #n n | j2                  d	vr|}t        j4                  }||z  }|j0                  r| j                  ||      }n| j                  j                  ||      } || j
                         || j                        z  } ||      }||z
  D ]r  }t7        t9        |d      ||
      }t;        |t8              s,|j
                  |k(  s< ||||j                        t        j                   u sa|j=                  |        t | |fD ]U  } ||||      t        j                   u s || ||      t        j                   us9|j=                  ||u r||k  n||k         W |j=                  |       t'        | S # t        t        f$ r= |s+	 t        | gg|      }n# t        $ r t        | |      }Y nw xY w || ||      }	|	t        j                   u r/ ||||      t        j"                  u r|j%                  ||k  d      } || ||       }
|
t        j                   u rG ||||       t        j"                  u r,|j%                  | |k  d      }|j%                  || kD  d      }|t        j                   u rJ|	t        j                   u r||k  n||k  }|
t        j                   urt'        | |k  |      }nt        |      }Y Pw xY w)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                     	 | j                  ||      }|t        j                  u r|S |dvry |S # t        $ r t        j                  cY S w xY w)NTF)r   r   NaNr   )ierP   r   r   s       rJ   classifyz#_solve_inequality.<locals>.classify  sN    	1AAEEz-'H 	55L	s   %/ / / 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qM88:?a(BAHHJN%%0 E	zIIK
   4 02	Qq!_  5 11II&!%&		-AAq==CB!!!S)B ""&&>F266N:!N2 	%A!"Q(Af=A!R QUUaZB155)QVV3LL!$	% #r 	:AQ"aff,RA&aff4a2gQU1q59	:
 
LL;A 01 81B4&!<" 80Q78 B2&Dqvv~(2q""5"@WWQVT*RRC(ERRC(AGG3WWbS1Wd+WWQ"Wd+QVV|"&!&&.a2gq2v&bS1Wb)BT
A+s8   
AK) )P6=LP6L$!P6#L$$DP65P6c           
         i i }}g }| D ]_  }|j                   |j                  }}|j                  t              }t	        |      dk(  r|j                         nh|j                  |z  }	t	        |	      dk(  r7|	j                         |j                  t        t        |d|                   t        t        d            |j                        r$|j                  g       j                  ||f       |j                  fd      }
|
r7t        d |
D              r%|j                  g       j                  ||f       :|j                  t        t        |d|                   b |j!                         D cg c]  \  }}t#        |g|       }}}|j!                         D cg c]  \  }}t%        ||       }}}t'        ||z   |z    S c c}}w c c}}w )Nr$   r   zZ
                    inequality has more than one symbol of interest.
                    c                     | j                        xr3 | j                  xs% | j                  xr | j                  j                   S r   )ru   is_Functionr   r   r   )urz   s    rJ   r   z&_reduce_inequalities.<locals>.<lambda>  s;    c
 DB!B!%%2B2B.B rL   c              3   <   K   | ]  }t        |t                y wr   )r+   r   r   r   s     rJ   r   z'_reduce_inequalities.<locals>.<genexpr>  s     !I*Q"4!Is   )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    bxIE" O
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##C,33T3K@.z$3/GMN?OB R[Q`Q`Qbc:30%#>cLcIQIYZ:3*5#6ZKZ+e355 dZs    G-Gc                 V   t        |       s| g} | D cg c]  }t        |       } } t               j                  | D cg c]  }|j                   c} }t        |      s|g}t        |      xs ||z  }t        d |D              rt        t        d            |D ci c]&  }|j                  |t        |j                  d      ( }}| D cg c]  }|j                  |       } }|D ch c]  }|j                  |       }}g }| D ]  }t        |t              rF|j                  |j                  j!                         |j"                  j!                         z
  d      }n|dvrt%        |d      }|dk(  ro|dk(  rt&        j(                  c S |j                  j*                  rt-        d|z        |j/                  |        |} ~t1        | |      }|j                  |j3                         D ci c]  \  }}||
 c}}      S c c}w c c}w c c}w c c}w c c}w c c}}w )	aE  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   8   K   | ]  }|j                   d u   yw)FNr   r	  s     rJ   r   z&reduce_inequalities.<locals>.<genexpr>  s     
811&
8s   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51GAJ5L535;;>A>?DG)7|#tt+G

8
88
 $   	 5++3 qvvT22 5F 50<=1AJJv&=L=+23aqzz&!3G3 D a$quu}}8!<Am#1aA9%Z77N55??%7!;= =A L 
lG	4B ;;8A1899Q 6>5=30 9s"   HH +HH/H 7H%
)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>r3     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   