Ejemplo n.º 1
0
def prime_equillibrium(vocab, signature, aux=set()):
    """
    Generates the formula:
       x = x' & y = y' & n* = n*' & ...
    for all the symbols in the vocabulary
    @param vocab symbols to process
    @param signature a (sorted) signature
    @param aux symbols to skip
    """
    res = []
    vocab_prime = vocab.prime()

    for v, vprime in vocab_prime.locals:
        # HACK: Exclude non-deterministic variables
        if v.literal.startswith('nondet') or v in aux: continue

        if tuple(signature.sorts[v][0].from_) == ("V", "V"):
            f = FolFormula(eqrel, [FolFormula(v), FolFormula(vprime)])
        elif tuple(signature.sorts[v][0].from_) == ("V", ):
            f = FolFormula(eqpred, [FolFormula(v), FolFormula(vprime)])
        else:
            f = FolFormula(FolWithEquality.eq,
                           [FolFormula(v), FolFormula(vprime)])
        res.append(f)

    return FolFormula.conjunction(res), vocab_prime
Ejemplo n.º 2
0
def transition_system(syn, loop, vocab, signature):
    fin, vocab_prime = prime_equillibrium(vocab, signature)
    L = syn.expansion.parser
    rho = FolScheme(L * 'wp_ea([?loopBody],[?trans])')(loop.body, fin)
    rho0 = FolFormula.conjunction(syn.first_pass([rho]))
    # set back in time; x->x0, x'->x
    rho0 = vocab.to_past(rho0)
    rho0 = vocab_prime.to_past(rho0)
    return rho0
Ejemplo n.º 3
0
def generate_p_properties(syn, consts, vocab):
    """
    Extra properties:  {n(u,v) | u,v program variables + null}
    """
    ptot_template = FolFormula.conjunction(
        map(FolScheme, syn.expansion("ptot_([?u],[?v])")))

    extras = [('p%s%s' % (u, v), ptot_template(u, v)) for u in consts
              for v in consts]

    return AbstractionProperties.from_named_formulas(extras, vocab)
Ejemplo n.º 4
0
 def formula(self, fol_formula):
     if isinstance(fol_formula, (str, unicode)):
         fol_formula = FolFormula.conjunction(self.expansion([fol_formula]))
     f_aux = AuxTransformers.renumber_bound_vars(fol_formula)
     return fol_formula_to_z3(f_aux, self.z3_decls)
Ejemplo n.º 5
0
def generate_gamma(syn, preds, decls):
    dtca = Identifier('dtca', '?')
    starred = [z for z in preds if '*' in z.literal]
    gamma = FolFormula.conjunction(
        [FolFormula(dtca, [FolFormula(z)]) for z in starred])
    return generate_z3_condition(gamma, syn, decls)
Ejemplo n.º 6
0
def generate_z3_condition(folformula, syn, decls):
    c = list(syn.first_pass([folformula]))
    f = FolFormula.conjunction(c)
    f_aux = AuxTransformers.renumber_bound_vars(f)
    f_z3 = fol_formula_to_z3(f_aux, decls)
    return hoist_forall(f_z3)
Ejemplo n.º 7
0
 def __call__(self, program):
     wps = WeakestPreSynthesis()    
     wps.configure(detptr_libraries())
     wps.syn.libs += [self.VC] #TODO - change        
     
     formulas , decls  =  wps_formula_get(wps,program)
     
     I_args = inv_args_get(wps, "I")
     
     formula = FolFormula.conjunction(formulas)
         
     prefix           =  wp_forall_prefix_get(formula)| set([Identifier('null', 'const')])
     bounded_prefix   =  AuxTransformers.get_all_bound_vars(formula)
     prefix-=bounded_prefix
     
     
     pprint( formulas )
     print  prefix
     
     
             
     z3_formulas_with_blasting = []    
 
     from shape2horn import hoist_forall
     from shape2horn import blast_horn
     from shape2horn import hoist_horn
     formulas_with_implies = []
     ackm_bools            = {}
     ackm_bools_to_vars    = {}
     
     #sanity = FormulaSanity()
             
     watch = Stopwatch()
     with watch:
             
         for f in formulas:
             
             if f.root == 'true':                    
                 continue 
             
             head    = f.subtrees[1]        
             body    = f.subtrees[0]
             head_ls = FolFormula.split(head) #splits conjunctions in head
             
             for i in head_ls:
                 #creates new formulas of form: body -> i
                 f_with_implies = create_f_with_implies(body,i)            
                 formulas_with_implies.append( f_with_implies )
                             
         for s in formulas_with_implies:
             print '--------   Input Clause   ----------------'
             print s      
             s_with_gamma = gamma_add( s )
             #renumber_bound_vars() renames bounded vars to unique numbers
             s_with_gamma = AuxTransformers.renumber_bound_vars( s_with_gamma )        
             print s_with_gamma                             
             z3_f = transform_formula_to_z3(prefix, s_with_gamma, decls)
             for f in hoist_horn(z3_f[0]):
                z3_f_hoisted = hoist_forall(f)
             		
                print '--------  Hoisted Formula  ------------------'
                print z3_f_hoisted
                blasted_f  =  blast_horn(z3_f_hoisted)
             
                print '--------  Blasted Formula  ---------------------'             
                #print blasted_f
                if 0:                        
                   blasted_f_with_replaced_n = replace_nstar_with_bools( blasted_f, \
                                                  decls, ackm_bools, ackm_bools_to_vars )            
                   f_with_ackm_reduction = ackerman_reduction_get( \
                                         blasted_f_with_replaced_n , ackm_bools_to_vars )
                #print ackm_bools_to_vars            
                z3_formulas_with_blasting.append( blasted_f )
         
         #benchmark_print_to_file(h, z3_formulas_with_blasting)            
         formulas_solver ( self, z3_formulas_with_blasting, decls["I"], I_args )
     
     print 'Total sovling time: ',watch.total_time,'sec'
Ejemplo n.º 8
0
def conjunct_formulas( fs ):
    return FolFormula.conjunction( fs )
Ejemplo n.º 9
0
def conjunct_formulas( fs ):
    return FolFormula.conjunction( fs )