本文整理汇总了Python中sympy.FiniteSet.union方法的典型用法代码示例。如果您正苦于以下问题:Python FiniteSet.union方法的具体用法?Python FiniteSet.union怎么用?Python FiniteSet.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.FiniteSet
的用法示例。
在下文中一共展示了FiniteSet.union方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Type_A_Interval_III
# 需要导入模块: from sympy import FiniteSet [as 别名]
# 或者: from sympy.FiniteSet import union [as 别名]
class Type_A_Interval_III(object):
#generate interval of type: {x, y, ...} (Finite set) or a Singleton - must not result in an EmptySet()
def __init__(self):
self.set_str = ""
self.val_lst = []
self.interval = FiniteSet()
def generate_interval(self):
if randint(0, 1) == 0:
#generate FiniteSet
amount = randint(1, 5)
for i in range(amount):
if self.val_lst == []:
self.val_lst.append(randint(-15,15))
else:
self.val_lst.append(randint(self.val_lst[i-1]-5, self.val_lst[i-1]+5))
else:
#generate Singleton
self.val_lst.append(randint(-20, 20))
for i in range(len(self.val_lst)):
self.interval = self.interval.union(FiniteSet(self.val_lst[i]))
self.set_str += '\{'+str(self.interval)+'\}'
示例2: set_second_part
# 需要导入模块: from sympy import FiniteSet [as 别名]
# 或者: from sympy.FiniteSet import union [as 别名]
def set_second_part(self, num, element):
set_str = ""
#set_type = choice(['finite_set', 'infinite_set', 'empty_set', 'powerset'])
#self.set_type = choice(['empty_set', 'finite_set', 'infinite_set'])
self.set_type = choice(['infinite_set', 'empty_set', 'finite_set'])
uberset = ""
x = 0
y = 0
temp_str = ''
temp_set = None
#generate set in formal notation: {x | x in R and ...}
if num == 0:
uberset = self.f_set_dict[element] if element != 'x' else self.f_set_dict[choice(list(self.f_set_dict.keys()))]
set_str += ' \ | \ '+element+'\in'+uberset
set_str += '\wedge \ '
if self.set_type == 'finite_set':
self.set_description[0] = 'finite_set'
c = choice([0, 1, 2, 3])
if c == 0:
temp_set = FiniteSet(1) if uberset == '\mathbb N_{> 0}' else FiniteSet(0, 1)
set_str += element+'^{2} = \ '+element
self.set_description[1] = '\{'+str(temp_set)+'\}'
self.set_description[2] = temp_set
elif c == 1:
x = randint(0, 5) if element == 'n' else randint(-5, 0)
y = randint(5, 10) if element == 'n' else randint(0, 5)
fin_set = FiniteSet()
for i in range(x+1, y, 1):
fin_set = fin_set.union(FiniteSet(i))
if element == 'n' or element == 'z':
set_str += element+'\in \ ('+str(x)+', '+str(y)+')'
self.set_description[1] = '\{'+str(fin_set)+'\}'
self.set_description[2] = fin_set
else:
x = randint(1, 99)
set_str += element+'\subseteq \ \{'+str(x)+'\}'
self.set_description[1] = '\{\emptyset, '+str(x)+'\}'
self.set_description[2] = FiniteSet(EmptySet(), x)
elif c == 2:
if choice([0, 1]) == 0:
x = randint(-5, -5)
y = randint(-5, 5)
set_str = '\{'+str(x)+', '+str(y)+'\}'
self.set_description[1] = '\{'+str(FiniteSet(x, y))+'\}'
self.set_description[2] = FiniteSet(x, y)
else:
x = choice([x for x in np.arange(0, 99) if sqrt(x).is_integer()])
set_str += '\sqrt{'+element+'} = '+str(int(sqrt(x)))
self.set_description[1] = '\{'+str(x)+'\}'
self.set_description[2] = FiniteSet(x)
elif c == 3:
element+'\\textless 2 \wedge'+element+'\in \mathbb{N}'
if uberset == '\mathbb N_{> 0}':
temp_set = FiniteSet(1)
elif uberset == '\mathbb{N}':
temp_set = FiniteSet(0, 1)
else:
temp_set = FiniteSet(0, 1)
set_str += element+'^{2} = \ '+element
self.set_description[1] = '\{'+str(temp_set)+'\}'
self.set_description[2] = temp_set
elif self.set_type == 'infinite_set':
self.set_description[0] = 'infinite_set'
if element == 'n':
if choice([0, 1]) == 0:
set_str += element+'> 0'
self.set_description[1] = '\mathbb N_{> 0}'
self.set_description[2] = 'NPOS'
else:
set_str += element+'\in \mathbb{Z}'
self.set_description[1] = '\mathbb{N}'
self.set_description[2] = 'N'
elif element == 'z':
if choice([0, 1]) == 0:
set_str += element+'\geq 0'
self.set_description[1] = '\mathbb{N}'
self.set_description[2] = 'N'
else:
set_str += '0 > '+element
self.set_description[1] = 'ZNEG'
self.set_description[2] = '-Z'
elif element == 'q':
if choice([0, 1]) == 0:
set_str += element+'\in \mathbb{Z}'
self.set_description[1] = '\mathbb{Z}'
self.set_description[2] = 'Z'
else:
set_str += element+' \in \mathbb{Q}'
self.set_description[1] = 'Q'
self.set_description[2] = QQ
elif element == 'r':
if choice([0, 1]) == 0:
set_str += element+'^{2} \in \mathbb{N}'
self.set_description[0] = 'finite_set'
self.set_description[1] = '\{'+str(FiniteSet(0, 1))+'\}'
self.set_description[2] = FiniteSet(0, 1)
else:
#.........这里部分代码省略.........
示例3: FiniteSet
# 需要导入模块: from sympy import FiniteSet [as 别名]
# 或者: from sympy.FiniteSet import union [as 别名]
from sympy import FiniteSet, pi
# Unions & Intersections
s = FiniteSet(1, 2, 3)
t = FiniteSet(2, 4, 6)
union = s.union(t)
print(union)
intersection = s.intersect(t)
print(intersection)
### Cartesian Products
cartesianProduct = s * t
print(cartesianProduct)
for elem in cartesianProduct:
print(elem)
# Raise set to the power (calculate triplets)
cartesianProductCubed = s ** 3
for elem in cartesianProductCubed:
print(elem)
def time_period(length, g):
T = 2*pi*(length/g)**0.5
return T
L = FiniteSet(15, 18, 21, 22.5, 25)
示例4: FiniteSet
# 需要导入模块: from sympy import FiniteSet [as 别名]
# 或者: from sympy.FiniteSet import union [as 别名]
from sympy import FiniteSet
s = FiniteSet(1, 2, 3, 4, 5, 6)
a = FiniteSet(2, 3, 5)
b = FiniteSet(1, 3, 5)
e = a.union(b)
print(len(e)/len(s))
# from sympy import FiniteSet
# s = FiniteSet(1, 2, 3, 4, 5, 6)
# a = FiniteSet(2, 3, 5)
# b = FiniteSet(1, 3, 5)
# e = a.intersect(b)
# print(len(e)/len(s))
示例5: FiniteSet
# 需要导入模块: from sympy import FiniteSet [as 别名]
# 或者: from sympy.FiniteSet import union [as 别名]
Conjunto y operaciones con conjuntos usando la libreria SYMPY
"""
# Utilizando FiniteSet de sympy
from sympy import FiniteSet
C = FiniteSet(1, 2, 3)
# Subconjunto y subconjunto propio
A = FiniteSet(1,2,3)
B = FiniteSet(1,2,3,4,5)
A.subset(B)
# Union de dos conjuntos
A = FiniteSet(1, 2, 3)
B = FiniteSet(2, 4, 6)
A.union(B)
# Interseccion de dos conjuntos
A = FiniteSet(1, 2)
B = FiniteSet(2, 3)
A.intersect(B)
# Diferencia entre conjuntos
print A - B
# Calculando el producto cartesiano.
A = FiniteSet(1, 2)
B = FiniteSet(3, 4)