コード例 #1
0
ファイル: z3test.c プロジェクト: AmesianX/symx
int main(){
	Z3_context context;
	Z3_solver solver;
	Z3_sort bvsort1;
	Z3_sort bvsort4;
	Z3_sort memsort;
	Z3_ast x_ast,y_ast,z_ast,u_ast,v_ast,w_ast,test_ast;
	Z3_model model;

	Z3_config config = Z3_mk_config();
	Z3_set_param_value(config,"model","true");
	context = Z3_mk_context_rc(config);
	Z3_set_error_handler(context,error_handler);

	solver = Z3_mk_solver(context);
	Z3_solver_inc_ref(context,solver);

	bvsort1 = Z3_mk_bv_sort(context,8);
	bvsort4 = Z3_mk_bv_sort(context,32);

	memsort = Z3_mk_array_sort(context,bvsort4,bvsort1);
	y_ast = Z3_mk_const(context,Z3_mk_string_symbol(context,"mem"),memsort);
	Z3_inc_ref(context,y_ast);

	u_ast = Z3_mk_unsigned_int64(context,13,bvsort4);
	Z3_inc_ref(context,u_ast);
	v_ast = Z3_mk_select(context,y_ast,u_ast);
	Z3_inc_ref(context,v_ast);

	z_ast = Z3_mk_unsigned_int64(context,7,bvsort1);
	Z3_inc_ref(context,z_ast);
	test_ast = Z3_mk_eq(context,v_ast,z_ast);
	Z3_inc_ref(context,test_ast);
	Z3_solver_assert(context,solver,test_ast);

	w_ast = Z3_mk_const(context,Z3_mk_string_symbol(context,"w"),bvsort1);
	y_ast = Z3_mk_store(context,y_ast,u_ast,w_ast);
	Z3_inc_ref(context,y_ast);

	v_ast = Z3_mk_select(context,y_ast,u_ast);
	Z3_inc_ref(context,v_ast);

	z_ast = Z3_mk_unsigned_int64(context,2,bvsort1);
	Z3_inc_ref(context,z_ast);
	test_ast = Z3_mk_eq(context,v_ast,z_ast);
	Z3_inc_ref(context,test_ast);
	Z3_solver_assert(context,solver,test_ast);

	Z3_solver_check(context,solver);
	model = Z3_solver_get_model(context,solver);
	fprintf(stderr,"%s\n",Z3_model_to_string(context,model));

	fprintf(stderr,"%s\n",Z3_simplify_get_help(context));

	return 0;
}
コード例 #2
0
ファイル: api.cpp プロジェクト: CHolmes3/z3
void test_apps() {
    Z3_config cfg = Z3_mk_config();
    Z3_set_param_value(cfg,"MODEL","true");
    Z3_context ctx = Z3_mk_context(cfg);
    Z3_symbol A = Z3_mk_string_symbol(ctx, "A");
    Z3_symbol F = Z3_mk_string_symbol(ctx, "f");
    Z3_sort SA = Z3_mk_uninterpreted_sort(ctx, A);
    Z3_func_decl f = Z3_mk_func_decl(ctx, F, 1, &SA, SA);
    Z3_symbol X = Z3_mk_string_symbol(ctx, "x");
    Z3_ast x = Z3_mk_const(ctx, X, SA);
    Z3_ast fx = Z3_mk_app(ctx, f, 1, &x);
    Z3_ast ffx = Z3_mk_app(ctx, f, 1, &fx);
    Z3_ast fffx = Z3_mk_app(ctx, f, 1, &ffx);
    Z3_ast ffffx = Z3_mk_app(ctx, f, 1, &fffx);
    Z3_ast fffffx = Z3_mk_app(ctx, f, 1, &ffffx);

    Z3_ast fml = Z3_mk_not(ctx, Z3_mk_eq(ctx, x, fffffx));
    
    Z3_assert_cnstr(ctx, fml);
    Z3_lbool r = Z3_check(ctx);
    std::cout << r << "\n";
    Z3_del_config(cfg);
    Z3_del_context(ctx);
}
コード例 #3
0
ファイル: iz3.cpp プロジェクト: therealoneisneo/Z3
int test(){
  int i;

  /* Create a Z3 context to contain formulas */

  Z3_config cfg = Z3_mk_config();
  Z3_context ctx = iz3_mk_context(cfg);
    
  int num = 2;

  Z3_ast *constraints = (Z3_ast *)malloc(num * sizeof(Z3_ast));

#if 1
  Z3_sort arr = Z3_mk_array_sort(ctx,Z3_mk_int_sort(ctx),Z3_mk_bool_sort(ctx)); 
  Z3_symbol  as  = Z3_mk_string_symbol(ctx, "a");
  Z3_symbol  bs  = Z3_mk_string_symbol(ctx, "b");
  Z3_symbol  xs  = Z3_mk_string_symbol(ctx, "x");

  Z3_ast a = Z3_mk_const(ctx,as,arr);
  Z3_ast b = Z3_mk_const(ctx,bs,arr);
  Z3_ast x = Z3_mk_const(ctx,xs,Z3_mk_int_sort(ctx));
  
  Z3_ast c1 = Z3_mk_eq(ctx,a,Z3_mk_store(ctx,b,x,Z3_mk_true(ctx)));
  Z3_ast c2 = Z3_mk_not(ctx,Z3_mk_select(ctx,a,x));
#else
  Z3_symbol  xs  = Z3_mk_string_symbol(ctx, "x");
  Z3_ast x = Z3_mk_const(ctx,xs,Z3_mk_bool_sort(ctx));
  Z3_ast c1 = Z3_mk_eq(ctx,x,Z3_mk_true(ctx));
  Z3_ast c2 = Z3_mk_eq(ctx,x,Z3_mk_false(ctx));

#endif

  constraints[0] = c1;
  constraints[1] = c2;
  
  /* print out the result for grins. */

  // Z3_string smtout = Z3_benchmark_to_smtlib_string (ctx, "foo", "QFLIA", "sat", "", num, constraints, Z3_mk_true(ctx));

  // Z3_string smtout = Z3_ast_to_string(ctx,constraints[0]);
  // Z3_string smtout = Z3_context_to_string(ctx);
  // puts(smtout);

  iz3_print(ctx,num,constraints,"iZ3temp.smt");

  /* Make room for interpolants. */

  Z3_ast *interpolants = (Z3_ast *)malloc((num-1) * sizeof(Z3_ast));

  /* Make room for the model. */

  Z3_model model = 0;

  /* Call the prover */

  Z3_lbool result = iz3_interpolate(ctx, num, constraints, interpolants, &model);

  switch (result) {
  
    /* If UNSAT, print the interpolants */
  case Z3_L_FALSE:
    printf("unsat, interpolants:\n");
    for(i = 0; i < num-1; i++)
      printf("%s\n", Z3_ast_to_string(ctx, interpolants[i]));
    break;
  case Z3_L_UNDEF:
    printf("fail\n");
    break;
  case Z3_L_TRUE:
    printf("sat\n");
    printf("model:\n%s\n", Z3_model_to_string(ctx, model));
    break;
  }

  /* Delete the model if there is one */
  
  if (model)
    Z3_del_model(ctx, model);
  
  /* Delete logical context (note, we call iz3_del_context, not
     Z3_del_context */

  iz3_del_context(ctx);

  return 1;
}
コード例 #4
0
ファイル: maxsat.c プロジェクト: NikolajBjorner/z3
/**
   \brief Create a variable using the given name and type.
*/
Z3_ast mk_var(Z3_context ctx, const char * name, Z3_sort ty) 
{
    Z3_symbol   s  = Z3_mk_string_symbol(ctx, name);
    return Z3_mk_const(ctx, s, ty);
}
コード例 #5
0
ファイル: no_overflow.cpp プロジェクト: CHolmes3/z3
void test_add(unsigned bvsize, bool is_signed) {

    TRACE("no_overflow", tout << "test_add: bvsize = " << bvsize << ", is_signed = " << is_signed << "\n";);

    Z3_config cfg = Z3_mk_config();
    Z3_context ctx = Z3_mk_context(cfg);
    Z3_sort bv = Z3_mk_bv_sort(ctx, bvsize);

    Z3_ast min = mk_min(ctx, bv, is_signed);
    Z3_ast max = mk_max(ctx, bv, is_signed);
    Z3_ast t1;
    Z3_ast t2;
    Z3_ast test_ovfl;
    Z3_ast test_udfl;

    t1 = Z3_mk_const(ctx, Z3_mk_string_symbol(ctx,"x"), bv);
    t2 = Z3_mk_const(ctx, Z3_mk_string_symbol(ctx,"y"), bv);
    test_ovfl = Z3_mk_bvadd_no_overflow(ctx, t1, t2, is_signed);
    test_udfl = is_signed ? Z3_mk_bvadd_no_underflow(ctx, t1, t2) : NULL;

    Z3_push(ctx);
    Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, t1, Z3_mk_numeral(ctx, "0", bv)));
    Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, t2, Z3_mk_numeral(ctx, "1", bv)));
    TEST_NO_OVERFLOW;
    TEST_NO_UNDERFLOW;
    Z3_pop(ctx, 1);

    Z3_push(ctx);
    Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, t1, Z3_mk_numeral(ctx, "0", bv)));
    Z3_assert_cnstr(ctx, Z3_mk_eq(ctx, t2, max));
    TEST_NO_OVERFLOW;
コード例 #6
0
static Z3_ast mk_var(Z3_context ctx, char const* name, Z3_sort s) {
	return Z3_mk_const(ctx, Z3_mk_string_symbol(ctx, name), s);
}