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


Python z3.simplify函数代码示例

本文整理汇总了Python中z3.simplify函数的典型用法代码示例。如果您正苦于以下问题:Python simplify函数的具体用法?Python simplify怎么用?Python simplify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: construct

 def construct(self, obj):
     '''
     Takes in a ConstructableObject with preconditions
     and postconditions. Checks that preconditions hold
     in the proof context and if so, asserts the post-conditions.
     '''
     self.solver.push()
     for prereq in obj.prereqs:
         self.solver.add(simplify(prereq, blast_distinct = True))
         prereqCheck = self.solver.check()
         if str(prereqCheck) != 'sat':
             print "ProofCheck >> Construction Failed - Could not meet: " + str(prereq) 
             self.solver.pop()
             return False
         
     if len(obj.prereqs) > 0:
         self.assumptions.extend(obj.prereqs)
         
     for conclusion in obj.conclusions:
         self.solver.add(simplify(conclusion, blast_distinct=True))
         self.conclusions.append(conclusion)
     
     if isinstance(obj, Point):
         self.points[obj.label] = obj
     elif isinstance(obj, Line):
         self.lines[obj.label] = obj
     elif isinstance(obj, Circle):
         self.circles[obj.label] = obj
         
     self.solver.pop()
     self.solver.add(obj.prereqs)
     self.solver.add(obj.conclusions)
     return True
开发者ID:kr0,项目名称:PyEuclid,代码行数:33,代码来源:core.py

示例2: prove

    def prove(self, hypotheses, conclusion=None, report=None):
        report = self.reportFun(report)

        x_hyps, x_concl = self.analyse_expt(hypotheses, conclusion, report)
        f_hyps, f_concl = self.fun_to_var([x_hyps, x_concl], report)[:]
        hyps = z3.simplify(f_hyps); concl = z3.simplify(f_concl)

        report('to_smt_w_expt.prove:')
        report('  hypotheses = ', hyps)
        report('  conclusion = ', concl)
        return super(to_smt_w_expt, self).prove(hyps, concl)
开发者ID:VladimirHo,项目名称:acl2,代码行数:11,代码来源:RewriteExpt.py

示例3: getValue

 def getValue(self, op):
   assert(self.m <> None)
   
   if (op.isReg()):
     
     #if (literal):
     #  
     #
     var = map(lambda b: z3.BitVec(b,8), op.get_bytes())
     var = map(lambda b: self.m[b], var)
     if (len(var) > 1):
       return z3.simplify(z3.Concat(var)).as_signed_long()
     else:
       return z3.simplify(var[0]).as_signed_long()
   elif (op.isMem()):
     array = z3.Array(op.mem_source, z3.BitVecSort(16), z3.BitVecSort(8))
     #print "debug getValue:"
     #print op, op.mem_offset ,"->", array
     f = self.m[array]
     #print f
     #
     #var = map(lambda b: z3.BitVec(b,8), op.get_bytes())
     #var = map(lambda b: self.m[b], var)
     #
     ##if (self.m):
     #print "eax:"
     #print "%x" % self.m[eax].as_unsigned()
     #assert(0)
     ##print op.mem_source
     ##print op.mem_offset
     
     es = f.as_list()[:-1]
     
     var = []
     
     for i in range(op.size):
       byte = None
       for entry in es:
         if op.mem_offset + i == entry[0].as_signed_long():
           byte = entry[1]#.as_signed_long()
           break
       
       if (byte == None):
         byte = f.else_value()
         
       var.append(byte)
       
     var.reverse()
     
     if (len(var) > 1):  
       return z3.simplify(z3.Concat(var)).as_signed_long()
     else:
       return z3.simplify(var[0]).as_signed_long()
开发者ID:mayfly74,项目名称:SEA,代码行数:53,代码来源:SMT.py

示例4: getDimacsMap

def getDimacsMap(goal): 
    d = DimacsConverter()
    t = Tactic("tseitin-cnf")
    cnf = t(goal)
    #print cnf
    clauses = []
    #print(cnf)
    for i in cnf:
        for j in i:
            variables = []
            #print (j)
            #print j.__class__
            if len(j.children()) == 0:
                variables.append(str(d.getVarIndex(str(j))))
            for k in j.children():
                #print k
                if is_not(k):
                    neg="-"
                    newk = (simplify(Not(k)))
                else:
                    neg=""
                    newk = k
                variables.append(neg + str(d.getVarIndex(str(newk))))
            clauses.append(variables)
    
    inv_map = {v:k for k, v in d.vars.items()}
    return inv_map
开发者ID:ai-se,项目名称:parGALE,代码行数:27,代码来源:MapDimacsBackToBestVars.py

示例5: convertToDimacs

def convertToDimacs(goal, file):
        #f_n = open(Options.DIMACS_FILE, 'w')
        d = DimacsConverter()
        t = Tactic("tseitin-cnf")
        cnf = t(goal)
        #print cnf
        clauses = []
        #print(cnf)
        for i in cnf:
            for j in i:
                variables = []
                #print (j)
                #print j.__class__
                if len(j.children()) == 0:
                    variables.append(str(d.getVarIndex(str(j))))
                for k in j.children():
                    #print k
                    if is_not(k):
                        neg="-"
                        newk = (simplify(Not(k)))
                    else:
                        neg=""
                        newk = k
                    variables.append(neg + str(d.getVarIndex(str(newk))))
                clauses.append(variables)
        
        inv_map = {v:k for k, v in d.vars.items()}
        #print(inv_map)
        f = open(file, 'r')
        for line in f:
            [var, val] = split(line)
            print("\"" + str(inv_map[int(var)])+"\",")
开发者ID:ai-se,项目名称:parGALE,代码行数:32,代码来源:MapDimacsBackToBestVars.py

示例6: simplify

    def simplify(self, expr):
        if expr._simplified:
            return expr

        if self._enable_simplification_cache:
            try:
                k = self._simplification_cache_key[expr._cache_key]
                #print "HIT WEAK KEY CACHE"
                return k
            except KeyError:
                pass
            try:
                k = self._simplification_cache_val[expr._cache_key]
                #print "HIT WEAK VALUE CACHE"
                return k
            except KeyError:
                pass

            #print "MISS CACHE"

        l.debug("SIMPLIFYING EXPRESSION")

        #print "SIMPLIFYING"

        expr_raw = self.convert(expr)

        #l.debug("... before: %s (%s)", expr_raw, expr_raw.__class__.__name__)

        if isinstance(expr_raw, z3.BoolRef):
            tactics = z3.Then(z3.Tactic("simplify"), z3.Tactic("propagate-ineqs"), z3.Tactic("propagate-values"), z3.Tactic("unit-subsume-simplify"))
            s = tactics(expr_raw).as_expr()
            n = s.decl().name()

            if n == 'true':
                s = True
            elif n == 'false':
                s = False
        elif isinstance(expr_raw, z3.BitVecRef):
            s = z3.simplify(expr_raw)
        else:
            s = expr_raw

        for b in _eager_backends:
            try:
                o = self.wrap(b.convert(s))
                break
            except BackendError:
                continue
        else:
            o = self._abstract(s)

        #print "SIMPLIFIED"
        #l.debug("... after: %s (%s)", s, s.__class__.__name__)

        o._simplified = Base.FULL_SIMPLIFY

        if self._enable_simplification_cache:
            self._simplification_cache_val[expr._cache_key] = o
            self._simplification_cache_key[expr._cache_key] = o
        return o
开发者ID:zhuyue1314,项目名称:claripy,代码行数:60,代码来源:backend_z3.py

示例7: bitblast

def bitblast (e):
  ctx = e.ctx
  goal = z3.Goal (ctx=ctx)
  goal.add (z3.simplify (e))
  tactic = z3.Tactic ('bit-blast', ctx=ctx)
  res = tactic.apply (goal, blast_full=True)
  assert (len (res) == 1)
  return res [0].as_expr ()
开发者ID:edmcman,项目名称:seahorn,代码行数:8,代码来源:z3_utils.py

示例8: PEPPolicy

def PEPPolicy(PEP, model):
    disjunctions = []
    for or_id in range(NUM_ORS):
        conjunctions = []
        for enum_id in range(NUM_ENUMS):
            enumVar = TEMPLATE_ENUM_VARS[PEP][or_id][enum_id]
            if model[enumVar] is not None:
                synthVal = model[enumVar].as_long()
            else:
                synthVal = -1
            if synthVal >= 0 and synthVal < len(ENUM_INDEX.keys()):                
                if not isinstance(ENUM_INDEX[synthVal], list):
                    boolVar = ENUM_INDEX[synthVal]
                    conjunctions.append(boolVar)
                else:
                    [enumVar, val] = ENUM_INDEX[synthVal]
                    conjunctions.append(enumVar == val)
            elif synthVal >= len(ENUM_INDEX.keys()) and synthVal < 2 * len(ENUM_INDEX.keys()):                
                if not isinstance(ENUM_INDEX[synthVal - len(ENUM_INDEX.keys())], list):
                    boolVar = ENUM_INDEX[synthVal - len(ENUM_INDEX.keys())]
                    conjunctions.append(Not(boolVar))
                else:
                    [enumVar, val] = ENUM_INDEX[synthVal - len(ENUM_INDEX.keys())]
                    conjunctions.append(enumVar != val)
            elif synthVal == 2 * len(ENUM_INDEX.keys()):
                conjunctions.append(True)
            else:
                conjunctions.append(False)
        for num_id in range(NUM_NUMERIC):
            minVar = TEMPLATE_NUMERIC_VARS[PEP][or_id][num_id]['min']
            maxVar = TEMPLATE_NUMERIC_VARS[PEP][or_id][num_id]['max']
            if model[minVar] is not None and model[maxVar] is not None:
                crosscheck = Solver()
                crosscheck.add(model[minVar] <= model[maxVar])
                if crosscheck.check() == sat:
                    conjunctions.append(NUM_VAR >= model[minVar].as_long())
                    conjunctions.append(NUM_VAR <= model[maxVar].as_long())
            elif model[minVar] is not None:
                conjunctions.append(NUM_VAR >= model[minVar].as_long())
            elif model[maxVar] is not None:
                conjunctions.append(NUM_VAR <= model[maxVar].as_long())
        disjunctions.append(simplify(And(conjunctions)))
    return simplify(Or(disjunctions))
开发者ID:ptsankov,项目名称:spctl,代码行数:43,代码来源:template.py

示例9: z3_flatten_exp

def z3_flatten_exp (z3exp) :
  return z3.simplify (z3exp, flat=True,
                      # don't care about other options,
                      # which are true by default...
                      algebraic_number_evaluator=False,
                      bit2bool=False,
                      elim_sign_ext=False,
                      hi_div0=False,
                      mul_to_power=False,
                      push_to_real=False)
开发者ID:edmcman,项目名称:seahorn,代码行数:10,代码来源:z3_utils.py

示例10: simplify

    def simplify(self, expr):
        if expr._simplified:
            return expr

        if self._enable_simplification_cache:
            try:
                k = self._simplification_cache_key[expr._cache_key]
                #print "HIT WEAK KEY CACHE"
                return k
            except KeyError:
                pass
            try:
                k = self._simplification_cache_val[expr._cache_key]
                #print "HIT WEAK VALUE CACHE"
                return k
            except KeyError:
                pass

            #print "MISS CACHE"

        l.debug("SIMPLIFYING EXPRESSION")

        #print "SIMPLIFYING"

        expr_raw = self.convert(expr)

        #l.debug("... before: %s (%s)", expr_raw, expr_raw.__class__.__name__)

        #s = expr_raw
        if isinstance(expr_raw, z3.BoolRef):
            tactics = z3.Then(
                z3.Tactic("simplify", ctx=self._context),
                z3.Tactic("propagate-ineqs", ctx=self._context),
                z3.Tactic("propagate-values", ctx=self._context),
                z3.Tactic("unit-subsume-simplify", ctx=self._context),
                ctx=self._context
            )
            s = tactics(expr_raw).as_expr()
            #n = s.decl().name()
            #if n == 'true':
            #   s = True
            #elif n == 'false':
            #   s = False
        elif isinstance(expr_raw, z3.BitVecRef):
            s = z3.simplify(expr_raw)
        else:
            s = expr_raw

        o = self._abstract(s)
        o._simplified = Base.FULL_SIMPLIFY

        if self._enable_simplification_cache:
            self._simplification_cache_val[expr._cache_key] = o
            self._simplification_cache_key[expr._cache_key] = o
        return o
开发者ID:redragonvn,项目名称:claripy,代码行数:55,代码来源:backend_z3.py

示例11: solve_for

def solve_for(inps):
    r1, r2, r3, r4, v11 = [BVV(x, 64) for x in map(int, inps.split(', '))]
    print r1, r2, r3, r4, v11

    for choice1, choice2, choice3 in all_choices():
        v6 = choose_op(r1, r2, choice1)
        v6_1 = choose_op(v6, r3, choice2)
        v6_2 = choose_op(v6_1, r4, choice3)

        if simplify(weird_op(v6_2)) == v11:
            return choice1, choice2, choice3
开发者ID:isislab,项目名称:CTF-Solutions,代码行数:11,代码来源:rasf.py

示例12: interpret

 def interpret(self, i, j):
     """ Convert logical indices i and j into a physical index. """
     Bx = i / self.lsize0()
     By = j / self.lsize1()
     p = self.fragment(Bx, By)
     if not self.terminal():
         x = i % self.lsize0()
         y = j % self.lsize1()
         p *= self.elem_size()
         p += self.rest.interpret(x, y)
     return z3.simplify(p)
开发者ID:mbdriscoll,项目名称:LogicalIndexingLibrary,代码行数:11,代码来源:lil.py

示例13: _pattern

	def _pattern(self, pattern, L):
		# we can exit early if we have a variable
		if self._is_var(pattern):
			return True
		constraints = [True]
		f, *args = breakout(pattern)
		# now we'll recurse appropriately
		for i, arg in enumerate(args):
			constraints.append( self._connect(f, i, arg, L) )
			constraints.append( self._pattern(arg, L))
		return simplify(And(constraints))
开发者ID:csmith49,项目名称:morlock,代码行数:11,代码来源:equations.py

示例14: getValue

  def getValue(self, op):
    assert(self.m <> None)
    
    if (op |iss| RegOp):
      var = map(lambda b: z3.BitVec(str(b),8), op.getLocations())
      var = map(lambda b: self.m[b], var)
      if (len(var) > 1):
        return z3.simplify(z3.Concat(var)).as_signed_long()
      else:
        return z3.simplify(var[0]).as_signed_long()
    elif (op.isMem()):
      array = z3.Array(op.name, z3.BitVecSort(16), z3.BitVecSort(8))
      f = self.m[array]
      
      #print self.m
      
      es = f.as_list()[:-1]

      var = []
      
      for loc in op.getLocations():
        byte = None
        for entry in es:
          #print entry
          if loc.getIndex() == entry[0].as_signed_long():
            byte = entry[1]#.as_signed_long()
            break
        
        if (byte == None):
          byte = f.else_value()
          
        var.append(byte)
        
      var.reverse()
      
      if (len(var) > 1):  
        return z3.simplify(z3.Concat(var)).as_signed_long()
      else:
        return z3.simplify(var[0]).as_signed_long()
    else:
      assert(0)
开发者ID:Debug-Orz,项目名称:SEA,代码行数:41,代码来源:SMT.py

示例15: prove

    def prove(self, hypotheses, conclusion=None, report=None):
        report = self.reportFun(report)

        if (conclusion is None):
            conclusion = hypotheses
            hypotheses = True

        x_hyps, x_concl = self.analyse_expt(z3.And(hypotheses,z3.Not(conclusion)), conclusion, report)
        f_hyps, f_concl = self.fun_to_var([x_hyps, x_concl], report)[:]
        if(f_hyps is None):
            hyps = f_hyps
        else:
            hyps = z3.simplify(f_hyps)
        if(f_concl is None):
            concl = f_concl
        else:
            concl = z3.simplify(f_concl)

        report('to_smt_w_expt.prove:')
        report('  hypotheses = ', hyps)
        report('  conclusion = ', concl)
        return super(to_smt_w_expt, self).prove(hyps, concl)
开发者ID:harshrc,项目名称:acl2,代码行数:22,代码来源:RewriteExpt.py


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