
    \h;                     :   S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJrJr  S SKJr  S S	KJr  S S
KJrJrJr  S SKJrJr  S SKJr  S SKJrJr  S SK J!r!J"r"J#r#  S SK$J%r%J&r&J'r'  S SK(J)r)J*r*  S SK+J,r,J-r-  S SK.J/r/J0r0  SSK1J2r2J3r3J4r4J5r5J6r6J7r7J8r8  S SK9J:r:   " S S\3\S9r; " S S\3\S9r< " S S\<5      r= " S S\3\S9r> " S S \4\S9r? " S! S"\35      r@ " S# S$\35      rAS% \'\B'   S& rC " S' S(\35      rD " S) S*\D5      rE " S+ S,\D5      rF " S- S.\E\S9rGg/)0    )reduce)product)Basic)Tuple)Expr)Lambda)	fuzzy_notfuzzy_or	fuzzy_and)Mod)igcd)ooRationalInteger)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                   v    \ rS rSrSrSr\R                  r\R                  r
SrSrS rS r\S 5       rS rS	rg
)	Rationals   a'  
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                 r    [        U[        5      (       d  [        R                  $ [        UR
                     $ N)
isinstancer   r   falser#   is_rationalselfothers     L/var/www/auris/envauris/lib/python3.13/site-packages/sympy/sets/fancysets.py	_containsRationals._contains.   s)    %&&77N5$$%%    c              #   @  #    [         R                  v   [         R                  v   [         R                  v   Sn [	        U5       HL  n[        X!5      S:X  d  M  [        X!5      v   [        X5      v   [        U* U5      v   [        U* U5      v   MN     US-  nMb  7f)N   r"   )r   ZeroOneNegativeOneranger   r   )r4   dns      r6   __iter__Rationals.__iter__3   s     ffeemm1X:?"1.("1.("A2q/)"A2q/)  FA s   ABABc                 "    [         R                  $ r/   )r   Realsr4   s    r6   	_boundaryRationals._boundaryA   s    wwr9   c                      [        [        5      $ r/   r)   r   rF   s    r6   _kindRationals._kindE       z""r9    N)__name__
__module____qualname____firstlineno____doc__is_iterabler   NegativeInfinity_infInfinity_supis_emptyis_finite_setr7   rB   propertyrG   rK   __static_attributes__rN   r9   r6   r,   r,      sO     KD::DHM&
  #r9   r,   )	metaclassc                       \ rS rSr% SrSr\R                  r\	\
S'   \R                  rSrSrS rS rS rS	 r\S
 5       rS rS rSrg)NaturalsI   a  
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
TrV   Fc                    [        U[        5      (       d  [        R                  $ UR                  (       a!  UR
                  (       a  [        R                  $ UR
                  SL d  UR                  SL a  [        R                  $ g NF)r0   r   r   r1   is_positive
is_integertruer3   s     r6   r7   Naturals._containsl   s\    %&&77N5#3#366M&%*;*;u*D77N +Er9   c                 @    [        S[        5      R                  U5      $ Nr"   Ranger   	is_subsetr3   s     r6   _eval_is_subsetNaturals._eval_is_subsett   s    Q|%%e,,r9   c                 @    [        S[        5      R                  U5      $ rh   rj   r   is_supersetr3   s     r6   _eval_is_supersetNaturals._eval_is_supersetw   s    Q|''..r9   c              #   :   #    U R                   n Uv   US-   nM  7frh   )rV   r4   is     r6   rB   Naturals.__iter__z   s$     IIGAA s   c                     U $ r/   rN   rF   s    r6   rG   Naturals._boundary       r9   c                 h    [        [        [        U5      U5      XR                  :  U[        :  5      $ r/   )r    r   r   infr   r4   xs     r6   as_relationalNaturals.as_relational   s%    2eAh?AM1r6::r9   c                      [        [        5      $ r/   rJ   rF   s    r6   rK   Naturals._kind   rM   r9   rN   N)rO   rP   rQ   rR   rS   rT   r   r=   rV   r   __annotations__rW   rX   rY   rZ   r7   rl   rq   rB   r[   rG   r~   rK   r\   rN   r9   r6   r_   r_   I   sa    8 KEED'::DHM-/  ;#r9   r_   c                   B    \ rS rSrSr\R                  rS rS r	S r
Srg)	Naturals0   zRepresents 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                    [        U[        5      (       d  [        R                  $ UR                  (       a!  UR
                  (       a  [        R                  $ UR                  SL d  UR
                  SL a  [        R                  $ g rb   )r0   r   r   r1   rd   is_nonnegativere   r3   s     r6   r7   Naturals0._contains   s\    %&&77N%"6"666M&%*>*>%*G77N +Hr9   c                 >    [        [        5      R                  U5      $ r/   ri   r3   s     r6   rl   Naturals0._eval_is_subset   s    Ry""5))r9   c                 >    [        [        5      R                  U5      $ r/   ro   r3   s     r6   rq   Naturals0._eval_is_superset   s    Ry$$U++r9   rN   N)rO   rP   rQ   rR   rS   r   r<   rV   r7   rl   rq   r\   rN   r9   r6   r   r      s!     66D*,r9   r   c                   x    \ rS rSrSrSrSrSrS rS r	\
S 5       r\
S 5       r\
S	 5       rS
 rS rS rS rSrg)Integers   a  
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                 r    [        U[        5      (       d  [        R                  $ [        UR
                     $ r/   )r0   r   r   r1   r#   rd   r3   s     r6   r7   Integers._contains   s)    %&&77N5##$$r9   c              #   p   #    [         R                  v   [         R                  n Uv   U* v   US-   nM  7frh   )r   r<   r=   rt   s     r6   rB   Integers.__iter__   s4     ffEEG"HAA s   46c                 "    [         R                  $ r/   r   rU   rF   s    r6   rV   Integers._inf       !!!r9   c                 "    [         R                  $ r/   r   rW   rF   s    r6   rX   Integers._sup       zzr9   c                     U $ r/   rN   rF   s    r6   rG   Integers._boundary   ry   r9   c                      [        [        5      $ r/   rJ   rF   s    r6   rK   Integers._kind   rM   r9   c                 `    [        [        [        U5      U5      [        * U:  U[        :  5      $ r/   )r    r   r   r   r|   s     r6   r~   Integers.as_relational   s%    2eAh?RC!GQV44r9   c                 J    [        [        * [        5      R                  U5      $ r/   ri   r3   s     r6   rl   Integers._eval_is_subset   s    bS"~''..r9   c                 J    [        [        * [        5      R                  U5      $ r/   ro   r3   s     r6   rq   Integers._eval_is_superset   s    bS"~))%00r9   rN   N)rO   rP   rQ   rR   rS   rT   rY   rZ   r7   rB   r[   rV   rX   rG   rK   r~   rl   rq   r\   rN   r9   r6   r   r      sr    < KHM%
 " "    #5/1r9   r   c                   d    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	S r
S rS	rg
)rE      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                 "    [         R                  $ r/   r   rF   s    r6   startReals.start  r   r9   c                 "    [         R                  $ r/   r   rF   s    r6   end	Reals.end  r   r9   c                     gNTrN   rF   s    r6   	left_openReals.left_open      r9   c                     gr   rN   rF   s    r6   
right_openReals.right_open  r   r9   c                 X    U[        [        R                  [        R                  5      :H  $ r/   )r%   r   rU   rW   r3   s     r6   __eq__Reals.__eq__  s    !3!3QZZ@@@r9   c                 d    [        [        [        R                  [        R                  5      5      $ r/   )hashr%   r   rU   rW   rF   s    r6   __hash__Reals.__hash__  s    HQ//<==r9   rN   N)rO   rP   rQ   rR   rS   r[   r   r   r   r   r   r   r\   rN   r9   r6   rE   rE      sb    8 " "      A>r9   rE   c                       \ rS rSrSrS r\" S 5      r\" S 5      r\S 5       r	\S 5       r
\S 5       rS	 rS
 rS r\S 5       rS rS rSrg)ImageSeti#  a  
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                   ^  [        U[        5      (       d  [        S5      eUR                  n[	        U5      [	        U5      :w  a  [        S5      eU Vs/ s H  n[        U5      PM     nn[        S U 5       5      (       d  [        S5      e[        U 4S j[        X25       5       5      (       d  [        SU< SU< 35      eU[        R                  L a  [	        U5      S:X  a  US	   $ [        UR                  5      UR                  R                  -  (       dC  [        S
 U 5       5      nUS:X  a  [        R                   $ US:X  a  [#        UR                  5      $ [$        R&                  " T U/UQ76 $ s  snf )NzFirst argument must be a LambdaIncompatible signaturec              3   B   #    U  H  n[        U[        5      v   M     g 7fr/   )r0   r$   .0ss     r6   	<genexpr>#ImageSet.__new__.<locals>.<genexpr>f  s     4t!:a%%ts   z,Set arguments to ImageSet should of type Setc              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   
_check_sig)r   sgstclss      r6   r   r   i  s!     M8Lfb3>>"))8L    #z
Signature z does not match sets r"   r   c              3   8   #    U  H  oR                   v   M     g 7fr/   )rY   r   s     r6   r   r   p  s     9Dq

D   TF)r0   r   
ValueError	signaturelenr   all	TypeErrorzipr   IdentityFunctionset	variablesexprfree_symbolsr
   EmptySetr'   r   __new__)r   flambdasetsr   r   rY   s   `     r6   r   ImageSet.__new__[  s1   '6**>??%%	y>SY&566%)*TT*4t444JKKMI8LM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   E7c                      U R                   S   $ Nr   argsrF   s    r6   <lambda>ImageSet.<lambda>x      $))A,r9   c                      U R                   SS  $ rh   r   rF   s    r6   r   r   y  s    diimr9   c                 n    U R                   n[        U5      S:X  a  US   $ [        U6 R                  5       $ )Nr"   r   )	base_setsr   r(   flatten)r4   r   s     r6   base_setImageSet.base_set{  s5     ~~t9>7Nt$,,..r9   c                 &    [        U R                  6 $ r/   )r(   r   rF   s    r6   	base_psetImageSet.base_pset  s    4>>**r9   c                    ^  UR                   (       a  g[        U[        5      (       aC  UR                  n[	        U5      [	        U5      :w  a  g[        U 4S j[        X5       5       5      $ g)NTFc              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr/   r   )r   tspsr   s      r6   r   &ImageSet._check_sig.<locals>.<genexpr>  s!     M<L&"s~~b--<Lr   )	is_symbolr0   r(   r   r   r   r   )r   sig_iset_ir   s   `   r6   r   ImageSet._check_sig  sQ    ??z**::D5zSY&MC<LMMM r9   c              #      #    [        5       nU R                   H.  nU R                  " U6 nX1;   a  M  UR                  U5        Uv   M0     g 7fr/   )r   r   lamdaadd)r4   already_seenru   vals       r6   rB   ImageSet.__iter__  sC     uA**a.C"  %	  s   A
Ac                 F    [        U R                  R                  5      S:  $ rh   )r   r   r   rF   s    r6   _is_multivariateImageSet._is_multivariate  s    4::''(1,,r9   c                 B   SSK Jn  S nS n[        U5      nU R                  R                  nU R                  R
                  nU R                  R                  nU R                  nU V	s0 s H  o[        U	R                  5      _M     n
n	U V	s/ s H  oR                  U
5      PM     nn	UR                  U
5      nUR                  U
5      n/ nU" XQ5       H+  nUSL a  [        R                  s  $ UR                  U5        M-     U" Xh5      nUc  g S U 5       n[        U5      [        [        R                   U[        5       5      -  n[#        U5      nU V	s/ s H  oU	   PM	     nn	U" XU5      nUc  g [$        ['        UR(                  5         $ s  sn	f s  sn	f s  sn	f )Nr   )_solveset_multic                 .   [        [        X5      5      n0 nU Hx  u  pEUR                  (       a  XSU'   M  UR                  (       aK  UR                  n[        U5      [        U5      :w  a  [        S5      eUR                  [        XF5      5        Mx    g   U$ )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          r6   get_symsetmap)ImageSet._contains.<locals>.get_symsetmap  s{    Y23EI!&==%-cN++#==D3x3t9,()ABBLLS0   "' r9   c              3     #    X4/nU Hv  u  p4[        U[        5      (       d  [        X45      v   M)  [        U[        5      (       a  [        U5      [        U5      :w  a  Sv     gUR	                  [        X45      5        Mx     g7f)z:Find the equations relating symbols in expr and candidate.FN)r0   r   r   r   r  r   )r   	candidater  ecs        r6   get_equations)ImageSet._contains.<locals>.get_equations  sf     &'E!!U++Q(N#Au--Q3q61AKLLQ+ s   BBFc              3   8   #    U  H  oR                   v   M     g 7fr/   )r   )r   eqs     r6   r   %ImageSet._contains.<locals>.<genexpr>  s     59R9r   )sympy.solvers.solvesetr  r   r   r   r   r   r   r   namesubsr   r1   appendr   r   uniontupler#   r	   rY   )r4   r5   r  r  r  r   r
  r   r   vrep	equationsr  r	  symsssolnsets                   r6   r7   ImageSet._contains  sn   :	(
	, zzjj""JJ((	NN	 *33A%-3*34)QVVC[)	4hhsmyy~ 	,BU{wwR 	 - "#1	 695	NVCIIuce%DD	 )$	+459aq\9	5!)	B?9W--.//; 440 6s   *FFFc                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr/   )rT   r   s     r6   r   'ImageSet.is_iterable.<locals>.<genexpr>  s     9.Q==.r   )r   r   rF   s    r6   rT   ImageSet.is_iterable  s    9$..999r9   c                   ^ SSK Jn  U R                  mTR                  n[	        U5      S:X  ac  US   R
                  (       aO  [        TR                  [        5      (       a0  U R                  S   nU" U5      R                  T5      R                  $ [        S U R                   5       5      (       a"  [        U4S j[        U R                  6  5       6 $ U $ )Nr   )SetExprr"   c              3   8   #    U  H  oR                   v   M     g 7fr/   is_FiniteSetr   s     r6   r    ImageSet.doit.<locals>.<genexpr>  s     6~!~~~r   c              3   .   >#    U  H
  nT" U6 v   M     g 7fr/   rN   )r   afs     r6   r   r+     s     G.Fq!u.Fs   )sympy.sets.setexprr'  r   r   r   r   r0   r   r   r   
_eval_funcr   r   r'   r   )r4   hintsr'  r
  r   r.  s        @r6   doitImageSet.doit  s    .JJkks8q=SV--*QVVT2J2J~~a(H8$//26666t~~666Ggt~~.FGHHr9   c                 T    [        U R                  R                  R                  5      $ r/   )r)   r   r   kindrF   s    r6   rK   ImageSet._kind  s    tzz++,,r9   rN   N)rO   rP   rQ   rR   rS   r   r[   r   r   r   r   classmethodr   rB   r   r7   rT   r2  rK   r\   rN   r9   r6   r   r   #  s    6n2: ./E34I/ / + +  $-I0V : :	-r9   r   c                       \ rS rSrSrS r\" S 5      r\" S 5      r\" S 5      r	\S 5       r
S rS	 rS
 r\S 5       rS r\S 5       r\S 5       r\S 5       rS rS r\S 5       r\S 5       r\S 5       rS rSrg)rj   i  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                    [        U5      S:X  a)  [        US   [        5      (       a  [        SUS   -  5      e[	        U6 nUR
                  S:X  a  [        S5      eUR                  =(       d    SUR                  UR
                  =(       d    SpTn / nX4U4 H  n[        U5      nU[        R                  [        R                  4;   d*  UR                  [        5      (       a#  UR                  S:w  a  UR!                  U5        Mo  UR"                  (       d"  UR$                  (       a  [        S5      e[        eUR!                  U5        M     Uu  p4nSn[)        S X4U4 5       5      (       a  XC-
  n	X-  n
U
R*                  (       ab  U	S:X  a  S	nGOw[-        U
5      n
X:U-  -   nU	R*                  (       a  X-
  R.                  (       a  X-  nGO;X-  S-
  R.                  (       a  X-  nGOU
R0                  (       a  S	nGO
UnGOUR$                  (       a  XTU-
  -  nU[        R2                  L d  US::  a  S	nOUR"                  (       aI  UR$                  (       a8  [5        U5      S:w  a)  [        ['        S
US:  a  S-  5      5      eS-  5      5      eUnOuUR$                  nU(       a&  US:  a  [        R6                  O[        R8                  n[;        XC-
  U-  5      n
U
S::  a  S	nO#U(       a  [        R6                  nX5-   nOX:U-  -   nU(       a!  [        R<                  =p;[        R6                  n[>        R@                  " XWU5      $ ! [         a    [        ['        S5      5      ef = f)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   J   #    U  H  oR                  [        5      v   M     g 7fr/   )hasr   r   ru   s     r6   r    Range.__new__.<locals>.<genexpr>|  s     :&9uuV}}&9s   !#Tz7
                    Step size must be %s in this case.)!r   r0   r?   r   slicestepr   r   stopr   r   rU   rW   r;  r   rd   r  
is_Integeris_infiniter*   anyis_Rationalr   is_negativeis_extended_negativeNaNabsr=   r>   r   r<   r   r   )r   r   slcr   rA  r@  okwnulldifrA   r   spanoosteps                 r6   r   Range.__new__Z  s   t9>$q'5))?$q'IK K Tl88q=/00IINCHHchhm!T	B4(AJ++QZZ88f!,,%*?IIaL}}()GHH$$IIaL )  T:uD&9:::,CA}}!8DaAD&.CJ33KCHqL55KC''&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lfn&& E55D}}Sd33g  	Z )   	s   B=M	 	M(c                      U R                   S   $ r   r   rF   s    r6   r   Range.<lambda>  r   r9   c                      U R                   S   $ rh   r   rF   s    r6   r   rS        1r9   c                      U R                   S   $ )Nr;   r   rF   s    r6   r   rS    rU  r9   c                    U R                  [        5      (       ac  U R                  U R                  -
  U R                  -  nUR
                  (       a!  [        S U R                   5       5      (       d  [        S5      eU R                  U R                  :X  a  U $ U R                  U R                  U R                  -
  U R                  U R                  -
  U R                  * 5      $ )zReturn an equivalent Range in the opposite order.

Examples
========

>>> from sympy import Range
>>> Range(10).reversed
Range(9, -1, -1)
c              3   ^   #    U  H#  oR                   =(       d    UR                  v   M%     g 7fr/   rd   rC  r<  s     r6   r   !Range.reversed.<locals>.<genexpr>  "      5F;DaLL1AMM19   +-!invalid method for symbolic range)
r;  r   rA  r   r@  is_extended_positiver   r   r   func)r4   rA   s     r6   reversedRange.reversed  s     88FTZZ'2A)) 5F;?995F 2F 2F !DEE::"KyyII		!4::		#9DII:G 	Gr9   c                      [        [        5      $ r/   rJ   rF   s    r6   rK   Range._kind  rM   r9   c                 (   U R                   U R                  :X  a  [        R                  $ UR                  (       a  [        R                  $ UR
                  (       d  [        UR
                     $ U R                  [        5      (       aZ  U R                  U R                   -
  U R                  -  nUR                  (       a!  [        S U R                   5       5      (       d  g OU R                  nU R                   R                  (       a  U R                   nO8U R                  R                  (       a  U R                  nO[        R                  $ US:X  a  [!        XS   5      $ X1-
  U R                  -  nU[        R"                  :X  ai  U R                  [        5      (       a+  [%        S5      nU R'                  U5      R)                  XQ5      $ [+        XR,                  :  XR.                  :*  5      $ UR0                  (       a  [        R                  $ g )Nc              3   ^   #    U  H#  oR                   =(       d    UR                  v   M%     g 7fr/   rY  r<  s     r6   r   "Range._contains.<locals>.<genexpr>  r[  r\  r"   r   ru   )r   rA  r   r1   rC  rd   r#   r;  r   r@  r^  r   r   size	is_finitere   r   r<   r   r~   r  r    r{   suprB  )r4   r5   rA   refresr@   s         r6   r7   Range._contains  sw   ::"77N77Nu''((88FTZZ'2A)) 5F;?995F 2F 2F2F 		A::**CYY  ))C66M6e!W%%{dii'!&&=xx#J))!,11!;;u(%88*;<<^^77Nr9   c              #   @  #    U R                   nUR                  [        R                  5      (       d@  UR                  [        R                  5      (       d  UR
                  (       d  [        S5      eU R                  [        R                  [        R                  4;   a  [        S5      eU R                  U R                  :w  aW  U R                  nUR                  (       a   Uv   X R                  -  nM  [        U5       H  nUv   X R                  -  nM     g g 7f)Nz"Cannot iterate over symbolic Rangez-Cannot iterate over Range with infinite start)rg  r;  r   rW   rU   rB  r   r   rA  rC  r@  r?   )r4   rA   ru   _s       r6   rB   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                    U R                   U R                  -
  nXR                  -  nUR                  [        R
                  5      (       d6  UR                  [        R                  5      (       d  UR                  (       d  gU R                  [        R                  [        R
                  4;   a  gUR                  (       a!  [        S U R                   5       5      (       d  gg)NFc              3   8   #    U  H  oR                   v   M     g 7fr/   rd   r<  s     r6   r   $Range.is_iterable.<locals>.<genexpr>   s     1R	1,,	r   T)rA  r   r@  r;  r   rW   rU   rB  is_extended_nonnegativer   r   r4   rN  rA   s      r6   rT   Range.is_iterable  s     ii$**$		Majj!!QUU1+=+=%>%>!,,::!,,ajj99))c1R		1R.R.Rr9   c                 l    U R                   nU[        R                  L a  [        S5      e[	        U5      $ )Nz0Use .size to get the length of an infinite Range)rg  r   rW   r   int)r4   rvs     r6   __len__Range.__len__  s,    YYOPP2wr9   c                    U R                   U R                  :X  a  [        R                  $ U R                  U R                   -
  nXR                  -  nUR
                  (       a  [        R                  $ UR                  (       a5  [        S U R                   5       5      (       a  [        [        U5      5      $ [        S5      e)Nc              3   8   #    U  H  oR                   v   M     g 7fr/   rr  r<  s     r6   r   Range.size.<locals>.<genexpr>  s     -NIqllIr   !Invalid method for symbolic Range)r   rA  r   r<   r@  rC  rW   rt  r   r   rI  r   r   ru  s      r6   rg  
Range.size
  s    ::"66Mii$**$		M==::%%#-NDII-N*N*NuQx= <==r9   c                     U R                   R                  (       a  U R                  R                  (       a  gU R                  R                  $ r   )r   rd   rA  rg  rh  rF   s    r6   rZ   Range.is_finite_set  s.    ::  TYY%9%9yy"""r9   c                 P     U R                   R                  $ ! [         a     g f = fr/   )rg  is_zeror   rF   s    r6   rY   Range.is_empty  s)    	99$$$ 		s    
%%c                 ~    [        U R                  U R                  5      nUc  [        S5      e[	        U5      (       + $ )Nz#cannot tell if Range is null or not)r   r   rA  r   bool)r4   bs     r6   __bool__Range.__bool__#  s5     $**dii(9BCC7{r9   c                 
   SnSnSnSn[        U[        5      (       Ga_  U R                  R                  (       a  U R                  U R
                  :X  a  [        S5      $ UR                  U R                  5      u  pgn[        Xv-
  U-  5      n	U	S::  a  [        S5      $ XiU-  -   n
X-
  nXR                  -  n[        X   X   U-   U5      $ UR                  nUR
                  nUR                  S:X  a  [        U5      eUR                  =(       d    SnXR                  -  nU R                  R                  (       a&  U R
                  R                  (       a  [        U5      eU R
                  R                  (       a+  U R                  Uc  UOU* S-   Uc  UOU* U2   R                  $ Uc  Uc3  US:  a  [        U S   U R                  U5      $ US:  a  [        U5      eU $ US:  a1  US:  a  [        U S   X   U5      $ [        U R                  X   U5      $ US:X  a  US:  a  [        S5      $ [        U5      eUS:X  a  US:  a  [        U5      e[        U5      e[        U5      eUS:  a  Uc8  US:  a  [        X   U R                  U5      $ [        X   U R
                  U5      $ US:  a  [        X   X   U5      $ US:X  a  US:  a  [        U5      e[        S5      $ US:  a  [        U5      eg US:X  as  Uc$  US:  a  [        U5      eUS:  a  [        U5      eU $ US:  a;  US:  a  [        U5      eUS:X  a  [        U R                  X   U5      $ [        S5      $ [        U5      eUS:  a  [        U5      eg U R                  U R
                  :X  a  [        S5      e[        S	 U R                   5       5      (       a5  U R
                  U R                  -
  U R                  -  R                   (       d  [        S
5      eUS:X  a2  U R                  R                  (       a  [        U5      eU R                  $ US:X  a?  U R
                  R                  (       a  [        U5      eU R
                  U R                  -
  $ U R                  n	US:  a  U R
                  OU R                  XR                  -  -   nUR                  (       a  [        U5      eXR                  -
  U R                  -  n[#        UR                  [%        UR&                  X-
  R&                  /5      /5      nU(       a  U$ Uc  [        S
5      e[        S5      e)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   `   #    U  H$  nUR                   =(       d    UR                  v   M&     g 7fr/   rY  r<  s     r6   r   $Range.__getitem__.<locals>.<genexpr>  s'      (& 55&s   ,.r  )r0   r?  rg  rh  r   rA  rj   indicesr   r@  r   rC  r`  
IndexErrorr   r   r^  r
   r   r   )r4   ru   ooslicezerostepinfinite	ambiguousr   rA  r@  rA   canonical_stopr   ssry  r   rels                   r6   __getitem__Range.__getitem__,  s   D.F%	ayy""::* 8O$%IIdii$8!TT\4/06 8O!&4$+))^T[$)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#(TZ#DD!8#(8O",W"55!8",W"55",W"55(11QY|!8#(djj"#EE#(dii#DD$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#(TZ#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'9AE;Q;Q&RSU VC	{ !DEE788r9   c                 f   U (       d  [         R                  R                  $ U R                  [        5      (       a  [        S U R                   5       5      (       a  U R                  U R                  -
  nU R                  R                  (       a  UR                  (       a  U R                  $ U R                  R                  (       a*  UR                  (       a  U R                  U R                  -
  $ [        S5      eU R                  S:  a  U R                  $ U R                  U R                  -
  $ )Nc              3   ^   #    U  H#  oR                   =(       d    UR                  v   M%     g 7fr/   rY  r<  s     r6   r   Range._inf.<locals>.<genexpr>       D)Q<<01==0)r\  r]  r   )r   r   r{   r;  r   r   r   rA  r   r@  rc   rF  r   r4   rN  s     r6   rV   
Range._inf  s    ::>>!88FD$))DDDii$**,99((S__::%YY**s99tyy00@AA99q=::99tyy((r9   c                 f   U (       d  [         R                  R                  $ U R                  [        5      (       a  [        S U R                   5       5      (       a  U R                  U R                  -
  nU R                  R                  (       a*  UR                  (       a  U R                  U R                  -
  $ U R                  R                  (       a  UR                  (       a  U R                  $ [        S5      eU R                  S:  a  U R                  U R                  -
  $ U R                  $ )Nc              3   ^   #    U  H#  oR                   =(       d    UR                  v   M%     g 7fr/   rY  r<  s     r6   r   Range._sup.<locals>.<genexpr>  r  r\  r]  r   )r   r   ri  r;  r   r   r   rA  r   r@  rc   rF  r   r  s     r6   rX   
Range._sup  s    ::>>!88FD$))DDDii$**,99((S__99tyy00YY**s::%@AA99q=99tyy((::r9   c                     U $ r/   rN   rF   s    r6   rG   Range._boundary  ry   r9   c           	         U R                   R                  (       a4  U R                  R                  (       a   eU R                  R                   nOU R                   nU R                  n[        [        X-
  U5      S5      n[        [        [        US5      S5      [        [        US5      S5      5      nU R                  U R                   -
  U R                  -  nUS:X  a  [        R                  R                  U5      $ US:X  a  [        [        X5      U5      $  U R                  U R                  prUb;  [        UR                  (       a  X:  OX:  WR                  (       a  X:  OX:*  5      nOU R                   U R                  U R                  -
  pr[        [        U R                  S:  UR                  (       a  X:  OX:  UR                  (       a  X:  OX:*  5      [        U R                  S:*  UR                  (       a  X:  OX:*  UR                  (       a  X:  OX:  5      5      n[        XEU5      $ ! [         a    Sn GNf = f)z<Rewrite a Range in terms of equalities and logic operators. r   r"   Nr>  )r   rC  rA  r`  r@  r   r   r    r   r   r~   r{   ri  r   r!   )	r4   r}   r-  r@  in_seqintsrA   r  
range_conds	            r6   r~   Range.as_relational  s   ::!!yy,,,,##A

AyyCt$a(2c!Qi#RD!a%89YY#TYY.6::++A..6r!x&&	88TXXq =AFAF4J ::tyy4994qDIINQ]]AEAF4DIIOammQUAF45J
 6,,  	A	s   H8 8IIrN   N)rO   rP   rQ   rR   rS   r   r[   r   rA  r@  r`  rK   r7   rB   rT   rz  rg  rZ   rY   r  r  rV   rX   rG   r~   r\   rN   r9   r6   rj   rj     s    PdM4^ ./E-.D-.DG G(#B#" 
 
 	> 	> # #
  J9X ) )      -r9   rj   c                 X    [        U R                  U R                  U R                  5      $ r/   )rj   r   rA  r@  )rs    r6   r   r     s    E!''166166$Br9   c           	      v   SSK Jn  U R                  (       Ga  U R                  nUS[        R
                  -  :  a  US[        R
                  -  :X  a  U R                  (       az  U R                  (       ai  U" U R                  5      n[        [        SU[        R
                  -  SS5      [        U[        R
                  -  S[        R
                  -  SS5      5      $ [        SS[        R
                  -  SS5      $ U" U R                  5      U" U R                  5      pTUb  Uc  [        S5      eU[        R
                  -  nU[        R
                  -  nXg:  aW  [        [        [        R                  USU R                  5      [        US[        R
                  -  U R                  S5      5      $ [        XgU R                  U R                  5      $ U R                  (       aK  / nU  H;  n	U" U	5      nUc  [        S5      eUR                  U[        R
                  -  5        M=     [!        U6 $ U R"                  (       a,  [        U R$                   V
s/ s H  n
['        U
5      PM     sn
6 $ U R)                  [        R*                  5      (       a  [        S[-        U 5      -  5      e[/        S	U -  5      es  sn
f )
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_coeffr;   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   NotImplementedErrorr<   r*  r  r'   is_Unionr   normalize_theta_setrk   rE   typer   )thetar  interval_lenkk_startk_end	new_startnew_end	new_thetaelementintervals              r6   r  r    s8   L C}}1QTT6!qv%%//e>N>Nekk*Xa144= 144144t<> >Aqvud33"5;;/5991E?em% ': ; ;ADDL	*!&&'5%:J:JK!)QqttVU__dKM M IAQAQRR				G'"Ay) +M N N   144(  )$$	UZZPZ*84ZPQQ		!	!! #026u+#> ? 	? 0E:;; Qs   J6c                       \ rS rSrSrSrSS jr\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
 r\S 5       rS rSrg)ComplexRegioniV  aU	  
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                 X    USL a  [        U5      $ USL a  [        U5      $ [        S5      e)NFTz$polar should be either True or False)CartesianComplexRegionPolarComplexRegionr   )r   r   polars      r6   r   ComplexRegion.__new__  s2    E>)$//d]%d++CDDr9   c                      U R                   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   rF   s    r6   r   ComplexRegion.sets  s    ( yy|r9   c                     U R                   R                  (       a  SnXR                   4-   nU$ U R                   R                  nU$ )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)))

rN   )r   r  r   )r4   psetss     r6   r  ComplexRegion.psets  s?    ( 99""EYYM)E  IINNEr9   c                 |    / nU R                    H!  nUR                  UR                  S   5        M#     [        U6 nU$ )a  
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   r  r  r   r&   )r4   
a_intervalr  s      r6   r  ComplexRegion.a_interval  ?    , 
zzGgll1o. " J'
r9   c                 |    / nU R                    H!  nUR                  UR                  S   5        M#     [        U6 nU$ )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"   r  )r4   
b_intervalr  s      r6   r  ComplexRegion.b_interval  r  r9   c                 .    U R                   R                  $ )a  
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   _measurerF   s    r6   r  ComplexRegion._measure  s    & yy!!!r9   c                 4    U R                   S   R                  $ r   )r   r5  rF   s    r6   rK   ComplexRegion._kind.  s    yy|   r9   c                     UR                  [        R                  5      (       d  [        S5      e[	        U[        S5      -  5      $ )z
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   )rk   r   rE   r   r  r'   )r   r   s     r6   	from_realComplexRegion.from_real1  s7     ~~agg&&EFF%dYq\&9::r9   c                   ^^^^ SSK JnJn  [        U[        5      nU(       a  [        U5      S:w  a  [        S5      e[        U[        [        45      (       d  [        R                  $ U R                  (       dC  U(       a  UOUR                  5       u  mm[        [        UU4S jU R                   5       5         $ U R                  (       a  UR                  (       a#  [        [        S U R                   5       5         $ U(       a  Uu  mmOU" U5      U" U5      smmTR                   (       aO  TR"                  (       a=  TS[        R$                  -  -  m[        [        UU4S jU R                   5       5         $ g g g )Nr   )argAbsr;   zexpecting Tuple of length 2c              3      >#    U  HJ  n[        UR                  S    R                  T5      UR                  S   R                  T5      /5      v   ML     g7fr   r"   Nr   r   r7   )r   psetimres     r6   r   *ComplexRegion._contains.<locals>.<genexpr>R  sW       ( 'D !*		!&&r*		!&&r*+, !- !- '   AAc              3   z   #    U  H1  nUR                   S    R                  [        R                  5      v   M3     g7f)r   N)r   r7   r   r<   )r   r  s     r6   r   r  [  s1      $, * %)IIaL$:$:166$B$B *s   9;c              3      >#    U  HJ  n[        UR                  S    R                  T5      UR                  S   R                  T5      /5      v   ML     g7fr  r  )r   r  r  r  s     r6   r   r  d  sW      $, !+ %.IIaL**1-IIaL**51/3 %4 %4 !+r  )sympy.functionsr  r  r0   r   r   r   r   r   r1   r  as_real_imagr#   r
   r  r  is_real	is_numberr  )	r4   r5   r  r  isTupler  r  r  r  s	        @@@@r6   r7   ComplexRegion._containsD  s2   ,UE*s5zQ:;; %$//77N zz%U5+=+=+?FBx  ( !JJ ( ( ) ) ZZ}}8 $, $

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

$, , - - "1} r9   rN   N)F)rO   rP   rQ   rR   rS   is_ComplexRegionr   r[   r   r  r  r  r  rK   r7  r  r7   r\   rN   r9   r6   r  r  V  s    LZ E  *  4  8  8 " "(! ; ;$#-r9   r  c                   @    \ rS rSrSrSr\" S\S9rS r	\
S 5       rSrg	)
r  ij  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                    U[         R                  [         R                  -  :X  a  [         R                  $ [        S UR                   5       5      (       at  [        UR                  5      S:X  a[  / nUR                  S    H>  nUR                  S    H(  nUR                  U[         R                  U-  -   5        M*     M@     [        U6 $ [        R                  " X5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr/   r)  )r   _as     r6   r   1CartesianComplexRegion.__new__.<locals>.<genexpr>  s     32r   r;   r   r"   )r   rE   	Complexesr   r   r   r  ImaginaryUnitr'   r$   r   )r   r   complex_numr}   ys        r6   r   CartesianComplexRegion.__new__  s    177177?";;3333TYY19L KYYq\1A&&q1??1+<'<= & " k**;;s))r9   c                 J    U R                   u  pU[        R                  U-  -   $ r/   )r   r   r  )r4   r}   r  s      r6   r   CartesianComplexRegion.expr  s!    ~~1??1$$$r9   rN   NrO   rP   rQ   rR   rS   r  r   r   r   r   r[   r   r\   rN   r9   r6   r  r  j  s3    . EE*I** % %r9   r  c                   @    \ rS rSrSrSr\" S\S9rS r	\
S 5       rSrg	)
r  i  a  
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                 Z   / nUR                   (       d%  UR                   H  nUR                  U5        M     OUR                  U5        [        U5       H6  u  p4[	        UR                  S   [        UR                  S   5      5      X#'   M8     [        U6 n[        R                  " X5      $ )Nr   r"   )	r  r   r  	enumerater(   r  r&   r$   r   )r   r   new_setsr  r  s        r6   r   PolarComplexRegion.__new__  s    !!YY"  OOD!h'DA$QVVAY%8%CEHK ( h{{3%%r9   c                 t    U R                   u  pU[        U5      [        R                  [	        U5      -  -   -  $ r/   )r   r   r   r  r   )r4   r  r  s      r6   r   PolarComplexRegion.expr  s.    >>#e*qs5z99::r9   rN   Nr  rN   r9   r6   r  r    s3    4 E
.I&" ; ;r9   r  c                   6    \ rS rSrSrSrSr\S 5       rS r	Sr
g)r  i  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    [        [        R                  [        R                  5      $ r/   )r(   r   rE   rF   s    r6   r   Complexes.sets  s    !''177++r9   c                 .    [         R                  " U 5      $ r/   )r$   r   r  s    r6   r   Complexes.__new__  s    {{3r9   rN   N)rO   rP   rQ   rR   rS   rY   rZ   r[   r   r   r\   rN   r9   r6   r  r    s,    ( HM , , r9   r  N)H	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   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,   r_   r   r   rE   r   rj   r?   r  r  r  r  r  rN   r9   r6   <module>r     s     " '   & ; ;  # 4 4 + & - 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 &)  r9   