SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | Error with nop theory plugin: | |
3 | $ gcc -o error error.c -lz3 | |
4 | $ ./error | |
5 | Z3 version 4.0.0.0 | |
6 | Context: | |
7 | (solver | |
8 | - | (forall ((i Int)) (>= (cu_a i) 0.0)) |
8 | + | (forall ((i Int)) (= (cu_a i) 0.0))) |
9 | - | (forall ((i Int)) |
9 | + | |
10 | - | (<= (+ (cu_a i) (* (- 1.0) (cu_v i))) 0.0)) |
10 | + | |
11 | - | (= cu_d 4) |
11 | + | |
12 | - | (= (cu_n 0) 0) |
12 | + | |
13 | - | (= (cu_n 1) 0) |
13 | + | |
14 | - | (= (cu_n 2) 0) |
14 | + | |
15 | - | (= (cu_n 3) 0) |
15 | + | |
16 | - | (= (cu_a 0) cu_a_0) |
16 | + | |
17 | - | (= (cu_a 1) cu_a_1) |
17 | + | |
18 | - | (= (cu_a 2) cu_a_2) |
18 | + | |
19 | - | (= (cu_a 3) cu_a_3) |
19 | + | |
20 | - | (= (+ cu_a_0 |
20 | + | (forall ((i Int)) (= (cu_a i) 0.0))) |
21 | - | cu_a_1 |
21 | + | |
22 | - | cu_a_2 |
22 | + | |
23 | - | cu_a_3 |
23 | + | |
24 | - | (* (- 1.0) cu_a_sum)) |
24 | + | |
25 | - | 0.0) |
25 | + | |
26 | - | (= (cu_v 0) 0.0) |
26 | + | |
27 | - | (= (cu_v 1) 1.0) |
27 | + | |
28 | - | (= (cu_v 2) 1.0) |
28 | + | |
29 | - | (= (cu_v 3) 1.0) |
29 | + | |
30 | - | (forall ((i Int)) (or (<= (cu_a i) 0.0) (= (cu_a i) 1.0)))) |
30 | + | |
31 | #include<stdarg.h> | |
32 | #include<memory.h> | |
33 | #include<z3.h> | |
34 | ||
35 | typedef struct _nopTheoryData { | |
36 | int dummy; | |
37 | } nopTheoryData; | |
38 | ||
39 | static void Th_delete(Z3_theory t) | |
40 | { | |
41 | - | (forall ((i Int)) (>= (cu_a i) 0.0)) |
41 | + | |
42 | - | (forall ((i Int)) (<= (+ (cu_a i) (* (- 1.0) (cu_v i))) 0.0)) |
42 | + | |
43 | - | (= cu_d 4) |
43 | + | |
44 | - | (= (cu_n 0) 0) |
44 | + | |
45 | - | (= (cu_n 1) 0) |
45 | + | |
46 | - | (= (cu_n 2) 0) |
46 | + | |
47 | - | (= (cu_n 3) 0) |
47 | + | |
48 | - | (= (cu_a 0) cu_a_0) |
48 | + | |
49 | - | (= (cu_a 1) cu_a_1) |
49 | + | |
50 | - | (= (cu_a 2) cu_a_2) |
50 | + | |
51 | - | (= (cu_a 3) cu_a_3) |
51 | + | |
52 | - | (= (+ cu_a_0 cu_a_1 cu_a_2 cu_a_3 (* (- 1.0) cu_a_sum)) 0.0) |
52 | + | |
53 | - | (= (cu_v 0) 0.0) |
53 | + | |
54 | - | (= (cu_v 1) 1.0) |
54 | + | |
55 | - | (= (cu_v 2) 1.0) |
55 | + | |
56 | - | (= (cu_v 3) 1.0) |
56 | + | |
57 | - | (forall ((i Int)) (or (<= (cu_a i) 0.0) (= (cu_a i) 1.0)))) |
57 | + | |
58 | } | |
59 | - | cu_a_sum -> 1 |
59 | + | |
60 | - | cu_a_0 -> 0 |
60 | + | |
61 | - | cu_a_1 -> 0 |
61 | + | |
62 | - | cu_a_3 -> 0 |
62 | + | |
63 | - | cu_a_2 -> 1 |
63 | + | |
64 | - | cu_d -> 4 |
64 | + | |
65 | static void Th_init_search(Z3_theory t) { | |
66 | - | 2 -> 1 |
66 | + | |
67 | - | else -> 0 |
67 | + | |
68 | static void Th_push(Z3_theory t) { | |
69 | - | cu_n -> { |
69 | + | |
70 | } | |
71 | static void Th_pop(Z3_theory t) { | |
72 | - | cu_v -> { |
72 | + | |
73 | - | 0 -> 0 |
73 | + | |
74 | - | 1 -> 1 |
74 | + | |
75 | - | 2 -> 1 |
75 | + | |
76 | - | 3 -> 1 |
76 | + | |
77 | - | else -> (cu_a #0) |
77 | + | |
78 | return; | |
79 | } | |
80 | static Z3_bool Th_final_check(Z3_theory t) | |
81 | { | |
82 | fprintf(stderr, "Final check\n"); | |
83 | fflush(stderr); | |
84 | return Z3_TRUE; | |
85 | } | |
86 | static void Th_new_eq(Z3_theory t, Z3_ast n1, Z3_ast n2) | |
87 | { | |
88 | return; | |
89 | } | |
90 | static void Th_new_diseq(Z3_theory t, Z3_ast n1, Z3_ast n2) | |
91 | { | |
92 | return; | |
93 | } | |
94 | static void Th_new_relevant(Z3_theory t, Z3_ast n) | |
95 | { | |
96 | return; | |
97 | } | |
98 | static void Th_new_assignment(Z3_theory t, Z3_ast n, Z3_bool v) | |
99 | { | |
100 | return; | |
101 | } | |
102 | static Z3_theory mk_simple_theory(Z3_context ctx) { | |
103 | nopTheoryData *td = (nopTheoryData*)malloc(sizeof(nopTheoryData)); | |
104 | Z3_theory Th = Z3_mk_theory(ctx, "simple_th", td); | |
105 | ||
106 | Z3_set_delete_callback(Th, Th_delete); | |
107 | Z3_set_reduce_app_callback(Th, Th_reduce_app); | |
108 | Z3_set_reduce_eq_callback(Th, Th_reduce_eq); | |
109 | Z3_set_reduce_distinct_callback(Th, Th_reduce_distinct); | |
110 | Z3_set_new_app_callback(Th, Th_new_app); | |
111 | Z3_set_new_elem_callback(Th, Th_new_elem); | |
112 | Z3_set_init_search_callback(Th, Th_init_search); | |
113 | Z3_set_push_callback(Th, Th_push); | |
114 | Z3_set_pop_callback(Th, Th_pop); | |
115 | Z3_set_restart_callback(Th, Th_restart); | |
116 | Z3_set_reset_callback(Th, Th_reset); | |
117 | Z3_set_final_check_callback(Th, Th_final_check); | |
118 | Z3_set_new_eq_callback(Th, Th_new_eq); | |
119 | Z3_set_new_diseq_callback(Th, Th_new_diseq); | |
120 | Z3_set_new_assignment_callback(Th, Th_new_assignment); | |
121 | Z3_set_new_relevant_callback(Th, Th_new_relevant); | |
122 | ||
123 | return Th; | |
124 | } | |
125 | /* end simple theory */ | |
126 | ||
127 | static int z3_error = 0; | |
128 | static void throw_z3_error(Z3_context ctx, Z3_error_code e) | |
129 | { | |
130 | z3_error = e; | |
131 | } | |
132 | ||
133 | static void nop_example() | |
134 | { | |
135 | Z3_ast a; | |
136 | Z3_context ctx; | |
137 | Z3_theory Th; | |
138 | Z3_config conf = Z3_mk_config(); | |
139 | Z3_lbool result; | |
140 | Z3_model m; | |
141 | unsigned major, minor, build, revision; | |
142 | ||
143 | Z3_get_version(&major, &minor, &build, &revision); | |
144 | fprintf(stderr, "Z3 version %d.%d.%d.%d\n", | |
145 | major, minor, build, revision); | |
146 | fflush(stderr); | |
147 | ||
148 | ctx = Z3_mk_context(conf); | |
149 | Z3_del_config(conf); | |
150 | Z3_set_error_handler(ctx, throw_z3_error); | |
151 | ||
152 | #ifndef NO_THEORY | |
153 | Th = mk_simple_theory(ctx); | |
154 | #endif | |
155 | ||
156 | { | |
157 | Z3_sort cu_a_dom = Z3_mk_int_sort(ctx); | |
158 | Z3_symbol cu_a_sym = Z3_mk_string_symbol(ctx, "cu_a"); | |
159 | Z3_func_decl cu_a_decl; | |
160 | ||
161 | cu_a_decl = Z3_mk_func_decl(ctx,cu_a_sym,1,&cu_a_dom,Z3_mk_real_sort(ctx)); | |
162 | ||
163 | a = Z3_parse_smtlib2_string(ctx, | |
164 | "(assert (forall ((i Int)) (= (cu_a i) 0.0)))", | |
165 | 0,0,0, | |
166 | 1,&cu_a_sym,&cu_a_decl); | |
167 | Z3_assert_cnstr(ctx, a); | |
168 | } | |
169 | ||
170 | printf("Context:\n%s\n", Z3_context_to_string(ctx)); | |
171 | result = Z3_check_and_get_model(ctx, &m); | |
172 | if (z3_error != 0) { | |
173 | fprintf(stderr, "Z3 check_and_get_model error: %s\n", | |
174 | Z3_get_error_msg((Z3_error_code)z3_error)); | |
175 | if (z3_error == Z3_EXCEPTION) { | |
176 | fprintf(stderr, "\t%s\n", Z3_get_error_msg_ex(ctx, z3_error)); | |
177 | } | |
178 | fflush(stderr); | |
179 | return; | |
180 | } | |
181 | switch (result) { | |
182 | case Z3_L_FALSE: | |
183 | fprintf(stderr, "unsat\n"); | |
184 | fflush(stderr); | |
185 | break; | |
186 | case Z3_L_UNDEF: | |
187 | fprintf(stderr, "unknown: potential model:\n %s\n", Z3_model_to_string(ctx,m)); | |
188 | fflush(stderr); | |
189 | break; | |
190 | case Z3_L_TRUE: | |
191 | fprintf(stderr, "sat:\n%s\n", Z3_model_to_string(ctx, m)); | |
192 | fflush(stderr); | |
193 | break; | |
194 | } | |
195 | Z3_del_context(ctx); | |
196 | } | |
197 | ||
198 | int main() | |
199 | { | |
200 | nop_example(); | |
201 | return 0; | |
202 | } |