
    \h2=                      S SK Jr  S SKJrJrJrJr  S SKJr  S SK	J
r
  S SKJrJr  S SKrS SKJrJrJr  S SKJr  S S	KJrJr  S S
KJr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$J%r%J&r&  S SK'J(r(J)r)  S SK*J+r+  S SK,J-r-  S SK.J/r/J0r0J1r1  S SK2J3r3J4r4  S SK5J6r6  S SK7J8r8J9r9J:r:J;r;  S SK<J=r=J>r>J?r?  S SK@JArAJBrB  S SKCJDrDJErE  S SKFJGrGJHrHJIrIJJrJJKrKJLrL  S SKMJNrN  S SKOJPrP  S SKQJRrRJSrSJTrTJUrUJVrV  S SKWJXrXJYrY  S SKZJ[r[J\r\  S SK]J^r^  \
" S  S!\4R                  \4R                  \4R                  S"\4R                  \4R                  \4R                  05      r_\ " S# S$\\5      5       r` " S% S&\`5      ra " S' S(\`5      rb " S) S*\`\+5      rc " S+ S,\`\+5      rd " S- S.\`5      re " S/ S0\`\3S19rf " S2 S3\`\3S19rg " S4 S5\`5      rhS6 \?\i'   S7 \?\j'    " S8 S9\`5      rk " S: S;\`5      rlS< rmS= rnS> roS? rpS@ rqSA rrSB rsSC rtSD ruSE rvSF rwSG rx " SH SI\5      ryg)J    )annotations)AnyCallableTYPE_CHECKINGoverload)reduce)defaultdict)MappingIterableN)KindUndefinedKind
NumberKind)Basic)Tuple	TupleKind)sympify_method_argssympify_return)
EvalfMixin)Expr)Lambda)	FuzzyBool
fuzzy_boolfuzzy_or	fuzzy_and	fuzzy_not)FloatInteger)	LatticeOp)global_parameters)EqNeis_lt)	SingletonS)ordered)symbolsSymbolDummyuniquely_named_symbol)_sympifysympify_sympy_converter)explog)MaxMin)AndOrNotXortruefalse)
deprecated)sympy_deprecation_warning)iproductsift
roundrobiniterablesubsets)	func_name
filldedent)mpimpf)prec_to_dpsc                     g N rE       G/var/www/auris/envauris/lib/python3.13/site-packages/sympy/sets/sets.py<lambda>rH   (   s    $rF   TFc                     \ rS rSr% SrSrS\S'   SrSrSr	Sr
SrSrSrSrS\S	'   SrS\S
'   SrS\S'   SrSrS\S'   SrS\S'   \\" SSSS9S 5       5       r\(       ar  SLS jr\SMSNS jj5       r\SMSOS jj5       r\SPS j5       r\SMSQS jj5       r\SMSRS jj5       r\SSS j5       r SM     STS jjrSUS jr   SV           SWS jjr\r\S 5       rS 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* 5       r,S+ r-S, r.S- r/S. r0S/ r1S0 r2S1 r3S2 r4S3 r5S4 r6S5 r7S6 r8\S7 5       r9\S8 5       r:\S9 5       r;\S: 5       r<\S; 5       r=\S< 5       r>\S= 5       r?\S> 5       r@\S? 5       rAS@ rBSA rC\D" SB/\E5      SC 5       rF\D" SB/\E5      SD 5       rG\D" SB/\E5      SE 5       rH\D" SB/\E5      SF 5       rI\D" SB/\E5      SG 5       rJ\D" SH\K4/\E5      SI 5       rL\D" SB/\E5      SJ 5       rMSK rNSrOg)XSet/   a  
The base class for any kind of set.

Explanation
===========

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

Real intervals are represented by the :class:`Interval` class and unions of
sets by the :class:`Union` class. The empty set is represented by the
:class:`EmptySet` class and available as a singleton as ``S.EmptySet``.
rE   z	tuple[()]	__slots__FNr   is_Intersectionis_UniversalSetis_Complementis_emptyis_finite_set
        The is_EmptySet attribute of Set objects is deprecated.
        Use 's is S.EmptySet" or 's.is_empty' instead.
        1.5deprecated-is-emptysetdeprecated_since_versionactive_deprecations_targetc                    g rD   rE   selfs    rG   is_EmptySetSet.is_EmptySetQ        rF   c                    g rD   rE   )clsargss     rG   __new__Set.__new___   s    rF   c                    g rD   rE   rZ   arg1arg2s      rG   subsSet.subsb   s    _brF   c                    g rD   rE   rZ   re   rf   kwargss       rG   rg   rh   d   s    vyrF   c                    g rD   rE   rd   s      rG   rg   rh   f   s    ILrF   c                    g rD   rE   rj   s       rG   rg   rh   h   s    rurF   c                    g rD   rE   rj   s       rG   rg   rh   j   s    z}rF   c                    g rD   rE   rj   s       rG   rg   rh   l   s    ^arF   c                    g rD   rE   rj   s       rG   rg   rh   o   s    rF   c                     erD   rE   )rZ   rk   s     rG   simplifySet.simplifys   s    5rF   c                    g rD   rE   )rZ   nrg   maxnchopstrictquadverboses           rG   evalf	Set.evalfv   s     rF   c                     U R                   nUR                  (       d   eUR                  5       nU$ ! [        [        [
        [        4 a    [        R                  n U$ f = f)z/
Return infimum (if possible) else S.Infinity.
)	infis_comparabler{   NotImplementedErrorAttributeErrorAssertionError
ValueErrorr$   Infinity)exprinfimums     rG   _infimum_keySet._infimum_key}   s\    
	!hhG((((mmoG  $
< 	!jjG	!s   /3 *A! A!c                    [        X5      $ )ah  
Returns the union of ``self`` and ``other``.

Examples
========

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

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

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

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

)UnionrZ   others     rG   union	Set.union   s    2 T!!rF   c                    [        X5      $ )a`  
Returns the intersection of 'self' and 'other'.

Examples
========

>>> from sympy import Interval

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

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

Intersectionr   s     rG   	intersectSet.intersect   s    & D((rF   c                $    U R                  U5      $ )z
Alias for :meth:`intersect()`
r   r   s     rG   intersectionSet.intersection        ~~e$$rF   c                F    U R                  U5      [        R                  :H  $ )a  
Returns True if ``self`` and ``other`` are disjoint.

Examples
========

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

References
==========

.. [1] https://en.wikipedia.org/wiki/Disjoint_sets
)r   r$   EmptySetr   s     rG   is_disjointSet.is_disjoint   s    $ ~~e$

22rF   c                $    U R                  U5      $ )z!
Alias for :meth:`is_disjoint()`
)r   r   s     rG   
isdisjointSet.isdisjoint        &&rF   c                    [        X5      $ )a  
The complement of 'self' w.r.t the given universe.

Examples
========

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

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


ComplementrZ   universes     rG   
complementSet.complement   s     ())rF   c           	     d  ^ ^ [        T [        5      (       a  [        U[        5      (       a  [        T R                  5      [        UR                  5      :w  a  U$ / n[	        [        T R                  UR                  5      5      n[        [        U5      5       H/  mU4S j[        U5       5       nUR                  [        U6 5        M1     [        U6 $ [        U[        5      (       aE  [        T [        [        45      (       a)  [        UT R                  [        R                  5      5      $ g [        U[        5      (       a  [        U 4S jUR                    5       6 $ [        U["        5      (       a/  [#        UR                   S   [        UR                   S   T 5      SS9$ U[        R$                  L a  [        R$                  $ [        U[        5      (       aU  ['        UU 4S j5      n[        [        US   6 US    (       a  [#        [        US    6 T SS95      $ [        R$                  5      $ g )Nc              3  F   >#    U  H  u  nu  p#UT:w  a  UOX2-
  v   M     g 7frD   rE   ).0isoru   s       rG   	<genexpr>"Set._complement.<locals>.<genexpr>   s&     O>NFQQ!V,>N   !c              3  ,   >#    U  H	  oT-
  v   M     g 7frD   rE   )r   r   rZ   s     rG   r   r     s     8Zt8Zs   r      Fevaluatec                8   > [        TR                  U 5      5      $ rD   r   contains)xrZ   s    rG   rH   !Set._complement.<locals>.<lambda>
  s    :dmmA6F+GrF   )
isinstance
ProductSetlensetslistziprange	enumerateappendr   Interval	FiniteSetr   r   r$   Realsr`   r   r   r:   )rZ   r   overlapspairsr   siftedru   s   `     @rG   _complementSet._complement   s   dJ''Juj,I,I499~UZZ0 HTYY

34E3u:&Oi>NO
D 12 ' (##x(($9 566#E4??177+CDD 7 u%%8UZZ899z**ejjmU5::a=$-GRWXXajj ::y))%!GHFVE]4$< 9vd|5teL1 1%&ZZ1 1 *rF   c                    [        X5      $ )a  
Returns symmetric difference of ``self`` and ``other``.

Examples
========

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

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

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

SymmetricDifferencer   s     rG   symmetric_differenceSet.symmetric_difference  s    , #4//rF   c                >    [        [        X5      [        X5      5      $ rD   )r   r   r   s     rG   _symmetric_differenceSet._symmetric_difference(  s    Z,j.EFFrF   c                    U R                   $ )z
The infimum of ``self``.

Examples
========

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

)_infrY   s    rG   r~   Set.inf+       yyrF   c                    [        SU -  5      e)Nz	(%s)._infr   rY   s    rG   r   Set._inf<      !+"455rF   c                    U R                   $ )z
The supremum of ``self``.

Examples
========

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

)_suprY   s    rG   supSet.sup@  r   rF   c                    [        SU -  5      e)Nz	(%s)._supr   rY   s    rG   r   Set._supQ  r   rF   c                    SSK Jn  [        USS9nU R                  U5      n[	        X25      (       a  U$ Uc  U" XSS9$ [
        U   nUc  U$ U$ )a0  
Returns a SymPy value indicating whether ``other`` is contained
in ``self``: ``true`` if it is, ``false`` if it is not, else
an unevaluated ``Contains`` expression (or, as in the case of
ConditionSet and a union of FiniteSet/Intervals, an expression
indicating the conditions for containment).

Examples
========

>>> from sympy import Interval, S
>>> from sympy.abc import x

>>> Interval(0, 1).contains(0.5)
True

As a shortcut it is possible to use the ``in`` operator, but that
will raise an error unless an affirmative true or false is not
obtained.

>>> Interval(0, 1).contains(x)
(0 <= x) & (x <= 1)
>>> x in Interval(0, 1)
Traceback (most recent call last):
...
TypeError: did not evaluate to a bool: None

The result of 'in' is a bool, not a SymPy value

>>> 1 in Interval(0, 2)
True
>>> _ is S.true
False
r   )ContainsT)rx   Fr   )r   r   r+   	_containsr   tfn)rZ   r   r   cbs        rG   r   Set.containsU  s\    F 	'd+NN5!a""H9E%88F9HrF   c                D    [        [        U 5      R                   S35      e)a  Test if ``other`` is an element of the set ``self``.

This is an internal method that is expected to be overridden by
subclasses of ``Set`` and will be called by the public
:func:`Set.contains` method or the :class:`Contains` expression.

Parameters
==========

other: Sympified :class:`Basic` instance
    The object whose membership in ``self`` is to be tested.

Returns
=======

Symbolic :class:`Boolean` or ``None``.

A return value of ``None`` indicates that it is unknown whether
``other`` is contained in ``self``. Returning ``None`` from here
ensures that ``self.contains(other)`` or ``Contains(self, other)`` will
return an unevaluated :class:`Contains` expression.

If not ``None`` then the returned value is a :class:`Boolean` that is
logically equivalent to the statement that ``other`` is an element of
``self``. Usually this would be either ``S.true`` or ``S.false`` but
not always.
z
._contains)r   type__name__r   s     rG   r   Set._contains  s!    8 "T$Z%8%8$9"DEErF   c                   [        U[        5      (       d  [        SU-  5      eX:X  a  gU R                  nUSL a  g[	        U5      (       a  UR                  (       a  gU R
                  SL a  UR
                  (       a  gU R                  U5      nUb  U$ UR                  U 5      nUb  U$ SSKJ	n  U" X5      nUb  U$ U R                  U5      U :X  a  gg)z
Returns True if ``self`` is a subset of ``other``.

Examples
========

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

Unknown argument '%s'TFNr   )is_subset_sets)r   rJ   r   rP   r   rQ   _eval_is_subset_eval_is_supersetsympy.sets.handlers.issubsetr   r   )rZ   r   rP   retr   s        rG   	is_subsetSet.is_subset  s     %%%4u<== ===tx  U^^&5+>+> ""5)?J%%d+?J 	@T)?J >>% D( )rF   c                    gz;Returns a fuzzy bool for whether self is a subset of other.NrE   r   s     rG   r   Set._eval_is_subset      rF   c                    gr   rE   r   s     rG   r   Set._eval_is_superset  r   rF   c                $    U R                  U5      $ )z
Alias for :meth:`is_subset()`
r   r   s     rG   issubsetSet.issubset  r   rF   c                    [        U[        5      (       a  X:g  =(       a    U R                  U5      $ [        SU-  5      e)z
Returns True if ``self`` is a proper subset of ``other``.

Examples
========

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

r   r   rJ   r   r   r   s     rG   is_proper_subsetSet.is_proper_subset  s8     eS!!=:T^^E%::4u<==rF   c                j    [        U[        5      (       a  UR                  U 5      $ [        SU-  5      e)z
Returns True if ``self`` is a superset of ``other``.

Examples
========

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

r   r   r   s     rG   is_supersetSet.is_superset  s1     eS!!??4((4u<==rF   c                $    U R                  U5      $ )z!
Alias for :meth:`is_superset()`
)r  r   s     rG   
issupersetSet.issuperset
  r   rF   c                    [        U[        5      (       a  X:g  =(       a    U R                  U5      $ [        SU-  5      e)z
Returns True if ``self`` is a proper superset of ``other``.

Examples
========

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

r   )r   rJ   r  r   r   s     rG   is_proper_supersetSet.is_proper_superset  s:     eS!!=<T%5%5e%<<4u<==rF   c                    SSK Jn  U" U 5      $ )Nr   PowerSet)powersetr  )rZ   r  s     rG   _eval_powersetSet._eval_powerset#  s    &~rF   c                "    U R                  5       $ )a  
Find the Power set of ``self``.

Examples
========

>>> from sympy import EmptySet, FiniteSet, Interval

A power set of an empty set:

>>> A = EmptySet
>>> A.powerset()
{EmptySet}

A power set of a finite set:

>>> A = FiniteSet(1, 2)
>>> a, b, c = FiniteSet(1), FiniteSet(2), FiniteSet(1, 2)
>>> A.powerset() == FiniteSet(a, b, c, EmptySet)
True

A power set of an interval:

>>> Interval(1, 2).powerset()
PowerSet(Interval(1, 2))

References
==========

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

)r  rY   s    rG   r  Set.powerset'  s    B ""$$rF   c                    U R                   $ )z
The (Lebesgue) measure of ``self``.

Examples
========

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

)_measurerY   s    rG   measureSet.measureJ  s     }}rF   c                "    U R                  5       $ )a  
The kind of a Set

Explanation
===========

Any :class:`Set` will have kind :class:`SetKind` which is
parametrised by the kind of the elements of the set. For example
most sets are sets of numbers and will have kind
``SetKind(NumberKind)``. If elements of sets are different in kind than
their kind will ``SetKind(UndefinedKind)``. See
:class:`sympy.core.kind.Kind` for an explanation of the kind system.

Examples
========

>>> from sympy import Interval, Matrix, FiniteSet, EmptySet, ProductSet, PowerSet

>>> FiniteSet(Matrix([1, 2])).kind
SetKind(MatrixKind(NumberKind))

>>> Interval(1, 2).kind
SetKind(NumberKind)

>>> EmptySet.kind
SetKind()

A :class:`sympy.sets.powerset.PowerSet` is a set of sets:

>>> PowerSet({1, 2, 3}).kind
SetKind(SetKind(NumberKind))

A :class:`ProductSet` represents the set of tuples of elements of
other sets. Its kind is :class:`sympy.core.containers.TupleKind`
parametrised by the kinds of the elements of those sets:

>>> p = ProductSet(FiniteSet(1, 2), FiniteSet(3, 4))
>>> list(p)
[(1, 3), (2, 3), (1, 4), (2, 4)]
>>> p.kind
SetKind(TupleKind(NumberKind, NumberKind))

When all elements of the set do not have same kind, the kind
will be returned as ``SetKind(UndefinedKind)``:

>>> FiniteSet(0, Matrix([1, 2])).kind
SetKind(UndefinedKind)

The kind of the elements of a set are given by the ``element_kind``
attribute of ``SetKind``:

>>> Interval(1, 2).kind.element_kind
NumberKind

See Also
========

NumberKind
sympy.core.kind.UndefinedKind
sympy.core.containers.TupleKind
MatrixKind
sympy.matrices.expressions.sets.MatrixSet
sympy.sets.conditionset.ConditionSet
Rationals
Naturals
Integers
sympy.sets.fancysets.ImageSet
sympy.sets.fancysets.Range
sympy.sets.fancysets.ComplexRegion
sympy.sets.powerset.PowerSet
sympy.sets.sets.ProductSet
sympy.sets.sets.Interval
sympy.sets.sets.Union
sympy.sets.sets.Intersection
sympy.sets.sets.Complement
sympy.sets.sets.EmptySet
sympy.sets.sets.UniversalSet
sympy.sets.sets.FiniteSet
sympy.sets.sets.SymmetricDifference
sympy.sets.sets.DisjointUnion
)_kindrY   s    rG   kindSet.kind[  s    f zz|rF   c                    U R                   $ )a  
The boundary or frontier of a set.

Explanation
===========

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

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

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

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

Examples
========

>>> from sympy import Interval
>>> Interval(0, 1).boundary
{0, 1}
>>> Interval(0, 1, True, False).boundary
{0, 1}
)	_boundaryrY   s    rG   boundarySet.boundary  s    > ~~rF   c                @    [        X R                  5      R                  $ )a  
Property method to check whether a set is open.

Explanation
===========

A set is open if and only if it has an empty intersection with its
boundary. In particular, a subset A of the reals is open if and only
if each one of its points is contained in an open interval that is a
subset of A.

Examples
========
>>> from sympy import S
>>> S.Reals.is_open
True
>>> S.Rationals.is_open
False
)r   r  rP   rY   s    rG   is_openSet.is_open  s    * D--0999rF   c                8    U R                   R                  U 5      $ )a8  
A property method to check whether a set is closed.

Explanation
===========

A set is closed if its complement is an open set. The closedness of a
subset of the reals is determined with respect to R and its standard
topology.

Examples
========
>>> from sympy import Interval
>>> Interval(0, 1).is_closed
True
)r  r   rY   s    rG   	is_closedSet.is_closed  s    $ }}&&t,,rF   c                    X R                   -   $ )z
Property method which returns the closure of a set.
The closure is defined as the union of the set itself and its
boundary.

Examples
========
>>> from sympy import S, Interval
>>> S.Reals.closure
Reals
>>> Interval(0, 1).closure
Interval(0, 1)
r  rY   s    rG   closureSet.closure       mm##rF   c                    X R                   -
  $ )a   
Property method which returns the interior of a set.
The interior of a set S consists all points of S that do not
belong to the boundary of S.

Examples
========
>>> from sympy import Interval
>>> Interval(0, 1).interior
Interval.open(0, 1)
>>> Interval(0, 1).boundary.interior
EmptySet
r'  rY   s    rG   interiorSet.interior  r*  rF   c                    [        5       erD   r   rY   s    rG   r  Set._boundary      !##rF   c                    [        SU -  5      e)Nz(%s)._measurer   rY   s    rG   r  Set._measure"  s    !/D"899rF   c                     [        [        5      $ rD   SetKindr   rY   s    rG   r  	Set._kind&      }%%rF   c           	         [        U5      nU R                  " U R                   Vs/ s H  o3R                  US9PM     sn6 $ s  snf Nru   )rB   funcr`   r{   )rZ   precdpsargs       rG   _eval_evalfSet._eval_evalf)  s:    $yytyyAy99s9+yABBAs   A)r   rJ   c                $    U R                  U5      $ rD   r   r   s     rG   __add__Set.__add__-      zz%  rF   c                $    U R                  U5      $ rD   rB  r   s     rG   __or__
Set.__or__1  rE  rF   c                $    U R                  U5      $ rD   r   r   s     rG   __and__Set.__and__5  s    ~~e$$rF   c                    [        X5      $ rD   )r   r   s     rG   __mul__Set.__mul__9      $&&rF   c                    [        X5      $ rD   r   r   s     rG   __xor__Set.__xor__=  s    "4//rF   r-   c                d    UR                   (       a  US:  d  [        SU-  5      e[        U /U-  6 $ )Nr   z'%s: Exponent must be a positive Integer)
is_Integerr   r   )rZ   r-   s     rG   __pow__Set.__pow__A  s1    3!8FLMMD6#:&&rF   c                    [        X5      $ rD   r   r   s     rG   __sub__Set.__sub__G  rO  rF   c                r    [        U5      nU R                  U5      n[        U   nUc  [        SU-  5      eU$ )Nzdid not evaluate to a bool: %r)r*   r   r   	TypeError)rZ   r   r   r   s       rG   __contains__Set.__contains__K  s?    NN5!F9 <q@AArF   )r`   Basic | complexreturnrJ   rD   )re   z'Mapping[Basic | complex, Set | complex]rf   Noner_  rJ   )re   z/Iterable[tuple[Basic | complex, Set | complex]]rf   r`  rk   r   r_  rJ   )re   Set | complexrf   ra  r_  rJ   )re   z)Mapping[Basic | complex, Basic | complex]rf   r`  rk   r   r_  r   )re   z1Iterable[tuple[Basic | complex, Basic | complex]]rf   r`  rk   r   r_  r   )re   r^  rf   r^  rk   r   r_  r   )re   z;Mapping[Basic | complex, Basic | complex] | Basic | complexrf   zBasic | complex | Nonerk   r   r_  r   )r_  rJ   )   Nd   FFNF)ru   intrg   z!dict[Basic, Basic | float] | Nonerv   rd  rw   boolrx   re  ry   z
str | Nonerz   re  r_  rJ   )Pr   
__module____qualname____firstlineno____doc__rL   __annotations__	is_numberis_iterableis_intervalis_FiniteSetis_Intervalis_ProductSetis_UnionrM   rN   rO   is_ComplexRegionrP   rQ   propertyr7   r[   r   ra   r   rg   rr   r{   ru   staticmethodr   r   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   r   r   r   r   r  r  r  r
  r  r  r  r  r  r!  r$  r(  r,  r  r  r  r?  r   NotImplementedrC  rG  rJ  rM  rQ  r   rU  rX  r\  __static_attributes__rE   rF   rG   rJ   rJ   /   s    IyIKKLKMH!%OY%!%OY%#M9#Hi#M9#	 "'#;  	 
b 
b	y 
y	L 
L	u 
u	} 
}	a 
a 15	-	@C	HM		 PTGL;@		)-	?C	"	48	EH	
  "6)*%3('*""1H00G    6 6    6 6.`F</b
%>&>('>&!%F    R Rh  @ : :, - -& $ $  $ $  $ $ : :&C %&7! 8! %&7! 8! %&7% 8% %&7' 8' %&70 80 eT]O^4' 5'
 %&7' 8'rF   rJ   c                      \ rS rSrSrSrS r\S 5       rS r	S r
S r\S	 5       r\S
 5       rS r\S 5       r\S 5       r\S 5       rS rS rS rSrg)r   iV  an  
Represents a Cartesian Product of Sets.

Explanation
===========

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

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

Examples
========

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

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

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

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

The Cartesian product is not commutative or associative e.g.:

>>> I*S == S*I
False
>>> (I*I)*I == I*(I*I)
False

Notes
=====

- Passes most operations down to the argument sets

References
==========

.. [1] https://en.wikipedia.org/wiki/Cartesian_product
Tc                   [        U5      S:X  aJ  [        US   5      (       a7  [        US   [        [        45      (       d  [        SSSS9  [        US   5      nU Vs/ s H  n[        U5      PM     nn[        S U 5       5      (       d  [        S5      e[        U5      S:X  a  [        S	5      $ [        R                  U;   a  [        R                  $ [        R                  " U /UQ70 UD6$ s  snf )
Nr   r   zX
ProductSet(iterable) is deprecated. Use ProductSet(*iterable) instead.
                rS   zdeprecated-productset-iterablerU   c              3  B   #    U  H  n[        U[        5      v   M     g 7frD   r   rJ   r   r   s     rG   r   %ProductSet.__new__.<locals>.<genexpr>  s     4t!:a%%t   z-Arguments to ProductSet should be of type SetrE   )r   r<   r   rJ   setr8   tupler+   allr[  r   r$   r   r   ra   )r_   r   assumptionsr   s       rG   ra   ProductSet.__new__  s    t9>htAw//
47SRUJ8W8W% */+K a>D$()Dq
D)4t444KLL t9>R= ::::}}S747;77 *s   C/c                    U R                   $ rD   r`   rY   s    rG   r   ProductSet.sets      yyrF   c                @   ^ U4S jm[        T" U R                  5      6 $ )Nc              3     >#    U  H4  nUR                   (       a  T" UR                  5       S h  vN   M0  Uv   M6     g  N7frD   )rp  r   )r   r   _flattens     rG   r  $ProductSet.flatten.<locals>._flatten  s1     ??'///G	 /s   ,A?A)r   r   )rZ   r  s    @rG   flattenProductSet.flatten  s    	 8DII.//rF   c           	     @   UR                   (       a  g[        U[        5      (       a"  [        U5      [        U R                  5      :w  a  [
        R                  $ [        [        U R                  U5       VVs/ s H  u  p#UR                  U5      PM     snn6 $ s  snnf )z
``in`` operator for ProductSets.

Examples
========

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

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

Passes operation on to constituent sets
N)
	is_Symbolr   r   r   r   r$   r6   r1   r   r   )rZ   elementr   es       rG   r   ProductSet._contains  sm      '5))S\S^-K77Ns499g/FG/FtqQZZ]/FGHHGs   8B
c           	     V   U Vs/ s H  n[        U5      PM     nn[        U5      [        U R                  5      :w  d  [        S U 5       5      (       d  [	        S5      e[        [        U R                  U5       VVs/ s H  u  p#UR                  U5      PM     snn6 $ s  snf s  snnf )Nc              3  8   #    U  H  oR                   v   M     g 7frD   )r  r   r   s     rG   r   +ProductSet.as_relational.<locals>.<genexpr>  s      5.%,W   z/number of symbols must match the number of sets)r*   r   r   r  r   r1   r   as_relational)rZ   r&   r   r   s       rG   r  ProductSet.as_relational  s    (/018A;0w<3tyy>) 5.%,5. 2. 2.AC CC		74KL4KDAQ__Q'4KLMM 1
 Ms   B >B%
c                N   ^  [        U 4S j[        T R                  5       5       6 $ )Nc              3  v   >^#    U  H-  u  mn[        U4S  j[        TR                  5       5       6 v   M/     g7f)c              3  h   >#    U  H'  u  pTU:w  a  X"R                   -   OUR                   v   M)     g 7frD   r'  )r   jr   r   s      rG   r   1ProductSet._boundary.<locals>.<genexpr>.<genexpr>  s0      $B,@DA 781fA

N!**$L,@s   /2N)r   r   r   )r   ar   rZ   s     @rG   r   'ProductSet._boundary.<locals>.<genexpr>  s;      B,@DAq " $B,5dii,@$B C,@s   59)r   r   r   rY   s   `rG   r  ProductSet._boundary  s*     B,5dii,@B C 	CrF   c                :    [        S U R                   5       5      $ )a!  
A property method which tests whether a set is iterable or not.
Returns True if set is iterable, otherwise returns False.

Examples
========

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

c              3  8   #    U  H  oR                   v   M     g 7frD   rl  r   r~  s     rG   r   )ProductSet.is_iterable.<locals>.<genexpr>       8is??ir  r  r   rY   s    rG   rl  ProductSet.is_iterable  s    $ 8dii888rF   c                &    [        U R                  6 $ )z
A method which implements is_iterable property method.
If self.is_iterable returns True (both constituent sets are iterable),
then return the Cartesian Product. Otherwise, raise TypeError.
)r9   r   rY   s    rG   __iter__ProductSet.__iter__  s     ##rF   c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   rP   r{  s     rG   r   &ProductSet.is_empty.<locals>.<genexpr>  s     6Iq

Ir  )r   r   rY   s    rG   rP   ProductSet.is_empty  s    6DII666rF   c                h    [        S U R                   5       5      n[        U R                  U/5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   rQ   r{  s     rG   r   +ProductSet.is_finite_set.<locals>.<genexpr>       B	1	r  r   r   r   rP   rZ   
all_finites     rG   rQ   ProductSet.is_finite_set  *    B		BB

344rF   c                L    SnU R                    H  nXR                  -  nM     U$ Nr   )r   r  )rZ   r  r   s      rG   r  ProductSet._measure  s&    Ayy G rF   c                F    [        [        S U R                   5       6 5      $ )Nc              3  L   #    U  H  oR                   R                  v   M     g 7frD   )r  element_kindr  s     rG   r   #ProductSet._kind.<locals>.<genexpr>  s     "J	166#6#6	   "$)r5  r   r`   rY   s    rG   r  ProductSet._kind  s    y"J		"JKLLrF   c                >    [        S S U R                   5       5      $ )Nc                
    X-  $ rD   rE   r  r   s     rG   rH   $ProductSet.__len__.<locals>.<lambda>  s    13rF   c              3  8   #    U  H  n[        U5      v   M     g 7frD   )r   r{  s     rG   r   %ProductSet.__len__.<locals>.<genexpr>  s     (CAQr  )r   r`   rY   s    rG   __len__ProductSet.__len__  s    &(C(CDDrF   c                ,    [        U R                  5      $ rD   r  rY   s    rG   __bool__ProductSet.__bool__      499~rF   rE   N)r   rf  rg  rh  ri  rp  ra   rs  r   r  r   r  r  rl  r  rP   rQ   r  r  r  r  rv  rE   rF   rG   r   r   V  s    -\ M82  0I0N C C
 9 9&$ 7 7 5 5  MErF   r   c                  j   \ 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
 5       r\S 5       r\S 5       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\S 5       rS rS!S jrS rS r\S 5       r\S 5       r S r!Sr"g)"r   i  a  
Represents a real interval as a Set.

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

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

Examples
========

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

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

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

References
==========

.. [1] https://en.wikipedia.org/wiki/Interval_%28mathematics%29
Tc           	        [        U5      n[        U5      n[        U5      n[        U5      n[        S X44 5       5      (       d  [        SU< SU< 35      e[        [	        S XX!-
  4 5       5      5      (       a  [        S5      e[        X!5      (       a  [        R                  $ X!-
  R                  (       a  [        R                  $ X!:X  a  U(       d  U(       a  [        R                  $ X!:X  aO  U(       dH  U(       dA  U[        R                  L d  U[        R                  L a  [        R                  $ [        U5      $ U[        R                  L a  [        nU[        R                  L a  [        nU[        R                  :X  d  U[        R                  :X  a  [        R                  $ [        R                  " XX#U5      $ )Nc              3  r   #    U  H-  n[        U[        [        5      [        [        5      45      v   M/     g 7frD   )r   r   r5   r6   )r   r  s     rG   r   #Interval.__new__.<locals>.<genexpr>>  s.      ., a$t*d5k!:;;,s   57z>left_open and right_open can have only true/false values, got z and c              3  8   #    U  H  oR                   v   M     g 7frD   )is_extended_realr  s     rG   r   r  E  s     S;Ra11;Rr  z$Non-real intervals are not supported)r*   r  r   r   r   r   r"   r$   r   is_negativer   NegativeInfinityr   r5   r   ra   )r_   startend	left_open
right_opens        rG   ra   Interval.__new__7  sX   smY'	j)
 .,. . .%#,j:; ;
 YSE	;RSSTTCDD ::k&&::<Y*::<j

"eq/A/A&Azz!S>! A&&&I!**JAJJ#););";::}}SDDrF   c                     U R                   S   $ )z
The left end point of the interval.

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

Examples
========

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

r   _argsrY   s    rG   r  Interval.start_       zz!}rF   c                     U R                   S   $ )z
The right end point of the interval.

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

Examples
========

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

r   r  rY   s    rG   r  Interval.endp  r  rF   c                     U R                   S   $ )z
True if interval is left-open.

Examples
========

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

   r  rY   s    rG   r  Interval.left_open  r  rF   c                     U R                   S   $ )z
True if interval is right-open.

Examples
========

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

   r  rY   s    rG   r  Interval.right_open  r  rF   c                    U " XSS5      $ )z.Return an interval including neither boundary.TrE   r_   r  r   s      rG   openInterval.open  s     1t$$rF   c                    U " XSS5      $ )z3Return an interval not including the left boundary.TFrE   r  s      rG   LopenInterval.Lopen  s     1u%%rF   c                    U " XSS5      $ )z4Return an interval not including the right boundary.FTrE   r  s      rG   RopenInterval.Ropen  s     1%%rF   c                    U R                   $ rD   r  rY   s    rG   r   Interval._inf      zzrF   c                    U R                   $ rD   r  rY   s    rG   r   Interval._sup      xxrF   c                    U R                   $ rD   r  rY   s    rG   leftInterval.left  r  rF   c                    U R                   $ rD   r  rY   s    rG   rightInterval.right  r  rF   c                    U R                   (       d  U R                  (       a  U R                  U R                  :  nOU R                  U R                  :  n[	        U5      $ rD   )r  r  r  r  r   )rZ   conds     rG   rP   Interval.is_empty  s>    >>T__::)D::(D$rF   c                .    U R                   R                  $ rD   )r  is_zerorY   s    rG   rQ   Interval.is_finite_set  s    ||###rF   c                   U[         R                  :X  au  [        [         R                  U R                  SU R
                  (       + 5      n[        U R                  [         R                  U R                  (       + S5      n[        X#5      $ [        U[        5      (       a5  UR                   Vs/ s H  oDR                  (       d  M  UPM     nnU/ :X  a  g [        R                  X5      $ s  snf NT)r$   r   r   r  r  r  r  r   r  r   r   r   r`   rk  rJ   r   )rZ   r   r  r   mnumss         rG   r   Interval._complement  s    AGG++TZZ4>>13A1::4??/BDIA;eY''$zz9z![[AzD9rzt++	 :s   -C)C)c                    U R                   U R                  4 Vs/ s H$  n[        U5      [        R                  :w  d  M"  UPM&     nn[        U6 $ s  snf rD   )r  r  absr$   r   r   )rZ   pfinite_pointss      rG   r  Interval._boundary  sL    %)ZZ$: 2$:qFajj0 $: 2-((2s   !A Ac                   [        U[        5      (       aF  U[        R                  L d3  UR                  SL d$  UR                  [        R                  5      (       a  [        $ U R                  [        R                  L a=  U R                  [        R                  L a   UR                  b  [        UR                     $ [        5       nU R                  U5      R                  X!5      $ )NF)r   r   r$   NaNis_realhasComplexInfinityr6   r  r  r  r   r   r(   r  rg   )rZ   r   ds      rG   r   Interval._contains  s    5$''5AEE>}}%13D3D)E)E ::+++AJJ0F}}(5==))G!!!$))!33rF   c                    [        U5      nU R                  (       a  XR                  :  nOXR                  :*  nU R                  (       a  U R                  U:  nOU R                  U:*  n[        X25      $ )zARewrite an interval in terms of inequalities and logic operators.)r+   r  r  r  r  r1   )rZ   r   r   r  s       rG   r  Interval.as_relational  sT    AJ??LEME>>::>D::?D4rF   c                4    U R                   U R                  -
  $ rD   )r  r  rY   s    rG   r  Interval._measure  s    xx$**$$rF   c                     [        [        5      $ rD   )r5  r   rY   s    rG   r  Interval._kind  s    z""rF   c                    [        [        U R                  R                  U5      5      [        U R                  R                  U5      5      5      $ rD   )r@   rA   r  r?  r  rZ   r<  s     rG   to_mpiInterval.to_mpi  s<    3tzz--d34$$T*+- 	-rF   c                    [        U R                  R                  U5      U R                  R                  U5      U R                  U R
                  S9$ )N)r  r  )r   r  _evalfr   r  r  r   s     rG   r?  Interval._eval_evalf  s@    		((.

0A0A$0GnnB 	BrF   c                    U R                   R                  nX R                  R                  -  nX!R                   R                  -  nX!R                  R                  -  nU$ rD   )r  r   r  )rZ   r   r   s      rG   _is_comparableInterval._is_comparable  sM    

00///222000rF   c                x    U R                   [        R                  L =(       d    U R                   [        S5      :H  $ )z;Return ``True`` if the left endpoint is negative infinity. z-inf)r  r$   r  r   rY   s    rG   is_left_unboundedInterval.is_left_unbounded  s+     yyA...L$))uV}2LLrF   c                x    U R                   [        R                  L =(       d    U R                   [        S5      :H  $ )z<Return ``True`` if the right endpoint is positive infinity. z+inf)r   r$   r   r   rY   s    rG   is_right_unboundedInterval.is_right_unbounded  s)     zzQZZ'F4::v+FFrF   c                    [        U[        5      (       d7  [        U[        5      (       a  [        $ [        U[        5      (       a  g [        $ g rD   )r   r   r   r6   rJ   r   s     rG   _eval_EqInterval._eval_Eq  s;    %**%++E3''L +rF   rE   N)FF)5   )#r   rf  rg  rh  ri  ro  ra   rs  r  r  r  r  classmethodr  r  r  r   r   r  r   rP   rQ   r   r  r   r  r  r  r!  r?  r'  r*  r-  r0  rv  rE   rF   rG   r   r     s   (R K&EP             % % & & & &             $ $, ) )
4  % %#-B M M G GrF   r   c                      \ rS rSrSrSr\S 5       r\S 5       rS r	\S 5       r
S 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S r\S 5       rS rSrg)r   i'  a  
Represents a union of sets as a :class:`Set`.

Examples
========

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

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

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

See Also
========

Intersection

References
==========

.. [1] https://en.wikipedia.org/wiki/Union_%28set_theory%29
Tc                "    [         R                  $ rD   r$   r   rY   s    rG   identityUnion.identityD      zzrF   c                "    [         R                  $ rD   r$   UniversalSetrY   s    rG   zero
Union.zeroH      ~~rF   c                H   UR                  S[        R                  5      n[        U5      nU(       a%  [	        U R                  U5      5      n[        U5      $ [	        [        U[        R                  5      5      n[        R                  " U /UQ76 n[        U5      Ul        U$ )Nr   )getr   r   r*   r   _new_args_filtersimplify_unionr%   rJ   r   r   ra   	frozenset_argset)r_   r`   rk   r   objs        rG   ra   Union.__new__L  s    ::j*;*D*DE ~ ,,T23D!$''GD#"2"234mmC'$'o
rF   c                    U R                   $ rD   r  rY   s    rG   r`   
Union.args]  r  rF   c                B   ^ [        U4S jU R                   5       5      $ )Nc              3  D   >#    U  H  oR                  T5      v   M     g 7frD   r   )r   r   r   s     rG   r   $Union._complement.<locals>.<genexpr>c  s     FIqLL22I    )r   r`   r   s    `rG   r   Union._complementa  s    FDIIFFFrF   c                d    [        U R                   Vs/ s H  oR                  PM     sn6 $ s  snf rD   )r0   r`   r~   rZ   r~  s     rG   r   
Union._infe  '     		2	WW	2332   -c                d    [        U R                   Vs/ s H  oR                  PM     sn6 $ s  snf rD   )r/   r`   r   rQ  s     rG   r   
Union._supk  rS  rT  c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  r  s     rG   r   !Union.is_empty.<locals>.<genexpr>s  s     ;#r  r   r`   rY   s    rG   rP   Union.is_emptyq  s    ;;;;rF   c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  r  s     rG   r   &Union.is_finite_set.<locals>.<genexpr>w  s     @is**ir  rZ  rY   s    rG   rQ   Union.is_finite_setu  s    @dii@@@rF   c                  ^  T R                    Vs/ s H  n[        U5      U4PM     nnSnSnU(       a  X4[        S U 5       5      -  -  nU 4S jU 5       nU VVs/ s H  u  pVUR                  S:w  d  M  XV4PM     nnn/ n/ nU H3  n	U	S   U;   a  M  UR	                  U	S   5        UR	                  U	5        M5     UnUS-  nU(       a  M  U$ s  snf s  snnf )Nr   r   c              3  >   #    U  H  u  pUR                   v   M     g 7frD   )r  )r   sosinters      rG   r   !Union._measure.<locals>.<genexpr>  s     #IDjcEMMDs   c              3     >#    U  HA  u  pTR                     H+  nX1;  d  M
  U[        U5      -   UR                  U5      4v   M-     MC     g 7frD   )r`   r   r   )r   rb  r   newsetrZ   s       rG   r   rd    sO      *-1)		f( NS9V,,f.>.>|.LM@I N-1s
   A*A)r`   r   sumr  r   )
rZ   r   r   r  parityrb  rc  sos_list	sets_list_sets
   `         rG   r  Union._measurey  s     ,09959a1q!95#ID#I IIIG*-1*D
 48N4ZS5==A;MLSL4DN HI7h&OODG,$$T*  D bLF3 d4 ; 6 Os   CC6Cc                   ^ [        S U R                   5       5      mT(       d
  [        5       $ [        U4S jT 5       5      (       a  TS   $ [        [        5      $ )Nc              3  b   #    U  H%  o[         R                  Ld  M  UR                  v   M'     g 7frD   )r$   r   r  r   r>  s     rG   r   Union._kind.<locals>.<genexpr>  s     M)3!**7Lhchh)   //c              3  2   >#    U  H  oTS    :H  v   M     g7fr   NrE   r   r   kindss     rG   r   rq         .1eAh   r   )r  r`   r5  r  r   rZ   rv  s    @rG   r  Union._kind  sG    M$))MM9....8O=))rF   c           
     l   ^  U 4S jn[        [        U[        [        T R                  5      5      5      6 $ )Nc                   > TR                   U    R                  n[        TR                   5       H  u  p#X :w  d  M  XR                  -
  nM     U$ )z7The boundary of set i minus interior of all other sets )r`   r  r   r,  )r   r   r  r  rZ   s       rG   boundary_of_set(Union._boundary.<locals>.boundary_of_set  sB    		!%%A!$)),6JJA - HrF   )r   mapr   r   r`   )rZ   r}  s   ` rG   r  Union._boundary  s)    	 c/5TYY+@ABBrF   c                n    [        U R                   Vs/ s H  o"R                  U5      PM     sn6 $ s  snf rD   )r2   r`   r   )rZ   r   r   s      rG   r   Union._contains  s*    tyy9y!JJu%y9::9   2c                B   ^ [        U4S jU R                   5       5      $ )Nc              3  D   >#    U  H  oR                  T5      v   M     g 7frD   r   )r   r   r   s     rG   r   "Union.is_subset.<locals>.<genexpr>  s     ?YU++YrN  rZ  r   s    `rG   r   Union.is_subset      ?TYY???rF   c                l   [        U R                  5      S:X  a  [        S U R                   5       5      (       a  U R                  u  p#UR                  UR                  :X  a  UR
                  (       a  UR                  (       a{  UR                  (       a  XR                  :  OXR                  :  nUR
                  (       a  XR                  :  OXR                  :*  n[        XR                  5      n[        XdU5      $ [        U R                   Vs/ s H  owR                  U5      PM     sn6 $ s  snf )z<Rewrite a Union in terms of equalities and logic operators. r  c              3  B   #    U  H  n[        U[        5      v   M     g 7frD   )r   r   r  s     rG   r   &Union.as_relational.<locals>.<genexpr>  s     ?YJq(++Yr}  )r   r`   r  r   r~   r  r  r!   r1   r2   r  )rZ   symbolr  r   mincondmaxcondnecondr   s           rG   r  Union.as_relational  s    		Na?TYY??? 99DAuu~!,,1;;,-KK&55.Vuu_,-LL&55.foFEE*6G44TYY?YOOF+Y?@@?s   D1c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  rp  s     rG   r   $Union.is_iterable.<locals>.<genexpr>  r  r  r  r`   rY   s    rG   rl  Union.is_iterable      8dii888rF   c                4    [        S U R                   5       6 $ )Nc              3  8   #    U  H  n[        U5      v   M     g 7frD   iterrp  s     rG   r   !Union.__iter__.<locals>.<genexpr>  s     ;#DIIr  )r;   r`   rY   s    rG   r  Union.__iter__  s    ;;<<rF   rE   N)r   rf  rg  rh  ri  rq  rs  r7  r=  ra   r`   r   r   r   rP   rQ   r  r  r  r   r   r  rl  r  rv  rE   rF   rG   r   r   '  s    4 H   "  G 4 4
 4 4
 < < A A ) )V* C C;@A" 9 9=rF   r   c                      \ rS rSrSrSr\S 5       r\S 5       rSS.S jr	\S	 5       r
\S
 5       r\S 5       rS r\S 5       r\S 5       rS rS r\S 5       rS rSrg)r   i  a  
Represents an intersection of sets as a :class:`Set`.

Examples
========

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

We often use the .intersect method

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

See Also
========

Union

References
==========

.. [1] https://en.wikipedia.org/wiki/Intersection_%28set_theory%29
Tc                "    [         R                  $ rD   r;  rY   s    rG   r7  Intersection.identity  r?  rF   c                "    [         R                  $ rD   r6  rY   s    rG   r=  Intersection.zero  r9  rF   Nr   c          	     d   Uc  [         R                  n[        [        [	        [        U5      5      5      5      nU(       a%  [        U R                  U5      5      n[        U5      $ [        [        U[        R                  5      5      n[        R                  " U /UQ76 n[        U5      Ul        U$ rD   )r   r   r   r%   r~  r*   rB  simplify_intersectionrJ   r   r   ra   rD  rE  )r_   r   r`   rF  s       rG   ra   Intersection.__new__  s    (11H GC/01 ,,T23D(..GD#"2"234mmC'$'o
rF   c                    U R                   $ rD   r  rY   s    rG   r`   Intersection.args  r  rF   c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  rp  s     rG   r   +Intersection.is_iterable.<locals>.<genexpr>  r  r  )anyr`   rY   s    rG   rl  Intersection.is_iterable  r  rF   c                H    [        S U R                   5       5      (       a  gg )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  rp  s     rG   r   -Intersection.is_finite_set.<locals>.<genexpr>  s     ;#%%r  T)r   r`   rY   s    rG   rQ   Intersection.is_finite_set  s    ;;;; <rF   c                   ^ [        S U R                   5       5      mT(       d  [        [        5      $ [	        U4S jT 5       5      (       a  TS   $ [        5       $ )Nc              3  b   #    U  H%  o[         R                  Ld  M  UR                  v   M'     g 7frD   )r$   r<  r  rp  s     rG   r   %Intersection._kind.<locals>.<genexpr>  s     Q)3!..7Phchh)rr  c              3  2   >#    U  H  oTS    :H  v   M     g7frt  rE   ru  s     rG   r   r    rw  rx  r   )r  r`   r5  r   r  ry  s    @rG   r  Intersection._kind  sG    Q$))QQ=))....8O9rF   c                    [        5       erD   r   rY   s    rG   r   Intersection._inf$  r0  rF   c                    [        5       erD   r   rY   s    rG   r   Intersection._sup(  r0  rF   c                n    [        U R                   Vs/ s H  o"R                  U5      PM     sn6 $ s  snf rD   )r1   r`   r   )rZ   r   r~  s      rG   r   Intersection._contains,  s*    DII>IS\\%(I>??>r  c              #  (  #    [        U R                  S 5      nSnUS   US    -   n/ / pTU H'  nS n [        U5      nUc  M  UR	                  U5        M)     UR                  [        S9  XE-    HG  n[        U R                  5      U1-
  n	[        U	SS06n
SnU H  n X;   a  Uv   M  M     U(       d  MG    g    U(       d  U(       d  [        S5      e[        S5      eg ! [         a    UR	                  U5         Nf = f! [         a    Sn Mu  f = f7f)Nc                    U R                   $ rD   r  r   s    rG   rH   'Intersection.__iter__.<locals>.<lambda>0  s    ammrF   FTkeyr   z)None of the constituent sets are iterableziThe computation had not completed because of the undecidable set membership is found in every candidates.)r:   r`   r   r[  r   sortr~  r   )rZ   	sets_sift	completed
candidatesfinite_candidatesothers	candidatelengthr   
other_setsr   r   s               rG   r  Intersection.__iter__/  s6    $;<		t_y6
$&6#IF)Y !!((3 $ 	3'"+ATYY1#-J *=u=EI&z "  y ,  KLLKL L )  )i() ! & %I&sX   /DCDAD	C?&D5)DC<9D;C<<D?DDDDc                p  ^^ [        U S SS9u  pU(       d  gU Vs/ s H  n[        U5      PM     nn[        S U[        5       5      m[        5       nT HM  m[        U4S jU  5       5      nUSL a  UR	                  T5        Uc  M3  U H  nUR                  T5        M     MO     [        S U[        5       5      nU Vs/ s H  n[        U6 PM     n	nU(       a  U H{  m[        U4S jU	 5       5      n
U
SL a  UR	                  T5        U
c  M3  [        U5       H(  u  pTU;   d  M  UR                  T5        [        U6 X'   M*     UR                  T5          O   O	U(       a  M  [        U5      (       d  [        5       /nU(       a  U Vs/ s H  o3U-  PM	     nnU[        5       /:X  a  [        R                  $ U Vs/ s H  n[        U6 PM     nn[        S	 U[        5       5      mU4S
 jnU Vs/ s H  o" U5      (       a  M  UPM     nnU(       ai  [        U6 nU[        R                  L a  [        R                  $ UR                  (       a  UR                  UR                  5        OUR!                  U5        [#        U5      S:X  a  US   $ [        USS06$ s  snf s  snf s  snf s  snf s  snf )z>Simplify intersection of one or more FiniteSets and other setsc                    U R                   $ rD   )rn  r  s    rG   rH   2Intersection._handle_finite_sets.<locals>.<lambda>Z  s    q~~rF   TbinaryNc                
    X-  $ rD   rE   r  s     rG   rH   r  b      15rF   c              3  D   >#    U  H  oR                  T5      v   M     g 7frD   r   r   r   r  s     rG   r   3Intersection._handle_finite_sets.<locals>.<genexpr>h  s     :TjjmmTrN  c                
    X-  $ rD   rE   r  s     rG   rH   r  y  s    !%rF   c              3  D   >#    U  H  oR                  T5      v   M     g 7frD   r  r  s     rG   r   r    s      C
1A
rN  c                
    X-  $ rD   rE   r  s     rG   rH   r    r  rF   c                0   >^  [        U 4S jT 5       5      $ )Nc              3  X   >#    U  H  n[        TR                  U5      5      v   M!     g 7frD   r   )r   r  r   s     rG   r   EIntersection._handle_finite_sets.<locals>.<lambda>.<locals>.<genexpr>  s!     $U1Z

1%>%>s   '*)r  )r   all_elementss   `rG   rH   r    s    $U$U!UrF   r   r   r   F)r:   r~  r   r   adddiscardr   r   remover  r$   r   r   rM   extendr`   r   r   )r`   fs_argsr  fsfs_setsdefiniteinallr   fs_elements
fs_symsetsinfsru   r   is_redundantr   restr  r  s                   @@rG   _handle_finite_sets Intersection._handle_finite_setsU  s_   
 t%=dK  &--Wr3r7W-0'35A 5A:T::E}Q  AIIaL ! $ /#%@ .55WimW
5   C
 CC4<LLO# )' 26HHQK,5qMJM	 !3
  &&q) ! ! k( 7||ugG /67wH}wG7sug::'./w!	1w/ 0'35AU#;V<?!V;(D qzz!zz!##DII&D!t9>7N666m .6 6< 8
 0 <s#   JJ$J) J.4J3J3c                n    [        U R                   Vs/ s H  o"R                  U5      PM     sn6 $ s  snf )zBRewrite an Intersection in terms of equalities and logic operators)r1   r`   r  )rZ   r  r~  s      rG   r  Intersection.as_relational  s,    $))D)3&&v.)DEEDr  rE   )r   rf  rg  rh  ri  rM   rs  r7  r=  ra   r`   rl  rQ   r  r   r   r   r  rt  r  r  rv  rE   rF   rG   r   r     s    2 O    '+ $   9 9   $ $ $ $@$LL a7 a7FFrF   r   c                  n    \ rS rSrSrSrSS jr\S 5       rS r	S r
S r\S	 5       r\S
 5       rS rSrg)r   i  ak  Represents the set difference or relative complement of a set with
another set.

$$A - B = \{x \in A \mid x \notin B\}$$


Examples
========

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

See Also
=========

Intersection, Union

References
==========

.. [1] https://mathworld.wolfram.com/ComplementSet.html
Tc                    [        [        X45      u  pU(       a  [        R                  X5      $ [        R
                  " XU5      $ rD   )r  r*   r   r   r   ra   r_   r  r   r   s       rG   ra   Complement.__new__  s7    8aV$$$Q**}}SQ''rF   c                  ^  U[         R                  :X  d  T R                  U5      (       a  [         R                  $ [	        U[
        5      (       a  [        U 4S jUR                   5       6 $ UR                  T 5      nUb  U$ [        T USS9$ )z"
Simplify a :class:`Complement`.

c              3  D   >#    U  H  oR                  T5      v   M     g 7frD   rL  )r   r   As     rG   r   $Complement.reduce.<locals>.<genexpr>  s     !B6a,,q//6rN  Fr   )
r$   r<  r   r   r   r   r   r`   r   r   r  Bresults   `  rG   r   Complement.reduce  sq     !++a..::a!B166!BCCq!MaU33rF   c                    U R                   S   nU R                   S   n[        UR                  U5      [        UR                  U5      5      5      $ )Nr   r   )r`   r1   r   r3   )rZ   r   r  r  s       rG   r   Complement._contains  s@    IIaLIIaL1::e$c!**U*;&<==rF   c                    U R                   u  p#UR                  U5      n[        UR                  U5      5      n[        XE5      $ )z?Rewrite a complement in terms of equalities and logic
operators)r`   r  r3   r1   rZ   r  r  r  A_relB_rels         rG   r  Complement.as_relational  s;     yy'AOOF+,5  rF   c                4    U R                   S   R                  $ Nr   )r`   r  rY   s    rG   r  Complement._kind  s    yy|   rF   c                B    U R                   S   R                  (       a  gg )Nr   T)r`   rl  rY   s    rG   rl  Complement.is_iterable  s    99Q<## $rF   c                t    U R                   u  pUR                  nUSL a  gUSL a  UR                  (       a  gg g )NTF)r`   rQ   )rZ   r  r  a_finites       rG   rQ   Complement.is_finite_set	  s:    yy??t1?? $3rF   c              #  P   #    U R                   u  pU H  nX2;  a  Uv   M  M     g 7frD   r  )rZ   r  r  r  s       rG   r  Complement.__iter__  s'     yyAzG	 s   $&rE   NT)r   rf  rg  rh  ri  rO   ra   rt  r   r   r  r  rs  rl  rQ   r  rv  rE   rF   rG   r   r     sc    0 M( 4 4">
!!    rF   r   c                      \ rS rSrSrSrSrSr\\	" SSSS9S 5       5       r
\S	 5       rS
 rS rS rS rS r\S 5       rS rS rS rSrg)r   i  aA  
Represents the empty set. The empty set is available as a singleton
as ``S.EmptySet``.

Examples
========

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

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

See Also
========

UniversalSet

References
==========

.. [1] https://en.wikipedia.org/wiki/Empty_set
TrR   rS   rT   rU   c                    gr	  rE   rY   s    rG   r[   EmptySet.is_EmptySet8  r]   rF   c                    gr  rE   rY   s    rG   r  EmptySet._measureD      rF   c                    [         $ rD   r6   r   s     rG   r   EmptySet._containsH      rF   c                    [         $ rD   r  rZ   r  s     rG   r  EmptySet.as_relationalK  r  rF   c                    gr  rE   rY   s    rG   r  EmptySet.__len__N  s    rF   c                    [        / 5      $ rD   r  rY   s    rG   r  EmptySet.__iter__Q  s    BxrF   c                    [        U 5      $ rD   r   rY   s    rG   r  EmptySet._eval_powersetT  s    rF   c                    U $ rD   rE   rY   s    rG   r  EmptySet._boundaryW      rF   c                    U$ rD   rE   r   s     rG   r   EmptySet._complement[      rF   c                    [        5       $ rD   )r5  rY   s    rG   r  EmptySet._kind^  s
    yrF   c                    U$ rD   rE   r   s     rG   r   EmptySet._symmetric_differencea  r&  rF   rE   N)r   rf  rg  rh  ri  rP   rQ   rn  rs  r7   r[   r  r   r  r  r  r  r  r   r  r   rv  rE   rF   rG   r   r     s    0 HML	 "'#;     rF   r   )	metaclassc                  b    \ rS rSrSrSrSrSrS rS r	\
S 5       rS rS	 rS
 r\
S 5       rSrg)r<  ie  ac  
Represents the set of all things.
The universal set is available as a singleton as ``S.UniversalSet``.

Examples
========

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

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

See Also
========

EmptySet

References
==========

.. [1] https://en.wikipedia.org/wiki/Universal_set
TFc                "    [         R                  $ rD   r6  r   s     rG   r   UniversalSet._complement  s    zzrF   c                    U$ rD   rE   r   s     rG   r   "UniversalSet._symmetric_difference  r&  rF   c                "    [         R                  $ rD   )r$   r   rY   s    rG   r  UniversalSet._measure  r9  rF   c                     [        [        5      $ rD   r4  rY   s    rG   r  UniversalSet._kind  r7  rF   c                    [         $ rD   r5   r   s     rG   r   UniversalSet._contains      rF   c                    [         $ rD   r6  r  s     rG   r  UniversalSet.as_relational  r8  rF   c                "    [         R                  $ rD   r6  rY   s    rG   r  UniversalSet._boundary  r9  rF   rE   N)r   rf  rg  rh  ri  rN   rP   rQ   r   r   rs  r  r  r   r  r  rv  rE   rF   rG   r<  r<  e  sY    2 OHM  &  rF   r<  c                    ^  \ rS rSr% SrS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 5       rS rS rS rS rS rS r\S 5       rS rS rS rS rS rS rU 4S jr \!RD                  r"S\#S'   Sr$U =r%$ )r   i  a7  
Represents a finite set of Sympy expressions.

Examples
========

>>> from sympy import FiniteSet, Symbol, Interval, Naturals0
>>> FiniteSet(1, 2, 3, 4)
{1, 2, 3, 4}
>>> 3 in FiniteSet(1, 2, 3, 4)
True
>>> FiniteSet(1, (1, 2), Symbol('x'))
{1, x, (1, 2)}
>>> FiniteSet(Interval(1, 2), Naturals0, {1, 2})
FiniteSet({1, 2}, Interval(1, 2), Naturals0)
>>> members = [1, 2, 3, 4]
>>> f = FiniteSet(*members)
>>> f
{1, 2, 3, 4}
>>> f - FiniteSet(2)
{1, 3, 4}
>>> f + FiniteSet(2, 5)
{1, 2, 3, 4, 5}

References
==========

.. [1] https://en.wikipedia.org/wiki/Finite_set
TFc                t   UR                  S[        R                  5      nU(       a9  [        [	        [
        U5      5      n[        U5      S:X  a  [        R                  $ O[        [	        [
        U5      5      n0 n[        [        [        U5      5      5       H-  nUR                  (       a  XTU'   M   XTUR                  5       '   M/     [        UR                  5       5      n[        [        U[         R"                  5      5      n[$        R&                  " U /UQ76 nXgl        U$ ! [         a    XTU'    M  f = f)Nr   r   )rA  r   r   r   r  r+   r   r$   r   reversedr%   r  as_dummyr[  r~  valuesrJ   r   r   ra   	_args_set)r_   r`   rk   r   dargsr   rB  rF  s           rG   ra   FiniteSet.__new__  s    ::j*;*D*DEGT*+D4yA~zz!  GT*+D $wt}-.A{{a!*+!**,' / '	GIs'7'789mmC'$'!
 ! ! !H!s   4D%%D76D7c                ,    [        U R                  5      $ rD   )r  r`   rY   s    rG   r  FiniteSet.__iter__  s    DIIrF   c           	        [        U[        5      (       Gan  / / p2U R                   H[  nUR                  (       a$  UR                  (       a  UR                  U5        M8  UR                  S:X  a  MJ  UR                  U5        M]     U[        R                  :X  a  U/ :w  a  UR                  5         / nU[        [        R                  US   SS5      /-  n[        US S USS  5       H!  u  pgUR                  [        XgSS5      5        M#     UR                  [        US   [        R                  SS5      5        U/ :w  a  [        [        USS06[        U6 SS9$ [        USS06$ U/ :X  a  U(       a  [        U[        U6 SS9$ U$ O[        U[        5      (       a  / nU  HX  n	[        UR!                  U	5      5      n
U
[        R"                  Ld  M2  U
[        R$                  Ld  MG  UR                  U	5        MZ     [        U6 nX:X  a  g / nU HC  n	[        U R!                  U	5      5      n
U
[        R"                  Ld  M2  UR                  U	5        ME     [        [        U6 U5      $ [&        R)                  X5      $ )NFr   Trg  r   r   r   )r   r   r`   rk  r  r   r$   r   r  r  r   r   r   r   r   r+   r   r5   r6   rJ   r   )rZ   r   r  symsr
  	intervalsr  r   unkr   r   not_trues               rG   r   FiniteSet._complement  s   eX&& R$YY;;199KKNYY%'KKN  DBJ			hq'9'947D$OPP	Sb	484DA$$XaD$%?@ 5  $r(AJJd!KL2:%eY&G&G%t,u> > !)<e<<%eY-=NN L	  y))CENN1-.AFF?q'7JJqM  S/C{HDMM!,-AFF?OOA&  i2C88t++rF   c                    XR                   ;   a  [        R                  $ [        U R                   Vs/ s H  n[        X!SS9PM     sn6 $ s  snf )aK  
Tests whether an element, other, is in the set.

Explanation
===========

The actual test is for mathematical equality (as opposed to
syntactical equality). In the worst case all elements of the
set must be checked.

Examples
========

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

Tr   )rB  r$   r5   r2   r`   r    )rZ   r   r  s      rG   r   FiniteSet._contains  sA    * NN"66M TYYGY1d3YGHHGs   Ac                B   ^ [        U4S jU R                   5       5      $ )Nc              3  F   >#    U  H  nTR                  U5      v   M     g 7frD   )r   )r   r  r   s     rG   r   ,FiniteSet._eval_is_subset.<locals>.<genexpr>+  s     ?Y++Yr   rZ  r   s    `rG   r   FiniteSet._eval_is_subset*  r  rF   c                    U $ rD   rE   rY   s    rG   r  FiniteSet._boundary-  r#  rF   c                    [        U 6 $ rD   )r0   rY   s    rG   r   FiniteSet._inf1      DzrF   c                    [        U 6 $ rD   )r/   rY   s    rG   r   FiniteSet._sup5  rW  rF   c                    gr  rE   rY   s    rG   r  FiniteSet.measure9  r  rF   c                   ^  T R                   (       d
  [        5       $ [        U 4S jT R                    5       5      (       a"  [        T R                   S   R                  5      $ [        [        5      $ )Nc              3  n   >#    U  H*  oR                   TR                  S    R                   :H  v   M,     g7frt  r  r`   r   r   rZ   s     rG   r   "FiniteSet._kind.<locals>.<genexpr>@  &     @i499Q<,,,i   25r   r`   r5  r  r  r   rY   s   `rG   r  FiniteSet._kind=  sK    yy9@dii@@@499Q<,,--=))rF   c                ,    [        U R                  5      $ rD   )r   r`   rY   s    rG   r  FiniteSet.__len__E  r  rF   c           	     P    [        U  Vs/ s H  n[        X5      PM     sn6 $ s  snf )z@Rewrite a FiniteSet in terms of equalities and logic operators. )r2   r    )rZ   r  elems      rG   r  FiniteSet.as_relationalH  s$    6Bv$6776s   #c                0    [        U 5      [        U5      -
  $ rD   )hashr   s     rG   compareFiniteSet.compareL  s    T
T%[()rF   c           	     l    [        U5      n[        U  Vs/ s H  o3R                  US9PM     sn6 $ s  snf r9  )rB   r   r{   )rZ   r<  r=  rh  s       rG   r?  FiniteSet._eval_evalfO  s2    $>:::,>??>s   1c           
     V    SSK Jn  [        U  Vs/ s H  o2" U40 UD6PM     sn6 $ s  snf )Nr   )rr   )sympy.simplifyrr   r   )rZ   rk   rr   rh  s       rG   _eval_simplifyFiniteSet._eval_simplifyS  s,    +E8D3F3EFFEs   &c                    U R                   $ rD   r  rY   s    rG   _sorted_argsFiniteSet._sorted_argsW  r  rF   c                    U R                   " [        U R                  5       Vs/ s H  oR                   " U6 PM     sn6 $ s  snf rD   )r;  r=   r`   )rZ   r   s     rG   r  FiniteSet._eval_powerset[  s4    yy'$))2DE2DQ99a=2DEFFEs   A c                  ^ SSK Jn  S nU" [        U 5      5      (       d  gS m[        U4S jU 5       5      (       d  g[	        U[        S9n[        UR                  5       H  n[        U6 nXq;  d  M    g   U" U5      $ )z1Rewriting method for a finite set to a power set.r   r  c                >    [        U =(       a    X S-
  -  (       + 5      $ r  )re  r:  s    rG   rH   5FiniteSet._eval_rewrite_as_PowerSet.<locals>.<lambda>b  s    4 5!1u+o6rF   Nc                H    [        U [        5      =(       a    U R                  $ rD   )r   rJ   rn  )r>  s    rG   rH   r{  f  s    jc2Gs7G7GGrF   c              3  4   >#    U  H  nT" U5      v   M     g 7frD   rE   )r   r>  fs_tests     rG   r   6FiniteSet._eval_rewrite_as_PowerSet.<locals>.<genexpr>g  s     04C73<<4s   r  )r  r  r   r  maxr=   r`   r   )	rZ   r`   rk   r  is2powbiggestr>  arg_setr~  s	           @rG   _eval_rewrite_as_PowerSet#FiniteSet._eval_rewrite_as_PowerSet^  st    &6c$i  G04000d$7<<(CoG" )   rF   c                |    [        U[        5      (       d  [        S[        U5      -  5      eUR	                  U 5      $ Nz!Invalid comparison of set with %sr   rJ   r[  r>   r   r   s     rG   __ge__FiniteSet.__ge__q  s4    %%%?)EBRRSSt$$rF   c                |    [        U[        5      (       d  [        S[        U5      -  5      eU R	                  U5      $ r  )r   rJ   r[  r>   r
  r   s     rG   __gt__FiniteSet.__gt__v  s6    %%%?)EBRRSS&&u--rF   c                |    [        U[        5      (       d  [        S[        U5      -  5      eU R	                  U5      $ r  r  r   s     rG   __le__FiniteSet.__le__{  s4    %%%?)EBRRSS~~e$$rF   c                |    [        U[        5      (       d  [        S[        U5      -  5      eU R	                  U5      $ r  )r   rJ   r[  r>   r  r   s     rG   __lt__FiniteSet.__lt__  s6    %%%?)EBRRSS$$U++rF   c                v   > [        U[        [        45      (       a  U R                  U:H  $ [        TU ]  U5      $ rD   )r   r~  rD  rB  super__eq__)rZ   r   	__class__s     rG   r  FiniteSet.__eq__  s3    ec9-..>>U**w~e$$rF   zCallable[[Basic], Any]__hash__rE   )&r   rf  rg  rh  ri  rn  rl  rP   rQ   ra   r  r   r   r   rs  r  r   r   r  r  r  r  rl  r?  rr  ru  r  r  r  r  r  r  r  r   r  rj  rv  __classcell__r  s   @rG   r   r     s    : LKHM8/,bI8@        *8*@G  G!&%
.
%
,
%
 ).H%66rF   r   c                    [        U 6 $ rD   r  r  s    rG   rH   rH     s    )Q-rF   c                    [        U 6 $ rD   r  r  s    rG   rH   rH     s    	1rF   c                  R    \ rS rSrSrSrSS jr\S 5       rS r	\
S 5       rS rS	rg
)r   i  al  Represents the set of elements which are in either of the
sets and not in their intersection.

Examples
========

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

See Also
========

Complement, Union

References
==========

.. [1] https://en.wikipedia.org/wiki/Symmetric_difference
Tc                h    U(       a  [         R                  X5      $ [        R                  " XU5      $ rD   )r   r   r   ra   r  s       rG   ra   SymmetricDifference.__new__  s'    &--a33}}SQ''rF   c                B    UR                  U 5      nUb  U$ [        XSS9$ )NFr   )r   r   r  s      rG   r   SymmetricDifference.reduce  s*    ((+M&qe<<rF   c                x    U R                   u  p#UR                  U5      nUR                  U5      n[        XE5      $ )zIRewrite a symmetric_difference in terms of equalities and
logic operators)r`   r  r4   r  s         rG   r  !SymmetricDifference.as_relational  s6     yy''5  rF   c                H    [        S U R                   5       5      (       a  gg )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  rp  s     rG   r   2SymmetricDifference.is_iterable.<locals>.<genexpr>  s     4)3)r  Tr  rY   s    rG   rl  SymmetricDifference.is_iterable  s    4$))444 5rF   c              #     #    U R                   n[        S U 5       6 nU H)  nSnU H  nX5;   d  M
  US-  nM     US-  S:X  d  M%  Uv   M+     g 7f)Nc              3  8   #    U  H  n[        U5      v   M     g 7frD   r  rp  s     rG   r   /SymmetricDifference.__iter__.<locals>.<genexpr>  s     7$3T#YY$r  r   r   r  )r`   r;   )rZ   r`   r   itemcountr   s         rG   r  SymmetricDifference.__iter__  sW     yy7$78DE9QJE  qyA~
 s   +AA	ArE   Nr  )r   rf  rg  rh  ri  is_SymmetricDifferencera   rt  r   r  rs  rl  r  rv  rE   rF   rG   r   r     sF    * "( = =!  rF   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 rS rSrg)DisjointUnioni  a  Represents the disjoint union (also known as the external disjoint union)
of a finite number of sets.

Examples
========

>>> from sympy import DisjointUnion, FiniteSet, Interval, Union, Symbol
>>> A = FiniteSet(1, 2, 3)
>>> B = Interval(0, 5)
>>> DisjointUnion(A, B)
DisjointUnion({1, 2, 3}, Interval(0, 5))
>>> DisjointUnion(A, B).rewrite(Union)
Union(ProductSet({1, 2, 3}, {0}), ProductSet(Interval(0, 5), {1}))
>>> C = FiniteSet(Symbol('x'), Symbol('y'), Symbol('z'))
>>> DisjointUnion(C, C)
DisjointUnion({x, y, z}, {x, y, z})
>>> DisjointUnion(C, C).rewrite(Union)
ProductSet({x, y, z}, {0, 1})

References
==========

https://en.wikipedia.org/wiki/Disjoint_union
c                    / nU H7  n[        U[        5      (       a  UR                  U5        M+  [        SU-  5      e   [        R
                  " U /UQ76 nU$ )NzQInvalid input: '%s', input args                     to DisjointUnion must be Sets)r   rJ   r   r[  r   ra   )r_   r   dj_collectionset_irF  s        rG   ra   DisjointUnion.__new__  s`    E%%%$$U+ !35:!; < <	  mmC0-0
rF   c                    U R                   $ rD   r  rY   s    rG   r   DisjointUnion.sets  r  rF   c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  r{  s     rG   r   )DisjointUnion.is_empty.<locals>.<genexpr> 	  s     7YYr  )r   r   rY   s    rG   rP   DisjointUnion.is_empty  s    7TYY777rF   c                h    [        S U R                   5       5      n[        U R                  U/5      $ )Nc              3  8   #    U  H  oR                   v   M     g 7frD   r  r{  s     rG   r   .DisjointUnion.is_finite_set.<locals>.<genexpr>	  r  r  r  r  s     rG   rQ   DisjointUnion.is_finite_set	  r  rF   c                    U R                   (       a  gSnU R                   H+  nUR                   (       a  M  U=(       a    UR                  nM-     U$ )NFT)rP   r   rl  )rZ   	iter_flagr  s      rG   rl  DisjointUnion.is_iterable	  s@    ==	YYE>>>%;%*;*;	  rF   c                    [         R                  nSnU H?  n[        U[        5      (       d  M  [	        U[        U5      5      n[        X65      nUS-   nMA     U$ )z{
Rewrites the disjoint union as the union of (``set`` x {``i``})
where ``set`` is the element in ``sets`` at index = ``i``
r   r   )r$   r   r   rJ   r   r   r   )rZ   r   rk   dj_unionindexr  crosss          rG   _eval_rewrite_as_Union$DisjointUnion._eval_rewrite_as_Union	  sT     ::E%%%"5)E*:; 1		 
 rF   c                d   [        U[        5      (       a  [        U5      S:w  a  [        R                  $ US   R
                  (       d  [        R                  $ US   [        U R                  5      :  d	  US   S:  a  [        R                  $ U R                  US      R                  US   5      $ )a!  
``in`` operator for DisjointUnion

Examples
========

>>> from sympy import Interval, DisjointUnion
>>> D = DisjointUnion(Interval(0, 1), Interval(0, 2))
>>> (0.5, 0) in D
True
>>> (0.5, 1) in D
True
>>> (1.5, 0) in D
False
>>> (1.5, 1) in D
True

Passes operation on to constituent sets
r  r   r   )r   r   r   r$   r6   rT  r   r   )rZ   r  s     rG   r   DisjointUnion._contains 	  s    ( '5))S\Q->77Nqz$$77N1:TYY'71:>77Nyy$..wqz::rF   c                   ^  T R                   (       d
  [        5       $ [        U 4S jT R                    5       5      (       a  T R                   S   R                  $ [        [        5      $ )Nc              3  n   >#    U  H*  oR                   TR                  S    R                   :H  v   M,     g7frt  r^  r_  s     rG   r   &DisjointUnion._kind.<locals>.<genexpr>B	  ra  rb  r   rc  rY   s   `rG   r  DisjointUnion._kind?	  sF    yy9@dii@@@99Q<$$$=))rF   c           	         U R                   (       aV  / n[        U R                  5       H*  u  p#UR                  [	        U[        U5      15      5        M,     [        [        U6 5      $ [        SU -  5      e)Nz'%s' is not iterable.)	rl  r   r   r   r9   r   r  r;   r   )rZ   itersr   r   s       rG   r  DisjointUnion.__iter__G	  sa    E!$)),Xa'!*67 - 
E*++4t;<<rF   c                    U R                   (       a%  SnU R                   H  nU[        U5      -  nM     U$ [        SU -  5      e)a  
Returns the length of the disjoint union, i.e., the number of elements in the set.

Examples
========

>>> from sympy import FiniteSet, DisjointUnion, EmptySet
>>> D1 = DisjointUnion(FiniteSet(1, 2, 3, 4), EmptySet, FiniteSet(3, 4, 5))
>>> len(D1)
7
>>> D2 = DisjointUnion(FiniteSet(3, 5, 7), EmptySet, FiniteSet(3, 5, 7))
>>> len(D2)
6
>>> D3 = DisjointUnion(EmptySet, EmptySet)
>>> len(D3)
0

Adds up the lengths of the constituent sets.
r   z'%s' is not a finite set.)rQ   r   r   r   )rZ   sizer~  s      rG   r  DisjointUnion.__len__R	  sD    * DyyC  !K84?@@rF   rE   N)r   rf  rg  rh  ri  ra   rs  r   rP   rQ   rl  r  r   r  r  r  rv  rE   rF   rG   r  r    sv    2	   8 8 5 5  ;>*	=ArF   r  c            	       ^ SSK Jn  SSKJn  [	        U 5      S:  a  [        S[	        U 5      -  5      e[        U S   [        [        45      (       a'  [	        U 5      S:  a  [        U S   U S   5      nU SS nO
U S   nU SS n[        U[        5      (       a  GO[        U5      (       a  [        US0 5      nU(       ag  [	        U5      S:w  a  [        [        S	5      5      eUR                  S   nUS:X  a  S
nOL[        SUS-   5       Vs/ s H  n[        SU-  5      PM     nnO [         R"                  " U5      R$                  n['        U" U Vs/ s H  n[)        5       PM     sn6 5      m[        U4S jU 5       5      n	[        X" U	6 5      nO [+        [        S[-        U5      -  5      5      e[/        S U 5       5      (       a)  U Vs/ s H  n[-        U5      PM     n
n[        SU
-  5      e[	        U5      S:X  Ga#  US   n U" X;5      nUc  [*        eU(       d  U$  [        X5      (       a  UR                  u  p;UR0                  S   UR2                  :X  a  U$ [        X5      (       a  [	        UR4                  R0                  5      S:X  a  [	        UR0                  5      S:X  at  UR4                  R0                  S   nUR0                  S   n[7        [        XR2                  R9                  XR4                  R2                  5      5      /UR:                  Q76 $ Ub  U$ U" U/UQ76 $ s  snf s  snf s  snf ! [*         a    U" X;5      n GN/f = f)a"  
Return an image of the set under transformation ``f``.

Explanation
===========

If this function cannot compute the image, it returns an
unevaluated ImageSet object.

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

Examples
========

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

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

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

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

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

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

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

See Also
========

sympy.sets.fancysets.ImageSet

r   ImageSet)set_functionr  z)imageset expects at least 2 args, got: %sr   Nnargsz
                    This function can take more than 1 arg
                    but the potentially complicated set input
                    has not been analyzed at this point to
                    know its dimensions. TODO
                    r   zx%ic              3  N   >#    U  H  n[        [        U5      T5      v   M     g 7frD   )r)   r'   )r   r   dexprs     rG   r   imageset.<locals>.<genexpr>	  s+      *'(! *1Iu '(s   "%zN
            expecting lambda, Lambda, or FunctionClass,
            not '%s'.c              3  L   #    U  H  n[        U[        5      (       + v   M     g 7frD   rz  r{  s     rG   r   r  	  s     
48az!S!!!8r  z.arguments after mapping should be sets, not %s)	fancysetsr  setexprr  r   r   r   r'   r  r   callablegetattrr   r?   r`   r   inspect	signature
parametersr*   r(   r[  r>   r  	variablesr   lamdaimagesetrg   	base_sets)r`   r  r  fset_listr  Nr   r   varnamer~  rr   yr  s                  @rG   r  r  p	  s   ^ $%
4y1}Ds4yPQQ$q'FE?++D	A47DG$8G8!V	!7B'5zQ)* 6 +   

1AAv05aQ@1VEAI&@!!!$//Aa0aUWa012 *'(* *33 
 $&q\$* + , 	, 
48
444&./h	!h/<tCE 	E 8}qk	!Q$Ay  a""VVFA;;q>QVV#Jc$$
 399&&'1,Q[[1AQ1FII''*KKN1ffkk!YY^^<=O@CO O =HA!!!c A 1 0  	! A	!s$   
L,L1L6L; ;MMc                    U [         [        4;   a  g[        S5      nU " U5      R                  U5      nUS:  S:X  d	  US:  S:X  a  gg)z_
Checks whether function ``func`` is invertible when the domain is
restricted to set ``setv``.
Tur   N)r-   r.   r(   diff)r;  setvr  fdiffs       rG   is_function_invertible_in_setr  	  sL     Szc
AGLLOE 		duqyT1rF   c                   SSK Jn  U (       d  [        R                  $ U  H#  n[	        U[
        5      (       a  M  [        S5      e   U  Vs/ s H  o3R                  (       d  M  UPM     nn[        U5      S:  a:  S U 5       n[        U6 nU/U  Vs/ s H  o3R                  (       a  M  UPM     sn-   n [        U 5      n SnU(       ae  U  HV  nSnX1-
   H=  n	U" X5      n
U
c  M  [	        U
[        5      (       d  U
1n
XU	1-
  R                  U
5      n  O   U(       d  MT  Un   O   U(       a  Me  [        U 5      S:X  a  U R                  5       $ [        U SS06$ s  snf s  snf )	a:  
Simplify a :class:`Union` using known rules.

Explanation
===========

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

Then we iterate through all pairs and ask the constituent sets if they
can simplify themselves with any other constituent.  This process depends
on ``union_sets(a, b)`` functions.
r   )
union_sets Input args to Union must be Setsr   c              3  6   #    U  H  o  H  o"v   M     M     g 7frD   rE   )r   r~  r   s      rG   r   !simplify_union.<locals>.<genexpr>
  s     3+3s!QsQ+s   TFr   )sympy.sets.handlers.unionr  r$   r   r   rJ   r[  rn  r   r   r~  r   popr   )r`   r  r>  r   finite_setsr  
finite_setnew_argsr   tnew_sets              rG   rC  rC  
  sK    5 zz#s##>?? 
 #5dnn1dK5
;!3+3]
|$E$Qnnq$EE t9DH
AHCZ$Q* &%gs33#*) $1v44W=H   x  (  4yA~xxzd+U++; 6 Fs   E#EE)Ec                  ^	 U (       d  [         R                  $ U  H#  n[        U[        5      (       a  M  [	        S5      e   [         R
                  U ;   a  [         R
                  $ [        R                  U 5      nUb  U$ U  Hl  nUR                  (       d  M  [        U 5      U1-
  n[        U5      S:  a&  [        U6 m	[        U	4S jUR                   5       6 s  $ [        UR                  6 s  $    U  HX  nUR                  (       d  M  U R                  U5        XR                  S   /-   n[        [        U6 UR                  S   5      s  $    SSKJn  [        U 5      n SnU(       aN  U  H?  nSnX1-
   H&  nU" X75      nUc  M  XU1-
  R%                  U15      n  O   U(       d  M=  Un   O   U(       a  MN  [        U 5      S:X  a  U R'                  5       $ [        U SS06$ )	a)  
Simplify an intersection using known rules.

Explanation
===========

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

Then we iterate through all pairs and ask the constituent sets if they
can simplify themselves with any other constituent
r  r   c              3  <   >#    U  H  n[        UT5      v   M     g 7frD   r   )r   r>  r   s     rG   r   (simplify_intersection.<locals>.<genexpr>`
  s     J6C|C776s   r   )intersection_setsTFr   )r$   r<  r   rJ   r[  r   r   r  rq  r~  r   r   r`   rO   r  r    sympy.sets.handlers.intersectionr  r   r  )
r`   r>  rvr   r  r  r  r   r  r   s
            @rG   r  r  :
  s    ~~#s##>?? 
 	zzTzz 
	)	)$	/B	~	 :::TaSJ:"$j1J166JKKaff~%  ???KKN+JlJ7CC	  C t9DH
AHCZ+A1 & $1v44gY?H   x  ( 4yA~xxzT2E22rF   c                &   [        X/S SS9u  pE[        U5      S:X  a/  [        US    VVs/ s H  odS     H
  op" Xg5      PM     M     snn6 $ [        U5      S:X  a*  US    Vs/ s H  n[        XS   Xc5      PM     nn[	        U6 $ g s  snnf s  snf )Nc                "    [        U [        5      $ rD   )r   r   r  s    rG   rH   %_handle_finite_sets.<locals>.<lambda>
  s    Jq),DrF   Tr  r  r   r   )r:   r   r   _apply_operationr   )	opr   r  commutativer  r   r   r  r   s	            rG   r  r  
  s    1&"DTRNG
7|qWQZLZA2a88ZLMM	W	HOPQ
S
1 1Xq>
Sd| MSs   B
$Bc           	        SSK Jn  [        S5      n[        XX#5      nUc  U " X5      nUc  U(       a  U " X!5      nUc  [	        S5      u  px[        U[        5      (       a=  [        U[        5      (       d(  U" [        XP" XR5      5      U5      R                  5       nU$ [        U[        5      (       d=  [        U[        5      (       a(  U" [        XP" X5      5      U5      R                  5       nU$ U" [        Xx4U " Xx5      5      X5      nU$ )Nr   r  r  zx y)	r  r  r(   r  r&   r   rJ   r   doit)	r  r   r  r  r  r  out_x_ys	            rG   r  r  
  s    #c
A
bQ
4C
{h
{{h
{ajC&8&86!RX.2779C
 J	 As##
1c(:(:6!RX.2779C J 62(BrJ7>CJrF   c                $    SSK Jn  [        X USS9$ )Nr   )_set_addTr  )sympy.sets.handlers.addr  r  )r   r  r  s      rG   set_addr  
      0H==rF   c                $    SSK Jn  [        X USS9$ )Nr   )_set_subFr  )r  r  r  )r   r  r  s      rG   set_subr  
      0H>>rF   c                $    SSK Jn  [        X USS9$ )Nr   )_set_mulTr  )sympy.sets.handlers.mulr  r  )r   r  r  s      rG   set_mulr   
  r  rF   c                $    SSK Jn  [        X USS9$ )Nr   )_set_divFr  )r  r"  r  )r   r  r"  s      rG   set_divr#  
  r  rF   c                $    SSK Jn  [        X USS9$ )Nr   )_set_powFr  )sympy.sets.handlers.powerr%  r  )r   r  r%  s      rG   set_powr'  
  s    2H>>rF   c                    SSK Jn  U" X5      $ )Nr   )_set_function)sympy.sets.handlers.functionsr)  )r  r   r)  s      rG   r  r  
  s    ;rF   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r5  i
  a  
SetKind is kind for all Sets

Every instance of Set will have kind ``SetKind`` parametrised by the kind
of the elements of the ``Set``. The kind of the elements might be
``NumberKind``, or ``TupleKind`` or something else. When not all elements
have the same kind then the kind of the elements will be given as
``UndefinedKind``.

Parameters
==========

element_kind: Kind (optional)
    The kind of the elements of the set. In a well defined set all elements
    will have the same kind. Otherwise the kind should
    :class:`sympy.core.kind.UndefinedKind`. The ``element_kind`` argument is optional but
    should only be omitted in the case of ``EmptySet`` whose kind is simply
    ``SetKind()``

Examples
========

>>> from sympy import Interval
>>> Interval(1, 2).kind
SetKind(NumberKind)
>>> Interval(1,2).kind.element_kind
NumberKind

See Also
========

sympy.core.kind.NumberKind
sympy.matrices.kind.MatrixKind
sympy.core.containers.TupleKind
c                2   > [         TU ]  X5      nXl        U$ rD   )r  ra   r  )r_   r  rF  r  s      rG   ra   SetKind.__new__
  s    goc0'
rF   c                D    U R                   (       d  gSU R                   -  $ )Nz	SetKind()zSetKind(%s))r  rY   s    rG   __repr__SetKind.__repr__
  s       4#4#444rF   rE   rD   )	r   rf  rg  rh  ri  ra   r/  rv  r  r  s   @rG   r5  r5  
  s    "F
5 5rF   r5  )z
__future__r   typingr   r   r   r   	functoolsr   collectionsr	   collections.abcr
   r   r  sympy.core.kindr   r   r   sympy.core.basicr   sympy.core.containersr   r   sympy.core.decoratorsr   r   sympy.core.evalfr   sympy.core.exprr   sympy.core.functionr   sympy.core.logicr   r   r   r   r   sympy.core.numbersr   r   sympy.core.operationsr   sympy.core.parametersr   sympy.core.relationalr    r!   r"   sympy.core.singletonr#   r$   sympy.core.sortingr%   sympy.core.symbolr&   r'   r(   r)   sympy.core.sympifyr*   r+   r,   &sympy.functions.elementary.exponentialr-   r.   (sympy.functions.elementary.miscellaneousr/   r0   sympy.logic.boolalgr1   r2   r3   r4   r5   r6   sympy.utilities.decoratorr7   sympy.utilities.exceptionsr8   sympy.utilities.iterablesr9   r:   r;   r<   r=   sympy.utilities.miscr>   r?   mpmathr@   rA   mpmath.libmp.libmpfrB   r   rJ   r   r   r   r   r   r   r<  r   r~  rD  r   r  r  r  rC  r  r  r  r  r  r   r#  r'  r  r5  rE   rF   rG   <module>rO     s   " 9 9  # -  ; ; " 2 E '   &  - + 3 / / - & K K B B ; = > > 0 @0 0 6  + ,!&&FFAFF	177GGQWW	!  c% c cLr rjYs Yxn=C n=bcF3	 cFLZ ZzGsi GT33) 3lo7 o7b 0  5  A# AJXAC XAv}"@$5,pK3\	*>
?
>
?
?

-5d -5rF   