modelparameters.sympy.sets package¶
Submodules¶
modelparameters.sympy.sets.conditionset module¶
- class modelparameters.sympy.sets.conditionset.ConditionSet(sym, condition, base_set)[source]¶
Bases:
Set
Set of elements which satisfies a given condition.
{x | condition(x) is True for x in S}
Examples
>>> from .. import Symbol, S, ConditionSet, Lambda, pi, Eq, sin, Interval >>> x = Symbol('x') >>> sin_sols = ConditionSet(x, Eq(sin(x), 0), Interval(0, 2*pi)) >>> 2*pi in sin_sols True >>> pi/2 in sin_sols False >>> 3*pi in sin_sols False >>> 5 in ConditionSet(x, x**2 > 4, S.Reals) True
- property base_set¶
- property condition¶
- contains(other)[source]¶
Returns True if ‘other’ is contained in ‘self’ as an element.
As a shortcut it is possible to use the ‘in’ operator:
Examples
>>> from .. import Interval >>> Interval(0, 1).contains(0.5) True >>> 0.5 in Interval(0, 1) True
- default_assumptions = {}¶
- property sym¶
modelparameters.sympy.sets.contains module¶
- class modelparameters.sympy.sets.contains.Contains(x, S)[source]¶
Bases:
BooleanFunction
Asserts that x is an element of the set S
Examples
>>> from .. import Symbol, Integer, S >>> from .contains import Contains >>> Contains(Integer(2), S.Integers) True >>> Contains(Integer(-2), S.Naturals) False >>> i = Symbol('i', integer=True) >>> Contains(i, S.Naturals) Contains(i, S.Naturals)
References
- default_assumptions = {}¶
- classmethod eval(x, S)[source]¶
Returns a canonical form of cls applied to arguments args.
The eval() method is called when the class cls is about to be instantiated and it should return either some simplified instance (possible of some other class), or if the class cls should be unmodified, return None.
Examples of eval() for the function “sign”¶
@classmethod def eval(cls, arg):
- if arg is S.NaN:
return S.NaN
if arg is S.Zero: return S.Zero if arg.is_positive: return S.One if arg.is_negative: return S.NegativeOne if isinstance(arg, Mul):
coeff, terms = arg.as_coeff_Mul(rational=True) if coeff is not S.One:
return cls(coeff) * cls(terms)
modelparameters.sympy.sets.fancysets module¶
- class modelparameters.sympy.sets.fancysets.ComplexRegion(sets, polar=False)[source]¶
Bases:
Set
Represents the Set of all Complex Numbers. It can represent a region of Complex Plane in both the standard forms Polar and Rectangular coordinates.
Polar Form Input is in the form of the ProductSet or Union of ProductSets of the intervals of r and theta, & use the flag polar=True.
Z = {z in C | z = r*[cos(theta) + I*sin(theta)], r in [r], theta in [theta]}
Rectangular Form Input is in the form of the ProductSet or Union of ProductSets of interval of x and y the of the Complex numbers in a Plane. Default input type is in rectangular form.
Z = {z in C | z = x + I*y, x in [Re(z)], y in [Im(z)]}
Examples
>>> from .fancysets import ComplexRegion >>> from ..sets import Interval >>> from .. import S, I, Union >>> a = Interval(2, 3) >>> b = Interval(4, 6) >>> c = Interval(1, 8) >>> c1 = ComplexRegion(a*b) # Rectangular Form >>> c1 ComplexRegion(Interval(2, 3) x Interval(4, 6), False)
c1 represents the rectangular region in complex plane surrounded by the coordinates (2, 4), (3, 4), (3, 6) and (2, 6), of the four vertices.
>>> c2 = ComplexRegion(Union(a*b, b*c)) >>> c2 ComplexRegion(Union(Interval(2, 3) x Interval(4, 6), Interval(4, 6) x Interval(1, 8)), False)
c2 represents the Union of two rectangular regions in complex plane. One of them surrounded by the coordinates of c1 and other surrounded by the coordinates (4, 1), (6, 1), (6, 8) and (4, 8).
>>> 2.5 + 4.5*I in c1 True >>> 2.5 + 6.5*I in c1 False
>>> r = Interval(0, 1) >>> theta = Interval(0, 2*S.Pi) >>> c2 = ComplexRegion(r*theta, polar=True) # Polar Form >>> c2 # unit Disk ComplexRegion(Interval(0, 1) x Interval.Ropen(0, 2*pi), True)
c2 represents the region in complex plane inside the Unit Disk centered at the origin.
>>> 0.5 + 0.5*I in c2 True >>> 1 + 2*I in c2 False
>>> unit_disk = ComplexRegion(Interval(0, 1)*Interval(0, 2*S.Pi), polar=True) >>> upper_half_unit_disk = ComplexRegion(Interval(0, 1)*Interval(0, S.Pi), polar=True) >>> intersection = unit_disk.intersect(upper_half_unit_disk) >>> intersection ComplexRegion(Interval(0, 1) x Interval(0, pi), True) >>> intersection == upper_half_unit_disk True
See also
- property a_interval¶
Return the union of intervals of x when, self is in rectangular form, or the union of intervals of r when self is in polar form.
Examples
>>> from .. import Interval, ComplexRegion, Union >>> a = Interval(2, 3) >>> b = Interval(4, 5) >>> c = Interval(1, 7) >>> C1 = ComplexRegion(a*b) >>> C1.a_interval Interval(2, 3) >>> C2 = ComplexRegion(Union(a*b, b*c)) >>> C2.a_interval Union(Interval(2, 3), Interval(4, 5))
- property args¶
Returns a tuple of arguments of ‘self’.
Examples
>>> from .. import cot >>> from ..abc import x, y
>>> cot(x).args (x,)
>>> cot(x).args[0] x
>>> (x*y).args (x, y)
>>> (x*y).args[1] y
Notes
Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).
- property b_interval¶
Return the union of intervals of y when, self is in rectangular form, or the union of intervals of theta when self is in polar form.
Examples
>>> from .. import Interval, ComplexRegion, Union >>> a = Interval(2, 3) >>> b = Interval(4, 5) >>> c = Interval(1, 7) >>> C1 = ComplexRegion(a*b) >>> C1.b_interval Interval(4, 5) >>> C2 = ComplexRegion(Union(a*b, b*c)) >>> C2.b_interval Interval(1, 7)
- default_assumptions = {}¶
- property expr¶
- classmethod from_real(sets)[source]¶
Converts given subset of real numbers to a complex region.
Examples
>>> from .. import Interval, ComplexRegion >>> unit = Interval(0,1) >>> ComplexRegion.from_real(unit) ComplexRegion(Interval(0, 1) x {0}, False)
- is_ComplexRegion = True¶
- property polar¶
Returns True if self is in polar form.
Examples
>>> from .. import Interval, ComplexRegion, Union, S >>> a = Interval(2, 3) >>> b = Interval(4, 5) >>> theta = Interval(0, 2*S.Pi) >>> C1 = ComplexRegion(a*b) >>> C1.polar False >>> C2 = ComplexRegion(a*theta, polar=True) >>> C2.polar True
- property psets¶
Return a tuple of sets (ProductSets) input of the self.
Examples
>>> from .. import Interval, ComplexRegion, Union >>> a = Interval(2, 3) >>> b = Interval(4, 5) >>> c = Interval(1, 7) >>> C1 = ComplexRegion(a*b) >>> C1.psets (Interval(2, 3) x Interval(4, 5),) >>> C2 = ComplexRegion(Union(a*b, b*c)) >>> C2.psets (Interval(2, 3) x Interval(4, 5), Interval(4, 5) x Interval(1, 7))
- property sets¶
Return raw input sets to the self.
Examples
>>> from .. import Interval, ComplexRegion, Union >>> a = Interval(2, 3) >>> b = Interval(4, 5) >>> c = Interval(1, 7) >>> C1 = ComplexRegion(a*b) >>> C1.sets Interval(2, 3) x Interval(4, 5) >>> C2 = ComplexRegion(Union(a*b, b*c)) >>> C2.sets Union(Interval(2, 3) x Interval(4, 5), Interval(4, 5) x Interval(1, 7))
- property variables¶
- class modelparameters.sympy.sets.fancysets.Complexes(*args, **kwargs)[source]¶
Bases:
ComplexRegion
- default_assumptions = {}¶
- class modelparameters.sympy.sets.fancysets.ImageSet(lamda, base_set)[source]¶
Bases:
Set
Image of a set under a mathematical function. The transformation must be given as a Lambda function which has as many arguments as the elements of the set upon which it operates, e.g. 1 argument when acting on the set of integers or 2 arguments when acting on a complex region.
This function is not normally called directly, but is called from imageset.
Examples
>>> from .. import Symbol, S, pi, Dummy, Lambda >>> from .sets import FiniteSet, Interval >>> from .fancysets import ImageSet
>>> x = Symbol('x') >>> N = S.Naturals >>> squares = ImageSet(Lambda(x, x**2), N) # {x**2 for x in N} >>> 4 in squares True >>> 5 in squares False
>>> FiniteSet(0, 1, 2, 3, 4, 5, 6, 7, 9, 10).intersect(squares) {1, 4, 9}
>>> square_iterable = iter(squares) >>> for i in range(4): ... next(square_iterable) 1 4 9 16
If you want to get value for x = 2, 1/2 etc. (Please check whether the x value is in base_set or not before passing it as args)
>>> squares.lamda(2) 4 >>> squares.lamda(S(1)/2) 1/4
>>> n = Dummy('n') >>> solutions = ImageSet(Lambda(n, n*pi), S.Integers) # solutions of sin(x) = 0 >>> dom = Interval(-1, 1) >>> dom.intersect(solutions) {0}
See also
sympy.sets.sets.imageset
- property base_set¶
- default_assumptions = {}¶
- property is_iterable¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- property lamda¶
- class modelparameters.sympy.sets.fancysets.Integers(*args, **kwargs)[source]¶
Bases:
Set
Represents all integers: positive, negative and zero. This set is also available as the Singleton, S.Integers.
Examples
>>> from .. import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Integers) >>> next(iterable) 0 >>> next(iterable) 1 >>> next(iterable) -1 >>> next(iterable) 2
>>> pprint(S.Integers.intersect(Interval(-4, 4))) {-4, -3, ..., 4}
- default_assumptions = {}¶
- is_iterable = True¶
- class modelparameters.sympy.sets.fancysets.Naturals(*args, **kwargs)[source]¶
Bases:
Set
Represents the natural numbers (or counting numbers) which are all positive integers starting from 1. This set is also available as the Singleton, S.Naturals.
Examples
>>> from .. import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Naturals) >>> next(iterable) 1 >>> next(iterable) 2 >>> next(iterable) 3 >>> pprint(S.Naturals.intersect(Interval(0, 10))) {1, 2, ..., 10}
See also
- default_assumptions = {}¶
- is_iterable = True¶
- class modelparameters.sympy.sets.fancysets.Naturals0(*args, **kwargs)[source]¶
Bases:
Naturals
Represents the whole numbers which are all the non-negative integers, inclusive of zero.
- default_assumptions = {}¶
- class modelparameters.sympy.sets.fancysets.Range(*args)[source]¶
Bases:
Set
Represents a range of integers. Can be called as Range(stop), Range(start, stop), or Range(start, stop, step); when stop is not given it defaults to 1.
Range(stop) is the same as Range(0, stop, 1) and the stop value (juse as for Python ranges) is not included in the Range values.
>>> from .. import Range >>> list(Range(3)) [0, 1, 2]
The step can also be negative:
>>> list(Range(10, 0, -2)) [10, 8, 6, 4, 2]
The stop value is made canonical so equivalent ranges always have the same args:
>>> Range(0, 10, 3) Range(0, 12, 3)
Infinite ranges are allowed. If the starting point is infinite, then the final value is
stop - step
. To iterate such a range, it needs to be reversed:>>> from .. import oo >>> r = Range(-oo, 1) >>> r[-1] 0 >>> next(iter(r)) Traceback (most recent call last): ... ValueError: Cannot iterate over Range with infinite start >>> next(iter(r.reversed)) 0
Although Range is a set (and supports the normal set operations) it maintains the order of the elements and can be used in contexts where range would be used.
>>> from .. import Interval >>> Range(0, 10, 2).intersect(Interval(3, 7)) Range(4, 8, 2) >>> list(_) [4, 6]
Athough slicing of a Range will always return a Range – possibly empty – an empty set will be returned from any intersection that is empty:
>>> Range(3)[:0] Range(0, 0, 1) >>> Range(3).intersect(Interval(4, oo)) EmptySet() >>> Range(3).intersect(Range(4, oo)) EmptySet()
- default_assumptions = {}¶
- is_iterable = True¶
- property reversed¶
Return an equivalent Range in the opposite order.
Examples
>>> from .. import Range >>> Range(10).reversed Range(9, -1, -1)
- property size¶
- property start¶
- property step¶
- property stop¶
- class modelparameters.sympy.sets.fancysets.Reals(*args, **kwargs)[source]¶
Bases:
Interval
- default_assumptions = {}¶
- modelparameters.sympy.sets.fancysets.normalize_theta_set(theta)[source]¶
Normalize a Real Set theta in the Interval [0, 2*pi). It returns a normalized value of theta in the Set. For Interval, a maximum of one cycle [0, 2*pi], is returned i.e. for theta equal to [0, 10*pi], returned normalized value would be [0, 2*pi). As of now intervals with end points as non-multiples of pi is not supported.
- Raises:
NotImplementedError – The algorithms for Normalizing theta Set are not yet implemented.
ValueError – The input is not valid, i.e. the input is not a real set.
RuntimeError – It is a bug, please report to the github issue tracker.
Examples
>>> from .fancysets import normalize_theta_set >>> from .. import Interval, FiniteSet, pi >>> normalize_theta_set(Interval(9*pi/2, 5*pi)) Interval(pi/2, pi) >>> normalize_theta_set(Interval(-3*pi/2, pi/2)) Interval.Ropen(0, 2*pi) >>> normalize_theta_set(Interval(-pi/2, pi/2)) Union(Interval(0, pi/2), Interval.Ropen(3*pi/2, 2*pi)) >>> normalize_theta_set(Interval(-4*pi, 3*pi)) Interval.Ropen(0, 2*pi) >>> normalize_theta_set(Interval(-3*pi/2, -pi/2)) Interval(pi/2, 3*pi/2) >>> normalize_theta_set(FiniteSet(0, pi, 3*pi)) {0, pi}
modelparameters.sympy.sets.sets module¶
- class modelparameters.sympy.sets.sets.Complement(a, b, evaluate=True)[source]¶
Bases:
Set
,EvalfMixin
Represents the set difference or relative complement of a set with another set.
A - B = {x in A| x \notin B}
Examples
>>> from .. import Complement, FiniteSet >>> Complement(FiniteSet(0, 1, 2), FiniteSet(1)) {0, 2}
See also
References
[1] - default_assumptions = {}¶
- is_Complement = True¶
- static reduce(A, B)[source]¶
Simplify a
Complement
.
- class modelparameters.sympy.sets.sets.EmptySet(*args, **kwargs)[source]¶
Bases:
Set
Represents the empty set. The empty set is available as a singleton as S.EmptySet.
Examples
>>> from .. import S, Interval >>> S.EmptySet EmptySet()
>>> Interval(1, 2).intersect(S.EmptySet) EmptySet()
See also
References
[1] - default_assumptions = {}¶
- is_EmptySet = True¶
- is_FiniteSet = True¶
- class modelparameters.sympy.sets.sets.FiniteSet(*args, **kwargs)[source]¶
Bases:
Set
,EvalfMixin
Represents a finite set of discrete numbers
Examples
>>> from .. import FiniteSet >>> FiniteSet(1, 2, 3, 4) {1, 2, 3, 4} >>> 3 in FiniteSet(1, 2, 3, 4) True
>>> 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] - compare(other)[source]¶
Return -1, 0, 1 if the object is smaller, equal, or greater than other.
Not in the mathematical sense. If the object is of a different type from the “other” then their classes are ordered according to the sorted_classes list.
Examples
>>> from ..abc import x, y >>> x.compare(y) -1 >>> x.compare(x) 0 >>> y.compare(x) 1
- default_assumptions = {}¶
- is_FiniteSet = True¶
- is_iterable = True¶
- property measure¶
The (Lebesgue) measure of ‘self’
Examples
>>> from .. import Interval, Union >>> Interval(0, 1).measure 1 >>> Union(Interval(0, 1), Interval(2, 3)).measure 2
- class modelparameters.sympy.sets.sets.Intersection(*args, **kwargs)[source]¶
Bases:
Set
Represents an intersection of sets as a
Set
.Examples
>>> from .. 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
References
[1] - default_assumptions = {}¶
- is_Intersection = True¶
- property is_iterable¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- static reduce(args)[source]¶
Return a simplified intersection by applying rules.
We first start with global rules like ‘if any empty sets, return empty set’ and ‘distribute unions’.
Then we iterate through all pairs and ask the constituent sets if they can simplify themselves with any other constituent
- class modelparameters.sympy.sets.sets.Interval(start, end, left_open=False, right_open=False)[source]¶
Bases:
Set
,EvalfMixin
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 .. 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] - default_assumptions = {}¶
- property end¶
The right end point of ‘self’.
This property takes the same value as the ‘sup’ property.
Examples
>>> from .. import Interval >>> Interval(0, 1).end 1
- is_Interval = True¶
- property is_left_unbounded¶
Return
True
if the left endpoint is negative infinity.
- property is_right_unbounded¶
Return
True
if the right endpoint is positive infinity.
- property left¶
The left end point of ‘self’.
This property takes the same value as the ‘inf’ property.
Examples
>>> from .. import Interval >>> Interval(0, 1).start 0
- property left_open¶
True if ‘self’ is left-open.
Examples
>>> from .. import Interval >>> Interval(0, 1, left_open=True).left_open True >>> Interval(0, 1, left_open=False).left_open False
- property right¶
The right end point of ‘self’.
This property takes the same value as the ‘sup’ property.
Examples
>>> from .. import Interval >>> Interval(0, 1).end 1
- property right_open¶
True if ‘self’ is right-open.
Examples
>>> from .. import Interval >>> Interval(0, 1, right_open=True).right_open True >>> Interval(0, 1, right_open=False).right_open False
- property start¶
The left end point of ‘self’.
This property takes the same value as the ‘inf’ property.
Examples
>>> from .. import Interval >>> Interval(0, 1).start 0
- class modelparameters.sympy.sets.sets.ProductSet(*sets, **assumptions)[source]¶
Bases:
Set
Represents a Cartesian Product of Sets.
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 .. import Interval, FiniteSet, ProductSet >>> I = Interval(0, 5); S = FiniteSet(1, 2, 3) >>> ProductSet(I, S) Interval(0, 5) x {1, 2, 3}
>>> (2, 2) in ProductSet(I, S) True
>>> Interval(0, 1) * Interval(0, 1) # The unit square Interval(0, 1) x Interval(0, 1)
>>> coin = FiniteSet('H', 'T') >>> set(coin**2) {(H, H), (H, T), (T, H), (T, T)}
Notes
Passes most operations down to the argument sets
Flattens Products of ProductSets
References
[1] - default_assumptions = {}¶
- is_ProductSet = True¶
- property is_iterable¶
A property method which tests whether a set is iterable or not. Returns True if set is iterable, otherwise returns False.
Examples
>>> from .. import FiniteSet, Interval, ProductSet >>> I = Interval(0, 1) >>> A = FiniteSet(1, 2, 3, 4, 5) >>> I.is_iterable False >>> A.is_iterable True
- property sets¶
- class modelparameters.sympy.sets.sets.Set(*args)[source]¶
Bases:
Basic
The base class for any kind of set.
This is not meant to be used directly as a container of items. It does not behave like the builtin
set
; seeFiniteSet
for that.Real intervals are represented by the
Interval
class and unions of sets by theUnion
class. The empty set is represented by theEmptySet
class and available as a singleton asS.EmptySet
.- property boundary¶
The boundary or frontier of a set
A point x is on the boundary of a set S if
x is in the closure of S. I.e. Every neighborhood of x contains a point in S.
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 .. import Interval >>> Interval(0, 1).boundary {0, 1} >>> Interval(0, 1, True, False).boundary {0, 1}
- property closure¶
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 .. import S, Interval >>> S.Reals.closure S.Reals >>> Interval(0, 1).closure Interval(0, 1)
- complement(universe)[source]¶
The complement of ‘self’ w.r.t the given the universe.
Examples
>>> from .. import Interval, S >>> Interval(0, 1).complement(S.Reals) Union(Interval.open(-oo, 0), Interval.open(1, oo))
>>> Interval(0, 1).complement(S.UniversalSet) UniversalSet() \ Interval(0, 1)
- contains(other)[source]¶
Returns True if ‘other’ is contained in ‘self’ as an element.
As a shortcut it is possible to use the ‘in’ operator:
Examples
>>> from .. import Interval >>> Interval(0, 1).contains(0.5) True >>> 0.5 in Interval(0, 1) True
- default_assumptions = {}¶
- property inf¶
The infimum of ‘self’
Examples
>>> from .. import Interval, Union >>> Interval(0, 1).inf 0 >>> Union(Interval(0, 1), Interval(2, 3)).inf 0
- property interior¶
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 .. import Interval >>> Interval(0, 1).interior Interval.open(0, 1) >>> Interval(0, 1).boundary.interior EmptySet()
- intersect(other)[source]¶
Returns the intersection of ‘self’ and ‘other’.
>>> from .. import Interval
>>> Interval(1, 3).intersect(Interval(1, 2)) Interval(1, 2)
>>> from .. 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()
- intersection(other)[source]¶
Alias for
intersect()
- is_Complement = None¶
- is_ComplexRegion = False¶
- is_EmptySet = None¶
- is_FiniteSet = False¶
- is_Intersection = None¶
- is_Interval = False¶
- is_ProductSet = False¶
- is_Union = False¶
- is_UniversalSet = None¶
- property is_closed¶
A property method to check whether a set is closed. A set is closed if it’s complement is an open set.
Examples
>>> from .. import Interval >>> Interval(0, 1).is_closed True
- is_disjoint(other)[source]¶
Returns True if ‘self’ and ‘other’ are disjoint
Examples
>>> from .. import Interval >>> Interval(0, 2).is_disjoint(Interval(1, 2)) False >>> Interval(0, 2).is_disjoint(Interval(3, 4)) True
References
[1]
- is_interval = False¶
- is_iterable = False¶
- is_number = False¶
- property is_open¶
Property method to check whether a set is open. A set is open if and only if it has an empty intersection with its boundary.
Examples
>>> from .. import S >>> S.Reals.is_open True
- is_proper_subset(other)[source]¶
Returns True if ‘self’ is a proper subset of ‘other’.
Examples
>>> from .. import Interval >>> Interval(0, 0.5).is_proper_subset(Interval(0, 1)) True >>> Interval(0, 1).is_proper_subset(Interval(0, 1)) False
- is_proper_superset(other)[source]¶
Returns True if ‘self’ is a proper superset of ‘other’.
Examples
>>> from .. import Interval >>> Interval(0, 1).is_proper_superset(Interval(0, 0.5)) True >>> Interval(0, 1).is_proper_superset(Interval(0, 1)) False
- is_subset(other)[source]¶
Returns True if ‘self’ is a subset of ‘other’.
Examples
>>> from .. import Interval >>> Interval(0, 0.5).is_subset(Interval(0, 1)) True >>> Interval(0, 1).is_subset(Interval(0, 1, left_open=True)) False
- is_superset(other)[source]¶
Returns True if ‘self’ is a superset of ‘other’.
Examples
>>> from .. import Interval >>> Interval(0, 0.5).is_superset(Interval(0, 1)) False >>> Interval(0, 1).is_superset(Interval(0, 1, left_open=True)) True
- isdisjoint(other)[source]¶
Alias for
is_disjoint()
- issubset(other)[source]¶
Alias for
is_subset()
- issuperset(other)[source]¶
Alias for
is_superset()
- property measure¶
The (Lebesgue) measure of ‘self’
Examples
>>> from .. import Interval, Union >>> Interval(0, 1).measure 1 >>> Union(Interval(0, 1), Interval(2, 3)).measure 2
- powerset()[source]¶
Find the Power set of ‘self’.
Examples
>>> from .. import FiniteSet, EmptySet >>> A = EmptySet() >>> A.powerset() {EmptySet()} >>> A = FiniteSet(1, 2) >>> a, b, c = FiniteSet(1), FiniteSet(2), FiniteSet(1, 2) >>> A.powerset() == FiniteSet(a, b, c, EmptySet()) True
References
[1]
- property sup¶
The supremum of ‘self’
Examples
>>> from .. import Interval, Union >>> Interval(0, 1).sup 1 >>> Union(Interval(0, 1), Interval(2, 3)).sup 3
- symmetric_difference(other)[source]¶
Returns symmetric difference of self and other.
Examples
>>> from .. 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 .. import S, EmptySet >>> S.Reals.symmetric_difference(EmptySet()) S.Reals
References
[1]
- union(other)[source]¶
Returns the union of ‘self’ and ‘other’.
Examples
As a shortcut it is possible to use the ‘+’ operator:
>>> from .. 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(Interval.Lopen(1, 2), {3})
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))
- class modelparameters.sympy.sets.sets.SymmetricDifference(a, b, evaluate=True)[source]¶
Bases:
Set
Represents the set of elements which are in either of the sets and not in their intersection.
Examples
>>> from .. import SymmetricDifference, FiniteSet >>> SymmetricDifference(FiniteSet(1, 2, 3), FiniteSet(3, 4, 5)) {1, 2, 4, 5}
See also
References
[1] - default_assumptions = {}¶
- is_SymmetricDifference = True¶
- class modelparameters.sympy.sets.sets.Union(*args, **kwargs)[source]¶
Bases:
Set
,EvalfMixin
Represents a union of sets as a
Set
.Examples
>>> from .. 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
References
[1] - default_assumptions = {}¶
- is_Union = True¶
- property is_iterable¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- class modelparameters.sympy.sets.sets.UniversalSet(*args, **kwargs)[source]¶
Bases:
Set
Represents the set of all things. The universal set is available as a singleton as S.UniversalSet
Examples
>>> from .. import S, Interval >>> S.UniversalSet UniversalSet()
>>> Interval(1, 2).intersect(S.UniversalSet) Interval(1, 2)
See also
References
[1] - default_assumptions = {}¶
- is_UniversalSet = True¶
- modelparameters.sympy.sets.sets.imageset(*args)[source]¶
Return an image of the set under transformation
f
.If this function can’t compute the image, it returns an unevaluated ImageSet object.
\[{ f(x) | x \in self }\]Examples
>>> from .. import S, Interval, Symbol, imageset, sin, Lambda >>> from ..abc import x, y
>>> 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(_x, _x + x), 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), S.Integers)
See also
sympy.sets.fancysets.ImageSet