forked from Z3Prover/z3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qflia_tactic.cpp
235 lines (197 loc) · 8.77 KB
/
qflia_tactic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
qflia_tactic.cpp
Abstract:
Tactic for QF_LIA
Author:
Leonardo (leonardo) 2012-02-26
Notes:
--*/
#include "tactic/tactical.h"
#include "tactic/core/simplify_tactic.h"
#include "tactic/core/propagate_values_tactic.h"
#include "tactic/arith/propagate_ineqs_tactic.h"
#include "tactic/arith/normalize_bounds_tactic.h"
#include "tactic/core/solve_eqs_tactic.h"
#include "tactic/core/elim_uncnstr_tactic.h"
#include "smt/tactic/smt_tactic.h"
#include "tactic/arith/add_bounds_tactic.h"
#include "tactic/arith/pb2bv_tactic.h"
#include "tactic/arith/lia2pb_tactic.h"
#include "tactic/core/ctx_simplify_tactic.h"
#include "tactic/bv/bit_blaster_tactic.h"
#include "tactic/bv/max_bv_sharing_tactic.h"
#include "tactic/aig/aig_tactic.h"
#include "sat/tactic/sat_tactic.h"
#include "tactic/arith/bound_manager.h"
#include "tactic/arith/probe_arith.h"
struct quasi_pb_probe : public probe {
result operator()(goal const & g) override {
bool found_non_01 = false;
bound_manager bm(g.m());
bm(g);
rational l, u; bool st;
for (expr * t : bm) {
if (bm.has_lower(t, l, st) && bm.has_upper(t, u, st) && (l.is_zero() || l.is_one()) && (u.is_zero() || u.is_one()))
continue;
if (found_non_01)
return false;
found_non_01 = true;
}
return true;
}
};
probe * mk_is_quasi_pb_probe() {
return mk_and(mk_not(mk_is_unbounded_probe()),
alloc(quasi_pb_probe));
}
// Create SMT solver that does not use cuts
static tactic * mk_no_cut_smt_tactic(unsigned rs) {
params_ref solver_p;
solver_p.set_uint("arith.branch_cut_ratio", 10000000);
solver_p.set_uint("random_seed", rs);
return annotate_tactic("no-cut-smt-tactic", using_params(mk_smt_tactic_using(false), solver_p));
}
// Create SMT solver that does not use cuts
static tactic * mk_no_cut_no_relevancy_smt_tactic(unsigned rs) {
params_ref solver_p;
solver_p.set_uint("arith.branch_cut_ratio", 10000000);
solver_p.set_uint("random_seed", rs);
solver_p.set_uint("relevancy", 0);
return annotate_tactic("no-cut-relevancy-tactic", using_params(mk_smt_tactic_using(false), solver_p));
}
static tactic * mk_bv2sat_tactic(ast_manager & m) {
params_ref solver_p;
// The cardinality constraint encoding generates a lot of shared if-then-else's that can be flattened.
// Several of them are simplified to and/or. If we flat them, we increase a lot the memory consumption.
solver_p.set_bool("flat", false);
solver_p.set_bool("som", false);
// dynamic psm seems to work well.
solver_p.set_sym("gc", symbol("dyn_psm"));
return using_params(and_then(mk_simplify_tactic(m),
mk_propagate_values_tactic(m),
mk_solve_eqs_tactic(m),
mk_max_bv_sharing_tactic(m),
mk_bit_blaster_tactic(m),
mk_aig_tactic(),
mk_sat_tactic(m, solver_p)),
solver_p);
}
#define SMALL_SIZE 80000
static tactic * mk_pb_tactic(ast_manager & m) {
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 annotate_tactic(
"pb-tactic",
and_then(fail_if_not(mk_is_pb_probe()),
fail_if(mk_produce_proofs_probe()),
fail_if(mk_produce_unsat_cores_probe()),
or_else(and_then(fail_if(mk_ge(mk_num_exprs_probe(), mk_const_probe(SMALL_SIZE))),
fail_if_not(mk_is_ilp_probe()),
// try_for(mk_mip_tactic(m), 8000),
mk_fail_if_undecided_tactic()),
and_then(using_params(mk_pb2bv_tactic(m), pb2bv_p),
fail_if_not(mk_is_qfbv_probe()),
using_params(mk_bv2sat_tactic(m), bv2sat_p)))));
}
static tactic * mk_lia2sat_tactic(ast_manager & m) {
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 annotate_tactic(
"lia2sat-tactic",
and_then(fail_if(mk_is_unbounded_probe()),
fail_if(mk_produce_proofs_probe()),
fail_if(mk_produce_unsat_cores_probe()),
mk_propagate_ineqs_tactic(m),
mk_normalize_bounds_tactic(m),
mk_lia2pb_tactic(m),
using_params(mk_pb2bv_tactic(m), pb2bv_p),
fail_if_not(mk_is_qfbv_probe()),
using_params(mk_bv2sat_tactic(m), bv2sat_p)));
}
// Try to find a model for an unbounded ILP problem.
// Fails if the problem is no ILP.
static tactic * mk_ilp_model_finder_tactic(ast_manager & m) {
params_ref add_bounds_p1;
add_bounds_p1.set_rat("add_bound_lower", rational(-16));
add_bounds_p1.set_rat("add_bound_upper", rational(15));
params_ref add_bounds_p2;
add_bounds_p2.set_rat("add_bound_lower", rational(-32));
add_bounds_p2.set_rat("add_bound_upper", rational(31));
return annotate_tactic(
"ilp-model-finder-tactic",
and_then(fail_if_not(mk_and(mk_is_ilp_probe(), mk_is_unbounded_probe())),
fail_if(mk_produce_proofs_probe()),
fail_if(mk_produce_unsat_cores_probe()),
mk_propagate_ineqs_tactic(m),
or_else(// try_for(mk_mip_tactic(m), 5000),
try_for(mk_no_cut_smt_tactic(100), 2000),
and_then(using_params(mk_add_bounds_tactic(m), add_bounds_p1),
try_for(mk_lia2sat_tactic(m), 5000)),
try_for(mk_no_cut_smt_tactic(200), 5000),
and_then(using_params(mk_add_bounds_tactic(m), add_bounds_p2),
try_for(mk_lia2sat_tactic(m), 10000))
// , mk_mip_tactic(m)
),
mk_fail_if_undecided_tactic()));
}
static tactic * mk_bounded_tactic(ast_manager & m) {
return annotate_tactic(
"bounded-tactic",
and_then(fail_if(mk_is_unbounded_probe()),
or_else(try_for(mk_no_cut_smt_tactic(100), 5000),
try_for(mk_no_cut_no_relevancy_smt_tactic(200), 5000),
try_for(mk_no_cut_smt_tactic(300), 15000)
),
mk_fail_if_undecided_tactic()));
}
tactic * mk_qflia_tactic(ast_manager & m, params_ref const & p) {
params_ref main_p;
main_p.set_bool("elim_and", true);
main_p.set_bool("som", true);
main_p.set_bool("blast_distinct", true);
main_p.set_uint("blast_distinct_threshold", 128);
// main_p.set_bool("push_ite_arith", true);
params_ref pull_ite_p;
pull_ite_p.set_bool("pull_cheap_ite", true);
pull_ite_p.set_bool("push_ite_arith", false);
pull_ite_p.set_bool("local_ctx", true);
pull_ite_p.set_uint("local_ctx_limit", 10000000);
params_ref ctx_simp_p;
ctx_simp_p.set_uint("max_depth", 30);
ctx_simp_p.set_uint("max_steps", 5000000);
params_ref lhs_p;
lhs_p.set_bool("arith_lhs", true);
tactic * preamble_st = and_then(and_then(mk_simplify_tactic(m),
mk_propagate_values_tactic(m),
using_params(mk_ctx_simplify_tactic(m), ctx_simp_p),
using_params(mk_simplify_tactic(m), pull_ite_p)),
mk_solve_eqs_tactic(m),
mk_elim_uncnstr_tactic(m),
using_params(mk_simplify_tactic(m), lhs_p)
);
params_ref quasi_pb_p;
quasi_pb_p.set_uint("lia2pb_max_bits", 64);
params_ref no_cut_p;
no_cut_p.set_uint("arith.branch_cut_ratio", 10000000);
tactic * st = using_params(and_then(preamble_st,
#if 0
mk_smt_tactic()),
#else
or_else(mk_ilp_model_finder_tactic(m),
mk_pb_tactic(m),
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),
mk_smt_tactic())),
#endif
main_p);
st->updt_params(p);
return st;
}