当前位置: 首页>>代码示例>>Python>>正文


Python sympy.FiniteSet类代码示例

本文整理汇总了Python中sympy.FiniteSet的典型用法代码示例。如果您正苦于以下问题:Python FiniteSet类的具体用法?Python FiniteSet怎么用?Python FiniteSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FiniteSet类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_finite_basic

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
开发者ID:baruchel,项目名称:sympy,代码行数:32,代码来源:test_sets.py

示例2: test_contains

def test_contains():
    assert Interval(0, 2).contains(1) is S.true
    assert Interval(0, 2).contains(3) is S.false
    assert Interval(0, 2, True, False).contains(0) is S.false
    assert Interval(0, 2, True, False).contains(2) is S.true
    assert Interval(0, 2, False, True).contains(0) is S.true
    assert Interval(0, 2, False, True).contains(2) is S.false
    assert Interval(0, 2, True, True).contains(0) is S.false
    assert Interval(0, 2, True, True).contains(2) is S.false

    assert (Interval(0, 2) in Interval(0, 2)) is False

    assert FiniteSet(1, 2, 3).contains(2) is S.true
    assert FiniteSet(1, 2, Symbol('x')).contains(Symbol('x')) is S.true

    # issue 8197
    from sympy.abc import a, b
    assert isinstance(FiniteSet(b).contains(-a), Contains)
    assert isinstance(FiniteSet(b).contains(a), Contains)
    assert isinstance(FiniteSet(a).contains(1), Contains)
    raises(TypeError, lambda: 1 in FiniteSet(a))

    # issue 8209
    rad1 = Pow(Pow(2, S(1)/3) - 1, S(1)/3)
    rad2 = Pow(S(1)/9, S(1)/3) - Pow(S(2)/9, S(1)/3) + Pow(S(4)/9, S(1)/3)
    s1 = FiniteSet(rad1)
    s2 = FiniteSet(rad2)
    assert s1 - s2 == S.EmptySet

    items = [1, 2, S.Infinity, S('ham'), -1.1]
    fset = FiniteSet(*items)
    assert all(item in fset for item in items)
    assert all(fset.contains(item) is S.true for item in items)

    assert Union(Interval(0, 1), Interval(2, 5)).contains(3) is S.true
    assert Union(Interval(0, 1), Interval(2, 5)).contains(6) is S.false
    assert Union(Interval(0, 1), FiniteSet(2, 5)).contains(3) is S.false

    assert S.EmptySet.contains(1) is S.false
    assert FiniteSet(rootof(x**3 + x - 1, 0)).contains(S.Infinity) is S.false

    assert rootof(x**5 + x**3 + 1, 0) in S.Reals
    assert not rootof(x**5 + x**3 + 1, 1) in S.Reals

    # non-bool results
    assert Union(Interval(1, 2), Interval(3, 4)).contains(x) == \
        Or(And(x <= 2, x >= 1), And(x <= 4, x >= 3))
    assert Intersection(Interval(1, x), Interval(2, 3)).contains(y) == \
        And(y <= 3, y <= x, y >= 1, y >= 2)

    assert (S.Complexes).contains(S.ComplexInfinity) == S.false
开发者ID:baruchel,项目名称:sympy,代码行数:51,代码来源:test_sets.py

示例3: test_powerset

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)
开发者ID:skymeson,项目名称:sympy,代码行数:15,代码来源:test_sets.py

示例4: test_real

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)
开发者ID:baruchel,项目名称:sympy,代码行数:16,代码来源:test_sets.py

示例5: test_finite_basic

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 AorB.subset(A) and AorB.subset(B)
    assert A.subset(AandB)
    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)

    # Ensure a variety of types can exist in a FiniteSet
    S = FiniteSet((1,2), Float, A, -5, x, 'eggs', x**2, Interval)
开发者ID:piyushbansal,项目名称:sympy,代码行数:17,代码来源:test_sets.py

示例6: test_contains

def test_contains():
    assert Interval(0, 2).contains(1) is S.true
    assert Interval(0, 2).contains(3) is S.false
    assert Interval(0, 2, True, False).contains(0) is S.false
    assert Interval(0, 2, True, False).contains(2) is S.true
    assert Interval(0, 2, False, True).contains(0) is S.true
    assert Interval(0, 2, False, True).contains(2) is S.false
    assert Interval(0, 2, True, True).contains(0) is S.false
    assert Interval(0, 2, True, True).contains(2) is S.false

    assert FiniteSet(1, 2, 3).contains(2) is S.true
    assert FiniteSet(1, 2, Symbol("x")).contains(Symbol("x")) is S.true

    # issue 8197
    from sympy.abc import a, b

    assert isinstance(FiniteSet(b).contains(-a), Contains)
    assert isinstance(FiniteSet(b).contains(a), Contains)
    assert isinstance(FiniteSet(a).contains(1), Contains)
    raises(TypeError, lambda: 1 in FiniteSet(a))

    # issue 8209
    rad1 = Pow(Pow(2, S(1) / 3) - 1, S(1) / 3)
    rad2 = Pow(S(1) / 9, S(1) / 3) - Pow(S(2) / 9, S(1) / 3) + Pow(S(4) / 9, S(1) / 3)
    s1 = FiniteSet(rad1)
    s2 = FiniteSet(rad2)
    assert s1 - s2 == S.EmptySet

    items = [1, 2, S.Infinity, S("ham"), -1.1]
    fset = FiniteSet(*items)
    assert all(item in fset for item in items)
    assert all(fset.contains(item) is S.true for item in items)

    assert Union(Interval(0, 1), Interval(2, 5)).contains(3) is S.true
    assert Union(Interval(0, 1), Interval(2, 5)).contains(6) is S.false
    assert Union(Interval(0, 1), FiniteSet(2, 5)).contains(3) is S.false

    assert S.EmptySet.contains(1) is S.false
    assert FiniteSet(RootOf(x ** 3 + x - 1, 0)).contains(S.Infinity) is S.false

    assert RootOf(x ** 5 + x ** 3 + 1, 0) in S.Reals
    assert not RootOf(x ** 5 + x ** 3 + 1, 1) in S.Reals
开发者ID:skymeson,项目名称:sympy,代码行数:42,代码来源:test_sets.py

示例7: test_contains

def test_contains():
    assert Interval(0, 2).contains(1) == True
    assert Interval(0, 2).contains(3) == False
    assert Interval(0, 2, True, False).contains(0) == False
    assert Interval(0, 2, True, False).contains(2) == True
    assert Interval(0, 2, False, True).contains(0) == True
    assert Interval(0, 2, False, True).contains(2) == False
    assert Interval(0, 2, True, True).contains(0) == False
    assert Interval(0, 2, True, True).contains(2) == False

    assert FiniteSet(1,2,3).contains(2)
    assert FiniteSet(1,2,Symbol('x')).contains(Symbol('x'))

    items = [1, 2, S.Infinity, S('ham'), -1.1]
    fset = FiniteSet(*items)
    assert all(item in fset for item in items)
    assert all(fset.contains(item) is True for item in items)

    assert Union(Interval(0, 1), Interval(2, 5)).contains(3) == True
    assert Union(Interval(0, 1), Interval(2, 5)).contains(6) == False
    assert Union(Interval(0, 1), FiniteSet(2, 5)).contains(3) == False

    assert S.EmptySet.contains(1) == False
开发者ID:piyushbansal,项目名称:sympy,代码行数:23,代码来源:test_sets.py

示例8: Type_A_Interval_III

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)+'\}'
开发者ID:prinzhf,项目名称:offset,代码行数:24,代码来源:intervals_A.py

示例9: set_second_part

 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:
#.........这里部分代码省略.........
开发者ID:prinzhf,项目名称:offset,代码行数:101,代码来源:set_templates_A.py

示例10: __init__

 def __init__(self):
     self.set_str = ""
     self.val_lst = []
     self.interval = FiniteSet()
开发者ID:prinzhf,项目名称:offset,代码行数:4,代码来源:intervals_A.py

示例11: FiniteSet

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))
开发者ID:KentFujii,项目名称:doing_math,代码行数:13,代码来源:probability.py

示例12: FiniteSet

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)
开发者ID:KentFujii,项目名称:doing_math,代码行数:25,代码来源:power_set.py

示例13: FiniteSet

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)
开发者ID:JSONMartin,项目名称:codingChallenges,代码行数:31,代码来源:sympy_operations.py

示例14: FiniteSet

print A.intersection(B)

# Diferencia entre conjuntos
print A - B
print B - A

"""
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)

开发者ID:josearcosaneas,项目名称:Matematicas-con-Python,代码行数:29,代码来源:conjuntos.py


注:本文中的sympy.FiniteSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。