Пример #1
0
def RcompUnits_mult_lowersets_continuous(A, a, B, b, C):
    """ Multiplication on Rcompunits, extended for top, so that top*0 = Top """
    from mcdp_posets.poset import is_top
     
    if is_top(A, a) or is_top(B, b):
        return C.get_top()

    mcdp_dev_warning('catch overflow')
    return a * b
Пример #2
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     assert isinstance(x, float)
     # XXX: overflow?
     r = int(math.ceil(x))
     return r
Пример #3
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     assert isinstance(x, float)
     # XXX: overflow?
     r = int(math.ceil(x))
     return r
Пример #4
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     r = int(x)
     if r != x:
         msg = 'We cannot just coerce %r into an int.' % x
         raise MapNotDefinedHere(msg)
     return r
Пример #5
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     try:
         return float(x)
     except BaseException as e:
         msg = 'Internal error in PromoteToFloat.'
         raise_wrapped(DPInternalError, e, msg, x=x)
Пример #6
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     try: 
         return float(x)
     except BaseException as e:
         msg = 'Internal error in PromoteToFloat.'
         raise_wrapped(DPInternalError, e, msg, x=x)
Пример #7
0
def Nat_mult_lowersets_continuous(a, b):
    """ Multiplication on Nat, extended for top, so that top*0 = Top """
    from mcdp_posets.poset import is_top
    N = Nat_add_Nat
     
    if is_top(N, a) or is_top(N, b):
        return Nat_add_top

    assert isinstance(a, int), (a, type(a))
    assert isinstance(b, int), (b, type(b))

    res = a * b
    if res > sys.maxint:
        return N.get_top()
    
    assert isinstance(res, int), (res, type(res))
    return res
Пример #8
0
 def _call(self, x):
     if is_top(self.dom, x):
         return self.cod.get_top()
     r = int(x)
     if r != x:
         msg = 'We cannot just coerce %r into an int.' % x
         raise MapNotDefinedHere(msg)
     return r
Пример #9
0
def Nat_add(a, b):
    """ Addition on Nat, extended for top """
    from mcdp_posets.poset import is_top
    N = Nat_add_Nat
    
    if is_top(N, a) or is_top(N, b):
        return Nat_add_top
    
    mcdp_dev_warning('catch overflow')
    assert isinstance(a, int), (a, type(a))
    assert isinstance(b, int), (b, type(b))
    res = a + b
    
    if res > sys.maxint:
        return N.get_top()
    
    assert isinstance(res, int), (res, type(res))
    return res
Пример #10
0
    def _call(self, x):
        if is_top(self.dom, x):
            return self.cod.get_top()
        
        if np.isinf(x):
            return self.cod.get_top()

        y = self.op(x)
        if np.isinf(y):
            return self.cod.get_top()

        return y
Пример #11
0
def Nat_mult_uppersets_continuous(a, b):
    """ Multiplication on Nat, extended for top, so that top*0 = 0 """
    from mcdp_posets.poset import is_top
    N = Nat_add_Nat
    
    a_is_zero = a == 0
    b_is_zero = b == 0
    
    if a_is_zero or b_is_zero:
        return 0
    
    if is_top(N, a) or is_top(N, b):
        return Nat_add_top
    
    mcdp_dev_warning('catch overflow')
    assert isinstance(a, int), (a, type(a))
    assert isinstance(b, int), (b, type(b))
    res = a * b
    if res > sys.maxint:
        return N.get_top()
    
    assert isinstance(res, int), (res, type(res))
    return res
Пример #12
0
 def solve(self, f):
     n = self.n
     Fbot = self.Fbot
     
     if is_bottom(self.F, f):
         return self.R.U(self.R.get_bottom())
     elif is_top(self.F, f):
         return self.R.U(self.R.get_top())
     else:
         minimals = set()
         for i in range(n):
             tops = [Fbot] * n
             tops[i] = f
             minimals.add(tuple(tops))
         return self.R.Us(minimals)
Пример #13
0
 def solve_r(self, r):
     Rtop = self.Rtop
     n = self.n
     
     if is_top(self.R, r):
         return self.F.L(self.F.get_top())
     elif is_bottom(self.R, r):
         return self.F.L(self.F.get_bottom())
     else:
         maximals = set()
         for i in range(n):
             tops = [Rtop] * n
             tops[i] = r
             maximals.add(tuple(tops))
         return self.F.Ls(maximals)