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


Python Interval.union方法代码示例

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


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

示例1: Type_B_Interval_III

# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import union [as 别名]
class Type_B_Interval_III(object):
    def __init__(self):
        self.set_str = ""
        self.interval = FiniteSet()
        self.val1 = None
        self.val2 = None
        self.left_border = True
        self.right_border = True
        self.interval_rep = 0
        self.val_lst = []
        
    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,代码行数:91,代码来源:intervals_B.py

示例2: create_ui_set

# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import union [as 别名]
 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,代码行数:65,代码来源:interval_exercise.py


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