def op_le(left,right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~BoolArg` Invariant: left and right have exactly one int Ensures that the left <= right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in lval] rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in rval] lsum = SMTLib.createSum(lval) rsum = SMTLib.createSum(rval) return BoolArg(SMTLib.SMT_LE(lsum, rsum))
def op_mul(left,right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~IntArg` Returns left * right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in lval] lval = SMTLib.createSum(lval) rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in rval] rval = SMTLib.createSum(rval) return IntArg(SMTLib.SMT_Times(lval, rval))
def op_mul(left, right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~IntArg` Returns left * right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in lval] lval = SMTLib.createSum(lval) rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in rval] rval = SMTLib.createSum(rval) return IntArg(SMTLib.SMT_Times(lval, rval))
def op_le(left, right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~BoolArg` Invariant: left and right have exactly one int Ensures that the left <= right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in lval] rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in rval] lsum = SMTLib.createSum(lval) rsum = SMTLib.createSum(rval) return BoolArg(SMTLib.SMT_LE(lsum, rsum))
def op_div(left,right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~IntArg` Returns left / right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in lval] lval = SMTLib.createSum(lval) rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in rval] rval = SMTLib.createSum(rval) return IntArg(SMTLib.SMT_Divide(lval, rval) if((not isinstance(lval, SMTLib.SMT_IntConst)) or (not isinstance(rval, SMTLib.SMT_IntConst))) else SMTLib.SMT_IntDivide(lval, rval))
def op_un_minus(arg): ''' :param arg: :type arg: :class:`~ExprArg` :returns: :class:`~IntArg` Negates arg. ''' assert isinstance(arg, IntArg) val = arg.getInts() val = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e,c) in val] val_sum = SMTLib.createSum(val) return IntArg(SMTLib.createNeg(val_sum))
def op_sum(arg): ''' :param arg: :type arg: :class:`~ExprArg` :returns: :class:`~IntArg` Computes the sum of all integer instances in arg. May not match the semantics of the Alloy backend. ''' assert isinstance(arg, ExprArg) sum_list = [] for (e,c) in arg.getInts(): sum_list.append(SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0))) return IntArg(SMTLib.createSum(sum_list))
def goalVisit(self, element): bracketedConstraintsVisitor = CreateBracketedConstraints.CreateBracketedConstraints(self.cfr) op = element.exp.iExp[0].operation if op == "min": op = Common.METRICS_MINIMIZE else: op = Common.METRICS_MAXIMIZE expr = bracketedConstraintsVisitor.objectiveVisit(element.exp.iExp[0].elements[0]) if isinstance(expr[0], JoinArg): #TODO cache stuff here too (pass cfr into computeJoin if caching expr = operations.Join.computeJoin(expr) valueList = [SMTLib.createIf(c, i, SMTLib.SMT_IntConst(0)) for (i,c) in expr.getInts()] self.cfr.objectives.append((op, SMTLib.createSum(valueList)))
def op_div(left, right): ''' :param left: :type left: :class:`~ExprArg` :param right: :type right: :class:`~ExprArg` :returns: :class:`~IntArg` Returns left / right. ''' assert isinstance(left, ExprArg) assert isinstance(right, ExprArg) lval = left.getInts() lval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in lval] lval = SMTLib.createSum(lval) rval = right.getInts() rval = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in rval] rval = SMTLib.createSum(rval) return IntArg( SMTLib.SMT_Divide(lval, rval) if ( (not isinstance(lval, SMTLib.SMT_IntConst)) or ( not isinstance(rval, SMTLib.SMT_IntConst)) ) else SMTLib.SMT_IntDivide(lval, rval))
def op_sum(arg): ''' :param arg: :type arg: :class:`~ExprArg` :returns: :class:`~IntArg` Computes the sum of all integer instances in arg. May not match the semantics of the Alloy backend. ''' assert isinstance(arg, ExprArg) sum_list = [] for (e, c) in arg.getInts(): sum_list.append(SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0))) return IntArg(SMTLib.createSum(sum_list))
def op_un_minus(arg): ''' :param arg: :type arg: :class:`~ExprArg` :returns: :class:`~IntArg` Negates arg. ''' assert isinstance(arg, IntArg) val = arg.getInts() val = [SMTLib.createIf(c, e, SMTLib.SMT_IntConst(0)) for (e, c) in val] val_sum = SMTLib.createSum(val) return IntArg(SMTLib.createNeg(val_sum))
def goalVisit(self, element): bracketedConstraintsVisitor = CreateBracketedConstraints.CreateBracketedConstraints( self.cfr) op = element.exp.iExp[0].operation if op == "min": op = Common.METRICS_MINIMIZE else: op = Common.METRICS_MAXIMIZE expr = bracketedConstraintsVisitor.objectiveVisit( element.exp.iExp[0].elements[0]) if isinstance(expr[0], JoinArg): #TODO cache stuff here too (pass cfr into computeJoin if caching expr = operations.Join.computeJoin(expr) valueList = [ SMTLib.createIf(c, i, SMTLib.SMT_IntConst(0)) for (i, c) in expr.getInts() ] self.cfr.objectives.append((op, SMTLib.createSum(valueList)))