K i2= ddlmZddlmZmZmZmZddlmZddl m Z ddl m Z m Z ddlZddlmZmZmZddlmZdd lmZmZdd lmZmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;ddlZ>m?Z?ddl@mAZAmBZBddlCmDZDmEZEddlFmGZGmHZHmIZImJZJmKZKmLZLddlMmNZNddlOmPZPddlQmRZRmSZSmTZTmUZUmVZVddlWmXZXmYZYddlZm[Z[m\Z\ddl]m^Z^e d d!e4je4je4jd"e4je4je4jiZ_eGd#d$eeZ`Gd%d&e`ZaGd'd(e`ZbGd)d*e`e+ZcGd+d,e`e+ZdGd-d.e`ZeGd/d0e`e31ZfGd2d3e`e31ZgGd4d5e`Zhd6e?ei<d7e?ej<Gd8d9e`ZkGd:d;e`Zld<Zmd=Znd>Zod?Zpd@ZqdAZrdBZsdCZtdDZudEZvdFZwdGZxGdHdIeZyy)J) annotations)AnyCallable TYPE_CHECKINGoverload)reduce) defaultdict)MappingIterableN)Kind UndefinedKind NumberKind)Basic)Tuple TupleKind)sympify_method_argssympify_return) EvalfMixin)Expr)Lambda) FuzzyBool fuzzy_boolfuzzy_or fuzzy_and fuzzy_not)FloatInteger) LatticeOp)global_parameters)EqNeis_lt) SingletonS)ordered)symbolsSymbolDummyuniquely_named_symbol)_sympifysympify_sympy_converter)explog)MaxMin)AndOrNotXortruefalse) deprecated)sympy_deprecation_warning)iproductsift roundrobiniterablesubsets) func_name filldedent)mpimpf) prec_to_dpscyNrEU/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/sets/sets.pyrH(srFTFceZdZUdZdZded<dZdZdZdZ dZ dZ dZ dZ ded<dZded <dZded <dZdZded <dZded <eed dddZerbdKdZedLdMdZedLdNdZedOdZedLdPdZedLdQdZedRdZ dL dSdZdTdZ dU dVdZeZedZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'ed&Z(ed'Z)ed(Z*ed)Z+d*Z,d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7ed6Z8ed7Z9ed8Z:ed9Z;ed:Zed=Z?ed>Z@d?ZAd@ZBeCdAgeDdBZEeCdAgeDdCZFeCdAgeDdDZGeCdAgeDdEZHeCdAgeDdFZIeCdGeJfgeDdHZKeCdAgeDdIZLdJZMy)WSeta 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``. rEz tuple[()] __slots__FNris_Intersectionis_UniversalSet is_Complementis_empty is_finite_set The is_EmptySet attribute of Set objects is deprecated. Use 's is S.EmptySet" or 's.is_empty' instead. 1.5deprecated-is-emptysetdeprecated_since_versionactive_deprecations_targetcyrDrEselfs rG is_EmptySetzSet.is_EmptySetQrFcyrDrE)clsargss rG__new__z Set.__new___s rFcyrDrErYarg1arg2s rGsubszSet.subsbs_brFc yrDrErYrbrckwargss rGrdzSet.subsdsvyrFcyrDrEras rGrdzSet.subsfsILrFc yrDrErfs rGrdzSet.subshsrurFc yrDrErfs rGrdzSet.subsjsz}rFc yrDrErfs rGrdzSet.subsls^arFc yrDrErfs rGrdzSet.subsos rFc JrDrE)rYrgs rGsimplifyz Set.simplifyss 5rFcyrDrE)rYnrdmaxnchopstrictquadverboses rGevalfz Set.evalfvs rFc |j}|jsJ|j}|S#ttt t f$rtj}Y|SwxYw)z? Return infimum (if possible) else S.Infinity. ) inf is_comparablervNotImplementedErrorAttributeErrorAssertionError ValueErrorr$Infinity)exprinfimums rG _infimum_keyzSet._infimum_key}s\  !hhG(( ((mmoG$ < !jjG !s*.)AAct||S)a 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)) )UnionrYothers rGunionz Set.unions2T5!!rFct||S)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  Intersectionrs rG intersectz Set.intersects&D%((rFc$|j|S)z/ Alias for :meth:`intersect()` rrs rG intersectionzSet.intersection~~e$$rFcF|j|tjk(S)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 )rr$EmptySetrs rG is_disjointzSet.is_disjoints$~~e$ 22rFc$|j|S)z1 Alias for :meth:`is_disjoint()` )rrs rG isdisjointzSet.isdisjoint&&rFct||S)ae 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))  ComplementrYuniverses rG complementzSet.complements(D))rFc ttrt|trtjt|jk7r|Sg}t t j|j}t t|D]-fdt|D}|jt|/t|St|tr@tttfr)t|jtjSyt|trtfd|j DSt|t"r2t#|j dt|j ddS|tj$urtj$St|trRt'|fd}tt|d|drt#t|ddStj$Sy)Nc3BK|]\}\}}|k7r|n||z ywrDrE).0isorps rG z"Set._complement..s(OFQQ!V1,Osc3(K|] }|z  ywrDrE)rrrYs rGrz"Set._complement..s81t88srFevaluatec8tj|SrDrcontains)xrYs rGrHz!Set._complement.. s:dmmA6F+GrF) isinstance ProductSetlensetslistziprange enumerateappendrInterval FiniteSetrrr$Realsr^rrr:)rYroverlapspairsrsiftedrps` @rG _complementzSet._complements dJ 'Juj,I499~UZZ0 HTYY 34E3u:& 3Oi>NO D 12 3(# # x ($9 56#E4??177+CDD7u %8UZZ89 9 z *ejjmU5::a=$-GRWX X ajj ::  y )%!GHFVE]4$<9vd|5teL1 1%&ZZ1 1*rFct||S)aW 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 SymmetricDifferencers rGsymmetric_differencezSet.symmetric_differences,#4//rFcBtt||t||SrD)rrrs rG_symmetric_differencezSet._symmetric_difference(sZe,j.EFFrFc|jS)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 )_infrXs rGrxzSet.inf+yyrFctd|z)Nz (%s)._infrzrXs rGrzSet._inf<!+"455rFc|jS)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 )_suprXs rGsupzSet.sup@rrFctd|z)Nz (%s)._suprrXs rGrzSet._supQrrFcddlm}t|d}|j|}t ||r|S| |||dSt |}||S|S)a 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)rsFr)rrr+ _containsrtfn)rYrrcbs rGrz Set.containsUs]F 'd+ NN5 ! a "H 9E4%8 8 F 9HrFcDtt|jd)aTest 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)rztype__name__rs rGrz Set._containss!8"T$Z%8%8$9"DEErFcxt|tstd|z||k(ry|j}|duryt |r |jry|j dur |j ry|j |}||S|j|}||Sddlm }|||}||S|j||k(ryy)a' 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) rrJr}rOrrP_eval_is_subset_eval_is_supersetsympy.sets.handlers.issubsetrr)rYrrOretrs rG is_subsetz Set.is_subsets%%4u<= = 5=== t  x U^^    &5+>+>""5) ?J%%d+ ?J @T5) ?J >>% D ( )rFcyz;Returns a fuzzy bool for whether self is a subset of other.NrErs rGrzSet._eval_is_subsetrFcyrrErs rGrzSet._eval_is_supersetrrFc$|j|S)z/ Alias for :meth:`is_subset()` rrs rGissubsetz Set.issubsetrrFcnt|tr||k7xr|j|Std|z)a, 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 rrrJrr}rs rGis_proper_subsetzSet.is_proper_subsets7 eS !5=:T^^E%: :4u<= =rFc`t|tr|j|Std|z)a- 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 rrrs rG is_supersetzSet.is_supersets. eS !??4( (4u<= =rFc$|j|S)z1 Alias for :meth:`is_superset()` )rrs rG issupersetzSet.issuperset rrFcnt|tr||k7xr|j|Std|z)a2 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)rrJrr}rs rGis_proper_supersetzSet.is_proper_supersets9 eS !5=>> 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 )rrXs rGrz Set.powerset'sB""$$rFc|jS)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 )_measurerXs rGmeasurez Set.measureJs}}rFc"|jS)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 )_kindrXs rGkindzSet.kind[sfzz|rFc|jS)ag 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} ) _boundaryrXs rGboundaryz Set.boundarys>~~rFcBt||jjS)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 )rrrOrXs rGis_openz Set.is_opens*D$--0999rFc8|jj|S)a 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 )rrrXs rG is_closedz Set.is_closeds$}}&&t,,rFc ||jzS)aN 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) rrXs rGclosurez Set.closuredmm##rFc ||jz S)ax 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 rrXs rGinteriorz Set.interior rrFctrDrrXs rGrz Set._boundary !##rFctd|z)Nz (%s)._measurerrXs rGrz Set._measure"s!/D"899rFc ttSrDSetKindr rXs rGrz Set._kind& }%%rFct|}|j|jDcgc]}|j|c}Scc}wNrp)rBfuncr^rv)rYprecdpsargs rG _eval_evalfzSet._eval_evalf)s:$tyytyyA399s9+ABBAsA)rrJc$|j|SrDrrs rG__add__z Set.__add__-zz%  rFc$|j|SrDrrs rG__or__z Set.__or__1rrFc$|j|SrDrrs rG__and__z Set.__and__5s~~e$$rFct||SrD)rrs rG__mul__z Set.__mul__9$&&rFct||SrDrrs rG__xor__z Set.__xor__=s"4//rFr-cX|jr|dk\std|zt|g|zS)Nrz'%s: Exponent must be a positive Integer) is_Integerr}r)rYr-s rG__pow__z Set.__pow__As13!8FLM MD6#:&&rFct||SrDrrs rG__sub__z Set.__sub__GrrFcpt|}|j|}t|}|td|z|S)Nzdid not evaluate to a bool: %r)r*rr TypeError)rYrrrs rG __contains__zSet.__contains__Ks? NN5 ! F 9&>(' >&!%F RRh@::,--&$$ $$ $$::&C%&7!8!%&7!8!%&7%8%%&7'8'%&7080eT]O^4'5' %&7'8'rFrJceZdZdZdZdZedZdZdZ dZ edZ ed Z d Z ed Zed Zed ZdZdZdZy)ra 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 Tct|dk(rCt|dr5t|dttfst dddt |d}|Dcgc] }t|}}td|Ds tdt|dk(r td Stj|vrtjStj|g|i|Scc}w) NrrzX ProductSet(iterable) is deprecated. Use ProductSet(*iterable) instead. rRzdeprecated-productset-iterablerTc3<K|]}t|tywrDrrJrrs rGrz%ProductSet.__new__..s4!:a%4z-Arguments to ProductSet should be of type SetrE)rr<rrJsetr8tupler+allr&rr$rrr_)r]r assumptionsrs rGr_zProductSet.__new__s t9>htAw/ 47SRUJ8W %*/+K  a>D$()q ))4t44KL L t9>R= :: :: }}S747;77*sCc|jSrDr^rXs rGrzProductSet.sets yyrFc>fdt|jS)Nc3vK|D]-}|jr|jEd{*|/y7 wrD)r9r)rr_flattens rGrNz$ProductSet.flatten.._flattens7 ??'///G  /s '97 9)rr)rYrNs @rGflattenzProductSet.flattens  8DII.//rFc &|jryt|tr!t|t|jk7rt j Stt|j|Dcgc]\}}|j|c}}Scc}}w)a8 ``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_Symbolrrrrr$r6r1rr)rYelementres rGrzProductSet._containssf   '5)S\S^-K77Ns499g/FGtq!QZZ]GHHGs-B c @|Dcgc] }t|}}t|t|jk7std|Ds t dt t |j|Dcgc]\}}|j|c}}Scc}wcc}}w)Nc34K|]}|jywrD)rQrrs rGrz+ProductSet.as_relational..s5. ! 5.z/number of symbols must match the number of sets)r*rrrGr}r1r as_relational)rYr&rrs rGrXzProductSet.as_relationals(/018A;00 w<3tyy> )5.%,5.2.AC CC 74KLDAqQ__Q'LMM 1 Ms B5B cLtfdtjDS)Nc3nK|]+\}tfdtjD-yw)c3dK|]'\}}|k7r||jzn |j)ywrDr)rjrrs rGrz1ProductSet._boundary...s6$B$(Aq781fA N!**$L$Bs-0N)rrr)rarrYs @rGrz'ProductSet._boundary..s=B$(Aq"$B,5dii,@$BCBs15)rrrrXs`rGrzProductSet._boundarys*B,5dii,@BC CrFc:td|jDS)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 c34K|]}|jywrDr5rrEs rGrz)ProductSet.is_iterable..8s3??8rWrGrrXs rGr5zProductSet.is_iterables$8dii888rFc&t|jS)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. )r9rrXs rG__iter__zProductSet.__iter__s ##rFc:td|jDS)Nc34K|]}|jywrDrOrCs rGrz&ProductSet.is_empty..s6q 6rW)rrrXs rGrOzProductSet.is_emptys6DII666rFchtd|jD}t|j|gS)Nc34K|]}|jywrDrPrCs rGrz+ProductSet.is_finite_set..B1qBrWrrrrOrY all_finites rGrPzProductSet.is_finite_set*B BB  344rFcJd}|jD]}||jz}|SNr)rr)rYrrs rGrzProductSet._measures- !A qyy G !rFcFttd|jDS)Nc3HK|]}|jjywrD)r element_kindrVs rGrz#ProductSet._kind..s"J1166#6#6"Js ")r rr^rXs rGrzProductSet._kindsy"J "JKLLrFc>tdd|jDS)Nc ||zSrDrEr]rs rGrHz$ProductSet.__len__..s 1Q3rFc32K|]}t|ywrD)rrCs rGrz%ProductSet.__len__..s(CAQ(C)rr^rXs rG__len__zProductSet.__len__s&(C(CDDrFc,t|jSrDrcrXs rG__bool__zProductSet.__bool__499~rFN)rr0r1r2r9r_r<rrOrrXrr5rerOrPrrr{r}rErFrGrrVs-\M820I0NCC 99&$7755 MErFrc^eZdZdZdZddZedZedZedZ edZ e dZ e d Z e d Zed Zed Zed ZedZedZedZdZedZdZdZedZdZddZdZdZedZedZdZ y) ra 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 2t|}t|}t|}t|}td||fDstd|d|tt d||||z fDr t dt ||rtjS||z jrtjS||k(r|s|rtjS||k(rC|sA|s?|tjus|tjurtjSt|S|tjurt}|tjurt}|tjk(s|tjk(rtjStj|||||S)Nc3lK|],}t|ttttf.ywrD)rrr5r6)rr]s rGrz#Interval.__new__..>s,.a$t*d5k!:;.s24z>left_open and right_open can have only true/false values, got z and c34K|]}|jywrD)is_extended_realrVs rGrz#Interval.__new__..EsSaq11SrWz$Non-real intervals are not supported)r*rGrzrrr}r"r$r is_negativer~NegativeInfinityrr5rr_)r]startend left_open right_opens rGr_zInterval.__new__7s_smY' j) .,..%#,j:; ; YSE3E ;RSS TCD D e :: Ek & &::  % ! A&& &I !** J AJJ #););";:: }}S%iDDrFc |jdS)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_argsrXs rGrzInterval.start_zz!}rFc |jdS)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 rrrXs rGrz Interval.endprrFc |jdS)a 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 rrXs rGrzInterval.left_openrrFc |jdS)a 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 rrXs rGrzInterval.right_openrrFc|||ddS)z.Return an interval including neither boundary.TrEr]r]rs rGopenz Interval.opens1at$$rFc|||ddS)z3Return an interval not including the left boundary.TFrErs rGLopenzInterval.Lopens1au%%rFc|||ddS)z4Return an interval not including the right boundary.FTrErs rGRopenzInterval.Ropens1a%%rFc|jSrDrrXs rGrz Interval._inf zzrFc|jSrDrrXs rGrz Interval._sup xxrFc|jSrDrrXs rGleftz Interval.leftrrFc|jSrDrrXs rGrightzInterval.rightrrFc|js |jr$|j|jk\}t |S|j|jkD}t |SrD)rrrrr)rYconds rGrOzInterval.is_emptysM >>T__::)D$::(D$rFc.|jjSrD)ris_zerorXs rGrPzInterval.is_finite_sets||###rFc|tjk(rnttj|jd|j }t|j tj|j d}t||St|tr,|jDcgc]}|js|}}|gk(rytj||Scc}wNT)r$rrrrrrr~rrrrr^r4rJr)rYrr]rmnumss rGrzInterval._complements AGG ++TZZ4>>13A1::4??/BDIAA;  eY '$zz9!Q[[A9D9rztU++ :s C2Cc|j|jfDcgc] }t|tjk7r|"}}t |Scc}wrD)rrabsr$r~r)rYp finite_pointss rGrzInterval._boundarysK%)ZZ$:2qFajj02 2-((2s%A ct|tr?|tjus-|jdus|j tj rtS|jtjur;|jtjur|jt|jSt}|j|j||S)NF)rrr$NaNis_realhasComplexInfinityr6rrrr~rr(rXrd)rYrds rGrzInterval._containss5$'5AEE>}}%13D3D)E ::++ +AJJ0F}}(5==)) G!!!$))!U33rFct|}|jr||jk}n||jk}|jr|j|k}n|j|k}t ||S)zARewrite an interval in terms of inequalities and logic operators.)r+rrrrr1)rYrrrs rGrXzInterval.as_relationalsZ AJ ??LEME >>::>D::?D4rFc4|j|jz SrD)rrrXs rGrzInterval._measuresxx$**$$rFc ttSrD)r rrXs rGrzInterval._kinds z""rFctt|jj|t|jj|SrD)r@rArrrrYrs rGto_mpizInterval.to_mpis<3tzz--d34 $$T* +- -rFct|jj||jj||j|j S)N)rr)rr_evalfrrrrs rGrzInterval._eval_evalfs@ ((. 0A0A$0GnnB BrFc|jj}||jjz}||jjz}||jjz}|SrD)rryr)rYrrys rG_is_comparablezInterval._is_comparable sS 00 /// 222 000 rFcn|jtjuxs|jtdk(S)z;Return ``True`` if the left endpoint is negative infinity. z-inf)rr$rrrXs rGis_left_unboundedzInterval.is_left_unboundeds+yyA...L$))uV}2LLrFcn|jtjuxs|jtdk(S)z>> 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"tjSrDr$rrXs rGidentityzUnion.identityD zzrFc"tjSrDr$ UniversalSetrXs rGzeroz Union.zeroH ~~rFc<|jdtj}t|}|r%t |j |}t |St t|tj}tj|g|}t||_ |S)Nr)getrrr*r_new_args_filtersimplify_unionr%rJrrr_ frozenset_argset)r]r^rgrobjs rGr_z Union.__new__Ls::j*;*D*DE~ ,,T23D!$' 'GD#"2"234mmC'$'o  rFc|jSrDrrXs rGr^z Union.args]rrFc@tfd|jDS)Nc3@K|]}|jywrDr)rrrs rGrz$Union._complement..csFqALL2F)rr^rs `rGrzUnion._complementasFDIIFFFrFc`t|jDcgc]}|jc}Scc}wrD)r0r^rxrYrEs rGrz Union._infe% 2SWW2332+c`t|jDcgc]}|jc}Scc}wrD)r/r^rrs rGrz Union._supkrrc:td|jDS)Nc34K|]}|jywrDrhras rGrz!Union.is_empty..ss;#;rWrr^rXs rGrOzUnion.is_emptyqs;;;;rFc:td|jDS)Nc34K|]}|jywrDrkras rGrz&Union.is_finite_set..ws@s**@rWrrXs rGrPzUnion.is_finite_setus@dii@@@rFcjDcgc]}t||f}}d}d}|r||td|Dzz }fd|D}|Dcgc]\}}|jdk7s||f}}}g}g}|D]/} | d|vr |j | d|j | 1|}|dz}|r|Scc}wcc}}w)Nrrc3:K|]\}}|jywrD)r)rsosinters rGrz!Union._measure..s#Ijc5EMM#Isc3K|];\}}jD]'}||vr!|t|z|j|f)=ywrD)r^rr)rrrnewsetrYs rGrz!Union._measure..sU*)\ *6<S(9V,,f.>.>|.LM*M*sAA)r^rsumrr) rYrrrparityrrsos_list sets_list_sets ` rGrzUnion._measureys,0995a1q!55 v#ID#I II IG*-1*D 48NZS%5==A;MS%LNDNHI +7h&OODG,$$T*  + D bLF34;6OsB9B>,B>ctd|jDs tStfdDrdSttS)Nc3ZK|]#}|tjus|j%ywrD)r$rrrrs rGrzUnion._kind..sM3s!**7LchhM++c3.K|] }|dk(ywrNrErrkindss rGrzUnion._kind...1eAh.r)rFr^r rGr rYrs @rGrz Union._kindsDM$))MM9  .. .8O=) )rFc jfd}tt|ttjS)Ncj|j}tjD]\}}||k7s ||jz }|S)z8 The boundary of set i minus interior of all other sets )r^rrr)rrr\r]rYs rGboundary_of_setz(Union._boundary..boundary_of_setsM ! %%A!$)), '16AJJA 'HrF)rmaprrr^)rYrs` rGrzUnion._boundarys) c/5TYY+@ABBrFcjt|jDcgc]}|j|c}Scc}wrD)r2r^r)rYrrs rGrzUnion._containss(tyy9!AJJu%9::90c@tfd|jDS)Nc3@K|]}|jywrDr)rrrs rGrz"Union.is_subset..s?U+?rrrs `rGrzUnion.is_subset?TYY???rFc@t|jdk(rtd|jDr|j\}}|j|jk(r|j r|j rw|j r||jkDn||jk\}|j r||jkn||jk}t||j}t|||St|jDcgc]}|j|c}Scc}w)z.s?Jq(+?rD) rr^rGrrxrrr!r1r2rX)rYsymbolr]rmincondmaxcondnecondrs rGrXzUnion.as_relationals  Na ?TYY?? 99DAquu~!,,1;;,-KK&155.Vquu_,-LL&155.foFAEE*67G44TYY?AOOF+?@@?s?Dc:td|jDS)Nc34K|]}|jywrDr`rs rGrz$Union.is_iterable..rbrWrGr^rXs rGr5zUnion.is_iterable8dii888rFc4td|jDS)Nc32K|]}t|ywrDiterrs rGrz!Union.__iter__..s;#DI;rz)r;r^rXs rGrezUnion.__iter__s;;<>> 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"tjSrDrrXs rGrzIntersection.identityrrFc"tjSrDrrXs rGrzIntersection.zerorrFNrc V|tj}ttt t |}|r%t|j |}t|Stt|tj}tj|g|}t||_ |SrD)rrrr%rEr*rsimplify_intersectionrJrrr_rr)r]rr^rs rGr_zIntersection.__new__s  (11HGC/01 ,,T23D(. .GD#"2"234mmC'$'o  rFc|jSrDrrXs rGr^zIntersection.argsrrFc:td|jDS)Nc34K|]}|jywrDr`rs rGrz+Intersection.is_iterable..rbrW)anyr^rXs rGr5zIntersection.is_iterablerrFc>td|jDryy)Nc34K|]}|jywrDrkrs rGrz-Intersection.is_finite_set..s;#C%%;rWT)rr^rXs rGrPzIntersection.is_finite_sets ;; ; .sQ3s!..7PchhQrc3.K|] }|dk(ywrrErs rGrz%Intersection._kind..rrr)rFr^r r rGrs @rGrzIntersection._kindsDQ$))QQ=) ) .. .8O9 rFctrDrrXs rGrzIntersection._inf$rrFctrDrrXs rGrzIntersection._sup(rrFcjt|jDcgc]}|j|c}Scc}wrD)r1r^r)rYrrEs rGrzIntersection._contains,s(DII>SS\\%(>??>rc#Kt|jd}d}|d|dz}gg}}|D]$}d} t|}||j |&|j t||zD]<}t |j|hz } t| ddi} d}|D] } | | vr|  |s<y|s|s tdtdy#t$r|j |YwxYw#t$rd}Y\wxYww)Nc|jSrDr`rs rGrHz'Intersection.__iter__..0s ammrFFTkeyrz)None of the constituent sets are iterableziThe computation had not completed because of the undecidable set membership is found in every candidates.)r:r^rr&rsortrEr) rY sets_sift completed candidatesfinite_candidatesothers candidatelengthr other_setsrrs rGrezIntersection.__iter__/sG$;<  t_y6 $&6# 4IF )Y!!((3 4 3'"V+ ATYY1#-J *=u=EI &&Ez &   KLLKL L) ) i( )!& %I&sX0C: C C:AC:C)&C:+C: C&#C:%C&&C:) C74C:6C77C:ct|dd\}}|sy|Dcgc] }t|}}td|tt}D]Ftfd|D}|dur|j |/|D]}|j Htd|t}|Dcgc] }t | } }|r}|D]ttfd| D} | dur|j | /t|D]&\} }|vs |jt || | <(|jnn|r}t|s tg}|r|Dcgc]}||z }}|tgk(rtjS|Dcgc] }t | } }td |tfd } |Dcgc] }| |r |}}|rct|}|tjurtjS|jr| j|jn| j!|t#| d k(r| d St| d diScc}wcc}wcc}wcc}wcc}w)z>Simplify intersection of one or more FiniteSets and other setsc|jSrD)r7r)s rGrHz2Intersection._handle_finite_sets..Zs q~~rFTbinaryNc ||zSrDrErxs rGrHz2Intersection._handle_finite_sets..b 1q5rFc3@K|]}|jywrDrrrrSs rGrz3Intersection._handle_finite_sets..hs:ajjm:rc ||zSrDrErxs rGrHz2Intersection._handle_finite_sets..ys !a%rFc3@K|]}|jywrDr<r=s rGrz3Intersection._handle_finite_sets..s C1A Crc ||zSrDrErxs rGrHz2Intersection._handle_finite_sets..r:rFc.tfdDS)Nc3RK|]}tj| ywrDr)rrSrs rGrzEIntersection._handle_finite_sets....s$U1Z 1 %>$Us$')rG)r all_elementss`rGrHz2Intersection._handle_finite_sets..s$U $U!UrFrrrF)r:rErradddiscardrrremoverGr$rrrLextendr^rr)r^fs_argsr1fsfs_setsdefiniteinallr fs_elements fs_symsetsinfsrpr is_redundantrrestrCrSs @@rG_handle_finite_setsz Intersection._handle_finite_setsUsr t%=dK &--r3r7--0'35A 5 !A:T::E} Q  !AIIaL!  !$/#%@ .55im5 5   C CC4<LLO# )' 2:16HHQK,5qMJqM :  &&q) !(7|ugG /67rH}7G7 sug :: './! 1 //0'35A U #;<?!;; (Dqzz!zz!## DII& D! t9>7N66 6m.66<8 0 >> 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 Tctt||f\}}|rtj||St j |||SrD)rr*rrrr_r]r]rrs rGr_zComplement.__new__s?8aV$1 $$Q* *}}S!Q''rFc|tjk(sj|rtjSt |t rt fd|jDS|j}||St|dS)z2 Simplify a :class:`Complement`. c3@K|]}|jywrDr)rrAs rGrz$Complement.reduce..s!Ba!,,q/!BrFr) r$rrrrrrr^rrrYBresults` rGrzComplement.reducesl  !++a.::  a !B166!BC Cq!  MaU3 3rFc|jd}|jd}t|j|t|j|S)Nrr)r^r1rr3)rYrrYr[s rGrzComplement._containss@ IIaL IIaL1::e$c!**U*;&<==rFc|j\}}|j|}t|j|}t||S)zGRewrite a complement in terms of equalities and logic operators)r^rXr3r1rYr rYr[A_relB_rels rGrXzComplement.as_relationals?yy1'AOOF+,5%  rFc4|jdjSNr)r^rrXs rGrzComplement._kindsyy|   rFc8|jdjryy)NrT)r^r5rXs rGr5zComplement.is_iterables 99Q< # # $rFch|j\}}|j}|dury|dur|jryyy)NTF)r^rP)rYrYr[a_finites rGrPzComplement.is_finite_set s<yy1?? t   1??$3 rFc#JK|j\}}|D] }||vr| ywrDrJ)rYrYr[r]s rGrezComplement.__iter__s1yy1 AzG  s!#NT)rr0r1r2rNr_r=rrrXrr<r5rPrerErFrGrrsc0M(44"> !!rFrceZdZdZdZdZdZeeddddZ edZ d Z d Z d Z d Zd ZedZdZdZdZy)ra 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 TrQrRrSrTcyrrErXs rGrZzEmptySet.is_EmptySet8r[rFcyrcrErXs rGrzEmptySet._measureDrFctSrDr6rs rGrzEmptySet._containsH rFctSrDrnrYr s rGrXzEmptySet.as_relationalKrorFcyrcrErXs rGr{zEmptySet.__len__NsrFctgSrDrrXs rGrezEmptySet.__iter__Qs BxrFct|SrDrrXs rGrzEmptySet._eval_powersetTs rFc|SrDrErXs rGrzEmptySet._boundaryW rFc|SrDrErs rGrzEmptySet._complement[ rFctSrD)r rXs rGrzEmptySet._kind^s yrFc|SrDrErs rGrzEmptySet._symmetric_differencearyrFN)rr0r1r2rOrPr7r<r7rZrrrXr{rerrrrrrErFrGrrs0HML  "'#; rFr) metaclasscZeZdZdZdZdZdZdZdZe dZ dZ dZ d Z e d Zy ) ra 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"tjSrDrrs rGrzUniversalSet._complements zzrFc|SrDrErs rGrz"UniversalSet._symmetric_differenceryrFc"tjSrD)r$r~rXs rGrzUniversalSet._measurerrFc ttSrDrrXs rGrzUniversalSet._kindr rFctSrDr5rs rGrzUniversalSet._contains rFctSrDrrqs rGrXzUniversalSet.as_relationalrrFc"tjSrDrrXs rGrzUniversalSet._boundaryrrFN)rr0r1r2rMrOrPrrr<rrrrXrrErFrGrresY2OHM&rFrc eZdZUdZdZdZdZdZdZdZ dZ dZ dZ e d Ze d Ze d Ze d Zd ZdZdZdZdZdZe dZdZdZdZdZdZdZfdZe jBZ!de"d<xZ#S)ra 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 TFcX|jdtj}|r7tt t |}t |dk(r)tjStt t |}i}ttt|D](}|jr|||< |||j<*t|j}tt|t j"}t%j&|g|}||_|S#t$r|||<YwxYw)Nrr)rrrrrr+rr$rreversedr%rQas_dummyr&rEvaluesrJrrr_ _args_set)r]r^rgrdargsrrrs rGr_zFiniteSet.__new__s::j*;*D*DE GT*+D4yA~zz!GT*+D$wt}-. !A{{a!*+E!**,'  ! ' GIs'7'789mmC'$'!  !! E!H!s(DD)(D)c,t|jSrD)rr^rXs rGrezFiniteSet.__iter__sDIIrFc t|tr\gg}}|jD]M}|jr|jr|j |-|jdk(r=|j |O|t jk(r|gk7r|jg}|tt j|dddgz }t|dd|ddD]"\}}|j t||dd$|j t|dt jdd|gk7rtt|ddit|dSt|ddiS|gk(r|rt|t|dS|St|trg}|D]S} t|j!| } | t j"us0| t j$usC|j | Ut|}||k(ryg} |D]@} t|j!| } | t j"us0| j | Btt| |St&j)||S)NFrTrrrr)rrr^r4rrr$rr,rrr~rrrr+rr5r6rJr) rYrrsymsr intervalsr]runkrrnot_trues rGrzFiniteSet._complements+ eX &R$DYY #;;199KKNYY%'KKN  #DBJ  hq'9'947D$OPP Sb 484ADAq$$XaD$%?@A  $r(AJJd!KL2:%eY&G&G%t,u>>!)>> from sympy import FiniteSet >>> 1 in FiniteSet(1, 2) True >>> 5 in FiniteSet(1, 2) False Tr)rr$r5r2r^r )rYrrSs rGrzFiniteSet._containssA* DNN "66MTYYG1ed3GH HGsA c@tfd|jDS)Nc3@K|]}j|ywrD)r)rrSrs rGrz,FiniteSet._eval_is_subset..+s?+?rrrs `rGrzFiniteSet._eval_is_subset*rrFc|SrDrErXs rGrzFiniteSet._boundary-rwrFct|SrD)r0rXs rGrzFiniteSet._inf1 DzrFct|SrD)r/rXs rGrzFiniteSet._sup5rrFcyrcrErXs rGrzFiniteSet.measure9rlrFcjs tStfdjDr"tjdjSttS)Nc3jK|]*}|jjdjk(,ywrrr^rrrYs rGrz"FiniteSet._kind..@(@499Q<,,,@03rr^r rGrr rXs`rGrzFiniteSet._kind=sHyy9  @dii@ @499Q<,,- -=) )rFc,t|jSrD)rr^rXs rGr{zFiniteSet.__len__Er~rFc Lt|Dcgc]}t||c}Scc}w)z@Rewrite a FiniteSet in terms of equalities and logic operators. )r2r )rYr elems rGrXzFiniteSet.as_relationalHs"6Bvt$6776s!c0t|t|z SrD)hashrs rGcomparezFiniteSet.compareLsT T%[()rFcnt|}t|Dcgc]}|j|c}Scc}wr )rBrrv)rYrrrs rGrzFiniteSet._eval_evalfOs0$>4:::,>??>s2c Rddlm}t|Dcgc] }||fi| c}Scc}w)Nr)rn)sympy.simplifyrnr)rYrgrnrs rG_eval_simplifyzFiniteSet._eval_simplifySs(+E8D3F3EFFEs$c|jSrDrJrXs rG _sorted_argszFiniteSet._sorted_argsWrKrFc|jt|jDcgc]}|j|c}Scc}wrD)rr=r^)rYrs rGrzFiniteSet._eval_powerset[s4tyy'$))2DEQ9499a=EFFEs>cddlm}d}|t|sydtfd|Dsyt |t}t |j D]}t|}||vsy||S)z1Rewriting method for a finite set to a power set.rrc.t|xr ||dz z Srr)r/r s rGrHz5FiniteSet._eval_rewrite_as_PowerSet..bs4 5!q1u+o6rFNc>t|txr |jSrD)rrJr7)rs rGrHz5FiniteSet._eval_rewrite_as_PowerSet..fsjc2Gs7G7GrFc3.K|] }|ywrDrE)rrfs_tests rGrz6FiniteSet._eval_rewrite_as_PowerSet..gs0C73<0rr*)rrrrGmaxr=r^r) rYr^rgris2powbiggestrarg_setrs @rG_eval_rewrite_as_PowerSetz#FiniteSet._eval_rewrite_as_PowerSet^su&6c$i G0400d$7<<( CoGd"   rFcrt|tstdt|z|j |SNz!Invalid comparison of set with %srrJr&r>rrs rG__ge__zFiniteSet.__ge__qs1%%?)EBRRS St$$rFcrt|tstdt|z|j |Sr)rrJr&r>rrs rG__gt__zFiniteSet.__gt__vs3%%?)EBRRS S&&u--rFcrt|tstdt|z|j |Srrrs rG__le__zFiniteSet.__le__{s1%%?)EBRRS S~~e$$rFcrt|tstdt|z|j |Sr)rrJr&r>rrs rG__lt__zFiniteSet.__lt__s3%%?)EBRRS S$$U++rFclt|ttfr|j|k(St||SrD)rrErrsuper__eq__)rYr __class__s rGrzFiniteSet.__eq__s0 ec9- .>>U* *w~e$$rFzCallable[[Basic], Any]__hash__)$rr0r1r2r7r5rOrPr_rerrrr<rrrrrr{rXrrrrrrrrrrrrrr3 __classcell__rs@rGrrs:LKHM8/,bI8@*8*@GG!&% . % , % ).H%6rFrct|SrDrur)s rGrHrHs )Q-rFct|SrDrur)s rGrHrHs 1 rFcHeZdZdZdZd dZedZdZe dZ dZ y) raRepresents 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`|rtj||Stj|||SrD)rrrr_rVs rGr_zSymmetricDifference.__new__s+ &--a3 3}}S!Q''rFcH|j|}||St||dS)NFr)rrrZs rGrzSymmetricDifference.reduces,((+  M&q!e< td|jDryy)Nc34K|]}|jywrDr`rs rGrz2SymmetricDifference.is_iterable..s43s4rWTrrXs rGr5zSymmetricDifference.is_iterables 4$))4 4 5rFc#K|j}td|D}|D]"}d}|D] }||vs|dz }|dzdk(s|$yw)Nc32K|]}t|ywrDrrs rGrz/SymmetricDifference.__iter__..s73T#Y7rzrrr)r^r;)rYr^ritemcountrs rGrezSymmetricDifference.__iter__sdyy7$78 DE 19QJE qyA~  s,AAANrh) rr0r1r2is_SymmetricDifferencer_r=rrXr<r5rerErFrGrrsF*"( ==! rFrcteZdZdZdZedZedZedZedZ dZ dZ d Z d Z d Zy ) DisjointUniona 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 cg}|D]1}t|tr|j|%td|zt j |g|}|S)NzQInvalid input: '%s', input args to DisjointUnion must be Sets)rrJrr&rr_)r]r dj_collectionset_irs rGr_zDisjointUnion.__new__sb  . s77rW)rrrXs rGrOzDisjointUnion.is_emptys7TYY777rFchtd|jD}t|j|gS)Nc34K|]}|jywrDrkrCs rGrz.DisjointUnion.is_finite_set.. rlrWrmrns rGrPzDisjointUnion.is_finite_set rprFc|jryd}|jD]}|jr|xr |j}!|S)NFT)rOrr5)rY iter_flagrs rGr5zDisjointUnion.is_iterable sC == YY >%;%*;*;  <rFctj}d}|D]9}t|tst |t |}t ||}|dz};|S)z Rewrites the disjoint union as the union of (``set`` x {``i``}) where ``set`` is the element in ``sets`` at index = ``i`` rr)r$rrrJrrr)rYrrgdj_unionindexrcrosss rG_eval_rewrite_as_Unionz$DisjointUnion._eval_rewrite_as_Union sX :: "E%%"5)E*:; 51   " rFcJt|trt|dk7rtjS|dj stjS|dt|j k\s|ddkrtjS|j |dj|dS)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 rrr)rrrr$r6r!rr)rYrRs rGrzDisjointUnion._contains s('5)S\Q->77Nqz$$77N 1:TYY '71:>77Nyy$..wqz::rFcjs tStfdjDrjdjSttS)Nc3jK|]*}|jjdjk(,ywrrrs rGrz&DisjointUnion._kind..B rrrrrXs`rGrzDisjointUnion._kind? sCyy9  @dii@ @99Q<$$ $=) )rFc |jrUg}t|jD]*\}}|jt |t |h,t t|Std|z)Nz'%s' is not iterable.) r5rrrr9rrr;r})rYitersrrs rGrezDisjointUnion.__iter__G sh   E!$)), 81 Xa'!*67 8 E*+ +4t;< >> 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. rz'%s' is not a finite set.)rPrrr})rYsizerEs rGr{zDisjointUnion.__len__R sI*   Dyy !C  !K84?@ @rFN)rr0r1r2r_r<rrOrPr5rrrrer{rErFrGrrsv2 8855 ;>* =ArFrc <ddlm}ddlm}t |dkrt dt |zt |dttfr&t |dkDrt|d|d}|dd}n |d}|dd}t |trnt|rt|di}|rbt |dk7rttd |jd}|dk(rd }nHtd|dzDcgc]}td |z}}nt!j"|j$}t'||Dcgc] }t)c}tfd |D} t| || }n t+td t-|zt/d|Dr&|Dcgc] }t-|} }t d| zt |dk(r|d} ||| } | t*| s| S t | |r| j\}} |j0d|j2k(r| St | |rt | j4j0dk(rt |j0dk(rv| j4j0d} |j0d}t7t| |j2j9|| j4j2g| j:S| | S||g|Scc}wcc}wcc}w#t*$r ||| } Y&wxYw)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 rImageSet) set_functionrz)imageset expects at least 2 args, got: %srNnargsz 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 rzx%ic3HK|]}tt|ywrD)r)r')rrdexprs rGrzimageset.. s'*"#* 1Iu*s"zN expecting lambda, Lambda, or FunctionClass, not '%s'.c3>K|]}t|t ywrDrBrCs rGrzimageset.. s 4az!S! ! 4sz.arguments after mapping should be sets, not %s) fancysetsrsetexprrrr}rr'rFrcallablegetattrrzr?r^rinspect signature parametersr*r(r&r>r variablesrlamdaimagesetrd base_sets)r^rrfset_listrNrrvarnamerErryrs @rGrrp s ^$% 4y1}Ds4yPQQ$q'FE?+D A 47DG $8 G8!V !7B' 5zQ)*6+  1 AAv05aQ@1VEAI&@@!!!$//Aa0UW012*'(** 33  $&q\$*+, , 48 44&./ ! // QVV #J c8 $ 399&&'1,Q[[1AQ1FII''*KKN1affkk!SYY^^<=O@C OO =H A ! !!cA10 !C A !s$2K64K; 'LLLLc|ttfvrytd}||j|}|dkDdk(s|dkdk(ryy)zk Checks whether function ``func`` is invertible when the domain is restricted to set ``setv``. TurN)r-r.r(diff)rsetvr fdiffs rGis_function_invertible_in_setr sL  Sz c A GLLOE  duqyT1 rFcXddlm}|stjS|D]}t |t rt d|Dcgc]}|js|}}t|dkDr2d|D}t|}|g|Dcgc]}|jr|c}z}t|}d}|rS|D]K}d}||hz D]8} ||| } | t | ts| h} ||| hz j| }n|sI|}n|rSt|dk(r|jSt|ddiScc}wcc}w) aZ 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 Setsrc3.K|] }|D]}|ywrDrE)rrErs rGrz!simplify_union.. s 33s 3!Q 3Q 3sTFr)sympy.sets.handlers.unionrr$rrrJr&r7rrrErpopr) r^rrr finite_setsr] finite_setnew_argsrtnew_sets rGrr sW5 zz@#s#>? ?@ #5ann15K5 ;! 3+ 3] |$EQannqEE t9DH  AHQCZ $Q*&%gs3#*) $1v 44W=H     4yA~xxzd+U++;6FsD"D"<D'D'cb |stjS|D]}t|trt dtj |vrtj St j|}||S|D]d}|jst||hz }t|dkDr%t | t fd|jDcSt|jcS|D]S}|js|j|||jdgz}tt ||jdcSddlm}t|}d}|rA|D]9}d}||hz D]&}|||}||||hz j%|h}n|s7|}n|rAt|dk(r|j'St |ddiS) aI 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 rrc36K|]}t|ywrDr)rrrs rGrz(simplify_intersection..` sJC|C7Jsr)intersection_setsTFr)r$rrrJr&rrrRr:rErrr^rNrFr sympy.sets.handlers.intersectionrrr) r^rrvrr4rrrrrs @rGrr: s ~~@#s#>? ?@  zzTzz  ) )$ /B ~ & ::TaSJ:"$j1J166JKKaff~%&D ?? KKN +JlJ7C C D C t9DH  AHQCZ +Aq1& $1v 44gY?H    4yA~xxzT2E22rFc $t||gdd\}}t|dk(r,t|dDcgc]}|dD] }||| c}}St|dk(r)|dDcgc]}t||d||}}t |Sycc}}wcc}w)Nc"t|tSrD)rrr)s rGrHz%_handle_finite_sets.. s Jq),DrFTr7rrr)r:rr_apply_operationr) oprr  commutativerHrrr\rs rGrRrR s1a&"DTRNGU 7|qWQZLLA2a8L8LMM W HOPQ S1 U1Xq+>SSd| MSs B $B c ddlm}td}t||||}| |||}| |r |||}|t d\}}t |t r:t |t s*|t|||||j}|St |t s:t |t r*|t|||||j}|S|t||f|||||}|S)Nrrrzx y) rrr(rRr&rrJrdoit) r#rr r$rrout_x_ys rGr"r" s# c A b!Q 4C {Ah {{Ah {B a jC&86!R1X.2779C J As# 1c(:6!R1X.2779C J62r(Br2J7A>C JrFc,ddlm}t|||dS)Nr)_set_addTr$)sympy.sets.handlers.addr+r")rr r+s rGset_addr. 0 Ha ==rFc,ddlm}t|||dS)Nr)_set_subFr,)r-r1r")rr r1s rGset_subr2 0 Ha >>rFc,ddlm}t|||dS)Nr)_set_mulTr,)sympy.sets.handlers.mulr5r")rr r5s rGset_mulr7 r/rFc,ddlm}t|||dS)Nr)_set_divFr,)r6r9r")rr r9s rGset_divr: r3rFc,ddlm}t|||dS)Nr)_set_powFr,)sympy.sets.handlers.powerr<r")rr r<s rGset_powr> s2 Ha >>rFc ddlm}|||S)Nr) _set_function)sympy.sets.handlers.functionsr@)rrr@s rGrr s; A rFc*eZdZdZdfd ZdZxZS)r 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 c6t|||}||_|SrD)rr_ru)r]rurrs rGr_zSetKind.__new__ s goc<0' rFc:|jsyd|jzS)Nz SetKind()z SetKind(%s))rurXs rG__repr__zSetKind.__repr__ s   4#4#44 4rFrD)rr0r1r2r_rErrs@rGr r  s"F 5rFr )z __future__rtypingrrrr functoolsr collectionsr collections.abcr r rsympy.core.kindr r rsympy.core.basicrsympy.core.containersrrsympy.core.decoratorsrrsympy.core.evalfrsympy.core.exprrsympy.core.functionrsympy.core.logicrrrrrsympy.core.numbersrrsympy.core.operationsrsympy.core.parametersrsympy.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/r0sympy.logic.boolalgr1r2r3r4r5r6sympy.utilities.decoratorr7sympy.utilities.exceptionsr8sympy.utilities.iterablesr9r:r;r<r=sympy.utilities.miscr>r?mpmathr@rAmpmath.libmp.libmpfrBrrJrrrrrrrrrErrrrrrrrRr"r.r2r7r:r>rr rErFrGrds"99#-;;"2E' &-+3//-&KKBB;=>>0@006+,!&&FFAFF 177GGQWW !c %c c LrrjYsYxn=Cn=bcF3 cFLZZzGsiGT33)3lo7o7b05A#AJXACXAv}"@$5,pK3\ *> ? > ? ?  -5d-5rF