mirror of
https://github.com/Z3Prover/z3
synced 2025-08-26 13:06:05 +00:00
fix write_bound_lemma to include term definitions
This commit is contained in:
parent
76b82318b8
commit
939091e2b5
2 changed files with 63 additions and 21 deletions
|
@ -1848,10 +1848,8 @@ namespace lp {
|
||||||
SASSERT((upper && bound < lra.get_upper_bound(j).x) ||
|
SASSERT((upper && bound < lra.get_upper_bound(j).x) ||
|
||||||
(!upper && bound > lra.get_lower_bound(j).x));
|
(!upper && bound > lra.get_lower_bound(j).x));
|
||||||
lconstraint_kind kind = upper ? lconstraint_kind::LE : lconstraint_kind::GE;
|
lconstraint_kind kind = upper ? lconstraint_kind::LE : lconstraint_kind::GE;
|
||||||
u_dependency* dep = lra.get_bound_constraint_witnesses_for_column(j);
|
u_dependency* dep = upper ? lra.get_column_upper_bound_witness(j) : lra.get_column_lower_bound_witness(j);
|
||||||
dep = lra.join_deps(dep, explain_fixed_in_meta_term(m_lspace.m_data));
|
dep = lra.join_deps(dep, explain_fixed_in_meta_term(m_lspace.m_data));
|
||||||
u_dependency* j_bound_dep = upper ? lra.get_column_upper_bound_witness(j) : lra.get_column_lower_bound_witness(j);
|
|
||||||
dep = lra.join_deps(dep, j_bound_dep);
|
|
||||||
dep = lra.join_deps(dep, explain_fixed(lra.get_term(j)));
|
dep = lra.join_deps(dep, explain_fixed(lra.get_term(j)));
|
||||||
TRACE("dio", tout << "jterm:";
|
TRACE("dio", tout << "jterm:";
|
||||||
print_lar_term_L(lra.get_term(j), tout) << "\ndep:";
|
print_lar_term_L(lra.get_term(j), tout) << "\ndep:";
|
||||||
|
|
|
@ -2584,8 +2584,7 @@ namespace lp {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Start SMT2 file
|
||||||
// Start SMT2 file
|
|
||||||
out << "(set-info : \"generated at " << location;
|
out << "(set-info : \"generated at " << location;
|
||||||
out << " for " << (is_low ? "lower" : "upper") << " bound of variable " << j << ",";
|
out << " for " << (is_low ? "lower" : "upper") << " bound of variable " << j << ",";
|
||||||
out << " bound value: " << bound_val << (is_strict ? (is_low ? " < " : " > ") : (is_low ? " <= " : " >= ")) << "x" << j << "\")\n";
|
out << " bound value: " << bound_val << (is_strict ? (is_low ? " < " : " > ") : (is_low ? " <= " : " >= ")) << "x" << j << "\")\n";
|
||||||
|
@ -2594,6 +2593,7 @@ namespace lp {
|
||||||
std::unordered_set<unsigned> vars_used;
|
std::unordered_set<unsigned> vars_used;
|
||||||
vars_used.insert(j);
|
vars_used.insert(j);
|
||||||
bool is_int = column_is_int(j);
|
bool is_int = column_is_int(j);
|
||||||
|
|
||||||
// Linearize the dependencies
|
// Linearize the dependencies
|
||||||
svector<constraint_index> deps;
|
svector<constraint_index> deps;
|
||||||
m_dependencies.linearize(bound_dep, deps);
|
m_dependencies.linearize(bound_dep, deps);
|
||||||
|
@ -2608,6 +2608,21 @@ namespace lp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect variables from terms
|
||||||
|
std::unordered_set<unsigned> term_variables;
|
||||||
|
for (unsigned var : vars_used) {
|
||||||
|
if (column_has_term(var)) {
|
||||||
|
const lar_term& term = get_term(var);
|
||||||
|
for (const auto& p : term) {
|
||||||
|
term_variables.insert(p.j());
|
||||||
|
if (!column_is_int(p.j()))
|
||||||
|
is_int = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add term variables to vars_used
|
||||||
|
vars_used.insert(term_variables.begin(), term_variables.end());
|
||||||
|
|
||||||
if (is_int) {
|
if (is_int) {
|
||||||
out << "(set-logic QF_LIA)\n\n";
|
out << "(set-logic QF_LIA)\n\n";
|
||||||
}
|
}
|
||||||
|
@ -2619,6 +2634,38 @@ namespace lp {
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
|
|
||||||
|
// Define term relationships
|
||||||
|
out << "; Term definitions\n";
|
||||||
|
for (unsigned var : vars_used) {
|
||||||
|
if (column_has_term(var)) {
|
||||||
|
const lar_term& term = get_term(var);
|
||||||
|
out << "(assert (= x" << var << " ";
|
||||||
|
|
||||||
|
if (term.size() == 0) {
|
||||||
|
out << "0";
|
||||||
|
} else {
|
||||||
|
if (term.size() > 1) out << "(+ ";
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& p : term) {
|
||||||
|
if (first) first = false;
|
||||||
|
else out << " ";
|
||||||
|
|
||||||
|
if (p.coeff().is_one()) {
|
||||||
|
out << "x" << p.j();
|
||||||
|
} else {
|
||||||
|
out << "(* " << format_smt2_constant(p.coeff()) << " x" << p.j() << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (term.size() > 1) out << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
out << "))\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out << "\n";
|
||||||
|
|
||||||
// Add assertions for the dependencies
|
// Add assertions for the dependencies
|
||||||
out << "; Bound dependencies\n";
|
out << "; Bound dependencies\n";
|
||||||
|
|
||||||
|
@ -2629,9 +2676,6 @@ namespace lp {
|
||||||
// Handle the constraint type and expression
|
// Handle the constraint type and expression
|
||||||
auto k = c.kind();
|
auto k = c.kind();
|
||||||
|
|
||||||
// Handle empty constraint (just constant)
|
|
||||||
SASSERT(c.coeffs().size());
|
|
||||||
|
|
||||||
// Normal constraint with variables
|
// Normal constraint with variables
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case LE: out << "(<= "; break;
|
case LE: out << "(<= "; break;
|
||||||
|
@ -2690,7 +2734,7 @@ namespace lp {
|
||||||
// Check sat and get model if available
|
// Check sat and get model if available
|
||||||
out << "(check-sat)\n";
|
out << "(check-sat)\n";
|
||||||
out << "(exit)\n";
|
out << "(exit)\n";
|
||||||
}
|
}
|
||||||
} // namespace lp
|
} // namespace lp
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue