Example #1
0
def test_finite_basic():
    x = Symbol('x')
    A = FiniteSet(1, 2, 3)
    B = FiniteSet(3, 4, 5)
    AorB = Union(A, B)
    AandB = A.intersect(B)
    assert A.is_subset(AorB) and B.is_subset(AorB)
    assert AandB.is_subset(A)
    assert AandB == FiniteSet(3)

    assert A.inf == 1 and A.sup == 3
    assert AorB.inf == 1 and AorB.sup == 5
    assert FiniteSet(x, 1, 5).sup == Max(x, 5)
    assert FiniteSet(x, 1, 5).inf == Min(x, 1)

    # issue 7335
    assert FiniteSet(S.EmptySet) != S.EmptySet
    assert FiniteSet(FiniteSet(1, 2, 3)) != FiniteSet(1, 2, 3)
    assert FiniteSet((1, 2, 3)) != FiniteSet(1, 2, 3)

    # Ensure a variety of types can exist in a FiniteSet
    s = FiniteSet((1, 2), Float, A, -5, x, 'eggs', x**2, Interval)

    assert (A > B) is False
    assert (A >= B) is False
    assert (A < B) is False
    assert (A <= B) is False
    assert AorB > A and AorB > B
    assert AorB >= A and AorB >= B
    assert A >= A and A <= A
    assert A >= AandB and B >= AandB
    assert A > AandB and B > AandB
Example #2
0
def test_real():
    x = Symbol('x', real=True, finite=True)

    I = Interval(0, 5)
    J = Interval(10, 20)
    A = FiniteSet(1, 2, 30, x, S.Pi)
    B = FiniteSet(-4, 0)
    C = FiniteSet(100)
    D = FiniteSet('Ham', 'Eggs')

    assert all(s.is_subset(S.Reals) for s in [I, J, A, B, C])
    assert not D.is_subset(S.Reals)
    assert all((a + b).is_subset(S.Reals) for a in [I, J, A, B, C] for b in [I, J, A, B, C])
    assert not any((a + D).is_subset(S.Reals) for a in [I, J, A, B, C, D])

    assert not (I + A + D).is_subset(S.Reals)
Example #3
0
from sympy import FiniteSet
from fractions import Fraction

s = FiniteSet(1)
t = FiniteSet(1, 2)
print("Is s is subset of t ", s.is_subset(t))
print("Is t is subset of s ", t.is_subset(s))

s = FiniteSet(1, 2, 3)
ps = s.powerset()
print("Power set ", ps)

s = FiniteSet(1, 2, 3)
t = FiniteSet(1, 2, 3)
print("Is s is proper subset ", s.is_proper_subset(t))
print("Is t is proper subset ", t.is_proper_subset(s))

s = FiniteSet(1, 2, 3)
t = FiniteSet(1, 2, 3, 4)
print("Is s is proper subset ", s.is_proper_subset(t))
print("Is t is proper subset ", t.is_proper_subset(s))
Example #4
0
# Igualdad
print('-' * 30)
A = FiniteSet(1, 2, 3)
B = FiniteSet(1, 3, 2)
print(A == B)

A = FiniteSet(1, 2, 3)
B = FiniteSet(1, 3, 4)
print(A == B)

# Subconjunto y subconjunto propio
print('-' * 30)
A = FiniteSet(1, 2, 3)
B = FiniteSet(1, 2, 3, 4, 5)
print(A.is_subset(B))

# A == B. El test de subconjunto propio da falso
print('-' * 30)
B = FiniteSet(2, 1, 3)
print(A.is_proper_subset(B))

# Union de dos conjuntos
print('-' * 30)
A = FiniteSet(1, 2, 3)
B = FiniteSet(2, 4, 6)
print(A.union(B))

# Interseccion de dos conjuntos
print('-' * 30)
A = FiniteSet(1, 2)
numberslist = [1, 99, 840]
fifthset = FiniteSet(*numberslist)
print(fifthset) #print {1, 99, 840}
print(set(numberslist)) #print {840, 1, 99}
#sets ignore repeats of a member and don't keep track of the order
numberslist2 = [1, 99, 7392, 99]
sixthset = FiniteSet(*numberslist2)
print(sixthset) #print {1, 99, 7392}
for eachsixthset in sixthset:
	print(eachsixthset) #print 1\n 99\n 7392

#A set is a subset of another set if all the members are also members of the other set.  Remember, all.
seventhset = FiniteSet(999, 439, 20984)
eigthset = FiniteSet(999, 69, 48)
ninthset = FiniteSet(999, 69)
print(seventhset.is_subset(eigthset)) #print False
print(eigthset.is_subset(seventhset)) #print False
print(ninthset.is_subset(eigthset)) #print True
#A set is a superset if the set contains all of the members.  Remember, contains.
print(ninthset.is_superset(eigthset)) #print False
print(eigthset.is_superset(ninthset)) #print True

#The power set is the set of all possible subsets
tenthset = FiniteSet(20, 55, 41, 98)
print(tenthset.powerset()) #print {EmptySet(), {20}, {41}, ..., {20, 55, 98}, {41, 55, 98}, {20, 41, 55, 98}}

seventhset = FiniteSet(999, 439, 20984)
eigthset = FiniteSet(999, 69, 48)
ninthset = FiniteSet(999, 69)
print(seventhset.is_proper_subset(eigthset)) #print False
print(eigthset.is_proper_subset(seventhset)) #print False
# 集合オブジェクトの特徴
# 集合オブジェクトは重複を許さない
s1 = FiniteSet(1, 3, 3, 5)
print(s1)

# 集合オブジェクトの順序は不定で、全ての要素が等しければ等価なオブジェクトである。
s2 = FiniteSet(5, 1, 3)
print(s1 == s2)

# 以下、集合に対する概念(若干マイナーな概念も含むかも...)。
sub = FiniteSet(1, 2)
super = FiniteSet(1, 2, 3)

# AはBの部分集合か?
print(sub.is_subset(super))

# AはBの上位集合か?
print(super.is_superset(sub))

# AはBの真部分集合か?
# ※真部分集合:Bが、Aにない要素を一つ以上含んでいる場合、BをAの真部分集合と呼ぶ。
print(sub.is_proper_subset(super))

# AはBの真上位集合か?
print(super.is_proper_superset(sub))

# 通常の上位集合と、真上位集合の違い。
print(FiniteSet(3, 1, 2).is_superset(super))
print(FiniteSet(3, 1, 2).is_proper_superset(super))
Example #7
0
s

a = FiniteSet(1, 2, 3)

for member in a:
    print(member)

a = FiniteSet(3, 4, 5)
t = FiniteSet(5, 4, 3)

s == t

a = FiniteSet(1)
t = FiniteSet(1, 2)

s.is_subset(t)

t.is_subset(t)

s = FiniteSet(1, 2, 3)
ps = s.powerset()
ps

len(ps)

s = FiniteSet(1, 2, 3)
t = FiniteSet(1, 2, 3)

s.is_proper_subset(t)

t = FiniteSet(1, 2, 3, 4)
Example #8
0
               #Two sets are said to be equal when they have the same mebers, irrelevant of their order

>>> s=FiniteSet(3,4,5)
>>> t=FiniteSet(5,4,3)
>>> s==t
True


          #Subsets,Supersets and Power Sets

               #A set s is a subset of another set t  if all the members of s are also members of t

>>> s=FiniteSet(1)
>>> t=FiniteSet(1,2)
>>> s.is_subset(t)
True
>>> t.is_subset(s)
False

               #An empty set is also a susbset of every set.
               #Also, any set is a subset of itself


>>> e=FiniteSet()
>>> e.is_subset(t)
True
>>> e.is_subset(s)
True
>>> s.is_subset(s)
True
Example #9
0
# Check whether a number is in the set
4 in s  # False

# Empty Set
s = FiniteSet()     # EmptySet()

# Set Repetition and Order
members = [1, 2, 3, 2]
FiniteSet(*members)     # {1, 2, 3}
for member in s:
    print(member)       # 1, 2, 3

# Subsets -> if all the members of s are also a member of t
s = FiniteSet(1)
t = FiniteSet(1,2)
s.is_subset(t)      # True
t.is_subset(s)      # False

# Supersets -> if t contains all of the members contained in s
s.is_superset(t)    # True
t.is_superset(s)    # True

# Powerset -> is the set of all possible subsets of s
s = FiniteSet(1, 2, 3)
ps = s.powerset()
ps                  # {{1}, {1, 2}, {1, 3}, {1, 2, 3}, {2}, {2, 3}, {3}, EmptySet()}

len(ps)             # 8

# Proper subset -> if all the members of s are also in t and t has at least one member that is not in s
s = FiniteSet(1, 2, 3)