
9\c           @  s  d  Z  d d l m Z m 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 m Z d d l m Z d d l m Z m Z m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m  Z  d d l! m" 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, d   Z- d   Z. d   Z/ e0 d  Z1 d   Z2 d   Z3 e0 e j4 e5 d  Z6 d   Z7 e5 d  Z8 d   Z9 g  d  Z: d S(   s<   Tools for solving inequalities and systems of inequalities. i(   t   print_functiont   division(   t   Symbolt   Dummyt   sympify(   t   iterable(   t   factor_terms(   t
   Relationalt   Eqt   Get   Ltt   Ne(   t   Interval(   t	   FiniteSett   Uniont   EmptySett   Intersection(   t   ImageSet(   t   S(   t
   expand_mul(   t   Abs(   t   And(   t   Polyt   PolynomialErrort   parallel_poly_from_expr(   t   _nsort(   t   sift(   t
   filldedentc         C  s  t  |  t  s t d   n  |  j r t |  j   d |  } | t j k rX t j g S| t j	 k rq t j
 g St d |   n  |  j d t  g  } } | d k r x]| D]( \ } } t | |  } | j |  q Wn*| d k rFt j } x| t j d f g D]4 \ }	 } t | |	 t t  } | j |  |	 } qWn|  j   d k rbd 
}
 n d }
 d t } } | d	 k rd 
} n^ | d
 k rd } nI | d k rd 
t } } n, | d k rd t } } n t d |   t j t }	 } x t |  D] \ } } | d rd|
 | k rK| j d t | |	 | |   n  |
 | | }
 }	 } q|
 | k r| r| j d t | |	 t |   | t }	 } q|
 | k r| r| j d t | |   qqW|
 | k r	| j d t t j |	 t |   n  | S(   s@  Solve a polynomial inequality with rational coefficients.

    Examples
    ========

    >>> from sympy import Poly
    >>> from sympy.abc import x
    >>> from sympy.solvers.inequalities import solve_poly_inequality

    >>> 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
    s8   For efficiency reasons, `poly` should be a Poly instancei    s%   could not determine truth value of %st   multiples   ==s   !=i   it   >t   <s   >=s   <=s   '%s' is not a valid relationi   N(   t
   isinstanceR   t
   ValueErrort	   is_numberR   t   as_exprR   t   truet   Realst   falseR   t   NotImplementedErrort
   real_rootst   FalseR   t   appendt   NegativeInfinityt   Infinityt   Truet   LCt   Nonet   reversedt   insert(   t   polyt   relt   tt   realst	   intervalst   roott   _t   intervalt   leftt   rightt   signt   eq_signt   equalt
   right_opent   multiplicity(    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   solve_poly_inequality   sh    	

	#

	
 c         C  s@   d d l  m } | g  |  D] } t |   D] } | ^ q* q   S(   s  Solve polynomial inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy.solvers.inequalities import solve_poly_inequalities
    >>> from sympy.polys import Poly
    >>> 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))
    i(   R   (   t   sympyR   R@   (   t   polysR   t   pt   s(    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   solve_poly_inequalitiesr   s    c         C  s^  t  j } xN|  D]F} | s" q n  t t  j t  j  g } x | D] \ \ } } } t | | |  } t | d  } g  }	 xM | D]E }
 x< | D]4 } |
 j |  } | t  j k	 r |	 j |  q q Wq W|	 } g  }	 xH | D]@ } x | D] } | | 8} q W| t  j k	 r |	 j |  q q W|	 } | sA PqA qA Wx | D] } | j |  } q=Wq W| S(   sa  Solve a system of rational inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy.abc import x
    >>> from sympy import Poly
    >>> from sympy.solvers.inequalities import solve_rational_inequalities

    >>> 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
    s   ==(	   R   R   R   R*   R+   R@   t	   intersectR)   t   union(   t   eqst   resultt   _eqst   global_intervalst   numert   denomR2   t   numer_intervalst   denom_intervalsR5   t   numer_intervalt   global_intervalR8   t   denom_interval(    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   solve_rational_inequalities   s6    	c         C  s  t  } g  } |  r t j n t j } x|  D]} g  } x| D]} t | t  rb | \ } }	 n3 | j r | j | j | j	 } }	 n | d } }	 | t j
 k r t j t j d }
 } }	 nD | t j k r t j t j d }
 } }	 n | j   j   \ }
 } y% t |
 | f |  \ \ }
 } } Wn# t k
 rOt t d    n X| j j s|
 j   | j   t }
 } } n  | j j   } | j p| j s|
 | } t | d |	  } | t | | d t M} q> | j |
 | f |	 f  q> W| r+ | j |  q+ q+ W| r| t |  M} t g  | D]C } | D]6 \ \ } } } | j |  r9| | j f d f ^ q9q/g  } | | 8} n  | r| r| j    } n  | r| j! |  } n  | S(   s$  Reduce a system of rational inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy import Poly, 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) & (x < oo)
    >>> reduce_rational_inequalities([[(x + 2, ">")]], x)
    (-2 < x) & (x < oo)
    >>> reduce_rational_inequalities([[x + 2]], x)
    Eq(x, -2)
    s   ==s   
                    only polynomials and rational functions are
                    supported in this context.
                    i    t
   relational("   R,   R   R$   R   R   t   tuplet   is_Relationalt   lhst   rhst   rel_opR#   t   Zerot   OneR%   t   togethert   as_numer_denomR   R   R   t   domaint   is_Exactt   to_exactR(   t	   get_exactt   is_ZZt   is_QQR   t   solve_univariate_inequalityR)   RS   t   hast   onet   evalft   as_relational(   t   exprst   genRT   t   exactRH   t   solutiont   _exprsRJ   t   exprR2   RL   RM   t   optR^   t   it   nt   dR7   t   exclude(    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   reduce_rational_inequalities   sT    	"#
Sc           s   | j  t k r$ t t d    n    f d       |   } i d d 6d d 6} g  } xf | D]^ \ }  } | | j   k r t |  d |  }  n t |  d | |  }  | j |  g |  q` Wt | |  S(   s  Reduce an inequality with nested absolute values.

    Examples
    ========

    >>> from sympy import Abs, Symbol
    >>> from sympy.solvers.inequalities import reduce_abs_inequality
    >>> 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
    sr   
            can't solve inequalities with absolute values containing
            non-real variables.
            c   
        s  g  } |  j  s |  j r |  j } x|  j D]{ }   |  } | sL | } q+ g  } xK | D]C \ }  } x4 | D], \ } } | j | |  |  | | f  ql WqY W| } q+ Wn |  j r|  j }	 |	 j s t d   n    |  j	  } x | D]# \ }  } | j |  |	 | f  q Wn t
 |  t  r  |  j d  } xm | D]S \ }  } | j |  | t |  d  g f  | j |  | t |  d  g f  q@Wn |  g  f g } | S(   Ns'   Only Integer Powers are allowed on Abs.i    (   t   is_Addt   is_Mult   funct   argsR)   t   is_Powt   expt
   is_IntegerR    t   baseR   R   R	   R
   (
   Rn   Ri   t   opt   argRm   Rx   t   condst   _exprt   _condsRq   (   t   _bottom_up_scan(    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyR   4  s4    		(			#+R   R   s   >=s   <=i    (   t   is_realR(   t	   TypeErrorR   t   keysR   R)   Rt   (   Rn   R2   Rj   Ri   t   mappingt   inequalitiesR   (    (   R   s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   reduce_abs_inequality  s    'c         C  s/   t  g  |  D] \ } } t | | |  ^ q
   S(   sU  Reduce a system of inequalities with nested absolute values.

    Examples
    ========

    >>> from sympy import Abs, Symbol
    >>> from sympy.abc import x
    >>> from sympy.solvers.inequalities import reduce_abs_inequalities
    >>> x = Symbol('x', 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   (   Ri   Rj   Rn   R2   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   reduce_abs_inequalitiesk  s    c   1        sa	  d d l  m } d d l m } m } m } d d l m }	 d d l m	 }
 m
 } m } d d l m }  } | }  j t k r t j } | s | S| j |  S j d k rt d d t  y  j i  | 6  Wqt k
 rt t d	    qXn  d }  t j k r%| } n% t j k r@t j } n
 j  j } | |   } | t j k rt |  }  j | d
  } | t j k r| } q| t j k rt j } qn| d k	 r| |  |  }  j } | d k s| d k rC j | j  d
  r| } q j | j! d
  st j } qnZ | d k s[| d k r j | j! d
  ry| } q j | j  d
  st j } qn  | j! | j  } } | | t j" k rt# d
 | t t  } qn  | d k rJ	| j$   \ } } yX  | j% k r,t& | j%  d k r,t'  n  | |  |  } | d k rSt'  n  Wn? t' t( f k
 rt( t d  j)  t* d      n Xt |        f d   } g  } x0 |	    D] } | j+ | |  |   qW| s|    |  } n  d  j k o& j d k } yt, | j- t. | j! | j    } t. | | t/ |    j0 t# | j! | j  | j! | k | j  | k   } t1 d   | D  rt2 | d t d
 }  nt t3 | d    }! |! d rt(  n  y5 |! t }  t& |   d k r t/ t4 |    }  n  Wn t k
 r:t(  n XWn t( k
 r[t( d   n Xt j5 }" |    t j k rt }# t.   }$ y| |     |  }% t6 |% t#  sxp|% D]: }& |& | k r| |&  r|& j r|$ t. |&  7}$ qqWn+|% j! |% j  }' }( x t2 | t. |(   D] }& | |'  }) |' |( k r| |&  }* t7 |' |&  }+ |+ | k r|+ j r| |+  r|) r|* r|$ t# |' |&  7}$ q|) r|$ t# j8 |' |&  7}$ q|* r|$ t# j9 |' |&  7}$ q|$ t# j: |' |&  7}$ qn  |& }' q%Wx | D] }, |$ t. |,  8}$ qWWn  t k
 rIt j5 }$ t }# n Xt6 |$ t  rt' t d  j)  |  | f    n  |" j; |$  }" n  t j g }- }. | j! }' | |'  r|' j< r|. j= t. |'   n  x |  D] }/ |/ }( | t7 |' |(   r!|. j= t# |' |( t t   n  |/ | k r=| j> |/  nJ |/ | k re| j> |/  | |/  }0 n | }0 |0 r|. j= t. |/   n  |( }' qW| j  }( | |(  r|( j< r|. j= t. |(   n  | t7 |' |(   r|. j= t# j: |' |(   n  |    t j k r#	|# r#	|" j; |  } qJ	t? t@ |.   |" |  j)  |  } n  | sT	| S| j |  S(   s0  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() doesn't need to be called on it)

    Raises
    ======

    NotImplementedError
        The solution of the inequality cannot be determined due to limitation
        in `solvify`.

    Notes
    =====

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

    See Also
    ========

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

    Examples
    ========

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

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

    >>> 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)

    i(   t   im(   t   continuous_domaint   periodicityt   function_range(   t   denoms(   t   solveset_realt   solvifyt   solveset(   t   solveRj   t   reals   
                When gen is real, the relational has a complex part
                which leads to an invalid comparison like I < 0.
                i    R   s   <=R   s   >=i   s   
                    The inequality, %s, cannot be solved using
                    solve_univariate_inequality.
                    t   xc           s     j   t |    } y  j | d  } Wn t k
 rJ t j } n X| t j t j f k rg | S| j t k r} t j S| j	 d  } | j
 r  j | d  St d |   d  S(   Ni    i   s!   relationship did not evaluate: %s(   t   subsR   Rw   R   R   R%   R#   R   R(   Rq   t   is_comparableR&   (   R   t   vt   r(   t
   expanded_eRn   Rj   (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   valid  s    
	t   =s   !=c         s  s   |  ] } | j  Vq d  S(   N(   R!   (   t   .0R   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys	   <genexpr>>  s    t	   separatedc         S  s   |  j  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   <lambda>A  t    s'   sorting of these roots is not supporteds   
                        %s contains imaginary parts which cannot be
                        made 0 for any value of %s satisfying the
                        inequality, leading to relations like I < 0.
                        N(A   RA   R   t   sympy.calculus.utilR   R   R   t   sympy.solvers.solversR   t   sympy.solvers.solvesetR   R   R   R   R   R(   R   R   Rh   R.   R   R,   t   xreplaceR   R   R#   R%   RW   RX   RZ   R   Rw   RY   t   supt   infR+   R   R]   t   free_symbolst   lenR    R&   R   R   t   extendt   sett   boundaryR   t   listt   intersectiont   allR   R   t   sortedR$   R   t   _ptt   Ropent   Lopent   openRF   t	   is_finiteR)   t   removeR   R   (1   Rn   Rj   RT   R^   t
   continuousR   R   R   R   R   R   R   R   R   t   _gent   _domaint   rvt   et   periodt   constt   frangeR2   R   R   Rq   Rr   t   solnsR   t   singularitiest	   include_xt   discontinuitiest   critical_pointsR4   t   siftedt	   make_realt   checkt   im_solt   at   zt   startt   endt   valid_startt   valid_zt   ptRD   t   emptyt   sol_setsR   t   _valid(    (   R   Rn   Rj   s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyRd     s&   :						$	&	!
	
		!!
	
%	
	$c         C  sD  |  j  r% | j  r% |  | d } n|  j  rC | j  rC t j } n |  j  r[ |  j d k ss | j  r | j d k r t d   n  | j  r | j s |  j  r |  j r | |  }  } n  | j  r |  j r |  d } q@|  j r |  t j } q@|  d } nE |  j  r@| j r| t j } q@| j r3| d } q@| d } n  | S(   s$   Return a point between start and endi   s,   cannot proceed with unsigned infinite valuesi   N(   t   is_infiniteR   RZ   t   is_positiveR.   R    t   is_negativet   Half(   R   R   R   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyR     s.    						c         C  s  d d l  m } | |  j k r# |  S|  j | k r> |  j }  n  |  j | k rc | |  j j k rc |  Sd   } d
 } t j } |  j |  j } yb t	 | |  } | j
   d k r |  j | j   d  } n" | r | j
   d k r t  n  Wnt t f k
 r| ssy t |  g g |  } Wn  t k
 rDt |  |  } n X| |  | |  }	 |	 t j k r| | | |  t j k r| j | | k  t  } n  | |  | |  }
 |
 t j k r| | | |  t j k r| j | | k  t  } | j | | k t  } n  | t j k r|	 t j k r9| | k n	 | | k  } |
 t j k	 rpt | | k  |  } qpqqt	 |  } n Xg  } | d
 k r| j   } d } | j | d t \ } } | | 8} | | 8} t |  } | j | d t \ } } | j t k s=| j | j k o)d
 k n rO|  j d k rO| } t j } n  | | } | j rw|  j | |  } n |  j j | |  } | |  j  | |  j  B} | |  } x | | D]t } t t | d  | d	 | } t  | t  r| j | k r| | | | j  t j k r3| j! |  q3qqWx| | | f D]j } | | | |  t j k rE| |  | |  t j k	 rE| j! | | k r| | k  n	 | | k   qEqEWn  | j! |  t |   S(   s  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 don't 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)
    i(   R   c         S  s_   yC |  j  | |  } | t j k r( | S| t t f k r> d  S| SWn t k
 rZ t j SXd  S(   N(   R   R   t   NaNR,   R(   R   (   t   ieRD   Rp   R   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   classify  s    i    i   t   as_Adds   !=s   ==t   linearN(   s   !=s   ==("   R   R   R   RX   R/   RW   R.   R   R+   R   t   degreeRw   R"   R&   R   Rt   Rd   R#   R%   R   R,   R   t   as_independentR   R(   t   is_zeroR   R   RY   R[   t   _solve_inequalityR   R   R)   (   R   RD   R   R   R   R   t   ooRn   RC   t   okoot   oknooR   R   RX   t   bt   axt   efR   t   beginning_denomst   current_denomsRr   t   cRp   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyR     s    J!		*'


	5c           s  i  i  } } g  } x_|  D]W} | j  | j } } | j t  } t |  d k rc | j     ne | j | @}	 t |	  d k r |	 j     | j t t	 | d |      q n t
 t d    | j    r | j   g   j | | f  q | j   f d    }
 |
 rOt d   |
 D  rO| j   g   j | | f  q | j t t	 | d |      q Wg  } g  } x3 | j   D]% \   } | j t | g     qWx0 | j   D]" \   } | j t |     qWt | | |   S(   Ni   i    sZ   
                    inequality has more than one symbol of interest.
                    c           s,   |  j     o+ |  j p+ |  j o+ |  j j S(   N(   Re   t   is_FunctionRy   Rz   R{   (   t   u(   Rj   (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyR     s    c         s  s   |  ] } t  | t  Vq d  S(   N(   R   R   (   R   Rp   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys	   <genexpr>  s    (   RW   RY   t   atomsR   R   t   popR   R)   R   R   R&   R   t   is_polynomialt
   setdefaultt   findR   t   itemsRt   R   R   (   R   t   symbolst	   poly_partt   abs_partt   othert
   inequalityRn   R2   t   genst   commont
   componentst   poly_reducedt   abs_reducedRi   (    (   Rj   s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   _reduce_inequalitiesq  s6    """&c           s  t  |   s |  g }  n  g  |  D] } t |  ^ q }  t   j g  |  D] } | j ^ qG   } t  |  sw | g } n  t |  p | | @} t d   | D  r t t d    n  d   | D   g  |  D] } | j    ^ q }    f d   | D } g  } x |  D] } t	 | t
  rM| j | j j   | j j   d  } n$ | t t f k rqt | d  } n  | t k rqn | t k rt j S| j j rt d |   n  | j |  qW| }  ~ t |  |  } | j d     j   D  S(   s  Reduce a system of inequalities with rational coefficients.

    Examples
    ========

    >>> from sympy import sympify as S, Symbol
    >>> from sympy.abc import x, y
    >>> from sympy.solvers.inequalities 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         s  s   |  ] } | j  t k Vq d  S(   N(   R   R(   (   R   Rp   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys	   <genexpr>  s    sP   
            inequalities cannot contain symbols that are not real.
            c         S  s7   i  |  ]- } | j  d k r t | j d  t |  q S(   R   N(   R   R.   R   t   nameR,   (   R   Rp   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys
   <dictcomp>  s   	c           s   h  |  ] } | j      q S(    (   R   (   R   Rp   (   t   recast(    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys	   <setcomp>  s   	 i    s%   could not determine truth value of %sc         S  s   i  |  ] \ } } | |  q S(    (    (   R   t   kR   (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pys
   <dictcomp>  s   	 (   R   R   R   RG   R   t   anyR   R   R   R   R   Rw   RW   R"   RX   R,   R(   R   R   R%   R!   R&   R)   R   R   (   R   R   Rp   R   t   keepR   (    (   R   s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   reduce_inequalities  s@    (
"+N(;   t   __doc__t
   __future__R    R   t
   sympy.coreR   R   R   t   sympy.core.compatibilityR   t   sympy.core.exprtoolsR   t   sympy.core.relationalR   R   R	   R
   R   t
   sympy.setsR   t   sympy.sets.setsR   R   R   R   t   sympy.sets.fancysetsR   t   sympy.core.singletonR   t   sympy.core.functionR   t   sympy.functionsR   t   sympy.logicR   t   sympy.polysR   R   R   t   sympy.polys.polyutilsR   t   sympy.utilities.iterablesR   t   sympy.utilities.miscR   R@   RE   RS   R,   Rt   R   R   R$   R(   Rd   R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/sympy/solvers/inequalities.pyt   <module>   s8   ("	\		CR	R	 	!	3