mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-03 21:09:11 +00:00 
			
		
		
		
	Merge branch 'unstable' of https://github.com/Z3Prover/z3 into unstable
This commit is contained in:
		
						commit
						6f0d76a62e
					
				
					 172 changed files with 5110 additions and 22752 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,10 @@
 | 
			
		|||
 | 
			
		||||
/*++
 | 
			
		||||
Copyright (c) 2015 Microsoft Corporation
 | 
			
		||||
 | 
			
		||||
--*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include"arith_bounds_tactic.h"
 | 
			
		||||
#include"arith_decl_plugin.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -485,10 +485,9 @@ public:
 | 
			
		|||
            return;
 | 
			
		||||
        }
 | 
			
		||||
                
 | 
			
		||||
        unsigned size = g->size();
 | 
			
		||||
        expr_ref new_f1(m), new_f2(m);
 | 
			
		||||
        proof_ref new_pr1(m), new_pr2(m);
 | 
			
		||||
        for (unsigned idx = 0; idx < size; idx++) {
 | 
			
		||||
        for (unsigned idx = 0; !g->inconsistent() && idx < g->size(); idx++) {
 | 
			
		||||
            m_rw1(g->form(idx), new_f1, new_pr1);
 | 
			
		||||
            TRACE("card2bv", tout << "Rewriting " << mk_ismt2_pp(new_f1.get(), m) << std::endl;);
 | 
			
		||||
            m_rw2.rewrite(new_f1, new_f2);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -854,7 +854,7 @@ private:
 | 
			
		|||
            m_temporary_ints(m),
 | 
			
		||||
            m_used_dependencies(m),
 | 
			
		||||
            m_rw(*this) {
 | 
			
		||||
            updt_params(p);
 | 
			
		||||
            updt_params(p);            
 | 
			
		||||
            m_b_rw.set_flat(false); // no flattening otherwise will blowup the memory
 | 
			
		||||
            m_b_rw.set_elim_and(true);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -871,12 +871,17 @@ private:
 | 
			
		|||
            m_max_memory   = megabytes_to_bytes(p.get_uint("max_memory", UINT_MAX));
 | 
			
		||||
            m_all_clauses_limit = p.get_uint("pb2bv_all_clauses_limit", 8);
 | 
			
		||||
            m_cardinality_limit = p.get_uint("pb2bv_cardinality_limit", UINT_MAX);
 | 
			
		||||
            m_b_rw.updt_params(p);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void collect_param_descrs(param_descrs & r) {
 | 
			
		||||
            insert_max_memory(r);
 | 
			
		||||
            insert_max_memory(r);            
 | 
			
		||||
            r.insert("pb2bv_all_clauses_limit", CPK_UINT, "(default: 8) maximum number of literals for using equivalent CNF encoding of PB constraint.");
 | 
			
		||||
            r.insert("pb2bv_cardinality_limit", CPK_UINT, "(default: inf) limit for using arc-consistent cardinality constraint encoding.");
 | 
			
		||||
 | 
			
		||||
            m_b_rw.get_param_descrs(r);        
 | 
			
		||||
            r.erase("flat"); 
 | 
			
		||||
            r.erase("elim_and");            
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        void set_cancel(bool f) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										150
									
								
								src/tactic/fpa/const_intro_rewriter.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								src/tactic/fpa/const_intro_rewriter.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,150 @@
 | 
			
		|||
/*++
 | 
			
		||||
Copyright (c) 2012 Microsoft Corporation
 | 
			
		||||
 | 
			
		||||
Module Name:
 | 
			
		||||
 | 
			
		||||
    const_intro_rewriter.h
 | 
			
		||||
 | 
			
		||||
Abstract:
 | 
			
		||||
 | 
			
		||||
    Rewriter for converting FPA to BV
 | 
			
		||||
 | 
			
		||||
Author:
 | 
			
		||||
 | 
			
		||||
    Christoph (cwinter) 2012-02-09
 | 
			
		||||
 | 
			
		||||
Notes:
 | 
			
		||||
 | 
			
		||||
--*/
 | 
			
		||||
 | 
			
		||||
#ifndef _CONST_INTRO_REWRITER_H_
 | 
			
		||||
#define _CONST_INTRO_REWRITER_H_
 | 
			
		||||
 | 
			
		||||
#include"cooperate.h"
 | 
			
		||||
#include"bv_decl_plugin.h"
 | 
			
		||||
#include"tactic_exception.h"
 | 
			
		||||
#include"fpa2bv_converter_prec.h"
 | 
			
		||||
 | 
			
		||||
struct const_intro_rewriter_cfg : public default_rewriter_cfg {
 | 
			
		||||
    ast_manager              & m_manager;        
 | 
			
		||||
 | 
			
		||||
    expr                     * m_exp;
 | 
			
		||||
    func_decl_ref_vector       m_introduced_consts;
 | 
			
		||||
    obj_map<func_decl, app*>   m_const2term_map;
 | 
			
		||||
 | 
			
		||||
    unsigned long long         m_max_memory;
 | 
			
		||||
    unsigned                   m_max_steps;
 | 
			
		||||
 | 
			
		||||
    fpa_util                   m_float_util;
 | 
			
		||||
 | 
			
		||||
    ast_manager & m() const { return m_manager; }
 | 
			
		||||
 | 
			
		||||
    const_intro_rewriter_cfg(ast_manager & m, params_ref const & p):
 | 
			
		||||
        m_manager(m),
 | 
			
		||||
        m_introduced_consts(m),
 | 
			
		||||
        m_float_util(m) {
 | 
			
		||||
        updt_params(p);
 | 
			
		||||
        // We need to make sure that the mananger has the BV plugin loaded.
 | 
			
		||||
        symbol s_bv("bv");
 | 
			
		||||
        if (!m_manager.has_plugin(s_bv))
 | 
			
		||||
            m_manager.register_plugin(s_bv, alloc(bv_decl_plugin));        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ~const_intro_rewriter_cfg() {
 | 
			
		||||
        for (obj_map<func_decl, app*>::iterator it = m_const2term_map.begin();
 | 
			
		||||
             it != m_const2term_map.end();
 | 
			
		||||
             it++)
 | 
			
		||||
        {
 | 
			
		||||
            m().dec_ref(it->m_key);
 | 
			
		||||
            m().dec_ref(it->m_value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void cleanup_buffers() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updt_params(params_ref const & p) {
 | 
			
		||||
        m_max_memory     = megabytes_to_bytes(p.get_uint("max_memory", UINT_MAX));
 | 
			
		||||
        m_max_steps      = p.get_uint("max_steps", UINT_MAX);        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool max_steps_exceeded(unsigned num_steps) const { 
 | 
			
		||||
        cooperate("fpa2bv");
 | 
			
		||||
        if (memory::get_allocation_size() > m_max_memory)
 | 
			
		||||
            throw tactic_exception(TACTIC_MAX_MEMORY_MSG);
 | 
			
		||||
        return num_steps > m_max_steps;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) {
 | 
			
		||||
        TRACE("fpa2bv_rw", tout << "APP: " << f->get_name() << std::endl; );
 | 
			
		||||
 | 
			
		||||
        if (num == 0 && f->get_family_id() == null_family_id && m_float_util.is_float(f->get_range())) {
 | 
			
		||||
    		app * f_cnst = m_manager.mk_const(f);
 | 
			
		||||
            if (!m_introduced_consts.contains(f))
 | 
			
		||||
			    m_introduced_consts.push_back(f);
 | 
			
		||||
            result = f_cnst;
 | 
			
		||||
            return BR_DONE;
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
        if (f->get_family_id() == m_float_util.get_family_id()) {
 | 
			
		||||
            switch (f->get_decl_kind()) {
 | 
			
		||||
            case OP_FPA_ADD:
 | 
			
		||||
            case OP_FPA_SUB:
 | 
			
		||||
            case OP_FPA_NEG:
 | 
			
		||||
            case OP_FPA_MUL:
 | 
			
		||||
            case OP_FPA_DIV:
 | 
			
		||||
            case OP_FPA_REM:
 | 
			
		||||
            case OP_FPA_ABS:
 | 
			
		||||
            case OP_FPA_MIN:
 | 
			
		||||
            case OP_FPA_MAX:
 | 
			
		||||
            case OP_FPA_FMA:
 | 
			
		||||
            case OP_FPA_SQRT:
 | 
			
		||||
            case OP_FPA_TO_FP:
 | 
			
		||||
            case OP_FPA_ROUND_TO_INTEGRAL:
 | 
			
		||||
				{					
 | 
			
		||||
					app * f_app = m_manager.mk_app(f, num, args);
 | 
			
		||||
            		result = m_manager.mk_fresh_const(NULL, f->get_range());             	            	
 | 
			
		||||
                    func_decl * fd = to_app(result)->get_decl();
 | 
			
		||||
					m_introduced_consts.push_back(fd);
 | 
			
		||||
                    m_const2term_map.insert_if_not_there(fd, f_app);
 | 
			
		||||
                    m().inc_ref(fd);
 | 
			
		||||
                    m().inc_ref(f_app);
 | 
			
		||||
            		return BR_DONE;
 | 
			
		||||
				}
 | 
			
		||||
            default:
 | 
			
		||||
            	return BR_FAILED;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return BR_FAILED;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool reduce_quantifier(quantifier * old_q, 
 | 
			
		||||
                           expr * new_body, 
 | 
			
		||||
                           expr * const * new_patterns, 
 | 
			
		||||
                           expr * const * new_no_patterns,
 | 
			
		||||
                           expr_ref & result,
 | 
			
		||||
                           proof_ref & result_pr) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool reduce_var(var * t, expr_ref & result, proof_ref & result_pr) { 
 | 
			
		||||
        return false; 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool pre_visit(expr * t){
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template class rewriter_tpl<const_intro_rewriter_cfg>;
 | 
			
		||||
 | 
			
		||||
struct const_intro_rewriter : public rewriter_tpl<const_intro_rewriter_cfg> {
 | 
			
		||||
    const_intro_rewriter_cfg m_cfg;
 | 
			
		||||
    const_intro_rewriter(ast_manager & m, params_ref const & p):
 | 
			
		||||
        rewriter_tpl<const_intro_rewriter_cfg>(m, m.proofs_enabled(), m_cfg),
 | 
			
		||||
        m_cfg(m, p) {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										1313
									
								
								src/tactic/fpa/fpa2bv_approx_tactic.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1313
									
								
								src/tactic/fpa/fpa2bv_approx_tactic.cpp
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										33
									
								
								src/tactic/fpa/fpa2bv_approx_tactic.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/tactic/fpa/fpa2bv_approx_tactic.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
/*++
 | 
			
		||||
Copyright (c) 2012 Microsoft Corporation
 | 
			
		||||
 | 
			
		||||
Module Name:
 | 
			
		||||
 | 
			
		||||
    fpa2bv_lazy_tactic.h
 | 
			
		||||
 | 
			
		||||
Abstract:
 | 
			
		||||
 | 
			
		||||
    Tactic that converts floating points to bit-vectors lazily
 | 
			
		||||
 | 
			
		||||
Author:
 | 
			
		||||
 | 
			
		||||
    Aleksander Zeljic 2012-11-15
 | 
			
		||||
 | 
			
		||||
Notes:
 | 
			
		||||
 | 
			
		||||
--*/
 | 
			
		||||
#ifndef _FPA2BV_APPROX_TACTIC_
 | 
			
		||||
#define _FPA2BV_APPROX_TACTIC_
 | 
			
		||||
 | 
			
		||||
#include"params.h"
 | 
			
		||||
class ast_manager;
 | 
			
		||||
class tactic;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
tactic * mk_fpa2bv_approx_tactic(ast_manager & m, params_ref const & p = params_ref());
 | 
			
		||||
/*
 | 
			
		||||
  ADD_TACTIC("fpa2bv_approx", "An iterative approximation based bit-blasting decision procedure for FPA.", "mk_fpa2bv_approx_tactic(m, p)")
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										1594
									
								
								src/tactic/fpa/fpa2bv_converter_prec.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1594
									
								
								src/tactic/fpa/fpa2bv_converter_prec.cpp
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										103
									
								
								src/tactic/fpa/fpa2bv_converter_prec.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								src/tactic/fpa/fpa2bv_converter_prec.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,103 @@
 | 
			
		|||
/*++
 | 
			
		||||
Copyright (c) 2012 Microsoft Corporation
 | 
			
		||||
 | 
			
		||||
Module Name:
 | 
			
		||||
 | 
			
		||||
    fpa2bv_converter_prec.h
 | 
			
		||||
 | 
			
		||||
Abstract:
 | 
			
		||||
 | 
			
		||||
    Conversion routines for Floating Point -> Bit-Vector
 | 
			
		||||
 | 
			
		||||
Author:
 | 
			
		||||
 | 
			
		||||
    Christoph (cwinter) 2012-02-09
 | 
			
		||||
 | 
			
		||||
Notes:
 | 
			
		||||
 | 
			
		||||
--*/
 | 
			
		||||
#ifndef _FPA2BV_CONVERTER_PREC
 | 
			
		||||
#define _FPA2BV_CONVERTER_PREC
 | 
			
		||||
 | 
			
		||||
#include"ast.h"
 | 
			
		||||
#include"obj_hashtable.h"
 | 
			
		||||
#include"ref_util.h"
 | 
			
		||||
#include"fpa_decl_plugin.h"
 | 
			
		||||
#include"bv_decl_plugin.h"
 | 
			
		||||
#include"model_converter.h"
 | 
			
		||||
#include"basic_simplifier_plugin.h"
 | 
			
		||||
#include"fpa2bv_converter.h"
 | 
			
		||||
 | 
			
		||||
#define MAX_PRECISION 100
 | 
			
		||||
#define MIN_PRECISION 0
 | 
			
		||||
 | 
			
		||||
class fpa2bv_prec_model_converter;
 | 
			
		||||
 | 
			
		||||
enum fpa_approximation_mode { 
 | 
			
		||||
    FPAA_PRECISE,      // Always use precise encoding
 | 
			
		||||
    FPAA_FIXBITS,      // Approximate by fixing some bits of the encoding
 | 
			
		||||
    FPAA_SMALL_FLOATS  // Approximate by using smaller floats
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define FPAA_DEFAULT_MODE FPAA_SMALL_FLOATS
 | 
			
		||||
 | 
			
		||||
class fpa2bv_converter_prec : public fpa2bv_converter {
 | 
			
		||||
    fpa_approximation_mode m_mode;
 | 
			
		||||
 | 
			
		||||
    void fix_bits(unsigned prec, expr_ref rounded, unsigned sbits, unsigned ebits);//expr_ref& fixed,
 | 
			
		||||
    
 | 
			
		||||
    void mk_small_op(func_decl * f, unsigned prec, unsigned num, expr * const * args, func_decl_ref & small_op, expr_ref_vector & cast_args);
 | 
			
		||||
    void mk_small_op(func_decl * f, unsigned new_ebits, unsigned new_sbits, unsigned num, expr * const * args, func_decl_ref & small_op, expr_ref_vector & cast_args);
 | 
			
		||||
    void mk_cast_small_to_big(func_decl * big_fd, expr * arg, expr_ref & result);
 | 
			
		||||
    void mk_cast_small_to_big(unsigned sbits, unsigned ebits, expr * arg, expr_ref & result);
 | 
			
		||||
    void match_sorts(expr * a, expr * b, expr_ref & n_a, expr_ref & n_b);
 | 
			
		||||
    void establish_sort(unsigned num, expr * const * args, unsigned & ebits, unsigned & sbits);
 | 
			
		||||
public:
 | 
			
		||||
    fpa2bv_converter_prec(ast_manager & m, fpa_approximation_mode mode);    
 | 
			
		||||
 | 
			
		||||
    void mk_const(func_decl * f, unsigned prec, expr_ref & result);
 | 
			
		||||
 | 
			
		||||
    void mk_eq(expr * a, expr * b, expr_ref & result);
 | 
			
		||||
    void mk_ite(expr * c, expr * t, expr * f, expr_ref & result);    
 | 
			
		||||
 | 
			
		||||
    void mk_add(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_sub(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_uminus(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_mul(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_div(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_remainder(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_abs(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_min(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_max(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_fusedma(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_sqrt(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_round_to_integral(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
 | 
			
		||||
    void mk_float_eq(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_float_lt(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_float_gt(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_float_le(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_float_ge(func_decl * f, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    void mk_is_zero(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_nzero(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_pzero(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_sign_minus(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_nan(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_inf(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_normal(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
    void mk_is_subnormal(func_decl * f, unsigned prec, unsigned num, expr * const * args, expr_ref & result);
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    void reset() {
 | 
			
		||||
        dec_ref_map_key_values(m, m_const2bv);
 | 
			
		||||
        dec_ref_map_key_values(m, m_rm_const2bv);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										261
									
								
								src/tactic/fpa/fpa2bv_rewriter_prec.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										261
									
								
								src/tactic/fpa/fpa2bv_rewriter_prec.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,261 @@
 | 
			
		|||
/*++
 | 
			
		||||
Copyright (c) 2012 Microsoft Corporation
 | 
			
		||||
 | 
			
		||||
Module Name:
 | 
			
		||||
 | 
			
		||||
    fpa2bv_rewriter.h
 | 
			
		||||
 | 
			
		||||
Abstract:
 | 
			
		||||
 | 
			
		||||
    Rewriter for converting FPA to BV
 | 
			
		||||
 | 
			
		||||
Author:
 | 
			
		||||
 | 
			
		||||
    Christoph (cwinter) 2012-02-09
 | 
			
		||||
 | 
			
		||||
Notes:
 | 
			
		||||
 | 
			
		||||
--*/
 | 
			
		||||
 | 
			
		||||
#ifndef _FPA2BV_REWRITER_H_
 | 
			
		||||
#define _FPA2BV_REWRITER_H_
 | 
			
		||||
 | 
			
		||||
#include"cooperate.h"
 | 
			
		||||
#include"rewriter_def.h"
 | 
			
		||||
#include"bv_decl_plugin.h"
 | 
			
		||||
#include"fpa2bv_converter_prec.h"
 | 
			
		||||
#include"tactic_exception.h"
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
struct fpa2bv_rewriter_prec_cfg : public default_rewriter_cfg {
 | 
			
		||||
    ast_manager              & m_manager;    
 | 
			
		||||
    expr_ref_vector            m_out; 
 | 
			
		||||
    fpa2bv_converter_prec    & m_conv;
 | 
			
		||||
    obj_map<func_decl,unsigned> * cnst2prec_map;
 | 
			
		||||
 | 
			
		||||
    unsigned precision;
 | 
			
		||||
    unsigned long long         m_max_memory;
 | 
			
		||||
    unsigned                   m_max_steps;
 | 
			
		||||
 | 
			
		||||
    ast_manager & m() const { return m_manager; }
 | 
			
		||||
 | 
			
		||||
    fpa2bv_rewriter_prec_cfg(ast_manager & m,  fpa2bv_converter_prec & c, params_ref const & p):
 | 
			
		||||
        m_manager(m),
 | 
			
		||||
        m_out(m),
 | 
			
		||||
        m_conv(c) {
 | 
			
		||||
        updt_params(p);
 | 
			
		||||
        // We need to make sure that the mananger has the BV plugin loaded.
 | 
			
		||||
        symbol s_bv("bv");
 | 
			
		||||
        if (!m_manager.has_plugin(s_bv))
 | 
			
		||||
            m_manager.register_plugin(s_bv, alloc(bv_decl_plugin));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ~fpa2bv_rewriter_prec_cfg() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void cleanup_buffers() {
 | 
			
		||||
        m_out.finalize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    unsigned get_precision(func_decl * f){
 | 
			
		||||
    	if(cnst2prec_map->contains(f))
 | 
			
		||||
    		return cnst2prec_map->find(f);
 | 
			
		||||
    	else return precision;
 | 
			
		||||
    }
 | 
			
		||||
    void set_precision(unsigned p) { precision=p; }
 | 
			
		||||
    void set_mappings(obj_map<func_decl,unsigned> * o2p)
 | 
			
		||||
    {
 | 
			
		||||
    	this->cnst2prec_map=o2p;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updt_params(params_ref const & p) {
 | 
			
		||||
        m_max_memory     = megabytes_to_bytes(p.get_uint("max_memory", UINT_MAX));
 | 
			
		||||
        m_max_steps      = p.get_uint("max_steps", UINT_MAX);        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool max_steps_exceeded(unsigned num_steps) const {
 | 
			
		||||
        cooperate("fpa2bv");
 | 
			
		||||
                return num_steps > m_max_steps;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) {
 | 
			
		||||
    	TRACE("fpa2bv_rw", tout << "APP: " << f->get_name() << std::endl; );
 | 
			
		||||
 | 
			
		||||
    	if (num == 0 && f->get_family_id() == null_family_id && m_conv.is_float(f->get_range())) {
 | 
			
		||||
    		m_conv.mk_const(f, get_precision(f), result);
 | 
			
		||||
    		return BR_DONE;
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
    	if (num == 0 && f->get_family_id() == null_family_id && m_conv.is_rm(f->get_range())) {
 | 
			
		||||
    		m_conv.mk_rm_const(f, result);
 | 
			
		||||
    		return BR_DONE;
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
        if (m().is_eq(f)) {
 | 
			
		||||
            SASSERT(num == 2);
 | 
			
		||||
            //SASSERT(m().get_sort(args[0]) == m().get_sort(args[1]));
 | 
			
		||||
            sort * ds = f->get_domain()[0];
 | 
			
		||||
            if (m_conv.is_float(ds)) {
 | 
			
		||||
                m_conv.mk_eq(args[0], args[1], result);
 | 
			
		||||
                return BR_DONE;
 | 
			
		||||
            }
 | 
			
		||||
            else if (m_conv.is_rm(ds)) {
 | 
			
		||||
                result = m().mk_eq(args[0], args[1]);
 | 
			
		||||
                return BR_DONE;
 | 
			
		||||
            }
 | 
			
		||||
            return BR_FAILED;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    	if (m().is_ite(f)) {
 | 
			
		||||
    		SASSERT(num == 3);
 | 
			
		||||
    		if (m_conv.is_float(args[1])) {
 | 
			
		||||
    			m_conv.mk_ite(args[0], args[1], args[2], result);
 | 
			
		||||
    			return BR_DONE;
 | 
			
		||||
    		}
 | 
			
		||||
    		return BR_FAILED;
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
    	expr_ref  newAssertion(m_manager);
 | 
			
		||||
 | 
			
		||||
    	if (m_conv.is_float_family(f))
 | 
			
		||||
    	{
 | 
			
		||||
    		switch (f->get_decl_kind())
 | 
			
		||||
    		{
 | 
			
		||||
    		case OP_FPA_RM_NEAREST_TIES_TO_AWAY:
 | 
			
		||||
    		case OP_FPA_RM_NEAREST_TIES_TO_EVEN:
 | 
			
		||||
    		case OP_FPA_RM_TOWARD_NEGATIVE:
 | 
			
		||||
    		case OP_FPA_RM_TOWARD_POSITIVE:
 | 
			
		||||
    		case OP_FPA_RM_TOWARD_ZERO: m_conv.mk_rounding_mode(f, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_NUM: m_conv.mk_numeral(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_PLUS_INF: m_conv.mk_pinf(f, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_MINUS_INF: m_conv.mk_ninf(f, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_PLUS_ZERO: m_conv.mk_pzero(f, result); return BR_DONE; 
 | 
			
		||||
			case OP_FPA_MINUS_ZERO: m_conv.mk_nzero(f, result); return BR_DONE;	
 | 
			
		||||
			case OP_FPA_NAN: m_conv.mk_nan(f, result); return BR_DONE;			
 | 
			
		||||
    		case OP_FPA_ADD:
 | 
			
		||||
    			m_conv.mk_add(f,get_precision(f), num, args, result);return BR_DONE;
 | 
			
		||||
    		case OP_FPA_SUB:
 | 
			
		||||
    			m_conv.mk_sub(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_NEG:
 | 
			
		||||
    			m_conv.mk_uminus(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_MUL:
 | 
			
		||||
    			m_conv.mk_mul(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_DIV:
 | 
			
		||||
    			m_conv.mk_div(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_REM:
 | 
			
		||||
    			m_conv.mk_remainder(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
			case OP_FPA_ABS: m_conv.mk_abs(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_MIN: m_conv.mk_min(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_MAX: m_conv.mk_max(f, get_precision(f), num, args, result); return BR_DONE;    		
 | 
			
		||||
			case OP_FPA_FMA:
 | 
			
		||||
    			m_conv.mk_fusedma(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_SQRT:
 | 
			
		||||
    			m_conv.mk_sqrt(f, get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_ROUND_TO_INTEGRAL: m_conv.mk_round_to_integral(f,  get_precision(f), num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_EQ: m_conv.mk_float_eq(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_LT: m_conv.mk_float_lt(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_GT: m_conv.mk_float_gt(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_LE: m_conv.mk_float_le(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_GE: m_conv.mk_float_ge(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_IS_ZERO: m_conv.mk_is_zero(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_IS_NAN: m_conv.mk_is_nan(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_IS_INF: m_conv.mk_is_inf(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_IS_NORMAL: m_conv.mk_is_normal(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_IS_SUBNORMAL: m_conv.mk_is_subnormal(f, num, args, result); return BR_DONE;
 | 
			
		||||
			case OP_FPA_IS_POSITIVE: m_conv.mk_is_positive(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_IS_NEGATIVE: m_conv.mk_is_negative(f, num, args, result); return BR_DONE;
 | 
			
		||||
    		case OP_FPA_TO_FP: m_conv.mk_to_fp(f, num, args, result); return BR_DONE;
 | 
			
		||||
			case OP_FPA_TO_FP_UNSIGNED: m_conv.mk_to_fp_unsigned(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_FP: m_conv.mk_fp(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_TO_UBV: m_conv.mk_to_ubv(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_TO_SBV: m_conv.mk_to_sbv(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_TO_REAL: m_conv.mk_to_real(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_TO_IEEE_BV: m_conv.mk_to_ieee_bv(f, num, args, result); return BR_DONE;
 | 
			
		||||
            case OP_FPA_INTERNAL_BVWRAP: 
 | 
			
		||||
            case OP_FPA_INTERNAL_BVUNWRAP:
 | 
			
		||||
            case OP_FPA_INTERNAL_TO_REAL_UNSPECIFIED:
 | 
			
		||||
            case OP_FPA_INTERNAL_TO_UBV_UNSPECIFIED: 
 | 
			
		||||
            case OP_FPA_INTERNAL_TO_SBV_UNSPECIFIED: return BR_FAILED;
 | 
			
		||||
            default:
 | 
			
		||||
                TRACE("fpa2bv", tout << "unsupported operator: " << f->get_name() << "\n";
 | 
			
		||||
                      for (unsigned i = 0; i < num; i++) tout << mk_ismt2_pp(args[i], m()) << std::endl;);
 | 
			
		||||
                NOT_IMPLEMENTED_YET();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (f->get_family_id() == null_family_id)
 | 
			
		||||
        {
 | 
			
		||||
            bool is_float_uf = m_conv.is_float(f->get_range());
 | 
			
		||||
            unsigned i = 0;
 | 
			
		||||
            while (!is_float_uf && i < num)
 | 
			
		||||
            {
 | 
			
		||||
                is_float_uf = m_conv.is_float(f->get_domain()[i]);
 | 
			
		||||
                i++;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (is_float_uf)
 | 
			
		||||
            {
 | 
			
		||||
                m_conv.mk_uninterpreted_function(f, num, args, result);
 | 
			
		||||
                return BR_DONE;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return BR_FAILED;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool pre_visit(expr * t)
 | 
			
		||||
    {
 | 
			
		||||
    	 TRACE("pre_visit_prec", tout << mk_ismt2_pp(t, m()) << std::endl;);
 | 
			
		||||
    	 
 | 
			
		||||
    	 if(t->get_kind() == AST_APP && is_app_of(t, to_app(t)->get_family_id(), OP_EQ)) {
 | 
			
		||||
    	     //Equation over non-boolean expressions, it should be of form constantI = subexprI
 | 
			
		||||
    		 app * a = to_app(t);
 | 
			
		||||
 | 
			
		||||
             if (a->get_num_args() == 2) {
 | 
			
		||||
                 expr * a0 = a->get_arg(0);
 | 
			
		||||
                 expr * a1 = a->get_arg(1);
 | 
			
		||||
                 func_decl * cnst = 0;
 | 
			
		||||
 | 
			
		||||
                 if (a0->get_kind() == AST_APP && cnst2prec_map->contains(to_app(a0)->get_decl()))
 | 
			
		||||
                     cnst = to_app(a0)->get_decl();
 | 
			
		||||
                 else if (a1->get_kind() == AST_APP && cnst2prec_map->contains(to_app(a1)->get_decl()))
 | 
			
		||||
                     cnst = to_app(a1)->get_decl();
 | 
			
		||||
    		 
 | 
			
		||||
                 if (cnst == 0) {
 | 
			
		||||
                     // For all equalities that were in the original problem, we don't
 | 
			
		||||
                     // have any precision tracking, so those simply get 100% precision.
 | 
			
		||||
                     set_precision(100);
 | 
			
		||||
                 }
 | 
			
		||||
                 else
 | 
			
		||||
                     set_precision(cnst2prec_map->find(cnst));
 | 
			
		||||
                 TRACE("pre_visit_prec", tout << "Precision = " << get_precision(NULL) << std::endl;);
 | 
			
		||||
             }
 | 
			
		||||
    	 }
 | 
			
		||||
         return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool reduce_quantifier(quantifier * old_q, 
 | 
			
		||||
                           expr * new_body, 
 | 
			
		||||
                           expr * const * new_patterns, 
 | 
			
		||||
                           expr * const * new_no_patterns,
 | 
			
		||||
                           expr_ref & result,
 | 
			
		||||
                           proof_ref & result_pr) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool reduce_var(var * t, expr_ref & result, proof_ref & result_pr) { 
 | 
			
		||||
        return false; 
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template class rewriter_tpl<fpa2bv_rewriter_prec_cfg>;
 | 
			
		||||
 | 
			
		||||
struct fpa2bv_rewriter_prec : public rewriter_tpl<fpa2bv_rewriter_prec_cfg> {
 | 
			
		||||
    fpa2bv_rewriter_prec_cfg m_cfg;
 | 
			
		||||
    fpa2bv_rewriter_prec(ast_manager & m, fpa2bv_converter_prec & c, params_ref const & p):
 | 
			
		||||
        rewriter_tpl<fpa2bv_rewriter_prec_cfg>(m, m.proofs_enabled(), m_cfg),
 | 
			
		||||
        m_cfg(m, c, p) {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ struct has_fp_to_real_predicate {
 | 
			
		|||
    void operator()(app * n) {
 | 
			
		||||
        sort * s = get_sort(n);
 | 
			
		||||
        if (au.is_real(s) && n->get_family_id() == fu.get_family_id() &&
 | 
			
		||||
            is_app(n) && to_app(n)->get_kind() == OP_FPA_TO_REAL)
 | 
			
		||||
            is_app(n) && to_app(n)->get_decl_kind() == OP_FPA_TO_REAL)
 | 
			
		||||
            throw found();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,7 @@ struct has_fp_to_real_predicate {
 | 
			
		|||
class has_fp_to_real_probe : public probe {
 | 
			
		||||
public:
 | 
			
		||||
    virtual result operator()(goal const & g) {
 | 
			
		||||
        return !test<has_fp_to_real_predicate>(g);
 | 
			
		||||
        return test<has_fp_to_real_predicate>(g);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual ~has_fp_to_real_probe() {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ struct quasi_pb_probe : public probe {
 | 
			
		|||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
probe * mk_quasi_pb_probe() {
 | 
			
		||||
probe * mk_is_quasi_pb_probe() {
 | 
			
		||||
    return mk_and(mk_not(mk_is_unbounded_probe()),
 | 
			
		||||
                  alloc(quasi_pb_probe));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -100,9 +100,11 @@ static tactic * mk_bv2sat_tactic(ast_manager & m) {
 | 
			
		|||
#define SMALL_SIZE 80000
 | 
			
		||||
 | 
			
		||||
static tactic * mk_pb_tactic(ast_manager & m) {
 | 
			
		||||
    params_ref pb2bv_p;
 | 
			
		||||
    pb2bv_p.set_bool("ite_extra", true);    
 | 
			
		||||
    params_ref pb2bv_p;    
 | 
			
		||||
    pb2bv_p.set_uint("pb2bv_all_clauses_limit", 8);
 | 
			
		||||
 | 
			
		||||
    params_ref bv2sat_p;
 | 
			
		||||
    bv2sat_p.set_bool("ite_extra", true);
 | 
			
		||||
    
 | 
			
		||||
    return and_then(fail_if_not(mk_is_pb_probe()),
 | 
			
		||||
                    fail_if(mk_produce_proofs_probe()),
 | 
			
		||||
| 
						 | 
				
			
			@ -113,14 +115,16 @@ static tactic * mk_pb_tactic(ast_manager & m) {
 | 
			
		|||
                                     mk_fail_if_undecided_tactic()),
 | 
			
		||||
                            and_then(using_params(mk_pb2bv_tactic(m), pb2bv_p),
 | 
			
		||||
                                     fail_if_not(mk_is_qfbv_probe()),
 | 
			
		||||
                                     mk_bv2sat_tactic(m))));
 | 
			
		||||
                                     using_params(mk_bv2sat_tactic(m), bv2sat_p))));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static tactic * mk_lia2sat_tactic(ast_manager & m) {
 | 
			
		||||
    params_ref pb2bv_p;
 | 
			
		||||
    pb2bv_p.set_bool("ite_extra", true);    
 | 
			
		||||
    pb2bv_p.set_uint("pb2bv_all_clauses_limit", 8);
 | 
			
		||||
 | 
			
		||||
    params_ref bv2sat_p;
 | 
			
		||||
    bv2sat_p.set_bool("ite_extra", true);
 | 
			
		||||
    
 | 
			
		||||
    return and_then(fail_if(mk_is_unbounded_probe()),
 | 
			
		||||
                    fail_if(mk_produce_proofs_probe()),
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +134,7 @@ static tactic * mk_lia2sat_tactic(ast_manager & m) {
 | 
			
		|||
                    mk_lia2pb_tactic(m),
 | 
			
		||||
                    using_params(mk_pb2bv_tactic(m), pb2bv_p),
 | 
			
		||||
                    fail_if_not(mk_is_qfbv_probe()),                    
 | 
			
		||||
                    mk_bv2sat_tactic(m));
 | 
			
		||||
                    using_params(mk_bv2sat_tactic(m), bv2sat_p));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Try to find a model for an unbounded ILP problem.
 | 
			
		||||
| 
						 | 
				
			
			@ -208,7 +212,7 @@ tactic * mk_qflia_tactic(ast_manager & m, params_ref const & p) {
 | 
			
		|||
    tactic * st = using_params(and_then(preamble_st,
 | 
			
		||||
                                        or_else(mk_ilp_model_finder_tactic(m),
 | 
			
		||||
                                                mk_pb_tactic(m),
 | 
			
		||||
                                                and_then(fail_if_not(mk_quasi_pb_probe()), 
 | 
			
		||||
                                                and_then(fail_if_not(mk_is_quasi_pb_probe()), 
 | 
			
		||||
                                                         using_params(mk_lia2sat_tactic(m), quasi_pb_p),
 | 
			
		||||
                                                         mk_fail_if_undecided_tactic()),
 | 
			
		||||
                                                mk_bounded_tactic(m),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,4 +28,11 @@ tactic * mk_qflia_tactic(ast_manager & m, params_ref const & p = params_ref());
 | 
			
		|||
  ADD_TACTIC("qflia", "builtin strategy for solving QF_LIA problems.", "mk_qflia_tactic(m, p)")
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
probe * mk_is_quasi_pb_probe();
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  ADD_PROBE("is-quasi-pb", "true if the goal is quasi-pb.", "mk_is_quasi_pb_probe()")
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue