
\c           @  s`  d  d l  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 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 d  d l m Z d  d l m  Z  m! Z! d  d l" m# Z# m$ Z$ d  d l% m& Z& m' Z' m( Z( d  d l) m* Z* m+ Z+ m, Z, d  d l- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 d  d l9 m: Z: m; Z; d  d l< m= Z= m> Z> d e f d     YZ? d e? f d     YZ@ d e? e f d     YZA d e? e e f d     YZB d  e? e f d!     YZC d" e? e f d#     YZD d$ e	 e# e?  f d%     YZE d& e	 e# e?  f d'     YZF d( e? e f d)     YZG d*   e, eH <d+   e, eI <d, e? f d-     YZJ d.   ZK d/   ZL d0   ZM d1   ZN d2   ZO d3   ZP d4   ZQ d5   ZR d6   ZS d7   ZT d8   ZU d9   ZV d: S(;   i(   t   print_functiont   division(   t   product(   t   Basic(   t   iterablet   with_metaclasst   orderedt   ranget   PY3(   t   cacheit(   t
   EvalfMixin(   t   global_evaluate(   t   Expr(   t   FunctionClass(   t
   fuzzy_bool(   t   Mul(   t   Float(   t	   LatticeOp(   t   Eqt   Ne(   t	   Singletont   S(   t   Symbolt   Dummyt   _uniquely_named_symbol(   t   _sympifyt   sympifyt	   converter(   t   Andt   Ort   Nott   truet   false(   t   Contains(   t   subsets(   t   sift(   t	   func_namet
   filldedent(   t   mpit   mpft   Setc           B  s  e  Z d  Z e Z e Z e Z e Z e Z e Z	 e Z
 d) Z d) Z d) Z d) Z e Z e d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z e d    Z e d    Z e d    Z e d    Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* e d    Z+ e d    Z, e d    Z- e d    Z. e d    Z/ e d    Z0 e d    Z1 e d     Z2 d!   Z3 d"   Z4 d#   Z5 d$   Z6 d%   Z7 d&   Z8 d'   Z9 d(   Z: RS(*   s  
    The base class for any kind of set.

    This is not meant to be used directly as a container of items. It does not
    behave like the builtin ``set``; see :class:`FiniteSet` for that.

    Real intervals are represented by the :class:`Interval` class and unions of
    sets by the :class:`Union` class. The empty set is represented by the
    :class:`EmptySet` class and available as a singleton as ``S.EmptySet``.
    c         C  sI   y |  j  } | j s t  Wn& t t t t f k
 rD t j } n X| S(   s?   
        Return infimum (if possible) else S.Infinity.
        (   t   inft   is_comparablet   AssertionErrort   NotImplementedErrort   AttributeErrort
   ValueErrorR   t   Infinity(   t   exprt   infimum(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _infimum_key6   s    	c         C  s   t  |  |  S(   s  
        Returns the union of 'self' and 'other'.

        Examples
        ========

        As a shortcut it is possible to use the '+' operator:

        >>> from sympy import Interval, FiniteSet
        >>> Interval(0, 1).union(Interval(2, 3))
        Union(Interval(0, 1), Interval(2, 3))
        >>> Interval(0, 1) + Interval(2, 3)
        Union(Interval(0, 1), Interval(2, 3))
        >>> Interval(1, 2, True, True) + FiniteSet(2, 3)
        Union(Interval.Lopen(1, 2), {3})

        Similarly it is possible to use the '-' operator for set differences:

        >>> Interval(0, 2) - Interval(0, 1)
        Interval.Lopen(1, 2)
        >>> Interval(1, 3) - FiniteSet(2)
        Union(Interval.Ropen(1, 2), Interval.Lopen(2, 3))

        (   t   Union(   t   selft   other(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   unionC   s    c         C  s   t  |  |  S(   s  
        Returns the intersection of 'self' and 'other'.

        >>> from sympy import Interval

        >>> Interval(1, 3).intersect(Interval(1, 2))
        Interval(1, 2)

        >>> from sympy import imageset, Lambda, symbols, S
        >>> n, m = symbols('n m')
        >>> a = imageset(Lambda(n, 2*n), S.Integers)
        >>> a.intersect(imageset(Lambda(m, 2*m + 1), S.Integers))
        EmptySet()

        (   t   Intersection(   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt	   intersect^   s    c         C  s   |  j  |  S(   s/   
        Alias for :meth:`intersect()`
        (   R8   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   intersectionp   s    c         C  s   |  j  |  t j k S(   sx  
        Returns True if 'self' and 'other' are disjoint

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 2).is_disjoint(Interval(1, 2))
        False
        >>> Interval(0, 2).is_disjoint(Interval(3, 4))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Disjoint_sets
        (   R8   R   t   EmptySet(   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_disjointv   s    c         C  s   |  j  |  S(   s1   
        Alias for :meth:`is_disjoint()`
        (   R;   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt
   isdisjoint   s    c         C  s   t  | |   S(   s\  
        The complement of 'self' w.r.t the given universe.

        Examples
        ========

        >>> from sympy import Interval, S
        >>> Interval(0, 1).complement(S.Reals)
        Union(Interval.open(-oo, 0), Interval.open(1, oo))

        >>> Interval(0, 1).complement(S.UniversalSet)
        UniversalSet() \ Interval(0, 1)

        (   t
   Complement(   R4   t   universe(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt
   complement   s    c           s  t    t  r^ t d   t  j   j  D  } d   | D } t   f d   | D   St    t  r t   t  s t   t  rt    j t	 j
   Sn t    t  r t  f d     j D   St    t  rt   j d t   j d   d t St    t  r"t	 j St    t  rd d	 l m } |    f d
    } t t | t   | d  rt t | d     d t n t	 j  Sd  S(   Nc         s  s(   |  ] \ } } t  | | |  Vq d  S(   N(   t	   FiniteSet(   t   .0t   st   o(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>   s    c         s  s   |  ] } t  |   Vq d  S(   N(   t
   ProductSet(   RA   t   set(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>   s    c         3  s!   |  ] } |   k r | Vq d  S(   N(    (   RA   t   p(   R5   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>   s    c         3  s   |  ] } |   Vq d  S(   N(    (   RA   RC   (   R4   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>   s    i    i   t   evaluatei(   R#   c           s   t    j |    S(   N(   R   t   contains(   t   x(   R4   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   <lambda>   t    (   t
   isinstanceRD   t   zipt   setsR3   t   IntervalR@   R7   R?   R   t   Realst   argsR=   t   FalseR:   t   sympy.utilities.iterablesR#   t   None(   R4   R5   t   switch_setst   product_setsR#   t   sifted(    (   R5   R4   s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _complement   s&    
	*c         C  s   t  |  |  S(   sU  
        Returns symmetric difference of `self` and `other`.

        Examples
        ========

        >>> from sympy import Interval, S
        >>> Interval(1, 3).symmetric_difference(S.Reals)
        Union(Interval.open(-oo, 1), Interval.open(3, oo))
        >>> Interval(1, 10).symmetric_difference(S.Reals)
        Union(Interval.open(-oo, 1), Interval.open(10, oo))

        >>> from sympy import S, EmptySet
        >>> S.Reals.symmetric_difference(EmptySet())
        Reals

        References
        ==========
        .. [1] https://en.wikipedia.org/wiki/Symmetric_difference

        (   t   SymmetricDifference(   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   symmetric_difference   s    c         C  s   t  t |  |  t | |    S(   N(   R3   R=   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _symmetric_difference   s    c         C  s   |  j  S(   s   
        The infimum of 'self'

        Examples
        ========

        >>> from sympy import Interval, Union
        >>> Interval(0, 1).inf
        0
        >>> Union(Interval(0, 1), Interval(2, 3)).inf
        0

        (   t   _inf(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR)      s    c         C  s   t  d |    d  S(   Ns	   (%s)._inf(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR\      s    c         C  s   |  j  S(   s   
        The supremum of 'self'

        Examples
        ========

        >>> from sympy import Interval, Union
        >>> Interval(0, 1).sup
        1
        >>> Union(Interval(0, 1), Interval(2, 3)).sup
        3

        (   t   _sup(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   sup   s    c         C  s   t  d |    d  S(   Ns	   (%s)._sup(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR]   
  s    c         C  sO   t  | d t } t  |  j |   } | d k rK t | |  d t } n  | S(   s@  
        Returns True if 'other' is contained in 'self' as an element.

        As a shortcut it is possible to use the 'in' operator:

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1).contains(0.5)
        True
        >>> 0.5 in Interval(0, 1)
        True

        t   strictRG   N(   R   t   Truet	   _containsRT   R!   RR   (   R4   R5   t   ret(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRH     s
    c         C  s   t  d |  | f   d  S(   Ns   (%s)._contains(%s)(   R,   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa   $  s    c         C  s6   t  | t  r" |  j |  |  k St d |   d S(   s#  
        Returns True if 'self' is a subset of 'other'.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 0.5).is_subset(Interval(0, 1))
        True
        >>> Interval(0, 1).is_subset(Interval(0, 1, left_open=True))
        False

        s   Unknown argument '%s'N(   RL   R(   R8   R.   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt	   is_subset'  s    c         C  s   |  j  |  S(   s/   
        Alias for :meth:`is_subset()`
        (   Rc   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   issubset:  s    c         C  s<   t  | t  r( |  | k o' |  j |  St d |   d S(   s(  
        Returns True if 'self' is a proper subset of 'other'.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 0.5).is_proper_subset(Interval(0, 1))
        True
        >>> Interval(0, 1).is_proper_subset(Interval(0, 1))
        False

        s   Unknown argument '%s'N(   RL   R(   Rc   R.   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_proper_subset@  s    c         C  s0   t  | t  r | j |   St d |   d S(   s)  
        Returns True if 'self' is a superset of 'other'.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 0.5).is_superset(Interval(0, 1))
        False
        >>> Interval(0, 1).is_superset(Interval(0, 1, left_open=True))
        True

        s   Unknown argument '%s'N(   RL   R(   Rc   R.   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_supersetS  s    c         C  s   |  j  |  S(   s1   
        Alias for :meth:`is_superset()`
        (   Rf   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt
   issupersetf  s    c         C  s<   t  | t  r( |  | k o' |  j |  St d |   d S(   s.  
        Returns True if 'self' is a proper superset of 'other'.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1).is_proper_superset(Interval(0, 0.5))
        True
        >>> Interval(0, 1).is_proper_superset(Interval(0, 1))
        False

        s   Unknown argument '%s'N(   RL   R(   Rf   R.   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_proper_supersetl  s    c         C  s   t  d |  j   d  S(   Ns   Power set not defined for: %s(   R,   t   func(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _eval_powerset  s    c         C  s
   |  j    S(   s  
        Find the Power set of 'self'.

        Examples
        ========

        >>> from sympy import FiniteSet, EmptySet
        >>> A = EmptySet()
        >>> A.powerset()
        {EmptySet()}
        >>> A = FiniteSet(1, 2)
        >>> a, b, c = FiniteSet(1), FiniteSet(2), FiniteSet(1, 2)
        >>> A.powerset() == FiniteSet(a, b, c, EmptySet())
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Power_set

        (   Rj   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   powerset  s    c         C  s   |  j  S(   s   
        The (Lebesgue) measure of 'self'

        Examples
        ========

        >>> from sympy import Interval, Union
        >>> Interval(0, 1).measure
        1
        >>> Union(Interval(0, 1), Interval(2, 3)).measure
        2

        (   t   _measure(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   measure  s    c         C  s   |  j  S(   s=  
        The boundary or frontier of a set

        A point x is on the boundary of a set S if

        1.  x is in the closure of S.
            I.e. Every neighborhood of x contains a point in S.
        2.  x is not in the interior of S.
            I.e. There does not exist an open set centered on x contained
            entirely within S.

        There are the points on the outer rim of S.  If S is open then these
        points need not actually be contained within S.

        For example, the boundary of an interval is its start and end points.
        This is true regardless of whether or not the interval is open.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1).boundary
        {0, 1}
        >>> Interval(0, 1, True, False).boundary
        {0, 1}
        (   t	   _boundary(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   boundary  s    c         C  s   t  |  |  j  s t Sd S(   s
  
        Property method to check whether a set is open.
        A set is open if and only if it has an empty intersection with its
        boundary.

        Examples
        ========
        >>> from sympy import S
        >>> S.Reals.is_open
        True
        N(   R7   Ro   R`   RT   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_open  s    c         C  s   |  j  j |   S(   s   
        A property method to check whether a set is closed. A set is closed
        if it's complement is an open set.

        Examples
        ========
        >>> from sympy import Interval
        >>> Interval(0, 1).is_closed
        True
        (   Ro   Rc   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt	   is_closed  s    c         C  s   |  |  j  S(   sN  
        Property method which returns the closure of a set.
        The closure is defined as the union of the set itself and its
        boundary.

        Examples
        ========
        >>> from sympy import S, Interval
        >>> S.Reals.closure
        Reals
        >>> Interval(0, 1).closure
        Interval(0, 1)
        (   Ro   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   closure  s    c         C  s   |  |  j  S(   sz  
        Property method which returns the interior of a set.
        The interior of a set S consists all points of S that do not
        belong to the boundary of S.

        Examples
        ========
        >>> from sympy import Interval
        >>> Interval(0, 1).interior
        Interval.open(0, 1)
        >>> Interval(0, 1).boundary.interior
        EmptySet()
        (   Ro   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   interior  s    c         C  s   t     d  S(   N(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn     s    c         C  s   t  d |    d  S(   Ns   (%s)._measure(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl     s    c         C  s   |  j  |  S(   N(   R6   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __add__  s    c         C  s   |  j  |  S(   N(   R6   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __or__  s    c         C  s   |  j  |  S(   N(   R8   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __and__  s    c         C  s   t  |  |  S(   N(   RD   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __mul__  s    c         C  s   t  |  |  S(   N(   RY   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __xor__  s    c         C  s@   t  |  j r/ | d k r/ t d |   n  t |  g |  S(   Ni    s'   %s: Exponent must be a positive Integer(   R   t
   is_IntegerR.   RD   (   R4   t   exp(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __pow__"  s    c         C  s   t  |  |  S(   N(   R=   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __sub__'  s    c         C  sP   t  |  j |   } | t j k p0 | t j k sF t d |   n  t |  S(   Ns'   contains did not evaluate to a bool: %r(   R   RH   R   R   R    t	   TypeErrort   bool(   R4   R5   t   symb(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __contains__*  s    N(;   t   __name__t
   __module__t   __doc__RR   t	   is_numbert   is_iterablet   is_intervalt   is_FiniteSett   is_Intervalt   is_ProductSett   is_UnionRT   t   is_Intersectiont   is_EmptySett   is_UniversalSett   is_Complementt   is_ComplexRegiont   staticmethodR2   R6   R8   R9   R;   R<   R?   RX   RZ   R[   t   propertyR)   R\   R^   R]   RH   Ra   Rc   Rd   Re   Rf   Rg   Rh   Rj   Rk   Rm   Ro   Rp   Rq   Rr   Rs   Rn   Rl   Rt   Ru   Rv   Rw   Rx   R{   R|   R   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR(      sj   
							(																			RD   c           B  s   e  Z d  Z e Z d   Z d   Z d   Z e d    Z	 e d    Z
 e d    Z d   Z e d    Z d	   Z d
   Z e Z RS(   sS  
    Represents a Cartesian Product of Sets.

    Returns a Cartesian product given several sets as either an iterable
    or individual arguments.

    Can use '*' operator on any sets for convenient shorthand.

    Examples
    ========

    >>> from sympy import Interval, FiniteSet, ProductSet
    >>> I = Interval(0, 5); S = FiniteSet(1, 2, 3)
    >>> ProductSet(I, S)
    Interval(0, 5) x {1, 2, 3}

    >>> (2, 2) in ProductSet(I, S)
    True

    >>> Interval(0, 1) * Interval(0, 1) # The unit square
    Interval(0, 1) x Interval(0, 1)

    >>> coin = FiniteSet('H', 'T')
    >>> set(coin**2)
    {(H, H), (H, T), (T, H), (T, T)}


    Notes
    =====

    - Passes most operations down to the argument sets
    - Flattens Products of ProductSets

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Cartesian_product
    c           sv     f d       t  |   } t   | k sB t |  d k rI t   St |  d k rc | d St j |  | |  S(   Nc           sm   t  |  t  r; |  j r1 t t   |  j  g   S|  g Sn" t |   r] t t   |   g   St d   d  S(   Ns'   Input must be Sets or iterables of Sets(   RL   R(   R   t   sumt   mapRQ   R   R}   (   t   arg(   t   flatten(    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   [  s    	
i    i   (   t   listR:   t   lenR   t   __new__(   t   clsRN   t   assumptions(    (   R   s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   Z  s    	!c         C  sR   | j  s d  St |  j  t | j  k r/ t St d   t |  j | j  D   S(   Nc         s  s$   |  ] \ } } t  | |  Vq d  S(   N(   R   (   RA   RI   t   y(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>u  s    (   R   R   RQ   R    R   RM   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _eval_Eqn  s
    	c         C  sp   y# t  |  t  |  j  k r" t SWn t k
 r7 t SXt g  t |  j |  D] \ } } | j |  ^ qN   S(   s5  
        'in' operator for ProductSets

        Examples
        ========

        >>> from sympy import Interval
        >>> (2, 3) in Interval(0, 5) * Interval(0, 5)
        True

        >>> (10, 10) in Interval(0, 5) * Interval(0, 5)
        False

        Passes operation on to constituent sets
        (   R   RQ   R    R}   R   RM   RN   RH   (   R4   t   elementRE   t   item(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa   w  s    c         C  s   |  j  S(   N(   RQ   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRN     s    c           s#   t    f d   t   j  D   S(   Nc         3  s:   |  ]0 \   } t    f d    t  j  D  Vq d S(   c         3  s7   |  ]- \ } }   | k r( | | j  n | j  Vq d  S(   N(   Ro   (   RA   t   jt   b(   t   i(    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s   N(   RD   t	   enumerateRN   (   RA   t   a(   R4   (   R   s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s   (   R3   R   RN   (   R4   (    (   R4   s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn     s    c         C  s   t  d   |  j D  S(   s  
        A property method which tests whether a set is iterable or not.
        Returns True if set is iterable, otherwise returns False.

        Examples
        ========

        >>> from sympy import FiniteSet, Interval, ProductSet
        >>> I = Interval(0, 1)
        >>> A = FiniteSet(1, 2, 3, 4, 5)
        >>> I.is_iterable
        False
        >>> A.is_iterable
        True

        c         s  s   |  ] } | j  Vq d  S(   N(   R   (   RA   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    (   t   allRN   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s&   |  j  r t |  j   St d   d S(   s   
        A method which implements is_iterable property method.
        If self.is_iterable returns True (both constituent sets are iterable),
        then return the Cartesian Product. Otherwise, raise TypeError.
        s%   Not all constituent sets are iterableN(   R   R   RN   R}   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __iter__  s    	c         C  s+   d } x |  j  D] } | | j 9} q W| S(   Ni   (   RN   Rm   (   R4   Rm   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl     s    c         C  s&   t  g  |  j D] } t |  ^ q   S(   N(   R   RQ   R   (   R4   RB   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __len__  s    c         C  s&   t  g  |  j D] } t |  ^ q  S(   N(   R   RQ   R~   (   R4   RB   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __bool__  s    (   R   R   R   R`   R   R   R   Ra   R   RN   Rn   R   R   Rl   R   R   t   __nonzero__(    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRD   1  s   &							RO   c           B  s  e  Z d  Z e Z e e d  Z e d    Z e Z	 Z
 e d    Z e d    Z e d    Z e d    Z e Z Z e d    Z e d    Z d	   Z e d
    Z d   Z e d    Z d d  Z d   Z d   Z e d    Z e d    Z d   Z d   Z RS(   s  
    Represents a real interval as a Set.

    Usage:
        Returns an interval with end points "start" and "end".

        For left_open=True (default left_open is False) the interval
        will be open on the left. Similarly, for right_open=True the interval
        will be open on the right.

    Examples
    ========

    >>> from sympy import Symbol, Interval
    >>> Interval(0, 1)
    Interval(0, 1)
    >>> Interval.Ropen(0, 1)
    Interval.Ropen(0, 1)
    >>> Interval.Ropen(0, 1)
    Interval.Ropen(0, 1)
    >>> Interval.Lopen(0, 1)
    Interval.Lopen(0, 1)
    >>> Interval.open(0, 1)
    Interval.open(0, 1)

    >>> a = Symbol('a', real=True)
    >>> Interval(0, a)
    Interval(0, a)

    Notes
    =====
    - Only real end points are supported
    - Interval(a, b) with a > b will return the empty set
    - Use the evalf() method to turn an Interval into an mpmath
      'mpi' interval instance

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Interval_%28mathematics%29
    c           s  t  |  } t  |  } t  |  } t  |  } t d   | | g D  se t d | | f   n  t j t j g   t   f d   | | f D  s t d   n  | | k  t k r t j S| | j	 r t j S| | k r | s | r t j S| | k r<| p	| r<| t j k s+| t j k r2t j St
 |  S| t j k rTt } n  | t j k rlt } n  t j |  | | | |  S(   Nc         s  s0   |  ]& } t  | t t  t t  f  Vq d  S(   N(   RL   t   typeR   R    (   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s   sG   left_open and right_open can have only true/false values, got %s and %sc         3  s*   |  ]  } | j  t k	 p! |   k Vq d  S(   N(   t   is_realRR   (   RA   R   (   t   inftys(    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    s$   Non-real intervals are not supported(   R   R   R,   R   R/   t   NegativeInfinityR.   R`   R:   t   is_negativeR@   R   R   R   (   R   t   startt   endt	   left_opent
   right_open(    (   R   s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s6    	"
		c         C  s   |  j  d S(   s   
        The left end point of 'self'.

        This property takes the same value as the 'inf' property.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1).start
        0

        i    (   t   _args(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   |  | | t  t   S(   s.   Return an interval including neither boundary.(   R`   (   R   R   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   open/  s    c         C  s   |  | | t  t  S(   s3   Return an interval not including the left boundary.(   R`   RR   (   R   R   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   Lopen4  s    c         C  s   |  | | t  t  S(   s4   Return an interval not including the right boundary.(   RR   R`   (   R   R   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   Ropen9  s    c         C  s   |  j  d S(   s   
        The right end point of 'self'.

        This property takes the same value as the 'sup' property.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1).end
        1

        i   (   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   >  s    c         C  s   |  j  d S(   s   
        True if 'self' is left-open.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1, left_open=True).left_open
        True
        >>> Interval(0, 1, left_open=False).left_open
        False

        i   (   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   Q  s    c         C  s   |  j  d S(   s  
        True if 'self' is right-open.

        Examples
        ========

        >>> from sympy import Interval
        >>> Interval(0, 1, right_open=True).right_open
        True
        >>> Interval(0, 1, right_open=False).right_open
        False

        i   (   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   b  s    c         C  s   | t  j k rZ t t  j |  j t |  j  } t |  j t  j |  j	 t  } t
 | |  St | t  r g  | j D] } | j rs | ^ qs } | g  k r d  Sn  t j |  |  S(   N(   R   RP   RO   R   R   R`   R   R   R/   R   R3   RL   R@   RQ   R   RT   R(   RX   (   R4   R5   R   R   t   mt   nums(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRX   s  s    %c         C  sD   g  |  j  |  j f D]! } t |  t j k r | ^ q } t |   S(   N(   R   R   t   absR   R/   R@   (   R4   RF   t   finite_points(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn     s    !c         C  s  t  | t  s[ | t j k s[ | t j k s[ | t j k s[ | t j k s[ | j t k r_ t	 S|  j
 t j k r |  j t j k r | j d  k	 r | j Sn  |  j r | |  j
 k } n | |  j
 k } |  j r t | | |  j k   } n t | | |  j k  } t |  S(   N(   RL   R   R   R/   R   t   NaNt   ComplexInfinityR   RR   R    R   R   RT   R   R   R   R   (   R4   R5   R0   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa     s     $
		c         C  s   |  j  |  j S(   N(   R   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl     s    i5   c         C  s1   t  t |  j j |   t |  j j |    S(   N(   R&   R'   R   t   _eval_evalfR   (   R4   t   prec(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   to_mpi  s    c         C  s7   t  |  j j |  |  j j |  d |  j d |  j S(   NR   R   (   RO   t   leftR   t   rightR   R   (   R4   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s@   |  j  j } | |  j j M} | | j  j M} | | j j M} | S(   N(   R   R*   R   (   R4   R5   R*   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _is_comparable  s
    c         C  s%   |  j  t j k p$ |  j  t d  k S(   s;   Return ``True`` if the left endpoint is negative infinity. s   -inf(   R   R   R   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_left_unbounded  s    c         C  s%   |  j  t j k p$ |  j  t d  k S(   s<   Return ``True`` if the right endpoint is positive infinity. s   +inf(   R   R   R/   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_right_unbounded  s    c         C  sm   t  |  } |  j r' | |  j k  } n | |  j k } |  j rQ |  j | k  } n |  j | k } t | |  S(   sA   Rewrite an interval in terms of inequalities and logic operators.(   R   R   R   R   R   R   (   R4   RI   R   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   as_relational  s    		c         C  s   t  | t  s9 t  | t  r" t St  | t  r5 d  St St t |  j | j  t |  j	 | j	  |  j
 | j
 k |  j | j k  S(   N(   RL   RO   R@   R    R(   RT   R   R   R   R   R   R   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    (   R   R   R   R`   R   RR   R   R   R   R\   R   t   classmethodR   R   R   R   R]   R   R   R   RX   Rn   Ra   Rl   R   R   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRO     s.   )'

					R3   c           B  s   e  Z d  Z e Z e d    Z e d    Z d   Z e e	 d     Z
 d   Z e d    Z e d    Z d   Z e d	    Z e d
    Z d   Z e d    Z d   Z d   Z RS(   s  
    Represents a union of sets as a :class:`Set`.

    Examples
    ========

    >>> from sympy import Union, Interval
    >>> Union(Interval(1, 2), Interval(3, 4))
    Union(Interval(1, 2), Interval(3, 4))

    The Union constructor will always try to merge overlapping intervals,
    if possible. For example:

    >>> Union(Interval(1, 2), Interval(2, 3))
    Interval(1, 3)

    See Also
    ========

    Intersection

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Union_%28set_theory%29
    c         C  s   t  j S(   N(   R   R:   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   identity  s    c         C  s   t  j S(   N(   R   t   UniversalSet(   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   zero  s    c         O  s   | j  d t d  } t |  } | rG t |  j |   } t |  St t | t j   } t	 j
 |  |  } t |  | _ | S(   NRG   i    (   t   getR   R   R   t   _new_args_filtert   simplify_unionR   R(   R2   R   R   t	   frozensett   _argset(   R   RQ   t   kwargsRG   t   obj(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    
c         C  s   |  j  S(   N(   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRQ     s    c           s   t    f d   |  j D  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   R?   (   RA   RB   (   R>   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    (   R7   RQ   (   R4   R>   (    (   R>   s.   lib/python2.7/site-packages/sympy/sets/sets.pyRX     s    c         C  s3   d d l  m } | g  |  j D] } | j ^ q   S(   Ni(   t   Min(   t(   sympy.functions.elementary.miscellaneousR   RQ   R)   (   R4   R   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR\     s    c         C  s3   d d l  m } | g  |  j D] } | j ^ q   S(   Ni(   t   Max(   R   R   RQ   R^   (   R4   R   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR]     s    c         C  s)   t  g  |  j D] } | j |  ^ q   S(   N(   R   RQ   RH   (   R4   R5   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa   &  s    c   
        s  g    j  D] } t |  | f ^ q
 } d } d } x | r	| | t d   | D  7}   f d   | D } g  | D]' \ } } | j d k rx | | f ^ qx } g  } g  } xB | D]: }	 |	 d | k r q q | j |	 d  | j |	  q W| } | d 9} q7 W| S(   Ni    i   c         s  s   |  ] \ } } | j  Vq d  S(   N(   Rm   (   RA   t   sost   inter(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>;  s    c         3  sP   |  ]F \ } }   j  D]0 } | | k r | t |  | j |  f Vq q d  S(   N(   RQ   R@   R8   (   RA   R   R9   t   newset(   R4   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>?  s   i(   RQ   R@   R   Rm   t   append(
   R4   RB   RN   Rm   t   parityR   R   t   sos_listt	   sets_listRE   (    (   R4   s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl   )  s$    (	
4c           s1     f d   } t  t | t t   j      S(   Nc           sP     j  |  j } x9 t   j   D]( \ } } | |  k r  | | j } q  q  W| S(   s8    The boundary of set i minus interior of all other sets (   RQ   Ro   R   Rs   (   R   R   R   R   (   R4   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   boundary_of_setW  s
    (   R3   R   R   R   RQ   (   R4   R   (    (   R4   s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn   U  s    c         C  s   t  |  j  d k r |  j \ } } | j | j k r | j t j k r | j t j k r t t | | j  | | j k  | | j k  Sn  t	 g  |  j D] } | j
 |  ^ q   S(   s<   Rewrite a Union in terms of equalities and logic operators. i   (   R   RQ   R^   R)   R   R   R/   R   R   R   R   (   R4   t   symbolR   R   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   `  s    $1c         C  s   t  d   |  j D  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   R   (   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>k  s    (   R   RQ   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   i  s    c           sm   y! t    f d   |  j D   SWnE t t t f k
 rh d d  l } t d  d  | j   d f  n Xd  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   R   (   RA   RE   (   R   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>o  s    is   Not all sets are evalf-ablei   (   R3   RQ   R}   R.   R,   t   sysRT   t   exc_info(   R4   R   R   (    (   R   s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   m  s    !	c           s[   d d  l      f d   } t d   |  j D  rK | d   |  j D   St d   d  S(   Nic          7  s   t  |   } t r.   j d   |  D  } n   j d   |  D  } x` | r y x | D] } |   VqZ WWqJ t k
 r | d 8}   j   j | |   } qJ XqJ Wd S(   s,   roundrobin('ABC', 'D', 'EF') --> A D E B F Cc         s  s   |  ] } t  |  j Vq d  S(   N(   t   itert   __next__(   RA   t   it(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    c         s  s   |  ] } t  |  j Vq d  S(   N(   R   t   next(   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    i   N(   R   R   t   cyclet   StopIterationt   islice(   t	   iterablest   pendingt   nextsR   (   t	   itertools(    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt
   roundrobin{  s    	
c         s  s   |  ] } | j  Vq d  S(   N(   R   (   RA   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    c         s  s   |  ] } t  |  Vq d  S(   N(   R   (   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    s%   Not all constituent sets are iterable(   R   R   RQ   R}   (   R4   R   (    (   R   s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   v  s
    (   R   R   R   R`   R   R   R   R   R   R	   RQ   RX   R\   R]   Ra   Rl   Rn   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR3     s"   			,				R7   c           B  s   e  Z d  Z e Z e d    Z e d    Z d   Z e e	 d     Z
 e d    Z e d    Z e d    Z d   Z d	   Z e d
    Z d   Z RS(   s  
    Represents an intersection of sets as a :class:`Set`.

    Examples
    ========

    >>> from sympy import Intersection, Interval
    >>> Intersection(Interval(1, 3), Interval(2, 4))
    Interval(2, 3)

    We often use the .intersect method

    >>> Interval(1,3).intersect(Interval(2,4))
    Interval(2, 3)

    See Also
    ========

    Union

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Intersection_%28set_theory%29
    c         C  s   t  j S(   N(   R   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   t  j S(   N(   R   R:   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         O  s   | j  d t d  } t |  } | rG t |  j |   } t |  St t | t j   } t	 j
 |  |  } t |  | _ | S(   NRG   i    (   R   R   R   R   R   t   simplify_intersectionR   R(   R2   R   R   R   R   (   R   RQ   R   RG   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    
c         C  s   |  j  S(   N(   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRQ     s    c         C  s   t  d   |  j D  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   R   (   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    (   t   anyRQ   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   t     d  S(   N(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR\     s    c         C  s   t     d  S(   N(   R,   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR]     s    c         C  s)   t  g  |  j D] } | j |  ^ q   S(   N(   R   RQ   RH   (   R4   R5   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa     s    c         c  s   t  } x |  j D] } | j r t } t |  j  t | f  } t d t |  } xT | D]I } t | j |   } | t j	 k r | VqZ | t j
 k r qZ | VqZ Wq q W| r t d   n  d  S(   NRG   s)   None of the constituent sets are iterable(   R`   RQ   R   RR   RE   R7   R   RH   R   R   R    R.   (   R4   t   no_iterRB   t
   other_setsR5   RI   t   c(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    	c           s  d d l  m } m   d d l m } t |  d   d t \ } } | sN d  S| j d t  | d } | d } g  } g  } xc | D][  |    f d	   | | D  } | r | j	   q | d  k r | j	   q q W| r t d
 t |  n t j } | r{g  | D]   j t  r ^ q}	 | t d
 t |	  }
 x | r| j   } t d   | |	 d   | D  D  rx |
 D]"   | k r| j   qqWqLg  |	 D]*  t | j    t j k r ^ q} | |	 k rL| j	 | t d
 t |   qLqLWt |   } | s7t j S| t j k rY| t |   7} q{| t t |   | d
 t 7} n  | S(   Ni(   t	   fuzzy_andR   (   t   zip_longestc         S  s   |  j  S(   N(   R   (   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRJ     RK   t   binaryt   keyi    i   c         3  s$   |  ] }   | j     Vq d  S(   N(   RH   (   RA   RC   (   R   RI   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s   RG   c         s  s!   |  ] \ } } | | k Vq d  S(   N(    (   RA   R   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    c         s  s$   |  ] } | j  t  r | Vq d  S(   N(   t   hasR   (   RA   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    (   t   sympy.core.logicR   R   t   sympy.core.compatibilityR   R#   R`   t   sortR   R   RT   R@   RR   R   R:   R   R   t   popR   t   removeR   RH   R   R7   R   (   RQ   R   R   t   fs_argsR5   RB   t   rest   unkR   t   symbolic_s_listt   non_symbolic_st   vt	   containedR   (    (   R   RI   s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _handle_finite_sets  s`    

!(		*		c         C  s)   t  g  |  j D] } | j |  ^ q   S(   sB   Rewrite an Intersection in terms of equalities and logic operators(   R   RQ   R   (   R4   R   RE   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   /  s    (   R   R   R   R`   R   R   R   R   R   R	   RQ   R   R\   R]   Ra   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR7     s   			CR=   c           B  s8   e  Z d  Z e Z e d  Z e d    Z d   Z RS(   s  Represents the set difference or relative complement of a set with
    another set.

    `A - B = \{x \in A| x \\notin B\}`


    Examples
    ========

    >>> from sympy import Complement, FiniteSet
    >>> Complement(FiniteSet(0, 1, 2), FiniteSet(1))
    {0, 2}

    See Also
    =========

    Intersection, Union

    References
    ==========

    .. [1] http://mathworld.wolfram.com/ComplementSet.html
    c         C  s)   | r t  j | |  St j |  | |  S(   N(   R=   t   reduceR   R   (   R   R   R   RG   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   O  s    c           s   | t  j k s   j |  r% t   St | t  rQ t   f d   | j D   S| j    } | d k	 rp | St
   | d t Sd S(   s2   
        Simplify a :class:`Complement`.

        c         3  s   |  ] } | j     Vq d  S(   N(   R?   (   RA   RB   (   t   A(    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>_  s    RG   N(   R   R   Rc   R:   RL   R3   R7   RQ   RX   RT   R=   RR   (   R  t   Bt   result(    (   R  s.   lib/python2.7/site-packages/sympy/sets/sets.pyR  U  s    c         C  s?   |  j  d } |  j  d } t | j |  t | j |    S(   Ni    i   (   RQ   R   RH   R   (   R4   R5   R  R  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa   g  s    (	   R   R   R   R`   R   R   R   R  Ra   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR=   4  s
   R:   c           B  sw   e  Z d  Z e Z e Z e d    Z d   Z d   Z	 d   Z
 d   Z d   Z e d    Z d   Z d	   Z RS(
   s  
    Represents the empty set. The empty set is available as a singleton
    as S.EmptySet.

    Examples
    ========

    >>> from sympy import S, Interval
    >>> S.EmptySet
    EmptySet()

    >>> Interval(1, 2).intersect(S.EmptySet)
    EmptySet()

    See Also
    ========

    UniversalSet

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Empty_set
    c         C  s   d S(   Ni    (    (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl     s    c         C  s   t  S(   N(   R    (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa     s    c         C  s   t  S(   N(   R    (   R4   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   d S(   Ni    (    (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s
   t  g   S(   N(   R   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s
   t  |   S(   N(   R@   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRj     s    c         C  s   |  S(   N(    (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn     s    c         C  s   | S(   N(    (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRX     s    c         C  s   | S(   N(    (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR[     s    (   R   R   R   R`   R   R   R   Rl   Ra   R   R   R   Rj   Rn   RX   R[   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR:   m  s   						R   c           B  sV   e  Z d  Z e Z d   Z d   Z e d    Z d   Z	 d   Z
 e d    Z RS(   s  
    Represents the set of all things.
    The universal set is available as a singleton as S.UniversalSet

    Examples
    ========

    >>> from sympy import S, Interval
    >>> S.UniversalSet
    UniversalSet()

    >>> Interval(1, 2).intersect(S.UniversalSet)
    Interval(1, 2)

    See Also
    ========

    EmptySet

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Universal_set
    c         C  s   t  j S(   N(   R   R:   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRX     s    c         C  s   | S(   N(    (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR[     s    c         C  s   t  j S(   N(   R   R/   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRl     s    c         C  s   t  S(   N(   R   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa     s    c         C  s   t  S(   N(   R   (   R4   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   t    S(   N(   R:   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn     s    (   R   R   R   R`   R   RX   R[   R   Rl   Ra   R   Rn   (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s   				R@   c           B  s   e  Z d  Z e Z e Z d   Z d   Z d   Z d   Z	 d   Z
 e d    Z e d    Z e d    Z e d	    Z d
   Z d   Z d   Z d   Z d   Z e d    Z d   Z d   Z d   Z d   Z d   Z RS(   s  
    Represents a finite set of discrete numbers

    Examples
    ========

    >>> from sympy import FiniteSet
    >>> FiniteSet(1, 2, 3, 4)
    {1, 2, 3, 4}
    >>> 3 in FiniteSet(1, 2, 3, 4)
    True

    >>> members = [1, 2, 3, 4]
    >>> f = FiniteSet(*members)
    >>> f
    {1, 2, 3, 4}
    >>> f - FiniteSet(2)
    {1, 3, 4}
    >>> f + FiniteSet(2, 5)
    {1, 2, 3, 4, 5}

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Finite_set
    c         O  s   | j  d t d  } | rM t t t |   } t |  d k rb t   Sn t t t |   } t t t t	 |   t
 j   } t j |  |  } t |  | _ | S(   NRG   i    (   R   R   R   R   R   R   R:   R   R   t   tupleR(   R2   R   R   t	   _elements(   R   RQ   R   RG   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    
$c         C  sx   t  | t  s9 t  | t  r" t St  | t  r5 d  St St |   t |  k rU t St d   t |  j	 | j	  D   S(   Nc         s  s$   |  ] \ } } t  | |  Vq d  S(   N(   R   (   RA   RI   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    (
   RL   R@   RO   R    R(   RT   R   R   RM   RQ   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s   t  |  j  S(   N(   R   RQ   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  sB  t  | t  rOt d   |  j D  } | t j k r<| g  k r<g  |  j D] } | j rM | ^ qM } g  } | t t j | d t t  g 7} xA t	 | d  | d  D]( \ } } | j
 t | | t t   q W| j
 t | d t j t t   | g  k r)t t d t |  t |   d t St d t |  Sq2| g  k r2d  Sn t  | t  r2g  } xQ |  D]I }	 t | j |	   }
 |
 t j k	 rk|
 t j k	 rk| j
 |	  qkqkWt |   } | |  k rd  Sg  } xB | D]: }	 t |  j |	   }
 |
 t j k	 r| j
 |	  qqWt t |   |  St j |  |  S(   Nc         s  s   |  ] } | j  r | Vq d  S(   N(   R   (   RA   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    i    ii   RG   (   RL   RO   t   sortedRQ   R   RP   t	   is_SymbolR   R`   RM   R   R/   R=   R3   RR   R@   RT   R   RH   R   R    R(   RX   (   R4   R5   R   R   t   symst	   intervalsR   R   R   R   R   t   not_true(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRX     s>    %#$ #c         C  sX   t  } xK |  j D]@ } t | | d t } | t k r; | S| t  k	 r d } q q W| S(   sR  
        Tests whether an element, other, is in the set.

        Relies on Python's set class. This tests for object equality
        All inputs are sympified

        Examples
        ========

        >>> from sympy import FiniteSet
        >>> 1 in FiniteSet(1, 2)
        True
        >>> 5 in FiniteSet(1, 2)
        False

        RG   N(   R    R  R   R`   R   RT   (   R4   R5   t   rt   et   t(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRa   <  s    c         C  s   |  S(   N(    (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRn   X  s    c         C  s   d d l  m } | |    S(   Ni(   R   (   R   R   (   R4   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR\   \  s    c         C  s   d d l  m } | |    S(   Ni(   R   (   R   R   (   R4   R   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR]   a  s    c         C  s   d S(   Ni    (    (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRm   f  s    c         C  s   t  |  j  S(   N(   R   RQ   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   j  s    c         C  s6   d d l  m } t g  |  D] } | | |  ^ q   S(   s@   Rewrite a FiniteSet in terms of equalities and logic operators. i(   R   (   t   sympy.core.relationalR   R   (   R4   R   R   t   elem(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   m  s    c         C  s   t  |   t  |  S(   N(   t   hash(   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   comparer  s    c         C  s&   t  g  |  D] } | j |  ^ q
   S(   N(   R@   R   (   R4   R   R  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   u  s    c         C  s
   |  j  f S(   N(   R  (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _hashable_contentx  s    c         C  s   t  t |  j t j   S(   N(   R  R   RQ   R(   R2   (   R4   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   _sorted_args{  s    c         C  s2   |  j  g  t |  j  D] } |  j  |   ^ q   S(   N(   Ri   R"   RQ   (   R4   RB   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRj     s    c         C  s5   t  | t  s( t d t |    n  | j |   S(   Ns!   Invalid comparison of set with %s(   RL   R(   R}   R$   Rc   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __ge__  s    c         C  s5   t  | t  s( t d t |    n  |  j |  S(   Ns!   Invalid comparison of set with %s(   RL   R(   R}   R$   Rh   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __gt__  s    c         C  s5   t  | t  s( t d t |    n  |  j |  S(   Ns!   Invalid comparison of set with %s(   RL   R(   R}   R$   Rc   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __le__  s    c         C  s5   t  | t  s( t d t |    n  |  j |  S(   Ns!   Invalid comparison of set with %s(   RL   R(   R}   R$   Re   (   R4   R5   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   __lt__  s    (   R   R   R   R`   R   R   R   R   R   RX   Ra   R   Rn   R\   R]   Rm   R   R   R  R   R  R  Rj   R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR@     s.   				'										c         C  s
   t  |    S(   N(   R@   (   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRJ     RK   c         C  s
   t  |    S(   N(   R@   (   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRJ     RK   RY   c           B  s/   e  Z d  Z e Z e d  Z e d    Z RS(   s  Represents the set of elements which are in either of the
    sets and not in their intersection.

    Examples
    ========

    >>> from sympy import SymmetricDifference, FiniteSet
    >>> SymmetricDifference(FiniteSet(1, 2, 3), FiniteSet(3, 4, 5))
    {1, 2, 4, 5}

    See Also
    ========

    Complement, Union

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Symmetric_difference
    c         C  s)   | r t  j | |  St j |  | |  S(   N(   RY   R  R   R   (   R   R   R   RG   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    c         C  s6   | j  |   } | d  k	 r | St |  | d t Sd  S(   NRG   (   R[   RT   RY   RR   (   R  R  R  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR    s    (   R   R   R   R`   t   is_SymmetricDifferenceR   R   R  (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRY     s   c          G  s  d d l  m } d d l m } d d l m } t |   d k  r[ t d t |     n  t |  d t	 t
 f  r t |   d k r | |  d |  d  } |  d } n |  d } |  d } t | |  r n t | t  s t |  d	 k rt |  d k r0t t	 d
  | t     } | |  } n? g  t t |   D] } t	 d | d  ^ qC} | |   } | | |  } n t t d t |     t d   | D  rg  | D] }	 t |	  ^ q}
 t d |
   n  t |  d k r| d } | | |  } | d k r.| | |  } n  t | |  rO| j \ } } n  | j d | j k ri| St | |  rt | j j  d k rt | j  d k rt | | j j d | j j | j d | j j   | j  Sn  | d k	 r| Sn  | | |  S(   s{  
    Return an image of the set under transformation ``f``.

    If this function can't compute the image, it returns an
    unevaluated ImageSet object.

    .. math::
        { f(x) | x \in self }

    Examples
    ========

    >>> from sympy import S, Interval, Symbol, imageset, sin, Lambda
    >>> from sympy.abc import x, y

    >>> imageset(x, 2*x, Interval(0, 2))
    Interval(0, 4)

    >>> imageset(lambda x: 2*x, Interval(0, 2))
    Interval(0, 4)

    >>> imageset(Lambda(x, sin(x)), Interval(-2, 1))
    ImageSet(Lambda(x, sin(x)), Interval(-2, 1))

    >>> imageset(sin, Interval(-2, 1))
    ImageSet(Lambda(x, sin(x)), Interval(-2, 1))
    >>> imageset(lambda y: x + y, Interval(-2, 1))
    ImageSet(Lambda(_x, _x + x), Interval(-2, 1))

    Expressions applied to the set of Integers are simplified
    to show as few negatives as possible and linear expressions
    are converted to a canonical form. If this is not desirable
    then the unevaluated ImageSet should be used.

    >>> imageset(x, -2*x + 5, S.Integers)
    ImageSet(Lambda(x, 2*x + 1), Integers)

    See Also
    ========

    sympy.sets.fancysets.ImageSet

    i(   t   Lambda(   t   ImageSet(   t   set_functioni   s)   imageset expects at least 2 args, got: %si    i   s   <lambda>RI   s   x%is>   
        expecting lambda, Lambda, or FunctionClass, not '%s'.c         s  s   |  ] } t  | t  Vq d  S(   N(   RL   R(   (   RA   RB   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    s.   arguments after mapping should be sets, not %sN(   t
   sympy.coreR  t   sympy.sets.fancysetsR  t   sympy.sets.setexprR  R   R.   RL   R   R  R   R$   R   R   R   R}   R%   R   RT   RQ   t	   variablesR0   t   lamdat   imagesett   subst   base_set(   RQ   R  R  R  t   ft   set_listt   varR0   R   RB   t   nameRE   R  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR"    sX    ,+

3
-"c         C  sy   d d l  m } m } |  | | f k r, t St d  } |  |  j |  } | d k t k sq | d k  t k ru t Sd S(   sk   
    Checks whether function ``func`` is invertible when the domain is
    restricted to set ``setv``.
    i(   Rz   t   logt   ui    N(   t   sympyRz   R)  R`   R   t   diffRT   (   Ri   t   setvRz   R)  R*  t   fdiff(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   is_function_invertible_in_set+  s    $c         C  s  d d l  m } |  s t j Sx, |  D]$ } t | t  s$ t d   q$ q$ Wg  |  D] } | j rS | ^ qS } t |  d k r d   | D } t	 |   } | g g  |  D] } | j s | ^ q }  n  t
 |   }  t } x | rx |  D] } t } xz |  t
 | f  D]e }	 | | |	  }
 |
 d k	 r
t |
 t
  sLt
 |
 f  }
 n  |  t
 | |	 f  j |
  } Pq
q
W| r | }  Pq q Wq Wt |   d k r|  j   St d t |   Sd S(   s8  
    Simplify a :class:`Union` using known rules

    We first start with global rules like 'Merge all FiniteSets'

    Then we iterate through all pairs and ask the constituent sets if they
    can simplify themselves with any other constituent.  This process depends
    on ``union_sets(a, b)`` functions.
    i(   t
   union_setss    Input args to Union must be Setsi   c         s  s"   |  ] } | D] } | Vq q d  S(   N(    (   RA   RE   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>U  s    RG   N(   t   sympy.sets.handlers.unionR0  R   R:   RL   R(   R}   R   R   R@   RE   R`   RR   RT   R6   R   R3   (   RQ   R0  R   RI   t   finite_setsR   t
   finite_sett   new_argsRB   R  t   new_set(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   >  s:    
",	
c   	        sI  |  s t  j Sx, |  D]$ } t | t  s t d   q q Wt d   |  D  rY t  j St j |   } | d	 k	 rx | Sx |  D] } | j
 r t |   t | f  } t |  d k r t |     t   f d   | j D   St g  | j D] } | ^ q   Sq q WxR |  D]J } | j r|  j |  |  | j d g } t t |   | j d  SqWd d l m } t |   }  t } x | rx |  D] } t } xb |  t | f  D]M } | | |  } | d	 k	 r|  t | | f  j t | f   } PqqW| r| }  PqqWqWt |   d k r5|  j   St d t |   Sd	 S(
   s'  
    Simplify an intersection using known rules

    We first start with global rules like
    'if any empty sets return empty set' and 'distribute any unions'

    Then we iterate through all pairs and ask the constituent sets if they
    can simplify themselves with any other constituent
    s    Input args to Union must be Setsc         s  s   |  ] } | j  Vq d  S(   N(   R   (   RA   RB   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    i    c         3  s   |  ] } t  |    Vq d  S(   N(   R7   (   RA   R   (   R5   (    s.   lib/python2.7/site-packages/sympy/sets/sets.pys	   <genexpr>  s    i   i(   t   intersection_setsRG   N(   R   R   RL   R(   R}   R   R:   R7   R   RT   R   RE   R   R3   RQ   R   R   R=   t    sympy.sets.handlers.intersectionR6  R`   RR   R6   R   (	   RQ   R   t   rvRB   R   R6  R4  R  R5  (    (   R5   s.   lib/python2.7/site-packages/sympy/sets/sets.pyR   s  sN    	'		(
c   	      C  s   t  | | g d   d t \ } } t |  d k rq t g  | d D]& } | d D] } |  | |  ^ qR qD   St |  d k r g  | d D] } t |  | d | |  ^ q } t |   Sd  Sd  S(   Nc         S  s   t  |  t  S(   N(   RL   R@   (   RI   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyRJ     RK   R   i   i    i   (   R#   R`   R   R@   t   _apply_operationR3   RT   (	   t   opRI   R   t   commutativeR   R5   R   R   RN   (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR     s    $;0
c         C  sj  d d l  m } d d l m } m } t d  } t |  | | |  } | d  k re |  | |  } n  | d  k r | r |  | |  } n  | d  k rf| d  \ }	 }
 t | t	  r t | t	  r | | | |  | |   |  j
   } qft | t	  r9t | t	  r9| | | |  | |   |  j
   } qf| | |	 |
 f |  |	 |
   | |  } n  | S(   Ni(   R  (   t   symbolsR  t   ds   x y(   t
   sympy.setsR  R+  R<  R  R   R   RT   RL   R(   t   doit(   R:  RI   R   R;  R  R<  R  R=  t   outt   _xt   _y(    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR9    s     **-c         C  s&   d d l  m } t | |  | d t S(   Ni(   t   _set_addR;  (   t   sympy.sets.handlers.addRC  R9  R`   (   RI   R   RC  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   set_add  s    c         C  s&   d d l  m } t | |  | d t S(   Ni(   t   _set_subR;  (   RD  RF  R9  RR   (   RI   R   RF  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   set_sub  s    c         C  s&   d d l  m } t | |  | d t S(   Ni(   t   _set_mulR;  (   t   sympy.sets.handlers.mulRH  R9  R`   (   RI   R   RH  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   set_mul  s    c         C  s&   d d l  m } t | |  | d t S(   Ni(   t   _set_divR;  (   RI  RK  R9  RR   (   RI   R   RK  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   set_div  s    c         C  s&   d d l  m } t | |  | d t S(   Ni(   t   _set_powR;  (   t   sympy.sets.handlers.powerRM  R9  RR   (   RI   R   RM  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   set_pow  s    c         C  s   d d l  m } | |  |  S(   Ni(   t   _set_function(   t   sympy.sets.handlers.functionsRP  (   R%  RI   RP  (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyR    s    N(W   t
   __future__R    R   R   R   t   sympy.core.basicR   R   R   R   R   R   R   t   sympy.core.cacheR	   t   sympy.core.evalfR
   t   sympy.core.evaluateR   t   sympy.core.exprR   t   sympy.core.functionR   R   R   t   sympy.core.mulR   t   sympy.core.numbersR   t   sympy.core.operationsR   R  R   R   t   sympy.core.singletonR   R   t   sympy.core.symbolR   R   R   t   sympy.core.sympifyR   R   R   t   sympy.logic.boolalgR   R   R   R   R    t   sympy.sets.containsR!   t   sympy.utilitiesR"   RS   R#   t   sympy.utilities.miscR$   R%   t   mpmathR&   R'   R(   RD   RO   R3   R7   R=   R:   R   R@   RE   R   RY   R"  R/  R   R   R   R9  RE  RG  RJ  RL  RO  R  (    (    (    s.   lib/python2.7/site-packages/sympy/sets/sets.pyt   <module>   sb   ((   9:1'	i		5	L							