
    wg)                     T   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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 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) d dl*m+Z+m,Z, d dl-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9  G d de2e      Z: G d de2e      Z; G d de;      Z< G d de2e      Z= G d d e3e      Z> G d! d"e2      Z? G d# d$e2      Z@d% e&eA<   d& ZB G d' d(e2      ZC G d) d*eC      ZD G d+ d,eC      ZE G d- d.eDe      ZFy/)0    )reduce)product)Basic)Tuple)Expr)Lambda)	fuzzy_notfuzzy_or	fuzzy_and)Mod)igcd)ooRational)Eqis_eq)
NumberKind)	SingletonS)DummysymbolsSymbol)_sympifysympify_sympy_converter)ceilingfloor)sincos)AndOr   )tfnSetIntervalUnion	FiniteSet
ProductSetSetKind)
filldedentc                   n    e Zd ZdZdZej                  Zej                  Z	dZ
dZd Zd Zed        Zd Zy)		RationalsaS  
    Represents the rational numbers. This set is also available as
    the singleton ``S.Rationals``.

    Examples
    ========

    >>> from sympy import S
    >>> S.Half in S.Rationals
    True
    >>> iterable = iter(S.Rationals)
    >>> [next(iterable) for i in range(12)]
    [0, 1, -1, 1/2, 2, -1/2, -2, 1/3, 3, -1/3, -3, 2/3]
    TFc                 h    t        |t              st        j                  S t        |j
                     S N)
isinstancer   r   falser"   is_rationalselfothers     Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/sets/fancysets.py	_containszRationals._contains.   s&    %&77N5$$%%    c              #   <  K   t         j                   t         j                   t         j                   d}	 t	        |      D ]L  }t        ||      dk(  st        ||       t        ||       t        | |       t        | |       N |dz  }`w)N   r!   )r   ZeroOneNegativeOneranger   r   )r2   dns      r4   __iter__zRationals.__iter__3   s     ffeemm1X *1:?"1a.("1a.("A2q/)"A2q/)* FA s   ABABc                 "    t         j                  S r-   )r   Realsr2   s    r4   	_boundaryzRationals._boundaryA   s    wwr6   c                      t        t              S r-   r(   r   rB   s    r4   _kindzRationals._kindE       z""r6   N)__name__
__module____qualname____doc__is_iterabler   NegativeInfinity_infInfinity_supis_emptyis_finite_setr5   r?   propertyrC   rF    r6   r4   r+   r+      sO     KD::DHM&
  #r6   r+   )	metaclassc                       e Zd ZdZdZej                  Zej                  Z	dZ
dZd Zd Zd Zd Zed        Zd	 Zd
 Zy)Naturalsak  
    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
    TFc                     t        |t              st        j                  S |j                  r|j
                  rt        j                  S |j
                  du s|j                  du rt        j                  S y NF)r.   r   r   r/   is_positive
is_integertruer1   s     r4   r5   zNaturals._containsl   sY    %&77N5#3#366M&%*;*;u*D77N +Er6   c                 @    t        dt              j                  |      S Nr!   Ranger   	is_subsetr1   s     r4   _eval_is_subsetzNaturals._eval_is_subsett   s    Q|%%e,,r6   c                 @    t        dt              j                  |      S r^   r`   r   is_supersetr1   s     r4   _eval_is_supersetzNaturals._eval_is_supersetw   s    Q|''..r6   c              #   8   K   | j                   }	 | |dz   }
wr^   )rN   r2   is     r4   r?   zNaturals.__iter__z   s%     IIGAA s   c                     | S r-   rT   rB   s    r4   rC   zNaturals._boundary       r6   c                 j    t        t        t        |      |      || j                  k\  |t        k        S r-   )r   r   r   infr   r2   xs     r4   as_relationalzNaturals.as_relational   s'    2eAh?AM1r6::r6   c                      t        t              S r-   rE   rB   s    r4   rF   zNaturals._kind   rG   r6   N)rH   rI   rJ   rK   rL   r   r:   rN   rO   rP   rQ   rR   r5   rb   rf   r?   rS   rC   rp   rF   rT   r6   r4   rW   rW   I   s\    8 K55D::DHM-/  ;#r6   rW   c                   :    e Zd ZdZej
                  Zd Zd Zd Z	y)	Naturals0zRepresents 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                     t        |t              st        j                  S |j                  r|j
                  rt        j                  S |j                  du s|j
                  du rt        j                  S y rY   )r.   r   r   r/   r[   is_nonnegativer\   r1   s     r4   r5   zNaturals0._contains   sY    %&77N%"6"666M&%*>*>%*G77N +Hr6   c                 >    t        t              j                  |      S r-   r_   r1   s     r4   rb   zNaturals0._eval_is_subset   s    Ry""5))r6   c                 >    t        t              j                  |      S r-   rd   r1   s     r4   rf   zNaturals0._eval_is_superset   s    Ry$$U++r6   N)
rH   rI   rJ   rK   r   r9   rN   r5   rb   rf   rT   r6   r4   rs   rs      s!     66D*,r6   rs   c                   p    e Zd ZdZdZdZdZd Zd Ze	d        Z
e	d        Ze	d        Zd	 Zd
 Zd Zd Zy)IntegersaH  
    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
    TFc                 h    t        |t              st        j                  S t        |j
                     S r-   )r.   r   r   r/   r"   r[   r1   s     r4   r5   zIntegers._contains   s&    %&77N5##$$r6   c              #   n   K   t         j                   t         j                  }	 | |  |dz   }wr^   )r   r9   r:   rh   s     r4   r?   zIntegers.__iter__   s5     ffEEG"HAA s   35c                 "    t         j                  S r-   r   rM   rB   s    r4   rN   zIntegers._inf       !!!r6   c                 "    t         j                  S r-   r   rO   rB   s    r4   rP   zIntegers._sup       zzr6   c                     | S r-   rT   rB   s    r4   rC   zIntegers._boundary   rk   r6   c                      t        t              S r-   rE   rB   s    r4   rF   zIntegers._kind   rG   r6   c                 `    t        t        t        |      |      t         |k  |t        k        S r-   )r   r   r   r   rn   s     r4   rp   zIntegers.as_relational   s%    2eAh?RC!GQV44r6   c                 J    t        t         t              j                  |      S r-   r_   r1   s     r4   rb   zIntegers._eval_is_subset   s    bS"~''..r6   c                 J    t        t         t              j                  |      S r-   rd   r1   s     r4   rf   zIntegers._eval_is_superset   s    bS"~))%00r6   N)rH   rI   rJ   rK   rL   rQ   rR   r5   r?   rS   rN   rP   rC   rF   rp   rb   rf   rT   r6   r4   ry   ry      sr    < KHM%
 " "    #5/1r6   ry   c                   \    e Zd ZdZed        Zed        Zed        Zed        Zd Z	d Z
y)	rA   a  
    Represents all real numbers
    from negative infinity to positive infinity,
    including all integer, rational and irrational numbers.
    This set is also available as the singleton ``S.Reals``.


    Examples
    ========

    >>> from sympy import S, Rational, pi, I
    >>> 5 in S.Reals
    True
    >>> Rational(-1, 2) in S.Reals
    True
    >>> pi in S.Reals
    True
    >>> 3*I in S.Reals
    False
    >>> S.Reals.contains(pi)
    True


    See Also
    ========

    ComplexRegion
    c                 "    t         j                  S r-   r}   rB   s    r4   startzReals.start  r~   r6   c                 "    t         j                  S r-   r   rB   s    r4   endz	Reals.end  r   r6   c                      yNTrT   rB   s    r4   	left_openzReals.left_open      r6   c                      yr   rT   rB   s    r4   
right_openzReals.right_open  r   r6   c                 X    |t        t        j                  t        j                        k(  S r-   )r$   r   rM   rO   r1   s     r4   __eq__zReals.__eq__  s    !3!3QZZ@@@r6   c                 d    t        t        t        j                  t        j                              S r-   )hashr$   r   rM   rO   rB   s    r4   __hash__zReals.__hash__  s    HQ//<==r6   N)rH   rI   rJ   rK   rS   r   r   r   r   r   r   rT   r6   r4   rA   rA      sb    8 " "      A>r6   rA   c                       e Zd ZdZd Z e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d Zy)ImageSetaY  
    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 import FiniteSet, ImageSet, Interval

    >>> 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                     t        |t              st        d      |j                  }t	        |      t	        |      k7  rt        d      |D cg c]  }t        |       }}t        d |D              st        d      t         fdt        ||      D              st        d|d|      |t        j                  u rt	        |      dk(  r|d	   S t        |j                        |j                  j                  z  sAt        d
 |D              }|dk(  rt        j                   S |dk(  rt#        |j                        S t%        j&                   |g| S c c}w )NzFirst argument must be a LambdaIncompatible signaturec              3   <   K   | ]  }t        |t                y wr-   )r.   r#   .0ss     r4   	<genexpr>z#ImageSet.__new__.<locals>.<genexpr>f  s     4!:a%4s   z,Set arguments to ImageSet should of type Setc              3   H   K   | ]  \  }}j                  ||        y wr-   
_check_sig)r   sgstclss      r4   r   z#ImageSet.__new__.<locals>.<genexpr>i  s      Mfb"3>>"b)M   "z
Signature z does not match sets r!   r   c              3   4   K   | ]  }|j                     y wr-   )rQ   r   s     r4   r   z#ImageSet.__new__.<locals>.<genexpr>p  s     9q

9   TF)r.   r   
ValueError	signaturelenr   all	TypeErrorzipr   IdentityFunctionset	variablesexprfree_symbolsr
   EmptySetr&   r   __new__)r   flambdasetsr   r   rQ   s   `     r4   r   zImageSet.__new__[  s)   '6*>??%%	y>SY&566%)***4t44JKKMIt8LMMiQUVWWa(((SY!^7N7$$%(A(AA9D99H4zz!U" ..}}S'1D11% +s   Ec                      | j                   d   S Nr   argsrB   s    r4   <lambda>zImageSet.<lambda>x      $))A, r6   c                      | j                   dd  S r^   r   rB   s    r4   r   zImageSet.<lambda>y  s    diim r6   c                 l    | j                   }t        |      dk(  r|d   S t        | j                         S )Nr!   r   )	base_setsr   r'   flatten)r2   r   s     r4   base_setzImageSet.base_set{  s5     ~~t9>7Nt$,,..r6   c                 &    t        | j                   S r-   )r'   r   rB   s    r4   	base_psetzImageSet.base_pset  s    4>>**r6   c                      |j                   ryt        |t              rB|j                  }t	        |      t	        |      k7  ryt         fdt        ||      D              S y)NTFc              3   H   K   | ]  \  }}j                  ||        y wr-   r   )r   tspsr   s      r4   r   z&ImageSet._check_sig.<locals>.<genexpr>  s      M&"bs~~b"-Mr   )	is_symbolr.   r'   r   r   r   r   )r   sig_iset_ir   s   `   r4   r   zImageSet._check_sig  sP    ??z*::D5zSY&MCt<LMMM r6   c              #      K   t               }| j                  D ]+  } | j                  | }||v r|j                  |       | - y wr-   )r   r   lamdaadd)r2   already_seenri   vals       r4   r?   zImageSet.__iter__  sM     u 	A$**a.Cl"  %		s   AAc                 F    t        | j                  j                        dkD  S r^   )r   r   r   rB   s    r4   _is_multivariatezImageSet._is_multivariate  s    4::''(1,,r6   c                 2   ddl m} d }d }t        |      }| j                  j                  }| j                  j
                  }| j                  j                  }| j                  }|D 	ci c]  }	|	t        |	j                         }
}	|D 	cg c]  }	|	j                  |
       }}	|j                  |
      }|j                  |
      }g } |||      D ])  }|du rt        j                  c S |j                  |       +  |||      }|y d |D        }t        |      t        t        j                   |t                     z  }t#        |      }|D 	cg c]  }	||	   	 }}	 ||||      }|y t$        t'        |j(                           S c c}	w c c}	w c c}	w )Nr   )_solveset_multic                    t        t        | |            }i }|D ]n  \  }}|j                  r|||<   |j                  rJ|j                  }t        |      t        |      k7  rt        d      |j                  t        ||             n y |S )z,Attempt to get a map of symbols to base_setsr   N)listr   r   is_ProductSetr   r   r   extend)r   r   queue	symsetmapsigr   r   s          r4   get_symsetmapz)ImageSet._contains.<locals>.get_symsetmap  s    Y	23EI!&  X==%-IcN++#==D3x3t9,()ABBLLS$0    r6   c              3      K   | |fg}|D ]l  \  }}t        |t              st        ||       %t        |t              rt        |      t        |      k7  rd  y|j	                  t        ||             n yw)z:Find the equations relating symbols in expr and candidate.FN)r.   r   r   r   r   r   )r   	candidater   ecs        r4   get_equationsz)ImageSet._contains.<locals>.get_equations  sn     I&'E ,1!!U+Q(N#Au-Q3q61AKLLQ+,s   A8A:Fc              3   4   K   | ]  }|j                     y wr-   )r   )r   eqs     r4   r   z%ImageSet._contains.<locals>.<genexpr>  s     5R5r   )sympy.solvers.solvesetr   r   r   r   r   r   r   r   namesubsr   r/   appendr   r   uniontupler"   r	   rQ   )r2   r3   r   r   r   r   r   r   r   vrep	equationsr   r   symsssolnsets                   r4   r5   zImageSet._contains  s|   :	(
	, zzjj""JJ((	NN	 *33Aq%-33*34QQVVC[4	4hhsmyy~ 	e, 	!BU{wwR 		! "#y1	 695	NVCIIuce%DD	 )$	+45aYq\5	5!)Y	B?9W--.//; 440 6s   *F
FFc                 :    t        d | j                  D              S )Nc              3   4   K   | ]  }|j                     y wr-   )rL   r   s     r4   r   z'ImageSet.is_iterable.<locals>.<genexpr>  s     9Q1==9r   )r   r   rB   s    r4   rL   zImageSet.is_iterable  s    9$..999r6   c                    ddl m} | j                  j                  }t	        |      dk(  rY|d   j
                  rJt        j                  t              r0| j                  d   } ||      j                        j                  S t        d | j                  D              r!t        fdt        | j                   D         S | S )Nr   )SetExprr!   c              3   4   K   | ]  }|j                     y wr-   is_FiniteSetr   s     r4   r   z ImageSet.doit.<locals>.<genexpr>  s     6!q~~6r   c              3   (   K   | ]	  } |   y wr-   rT   )r   afs     r4   r   z ImageSet.doit.<locals>.<genexpr>   s     Gq!uGs   )sympy.sets.setexprr   r   r   r   r   r.   r   r   r   
_eval_funcr   r   r&   r   )r2   hintsr   r   r   r   s        @r4   doitzImageSet.doit  s    .JJkks8q=SV--*QVVT2J~~a(H8$//26666t~~66Ggt~~.FGHHr6   c                 T    t        | j                  j                  j                        S r-   )r(   r   r   kindrB   s    r4   rF   zImageSet._kind  s    tzz++,,r6   N)rH   rI   rJ   rK   r   rS   r   r   r   r   classmethodr   r?   r   r5   rL   r   rF   rT   r6   r4   r   r   #  s    6n2: ./E34I/ / + +  $-I0V : :	-r6   r   c                       e 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ed
        Zd Zed        Zed        Zed        Zd Zd Zed        Zed        Zed        Zd Zy)r`   a	  
    Represents a range of integers. Can be called as ``Range(stop)``,
    ``Range(start, stop)``, or ``Range(start, stop, step)``; when ``step`` is
    not given it defaults to 1.

    ``Range(stop)`` is the same as ``Range(0, stop, 1)`` and the stop value
    (just 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):
        ...
        TypeError: Cannot iterate over Range with infinite start
        >>> next(iter(r.reversed))
        0

    Although ``Range`` is a :class:`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

    Range will accept symbolic arguments but has very limited support
    for doing anything other than displaying the Range:

        >>> from sympy import Symbol, pprint
        >>> from sympy.abc import i, j, k
        >>> Range(i, j, k).start
        i
        >>> Range(i, j, k).inf
        Traceback (most recent call last):
        ...
        ValueError: invalid method for symbolic range

    Better success will be had when using integer symbols:

        >>> n = Symbol('n', integer=True)
        >>> r = Range(n, n + 20, 3)
        >>> r.inf
        n
        >>> pprint(r)
        {n, n + 3, ..., n + 18}
    c                 "   t        |      dk(  r$t        |d   t              rt        d|d   z        t	        | }|j
                  dk(  rt        d      |j                  xs d|j                  |j
                  xs d}}}	 g }|||fD ]  }t        |      }|t        j                  t        j                  fv s$|j                  t              r!|j                  dk7  r|j!                  |       f|j"                  s|j$                  rt        d      t        |j!                  |        	 |\  }}}d}t)        d |||fD              r||z
  }	|	|z  }
|
j*                  rX|	dk(  rd	}nLt-        |
      }
||
|z  z   }|	j*                  r||z
  j.                  r||z  }n||z  dz
  j.                  r||z  }n|
j0                  rd	}n|}n|j$                  rs|||z
  z  }|t        j2                  u s|dk  rd	}n|j"                  rB|j$                  r6t5        |      dk7  r(t        t'        d
|dkD  rdz              dz              |}nl|j$                  }|r%|dkD  rt        j6                  nt        j8                  }t;        ||z
  |z        }
|
dk  rd	}n |rt        j6                  }||z   }n||
|z  z   }|r"t        j<                  x}}t        j6                  }t?        j@                  | ||      S # t        $ r t        t'        d            w xY w)Nr!   r   z)use sympify(%s) to convert range to Rangezstep cannot be 0Fzinfinite symbols not allowedz
    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].c              3   F   K   | ]  }|j                  t                y wr-   )hasr   r   ri   s     r4   r   z Range.__new__.<locals>.<genexpr>|  s     :quuV}:s   !Tz7
                    Step size must be %s in this case.)!r   r.   r<   r   slicestepr   r   stopr   r   rM   rO   r  r   r[   r   
is_Integeris_infiniter)   anyis_Rationalr   is_negativeis_extended_negativeNaNabsr:   r;   r   r9   r   r   )r   r   slcr   r  r  okwnulldifr>   r   spanoosteps                 r4   r   zRange.__new__Z  s   t9>$q'5)?$q'IK K Tl88q=/00IINCHHchhm!Tt	BT4( 
!AJ++QZZ88f!,,%*?IIaL}}()GHH$$IIaL
!  tT:udD&9::,CDA}}!8DaA!D&.C$J334KCHqL554KC''&Dquu}	T%5%5#d)q.  -:BF(Q-T "U V VPR-T "U V V %%F $qquuammt+,AAvuudlafn&& EC55D}}S%d33g  	Z )   	s   B)K0 0Lc                      | j                   d   S r   r   rB   s    r4   r   zRange.<lambda>  r   r6   c                      | j                   d   S r^   r   rB   s    r4   r   zRange.<lambda>      1 r6   c                      | j                   d   S )Nr8   r   rB   s    r4   r   zRange.<lambda>  r  r6   c                    | j                  t              rY| j                  | j                  z
  | j                  z  }|j
                  rt        d | j                  D              st        d      | j                  | j                  k(  r| S | j                  | j                  | j                  z
  | j                  | j                  z
  | j                         S )zReturn an equivalent Range in the opposite order.

        Examples
        ========

        >>> from sympy import Range
        >>> Range(10).reversed
        Range(9, -1, -1)
        c              3   P   K   | ]  }|j                   xs |j                     y wr-   r[   r
  r  s     r4   r   z!Range.reversed.<locals>.<genexpr>  '      5F67ALL1AMM15F   $&!invalid method for symbolic range)
r  r   r  r   r  is_extended_positiver   r   r   func)r2   r>   s     r4   reversedzRange.reversed  s     88FTZZ'2A)) 5F;?995F 2F !DEE::"KyyII		!4::		#9DII:G 	Gr6   c                      t        t              S r-   rE   rB   s    r4   rF   zRange._kind  rG   r6   c                    | j                   | j                  k(  rt        j                  S |j                  rt        j                  S |j
                  st        |j
                     S | j                  t              rO| j                  | j                   z
  | j                  z  }|j                  rt        d | j                  D              sy | j                  }| j                   j                  r| j                   }n3| j                  j                  r| j                  }nt        j                  S |dk(  rt!        || d         S ||z
  | j                  z  }|t        j"                  k(  rg| j                  t              r,t%        d      }| j'                  |      j)                  ||      S t+        || j,                  k\  || j.                  k        S |j0                  rt        j                  S y )Nc              3   P   K   | ]  }|j                   xs |j                     y wr-   r  r  s     r4   r   z"Range._contains.<locals>.<genexpr>  r  r   r!   r   ri   )r   r  r   r/   r
  r[   r"   r  r   r  r"  r   r   size	is_finiter\   r   r9   r   rp   r   r   rm   supr	  )r2   r3   r>   refresr=   s         r4   r5   zRange._contains  sm   ::"77N77Nu''((88FTZZ'2A)) 5F;?995F 2F		A::**CYY  ))C66M6eT!W%%U{dii'!&&=xx#J))!,11!U;;u(%488*;<<^^77Nr6   c              #     K   | j                   }|j                  t        j                        s6|j                  t        j                        s|j
                  st        d      | j                  t        j                  t        j                  fv rt        d      | j                  | j                  k7  rQ| j                  }|j                  r	 | || j                  z  }t        |      D ]  }| || j                  z  } y y w)Nz"Cannot iterate over symbolic Rangez-Cannot iterate over Range with infinite start)r(  r  r   rO   rM   r	  r   r   r  r
  r  r<   )r2   r>   ri   _s       r4   r?   zRange.__iter__  s     IIajj!QUU1+=+=%>!,,@AA::!,,ajj99KLLZZ499$

A}}GNA  q #AGNA# %s   DDc                    | j                   | j                  z
  }|| j                  z  }|j                  t        j
                        s,|j                  t        j                        s|j                  sy| j                  t        j                  t        j
                  fv ry|j                  rt        d | j                  D              syy)NFc              3   4   K   | ]  }|j                     y wr-   r[   r  s     r4   r   z$Range.is_iterable.<locals>.<genexpr>   s     1R1!,,1Rr   T)r  r   r  r  r   rO   rM   r	  is_extended_nonnegativer   r   r2   r  r>   s      r4   rL   zRange.is_iterable  s     ii$**$		Majj!QUU1+=+=%>!,,::!,,ajj99))c1R		1R.Rr6   c                 j    | j                   }|t        j                  u rt        d      t	        |      S )Nz0Use .size to get the length of an infinite Range)r(  r   rO   r   int)r2   rvs     r4   __len__zRange.__len__  s,    YYOPP2wr6   c                 j   | j                   | j                  k(  rt        j                  S | j                  | j                   z
  }|| j                  z  }|j
                  rt        j                  S |j                  r0t        d | j                  D              rt        t        |            S t        d      )Nc              3   4   K   | ]  }|j                     y wr-   r1  r  s     r4   r   zRange.size.<locals>.<genexpr>  s     -Nqall-Nr   !Invalid method for symbolic Range)r   r  r   r9   r  r
  rO   r2  r   r   r  r   r   r3  s      r4   r(  z
Range.size
  s    ::"66Mii$**$		M==::%%#-NDII-N*NuQx= <==r6   c                     | j                   j                  r| j                  j                  ry| j                  j                  S r   )r   r[   r  r(  r)  rB   s    r4   rR   zRange.is_finite_set  s.    ::  TYY%9%9yy"""r6   c                 N    	 | j                   j                  S # t        $ r Y y w xY wr-   )r(  is_zeror   rB   s    r4   rQ   zRange.is_empty  s)    	99$$$ 		s    	$$c                 t    t        | j                  | j                        }|t        d      t	        |       S )Nz#cannot tell if Range is null or not)r   r   r  r   bool)r2   bs     r4   __bool__zRange.__bool__#  s5     $**dii(9BCC7{r6   c                 	   d}d}d}d}t        |t              r7| j                  j                  r| j                  | j
                  k(  rt        d      S |j                  | j                        \  }}}t        ||z
  |z        }	|	dk  rt        d      S ||	|z  z   }
|
|z
  }|| j                  z  }t        | |   | |   |z   |      S |j                  }|j
                  }|j                  dk(  rt        |      |j                  xs d}|| j                  z  }| j                  j                  r!| j
                  j                  rt        |      | j
                  j                  r)| j                  ||n| dz   ||n| |   j                  S ||1|dk  rt        | d   | j                  |      S |dkD  rt        |      | S |dk  r2|dk  rt        | d   | |   |      S t        | j                  | |   |      S |dk(  r|dkD  rt        d      S t        |      |dk(  r|dkD  rt        |      t        |      t        |      |dk  r|9|dk  rt        | |   | j                  |      S t        | |   | j
                  |      S |dk  rt        | |   | |   |      S |dk(  r|dk  rt        |      t        d      S |dkD  rt        |      |dk(  rn|"|dk  rt        |      |dkD  rt        |      | S |dk  r:|dkD  rt        |      |dk(  rt        | j                  | |   |      S t        d      S t        |      |dkD  rt        |      y y | j                  | j
                  k(  rt        d      t        d	 | j                  D              r0| j
                  | j                  z
  | j                  z  j                   st        d
      |dk(  r-| j                  j                  rt        |      | j                  S |dk(  r:| j
                  j                  rt        |      | j
                  | j                  z
  S | j                  }	|dk  r| j
                  n| j                  || j                  z  z   }|j                  rt        |      || j                  z
  | j                  z  }t#        |j                  t%        |j&                  |	|z
  j&                  g      g      }|r|S |t        d
      t        d      )Nz0cannot slice from the end with an infinite valuezslice step cannot be zeroz1slicing not possible on range with infinite startzBcannot unambiguously re-stride from the end with an infinite valuer   r!   r  zRange index out of rangec              3   P   K   | ]  }|j                   xs |j                     y wr-   r  r  s     r4   r   z$Range.__getitem__.<locals>.<genexpr>  s(      ( 55 (r   r:  )r.   r  r(  r)  r   r  r`   indicesr   r  r   r
  r$  
IndexErrorr   r   r"  r
   r   ru   )r2   ri   ooslicezerostepinfinite	ambiguousr   r  r  r>   canonical_stopr   ssr6  r   rels                   r4   __getitem__zRange.__getitem__,  s   D.F%	ayy""::* 8O$%IIdii$8!tTTE\4/06 8O!&4$t+$))^T%[$s)b."==vv66Q;$X..vv{$))^
 ::))dii.C.C$X..
 99((  == $4%!)!&UF 'h' =|!8#(b4::r#BB!AX",Y"77#'K!8#(b4:r#BB#(T$Z#DD!8#(8O",W"55!8",W"55",W"55(11QY|!8#(edjj"#EE#(edii#DD$T%[$t*bAA!8",W"55#(8O(11aZ|!8",W"55!AX",Y"77#'K!8",Y"77!QY#(T$Z#DD#(8O(11QY$W-- ' ", zzTYY& !;<< (!YY( (.2ii$**.DII.33-4 !DEEAv::))$W--zz!Bw99(($W--yy499,,		A 1u$))$**$))CB~~ ))

?DII-CCOO%s'9'9AcE;Q;Q&RSU VC	{ !DEE788r6   c                    | st         j                  j                  S | j                  t              rt        d | j                  D              r| j                  | j                  z
  }| j                  j                  r|j                  r| j                  S | j                  j                  r%|j                  r| j                  | j                  z
  S t        d      | j                  dkD  r| j                  S | j                  | j                  z
  S )Nc              3   P   K   | ]  }|j                   xs |j                     y wr-   r  r  s     r4   r   zRange._inf.<locals>.<genexpr>        DQ1<<01==0Dr   r!  r   )r   r   rm   r  r   r   r   r  r   r  rZ   r  r   r2   r  s     r4   rN   z
Range._inf  s    ::>>!88FD$))DDii$**,99((S__::%YY**s99tyy00@AA99q=::99tyy((r6   c                    | st         j                  j                  S | j                  t              rt        d | j                  D              r| j                  | j                  z
  }| j                  j                  r%|j                  r| j                  | j                  z
  S | j                  j                  r|j                  r| j                  S t        d      | j                  dkD  r| j                  | j                  z
  S | j                  S )Nc              3   P   K   | ]  }|j                   xs |j                     y wr-   r  r  s     r4   r   zRange._sup.<locals>.<genexpr>  rP  r   r!  r   )r   r   r*  r  r   r   r   r  r   r  rZ   r  r   rQ  s     r4   rP   z
Range._sup  s    ::>>!88FD$))DDii$**,99((S__99tyy00YY**s::%@AA99q=99tyy((::r6   c                     | S r-   rT   rB   s    r4   rC   zRange._boundary  rk   r6   c           	      `   | j                   j                  r/| j                  j                  rJ | j                  j                   }n| j                   }| j                  }t        t        ||z
  |      d      }t        t        t        |d      d      t        t        |d      d            }| j                  | j                   z
  | j                  z  }|dk(  rt        j                  j                  |      S |dk(  rt        t        ||      |      S 	 | j                  | j                  }}|5t        |j                  r||kD  n||k\  j                  r||k  n||k        }n| j                   | j                  | j                  z
  }}t        t        | j                  dk\  |j                  r||kD  n||k\  |j                  r||k  n||k        t        | j                  dk  |j                  r||k  n||k  |j                  r||kD  n||k\              }t        |||      S # t        $ r d}Y w xY w)z<Rewrite a Range in terms of equalities and logic operators. r   r!   Nr  )r   r
  r  r$  r  r   r   r   r   r   rp   rm   r*  r   r    )	r2   ro   r   r  in_seqintsr>   r@  
range_conds	            r4   rp   zRange.as_relational  s   ::!!yy,,,,##A

AyyCAt$a(2c!Qi#RD!a%89YY#TYY.6::++A..6r!Qx&&	88TXXqA =AAFAAF4J ::tyy4994qADIINQ]]AEQAAF4DIIOammQUaAAF45J
 64,,  	A	s   H H-,H-N)rH   rI   rJ   rK   r   rS   r   r  r  r$  rF   r5   r?   rL   r7  r(  rR   rQ   rA  rM  rN   rP   rC   rp   rT   r6   r4   r`   r`     s    PdM4^ ./E-.D-.DG G(#B#" 
 
 	> 	> # #
  J9X ) )      -r6   r`   c                 X    t        | j                  | j                  | j                        S r-   )r`   r   r  r  )rs    r4   r   r     s    E!''166166$B r6   c           	      *   ddl m} | j                  r| j                  }|dt        j
                  z  k\  r|dt        j
                  z  k(  r| j                  ru| j                  ri || j                        }t        t        d|t        j
                  z  dd      t        |t        j
                  z  dt        j
                  z  dd            S t        ddt        j
                  z  dd      S  || j                         || j                        }}||t        d      |t        j
                  z  }|t        j
                  z  }||kD  rWt        t        t        j                  |d| j                        t        |dt        j
                  z  | j                  d            S t        ||| j                  | j                        S | j                  rHg }| D ]9  }	 ||	      }|t        d      |j                  |t        j
                  z         ; t!        | S | j"                  r)t        | j$                  D 
cg c]  }
t'        |
       c}
 S | j)                  t        j*                        rt        dt-        |       z        t/        d	| z        c c}
w )
a  
    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}

    r   )	_pi_coeffr8   FTzBNormalizing theta without pi as coefficient is not yet implementedz@Normalizing theta without pi as coefficient, is not Implemented.z;Normalizing theta when, it is of type %s is not implementedz %s is not a real set)(sympy.functions.elementary.trigonometricr\  is_Intervalmeasurer   Pir   r   r   r%   r$   r   NotImplementedErrorr9   r   r   r&   is_Unionr   normalize_theta_setra   rA   typer   )thetar\  interval_lenkk_startk_end	new_startnew_end	new_thetaelementintervals              r4   rc  rc    s9   L C}}1QTT6!qv%%//e>N>Nekk*Xa144= 144144t<> >Aqvud33"5;;/5991E?em% ': ; ;ADDL	*w!&&'5%:J:JK!)QqttVU__dKM M IwAQAQRR				 	)G'"Ay) +M N N   144(	) )$$	UZZP*84PQQ		!! #026u+#> ? 	? 0E:;; Qs   6Jc                       e Zd ZdZdZddZed        Zed        Zed        Z	ed        Z
ed        Zd	 Zed
        Zd Zy)ComplexRegionaA
  
    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``, and use the flag ``polar=True``.

      .. math:: Z = \{z \in \mathbb{C} \mid z = r\times (\cos(\theta) + I\sin(\theta)), r \in [\texttt{r}], \theta \in [\texttt{theta}]\}

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

    .. math:: Z = \{z \in \mathbb{C} \mid z = x + Iy, x \in [\operatorname{re}(z)], y \in [\operatorname{im}(z)]\}

    Examples
    ========

    >>> from sympy import ComplexRegion, Interval, S, I, Union
    >>> a = Interval(2, 3)
    >>> b = Interval(4, 6)
    >>> c1 = ComplexRegion(a*b)  # Rectangular Form
    >>> c1
    CartesianComplexRegion(ProductSet(Interval(2, 3), Interval(4, 6)))

    * 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.

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

    * 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
    PolarComplexRegion(ProductSet(Interval(0, 1), Interval.Ropen(0, 2*pi)))

    * 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
    PolarComplexRegion(ProductSet(Interval(0, 1), Interval(0, pi)))
    >>> intersection == upper_half_unit_disk
    True

    See Also
    ========

    CartesianComplexRegion
    PolarComplexRegion
    Complexes

    Tc                 T    |du rt        |      S |du rt        |      S t        d      )NFTz$polar should be either True or False)CartesianComplexRegionPolarComplexRegionr   )r   r   polars      r4   r   zComplexRegion.__new__  s2    E>)$//d]%d++CDDr6   c                      | j                   d   S )a  
        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
        ProductSet(Interval(2, 3), Interval(4, 5))
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.sets
        Union(ProductSet(Interval(2, 3), Interval(4, 5)), ProductSet(Interval(4, 5), Interval(1, 7)))

        r   r   rB   s    r4   r   zComplexRegion.sets  s    ( yy|r6   c                     | j                   j                  rd}|| j                   fz   }|S | j                   j                  }|S )a  
        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
        (ProductSet(Interval(2, 3), Interval(4, 5)),)
        >>> C2 = ComplexRegion(Union(a*b, b*c))
        >>> C2.psets
        (ProductSet(Interval(2, 3), Interval(4, 5)), ProductSet(Interval(4, 5), Interval(1, 7)))

        rT   )r   r   r   )r2   psetss     r4   rw  zComplexRegion.psets  sA    ( 99""ETYYM)E  IINNEr6   c                 x    g }| j                   D ]   }|j                  |j                  d          " t        | }|S )a2  
        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))

        r   rw  r   r   r%   )r2   
a_intervalrm  s      r4   rz  zComplexRegion.a_interval  D    , 
zz 	/Ggll1o.	/ J'
r6   c                 x    g }| j                   D ]   }|j                  |j                  d          " t        | }|S )a  
        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)

        r!   ry  )r2   
b_intervalrm  s      r4   r}  zComplexRegion.b_interval  r{  r6   c                 .    | j                   j                  S )ay  
        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   _measurerB   s    r4   r  zComplexRegion._measure  s    & yy!!!r6   c                 4    | j                   d   j                  S r   )r   r   rB   s    r4   rF   zComplexRegion._kind.  s    yy|   r6   c                     |j                  t        j                        st        d      t	        |t        d      z        S )a2  
        Converts given subset of real numbers to a complex region.

        Examples
        ========

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

        z&sets must be a subset of the real liner   )ra   r   rA   r   rr  r&   )r   r   s     r4   	from_realzComplexRegion.from_real1  s4     ~~agg&EFF%dYq\&9::r6   c                    ddl m}m} t        |t              }|rt        |      dk7  rt        d      t        |t        t        f      st        j                  S | j                  s=|r|n|j                         \  t        t        fd| j                  D                 S | j                  r|j                  r#t        t        d | j                  D                 S |r|\  n ||       ||      cj                   rIj"                  r<dt        j$                  z  z  t        t        fd| j                  D                 S y y y )Nr   )argAbsr8   zexpecting Tuple of length 2c              3      K   | ]I  }t        |j                  d    j                        |j                  d   j                        g       K ywr   r!   Nr   r   r5   )r   psetimres     r4   r   z*ComplexRegion._contains.<locals>.<genexpr>R  sQ       (  !*		!&&r*		!&&r*+, !-  (   AAc              3   t   K   | ]0  }|j                   d    j                  t        j                         2 yw)r   N)r   r5   r   r9   )r   r  s     r4   r   z*ComplexRegion._contains.<locals>.<genexpr>[  s/      $, %)IIaL$:$:166$B $,s   68c              3      K   | ]I  }t        |j                  d    j                        |j                  d   j                        g       K ywr  r  )r   r  rZ  re  s     r4   r   z*ComplexRegion._contains.<locals>.<genexpr>d  sQ      $,  %.IIaL**1-IIaL**51/3 %4 $,r  )sympy.functionsr  r  r.   r   r   r   r   r   r/   rt  as_real_imagr"   r
   rw  r=  is_real	is_numberr`  )	r2   r3   r  r  isTupler  rZ  r  re  s	        @@@@r4   r5   zComplexRegion._containsD  s/   ,UE*s5zQ:;; %$/77N zz%U5+=+=+?FBx  ( !JJ ( ( ) ) ZZ}}8 $, $

$, , - - 5u:s5z5}}1448 $, !%

$, , - - "1} r6   N)F)rH   rI   rJ   rK   is_ComplexRegionr   rS   r   rw  rz  r}  r  rF   r   r  r5   rT   r6   r4   rp  rp  V  s    LZ E  *  4  8  8 " "(! ; ;$#-r6   rp  c                   >    e Zd ZdZdZ ede      Zd Ze	d        Z
y)rr  a  
    Set representing a square region of the complex plane.

    .. math:: Z = \{z \in \mathbb{C} \mid z = x + Iy, x \in [\operatorname{re}(z)], y \in [\operatorname{im}(z)]\}

    Examples
    ========

    >>> from sympy import ComplexRegion, I, Interval
    >>> region = ComplexRegion(Interval(1, 3) * Interval(4, 6))
    >>> 2 + 5*I in region
    True
    >>> 5*I in region
    False

    See also
    ========

    ComplexRegion
    PolarComplexRegion
    Complexes
    Fzx, yr   c                    |t         j                  t         j                  z  k(  rt         j                  S t        d |j                  D              rot        |j                        dk(  rWg }|j                  d   D ];  }|j                  d   D ]'  }|j                  |t         j                  |z  z          ) = t        | S t        j                  | |      S )Nc              3   4   K   | ]  }|j                     y wr-   r   )r   _as     r4   r   z1CartesianComplexRegion.__new__.<locals>.<genexpr>  s     32r3r   r8   r   r!   )r   rA   	Complexesr   r   r   r   ImaginaryUnitr&   r#   r   )r   r   complex_numro   ys        r4   r   zCartesianComplexRegion.__new__  s    177177?";;333TYY19L KYYq\ >1 >A&&q1??1+<'<=>> k**;;sD))r6   c                 L    | j                   \  }}|t        j                  |z  z   S r-   )r   r   r  )r2   ro   r  s      r4   r   zCartesianComplexRegion.expr  s#    ~~11??1$$$r6   NrH   rI   rJ   rK   rt  r   r   r   r   rS   r   rT   r6   r4   rr  rr  j  s3    . EE*I** % %r6   rr  c                   >    e Zd ZdZdZ ede      Zd Ze	d        Z
y)rs  aX  
    Set representing a polar region of the complex plane.

    .. math:: Z = \{z \in \mathbb{C} \mid z = r\times (\cos(\theta) + I\sin(\theta)), r \in [\texttt{r}], \theta \in [\texttt{theta}]\}

    Examples
    ========

    >>> from sympy import ComplexRegion, Interval, oo, pi, I
    >>> rset = Interval(0, oo)
    >>> thetaset = Interval(0, pi)
    >>> upper_half_plane = ComplexRegion(rset * thetaset, polar=True)
    >>> 1 + I in upper_half_plane
    True
    >>> 1 - I in upper_half_plane
    False

    See also
    ========

    ComplexRegion
    CartesianComplexRegion
    Complexes

    Tzr, thetar  c                 L   g }|j                   s#|j                  D ]  }|j                  |        n|j                  |       t        |      D ]7  \  }}t	        |j                  d   t        |j                  d               ||<   9 t        | }t        j                  | |      S )Nr   r!   )	r   r   r   	enumerater'   rc  r%   r#   r   )r   r   new_setsrg  r   s        r4   r   zPolarComplexRegion.__new__  s    !!YY #"# OOD!h' 	EDAq$QVVAY%8%CEHQK	E h{{3%%r6   c                 v    | j                   \  }}|t        |      t        j                  t	        |      z  z   z  S r-   )r   r   r   r  r   )r2   rZ  re  s      r4   r   zPolarComplexRegion.expr  s0    >>5#e*qs5z99::r6   Nr  rT   r6   r4   rs  rs    s3    4 E
.I&" ; ;r6   rs  c                   .    e Zd ZdZdZdZed        Zd Zy)r  z
    The :class:`Set` of all complex numbers

    Examples
    ========

    >>> from sympy import S, I
    >>> S.Complexes
    Complexes
    >>> 1 + I in S.Complexes
    True

    See also
    ========

    Reals
    ComplexRegion

    Fc                 R    t        t        j                  t        j                        S r-   )r'   r   rA   rB   s    r4   r   zComplexes.sets  s    !''177++r6   c                 ,    t        j                  |       S r-   )r#   r   r  s    r4   r   zComplexes.__new__  s    {{3r6   N)	rH   rI   rJ   rK   rQ   rR   rS   r   r   rT   r6   r4   r  r    s,    ( HM , , r6   r  N)G	functoolsr   	itertoolsr   sympy.core.basicr   sympy.core.containersr   sympy.core.exprr   sympy.core.functionr   sympy.core.logicr	   r
   r   sympy.core.modr   sympy.core.intfuncr   sympy.core.numbersr   r   sympy.core.relationalr   r   sympy.core.kindr   sympy.core.singletonr   r   sympy.core.symbolr   r   r   sympy.core.sympifyr   r   r   #sympy.functions.elementary.integersr   r   r]  r   r   sympy.logic.boolalgr   r    r   r"   r#   r$   r%   r&   r'   r(   sympy.utilities.miscr)   r+   rW   rs   ry   rA   r   r`   r<   rc  rp  rr  rs  r  rT   r6   r4   <module>r     s     " '   & ; ;  # + + & - 4 4 B B > = ' K K K +.#y .#b?#si ?#D, ,6F1si F1R1>H	 1>ha-s a-Hu-C u-p C  R<jQ-C Q-h3%] 3%l2; 2;j &)  r6   