예제 #1
0
파일: nat.py 프로젝트: AndreaCensi/mcdp
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
파일: coerce_to_int.py 프로젝트: rusi/mcdp
 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
파일: coerce_to_int.py 프로젝트: rusi/mcdp
 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
파일: nat.py 프로젝트: AndreaCensi/mcdp
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
파일: nat.py 프로젝트: AndreaCensi/mcdp
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
파일: nat.py 프로젝트: AndreaCensi/mcdp
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
파일: dp_max.py 프로젝트: AndreaCensi/mcdp
 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
파일: dp_max.py 프로젝트: AndreaCensi/mcdp
 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)