Esempio n. 1
0
int main() {
/* (assert(= x_0 0)) */
/* (assert(= x_18 (sin x_1))) */
/* (assert(= x_21 (cos x_2))) */
/* (assert(= x_22 (+ x_21 x_18))) */
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_set_verbosity(ctx, 10);

    opensmt_expr x_0  = opensmt_mk_unbounded_real_var(ctx, "x_0");
    opensmt_expr x_1  = opensmt_mk_unbounded_real_var(ctx, "x_1");
    opensmt_expr x_18 = opensmt_mk_unbounded_real_var(ctx, "x_18");
    opensmt_expr x_21 = opensmt_mk_unbounded_real_var(ctx, "x_21");
    opensmt_expr x_22 = opensmt_mk_unbounded_real_var(ctx, "x_22");
    opensmt_expr zero = opensmt_mk_num(ctx, 0.0);
    opensmt_expr assert_1 = opensmt_mk_eq(ctx,  x_0, zero);
    opensmt_expr assert_2 = opensmt_mk_eq(ctx, x_18, opensmt_mk_sin(ctx, x_1));
    opensmt_expr assert_3 = opensmt_mk_eq(ctx, x_21, opensmt_mk_cos(ctx, x_1));
    opensmt_expr assert_4 = opensmt_mk_eq(ctx, x_22, opensmt_mk_plus_2(ctx, x_21, x_18));
    opensmt_assert(ctx, assert_1);
    opensmt_assert(ctx, assert_2);
    opensmt_assert(ctx, assert_3);
    opensmt_assert(ctx, assert_4);
    opensmt_result res = opensmt_check( ctx );
    printf( "%s\n\n", res == l_false ? "unsat" : "sat" );
    opensmt_del_context(ctx);
    return 0;
}
Esempio n. 2
0
int main(int argc, char * argv[]) {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_set_precision (ctx, 0.001);
    opensmt_expr x = opensmt_mk_real_var(ctx, "x" , -3.141592, 3.141592);
    opensmt_expr y = opensmt_mk_real_var(ctx, "y" , -3.141592, 3.141592);
    opensmt_expr eq1 = opensmt_mk_eq(ctx, opensmt_mk_sin(ctx, x), opensmt_mk_cos(ctx, y));
    opensmt_assert(ctx, eq1);
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        double const x_lb = opensmt_get_lb(ctx, x);
        double const x_ub = opensmt_get_ub(ctx, x);
        fprintf(stderr, "x = [%f, %f]\n", x_lb, x_ub);
        double const y_lb = opensmt_get_lb(ctx, y);
        double const y_ub = opensmt_get_ub(ctx, y);
        fprintf(stderr, "y = [%f, %f]\n", y_lb, y_ub);
    }

    opensmt_expr eq2 = opensmt_mk_eq(ctx, opensmt_mk_tan(ctx, x), opensmt_mk_sin(ctx, y));
    opensmt_assert(ctx, eq2);
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        double const x_lb = opensmt_get_lb(ctx, x);
        double const x_ub = opensmt_get_ub(ctx, x);
        fprintf(stderr, "x = [%f, %f]\n", x_lb, x_ub);
        double const y_lb = opensmt_get_lb(ctx, y);
        double const y_ub = opensmt_get_ub(ctx, y);
        fprintf(stderr, "y = [%f, %f]\n", y_lb, y_ub);
    }
    opensmt_del_context(ctx);
    return 0;
}
Esempio n. 3
0
// Test Memory Leaks
int main(int argc, char * argv[]) {
    int i = 0;
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_set_precision (ctx, 0.0000001);
    opensmt_expr x = opensmt_mk_real_var(ctx, "a" , 0.0, 1.0);
    opensmt_expr point1 = opensmt_mk_num(ctx, 0.1);
    opensmt_expr point9 = opensmt_mk_num(ctx, 0.9);
    opensmt_expr leq = opensmt_mk_leq(ctx, x, point1);
    opensmt_expr geq = opensmt_mk_leq(ctx, x, point9);
    opensmt_expr list[2] = {geq, leq};
    opensmt_expr orr = opensmt_mk_or(ctx, list, 2);
    opensmt_push(ctx);
    opensmt_assert(ctx, orr);
    opensmt_result res = opensmt_check( ctx );
    /* printf( "%s\n\n", res == l_false ? "unsat" : "sat" ); */
    /* fprintf(stderr, "=============\nbefore pop 2\n============\n"); */
    opensmt_pop(ctx);
    /* fprintf(stderr, "=============\nafter  pop 2\n============\n"); */
    opensmt_expr andd = opensmt_mk_and(ctx, list, 2);
    opensmt_assert(ctx, andd);
    opensmt_result res2 = opensmt_check( ctx );
    /* fprintf( stderr, "6\n"); */
    /* printf( "%s\n\n", res2 == l_false ? "unsat" : "sat" ); */
    /* fprintf( stderr, "7\n"); */
    opensmt_del_context(ctx);
    return 0;
}
Esempio n. 4
0
int main() {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra_ode);
    opensmt_set_verbosity(ctx, 10);
    opensmt_expr a = opensmt_mk_bool_var(ctx, "a");
    opensmt_expr not_a = opensmt_mk_not(ctx, a);
    opensmt_assert(ctx, a);
    opensmt_assert(ctx, not_a);
    assert(opensmt_check(ctx) == l_false);
    opensmt_reset(ctx);
    opensmt_assert(ctx, a);
    assert(opensmt_check(ctx) == l_true);
    return 0;
}
Esempio n. 5
0
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);

    // numbers -- 2, 7, 10
    opensmt_expr num2  = opensmt_mk_num_from_string(ctx, "2");
    opensmt_expr num7  = opensmt_mk_num_from_string(ctx, "7");
    opensmt_expr num10 = opensmt_mk_num_from_string(ctx, "10");

    // t1 = x > 2
    opensmt_expr t1 = opensmt_mk_gt(ctx, x, num2);
    
    // t2 = y < 10
    opensmt_expr t2 = opensmt_mk_lt(ctx, y, num10);


    // t3 = 2 * y
    opensmt_expr subarray1[2] = {num2, y};
    opensmt_expr t3 = opensmt_mk_times(ctx, subarray1, 2);

    // t4 = x + t3 == 7
    opensmt_expr subarray2[2] = {x, t3};
    opensmt_expr t4 = opensmt_mk_eq(ctx, opensmt_mk_plus(ctx, subarray2, 2), num7);

    // t5 = t1 /\ t2 /\ t4
    opensmt_expr subarray3[3] = {t1, t2, t4};
    opensmt_expr t5 = opensmt_mk_and(ctx, subarray3, 3);

    opensmt_assert(ctx, t5);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
Esempio n. 6
0
int main() {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_set_precision (ctx, 0.001);

    // Creating Exist Real variables
    opensmt_expr x = opensmt_mk_real_var(ctx, "x" , 0, 8);
    // Creating Forall Real variables
    opensmt_expr y = opensmt_mk_forall_real_var(ctx, "y" , 0, 8.0);

    // constants
    opensmt_expr two = opensmt_mk_num(ctx, 2.0);
    opensmt_expr five = opensmt_mk_num(ctx, 5.0);
    opensmt_expr nine = opensmt_mk_num(ctx, 9.0);

    // circle1 := (x-2)^2 + (y-2)^2 <= 9
    opensmt_expr circle1 =
        opensmt_mk_leq(ctx,
                       opensmt_mk_plus_2(ctx,
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, x, two), two),
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, y, two), two)),
                       nine);
    // circle2 := (x-5)^2 + (y-5)^2 <= 9
    opensmt_expr circle2 =
        opensmt_mk_leq(ctx,
                       opensmt_mk_plus_2(ctx,
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, x, five), two),
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, y, five), two)),
                       nine);

    opensmt_expr vars[] = {y};
    opensmt_expr formula = opensmt_mk_forall(ctx, vars, 1,
                                             opensmt_mk_or_2(ctx, circle1, circle2));

    opensmt_assert(ctx, formula);
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, "x", x);
    }

    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
Esempio n. 7
0
// Test Memory Leaks
int main() {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_expr x = opensmt_mk_unbounded_real_var(ctx, "x");
    opensmt_expr zero = opensmt_mk_num(ctx, 0.0);
    opensmt_expr leq = opensmt_mk_leq(ctx, zero, x);
    opensmt_assert(ctx, leq);
    opensmt_result res = opensmt_check( ctx );
    if (res == l_true) {
        double const x_lb = opensmt_get_lb(ctx, x);
        double const x_ub = opensmt_get_ub(ctx, x);
        printf("sat: x = [%f, %f]\n", x_lb, x_ub);
    } else {
        printf("unsat\n");
    }
    opensmt_del_context(ctx);
    return 0;
}
Esempio n. 8
0
int main(int argc, char * argv[]) {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_expr x = opensmt_mk_real_var(ctx, "x" , 0.0, 1.0);
    opensmt_expr y = opensmt_mk_real_var(ctx, "y" , 0.0, 1.0);
    opensmt_expr ite = opensmt_mk_ite(ctx, opensmt_mk_gt(ctx, x, opensmt_mk_num(ctx, 0.4)),
                                      opensmt_mk_num(ctx, 0.3),
                                      opensmt_mk_num(ctx, 0.4));
    opensmt_expr eq = opensmt_mk_eq(ctx, y, ite);
    opensmt_assert( ctx, eq);
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y);
    }
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);
    return 0;
}
Esempio n. 9
0
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating boolean variables
    fprintf(stderr, "Creating some boolean variables\n");
    opensmt_expr a = opensmt_mk_bool_var(ctx, "a");
    opensmt_expr b = opensmt_mk_bool_var(ctx, "b");
    opensmt_expr c = opensmt_mk_bool_var(ctx, "c");
    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);
    opensmt_expr z = opensmt_mk_int_var(ctx, "z" , -10, 10);
    // Creating inequality
    fprintf(stderr, "Creating x - y <= 0\n");

    fprintf(stderr, "  Creating x - y\n");
    opensmt_expr minus = opensmt_mk_minus(ctx, x, y);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(minus);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating 0\n");
    opensmt_expr zero = opensmt_mk_num_from_string(ctx, "0");
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(zero);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating x - y <= 0\n");
    opensmt_expr leq = opensmt_mk_leq(ctx, minus, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");

    // Creating inequality 2
    fprintf(stderr, "Creating y - z <= 0\n");
    opensmt_expr minus2 = opensmt_mk_minus(ctx, y, z);
    opensmt_expr leq2 = opensmt_mk_leq(ctx, minus2, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");

    // Creating inequality 3
    fprintf(stderr, "Creating z - x <= -1\n");
    opensmt_expr minus3 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr mone = opensmt_mk_num_from_string(ctx, "-1");
    opensmt_expr leq3 = opensmt_mk_leq(ctx, minus3, mone);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");

    // Creating inequality 4
    fprintf(stderr, "Creating z - x <= 0\n");
    opensmt_expr minus4 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr leq4 = opensmt_mk_leq(ctx, minus4, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");

    // Asserting first inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting second inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq2);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting third inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq3);
    opensmt_push(ctx);

    // Checking for consistency - it is UNSAT
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Backtracking one step - so the state is SAT again
    opensmt_pop(ctx);
    fprintf(stderr, "Backtracking one step\n\n");

    // Asserting fourth inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq4);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
Esempio n. 10
0
// Related PR : https://github.com/dreal/DReal.jl/pull/23
int main(int argc, char * argv[]) {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    opensmt_expr a = opensmt_mk_bool_var( ctx, "a" );
    opensmt_expr b = opensmt_mk_bool_var( ctx, "b" );
    opensmt_expr c = opensmt_mk_bool_var( ctx, "c" );

     /*  # Creating integer variables */
    opensmt_expr x = opensmt_mk_int_var( ctx, "x" , -100, 100);
    opensmt_expr y = opensmt_mk_int_var( ctx, "y" , -100, 100);
    opensmt_expr z = opensmt_mk_int_var( ctx, "z" , -100, 100);
    /*  # Creating inequality */
    opensmt_expr minus = opensmt_mk_minus( ctx, x, y );
    opensmt_expr zero = opensmt_mk_num_from_string( ctx, "0" );
    opensmt_expr leq = opensmt_mk_leq( ctx, minus, zero );

    /*  # Creating inequality 2 */
    opensmt_expr minus2 = opensmt_mk_minus( ctx, y, z );
    opensmt_expr leq2 = opensmt_mk_leq( ctx, minus2, zero );

    /*  # Creating inequality 3 */
    opensmt_expr minus3 = opensmt_mk_minus( ctx, z, x );
    opensmt_expr mone = opensmt_mk_num_from_string( ctx, "-1" );
    opensmt_expr leq3 = opensmt_mk_leq( ctx, minus3, mone );

    /*  # Creating inequality 4 */
    opensmt_expr minus4 = opensmt_mk_minus( ctx, z, x );
    opensmt_expr leq4 = opensmt_mk_leq( ctx, minus4, zero );

    /*  # Asserting first inequality */
    opensmt_assert( ctx, leq );                 /* ASSERT (e1) */
    opensmt_push( ctx );                        /* PUSH */

    /* # Checking for consistency */
    opensmt_result res = opensmt_check( ctx );  /* CHECK */
    assert(res == l_true);

    // # Asserting second inequality
    opensmt_assert( ctx, leq2 );               /* ASSERT (e2) */
    opensmt_push( ctx );                       /* PUSH */

    // # Checking for consistency
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_true);

    // # Asserting third inequality
    opensmt_assert( ctx, leq3 );               /* ASSERT (e3)*/
    opensmt_push( ctx );                       /* PUSH */

    // # Checking for consistency - it is UNSAT
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);

    /*  # Backtracking one step - so the state is SAT again */
    opensmt_pop( ctx );                        /* POP */

    /* # Asserting fourth inequality */
    opensmt_assert( ctx, leq4 );               /* ASSERT (e4) */

    /*  # Checking for consistency */
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);
    res = opensmt_check( ctx );                /* CHECK */
    assert(res == l_false);

    opensmt_del_context(ctx);
    return 0;
}