Пример #1
0
def test_powerset():
    # EmptySet
    A = FiniteSet()
    pset = A.powerset()
    assert len(pset) == 1
    assert pset == FiniteSet(S.EmptySet)

    # FiniteSets
    A = FiniteSet(1, 2)
    pset = A.powerset()
    assert len(pset) == 2 ** len(A)
    assert pset == FiniteSet(FiniteSet(), FiniteSet(1), FiniteSet(2), A)
    # Not finite sets
    I = Interval(0, 1)
    raises(NotImplementedError, I.powerset)
Пример #2
0
def test_powerset():
    # EmptySet
    A = FiniteSet()
    pset = A.powerset()
    assert len(pset) == 1
    assert pset == FiniteSet(S.EmptySet)

    # FiniteSets
    A = FiniteSet(1, 2)
    pset = A.powerset()
    assert len(pset) == 2**len(A)
    assert pset == FiniteSet(FiniteSet(), FiniteSet(1), FiniteSet(2), A)
    # Not finite sets
    I = Interval(0, 1)
    raises(NotImplementedError, I.powerset)
Пример #3
0
##------ Utilizando sympy -------
# Utilizando FiniteSet de sympy
"""Para que el import no de error, abrir el power shell como admin
en la carpeta donde este el archivo (en mi caso, que utilizo el 
sublime text 3) o si ejecutais desde el interprete por consola, en ambos
casos teneis que poner pip install sympy"""
print('-' * 30)
from sympy import FiniteSet
C = FiniteSet(1, 2, 3)
print(C)

# Generando el conjunto potencia. Esto no se puede
# hacer utilizando el conjunto por defecto de python.
print('-' * 30)
print(C.powerset())

# Cardinalidad
print('-' * 30)
print(
    "La cardinalidad del conjunto potencia del conjunto C = {0} es {1}".format(
        C, len(C.powerset())))

# 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)
Пример #4
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))
	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
print(ninthset.is_proper_subset(eigthset)) #print True
print(ninthset.is_proper_superset(eigthset)) #print False
print(eigthset.is_proper_superset(ninthset)) #print True

tenthset = FiniteSet(1, 2, 3)
eleventhset = FiniteSet(2, 4, 6)
print(tenthset.union(eleventhset)) #print {1, 2, 3, 4, 6}
print(tenthset.intersect(eleventhset)) #print {2}
#we can apply union and intersect to more than two sets.
Run this cell before any other
Declare any other sets here if you'd like
"""
from sympy import FiniteSet, ProductSet
from sympy.sets.powerset import PowerSet

"""Finite Sets: represents a finite set of discrete numbers"""

A = FiniteSet(1, 2, 3, 4, 5)
B = FiniteSet(5, 6, 7, 8, 9)
C = FiniteSet(9, 10, 11, 12)

#%%
"""Powersets: all possible sets in a set"""

E = A.powerset() # Returns a new finite set with a finite set
F = PowerSet(A).rewrite(FiniteSet) # Returns a setwith many finite sets

print(F)

#%%
"""Cartesian product: """

cp_m1 = ProductSet(A, B) # Uses sympy function 
cp_m2 = A*B # Sympy syntax for finite sets

print()



Пример #7
0
from sympy import FiniteSet
s = FiniteSet(1, 2, 3)
ps = s.powerset()
print(ps)

# from sympy import FiniteSet
# s = FiniteSet(1, 2, 3)
# t = FiniteSet(2, 4, 6)
# unioned = s.union(t)
# print(unioned)

# from sympy import FiniteSet
# s = FiniteSet(1, 2)
# t = FiniteSet(2, 3)
# intersected = s.intersect(t)
# print(intersected)

# from sympy import FiniteSet
# s = FiniteSet(1, 2)
# t = FiniteSet(3, 4)
# p = s*t
# # u = FiniteSet(5, 6)
# # p = s*t*u
# for elem in p:
#         print(elem)