
\c           @  s  d  d l  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 m 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 m Z m Z m Z d  d l m  Z  d e e e  f d     YZ! d e! f d     YZ" d e e e  f d     YZ# d e e e  f d     YZ$ d e f d     YZ% d e f d     YZ& e	 re& e e <n
 e& e e' <d   Z( d e f d     YZ) d e e e)  f d     YZ* d S(   i(   t   print_functiont   division(   t   Basic(   t   as_intt   with_metaclasst   ranget   PY3(   t   Expr(   t   Lambda(   t	   Singletont   S(   t   Dummyt   symbols(   t   _sympifyt   sympifyt	   converter(   t   And(   t   Sett   Intervalt   Uniont	   FiniteSet(   t
   filldedentt   Naturalsc           B  sG   e  Z d  Z e Z e j Z e j Z	 d   Z
 d   Z e d    Z RS(   sh  
    Represents the natural numbers (or counting numbers) which are all
    positive integers starting from 1. This set is also available as
    the Singleton, S.Naturals.

    Examples
    ========

    >>> from sympy import S, Interval, pprint
    >>> 5 in S.Naturals
    True
    >>> iterable = iter(S.Naturals)
    >>> next(iterable)
    1
    >>> next(iterable)
    2
    >>> next(iterable)
    3
    >>> pprint(S.Naturals.intersect(Interval(0, 10)))
    {1, 2, ..., 10}

    See Also
    ========

    Naturals0 : non-negative integers (i.e. includes 0, too)
    Integers : also includes negative integers
    c         C  sX   t  | t  s t j S| j r/ | j r/ t j S| j t k sM | j t k rT t j Sd  S(   N(   t
   isinstanceR   R
   t   falset   is_positivet
   is_integert   truet   False(   t   selft   other(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt	   _contains0   s    c         c  s)   |  j  } x t r$ | V| d } q Wd  S(   Ni   (   t   _inft   True(   R   t   i(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __iter__8   s    		c         C  s   |  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt	   _boundary>   s    (   t   __name__t
   __module__t   __doc__R!   t   is_iterableR
   t   OneR    t   Infinityt   _supR   R#   t   propertyR$   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR      s   				t	   Naturals0c           B  s    e  Z d  Z e j Z d   Z RS(   s   Represents the whole numbers which are all the non-negative integers,
    inclusive of zero.

    See Also
    ========

    Naturals : positive integers; does not include 0
    Integers : also includes the negative integers
    c         C  sX   t  | t  s t j S| j r/ | j r/ t j S| j t k sM | j t k rT t j Sd  S(   N(   R   R   R
   R   R   t   is_nonnegativeR   R   (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR   O   s    (   R%   R&   R'   R
   t   ZeroR    R   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR-   C   s   		t   Integersc           B  sS   e  Z d  Z e Z d   Z d   Z e d    Z e d    Z	 e d    Z
 RS(   sE  
    Represents all integers: positive, negative and zero. This set is also
    available as the Singleton, S.Integers.

    Examples
    ========

    >>> from sympy import S, Interval, pprint
    >>> 5 in S.Naturals
    True
    >>> iterable = iter(S.Integers)
    >>> next(iterable)
    0
    >>> next(iterable)
    1
    >>> next(iterable)
    -1
    >>> next(iterable)
    2

    >>> pprint(S.Integers.intersect(Interval(-4, 4)))
    {-4, -3, ..., 4}

    See Also
    ========

    Naturals0 : non-negative integers
    Integers : positive and negative integers and zero
    c         C  s@   t  | t  s t j S| j r& t j S| j t k r< t j Sd  S(   N(   R   R   R
   R   R   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR   y   s    	c         c  s7   t  j Vt  j } x t r2 | V| V| d } q Wd  S(   Ni   (   R
   R/   R)   R!   (   R   R"   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR#      s    		c         C  s   t  j S(   N(   R
   R*   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR       s    c         C  s   t  j S(   N(   R
   R*   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR+      s    c         C  s   |  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR$      s    (   R%   R&   R'   R!   R(   R   R#   R,   R    R+   R$   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR0   X   s   		t   Realsc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s   t  j |  t j t j  S(   N(   R   t   __new__R
   R*   (   t   cls(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR2      s    c         C  s   | t  t j t j  k S(   N(   R   R
   R*   (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __eq__   s    c         C  s   t  t t j t j   S(   N(   t   hashR   R
   R*   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __hash__   s    (   R%   R&   R2   R4   R6   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR1      s   		t   ImageSetc           B  sh   e  Z d  Z d   Z e d    Z e d    Z d   Z d   Z d   Z	 e d    Z
 d   Z RS(	   s  
    Image of a set under a mathematical function. The transformation
    must be given as a Lambda function which has as many arguments
    as the elements of the set upon which it operates, e.g. 1 argument
    when acting on the set of integers or 2 arguments when acting on
    a complex region.

    This function is not normally called directly, but is called
    from `imageset`.


    Examples
    ========

    >>> from sympy import Symbol, S, pi, Dummy, Lambda
    >>> from sympy.sets.sets import FiniteSet, Interval
    >>> from sympy.sets.fancysets import ImageSet

    >>> x = Symbol('x')
    >>> N = S.Naturals
    >>> squares = ImageSet(Lambda(x, x**2), N) # {x**2 for x in N}
    >>> 4 in squares
    True
    >>> 5 in squares
    False

    >>> FiniteSet(0, 1, 2, 3, 4, 5, 6, 7, 9, 10).intersect(squares)
    {1, 4, 9}

    >>> square_iterable = iter(squares)
    >>> for i in range(4):
    ...     next(square_iterable)
    1
    4
    9
    16

    If you want to get value for `x` = 2, 1/2 etc. (Please check whether the
    `x` value is in `base_set` or not before passing it as args)

    >>> squares.lamda(2)
    4
    >>> squares.lamda(S(1)/2)
    1/4

    >>> n = Dummy('n')
    >>> solutions = ImageSet(Lambda(n, n*pi), S.Integers) # solutions of sin(x) = 0
    >>> dom = Interval(-1, 1)
    >>> dom.intersect(solutions)
    {0}

    See Also
    ========

    sympy.sets.sets.imageset
    c         G  s   t  | t  s t d   n  | t j k rG t |  d k rG | d S| j j sa | j j rn t	 | j  St
 j |  | |  S(   Ns   first argument must be a Lambdai   i    (   R   R   t
   ValueErrorR
   t   IdentityFunctiont   lent   exprt   free_symbolst   argsR   R   R2   (   R3   t   flambdat   sets(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR2      s    !c         C  s   |  j  d S(   Ni    (   R=   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   <lambda>   t    c         C  s   |  j  d S(   Ni   (   R=   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR@      RA   c         c  sT   t    } xD |  j D]9 } |  j |  } | | k r: q q | j |  | Vq Wd  S(   N(   t   sett   base_sett   lamdat   add(   R   t   already_seenR"   t   val(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR#      s    	c         C  s   t  |  j j  d k S(   Ni   (   R:   RD   t	   variables(   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   _is_multivariate   s    c         C  st  d d l  m } d d l m } m } d d l m } m } m } |  j	 } | |  r | | j
  sm t j St | j
  t |  k r t t d    q n! | |  r t t d    n  d  }	 |  j   r| | j
  s| j   |  j t | j | j
 j    |  j  k Sg  t | | j
  D] \ }
 } | |
 ^ q)} | j } t |  } t d   t | |  j |   D  rt | g  t | j
 |  D] \ } }
 | |
 ^ q|   }	 qg  | D] } | j | @^ q} i  }	 x t t | | |   D] \ } \ } } } | sJ| | k r3t j S| g |	 t | <qqt |  d k r| j   } | | |  } | t j  k rt j St! | t"  rt |  |	 | <qt#  qt#  qW| g  | D] } |	 | ^ q  }	 n| j d	 } t! | j
 t$  r>| | j
 | |  } | j% r5t |  }	 q| } n x t | j
 |  D] \ } } | | | |  }	 |	 t j  k rt j Sx\ |	 D]M } y | |  j k rPn  Wqt& k
 r|  j j' | j(    rPqqXqWt j SqQWt j) S|	 d  k rt# t d
 | | f    n  xO |	 D]G } y | |  j k rAt j) SWq"t& k
 rh|  j j' | j(    SXq"Wt j S(   Ni(   t   Matrix(   t   solvesett   linsolve(   t   is_sequencet   iterablet   cartess<   
    Dimensions of other and output of Lambda are different.s6   
    `other` should be an ordered object like a Tuple.c         s  s   |  ] } | j  Vq d  S(   N(   t	   is_number(   t   .0R"   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pys	   <genexpr>  s    i   i    sU   
            Determining whether %s contains %s has not
            been implemented.(*   t   sympy.matricesRJ   t   sympy.solvers.solvesetRK   RL   t   sympy.utilities.iterablesRM   RN   RO   RD   R;   R
   R   R:   R8   R   t   NoneRI   t   as_numer_denomt   funcR   RH   RC   t   zipRB   t   allt   listt   jacobianR<   t	   enumeratet   varst   popt   EmptySetR   R   t   NotImplementedErrorR   t   is_FiniteSett	   TypeErrort   containst   evalfR   (   R   R   RJ   RK   RL   RM   RN   RO   t   Lt   solnsRG   R;   t   eqsRH   t   freet   et   symsR"   t   st   vt   syt   solt   xt   solnsSett   msgsett   ot   soln(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR      s    	%/	+	8 .	
&		c         C  s
   |  j  j S(   N(   RC   R(   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR(   M  s    c         K  s8   d d l  m } |  j } |  j } | |  j |  j S(   Ni(   t   SetExpr(   t   sympy.sets.setexprRt   RD   RC   t
   _eval_funcRB   (   R   t   kwargsRt   t   fRC   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   doitQ  s    		(   R%   R&   R'   R2   R,   RD   RC   R#   RI   R   R(   Ry   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR7      s   8	
	
		Xt   Rangec           B  s   e  Z d  Z e Z d   Z e d    Z e d    Z e d    Z	 e d    Z
 d   Z d   Z d   Z e d	    Z d
   Z e Z d   Z e d    Z e d    Z e d    Z RS(   s9  
    Represents a range of integers. Can be called as Range(stop),
    Range(start, stop), or Range(start, stop, step); when stop is
    not given it defaults to 1.

    `Range(stop)` is the same as `Range(0, stop, 1)` and the stop value
    (juse as for Python ranges) is not included in the Range values.

        >>> from sympy import Range
        >>> list(Range(3))
        [0, 1, 2]

    The step can also be negative:

        >>> list(Range(10, 0, -2))
        [10, 8, 6, 4, 2]

    The stop value is made canonical so equivalent ranges always
    have the same args:

        >>> Range(0, 10, 3)
        Range(0, 12, 3)

    Infinite ranges are allowed. ``oo`` and ``-oo`` are never included in the
    set (``Range`` is always a subset of ``Integers``). If the starting point
    is infinite, then the final value is ``stop - step``. To iterate such a
    range, it needs to be reversed:

        >>> from sympy import oo
        >>> r = Range(-oo, 1)
        >>> r[-1]
        0
        >>> next(iter(r))
        Traceback (most recent call last):
        ...
        ValueError: Cannot iterate over Range with infinite start
        >>> next(iter(r.reversed))
        0

    Although Range is a set (and supports the normal set
    operations) it maintains the order of the elements and can
    be used in contexts where `range` would be used.

        >>> from sympy import Interval
        >>> Range(0, 10, 2).intersect(Interval(3, 7))
        Range(4, 8, 2)
        >>> list(_)
        [4, 6]

    Although slicing of a Range will always return a Range -- possibly
    empty -- an empty set will be returned from any intersection that
    is empty:

        >>> Range(3)[:0]
        Range(0, 0, 1)
        >>> Range(3).intersect(Interval(4, oo))
        EmptySet()
        >>> Range(3).intersect(Range(4, oo))
        EmptySet()

    c         G  s  d d l  m } t |  d k r[ t | d t r8 t n t  r[ | d j   d } q[ n  t |   } | j	 d k r t
 d   n  | j p d | j | j	 p d } } } yY g  | | | f D]6 } | t j t j g k r | n t t |   ^ q \ } } } Wn# t
 k
 r,t
 t d    n X| j sKt
 t d    n  t d   | | f D  r| | k rt j } } qt
 t d	    n  | j r| } nV | j r| n | }	 | | |	 |  }
 |
 d k rd } } d } n |	 |
 | } t j |  | | |  S(
   Ni(   t   ceilingi   i    s   step cannot be 0s   
    Finite arguments to Range must be integers; `imageset` can define
    other cases, e.g. use `imageset(i, i/10, Range(3))` to give
    [0, 1/10, 1/5].s-   
    Ranges must have a literal integer step.c         s  s   |  ] } | j  Vq d  S(   N(   t   is_infinite(   RQ   R"   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pys	   <genexpr>  s    s?   
    Either the start or end value of the Range must be finite.(   t#   sympy.functions.elementary.integersR{   R:   R   R   R   t   xranget
   __reduce__t   slicet   stepR8   t   startt   stopR
   t   NegativeInfinityR*   R   R   R   t
   is_IntegerRY   R)   R|   t	   is_finiteR   R2   (   R3   R=   R{   t   slcR   R   R   t   wt   endt   reft   n(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR2     s>    )V			
	c         C  s   |  j  d S(   Ni    (   R=   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR@     RA   c         C  s   |  j  d S(   Ni   (   R=   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR@     RA   c         C  s   |  j  d S(   Ni   (   R=   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR@     RA   c         C  s5   |  s
 |  S|  j  |  j |  j |  j |  j |  j  S(   s   Return an equivalent Range in the opposite order.

        Examples
        ========

        >>> from sympy import Range
        >>> Range(10).reversed
        Range(9, -1, -1)
        (   RW   R   R   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   reversed  s    c         C  s   |  s t  j S| j r t  j S| j s- | j S|  j j rB |  j n |  j } | | |  j rc t  j St | |  j	 k o | |  j
 k  S(   N(   R
   R   R|   R   R   R   R   R   R   t   inft   sup(   R   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s    		c         c  s   |  j  t j t j g k r* t d   n |  r |  j  } |  j } x~ t r | d k rz |  j  | k ot |  j k  n s | d k  r |  j | k  o |  j  k n r Pn  | V| | 7} qE Wn  d  S(   Ns-   Cannot iterate over Range with infinite starti    (   R   R
   R   R*   R8   R   R!   R   (   R   R"   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR#     s    			//c         C  sC   |  s
 d S|  j  |  j } | j r2 t d   n  t | |  j  S(   Ni    s0   Use .size to get the length of an infinite Range(   R   R   R|   R8   t   absR   (   R   t   dif(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __len__  s    	c         C  s0   y t  t |    SWn t k
 r+ t j SXd  S(   N(   R   R:   R8   R
   R*   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   size  s    c         C  s   |  j  |  j k S(   N(   R   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __nonzero__  s    c         C  s  d d l  m } d } d } d d } t | t  r!|  j j r | j |  j  \ } } } | | | |  }	 |	 d k r t d  S| |	 | }
 |
 | } | |  j } t |  | |  | | |  S| j	 } | j
 } | j d k r t |   n  | j pd } | |  j } |  j
 j r`|  j | d  k r7| n | d | d  k rQ| n | |  j S| d  k r}| d  k r| d k  rt |  d |  j	 |  S| d k rt |   qz|  Sq| d k  r| d k  rt |  d |  | |  St |  j	 |  | |  Sq| d k r8| d k r)t d  St |   q| d k rn| d k r_t |   qzt |   qt |   q| d k  rH| d  k r| d k  rt |  | |  j	 |  St |  | |  j
 |  Sq| d k  rt |  | |  | |  S| d k r*| d k  rt |   qEt d  Sq| d k rt |   qq| d k r| d  k r| d k  r{t |   q | d k rt |   q |  Sq| d k  r| d k rt |   q | d k rt |  j	 |  | |  St d  Sqt |   q| d k rt |   qn |  s6t d	   n  | d k rI|  j	 S| d k sd| t j k rr|  j
 |  j S| d k  r|  j
 n |  j	 | |  j } | j rt |   n  | |  j k  s| |  j k rt d	   n  | Sd  S(
   Ni(   R{   s0   cannot slice from the end with an infinite values   slice step cannot be zeros,   cannot unambiguously re-stride from the end s   with an infinite valuei    i   s   Range index out of range(   R}   R{   R   R   R   R   t   indicesRz   R   R   R   R8   R|   R   RU   t
   IndexErrorR
   R*   R   R   (   R   R"   R{   t   ooslicet   zerostept	   ambiguousR   R   R   R   t   canonical_stopR   t   sst   rv(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __getitem__  s    

		
)	c         C  s7   |  s t   n  |  j d k r% |  j S|  j |  j Sd  S(   Ni    (   R`   R   R   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR      s
    	c         C  s7   |  s t   n  |  j d k r, |  j |  j S|  j Sd  S(   Ni    (   R`   R   R   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR+     s
    	c         C  s   |  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR$     s    (   R%   R&   R'   R!   R(   R2   R,   R   R   R   R   R   R#   R   R   R   t   __bool__R   R    R+   R$   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyRz   X  s"   =	1						v		c         C  sY  d d l  m } |  j r|  j } | d t j k r | d t j k r |  j r |  j r | |  j  } t	 t
 d | t j t t  t
 | t j d t j t t   St
 d d t j t t  S| |  j  | |  j  } } | d	 k s | d	 k r	t d   n  | t j } | t j } | | k rjt	 t
 t j | t |  j  t
 | d t j |  j t   St
 | | |  j |  j  Sn |  j rg  } xI |  D]A }	 | |	  } | d	 k rt d   q| j | t j  qWt |   S|  j rt	 g  |  j D] }
 t |
  ^ q  S|  j t j  rEt d t |     n t d |    d	 S(
   s  
    Normalize a Real Set `theta` in the Interval [0, 2*pi). It returns
    a normalized value of theta in the Set. For Interval, a maximum of
    one cycle [0, 2*pi], is returned i.e. for theta equal to [0, 10*pi],
    returned normalized value would be [0, 2*pi). As of now intervals
    with end points as non-multiples of `pi` is not supported.

    Raises
    ======

    NotImplementedError
        The algorithms for Normalizing theta Set are not yet
        implemented.
    ValueError
        The input is not valid, i.e. the input is not a real set.
    RuntimeError
        It is a bug, please report to the github issue tracker.

    Examples
    ========

    >>> from sympy.sets.fancysets import normalize_theta_set
    >>> from sympy import Interval, FiniteSet, pi
    >>> normalize_theta_set(Interval(9*pi/2, 5*pi))
    Interval(pi/2, pi)
    >>> normalize_theta_set(Interval(-3*pi/2, pi/2))
    Interval.Ropen(0, 2*pi)
    >>> normalize_theta_set(Interval(-pi/2, pi/2))
    Union(Interval(0, pi/2), Interval.Ropen(3*pi/2, 2*pi))
    >>> normalize_theta_set(Interval(-4*pi, 3*pi))
    Interval.Ropen(0, 2*pi)
    >>> normalize_theta_set(Interval(-3*pi/2, -pi/2))
    Interval(pi/2, 3*pi/2)
    >>> normalize_theta_set(FiniteSet(0, pi, 3*pi))
    {0, pi}

    i(   t	   _pi_coeffi   i    sB   Normalizing theta without pi as coefficient is not yet implementeds@   Normalizing theta without pi as coefficient, is not Implemented.s;   Normalizing theta when, it is of type %s is not implementeds    %s is not a real setN(   t(   sympy.functions.elementary.trigonometricR   t   is_Intervalt   measureR
   t   Pit	   left_opent
   right_openR   R   R   R   R!   R   RU   R`   R/   Ra   t   appendR   t   is_UnionR=   t   normalize_theta_sett	   is_subsetR1   t   typeR8   (   t   thetat   coefft   interval_lent   kt   k_startt   k_endt	   new_startt   new_endt	   new_thetat   elementt   interval(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s@    &		%$ 	
	&t   ComplexRegionc           B  s   e  Z d  Z e Z e d  Z e d    Z e d    Z	 e d    Z
 e d    Z e d    Z e d    Z e d    Z e d	    Z e d
    Z e d    Z d   Z RS(   s	  
    Represents the Set of all Complex Numbers. It can represent a
    region of Complex Plane in both the standard forms Polar and
    Rectangular coordinates.

    * Polar Form
      Input is in the form of the ProductSet or Union of ProductSets
      of the intervals of r and theta, & use the flag polar=True.

    Z = {z in C | z = r*[cos(theta) + I*sin(theta)], r in [r], theta in [theta]}

    * Rectangular Form
      Input is in the form of the ProductSet or Union of ProductSets
      of interval of x and y the of the Complex numbers in a Plane.
      Default input type is in rectangular form.

    Z = {z in C | z = x + I*y, x in [Re(z)], y in [Im(z)]}

    Examples
    ========

    >>> from sympy.sets.fancysets import ComplexRegion
    >>> from sympy.sets import Interval
    >>> from sympy import S, I, Union
    >>> a = Interval(2, 3)
    >>> b = Interval(4, 6)
    >>> c = Interval(1, 8)
    >>> c1 = ComplexRegion(a*b)  # Rectangular Form
    >>> c1
    ComplexRegion(Interval(2, 3) x Interval(4, 6), False)

    * c1 represents the rectangular region in complex plane
      surrounded by the coordinates (2, 4), (3, 4), (3, 6) and
      (2, 6), of the four vertices.

    >>> c2 = ComplexRegion(Union(a*b, b*c))
    >>> c2
    ComplexRegion(Union(Interval(2, 3) x Interval(4, 6), Interval(4, 6) x Interval(1, 8)), False)

    * c2 represents the Union of two rectangular regions in complex
      plane. One of them surrounded by the coordinates of c1 and
      other surrounded by the coordinates (4, 1), (6, 1), (6, 8) and
      (4, 8).

    >>> 2.5 + 4.5*I in c1
    True
    >>> 2.5 + 6.5*I in c1
    False

    >>> r = Interval(0, 1)
    >>> theta = Interval(0, 2*S.Pi)
    >>> c2 = ComplexRegion(r*theta, polar=True)  # Polar Form
    >>> c2  # unit Disk
    ComplexRegion(Interval(0, 1) x Interval.Ropen(0, 2*pi), True)

    * c2 represents the region in complex plane inside the
      Unit Disk centered at the origin.

    >>> 0.5 + 0.5*I in c2
    True
    >>> 1 + 2*I in c2
    False

    >>> unit_disk = ComplexRegion(Interval(0, 1)*Interval(0, 2*S.Pi), polar=True)
    >>> upper_half_unit_disk = ComplexRegion(Interval(0, 1)*Interval(0, S.Pi), polar=True)
    >>> intersection = unit_disk.intersect(upper_half_unit_disk)
    >>> intersection
    ComplexRegion(Interval(0, 1) x Interval(0, pi), True)
    >>> intersection == upper_half_unit_disk
    True

    See Also
    ========

    Reals

    c      	   C  si  d d l  m } m } t d d t \ } } } } t j }	 t |  } | t k r,t	 d   | j
 D  r t | j
  d k r g  }
 xB | j
 d D]3 } x* | j
 d D] } |
 j | |	 |  q Wq Wt |
   } n, t j |  t | | f | |	 |  |  } | | f | _ | |	 | | _ n'| t k rGg  } | j skx. | j
 D] } | j |  qQWn | j |  xQ t |  D]C \ } } d d	 l m } | | j
 d t | j
 d   | | <qWt |   } t j |  t | | f | | |  |	 | |   |  } | | f | _ | | |  |	 | |  | _ n t d
   | | _ | | _ | S(   Ni(   t   sint   coss   x, y, r, thetaR3   c         s  s   |  ] } | j  Vq d  S(   N(   Ra   (   RQ   t   _a(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pys	   <genexpr>M  s    i   i    i   (   t
   ProductSets$   polar should be either True or False(   t   sympyR   R   R   R   R
   t   ImaginaryUnitR   R   RY   R=   R:   R   R   R7   R2   R   t
   _variablest   _exprR!   t   is_ProductSetR\   t
   sympy.setsR   R   R   R8   t   _setst   _polar(   R3   R?   t   polarR   R   Ro   t   yt   rR   t   It   complex_numt   objt   new_setsR   Rl   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR2   D  sD    	.,		$		c         C  s   |  j  S(   s  
        Return raw input sets to the self.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, Union
        >>> a = Interval(2, 3)
        >>> b = Interval(4, 5)
        >>> c = Interval(1, 7)
        >>> C1 = ComplexRegion(a*b)
        >>> C1.sets
        Interval(2, 3) x Interval(4, 5)
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.sets
        Union(Interval(2, 3) x Interval(4, 5), Interval(4, 5) x Interval(1, 7))

        (   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR?   y  s    c         C  s   |  j  |  j f S(   N(   R   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR=     s    c         C  s   |  j  S(   N(   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyRH     s    c         C  s   |  j  S(   N(   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR;     s    c         C  s5   |  j  j r% d } | |  j  f } n |  j  j } | S(   s  
        Return a tuple of sets (ProductSets) input of the self.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, Union
        >>> a = Interval(2, 3)
        >>> b = Interval(4, 5)
        >>> c = Interval(1, 7)
        >>> C1 = ComplexRegion(a*b)
        >>> C1.psets
        (Interval(2, 3) x Interval(4, 5),)
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.psets
        (Interval(2, 3) x Interval(4, 5), Interval(4, 5) x Interval(1, 7))

        (    (   R?   R   R=   (   R   t   psets(    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s
    c         C  s>   g  } x% |  j  D] } | j | j d  q Wt |   } | S(   s2  
        Return the union of intervals of `x` when, self is in
        rectangular form, or the union of intervals of `r` when
        self is in polar form.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, Union
        >>> a = Interval(2, 3)
        >>> b = Interval(4, 5)
        >>> c = Interval(1, 7)
        >>> C1 = ComplexRegion(a*b)
        >>> C1.a_interval
        Interval(2, 3)
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.a_interval
        Union(Interval(2, 3), Interval(4, 5))

        i    (   R   R   R=   R   (   R   t
   a_intervalR   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s
    c         C  s>   g  } x% |  j  D] } | j | j d  q Wt |   } | S(   s  
        Return the union of intervals of `y` when, self is in
        rectangular form, or the union of intervals of `theta`
        when self is in polar form.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, Union
        >>> a = Interval(2, 3)
        >>> b = Interval(4, 5)
        >>> c = Interval(1, 7)
        >>> C1 = ComplexRegion(a*b)
        >>> C1.b_interval
        Interval(4, 5)
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.b_interval
        Interval(1, 7)

        i   (   R   R   R=   R   (   R   t
   b_intervalR   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s
    c         C  s   |  j  S(   s  
        Returns True if self is in polar form.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, Union, S
        >>> a = Interval(2, 3)
        >>> b = Interval(4, 5)
        >>> theta = Interval(0, 2*S.Pi)
        >>> C1 = ComplexRegion(a*b)
        >>> C1.polar
        False
        >>> C2 = ComplexRegion(a*theta, polar=True)
        >>> C2.polar
        True
        (   R   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s    c         C  s
   |  j  j S(   sy  
        The measure of self.sets.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion, S
        >>> a, b = Interval(2, 5), Interval(4, 8)
        >>> c = Interval(0, 2*S.Pi)
        >>> c1 = ComplexRegion(a*b)
        >>> c1.measure
        12
        >>> c2 = ComplexRegion(a*c, polar=True)
        >>> c2.measure
        6*pi

        (   R?   t   _measure(   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s    c         C  s5   | j  t j  s! t d   n  |  | t d   S(   s%  
        Converts given subset of real numbers to a complex region.

        Examples
        ========

        >>> from sympy import Interval, ComplexRegion
        >>> unit = Interval(0,1)
        >>> ComplexRegion.from_real(unit)
        ComplexRegion(Interval(0, 1) x {0}, False)

        s&   sets must be a subset of the real linei    (   R   R
   R1   R8   R   (   R3   R?   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt	   from_real  s    c         C  s  d d l  m } m } d d l m } t |  } t | |  } | rh t |  d k rh t d   n  t | t	  r t | |  r t
 j S|  j s| r | n	 | j   \ } } xD |  j D]9 } t | j d j |  | j d j |   r t Sq Wt S|  j r| r| \ }	 }
 n8 | j r>t
 j t
 j }	 }
 n | |  | |  }	 }
 xD |  j D]9 } t | j d j |	  | j d j |
   rat SqaWt Sd  S(   Ni(   t   argt   Abs(   t   Tuplei   s   expecting Tuple of length 2i    i   (   t   sympy.functionsR   R   t   sympy.core.containersR   R   R   R:   R8   R   R
   R   R   t   as_real_imagR   R   R=   R   R!   R   t   is_zeroR/   (   R   R   R   R   R   t   isTuplet   ret   imR   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR   -  s4     			(   R%   R&   R'   R!   t   is_ComplexRegionR   R2   R,   R?   R=   RH   R;   R   R   R   R   R   t   classmethodR   R   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR     s   M5t	   Complexesc           B  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C  s   t  j |  t j t j  S(   N(   R   R2   R
   R1   (   R3   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR2   R  s    c         C  s   | t  t j t j  k S(   N(   R   R
   R1   (   R   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR4   U  s    c         C  s   t  t t j t j   S(   N(   R5   R   R
   R1   (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR6   X  s    c         C  s   d S(   Ns   S.Complexes(    (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __str__[  s    c         C  s   d S(   Ns   S.Complexes(    (   R   (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   __repr__^  s    (   R%   R&   R2   R4   R6   R   R   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyR   P  s
   				N(+   t
   __future__R    R   t   sympy.core.basicR   t   sympy.core.compatibilityR   R   R   R   t   sympy.core.exprR   t   sympy.core.functionR   t   sympy.core.singletonR	   R
   t   sympy.core.symbolR   R   t   sympy.core.sympifyR   R   R   t   sympy.logic.boolalgR   t   sympy.sets.setsR   R   R   R   t   sympy.utilities.miscR   R   R-   R0   R1   R7   Rz   R~   R   R   R   (    (    (    s3   lib/python2.7/site-packages/sympy/sets/fancysets.pyt   <module>   s0   ""4> C
	U ]