示例#1
0
 // Strict case
 // p1^{2*k1} * p2^{2*k2 + 1} >< 0
 // -->
 // p1 != 0 and p2 >< 0
 //
 // Nonstrict
 // p1^{2*k1} * p2^{2*k2 + 1} >=< 0
 // -->
 // p1 = 0 or p2 >=< 0
 //
 void mk_split_comp(decl_kind k, polynomial::factors const & fs, expr_ref & result) {
     SASSERT(k == OP_LT || k == OP_GT || k == OP_LE || k == OP_GE);
     bool strict = (k == OP_LT) || (k == OP_GT);
     expr_ref_buffer args(m);
     expr_ref_buffer odd_factors(m);
     split_even_odd(strict, fs, args, odd_factors);
     if (odd_factors.empty()) {
         if (k == OP_LT) {
             result = m.mk_false();
             return;
         }
         if (k == OP_GE) {
             result = m.mk_true();
             return;
         }
     }
     else {
         args.push_back(m.mk_app(m_util.get_family_id(), k, mk_mul(odd_factors.size(), odd_factors.c_ptr()), mk_zero_for(odd_factors[0])));
     }
     SASSERT(!args.empty());
     if (args.size() == 1)
         result = args[0];
     else if (strict)
         result = m.mk_and(args.size(), args.c_ptr());
     else
         result = m.mk_or(args.size(), args.c_ptr());
 }
示例#2
0
 // p1^k1 * p2^k2 = 0 --> p1*p2 = 0
 void mk_eq(polynomial::factors const & fs, expr_ref & result) {
     expr_ref_buffer args(m);
     expr_ref arg(m);
     for (unsigned i = 0; i < fs.distinct_factors(); i++) {
         m_expr2poly.to_expr(fs[i], true, arg);
         args.push_back(arg);
     }
     result = m.mk_eq(mk_mul(args.size(), args.c_ptr()), mk_zero_for(arg));
 }
示例#3
0
 // p1^{2*k1} * p2^{2*k2 + 1} >=< 0
 // -->
 // (p1^2)*p2 >=<0
 void mk_comp(decl_kind k, polynomial::factors const & fs, expr_ref & result) {
     SASSERT(k == OP_LT || k == OP_GT || k == OP_LE || k == OP_GE);
     expr_ref_buffer args(m);
     expr_ref arg(m);
     for (unsigned i = 0; i < fs.distinct_factors(); i++) {
         m_expr2poly.to_expr(fs[i], true, arg);
         if (fs.get_degree(i) % 2 == 0)
             arg = m_util.mk_power(arg, m_util.mk_numeral(rational(2), m_util.is_int(arg)));
         args.push_back(arg);
     }
     expr * lhs = mk_mul(args.size(), args.c_ptr());
     result = m.mk_app(m_util.get_family_id(), k, lhs, mk_zero_for(lhs));
 }
示例#4
0
void arith_simplifier_plugin::div_monomial(expr_ref_vector& monomials, numeral const& g) {
    numeral n;
    for (unsigned  i = 0; i < monomials.size(); ++i) {
        expr* e = monomials[i].get();
        if (is_numeral(e, n)) {
            SASSERT((n/g).is_int());
            monomials[i] = mk_numeral(n/g);
        }
        else if (is_mul(e) && is_numeral(to_app(e)->get_arg(0), n)) {
            SASSERT((n/g).is_int());
            monomials[i] = mk_mul(n/g, to_app(e)->get_arg(1));
        }
        else {
            UNREACHABLE();
        }
    }
}
expr * poly_simplifier_plugin::mk_mul(numeral const & c, expr * body) {
    numeral c_prime, d;
    c_prime = norm(c);
    if (c_prime.is_zero())
        return 0;
    if (body == 0)
        return mk_numeral(c_prime);
    if (c_prime.is_one())
         return body;
    if (is_numeral(body, d)) {
        c_prime = norm(c_prime*d);
        if (c_prime.is_zero())
            return 0;
        return mk_numeral(c_prime);
    }
    set_curr_sort(body);
    expr * args[2] = { mk_numeral(c_prime), body };
    return mk_mul(2, args);
}
示例#6
0
br_status float_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) {
    br_status st = BR_FAILED;
    SASSERT(f->get_family_id() == get_fid());
    switch (f->get_decl_kind()) {
    case OP_TO_FLOAT:        st = mk_to_fp(f, num_args, args, result); break;
    case OP_FLOAT_ADD:       SASSERT(num_args == 3); st = mk_add(args[0], args[1], args[2], result); break;
    case OP_FLOAT_SUB:       SASSERT(num_args == 3); st = mk_sub(args[0], args[1], args[2], result); break;
    case OP_FLOAT_NEG:       SASSERT(num_args == 1); st = mk_neg(args[0], result); break;
    case OP_FLOAT_MUL:       SASSERT(num_args == 3); st = mk_mul(args[0], args[1], args[2], result); break;
    case OP_FLOAT_DIV:       SASSERT(num_args == 3); st = mk_div(args[0], args[1], args[2], result); break;
    case OP_FLOAT_REM:       SASSERT(num_args == 2); st = mk_rem(args[0], args[1], result); break;
    case OP_FLOAT_ABS:       SASSERT(num_args == 1); st = mk_abs(args[0], result); break;
    case OP_FLOAT_MIN:       SASSERT(num_args == 2); st = mk_min(args[0], args[1], result); break;
    case OP_FLOAT_MAX:       SASSERT(num_args == 2); st = mk_max(args[0], args[1], result); break;
    case OP_FLOAT_FMA:       SASSERT(num_args == 4); st = mk_fma(args[0], args[1], args[2], args[3], result); break;
    case OP_FLOAT_SQRT:      SASSERT(num_args == 2); st = mk_sqrt(args[0], args[1], result); break;
    case OP_FLOAT_ROUND_TO_INTEGRAL: SASSERT(num_args == 2); st = mk_round(args[0], args[1], result); break;

    case OP_FLOAT_EQ:        SASSERT(num_args == 2); st = mk_float_eq(args[0], args[1], result); break; 
    case OP_FLOAT_LT:        SASSERT(num_args == 2); st = mk_lt(args[0], args[1], result); break;
    case OP_FLOAT_GT:        SASSERT(num_args == 2); st = mk_gt(args[0], args[1], result); break;
    case OP_FLOAT_LE:        SASSERT(num_args == 2); st = mk_le(args[0], args[1], result); break;
    case OP_FLOAT_GE:        SASSERT(num_args == 2); st = mk_ge(args[0], args[1], result); break;
    case OP_FLOAT_IS_ZERO:   SASSERT(num_args == 1); st = mk_is_zero(args[0], result); break;
    case OP_FLOAT_IS_NZERO:  SASSERT(num_args == 1); st = mk_is_nzero(args[0], result); break;
    case OP_FLOAT_IS_PZERO:  SASSERT(num_args == 1); st = mk_is_pzero(args[0], result); break;
    case OP_FLOAT_IS_NAN:    SASSERT(num_args == 1); st = mk_is_nan(args[0], result); break;
    case OP_FLOAT_IS_INF:    SASSERT(num_args == 1); st = mk_is_inf(args[0], result); break;
    case OP_FLOAT_IS_NORMAL: SASSERT(num_args == 1); st = mk_is_normal(args[0], result); break;
    case OP_FLOAT_IS_SUBNORMAL: SASSERT(num_args == 1); st = mk_is_subnormal(args[0], result); break;
    case OP_FLOAT_IS_NEGATIVE: SASSERT(num_args == 1); st = mk_is_negative(args[0], result); break;
    case OP_FLOAT_IS_POSITIVE: SASSERT(num_args == 1); st = mk_is_positive(args[0], result); break;
    case OP_FLOAT_TO_IEEE_BV: SASSERT(num_args == 1); st = mk_to_ieee_bv(args[0], result); break;
    case OP_FLOAT_FP:        SASSERT(num_args == 3); st = mk_fp(args[0], args[1], args[2], result); break;
    case OP_FLOAT_TO_UBV:    SASSERT(num_args == 2); st = mk_to_ubv(args[0], args[1], result); break;
    case OP_FLOAT_TO_SBV:    SASSERT(num_args == 2); st = mk_to_sbv(args[0], args[1], result); break;
    case OP_FLOAT_TO_REAL:   SASSERT(num_args == 1); st = mk_to_real(args[0], result); break;
    }
    return st;
}
示例#7
0
br_status fpa_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) {
    br_status st = BR_FAILED;
    SASSERT(f->get_family_id() == get_fid());
    fpa_op_kind k = (fpa_op_kind)f->get_decl_kind();
    switch (k) {
    case OP_FPA_RM_NEAREST_TIES_TO_EVEN:
    case OP_FPA_RM_NEAREST_TIES_TO_AWAY:
    case OP_FPA_RM_TOWARD_POSITIVE:
    case OP_FPA_RM_TOWARD_NEGATIVE:
    case OP_FPA_RM_TOWARD_ZERO:
        SASSERT(num_args == 0); result = m().mk_app(f, (expr * const *)0); st = BR_DONE; break;

    case OP_FPA_PLUS_INF:
    case OP_FPA_MINUS_INF:
    case OP_FPA_NAN:
    case OP_FPA_PLUS_ZERO:
    case OP_FPA_MINUS_ZERO:
        SASSERT(num_args == 0); result = m().mk_app(f, (expr * const *)0); st = BR_DONE; break;

    case OP_FPA_NUM:
        SASSERT(num_args == 0); result = m().mk_app(f, (expr * const *)0); st = BR_DONE; break;

    case OP_FPA_ADD:       SASSERT(num_args == 3); st = mk_add(args[0], args[1], args[2], result); break;
    case OP_FPA_SUB:       SASSERT(num_args == 3); st = mk_sub(args[0], args[1], args[2], result); break;
    case OP_FPA_NEG:       SASSERT(num_args == 1); st = mk_neg(args[0], result); break;
    case OP_FPA_MUL:       SASSERT(num_args == 3); st = mk_mul(args[0], args[1], args[2], result); break;
    case OP_FPA_DIV:       SASSERT(num_args == 3); st = mk_div(args[0], args[1], args[2], result); break;
    case OP_FPA_REM:       SASSERT(num_args == 2); st = mk_rem(args[0], args[1], result); break;
    case OP_FPA_ABS:       SASSERT(num_args == 1); st = mk_abs(args[0], result); break;
    case OP_FPA_MIN:       SASSERT(num_args == 2); st = mk_min(args[0], args[1], result); break;
    case OP_FPA_MAX:       SASSERT(num_args == 2); st = mk_max(args[0], args[1], result); break;
    case OP_FPA_FMA:       SASSERT(num_args == 4); st = mk_fma(args[0], args[1], args[2], args[3], result); break;
    case OP_FPA_SQRT:      SASSERT(num_args == 2); st = mk_sqrt(args[0], args[1], result); break;
    case OP_FPA_ROUND_TO_INTEGRAL: SASSERT(num_args == 2); st = mk_round_to_integral(args[0], args[1], result); break;

    case OP_FPA_EQ:        SASSERT(num_args == 2); st = mk_float_eq(args[0], args[1], result); break;
    case OP_FPA_LT:        SASSERT(num_args == 2); st = mk_lt(args[0], args[1], result); break;
    case OP_FPA_GT:        SASSERT(num_args == 2); st = mk_gt(args[0], args[1], result); break;
    case OP_FPA_LE:        SASSERT(num_args == 2); st = mk_le(args[0], args[1], result); break;
    case OP_FPA_GE:        SASSERT(num_args == 2); st = mk_ge(args[0], args[1], result); break;
    case OP_FPA_IS_ZERO:   SASSERT(num_args == 1); st = mk_is_zero(args[0], result); break;
    case OP_FPA_IS_NAN:    SASSERT(num_args == 1); st = mk_is_nan(args[0], result); break;
    case OP_FPA_IS_INF:    SASSERT(num_args == 1); st = mk_is_inf(args[0], result); break;
    case OP_FPA_IS_NORMAL: SASSERT(num_args == 1); st = mk_is_normal(args[0], result); break;
    case OP_FPA_IS_SUBNORMAL: SASSERT(num_args == 1); st = mk_is_subnormal(args[0], result); break;
    case OP_FPA_IS_NEGATIVE: SASSERT(num_args == 1); st = mk_is_negative(args[0], result); break;
    case OP_FPA_IS_POSITIVE: SASSERT(num_args == 1); st = mk_is_positive(args[0], result); break;

    case OP_FPA_FP:        SASSERT(num_args == 3); st = mk_fp(args[0], args[1], args[2], result); break;
    case OP_FPA_TO_FP:     st = mk_to_fp(f, num_args, args, result); break;
    case OP_FPA_TO_FP_UNSIGNED: SASSERT(num_args == 2); st = mk_to_fp_unsigned(f, args[0], args[1], result); break;
    case OP_FPA_TO_UBV:    SASSERT(num_args == 2); st = mk_to_ubv(f, args[0], args[1], result); break;
    case OP_FPA_TO_SBV:    SASSERT(num_args == 2); st = mk_to_sbv(f, args[0], args[1], result); break;
    case OP_FPA_TO_IEEE_BV: SASSERT(num_args == 1); st = mk_to_ieee_bv(f, args[0], result); break;
    case OP_FPA_TO_REAL:   SASSERT(num_args == 1); st = mk_to_real(args[0], result); break;

    case OP_FPA_INTERNAL_MIN_I:
    case OP_FPA_INTERNAL_MAX_I:
    case OP_FPA_INTERNAL_MIN_UNSPECIFIED:
    case OP_FPA_INTERNAL_MAX_UNSPECIFIED:
        SASSERT(num_args == 2); st = BR_FAILED; break;

    case OP_FPA_INTERNAL_RM:
        SASSERT(num_args == 1); st = mk_rm(args[0], result); break;
    case OP_FPA_INTERNAL_TO_UBV_UNSPECIFIED:
        SASSERT(num_args == 0); st = mk_to_ubv_unspecified(f, result); break;
    case OP_FPA_INTERNAL_TO_SBV_UNSPECIFIED:
        SASSERT(num_args == 0); st = mk_to_sbv_unspecified(f, result); break;
    case OP_FPA_INTERNAL_TO_REAL_UNSPECIFIED:
        SASSERT(num_args == 0); st = mk_to_real_unspecified(result); break;

    case OP_FPA_INTERNAL_BVWRAP:
    case OP_FPA_INTERNAL_BVUNWRAP:
        st = BR_FAILED;
        break;

    default:
        NOT_IMPLEMENTED_YET();
    }
    return st;
}