3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-04 22:36:10 +00:00

Standardize for-loop increments to prefix form (++i) (#8199)

* Initial plan

* Convert postfix to prefix increment in for loops

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix member variable increment conversion bug

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update API generator to produce prefix increments

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-14 19:55:31 -08:00 committed by GitHub
parent 1bf463d77a
commit 2436943794
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
475 changed files with 3237 additions and 3237 deletions

View file

@ -47,8 +47,8 @@ void mpz_matrix_manager::mk(unsigned m, unsigned n, mpz_matrix & A) {
void mpz_matrix_manager::del(mpz_matrix & A) {
if (A.a_ij != nullptr) {
for (unsigned i = 0; i < A.m; i++)
for (unsigned j = 0; j < A.n; j++)
for (unsigned i = 0; i < A.m; ++i)
for (unsigned j = 0; j < A.n; ++j)
nm().del(A(i,j));
unsigned sz = sizeof(mpz) * A.m * A.n;
m_allocator.deallocate(sz, A.a_ij);
@ -66,16 +66,16 @@ void mpz_matrix_manager::set(mpz_matrix & A, mpz_matrix const & B) {
mk(B.m, B.n, A);
}
SASSERT(A.m == B.m && A.n == B.n);
for (unsigned i = 0; i < B.m; i++)
for (unsigned j = 0; j < B.n; j++)
for (unsigned i = 0; i < B.m; ++i)
for (unsigned j = 0; j < B.n; ++j)
nm().set(A(i, j), B(i, j));
}
void mpz_matrix_manager::tensor_product(mpz_matrix const & A, mpz_matrix const & B, mpz_matrix & C) {
scoped_mpz_matrix CC(*this);
mk(A.m * B.m, A.n * B.n, CC);
for (unsigned i = 0; i < CC.m(); i++)
for (unsigned j = 0; j < CC.n(); j++)
for (unsigned i = 0; i < CC.m(); ++i)
for (unsigned j = 0; j < CC.n(); ++j)
nm().mul(A(i / B.m, j / B.n),
B(i % B.m, j % B.n),
CC(i, j));
@ -84,7 +84,7 @@ void mpz_matrix_manager::tensor_product(mpz_matrix const & A, mpz_matrix const &
void mpz_matrix_manager::swap_rows(mpz_matrix & A, unsigned i, unsigned j) {
if (i != j) {
for (unsigned k = 0; k < A.n; k++)
for (unsigned k = 0; k < A.n; ++k)
::swap(A(i, k), A(j, k));
}
}
@ -98,7 +98,7 @@ void mpz_matrix_manager::swap_rows(mpz_matrix & A, unsigned i, unsigned j) {
bool mpz_matrix_manager::normalize_row(mpz * A_i, unsigned n, mpz * b_i, bool int_solver) {
scoped_mpz g(nm());
bool first = true;
for (unsigned j = 0; j < n; j++) {
for (unsigned j = 0; j < n; ++j) {
if (nm().is_zero(A_i[j]))
continue;
if (first) {
@ -117,7 +117,7 @@ bool mpz_matrix_manager::normalize_row(mpz * A_i, unsigned n, mpz * b_i, bool in
if (!nm().is_one(g)) {
if (b_i) {
if (nm().divides(g, *b_i)) {
for (unsigned j = 0; j < n; j++) {
for (unsigned j = 0; j < n; ++j) {
nm().div(A_i[j], g, A_i[j]);
}
nm().div(*b_i, g, *b_i);
@ -128,7 +128,7 @@ bool mpz_matrix_manager::normalize_row(mpz * A_i, unsigned n, mpz * b_i, bool in
}
}
else {
for (unsigned j = 0; j < n; j++) {
for (unsigned j = 0; j < n; ++j) {
nm().div(A_i[j], g, A_i[j]);
}
}
@ -174,15 +174,15 @@ k1=> 0 0 ... 0 X ... X
*/
bool mpz_matrix_manager::eliminate(mpz_matrix & A, mpz * b, unsigned k1, unsigned k2, bool int_solver) {
// check if first k2-1 positions of row k1 are 0
DEBUG_CODE(for (unsigned j = 0; j < k2; j++) { SASSERT(nm().is_zero(A(k1, j))); });
DEBUG_CODE(for (unsigned j = 0; j < k2; ++j) { SASSERT(nm().is_zero(A(k1, j))); });
mpz & a_kk = A(k1, k2);
SASSERT(!nm().is_zero(a_kk));
scoped_mpz t1(nm()), t2(nm());
scoped_mpz a_ik_prime(nm()), a_kk_prime(nm()), lcm_a_kk_a_ik(nm());
// for all rows below pivot
for (unsigned i = k1+1; i < A.m; i++) {
for (unsigned i = k1+1; i < A.m; ++i) {
// check if first k-1 positions of row k are 0
DEBUG_CODE(for (unsigned j = 0; j < k2; j++) { SASSERT(nm().is_zero(A(i, j))); });
DEBUG_CODE(for (unsigned j = 0; j < k2; ++j) { SASSERT(nm().is_zero(A(i, j))); });
mpz & a_ik = A(i, k2);
if (!nm().is_zero(a_ik)) {
// a_ik' = lcm(a_kk, a_ik)/a_kk
@ -190,7 +190,7 @@ bool mpz_matrix_manager::eliminate(mpz_matrix & A, mpz * b, unsigned k1, unsigne
nm().lcm(a_kk, a_ik, lcm_a_kk_a_ik);
nm().div(lcm_a_kk_a_ik, a_kk, a_ik_prime);
nm().div(lcm_a_kk_a_ik, a_ik, a_kk_prime);
for (unsigned j = k2+1; j < A.n; j++) {
for (unsigned j = k2+1; j < A.n; ++j) {
// a_ij <- a_kk' * a_ij - a_ik' * a_kj
nm().mul(a_ik_prime, A(k1, j), t1);
nm().mul(a_kk_prime, A(i, j), t2);
@ -217,18 +217,18 @@ bool mpz_matrix_manager::solve_core(mpz_matrix const & _A, mpz * b, bool int_sol
SASSERT(_A.n == _A.m);
scoped_mpz_matrix A(*this);
set(A, _A);
for (unsigned k = 0; k < A.m(); k++) {
for (unsigned k = 0; k < A.m(); ++k) {
TRACE(mpz_matrix,
tout << "k: " << k << "\n" << A;
tout << "b:";
for (unsigned i = 0; i < A.m(); i++) {
for (unsigned i = 0; i < A.m(); ++i) {
tout << " ";
nm().display(tout, b[i]);
}
tout << "\n";);
// find pivot
unsigned i = k;
for (; i < A.m(); i++) {
for (; i < A.m(); ++i) {
if (!nm().is_zero(A(i, k)))
break;
}
@ -245,7 +245,7 @@ bool mpz_matrix_manager::solve_core(mpz_matrix const & _A, mpz * b, bool int_sol
unsigned k = A.m();
while (k > 0) {
--k;
DEBUG_CODE(for (unsigned j = 0; j < A.n(); j++) { SASSERT(j == k || nm().is_zero(A(k, j))); });
DEBUG_CODE(for (unsigned j = 0; j < A.n(); ++j) { SASSERT(j == k || nm().is_zero(A(k, j))); });
SASSERT(!nm().is_zero(A(k, k)));
if (nm().divides(A(k, k), b[k])) {
nm().div(b[k], A(k, k), b[k]);
@ -283,7 +283,7 @@ bool mpz_matrix_manager::solve_core(mpz_matrix const & _A, mpz * b, bool int_sol
}
bool mpz_matrix_manager::solve(mpz_matrix const & A, mpz * b, mpz const * c) {
for (unsigned i = 0; i < A.n; i++)
for (unsigned i = 0; i < A.n; ++i)
nm().set(b[i], c[i]);
return solve_core(A, b, true);
}
@ -291,11 +291,11 @@ bool mpz_matrix_manager::solve(mpz_matrix const & A, mpz * b, mpz const * c) {
bool mpz_matrix_manager::solve(mpz_matrix const & A, int * b, int const * c) {
scoped_mpz_matrix _b(*this);
mk(A.n, 1, _b);
for (unsigned i = 0; i < A.n; i++)
for (unsigned i = 0; i < A.n; ++i)
nm().set(_b(i,0), c[i]);
bool r = solve_core(A, _b.A.a_ij, true);
if (r) {
for (unsigned i = 0; i < A.n; i++)
for (unsigned i = 0; i < A.n; ++i)
b[i] = _b.get_int(i, 0);
}
return r;
@ -321,8 +321,8 @@ void mpz_matrix_manager::filter_cols(mpz_matrix const & A, unsigned num_cols, un
SASSERT(num_cols < A.n);
scoped_mpz_matrix C(*this);
mk(A.m, num_cols, C);
for (unsigned i = 0; i < A.m; i++)
for (unsigned j = 0; j < num_cols; j++)
for (unsigned i = 0; i < A.m; ++i)
for (unsigned j = 0; j < num_cols; ++j)
nm().set(C(i, j), A(i, cols[j]));
B.swap(C);
}
@ -333,7 +333,7 @@ void mpz_matrix_manager::permute_rows(mpz_matrix const & A, unsigned const * p,
DEBUG_CODE({
buffer<bool> seen;
seen.resize(A.m, false);
for (unsigned i = 0; i < A.m; i++) {
for (unsigned i = 0; i < A.m; ++i) {
SASSERT(p[i] < A.m);
SASSERT(!seen[p[i]]);
seen[p[i]] = true;
@ -341,8 +341,8 @@ void mpz_matrix_manager::permute_rows(mpz_matrix const & A, unsigned const * p,
});
scoped_mpz_matrix C(*this);
mk(A.m, A.n, C);
for (unsigned i = 0; i < A.m; i++)
for (unsigned j = 0; j < A.n; j++)
for (unsigned i = 0; i < A.m; ++i)
for (unsigned j = 0; j < A.n; ++j)
nm().set(C(i, j), A(p[i], j));
B.swap(C);
}
@ -356,13 +356,13 @@ unsigned mpz_matrix_manager::linear_independent_rows(mpz_matrix const & _A, unsi
set(A, _A);
sbuffer<unsigned, 128> rows;
rows.resize(A.m(), 0);
for (unsigned i = 0; i < A.m(); i++)
for (unsigned i = 0; i < A.m(); ++i)
rows[i] = i;
for (unsigned k1 = 0, k2 = 0; k1 < A.m(); k1++) {
for (unsigned k1 = 0, k2 = 0; k1 < A.m(); ++k1) {
TRACE(mpz_matrix, tout << "k1: " << k1 << ", k2: " << k2 << "\n" << A;);
// find pivot
unsigned pivot = UINT_MAX;
for (unsigned i = k1; i < A.m(); i++) {
for (unsigned i = k1; i < A.m(); ++i) {
if (!nm().is_zero(A(i, k2))) {
if (pivot == UINT_MAX) {
pivot = i;
@ -390,8 +390,8 @@ unsigned mpz_matrix_manager::linear_independent_rows(mpz_matrix const & _A, unsi
// Copy linear independent rows to B
mpz_matrix & C = A;
mk(r_sz, _A.n, C);
for (unsigned i = 0; i < r_sz; i++ ) {
for (unsigned j = 0; j < _A.n; j++) {
for (unsigned i = 0; i < r_sz; ++i ) {
for (unsigned j = 0; j < _A.n; ++j) {
nm().set(C(i, j), _A(r[i], j));
}
}
@ -401,14 +401,14 @@ unsigned mpz_matrix_manager::linear_independent_rows(mpz_matrix const & _A, unsi
void mpz_matrix_manager::display(std::ostream & out, mpz_matrix const & A, unsigned cell_width) const {
out << A.m << " x " << A.n << " Matrix\n";
for (unsigned i = 0; i < A.m; i++) {
for (unsigned j = 0; j < A.n; j++) {
for (unsigned i = 0; i < A.m; ++i) {
for (unsigned j = 0; j < A.n; ++j) {
if (j > 0)
out << " ";
std::string s = nm().to_string(A(i, j));
if (s.size() < cell_width) {
unsigned space = cell_width - static_cast<unsigned>(s.size());
for (unsigned k = 0; k < space; k++)
for (unsigned k = 0; k < space; ++k)
out << " ";
}
out << s;

View file

@ -689,7 +689,7 @@ namespace realclosure {
template<typename T>
void restore_saved_intervals(ptr_vector<T> & to_restore) {
unsigned sz = to_restore.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
T * v = to_restore[i];
set_interval(v->m_interval, *(v->m_old_interval));
bqim().del(*(v->m_old_interval));
@ -772,7 +772,7 @@ namespace realclosure {
}
void finalize(array<polynomial> & ps) {
for (unsigned i = 0; i < ps.size(); i++)
for (unsigned i = 0; i < ps.size(); ++i)
reset_p(ps[i]);
ps.finalize(allocator());
}
@ -783,7 +783,7 @@ namespace realclosure {
void del_sign_conditions(unsigned sz, sign_condition * const * to_delete) {
ptr_buffer<sign_condition> all_to_delete;
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
sign_condition * sc = to_delete[i];
while (sc && sc->m_mark == false) {
sc->m_mark = true;
@ -791,7 +791,7 @@ namespace realclosure {
sc = sc->m_prev;
}
}
for (unsigned i = 0; i < all_to_delete.size(); i++) {
for (unsigned i = 0; i < all_to_delete.size(); ++i) {
del_sign_condition(all_to_delete[i]);
}
}
@ -863,7 +863,7 @@ namespace realclosure {
}
void inc_ref(unsigned sz, value * const * p) {
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
inc_ref(p[i]);
}
@ -877,7 +877,7 @@ namespace realclosure {
}
void dec_ref(unsigned sz, value * const * p) {
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
dec_ref(p[i]);
}
@ -887,7 +887,7 @@ namespace realclosure {
}
void del(numeral_vector & v) {
for (unsigned i = 0; i < v.size(); i++)
for (unsigned i = 0; i < v.size(); ++i)
del(v[i]);
}
@ -1104,7 +1104,7 @@ namespace realclosure {
}
bool depends_on_infinitesimals(unsigned sz, value * const * p) const {
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
if (depends_on_infinitesimals(p[i]))
return true;
return false;
@ -1466,7 +1466,7 @@ namespace realclosure {
if (!abs_lower_magnitude(interval(p[n-1]), lc_mag))
return false;
N = -static_cast<int>(m_ini_precision);
for (unsigned k = 2; k <= n; k++) {
for (unsigned k = 2; k <= n; ++k) {
value * a = p[n - k];
if (!is_zero(a) && sign(a) != lc_sign) {
int a_mag;
@ -1512,7 +1512,7 @@ namespace realclosure {
if (!abs_lower_magnitude(aux, lc_mag))
return false;
N = -static_cast<int>(m_ini_precision);
for (unsigned k = 2; k <= n; k++) {
for (unsigned k = 2; k <= n; ++k) {
value * a = as[n - k];
if (!is_zero(a)) {
neg_root_adjust(interval(as[n-k]), n-k, aux);
@ -1590,7 +1590,7 @@ namespace realclosure {
derivative(n, p, p_prime);
ds.push(p_prime.size(), p_prime.data());
SASSERT(n >= 3);
for (unsigned i = 0; i < n - 2; i++) {
for (unsigned i = 0; i < n - 2; ++i) {
SASSERT(ds.size() > 0);
unsigned prev = ds.size() - 1;
n = ds.size(prev);
@ -1710,7 +1710,7 @@ namespace realclosure {
) {
SASSERT(taqrs.size() == prs.size());
new_taqrs.reset(); new_prs.reset();
for (unsigned i = 0; i < taqrs.size(); i++) {
for (unsigned i = 0; i < taqrs.size(); ++i) {
// Add prs * 1
new_taqrs.push_back(taqrs[i]);
new_prs.push(prs.size(i), prs.coeffs(i));
@ -1776,7 +1776,7 @@ namespace realclosure {
void set_array_p(array<polynomial> & ps, scoped_polynomial_seq const & prs) {
unsigned sz = prs.size();
ps.set(allocator(), sz, polynomial());
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
unsigned pi_sz = prs.size(i);
value * const * pi = prs.coeffs(i);
set_p(ps[i], pi_sz, pi);
@ -1991,12 +1991,12 @@ namespace realclosure {
SASSERT(M_s.m() == scs.size());
TRACE(rcf_sign_det,
tout << M_s;
for (unsigned j = 0; j < scs.size(); j++) {
for (unsigned j = 0; j < scs.size(); ++j) {
display_sign_conditions(tout, scs[j]);
tout << " = " << taqrs[j] << "\n";
}
tout << "qs:\n";
for (unsigned j = 0; j < qs.size(); j++) {
for (unsigned j = 0; j < qs.size(); ++j) {
display_poly(tout, qs.size(j), qs.coeffs(j)); tout << "\n";
});
// We keep executing this loop until we have only one root for each sign condition in scs.
@ -2028,9 +2028,9 @@ namespace realclosure {
// Solve
// new_M_s * sc_cardinalities = new_taqrs
VERIFY(mm().solve(new_M_s, sc_cardinalities.data(), new_taqrs.data()));
TRACE(rcf_sign_det, tout << "solution: "; for (unsigned i = 0; i < sc_cardinalities.size(); i++) { tout << sc_cardinalities[i] << " "; } tout << "\n";);
TRACE(rcf_sign_det, tout << "solution: "; for (unsigned i = 0; i < sc_cardinalities.size(); ++i) { tout << sc_cardinalities[i] << " "; } tout << "\n";);
// The solution must contain only positive values <= num_roots
DEBUG_CODE(for (unsigned j = 0; j < sc_cardinalities.size(); j++) { SASSERT(0 <= sc_cardinalities[j] && sc_cardinalities[j] <= num_roots); });
DEBUG_CODE(for (unsigned j = 0; j < sc_cardinalities.size(); ++j) { SASSERT(0 <= sc_cardinalities[j] && sc_cardinalities[j] <= num_roots); });
// We should keep q only if it discriminated something.
// That is,
// If !use_q2, then There is an i s.t. sc_cardinalities[2*i] > 0 && sc_cardinalities[2*i] > 0
@ -2051,7 +2051,7 @@ namespace realclosure {
while (j < sc_cardinalities.size()) {
sign_condition * sc = scs[k];
k++;
for (unsigned s = 0; s < step_sz; s++) {
for (unsigned s = 0; s < step_sz; ++s) {
// Remark: the second row of M contains the sign for q
if (sc_cardinalities[j] > 0) {
new_scs.push_back(mk_sign_condition(q_idx, M.get_int(1, s), sc));
@ -2074,7 +2074,7 @@ namespace realclosure {
// Update taqrs and prs
prs.reset();
taqrs.reset();
for (unsigned j = 0; j < new_num_rows; j++) {
for (unsigned j = 0; j < new_num_rows; ++j) {
unsigned rid = new_row_idxs[j];
prs.push(new_prs.size(rid), new_prs.coeffs(rid));
taqrs.push_back(new_taqrs[rid]);
@ -2089,21 +2089,21 @@ namespace realclosure {
tout << "Final state\n";
display_poly(tout, p_sz, p); tout << "\n";
tout << M_s;
for (unsigned j = 0; j < scs.size(); j++) {
for (unsigned j = 0; j < scs.size(); ++j) {
display_sign_conditions(tout, scs[j]);
tout << " = " << taqrs[j] << "\n";
}
tout << "qs:\n";
for (unsigned j = 0; j < qs.size(); j++) {
for (unsigned j = 0; j < qs.size(); ++j) {
display_poly(tout, qs.size(j), qs.coeffs(j)); tout << "\n";
}
tout << "prs:\n";
for (unsigned j = 0; j < prs.size(); j++) {
for (unsigned j = 0; j < prs.size(); ++j) {
display_poly(tout, prs.size(j), prs.coeffs(j)); tout << "\n";
});
SASSERT(M_s.n() == M_s.m()); SASSERT(M_s.n() == static_cast<unsigned>(num_roots));
sign_det * sd = mk_sign_det(M_s, prs, taqrs, qs, scs);
for (unsigned idx = 0; idx < static_cast<unsigned>(num_roots); idx++) {
for (unsigned idx = 0; idx < static_cast<unsigned>(num_roots); ++idx) {
add_root(p_sz, p, interval, iso_interval, sd, idx, roots);
}
}
@ -2115,7 +2115,7 @@ namespace realclosure {
SASSERT(n >= 2);
SASSERT(!is_zero(p[0]));
SASSERT(!is_zero(p[n-1]));
for (unsigned i = 1; i < n - 1; i++) {
for (unsigned i = 1; i < n - 1; ++i) {
if (!is_zero(p[i]))
return false;
}
@ -2410,7 +2410,7 @@ namespace realclosure {
\brief Root isolation entry point.
*/
void isolate_roots(unsigned n, numeral const * p, numeral_vector & roots) {
TRACE(rcf_isolate_bug, tout << "isolate_roots: "; for (unsigned i = 0; i < n; i++) { display(tout, p[i]); tout << " "; } tout << "\n";);
TRACE(rcf_isolate_bug, tout << "isolate_roots: "; for (unsigned i = 0; i < n; ++i) { display(tout, p[i]); tout << " "; } tout << "\n";);
SASSERT(n > 0);
SASSERT(!is_zero(p[n-1]));
if (n == 1) {
@ -2418,14 +2418,14 @@ namespace realclosure {
return;
}
unsigned i = 0;
for (; i < n; i++) {
for (; i < n; ++i) {
if (!is_zero(p[i]))
break;
}
SASSERT(i < n);
SASSERT(!is_zero(p[i]));
ptr_buffer<value> nz_p;
for (; i < n; i++)
for (; i < n; ++i)
nz_p.push_back(p[i].m_value);
nz_isolate_roots(nz_p.size(), nz_p.data(), roots);
if (nz_p.size() < n) {
@ -2705,13 +2705,13 @@ namespace realclosure {
value_ref a_i(*this);
unsigned min = std::min(sz1, sz2);
unsigned i = 0;
for (; i < min; i++) {
for (; i < min; ++i) {
add(p1[i], p2[i], a_i);
r.push_back(a_i);
}
for (; i < sz1; i++)
for (; i < sz1; ++i)
r.push_back(p1[i]);
for (; i < sz2; i++)
for (; i < sz2; ++i)
r.push_back(p2[i]);
SASSERT(r.size() == std::max(sz1, sz2));
adjust_size(r);
@ -2741,13 +2741,13 @@ namespace realclosure {
value_ref a_i(*this);
unsigned min = std::min(sz1, sz2);
unsigned i = 0;
for (; i < min; i++) {
for (; i < min; ++i) {
sub(p1[i], p2[i], a_i);
r.push_back(a_i);
}
for (; i < sz1; i++)
for (; i < sz1; ++i)
r.push_back(p1[i]);
for (; i < sz2; i++) {
for (; i < sz2; ++i) {
neg(p2[i], a_i);
r.push_back(a_i);
}
@ -2778,7 +2778,7 @@ namespace realclosure {
if (a == nullptr)
return;
value_ref a_i(*this);
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
mul(a, p[i], a_i);
r.push_back(a_i);
}
@ -2798,11 +2798,11 @@ namespace realclosure {
std::swap(p1, p2);
}
value_ref tmp(*this);
for (unsigned i = 0; i < sz1; i++) {
for (unsigned i = 0; i < sz1; ++i) {
checkpoint();
if (p1[i] == nullptr)
continue;
for (unsigned j = 0; j < sz2; j++) {
for (unsigned j = 0; j < sz2; ++j) {
// r[i+j] <- r[i+j] + p1[i]*p2[j]
mul(p1[i], p2[j], tmp);
add(r[i+j], tmp, tmp);
@ -2821,7 +2821,7 @@ namespace realclosure {
return;
value_ref a_i(*this);
unsigned sz = p.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
div(p[i], a, a_i);
p.set(i, a_i);
}
@ -2864,7 +2864,7 @@ namespace realclosure {
// q[m_n] <- q[m_n] + r[sz1 - 1]/b_n
add(q[m_n], ratio, aux);
q.set(m_n, aux);
for (unsigned i = 0; i < sz2 - 1; i++) {
for (unsigned i = 0; i < sz2 - 1; ++i) {
// r[i + m_n] <- r[i + m_n] - ratio * p2[i]
mul(ratio, p2[i], aux);
sub(r[i + m_n], aux, aux);
@ -2891,7 +2891,7 @@ namespace realclosure {
void div(unsigned sz, value * const * p, value * a, value_ref_buffer & r) {
r.reset();
value_ref a_i(*this);
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
div(p[i], a, a_i);
r.push_back(a_i);
}
@ -2927,7 +2927,7 @@ namespace realclosure {
}
unsigned m_n = sz1 - sz2;
div(r[sz1 - 1], b_n, ratio);
for (unsigned i = 0; i < sz2 - 1; i++) {
for (unsigned i = 0; i < sz2 - 1; ++i) {
mul(ratio, p2[i], new_a);
sub(r[i + m_n], new_a, new_a);
r.set(i + m_n, new_a);
@ -2977,14 +2977,14 @@ namespace realclosure {
a_m = r[sz1 - 1];
// don't need to update position sz1 - 1, since it will become 0
if (!is_rational_one(b_n)) {
for (unsigned i = 0; i < sz1 - 1; i++) {
for (unsigned i = 0; i < sz1 - 1; ++i) {
mul(r[i], b_n, new_a);
r.set(i, new_a);
}
}
// buffer: a_m * x^m + b_n * a_{m-1} * x^{m-1} + ... + b_n * a_0
// don't need to process i = sz2 - 1, because r[sz1 - 1] will become 0.
for (unsigned i = 0; i < sz2 - 1; i++) {
for (unsigned i = 0; i < sz2 - 1; ++i) {
mul(a_m, p2[i], new_a);
sub(r[i + m_n], new_a, new_a);
r.set(i + m_n, new_a);
@ -3006,7 +3006,7 @@ namespace realclosure {
SASSERT(p != r.data());
r.reset();
value_ref a_i(*this);
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
neg(p[i], a_i);
r.push_back(a_i);
}
@ -3018,7 +3018,7 @@ namespace realclosure {
void neg(value_ref_buffer & r) {
value_ref a_i(*this);
unsigned sz = r.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
neg(r[i], a_i);
r.set(i, a_i);
}
@ -3030,7 +3030,7 @@ namespace realclosure {
void neg(polynomial & p) {
value_ref a_i(*this);
unsigned sz = p.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
neg(p[i], a_i);
inc_ref(a_i.get());
dec_ref(p[i]);
@ -3106,7 +3106,7 @@ namespace realclosure {
bool struct_eq(unsigned sz_a, value * const * p_a, unsigned sz_b, value * const * p_b) const {
if (sz_a != sz_b)
return false;
for (unsigned i = 0; i < sz_a; i++) {
for (unsigned i = 0; i < sz_a; ++i) {
if (!struct_eq(p_a[i], p_b[i]))
return false;
}
@ -3148,7 +3148,7 @@ namespace realclosure {
\brief See comment at has_clean_denominators(value * a)
*/
bool has_clean_denominators(unsigned sz, value * const * p) const {
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if (!has_clean_denominators(p[i]))
return false;
}
@ -3218,7 +3218,7 @@ namespace realclosure {
value_ref_buffer nums(*this), dens(*this);
value_ref a_n(*this), a_d(*this);
bool all_one = true;
for (unsigned i = 0; i < p_sz; i++) {
for (unsigned i = 0; i < p_sz; ++i) {
if (p[i]) {
clean_denominators_core(p[i], a_n, a_d);
nums.push_back(a_n);
@ -3243,7 +3243,7 @@ namespace realclosure {
bool found_z = false;
SASSERT(nums.size() == p_sz);
SASSERT(dens.size() == p_sz);
for (unsigned i = 0; i < p_sz; i++) {
for (unsigned i = 0; i < p_sz; ++i) {
if (!dens[i])
continue;
if (is_nz_rational(dens[i])) {
@ -3278,7 +3278,7 @@ namespace realclosure {
d = lcm;
value_ref_buffer multipliers(*this);
value_ref m(*this);
for (unsigned i = 0; i < p_sz; i++) {
for (unsigned i = 0; i < p_sz; ++i) {
if (!nums[i]) {
norm_p.push_back(nullptr);
}
@ -3297,7 +3297,7 @@ namespace realclosure {
is_z = true;
}
bool found_lt_eq = false;
for (unsigned j = 0; j < p_sz; j++) {
for (unsigned j = 0; j < p_sz; ++j) {
TRACE(rcf_clean_bug, tout << "j: " << j << " "; display(tout, m, false); tout << "\n";);
if (!dens[j])
continue;
@ -3547,7 +3547,7 @@ namespace realclosure {
return false;
}
else {
for (unsigned i = 0; i < p_sz; i++) {
for (unsigned i = 0; i < p_sz; ++i) {
if (p[i]) {
if (!gcd_int_coeffs(p[i], g))
return false;
@ -3574,7 +3574,7 @@ namespace realclosure {
if (gcd_int_coeffs(p.size(), p.data(), g) && !qm().is_one(g)) {
SASSERT(qm().is_pos(g));
value_ref a(*this);
for (unsigned i = 0; i < p.size(); i++) {
for (unsigned i = 0; i < p.size(); ++i) {
if (p[i]) {
a = p[i];
p.set(i, nullptr);
@ -3608,7 +3608,7 @@ namespace realclosure {
value_ref_buffer new_ais(*this);
value_ref ai(*this);
polynomial const & p = rf->num();
for (unsigned i = 0; i < p.size(); i++) {
for (unsigned i = 0; i < p.size(); ++i) {
if (p[i]) {
ai = p[i];
exact_div_z(ai, b);
@ -3649,7 +3649,7 @@ namespace realclosure {
value_ref a_i(*this);
SASSERT(p[sz-1] != 0);
if (!is_rational_one(p[sz-1])) {
for (unsigned i = 0; i < sz - 1; i++) {
for (unsigned i = 0; i < sz - 1; ++i) {
div(p[i], p[sz-1], a_i);
p.set(i, a_i);
}
@ -3759,7 +3759,7 @@ namespace realclosure {
void derivative(unsigned sz, value * const * p, value_ref_buffer & r) {
r.reset();
if (sz > 1) {
for (unsigned i = 1; i < sz; i++) {
for (unsigned i = 1; i < sz; ++i) {
value_ref a_i(*this);
a_i = mk_rational(mpq(i));
mul(a_i, p[i], a_i);
@ -3937,7 +3937,7 @@ namespace realclosure {
approximating the coefficients do not have -oo or oo as lower/upper bounds.
*/
bool has_refineable_approx_coeffs(unsigned n, value * const * p) {
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
if (p[i] != nullptr) {
mpbqi & a_i = interval(p[i]);
if (a_i.lower_is_inf() || a_i.upper_is_inf())
@ -4021,7 +4021,7 @@ namespace realclosure {
*/
int find_biggest_interval_magnitude(unsigned n, value * const * p) {
int r = INT_MIN;
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
if (p[i] != nullptr) {
mpbqi & a_i = interval(p[i]);
SASSERT(!a_i.lower_is_inf() && !a_i.upper_is_inf());
@ -4109,7 +4109,7 @@ namespace realclosure {
sign = 0;
prev_sign = 0;
unsigned i = 0;
for (; i < sz; i++) {
for (; i < sz; ++i) {
// find next nonzero
unsigned psz = seq.size(i);
value * const * p = seq.coeffs(i);
@ -4254,7 +4254,7 @@ namespace realclosure {
\brief Refine the interval for each coefficient of in the polynomial p.
*/
bool refine_coeffs_interval(unsigned n, value * const * p, unsigned prec) {
for (unsigned i = 0; i < n; i++) {
for (unsigned i = 0; i < n; ++i) {
if (p[i] != nullptr && !refine_interval(p[i], prec))
return false;
}
@ -4517,7 +4517,7 @@ namespace realclosure {
*/
static unsigned first_non_zero(polynomial const & p) {
unsigned sz = p.size();
for (unsigned i = 0; i < sz; i++) {
for (unsigned i = 0; i < sz; ++i) {
if (p[i] != 0)
return i;
}
@ -4531,7 +4531,7 @@ namespace realclosure {
int sign_of_first_non_zero(polynomial const & p, unsigned start_idx) {
unsigned sz = p.size();
SASSERT(start_idx < sz);
for (unsigned i = start_idx; i < sz; i++) {
for (unsigned i = start_idx; i < sz; ++i) {
if (p[i] != 0)
return sign(p[i]);
}
@ -4810,7 +4810,7 @@ namespace realclosure {
int_buffer new_taqrs;
value_ref_buffer prq(*this);
// fill new_taqrs using taqrs and the new tarski queries containing q (and q^2 when use_q2 == true).
for (unsigned i = 0; i < taqrs.size(); i++) {
for (unsigned i = 0; i < taqrs.size(); ++i) {
// Add TaQ(p, prs[i] * 1; x->iso_interval())
new_taqrs.push_back(taqrs[i]);
// Add TaQ(p, prs[i] * q; x->iso_interval())
@ -4832,16 +4832,16 @@ namespace realclosure {
// - contains only 0 or 1
// - !use_q2 IMPLIES for all i in [0, taqrs.size()) (sc_cardinalities[2*i] == 1) + (sc_cardinalities[2*i + 1] == 1) == 1
// - use_q2 IMPLIES for all i in [0, taqrs.size()) (sc_cardinalities[3*i] == 1) + (sc_cardinalities[3*i + 1] == 1) + (sc_cardinalities[3*i + 2] == 1) == 1
for (unsigned i = 0; i < sc_cardinalities.size(); i++) {
for (unsigned i = 0; i < sc_cardinalities.size(); ++i) {
SASSERT(sc_cardinalities[i] == 0 || sc_cardinalities[i] == 1);
}
if (!use_q2) {
for (unsigned i = 0; i < taqrs.size(); i++) {
for (unsigned i = 0; i < taqrs.size(); ++i) {
SASSERT((sc_cardinalities[2*i] == 1) + (sc_cardinalities[2*i + 1] == 1) == 1);
}
}
else {
for (unsigned i = 0; i < taqrs.size(); i++) {
for (unsigned i = 0; i < taqrs.size(); ++i) {
SASSERT((sc_cardinalities[3*i] == 1) + (sc_cardinalities[3*i + 1] == 1) + (sc_cardinalities[3*i + 2] == 1) == 1);
}
}
@ -5667,7 +5667,7 @@ namespace realclosure {
alpha_val = mk_rational_function_value(alpha);
// search for the root that is equal to alpha
unsigned i = 0;
for (i = 0; i < roots.size(); i++) {
for (i = 0; i < roots.size(); ++i) {
if (compare(alpha_val, roots[i].m_value) == 0) {
// found it;
break;
@ -5809,7 +5809,7 @@ namespace realclosure {
value_ref neg_a(*this);
neg(a.m_value, neg_a);
p.push_back(neg_a);
for (unsigned i = 0; i < k - 1; i++)
for (unsigned i = 0; i < k - 1; ++i)
p.push_back(nullptr);
p.push_back(one());
@ -5904,7 +5904,7 @@ namespace realclosure {
}
void mark(polynomial const & p) {
for (unsigned i = 0; i < p.size(); i++) {
for (unsigned i = 0; i < p.size(); ++i) {
mark(p[i]);
}
}
@ -5921,7 +5921,7 @@ namespace realclosure {
static unsigned num_nz_coeffs(polynomial const & p) {
unsigned r = 0;
for (unsigned i = 0; i < p.size(); i++) {
for (unsigned i = 0; i < p.size(); ++i) {
if (p[i])
r++;
}
@ -6068,11 +6068,11 @@ namespace realclosure {
void display_poly(std::ostream & out, unsigned n, value * const * p) const {
collect_algebraic_refs c;
for (unsigned i = 0; i < n; i++)
for (unsigned i = 0; i < n; ++i)
c.mark(p[i]);
display_polynomial(out, n, p, display_free_var_proc(), true, false);
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
for (unsigned i = 0; i < c.m_found.size(); i++) {
for (unsigned i = 0; i < c.m_found.size(); ++i) {
algebraic * ext = c.m_found[i];
out << "\n r!" << ext->idx() << " := ";
display_algebraic_def(out, ext, true, false);
@ -6131,7 +6131,7 @@ namespace realclosure {
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
out << "[";
display(out, a, true, pp);
for (unsigned i = 0; i < c.m_found.size(); i++) {
for (unsigned i = 0; i < c.m_found.size(); ++i) {
algebraic * ext = c.m_found[i];
if (pp)
out << "; &alpha;<sub>" << ext->idx() << "</sub> := ";
@ -6502,12 +6502,12 @@ void pp(realclosure::manager::imp * imp, realclosure::value * v) {
}
void pp(realclosure::manager::imp * imp, unsigned sz, realclosure::value * const * p) {
for (unsigned i = 0; i < sz; i++)
for (unsigned i = 0; i < sz; ++i)
pp(imp, p[i]);
}
void pp(realclosure::manager::imp * imp, realclosure::manager::imp::value_ref_buffer const & p) {
for (unsigned i = 0; i < p.size(); i++)
for (unsigned i = 0; i < p.size(); ++i)
pp(imp, p[i]);
}