Skip to content

Commit c79967b

Browse files
using iterators
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 17f239c commit c79967b

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

genaisrc/myai.genai.mts

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ export async function invokeLLMClassInvariant(header : string, code : string) {
228228
Create only code for the class invariant methods and optionally auxiliary helper functions.
229229
230230
In addition, for each method, provide pre and post conditions.
231+
A precondition is an assertion that must be true before the method is called.
232+
Similarly, a postcondition is an assertion that must be true after the method is called.
231233
Include the well_formed() method in the pre and post conditions if it should be included.
232234
`
233235
}, {

src/muz/spacer/spacer_qe_project.cpp

+27-26
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ void peq::mk_peq(app_ref &result) {
129129
ptr_vector<expr> args;
130130
args.push_back(m_lhs);
131131
args.push_back(m_rhs);
132-
for (unsigned i = 0; i < m_num_indices; i++) {
133-
args.push_back(m_diff_indices.get(i));
134-
}
132+
for (auto idx : m_diff_indices)
133+
args.push_back(idx);
134+
135135
m_peq = m.mk_app(m_decl, args.size(), args.data());
136136
}
137137
result = m_peq;
@@ -144,13 +144,11 @@ void peq::mk_eq(app_ref_vector &aux_consts, app_ref &result,
144144
if (!stores_on_rhs) { std::swap(lhs, rhs); }
145145
// lhs = (...(store (store rhs i0 v0) i1 v1)...)
146146
sort *val_sort = get_array_range(lhs->get_sort());
147-
expr_ref_vector::iterator end = m_diff_indices.end();
148-
for (expr_ref_vector::iterator it = m_diff_indices.begin(); it != end;
149-
it++) {
147+
for (auto it : m_diff_indices) {
150148
app *val = m.mk_fresh_const("diff", val_sort);
151149
ptr_vector<expr> store_args;
152150
store_args.push_back(rhs);
153-
store_args.push_back(*it);
151+
store_args.push_back(it);
154152
store_args.push_back(val);
155153
rhs = m_arr_u.mk_store(store_args);
156154
aux_consts.push_back(val);
@@ -333,19 +331,19 @@ class arith_project_util {
333331
m_strict.reset();
334332
m_eq.reset();
335333

336-
for (unsigned i = 0; i < lits.size(); ++i) {
334+
for (auto lit : lits) {
337335
rational c(0), d(0);
338336
expr_ref t(m);
339337
bool is_strict = false;
340338
bool is_eq = false;
341339
bool is_diseq = false;
342-
if (!(*m_var)(lits.get(i))) {
343-
new_lits.push_back(lits.get(i));
340+
if (!(*m_var)(lit)) {
341+
new_lits.push_back(lit);
344342
continue;
345343
}
346-
if (is_linear(lits.get(i), c, t, d, is_strict, is_eq, is_diseq)) {
344+
if (is_linear(lit, c, t, d, is_strict, is_eq, is_diseq)) {
347345
if (c.is_zero()) {
348-
m_rw(lits.get(i), t);
346+
m_rw(lit, t);
349347
new_lits.push_back(t);
350348
}
351349
else if (is_eq) {
@@ -354,12 +352,13 @@ class arith_project_util {
354352
eq_term = mk_mul(-(rational::one() / c), t);
355353
use_eq = true;
356354
}
357-
m_lits.push_back(lits.get(i));
355+
m_lits.push_back(lit);
358356
m_coeffs.push_back(c);
359357
m_terms.push_back(t);
360358
m_strict.push_back(false);
361359
m_eq.push_back(true);
362-
} else {
360+
}
361+
else {
363362
if (is_diseq) {
364363
// c*x + t != 0
365364
// find out whether c*x + t < 0, or c*x + t > 0
@@ -376,7 +375,7 @@ class arith_project_util {
376375
}
377376
is_strict = true;
378377
}
379-
m_lits.push_back(lits.get(i));
378+
m_lits.push_back(lit);
380379
m_coeffs.push_back(c);
381380
m_terms.push_back(t);
382381
m_strict.push_back(is_strict);
@@ -390,7 +389,7 @@ class arith_project_util {
390389
}
391390
else
392391
return false;
393-
}
392+
}
394393
if (use_eq) {
395394
TRACE("qe", tout << "Using equality term: " << mk_pp(eq_term, m)
396395
<< "\n";);
@@ -488,7 +487,8 @@ class arith_project_util {
488487
m_strict.push_back(false);
489488
m_eq.push_back(true);
490489
m_divs.push_back(d);
491-
} else {
490+
}
491+
else {
492492
TRACE("qe", tout << "not an equality term\n";);
493493
if (is_diseq) {
494494
// c*x + t != 0
@@ -513,18 +513,18 @@ class arith_project_util {
513513
(!is_strict &&
514514
r <= rational::zero())) { // literal true in the
515515
// model
516-
if (c.is_pos()) {
516+
if (c.is_pos())
517517
++num_pos;
518-
} else {
519-
++num_neg;
520-
}
518+
else
519+
++num_neg;
521520
}
522521
}
523522
}
524523
TRACE("qe", tout << "c: " << c << "\n";
525524
tout << "t: " << mk_pp(t, m) << "\n";
526525
tout << "d: " << d << "\n";);
527-
} else
526+
}
527+
else
528528
return false;
529529
}
530530

@@ -573,13 +573,14 @@ class arith_project_util {
573573
map.insert(m_var->x(), eq_term, nullptr);
574574
TRACE("qe", tout << "Using equality term: " << mk_pp(eq_term, m)
575575
<< "\n";);
576-
} else {
576+
}
577+
else {
577578
// find substitution term for (lcm_coeffs * x)
578-
if (m_coeffs[eq_idx].is_pos()) {
579+
if (m_coeffs[eq_idx].is_pos())
579580
x_term_val = a.mk_uminus(m_terms.get(eq_idx));
580-
} else {
581+
else
581582
x_term_val = m_terms.get(eq_idx);
582-
}
583+
583584
m_rw(x_term_val);
584585
TRACE("qe", tout << "Using equality literal: "
585586
<< mk_pp(m_lits.get(eq_idx), m) << "\n";

0 commit comments

Comments
 (0)