Esempio n. 1
0
def op_difference(left,right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~ExprArg` 
    
    Computes the set difference (left - - right)
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    if left.getInts() or right.getInts():
        sys.exit("FIXME ints diff")
    matches = getSetInstancePairs(left,right)
    newInstances = {}
    for (sort,index) in matches.keys():
        key = (sort,index)
        ((lexpr,lpol),(rexpr,rpol)) = matches[(sort,index)]
        if rpol == Common.DEFINITELY_ON or lpol == Common.DEFINITELY_OFF:
            #cases (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)
            continue
        elif rpol == Common.DEFINITELY_OFF:
            #cases (0 , -1), (1, -1)
            newInstances[key] = (lexpr, lpol)
        else:
            #rpol is unknown, lpol is unknown or on => new_pol is UNKNOWN
            #cases (0, 0), (1, 0)
            #if right is not on, then left, else sort.isOff
            new_expr = SMTLib.SMT_If(SMTLib.createNot(rexpr), lexpr, sort.parentInstances)
            newInstances[key] = (new_expr, Common.UNKNOWN)
    return ExprArg(newInstances)
Esempio n. 2
0
def op_difference(left, right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~ExprArg` 
    
    Computes the set difference (left - - right)
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    if left.getInts() or right.getInts():
        sys.exit("FIXME ints diff")
    matches = getSetInstancePairs(left, right)
    newInstances = {}
    for (sort, index) in matches.keys():
        key = (sort, index)
        ((lexpr, lpol), (rexpr, rpol)) = matches[(sort, index)]
        if rpol == Common.DEFINITELY_ON or lpol == Common.DEFINITELY_OFF:
            #cases (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)
            continue
        elif rpol == Common.DEFINITELY_OFF:
            #cases (0 , -1), (1, -1)
            newInstances[key] = (lexpr, lpol)
        else:
            #rpol is unknown, lpol is unknown or on => new_pol is UNKNOWN
            #cases (0, 0), (1, 0)
            #if right is not on, then left, else sort.isOff
            new_expr = SMTLib.SMT_If(SMTLib.createNot(rexpr), lexpr,
                                     sort.parentInstances)
            newInstances[key] = (new_expr, Common.UNKNOWN)
    return ExprArg(newInstances)
Esempio n. 3
0
def compute_int_set(instances):
    cons = []
    for index in range(len(instances)):
        (i, c) = instances[index]
        cons.append(
            mAnd(
                c, *[
                    mOr(SMTLib.createNot(jc), SMTLib.SMT_NE(j, i))
                    for (j, jc) in instances[0:index]
                ]))
    return cons
Esempio n. 4
0
def op_not(arg):
    '''
    :param arg:
    :type arg: :class:`~ExprArg`
    :returns: :class:`~IntArg` 
    
    Boolean negation of arg.
    '''
    assert isinstance(arg, ExprArg)
    val = arg.getBool()
    return BoolArg(SMTLib.createNot(val))
Esempio n. 5
0
def op_nin(left, right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~ExprArg` 
    
    Ensures that left is not a subset of right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    expr = op_in(left, right)
    return BoolArg(SMTLib.createNot(expr.pop_value()))
Esempio n. 6
0
def op_nin(left,right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~ExprArg` 
    
    Ensures that left is not a subset of right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    expr = op_in(left,right)
    return BoolArg(SMTLib.createNot(expr.pop_value()))
Esempio n. 7
0
def op_ne(left, right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~BoolArg` 
    
    Ensures that the left != right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    expr = op_eq(left, right)
    b = expr.getBool()
    return BoolArg(SMTLib.createNot(b))
Esempio n. 8
0
def op_ne(left,right):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~BoolArg` 
    
    Ensures that the left != right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    expr = op_eq(left, right)
    b = expr.getBool()
    return BoolArg(SMTLib.createNot(b))
Esempio n. 9
0
 def isOff(self, arg):
     '''
     Returns a Boolean Constraint stating whether or not the instance at the given index is *off*.
     '''
     return SMTLib.createNot(self.isOn(arg))
Esempio n. 10
0
 def isOff(self, arg):
     '''
     Returns a Boolean Constraint stating whether or not the instance at the given index is *off*.
     '''
     return SMTLib.createNot(self.isOn(arg))
Esempio n. 11
0
def op_eq(left, right, cacheJoins=False, bc=None):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~BoolArg` 
    
    Ensures that the left = right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    if cacheJoins and bc:
        #TODO CLEAN
        left_key = None
        right_key = None
        keys = []
        #asil allocation speedup, if both sides are sets, we can perform expression substitution in other constraints
        #bc is the bracketed constraint to put the cache

        for i in [left, right]:
            if isinstance(i, JoinArg):
                newkeys = Common.computeCacheKeys(i.flattenJoin())

                #print(tuple(key))
                keys = keys + newkeys
                #need to return all keys during the progress of join, add flag?
                #get the all keys
                all_keys = i.checkIfJoinIsComputed(nonsupered=True,
                                                   getAllKeys=True)
                #print(keys)
                #print(all_keys)
                keys = keys + all_keys
                #sys.exit()
                #print()
            #print("GGGG right" + str(right.__class__))
            #print(right.clafers)
        if len(left.clafers) != len(right.clafers):
            minJoinVal = left.clafers if len(left.clafers) < len(
                right.clafers) else right.clafers
            for i in keys:
                #TODO make more robust (e.g. if multiple equalities exist for the same join key, aggregate expressions
                bc.cache[i] = ExprArg(minJoinVal)
                #print(i)
                #print(minJoinVal)
                #print(str(len(minJoinVal)) + "  " + str(len(left.clafers)) + "  " + str(len(right.clafers)))
        #print(str(len(left.clafers)) + " " + str(len(right.clafers)))

    cond = []
    #int equality case
    lints = [(e, c) for (e, c) in left.getInts() if str(c) != "False"]
    rints = [(e, c) for (e, c) in right.getInts() if str(c) != "False"]
    if lints or rints:
        for (e, c) in lints:
            #exists r in R s.t. e == r
            expr = mOr(*[mAnd(rc, SMTLib.SMT_EQ(e, r)) for (r, rc) in rints])
            if str(c) != "True":
                expr = SMTLib.SMT_Implies(c, expr)
            cond.append(expr)
        for (e, c) in rints:
            #exists l in L s.t. e == l
            expr = mOr(*[mAnd(lc, SMTLib.SMT_EQ(e, l)) for (l, lc) in lints])
            if str(c) != "True":
                expr = SMTLib.SMT_Implies(c, expr)
            cond.append(expr)
    #clafer-set equality case
    matches = getSetInstancePairs(left, right)
    for ((lexpr, lpol), (rexpr, rpol)) in matches.values():
        if lpol == Common.DEFINITELY_OFF and rpol == Common.DEFINITELY_OFF:
            continue
        elif lpol == Common.DEFINITELY_OFF:
            cond.append(SMTLib.createNot(rexpr))
        elif rpol == Common.DEFINITELY_OFF:
            cond.append(SMTLib.createNot(lexpr))
        else:
            cond.append(SMTLib.SMT_Implies(lexpr, rexpr))
            cond.append(SMTLib.SMT_Implies(rexpr, lexpr))
    return BoolArg(mAnd(*cond))
Esempio n. 12
0
def op_eq(left,right, cacheJoins=False, bc = None):
    '''
    :param left:
    :type left: :class:`~ExprArg`
    :param right:
    :type right: :class:`~ExprArg`
    :returns: :class:`~BoolArg` 
    
    Ensures that the left = right.
    '''
    assert isinstance(left, ExprArg)
    assert isinstance(right, ExprArg)
    if cacheJoins and bc:
        #TODO CLEAN
        left_key = None
        right_key = None
        keys = []
        #asil allocation speedup, if both sides are sets, we can perform expression substitution in other constraints
        #bc is the bracketed constraint to put the cache
        
        for i in [left,right]:
            if isinstance(i, JoinArg):
                newkeys = Common.computeCacheKeys(i.flattenJoin())
                
                #print(tuple(key))
                keys = keys + newkeys
                #need to return all keys during the progress of join, add flag?
                #get the all keys
                all_keys = i.checkIfJoinIsComputed(nonsupered=True, getAllKeys = True)
                #print(keys)
                #print(all_keys)
                keys = keys+all_keys
                #sys.exit()
                #print()
            #print("GGGG right" + str(right.__class__))
            #print(right.clafers)
        if len(left.clafers) != len(right.clafers):
            minJoinVal = left.clafers if len(left.clafers) < len(right.clafers) else right.clafers
            for i in keys:
                #TODO make more robust (e.g. if multiple equalities exist for the same join key, aggregate expressions
                bc.cache[i] = ExprArg(minJoinVal)
                #print(i)
                #print(minJoinVal)
                #print(str(len(minJoinVal)) + "  " + str(len(left.clafers)) + "  " + str(len(right.clafers)))
        #print(str(len(left.clafers)) + " " + str(len(right.clafers)))
    
    cond = []
    #int equality case
    lints = [(e,c) for (e,c) in left.getInts() if str(c) != "False"]
    rints = [(e,c) for (e,c) in right.getInts() if str(c) != "False"]
    if lints or rints:
        for (e,c) in lints:
            #exists r in R s.t. e == r
            expr = mOr(*[mAnd(rc, SMTLib.SMT_EQ(e,r)) for (r,rc) in rints]) 
            if str(c) != "True":
                expr = SMTLib.SMT_Implies(c, expr)
            cond.append(expr)        
        for (e,c) in rints:
            #exists l in L s.t. e == l
            expr = mOr(*[mAnd(lc, SMTLib.SMT_EQ(e,l)) for (l,lc) in lints]) 
            if str(c) != "True":
                expr = SMTLib.SMT_Implies(c, expr)
            cond.append(expr)    
    #clafer-set equality case
    matches = getSetInstancePairs(left,right)
    for ((lexpr, lpol),(rexpr, rpol)) in matches.values():
        if lpol == Common.DEFINITELY_OFF and rpol == Common.DEFINITELY_OFF:
            continue
        elif lpol == Common.DEFINITELY_OFF:
            cond.append(SMTLib.createNot(rexpr))
        elif rpol == Common.DEFINITELY_OFF:
            cond.append(SMTLib.createNot(lexpr))
        else:
            cond.append(SMTLib.SMT_Implies(lexpr, rexpr))
            cond.append(SMTLib.SMT_Implies(rexpr, lexpr))
    return BoolArg(mAnd(*cond))
Esempio n. 13
0
def compute_int_set(instances):
    cons = []
    for index in range(len(instances)):
        (i,c) = instances[index]
        cons.append(mAnd(c, *[mOr(SMTLib.createNot(jc), SMTLib.SMT_NE(j,i)) for (j, jc) in instances[0:index]]))
    return cons 
Esempio n. 14
0
def quant_no(exprs, ifConstraints):
    condList = getQuantifierConditionList(exprs)
    if ifConstraints:
        condList = [mAnd(i, j) for i, j in zip(ifConstraints, condList)]
    return SMTLib.createNot(mOr(*condList))
Esempio n. 15
0
def quant_no(exprs, ifConstraints):
    condList = getQuantifierConditionList(exprs)
    if ifConstraints:
        condList = [mAnd(i, j) for i,j in zip(ifConstraints, condList)]
    return SMTLib.createNot(mOr(*condList))