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


Python sympy.Interval类代码示例

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


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

示例1: test_union

def test_union():
    assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3)
    assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3)
    assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4)
    assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3)
    assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3)
    assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \
        Interval(1, 3, False, True)
    assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3)
    assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3)
    assert Union(Interval(1, 2, True), Interval(1, 3, True)) == \
        Interval(1, 3, True)
    assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \
        Interval(1, 3, True, True)
    assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \
        Interval(1, 3, True)
    assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3)
    assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \
        Interval(1, 3)
    assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \
        Interval(1, 3)
    assert Union(Interval(1, 2), S.EmptySet) == Interval(1, 2)
    assert Union(S.EmptySet) == S.EmptySet

    assert Union(Interval(0, 1), [FiniteSet(1.0/n) for n in range(1, 10)]) == \
        Interval(0, 1)

    assert Interval(1, 2).union(Interval(2, 3)) == \
        Interval(1, 2) + Interval(2, 3)

    assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)

    assert Union(Set()) == Set()

    assert FiniteSet(1) + FiniteSet(2) + FiniteSet(3) == FiniteSet(1, 2, 3)
    assert FiniteSet('ham') + FiniteSet('eggs') == FiniteSet('ham', 'eggs')
    assert FiniteSet(1, 2, 3) + S.EmptySet == FiniteSet(1, 2, 3)

    assert FiniteSet(1, 2, 3) & FiniteSet(2, 3, 4) == FiniteSet(2, 3)
    assert FiniteSet(1, 2, 3) | FiniteSet(2, 3, 4) == FiniteSet(1, 2, 3, 4)

    x = Symbol("x")
    y = Symbol("y")
    z = Symbol("z")
    assert S.EmptySet | FiniteSet(x, FiniteSet(y, z)) == \
        FiniteSet(x, FiniteSet(y, z))

    # Test that Intervals and FiniteSets play nicely
    assert Interval(1, 3) + FiniteSet(2) == Interval(1, 3)
    assert Interval(1, 3, True, True) + FiniteSet(3) == \
        Interval(1, 3, True, False)
    X = Interval(1, 3) + FiniteSet(5)
    Y = Interval(1, 2) + FiniteSet(3)
    XandY = X.intersect(Y)
    assert 2 in X and 3 in X and 3 in XandY
    assert XandY.is_subset(X) and XandY.is_subset(Y)

    raises(TypeError, lambda: Union(1, 2, 3))

    assert X.is_iterable is False
开发者ID:Eskatrem,项目名称:sympy,代码行数:60,代码来源:test_sets.py

示例2: test_measure

def test_measure():
    a = Symbol('a', real=True)

    assert Interval(1, 3).measure == 2
    assert Interval(0, a).measure == a
    assert Interval(1, a).measure == a - 1

    assert Union(Interval(1, 2), Interval(3, 4)).measure == 2
    assert Union(Interval(1, 2), Interval(3, 4), FiniteSet(5, 6, 7)).measure \
        == 2

    assert FiniteSet(1, 2, oo, a, -oo, -5).measure == 0

    assert S.EmptySet.measure == 0

    square = Interval(0, 10) * Interval(0, 10)
    offsetsquare = Interval(5, 15) * Interval(5, 15)
    band = Interval(-oo, oo) * Interval(2, 4)

    assert square.measure == offsetsquare.measure == 100
    assert (square + offsetsquare).measure == 175  # there is some overlap
    assert (square - offsetsquare).measure == 75
    assert (square * FiniteSet(1, 2, 3)).measure == 0
    assert (square.intersect(band)).measure == 20
    assert (square + band).measure == oo
    assert (band * FiniteSet(1, 2, 3)).measure == nan
开发者ID:baruchel,项目名称:sympy,代码行数:26,代码来源:test_sets.py

示例3: find_curve_range_intersection

def find_curve_range_intersection(curve_1, curve_2, cut_at_inflection=False):
    """
    Return intersections of x- and y-ranges of two real curves,
    which are parametric curves on the xy-plane given as 
    (x_array, y_array), a tuple of NumPy arrays.
    """
    x1, y1 = curve_1
    x2, y2 = curve_2

    if cut_at_inflection is True:
        x1_min, x1_max = sorted([x1[0], x1[-1]])
        x2_min, x2_max = sorted([x2[0], x2[-1]])

        y1_min, y1_may = sorted([y1[0], y1[-1]])
        y2_min, y2_may = sorted([y2[0], y2[-1]])
    else:
        x1_min, x1_max = numpy.sort(x1)[[0, -1]]
        x2_min, x2_max = numpy.sort(x2)[[0, -1]]

        y1_min, y1_may = numpy.sort(y1)[[0, -1]]
        y2_min, y2_may = numpy.sort(y2)[[0, -1]]

    x1_interval = Interval(x1_min, x1_max)
    x2_interval = Interval(x2_min, x2_max)

    y1_interval = Interval(y1_min, y1_may)
    y2_interval = Interval(y2_min, y2_may)

    x_range = x1_interval.intersect(x2_interval)
    y_range = y1_interval.intersect(y2_interval)

    return (x_range, y_range)
开发者ID:chan-y-park,项目名称:mose,代码行数:32,代码来源:intersection.py

示例4: test_complement

def test_complement():
    assert Interval(0, 1).complement == \
           Union(Interval(-oo, 0, True, True), Interval(1, oo, True, True))
    assert Interval(0, 1, True, False).complement == \
           Union(Interval(-oo, 0, True, False), Interval(1, oo, True, True))
    assert Interval(0, 1, False, True).complement == \
           Union(Interval(-oo, 0, True, True), Interval(1, oo, False, True))
    assert Interval(0, 1, True, True).complement == \
           Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))

    assert -S.EmptySet == S.EmptySet.complement
    assert ~S.EmptySet == S.EmptySet.complement

    assert S.EmptySet.complement == Interval(-oo, oo)

    assert Union(Interval(0, 1), Interval(2, 3)).complement == \
           Union(Interval(-oo, 0, True, True), Interval(1, 2, True, True),
                 Interval(3, oo, True, True))

    assert FiniteSet(0).complement == Union(Interval(-oo,0, True,True) ,
            Interval(0,oo, True, True))

    assert (FiniteSet(5) + Interval(S.NegativeInfinity, 0)).complement == \
            Interval(0, 5, True, True) + Interval(5, S.Infinity, True,True)

    assert FiniteSet(1,2,3).complement == Interval(S.NegativeInfinity,1, True,True) + Interval(1,2, True,True) + Interval(2,3, True,True) + Interval(3,S.Infinity, True,True)

    X = Interval(1,3)+FiniteSet(5)
    assert X.intersect(X.complement) == S.EmptySet
开发者ID:Jerryy,项目名称:sympy,代码行数:29,代码来源:test_sets.py

示例5: test_interval_symbolic

def test_interval_symbolic():
    x = Symbol('x')
    e = Interval(0, 1)
    assert e.contains(x) == And(0 <= x, x <= 1)
    raises(TypeError, lambda: x in e)
    e = Interval(0, 1, True, True)
    assert e.contains(x) == And(0 < x, x < 1)
开发者ID:baruchel,项目名称:sympy,代码行数:7,代码来源:test_sets.py

示例6: test_issue_10285

def test_issue_10285():
    assert FiniteSet(-x - 1).intersect(Interval.Ropen(1, 2)) == FiniteSet(x).intersect(Interval.Lopen(-3, -2))
    eq = -x - 2 * (-x - y)
    s = signsimp(eq)
    ivl = Interval.open(0, 1)
    assert FiniteSet(eq).intersect(ivl) == FiniteSet(s).intersect(ivl)
    assert FiniteSet(-eq).intersect(ivl) == FiniteSet(s).intersect(Interval.open(-1, 0))
    eq -= 1
    ivl = Interval.Lopen(1, oo)
    assert FiniteSet(eq).intersect(ivl) == FiniteSet(s).intersect(Interval.Lopen(2, oo))
开发者ID:Carreau,项目名称:sympy,代码行数:10,代码来源:test_sets.py

示例7: test_reduce_rational_inequalities_real_relational

def test_reduce_rational_inequalities_real_relational():
    assert reduce_rational_inequalities([], x) == False
    assert reduce_rational_inequalities(
        [[(x**2 + 3*x + 2)/(x**2 - 16) >= 0]], x, relational=False) == \
        Union(Interval.open(-oo, -4), Interval(-2, -1), Interval.open(4, oo))

    assert reduce_rational_inequalities(
        [[((-2*x - 10)*(3 - x))/((x**2 + 5)*(x - 2)**2) < 0]], x,
        relational=False) == \
        Union(Interval.open(-5, 2), Interval.open(2, 3))

    assert reduce_rational_inequalities([[(x + 1)/(x - 5) <= 0]], x,
        relational=False) == \
        Interval.Ropen(-1, 5)

    assert reduce_rational_inequalities([[(x**2 + 4*x + 3)/(x - 1) > 0]], x,
        relational=False) == \
        Union(Interval.open(-3, -1), Interval.open(1, oo))

    assert reduce_rational_inequalities([[(x**2 - 16)/(x - 1)**2 < 0]], x,
        relational=False) == \
        Union(Interval.open(-4, 1), Interval.open(1, 4))

    assert reduce_rational_inequalities([[(3*x + 1)/(x + 4) >= 1]], x,
        relational=False) == \
        Union(Interval.open(-oo, -4), Interval.Ropen(S(3)/2, oo))

    assert reduce_rational_inequalities([[(x - 8)/x <= 3 - x]], x,
        relational=False) == \
        Union(Interval.Lopen(-oo, -2), Interval.Lopen(0, 4))

    # issue sympy/sympy#10237
    assert reduce_rational_inequalities(
        [[x < oo, x >= 0, -oo < x]], x, relational=False) == Interval(0, oo)
开发者ID:richardotis,项目名称:sympy,代码行数:34,代码来源:test_inequalities.py

示例8: test_union

def test_union():
    assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3)
    assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3)
    assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4)
    assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3)
    assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3)
    assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \
           Interval(1, 3, False, True)
    assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3)
    assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3)
    assert Union(Interval(1, 2, True), Interval(1, 3, True)) == Interval(1, 3, True)
    assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \
           Interval(1, 3, True, True)
    assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \
           Interval(1, 3, True)
    assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3)
    assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \
           Interval(1, 3)
    assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \
           Interval(1, 3)
    assert Union(Interval(1, 2), S.EmptySet) == Interval(1, 2)
    assert Union(S.EmptySet) == S.EmptySet

    assert Union(Interval(0,1), [FiniteSet(1.0/n) for n in range(1,10)]) == \
            Interval(0,1)

    assert Interval(1, 2).union(Interval(2, 3)) == \
           Interval(1, 2) + Interval(2, 3)

    assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)

    assert Union(Set()) == Set()

    assert FiniteSet(1) + FiniteSet(2) + FiniteSet(3) == FiniteSet(1,2,3)
    assert FiniteSet(['ham']) + FiniteSet(['eggs']) == FiniteSet('ham', 'eggs')
    assert FiniteSet(1,2,3) + S.EmptySet == FiniteSet(1,2,3)

    assert FiniteSet(1,2,3) & FiniteSet(2,3,4) == FiniteSet(2,3)
    assert FiniteSet(1,2,3) | FiniteSet(2,3,4) == FiniteSet(1,2,3,4)


    # Test that Intervals and FiniteSets play nicely
    assert Interval(1,3) + FiniteSet(2) == Interval(1,3)
    assert Interval(1,3, True,True) + FiniteSet(3) == Interval(1,3, True,False)
    X = Interval(1,3)+FiniteSet(5)
    Y = Interval(1,2)+FiniteSet(3)
    XandY = X.intersect(Y)
    assert 2 in X and 3 in X and 3 in XandY
    assert X.subset(XandY) and Y.subset(XandY)


    raises(TypeError, "Union(1, 2, 3)")
开发者ID:MichaelMayorov,项目名称:sympy,代码行数:52,代码来源:test_sets.py

示例9: WordInterval

class WordInterval(object):
    SILENCE_WORD = '#'

    def __init__(self, inf, sup, word):
        self.word = word
        self.interval = Interval(inf, sup)

    @property
    def is_silent(self):
        return self.word == WordInterval.SILENCE_WORD

    @property
    def inf(self):
        return self.interval.inf

    @property
    def sup(self):
        return self.interval.sup

    def intersect(self, another_interval):
        return self.interval.intersect(another_interval)


    def __eq__(self, other):
        return (self.interval == other.interval) and (self.word == other.word)

    def __str__(self):
        return "%s -> %s" % (self.interval, self.word)

    def __repr__(self):
        return self.__str__()
开发者ID:finiteautomata,项目名称:tesis,代码行数:31,代码来源:word_interval.py

示例10: test_complement

def test_complement():
    assert Interval(0, 1).complement(S.Reals) == \
        Union(Interval(-oo, 0, True, True), Interval(1, oo, True, True))
    assert Interval(0, 1, True, False).complement(S.Reals) == \
        Union(Interval(-oo, 0, True, False), Interval(1, oo, True, True))
    assert Interval(0, 1, False, True).complement(S.Reals) == \
        Union(Interval(-oo, 0, True, True), Interval(1, oo, False, True))
    assert Interval(0, 1, True, True).complement(S.Reals) == \
        Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))

    assert S.UniversalSet.complement(S.EmptySet) == S.EmptySet
    assert S.UniversalSet.complement(S.Reals) == S.EmptySet
    assert S.UniversalSet.complement(S.UniversalSet) == S.EmptySet

    assert S.EmptySet.complement(S.Reals) == S.Reals

    assert Union(Interval(0, 1), Interval(2, 3)).complement(S.Reals) == \
        Union(Interval(-oo, 0, True, True), Interval(1, 2, True, True),
              Interval(3, oo, True, True))

    assert FiniteSet(0).complement(S.Reals) ==  \
        Union(Interval(-oo, 0, True, True), Interval(0, oo, True, True))

    assert (FiniteSet(5) + Interval(S.NegativeInfinity,
                                    0)).complement(S.Reals) == \
        Interval(0, 5, True, True) + Interval(5, S.Infinity, True, True)

    assert FiniteSet(1, 2, 3).complement(S.Reals) == \
        Interval(S.NegativeInfinity, 1, True, True) + \
        Interval(1, 2, True, True) + Interval(2, 3, True, True) +\
        Interval(3, S.Infinity, True, True)

    assert FiniteSet(x).complement(S.Reals) == Complement(S.Reals, FiniteSet(x))

    assert FiniteSet(0, x).complement(S.Reals) == Complement(Interval(-oo, 0, True, True) +
                                                             Interval(0, oo, True, True)
                                                             ,FiniteSet(x), evaluate=False)

    square = Interval(0, 1) * Interval(0, 1)
    notsquare = square.complement(S.Reals*S.Reals)

    assert all(pt in square for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
    assert not any(
        pt in notsquare for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
    assert not any(pt in square for pt in [(-1, 0), (1.5, .5), (10, 10)])
    assert all(pt in notsquare for pt in [(-1, 0), (1.5, .5), (10, 10)])
开发者ID:baruchel,项目名称:sympy,代码行数:46,代码来源:test_sets.py

示例11: test_solve_abs

def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2 * Abs(x - 3), x) == FiniteSet(1, 9)
    assert solveset_real(2 * Abs(x) - Abs(x - 1), x) == FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))

    # issue 9565. Note: solveset_real does not solve this as it is
    # solveset's job to handle Relationals
    assert solveset(Abs((x - 1) / (x - 5)) <= S(1) / 3, domain=S.Reals) == Interval(-1, 2)

    # issue #10069
    eq = abs(1 / (x - 1)) - 1 > 0
    u = Union(Interval.open(0, 1), Interval.open(1, 2))
    assert solveset_real(eq, x) == u
    assert solveset(eq, x, domain=S.Reals) == u

    raises(ValueError, lambda: solveset(abs(x) - 1, x))
开发者ID:pabloferz,项目名称:sympy,代码行数:18,代码来源:test_solveset.py

示例12: test_solve_abs

def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2*Abs(x - 3), x) == \
        FiniteSet(1, 9)
    assert solveset_real(2*Abs(x) - Abs(x - 1), x) == \
        FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))

    # issue 9565. Note: solveset_real does not solve this as it is
    # solveset's job to handle Relationals
    assert solveset(Abs((x - 1)/(x - 5)) <= S(1)/3, domain=S.Reals
        ) == Interval(-1, 2)

    # issue #10069
    assert solveset_real(abs(1/(x - 1)) - 1 > 0, x) == \
        ConditionSet(x, Eq((1 - Abs(x - 1))/Abs(x - 1) > 0, 0),
            S.Reals)
    assert solveset(abs(1/(x - 1)) - 1 > 0, x, domain=S.Reals
        ) == Union(Interval.open(0, 1), Interval.open(1, 2))
开发者ID:nickle8424,项目名称:sympy,代码行数:20,代码来源:test_solveset.py

示例13: test_complement

def test_complement():
    assert Interval(0, 1).complement == \
        Union(Interval(-oo, 0, True, True), Interval(1, oo, True, True))
    assert Interval(0, 1, True, False).complement == \
        Union(Interval(-oo, 0, True, False), Interval(1, oo, True, True))
    assert Interval(0, 1, False, True).complement == \
        Union(Interval(-oo, 0, True, True), Interval(1, oo, False, True))
    assert Interval(0, 1, True, True).complement == \
        Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))

    assert -S.EmptySet == S.EmptySet.complement
    assert ~S.EmptySet == S.EmptySet.complement

    assert S.EmptySet.complement == S.UniversalSet
    assert S.UniversalSet.complement == S.EmptySet

    assert Union(Interval(0, 1), Interval(2, 3)).complement == \
        Union(Interval(-oo, 0, True, True), Interval(1, 2, True, True),
              Interval(3, oo, True, True))

    assert FiniteSet(0).complement == Union(Interval(-oo, 0, True, True),
            Interval(0, oo, True, True))

    assert (FiniteSet(5) + Interval(S.NegativeInfinity, 0)).complement == \
        Interval(0, 5, True, True) + Interval(5, S.Infinity, True, True)

    assert FiniteSet(1, 2, 3).complement == \
        Interval(S.NegativeInfinity, 1, True, True) + Interval(1, 2, True, True) + \
        Interval(2, 3, True, True) + Interval(3, S.Infinity, True, True)

    X = Interval(1, 3) + FiniteSet(5)
    assert X.intersect(X.complement) == S.EmptySet

    square = Interval(0, 1) * Interval(0, 1)
    notsquare = square.complement

    assert all(pt in square for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
    assert not any(
        pt in notsquare for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
    assert not any(pt in square for pt in [(-1, 0), (1.5, .5), (10, 10)])
    assert all(pt in notsquare for pt in [(-1, 0), (1.5, .5), (10, 10)])
开发者ID:Eskatrem,项目名称:sympy,代码行数:41,代码来源:test_sets.py

示例14: create_ui_set

 def create_ui_set(self, X):
     result = None
     nums = []
     allowed = "-0123456789{},()[]o"
     if not all(c in allowed for c in X):
         return False
     if len(X) < 3 and X != '{}':
         return False
     if (X[0] == '(' or X[0] == '[') and  (X[-1] == ')' or X[-1] == ']'):
         nums = re.findall("[-\d]+", X)
         if '-' in nums:
             nums.remove('-')
         if len(nums) == 1:
             if '-oo' in X or 'oo' in X:
                 if '-oo' in X:
                     nums.append(nums[0])
                     nums[0] = -oo
                 elif 'oo' in X:
                     nums.append(oo)
                 else:
                     return False
         if len(nums) != 2:
             return False
         commata = re.findall(",", X)
         if len(commata) != 1:
             return False
         for i in range(len(X)):
             if X[i] == ',' and not (((X[i-1].isdigit() or X[i+1].isdigit()) or (X[i-1] == 'o' or X[i+1] == 'o'))): 
                 return False
         left = True if X[0] == '(' else False
         right = True if X[-1] == ')' else False
         if oo in nums or -oo in nums:
             if oo in nums:
                 result = Interval(int(nums[0]), oo, left, right)
                 return result
             else:
                 result = Interval(-oo, int(nums[1]), left, right)
                 return result
         else:
             if nums[0] <= nums[1]:
                 result = Interval(int(nums[0]), int(nums[1]), left, right)
                 return result
             else:
                 return False
         
     elif X[0] == '{' and X[-1] == '}':
         if len(X) == 2:
             return EmptySet()
         else:
             nums = re.findall("[-\d]+", X)
             if len(re.findall(",", X)) != len(nums)-1:
                 return False
             num_count = 0    
             for i in range(len(nums)):
                 if X[i] == ',' and not X.index(nums[num_count]) < i and X[i+1]  == ',':
                     return False
                 num_count += 1
             result = FiniteSet()
             for i in range(len(nums)):
                 result = result.union(FiniteSet(int(nums[i])))
             return result
     else:
         return False
开发者ID:prinzhf,项目名称:offset,代码行数:63,代码来源:interval_exercise.py

示例15: generate_interval

    def generate_interval(self, A, OP):
        if OP == '\setminus':
            if len(A.interval) == 1:
                self.interval_rep = 1
                self.val1 = choice([A.val_lst[0], -oo, oo])
                if self.val1 == -oo or self.val1 == oo:
                    self.val2 = A.val_lst[0]
                else:
                    self.val2 = choice([-oo, oo])
            else:
                self.interval_rep = 0
                self.val1 = choice(A.val_lst)
                self.val2 = self.val1
            self.left_border = choice([True, False])
            self.left_border = choice([True, False])
                
        elif OP == '\cap':
            self.interval_rep = 0
            if len(A.val_lst) == 1:
                if randint(0, 1) == 0:
                    self.val1 = randint(-25, A.val_lst[0])
                    self.val2 = A.val_lst[0] + randint(0, 2)
                else:
                    self.val1 = A.val_lst[-1]-randint(0, 2)
                    self.val2 = randint(A.val_lst[-1], 25)
            else:
                if randint(0, 1) == 0:
                    self.val1 = randint(-25, A.val_lst[1])
                    self.val2 = A.val_lst[1] + randint(0, 2)
                else:
                    self.val1 = A.val_lst[-1] - randint(0, 2)
                    self.val2 = randint(A.val_lst[-1], 25)
        else:
            self.interval_rep = 2
            tmp_lst = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5]
            tmp_lst.extend(A.val_lst)
            for i in range(0, randint(1, 5)):
                self.val_lst.append(choice(tmp_lst))
        
        if self.interval_rep == 0:
            self.interval = Interval(self.val1, self.val2, self.left_border, self.right_border)
            self.set_str += "\{r \ | \ r \in \mathbb{R} \wedge \ "+str(self.val1)
            self.set_str += '<' if self.left_border == True else '\leq'
            self.set_str += ' \ r'
            self.set_str += '<' if self.right_border == True else '\leq'
            self.set_str += str(self.val2)
            self.set_str += '\}'
            if isinstance(self.interval, EmptySet):
                self.interval = FiniteSet(self.val1)
                self.set_str = '\{'+str(self.val1)+'\}'
        elif self.interval_rep == 1:
            self.interval = Interval(self.val1, self.val2, self.left_border, self.right_border)
            self.set_str +=  "\{r \ | \ r \in \mathbb{R} \wedge \ r"
            if self.val1 == -oo or self.val1 == oo:
                if self.val1 == -oo:
                    self.set_str += '<' if self.left_border == True else '\leq'
                else: 
                    self.set_str += '>' if self.left_border == True else '\geq'
                #if self.val1 == oo:
                #    self.set_str += '<' if self.left_border == True else '\leq'
                #else: 
                #    self.set_str += '>' if self.left_border == True else '\geq'
                self.set_str += str(self.val2)+'\}'
            else:
                if self.val2 == -oo:
                    self.set_str += '<' if self.left_border == True else '\leq'
                else: 
                    self.set_str += '>' if self.left_border == True else '\geq'
                #if self.val2 == oo:
                #    self.set_str += '<' if self.left_border == True else '\leq'
                #else:
                #    self.set_str += '>' if self.left_border == True else '\geq'
                self.set_str += str(self.val1)+'\}'

        else:
            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,代码行数:78,代码来源:intervals_B.py


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