mirror of
https://github.com/Z3Prover/z3
synced 2025-04-28 19:35:50 +00:00
call it data instead of c_ptr for approaching C++11 std::vector convention.
This commit is contained in:
parent
524dcd35f9
commit
4a6083836a
456 changed files with 2802 additions and 2802 deletions
|
@ -554,8 +554,8 @@ namespace algebraic_numbers {
|
|||
else {
|
||||
scoped_upoly & up_sqf = m_isolate_tmp3;
|
||||
up_sqf.reset();
|
||||
upm().square_free(up.size(), up.c_ptr(), up_sqf);
|
||||
TRACE("algebraic", upm().display(tout, up_sqf.size(), up_sqf.c_ptr()); tout << "\n";);
|
||||
upm().square_free(up.size(), up.data(), up_sqf);
|
||||
TRACE("algebraic", upm().display(tout, up_sqf.size(), up_sqf.data()); tout << "\n";);
|
||||
r.push_back(up_sqf, 1);
|
||||
return false;
|
||||
}
|
||||
|
@ -610,10 +610,10 @@ namespace algebraic_numbers {
|
|||
factors & fs = m_isolate_factors;
|
||||
fs.reset();
|
||||
bool full_fact;
|
||||
if (upm().has_zero_roots(up.size(), up.c_ptr())) {
|
||||
if (upm().has_zero_roots(up.size(), up.data())) {
|
||||
roots.push_back(numeral());
|
||||
scoped_upoly & nz_up = m_isolate_tmp2;
|
||||
upm().remove_zero_roots(up.size(), up.c_ptr(), nz_up);
|
||||
upm().remove_zero_roots(up.size(), up.data(), nz_up);
|
||||
full_fact = factor(nz_up, fs);
|
||||
}
|
||||
else {
|
||||
|
@ -640,7 +640,7 @@ namespace algebraic_numbers {
|
|||
continue;
|
||||
}
|
||||
SASSERT(m_isolate_roots.empty() && m_isolate_lowers.empty() && m_isolate_uppers.empty());
|
||||
upm().sqf_isolate_roots(f.size(), f.c_ptr(), bqm(), m_isolate_roots, m_isolate_lowers, m_isolate_uppers);
|
||||
upm().sqf_isolate_roots(f.size(), f.data(), bqm(), m_isolate_roots, m_isolate_lowers, m_isolate_uppers);
|
||||
// collect rational/basic roots
|
||||
unsigned sz = m_isolate_roots.size();
|
||||
TRACE("algebraic", tout << "isolated roots: " << sz << "\n";);
|
||||
|
@ -654,13 +654,13 @@ namespace algebraic_numbers {
|
|||
for (unsigned i = 0; i < sz; i++) {
|
||||
mpbq & lower = m_isolate_lowers[i];
|
||||
mpbq & upper = m_isolate_uppers[i];
|
||||
if (!upm().isolating2refinable(f.size(), f.c_ptr(), bqm(), lower, upper)) {
|
||||
if (!upm().isolating2refinable(f.size(), f.data(), bqm(), lower, upper)) {
|
||||
// found rational root... it is stored in lower
|
||||
to_mpq(qm(), lower, r);
|
||||
roots.push_back(numeral(mk_basic_cell(r)));
|
||||
}
|
||||
else {
|
||||
algebraic_cell * c = mk_algebraic_cell(f.size(), f.c_ptr(), lower, upper, full_fact);
|
||||
algebraic_cell * c = mk_algebraic_cell(f.size(), f.data(), lower, upper, full_fact);
|
||||
roots.push_back(numeral(c));
|
||||
}
|
||||
}
|
||||
|
@ -990,7 +990,7 @@ namespace algebraic_numbers {
|
|||
void set_core(numeral & c, scoped_upoly & p, mpbqi & r_i, upolynomial::scoped_upolynomial_sequence & seq, int lV, int uV, bool minimal) {
|
||||
TRACE("algebraic", tout << "set_core p: "; upm().display(tout, p); tout << "\n";);
|
||||
if (bqim().contains_zero(r_i)) {
|
||||
if (upm().has_zero_roots(p.size(), p.c_ptr())) {
|
||||
if (upm().has_zero_roots(p.size(), p.data())) {
|
||||
// zero is a root of p, and r_i is an isolating interval containing zero,
|
||||
// then c is zero
|
||||
reset(c);
|
||||
|
@ -1012,15 +1012,15 @@ namespace algebraic_numbers {
|
|||
|
||||
// make sure 0 is not a root of p
|
||||
scoped_upoly & nz_p = m_add_tmp;
|
||||
if (upm().has_zero_roots(p.size(), p.c_ptr())) {
|
||||
if (upm().has_zero_roots(p.size(), p.data())) {
|
||||
// remove zero root
|
||||
upm().remove_zero_roots(p.size(), p.c_ptr(), nz_p);
|
||||
upm().remove_zero_roots(p.size(), p.data(), nz_p);
|
||||
}
|
||||
else {
|
||||
p.swap(nz_p);
|
||||
}
|
||||
|
||||
if (!upm().isolating2refinable(nz_p.size(), nz_p.c_ptr(), bqm(), r_i.lower(), r_i.upper())) {
|
||||
if (!upm().isolating2refinable(nz_p.size(), nz_p.data(), bqm(), r_i.lower(), r_i.upper())) {
|
||||
// found actual root
|
||||
scoped_mpq r(qm());
|
||||
to_mpq(qm(), r_i.lower(), r);
|
||||
|
@ -1028,7 +1028,7 @@ namespace algebraic_numbers {
|
|||
}
|
||||
else {
|
||||
TRACE("algebraic", tout << "set_core...\n";);
|
||||
set(c, nz_p.size(), nz_p.c_ptr(), r_i.lower(), r_i.upper(), minimal);
|
||||
set(c, nz_p.size(), nz_p.data(), r_i.lower(), r_i.upper(), minimal);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ namespace algebraic_numbers {
|
|||
for (unsigned i = 0; i < num_fs; i++) {
|
||||
TRACE("anum_mk_binary", tout << "factor " << i << "\n"; upm().display(tout, fs[i]); tout << "\n";);
|
||||
typename upolynomial::scoped_upolynomial_sequence * seq = alloc(typename upolynomial::scoped_upolynomial_sequence, upm());
|
||||
upm().sturm_seq(fs[i].size(), fs[i].c_ptr(), *seq);
|
||||
upm().sturm_seq(fs[i].size(), fs[i].data(), *seq);
|
||||
seqs.push_back(seq);
|
||||
}
|
||||
SASSERT(seqs.size() == num_fs);
|
||||
|
@ -1114,7 +1114,7 @@ namespace algebraic_numbers {
|
|||
TRACE("anum_mk_binary", tout << "target_i: " << target_i << "\n";);
|
||||
saved_a.restore_if_too_small();
|
||||
saved_b.restore_if_too_small();
|
||||
upm().set(fs[target_i].size(), fs[target_i].c_ptr(), f);
|
||||
upm().set(fs[target_i].size(), fs[target_i].data(), f);
|
||||
set_core(c, f, r_i, *(seqs[target_i]), target_lV, target_uV, full_fact);
|
||||
return;
|
||||
}
|
||||
|
@ -1144,7 +1144,7 @@ namespace algebraic_numbers {
|
|||
scoped_ptr_vector<typename upolynomial::scoped_upolynomial_sequence> seqs;
|
||||
for (unsigned i = 0; i < num_fs; i++) {
|
||||
typename upolynomial::scoped_upolynomial_sequence * seq = alloc(typename upolynomial::scoped_upolynomial_sequence, upm());
|
||||
upm().sturm_seq(fs[i].size(), fs[i].c_ptr(), *seq);
|
||||
upm().sturm_seq(fs[i].size(), fs[i].data(), *seq);
|
||||
seqs.push_back(seq);
|
||||
}
|
||||
SASSERT(seqs.size() == num_fs);
|
||||
|
@ -1188,7 +1188,7 @@ namespace algebraic_numbers {
|
|||
if (num_rem == 1 && target_i != UINT_MAX) {
|
||||
// found isolating interval
|
||||
saved_a.restore_if_too_small();
|
||||
upm().set(fs[target_i].size(), fs[target_i].c_ptr(), f);
|
||||
upm().set(fs[target_i].size(), fs[target_i].data(), f);
|
||||
set_core(b, f, r_i, *(seqs[target_i]), target_lV, target_uV, full_fact);
|
||||
return;
|
||||
}
|
||||
|
@ -1363,10 +1363,10 @@ namespace algebraic_numbers {
|
|||
bqm().add(upper, mpz(1), upper); // make sure (a_val)^{1/k} < upper
|
||||
}
|
||||
SASSERT(bqm().lt(lower, upper));
|
||||
TRACE("algebraic", tout << "root_core:\n"; upm().display(tout, p.size(), p.c_ptr()); tout << "\n";);
|
||||
TRACE("algebraic", tout << "root_core:\n"; upm().display(tout, p.size(), p.data()); tout << "\n";);
|
||||
// p is not necessarily a minimal polynomial.
|
||||
// So, we set the m_minimal flag to false. TODO: try to factor.
|
||||
set(b, p.size(), p.c_ptr(), lower, upper, false);
|
||||
set(b, p.size(), p.data(), lower, upper, false);
|
||||
}
|
||||
|
||||
void root(numeral & a, unsigned k, numeral & b) {
|
||||
|
@ -1466,15 +1466,15 @@ namespace algebraic_numbers {
|
|||
qm().add(il, nbv, il);
|
||||
qm().add(iu, nbv, iu);
|
||||
// (il, iu) is an isolating refinable (rational) interval for the new polynomial.
|
||||
upm().convert_q2bq_interval(m_add_tmp.size(), m_add_tmp.c_ptr(), il, iu, bqm(), l, u);
|
||||
upm().convert_q2bq_interval(m_add_tmp.size(), m_add_tmp.data(), il, iu, bqm(), l, u);
|
||||
}
|
||||
TRACE("algebraic",
|
||||
upm().display(tout, m_add_tmp.size(), m_add_tmp.c_ptr());
|
||||
upm().display(tout, m_add_tmp.size(), m_add_tmp.data());
|
||||
tout << ", l: " << l << ", u: " << u << "\n";
|
||||
tout << "l_sign: " << upm().eval_sign_at(m_add_tmp.size(), m_add_tmp.c_ptr(), l) << "\n";
|
||||
tout << "u_sign: " << upm().eval_sign_at(m_add_tmp.size(), m_add_tmp.c_ptr(), u) << "\n";
|
||||
tout << "l_sign: " << upm().eval_sign_at(m_add_tmp.size(), m_add_tmp.data(), l) << "\n";
|
||||
tout << "u_sign: " << upm().eval_sign_at(m_add_tmp.size(), m_add_tmp.data(), u) << "\n";
|
||||
);
|
||||
set(c, m_add_tmp.size(), m_add_tmp.c_ptr(), l, u, a->m_minimal /* minimality is preserved */);
|
||||
set(c, m_add_tmp.size(), m_add_tmp.data(), l, u, a->m_minimal /* minimality is preserved */);
|
||||
normalize(c);
|
||||
}
|
||||
|
||||
|
@ -1550,7 +1550,7 @@ namespace algebraic_numbers {
|
|||
qm().inv(nbv);
|
||||
scoped_upoly & mulp = m_add_tmp;
|
||||
upm().set(a->m_p_sz, a->m_p, mulp);
|
||||
upm().compose_p_q_x(mulp.size(), mulp.c_ptr(), nbv);
|
||||
upm().compose_p_q_x(mulp.size(), mulp.data(), nbv);
|
||||
mpbqi const & i = a->m_interval;
|
||||
scoped_mpbq l(bqm());
|
||||
scoped_mpbq u(bqm());
|
||||
|
@ -1576,15 +1576,15 @@ namespace algebraic_numbers {
|
|||
if (is_neg)
|
||||
qm().swap(il, iu);
|
||||
// (il, iu) is an isolating refinable (rational) interval for the new polynomial.
|
||||
upm().convert_q2bq_interval(mulp.size(), mulp.c_ptr(), il, iu, bqm(), l, u);
|
||||
upm().convert_q2bq_interval(mulp.size(), mulp.data(), il, iu, bqm(), l, u);
|
||||
}
|
||||
TRACE("algebraic",
|
||||
upm().display(tout, mulp.size(), mulp.c_ptr());
|
||||
upm().display(tout, mulp.size(), mulp.data());
|
||||
tout << ", l: " << l << ", u: " << u << "\n";
|
||||
tout << "l_sign: " << upm().eval_sign_at(mulp.size(), mulp.c_ptr(), l) << "\n";
|
||||
tout << "u_sign: " << upm().eval_sign_at(mulp.size(), mulp.c_ptr(), u) << "\n";
|
||||
tout << "l_sign: " << upm().eval_sign_at(mulp.size(), mulp.data(), l) << "\n";
|
||||
tout << "u_sign: " << upm().eval_sign_at(mulp.size(), mulp.data(), u) << "\n";
|
||||
);
|
||||
set(c, mulp.size(), mulp.c_ptr(), l, u, a->m_minimal /* minimality is preserved */);
|
||||
set(c, mulp.size(), mulp.data(), l, u, a->m_minimal /* minimality is preserved */);
|
||||
normalize(c);
|
||||
}
|
||||
|
||||
|
@ -2223,7 +2223,7 @@ namespace algebraic_numbers {
|
|||
SASSERT(pm().is_univariate(R));
|
||||
scoped_upoly & _R = m_eval_sign_tmp;
|
||||
upm().to_numeral_vector(R, _R);
|
||||
unsigned k = upm().nonzero_root_lower_bound(_R.size(), _R.c_ptr());
|
||||
unsigned k = upm().nonzero_root_lower_bound(_R.size(), _R.data());
|
||||
TRACE("anum_eval_sign", tout << "R: " << R << "\nk: " << k << "\nri: "<< ri << "\n";);
|
||||
scoped_mpbq mL(bqm()), L(bqm());
|
||||
bqm().set(mL, -1);
|
||||
|
|
|
@ -917,7 +917,7 @@ namespace polynomial {
|
|||
else
|
||||
m_powers_tmp.push_back(power(x, 1));
|
||||
}
|
||||
return mk_monomial(m_powers_tmp.size(), m_powers_tmp.c_ptr());
|
||||
return mk_monomial(m_powers_tmp.size(), m_powers_tmp.data());
|
||||
}
|
||||
|
||||
monomial * mul(unsigned sz1, power const * pws1, unsigned sz2, power const * pws2) {
|
||||
|
@ -1335,8 +1335,8 @@ namespace polynomial {
|
|||
buckets[i].reset();
|
||||
}
|
||||
SASSERT(p.size() == end - start);
|
||||
apply_permutation(p.size(), m_as + start, p.c_ptr());
|
||||
apply_permutation_core(p.size(), m_ms + start, p.c_ptr()); // p is not needed anymore after this command
|
||||
apply_permutation(p.size(), m_as + start, p.data());
|
||||
apply_permutation_core(p.size(), m_ms + start, p.data()); // p is not needed anymore after this command
|
||||
i = start;
|
||||
while (i < end) {
|
||||
monomial * m = m_ms[i];
|
||||
|
@ -1878,7 +1878,7 @@ namespace polynomial {
|
|||
if (sz == 0)
|
||||
return false;
|
||||
scoped_numeral g(m);
|
||||
m.gcd(as.size(), as.c_ptr(), g);
|
||||
m.gcd(as.size(), as.data(), g);
|
||||
if (m.is_one(g))
|
||||
return false;
|
||||
SASSERT(m.is_pos(g));
|
||||
|
@ -2152,7 +2152,7 @@ namespace polynomial {
|
|||
|
||||
polynomial * mk(bool normalize = false) {
|
||||
remove_zeros(normalize);
|
||||
polynomial * p = m_owner->mk_polynomial_core(m_tmp_as.size(), m_tmp_as.c_ptr(), m_tmp_ms.c_ptr());
|
||||
polynomial * p = m_owner->mk_polynomial_core(m_tmp_as.size(), m_tmp_as.data(), m_tmp_ms.data());
|
||||
m_tmp_as.reset();
|
||||
m_tmp_ms.reset();
|
||||
return p;
|
||||
|
@ -2312,7 +2312,7 @@ namespace polynomial {
|
|||
}
|
||||
|
||||
polynomial * mk() {
|
||||
polynomial * new_p = m_owner->mk_polynomial_core(m_tmp_as.size(), m_tmp_as.c_ptr(), m_tmp_ms.c_ptr());
|
||||
polynomial * new_p = m_owner->mk_polynomial_core(m_tmp_as.size(), m_tmp_as.data(), m_tmp_ms.data());
|
||||
m_tmp_as.reset();
|
||||
m_tmp_ms.reset();
|
||||
return new_p;
|
||||
|
@ -2614,7 +2614,7 @@ namespace polynomial {
|
|||
|
||||
polynomial * mk_polynomial(unsigned sz, rational const * as, monomial * const * ms) {
|
||||
rational2numeral(sz, as);
|
||||
polynomial * p = mk_polynomial(sz, m_rat2numeral.c_ptr(), ms);
|
||||
polynomial * p = mk_polynomial(sz, m_rat2numeral.data(), ms);
|
||||
reset_tmp_as2();
|
||||
return p;
|
||||
}
|
||||
|
@ -2636,7 +2636,7 @@ namespace polynomial {
|
|||
polynomial * mk_univariate(var x, unsigned n, rational const * as) {
|
||||
SASSERT(is_valid(x));
|
||||
rational2numeral(n+1, as);
|
||||
polynomial * p = mk_univariate(x, n, m_rat2numeral.c_ptr());
|
||||
polynomial * p = mk_univariate(x, n, m_rat2numeral.data());
|
||||
reset_tmp_as2();
|
||||
return p;
|
||||
}
|
||||
|
@ -2656,7 +2656,7 @@ namespace polynomial {
|
|||
swap(m_tmp_linear_as.back(), c);
|
||||
m_tmp_linear_ms.push_back(mk_unit());
|
||||
}
|
||||
polynomial * p = mk_polynomial(m_tmp_linear_as.size(), m_tmp_linear_as.c_ptr(), m_tmp_linear_ms.c_ptr());
|
||||
polynomial * p = mk_polynomial(m_tmp_linear_as.size(), m_tmp_linear_as.data(), m_tmp_linear_ms.data());
|
||||
for (auto& a : m_tmp_linear_as) {
|
||||
m_manager.del(a);
|
||||
}
|
||||
|
@ -2670,7 +2670,7 @@ namespace polynomial {
|
|||
rational2numeral(sz, as);
|
||||
numeral tmp_c;
|
||||
m_manager.set(tmp_c, c.to_mpq().numerator());
|
||||
polynomial * p = mk_linear(sz, m_rat2numeral.c_ptr(), xs, tmp_c);
|
||||
polynomial * p = mk_linear(sz, m_rat2numeral.data(), xs, tmp_c);
|
||||
SASSERT(m_manager.is_zero(tmp_c));
|
||||
reset_tmp_as2();
|
||||
return p;
|
||||
|
@ -3202,7 +3202,7 @@ namespace polynomial {
|
|||
tout << m.to_string(cs[i]) << " ";
|
||||
}
|
||||
tout << "\n";);
|
||||
solver.add(i, cs.c_ptr(), m_outputs[output_idx]);
|
||||
solver.add(i, cs.data(), m_outputs[output_idx]);
|
||||
}
|
||||
TRACE("sparse_interpolator",
|
||||
tout << "find coefficients of:\n";
|
||||
|
@ -3211,7 +3211,7 @@ namespace polynomial {
|
|||
}
|
||||
tout << "system of equations:\n";
|
||||
solver.display(tout););
|
||||
if (!solver.solve(new_as.c_ptr()))
|
||||
if (!solver.solve(new_as.data()))
|
||||
return false;
|
||||
for (unsigned i = 0; i < num_pws; i++) {
|
||||
if (!m.is_zero(new_as[i])) {
|
||||
|
@ -3220,7 +3220,7 @@ namespace polynomial {
|
|||
}
|
||||
}
|
||||
}
|
||||
r = m_skeleton->pm.mk_polynomial(as.size(), as.c_ptr(), mons.c_ptr());
|
||||
r = m_skeleton->pm.mk_polynomial(as.size(), as.data(), mons.data());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -4737,7 +4737,7 @@ namespace polynomial {
|
|||
push_power(pws, y, n - k);
|
||||
push_power(pws, x, k);
|
||||
}
|
||||
monomial * new_m = mk_monomial(pws.size(), pws.c_ptr());
|
||||
monomial * new_m = mk_monomial(pws.size(), pws.data());
|
||||
m_cheap_som_buffer.add(p->a(i), new_m);
|
||||
}
|
||||
return m_cheap_som_buffer.mk();
|
||||
|
@ -5668,7 +5668,7 @@ namespace polynomial {
|
|||
h1 = exact_div(h1, hs0);
|
||||
S.push_back(h1);
|
||||
if (is_zero(G2)) {
|
||||
std::reverse(S.c_ptr(), S.c_ptr() + S.size());
|
||||
std::reverse(S.data(), S.data() + S.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -5855,7 +5855,7 @@ namespace polynomial {
|
|||
psc_chain_optimized_core(Q, P, x, S);
|
||||
if (S.empty())
|
||||
S.push_back(mk_zero());
|
||||
std::reverse(S.c_ptr(), S.c_ptr() + S.size());
|
||||
std::reverse(S.data(), S.data() + S.size());
|
||||
}
|
||||
|
||||
void psc_chain_classic_core(polynomial const * P, polynomial const * Q, var x, polynomial_ref_vector & S) {
|
||||
|
@ -5935,7 +5935,7 @@ namespace polynomial {
|
|||
psc_chain_classic_core(Q, P, x, S);
|
||||
if (S.empty())
|
||||
S.push_back(mk_zero());
|
||||
std::reverse(S.c_ptr(), S.c_ptr() + S.size());
|
||||
std::reverse(S.data(), S.data() + S.size());
|
||||
}
|
||||
|
||||
void psc_chain(polynomial const * A, polynomial const * B, var x, polynomial_ref_vector & S) {
|
||||
|
@ -6253,7 +6253,7 @@ namespace polynomial {
|
|||
|
||||
unsigned num_vars() const { return m_xs.size(); }
|
||||
|
||||
var const * vars() const { return m_xs.c_ptr(); }
|
||||
var const * vars() const { return m_xs.data(); }
|
||||
};
|
||||
|
||||
struct scoped_var_max_degree {
|
||||
|
@ -6752,7 +6752,7 @@ namespace polynomial {
|
|||
for (unsigned i = 0; i < num_factors; i++) {
|
||||
numeral_vector const & f1 = fs[i];
|
||||
unsigned k1 = fs.get_degree(i);
|
||||
f = to_polynomial(f1.size(), f1.c_ptr(), x);
|
||||
f = to_polynomial(f1.size(), f1.data(), x);
|
||||
TRACE("factor_bug",
|
||||
tout << "uni-factor:\n"; upm().display(tout, f1); tout << "\n";
|
||||
tout << "factor:\n" << f << "\n";);
|
||||
|
@ -6878,7 +6878,7 @@ namespace polynomial {
|
|||
coeffs.push_back(numeral());
|
||||
m_manager.set(coeffs.back(), p[i]);
|
||||
}
|
||||
return mk_univariate(x, sz-1, coeffs.c_ptr());
|
||||
return mk_univariate(x, sz-1, coeffs.data());
|
||||
}
|
||||
|
||||
polynomial * mk_glex_monic(polynomial const * p) {
|
||||
|
@ -7510,7 +7510,7 @@ polynomial::polynomial * convert(polynomial::manager & sm, polynomial::polynomia
|
|||
}
|
||||
}
|
||||
}
|
||||
return tm.mk_polynomial(as.size(), as.c_ptr(), ms.c_ptr());
|
||||
return tm.mk_polynomial(as.size(), as.data(), ms.data());
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, polynomial_ref_vector const & seq) {
|
||||
|
|
|
@ -981,7 +981,7 @@ namespace polynomial {
|
|||
*/
|
||||
polynomial * to_polynomial(unsigned sz, numeral const * p, var x);
|
||||
polynomial * to_polynomial(numeral_vector const & p, var x) {
|
||||
return to_polynomial(p.size(), p.c_ptr(), x);
|
||||
return to_polynomial(p.size(), p.data(), x);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1003,7 +1003,7 @@ namespace polynomial {
|
|||
void translate(polynomial const * p, unsigned xs_sz, var const * xs, numeral const * vs, polynomial_ref & r);
|
||||
void translate(polynomial const * p, var_vector const & xs, numeral_vector const & vs, polynomial_ref & r) {
|
||||
SASSERT(xs.size() == vs.size());
|
||||
translate(p, xs.size(), xs.c_ptr(), vs.c_ptr(), r);
|
||||
translate(p, xs.size(), xs.data(), vs.data(), r);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -318,7 +318,7 @@ namespace rpolynomial {
|
|||
numeral * new_arg = mk_numeral();
|
||||
m_manager.set(*new_arg, 1);
|
||||
new_args.push_back(to_poly_or_num(new_arg));
|
||||
return mk_poly(new_args.size(), new_args.c_ptr(), x);
|
||||
return mk_poly(new_args.size(), new_args.data(), x);
|
||||
}
|
||||
|
||||
poly_or_num * unpack(polynomial const * p) {
|
||||
|
@ -361,7 +361,7 @@ namespace rpolynomial {
|
|||
for (unsigned i = 0; i < sz; i++) {
|
||||
new_args.push_back(mul_core(c, _p->arg(i)));
|
||||
}
|
||||
return mk_poly_core(new_args.size(), new_args.c_ptr(), _p->max_var());
|
||||
return mk_poly_core(new_args.size(), new_args.data(), _p->max_var());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ namespace rpolynomial {
|
|||
new_args.push_back(add_core(c, _p->arg(0)));
|
||||
for (unsigned i = 1; i < sz; i++)
|
||||
new_args.push_back(_p->arg(1));
|
||||
return mk_poly_core(new_args.size(), new_args.c_ptr(), _p->max_var());
|
||||
return mk_poly_core(new_args.size(), new_args.data(), _p->max_var());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ void sexpr2upolynomial(upolynomial::manager & m, sexpr const * s, upolynomial::n
|
|||
for (unsigned i = 2; i < num; i++) {
|
||||
m.reset(arg);
|
||||
sexpr2upolynomial(m, s->get_child(i), arg, depth+1);
|
||||
m.add(arg.size(), arg.c_ptr(), p.size(), p.c_ptr(), p);
|
||||
m.add(arg.size(), arg.data(), p.size(), p.data(), p);
|
||||
}
|
||||
}
|
||||
else if (op == "-") {
|
||||
|
@ -60,7 +60,7 @@ void sexpr2upolynomial(upolynomial::manager & m, sexpr const * s, upolynomial::n
|
|||
for (unsigned i = 2; i < num; i++) {
|
||||
m.reset(arg);
|
||||
sexpr2upolynomial(m, s->get_child(i), arg, depth+1);
|
||||
m.sub(p.size(), p.c_ptr(), arg.size(), arg.c_ptr(), p);
|
||||
m.sub(p.size(), p.data(), arg.size(), arg.data(), p);
|
||||
}
|
||||
}
|
||||
else if (op == "*") {
|
||||
|
@ -71,7 +71,7 @@ void sexpr2upolynomial(upolynomial::manager & m, sexpr const * s, upolynomial::n
|
|||
for (unsigned i = 2; i < num; i++) {
|
||||
m.reset(arg);
|
||||
sexpr2upolynomial(m, s->get_child(i), arg, depth+1);
|
||||
m.mul(arg.size(), arg.c_ptr(), p.size(), p.c_ptr(), p);
|
||||
m.mul(arg.size(), arg.data(), p.size(), p.data(), p);
|
||||
}
|
||||
}
|
||||
else if (op == "^") {
|
||||
|
@ -82,7 +82,7 @@ void sexpr2upolynomial(upolynomial::manager & m, sexpr const * s, upolynomial::n
|
|||
if (!arg2->is_numeral() || !arg2->get_numeral().is_unsigned())
|
||||
throw sexpr2upolynomial_exception("invalid univariate polynomial, exponent must be an unsigned integer", arg2);
|
||||
unsigned k = arg2->get_numeral().get_unsigned();
|
||||
m.pw(p.size(), p.c_ptr(), k, p);
|
||||
m.pw(p.size(), p.data(), k, p);
|
||||
}
|
||||
else {
|
||||
throw sexpr2upolynomial_exception("invalid univariate polynomial, '+', '-', '^' or '*' expected", s);
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace upolynomial {
|
|||
SASSERT(degree > 0);
|
||||
m_factors.push_back(numeral_vector());
|
||||
m_degrees.push_back(degree);
|
||||
m_upm.set(p.size(), p.c_ptr(), m_factors.back());
|
||||
m_upm.set(p.size(), p.data(), m_factors.back());
|
||||
m_total_factors += degree;
|
||||
m_total_degree += m_upm.degree(p)*degree;
|
||||
}
|
||||
|
@ -84,11 +84,11 @@ namespace upolynomial {
|
|||
for (unsigned i = 0; i < m_factors.size(); ++ i) {
|
||||
if (m_degrees[i] > 1) {
|
||||
numeral_vector power;
|
||||
m_upm.pw(m_factors[i].size(), m_factors[i].c_ptr(), m_degrees[i], power);
|
||||
m_upm.mul(out.size(), out.c_ptr(), power.size(), power.c_ptr(), out);
|
||||
m_upm.pw(m_factors[i].size(), m_factors[i].data(), m_degrees[i], power);
|
||||
m_upm.mul(out.size(), out.data(), power.size(), power.data(), out);
|
||||
m_upm.reset(power);
|
||||
} else {
|
||||
m_upm.mul(out.size(), out.c_ptr(), m_factors[i].size(), m_factors[i].c_ptr(), out);
|
||||
m_upm.mul(out.size(), out.data(), m_factors[i].size(), m_factors[i].data(), out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ namespace upolynomial {
|
|||
|
||||
// Copy elements from p to buffer.
|
||||
void core_manager::set(unsigned sz, numeral const * p, numeral_vector & buffer) {
|
||||
if (p != nullptr && buffer.c_ptr() == p) {
|
||||
if (p != nullptr && buffer.data() == p) {
|
||||
SASSERT(buffer.size() == sz);
|
||||
return;
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ namespace upolynomial {
|
|||
|
||||
// Divide coefficients of p by their GCD
|
||||
void core_manager::normalize(numeral_vector & p) {
|
||||
normalize(p.size(), p.c_ptr());
|
||||
normalize(p.size(), p.data());
|
||||
}
|
||||
|
||||
void core_manager::div(unsigned sz, numeral * p, numeral const & b) {
|
||||
|
@ -423,7 +423,7 @@ namespace upolynomial {
|
|||
reset(p);
|
||||
return;
|
||||
}
|
||||
mul(p.size(), p.c_ptr(), b);
|
||||
mul(p.size(), p.data(), b);
|
||||
}
|
||||
|
||||
// Pseudo division
|
||||
|
@ -568,7 +568,7 @@ namespace upolynomial {
|
|||
rem(sz1, p1, sz2, p2, d, buffer);
|
||||
// We don't need to flip the sign if d is odd and leading coefficient of p2 is negative
|
||||
if (d % 2 == 0 || (sz2 > 0 && m().is_pos(p2[sz2-1])))
|
||||
neg(buffer.size(), buffer.c_ptr());
|
||||
neg(buffer.size(), buffer.data());
|
||||
}
|
||||
|
||||
|
||||
|
@ -619,7 +619,7 @@ namespace upolynomial {
|
|||
_r.reserve(deg+1);
|
||||
numeral_vector & _p1 = m_div_tmp1;
|
||||
// std::cerr << "dividing with "; display(std::cerr, _p1); std::cerr << std::endl;
|
||||
TRACE("factor_bug", tout << "sz1: " << sz1 << " p1: " << p1 << ", _p1.c_ptr(): " << _p1.c_ptr() << ", _p1.size(): " << _p1.size() << "\n";);
|
||||
TRACE("factor_bug", tout << "sz1: " << sz1 << " p1: " << p1 << ", _p1.c_ptr(): " << _p1.data() << ", _p1.size(): " << _p1.size() << "\n";);
|
||||
set(sz1, p1, _p1);
|
||||
SASSERT(_p1.size() == sz1);
|
||||
while (true) {
|
||||
|
@ -750,8 +750,8 @@ namespace upolynomial {
|
|||
TRACE("mgcd", tout << "trying prime: " << p << "\n";);
|
||||
{
|
||||
scoped_set_zp setZp(*this, p);
|
||||
set(pp_u.size(), pp_u.c_ptr(), u_Zp);
|
||||
set(pp_v.size(), pp_v.c_ptr(), v_Zp);
|
||||
set(pp_u.size(), pp_u.data(), u_Zp);
|
||||
set(pp_v.size(), pp_v.data(), v_Zp);
|
||||
if (degree(u_Zp) < d_u) {
|
||||
TRACE("mgcd", tout << "bad prime, leading coefficient vanished\n";);
|
||||
continue; // bad prime
|
||||
|
@ -760,9 +760,9 @@ namespace upolynomial {
|
|||
TRACE("mgcd", tout << "bad prime, leading coefficient vanished\n";);
|
||||
continue; // bad prime
|
||||
}
|
||||
euclid_gcd(u_Zp.size(), u_Zp.c_ptr(), v_Zp.size(), v_Zp.c_ptr(), q);
|
||||
euclid_gcd(u_Zp.size(), u_Zp.data(), v_Zp.size(), v_Zp.data(), q);
|
||||
// normalize so that lc_g is leading coefficient of q
|
||||
mk_monic(q.size(), q.c_ptr());
|
||||
mk_monic(q.size(), q.data());
|
||||
scoped_numeral c(m());
|
||||
m().set(c, lc_g);
|
||||
mul(q, c);
|
||||
|
@ -776,13 +776,13 @@ namespace upolynomial {
|
|||
return;
|
||||
}
|
||||
if (i == 0) {
|
||||
set(q.size(), q.c_ptr(), C);
|
||||
set(q.size(), q.data(), C);
|
||||
m().set(bound, p);
|
||||
}
|
||||
else if (q.size() < C.size() || m().m().is_even(p) || m().m().is_even(bound)) {
|
||||
// discard accumulated image, it was affected by unlucky primes
|
||||
TRACE("mgcd", tout << "discarding image\n";);
|
||||
set(q.size(), q.c_ptr(), C);
|
||||
set(q.size(), q.data(), C);
|
||||
m().set(bound, p);
|
||||
}
|
||||
else {
|
||||
|
@ -829,7 +829,7 @@ namespace upolynomial {
|
|||
set(sz1, p1, A);
|
||||
set(sz2, p2, B);
|
||||
TRACE("upolynomial", tout << "sz1: " << sz1 << ", p1: " << p1 << ", sz2: " << sz2 << ", p2: " << p2 << "\nB.size(): " << B.size() <<
|
||||
", B.c_ptr(): " << B.c_ptr() << "\n";);
|
||||
", B.c_ptr(): " << B.data() << "\n";);
|
||||
while (m_limit.inc()) {
|
||||
TRACE("upolynomial", tout << "A: "; display(tout, A); tout <<"\nB: "; display(tout, B); tout << "\n";);
|
||||
if (B.empty()) {
|
||||
|
@ -837,7 +837,7 @@ namespace upolynomial {
|
|||
buffer.swap(A);
|
||||
// to be consistent, if in a field, we make gcd monic
|
||||
if (is_field) {
|
||||
mk_monic(buffer.size(), buffer.c_ptr());
|
||||
mk_monic(buffer.size(), buffer.data());
|
||||
}
|
||||
else {
|
||||
flip_sign_if_lm_neg(buffer);
|
||||
|
@ -846,7 +846,7 @@ namespace upolynomial {
|
|||
display(tout, buffer); tout << "\n";);
|
||||
return;
|
||||
}
|
||||
rem(A.size(), A.c_ptr(), B.size(), B.c_ptr(), R);
|
||||
rem(A.size(), A.data(), B.size(), B.data(), R);
|
||||
normalize(R);
|
||||
A.swap(B);
|
||||
B.swap(R);
|
||||
|
@ -906,7 +906,7 @@ namespace upolynomial {
|
|||
buffer.swap(A);
|
||||
// to be consistent, if in a field, we make gcd monic
|
||||
if (field()) {
|
||||
mk_monic(buffer.size(), buffer.c_ptr());
|
||||
mk_monic(buffer.size(), buffer.data());
|
||||
}
|
||||
else {
|
||||
flip_sign_if_lm_neg(buffer);
|
||||
|
@ -915,7 +915,7 @@ namespace upolynomial {
|
|||
display(tout, buffer); tout << "\n";);
|
||||
return;
|
||||
}
|
||||
rem(A.size(), A.c_ptr(), B.size(), B.c_ptr(), d, R);
|
||||
rem(A.size(), A.data(), B.size(), B.data(), d, R);
|
||||
unsigned pseudo_div_d = A.size() - B.size();
|
||||
if (d < pseudo_div_d + 1) {
|
||||
// I used a standard subresultant implementation.
|
||||
|
@ -967,13 +967,13 @@ namespace upolynomial {
|
|||
numeral_vector & p_prime = m_sqf_tmp1;
|
||||
numeral_vector & g = m_sqf_tmp2;
|
||||
derivative(sz, p, p_prime);
|
||||
gcd(sz, p, p_prime.size(), p_prime.c_ptr(), g);
|
||||
gcd(sz, p, p_prime.size(), p_prime.data(), g);
|
||||
// subresultant_gcd(sz, p, p_prime.size(), p_prime.c_ptr(), g);
|
||||
if (g.size() <= 1) {
|
||||
set(sz, p, buffer);
|
||||
}
|
||||
else {
|
||||
div(sz, p, g.size(), g.c_ptr(), buffer);
|
||||
div(sz, p, g.size(), g.data(), buffer);
|
||||
normalize(buffer);
|
||||
}
|
||||
}
|
||||
|
@ -985,7 +985,7 @@ namespace upolynomial {
|
|||
numeral_vector & p_prime = m_sqf_tmp1;
|
||||
numeral_vector & g = m_sqf_tmp2;
|
||||
derivative(sz, p, p_prime);
|
||||
gcd(sz, p, p_prime.size(), p_prime.c_ptr(), g);
|
||||
gcd(sz, p, p_prime.size(), p_prime.data(), g);
|
||||
return g.size() <= 1;
|
||||
}
|
||||
|
||||
|
@ -1006,7 +1006,7 @@ namespace upolynomial {
|
|||
numeral_vector & result = m_pw_tmp;
|
||||
set(sz, p, result);
|
||||
for (unsigned i = 1; i < k; i++)
|
||||
mul(m_pw_tmp.size(), m_pw_tmp.c_ptr(), sz, p, m_pw_tmp);
|
||||
mul(m_pw_tmp.size(), m_pw_tmp.data(), sz, p, m_pw_tmp);
|
||||
r.swap(result);
|
||||
#if 0
|
||||
unsigned mask = 1;
|
||||
|
@ -1057,7 +1057,7 @@ namespace upolynomial {
|
|||
reset(U); U.push_back(numeral()); m().set(U.back(), 1);
|
||||
// D <- A
|
||||
set(szA, A, D);
|
||||
mk_monic(szA, D.c_ptr());
|
||||
mk_monic(szA, D.data());
|
||||
// V1 <- 0
|
||||
reset(V1);
|
||||
// V3 <- B
|
||||
|
@ -1069,30 +1069,30 @@ namespace upolynomial {
|
|||
numeral_vector & AU = V1;
|
||||
numeral_vector & D_AU = V3;
|
||||
// V <- (D - AU)/B
|
||||
mul(szA, A, U.size(), U.c_ptr(), AU);
|
||||
sub(D.size(), D.c_ptr(), AU.size(), AU.c_ptr(), D_AU);
|
||||
div(D_AU.size(), D_AU.c_ptr(), szB, B, V);
|
||||
mul(szA, A, U.size(), U.data(), AU);
|
||||
sub(D.size(), D.data(), AU.size(), AU.data(), D_AU);
|
||||
div(D_AU.size(), D_AU.data(), szB, B, V);
|
||||
DEBUG_CODE({
|
||||
scoped_numeral_vector BV(m());
|
||||
scoped_numeral_vector expected_D(m());
|
||||
mul(szB, B, V.size(), V.c_ptr(), BV);
|
||||
add(AU.size(), AU.c_ptr(), BV.size(), BV.c_ptr(), expected_D);
|
||||
mul(szB, B, V.size(), V.data(), BV);
|
||||
add(AU.size(), AU.data(), BV.size(), BV.data(), expected_D);
|
||||
SASSERT(eq(expected_D, D));
|
||||
});
|
||||
// if D is not monic, make it monic
|
||||
scoped_numeral lc_inv(m()), lc(m());
|
||||
mk_monic(D.size(), D.c_ptr(), lc, lc_inv);
|
||||
mk_monic(D.size(), D.data(), lc, lc_inv);
|
||||
mul(U, lc_inv);
|
||||
mul(V, lc_inv);
|
||||
return;
|
||||
}
|
||||
|
||||
// D = QV3 + R
|
||||
div_rem(D.size(), D.c_ptr(), V3.size(), V3.c_ptr(), Q, R);
|
||||
div_rem(D.size(), D.data(), V3.size(), V3.data(), Q, R);
|
||||
|
||||
// T <- U - V1Q
|
||||
mul(V1.size(), V1.c_ptr(), Q.size(), Q.c_ptr(), V1Q);
|
||||
sub(U.size(), U.c_ptr(), V1Q.size(), V1Q.c_ptr(), T);
|
||||
mul(V1.size(), V1.data(), Q.size(), Q.data(), V1Q);
|
||||
sub(U.size(), U.data(), V1Q.size(), V1Q.data(), T);
|
||||
// U <- V1
|
||||
U.swap(V1);
|
||||
// D <- V3
|
||||
|
@ -1413,21 +1413,21 @@ namespace upolynomial {
|
|||
TRACE("upolynomial", tout << "after translation\n"; display(tout, p_aux); tout << "\n";);
|
||||
scoped_mpbq b_a(bqm);
|
||||
bqm.sub(b, a, b_a);
|
||||
compose_p_b_x(p_aux.size(), p_aux.c_ptr(), b_a);
|
||||
compose_p_b_x(p_aux.size(), p_aux.data(), b_a);
|
||||
TRACE("upolynomial", tout << "after composition: " << bqm.to_string(b_a) << "\n"; display(tout, p_aux); tout << "\n";);
|
||||
unsigned result = descartes_bound_0_1(p_aux.size(), p_aux.c_ptr());
|
||||
unsigned result = descartes_bound_0_1(p_aux.size(), p_aux.data());
|
||||
return result;
|
||||
}
|
||||
else if (bqm.is_nonpos(b)) {
|
||||
// Basic idea: apply descartes_bound_a_b to p(-x) with intervals (-b, -a)
|
||||
numeral_vector & p_aux = m_dbab_tmp2;
|
||||
set(sz, p, p_aux);
|
||||
p_minus_x(p_aux.size(), p_aux.c_ptr());
|
||||
p_minus_x(p_aux.size(), p_aux.data());
|
||||
scoped_mpbq mb(bqm);
|
||||
scoped_mpbq ma(bqm);
|
||||
bqm.set(mb, b); bqm.neg(mb);
|
||||
bqm.set(ma, a); bqm.neg(ma);
|
||||
unsigned result = descartes_bound_a_b(p_aux.size(), p_aux.c_ptr(), bqm, mb, ma);
|
||||
unsigned result = descartes_bound_a_b(p_aux.size(), p_aux.data(), bqm, mb, ma);
|
||||
return result;
|
||||
}
|
||||
else if (!has_zero_roots(sz, p)) {
|
||||
|
@ -2118,7 +2118,7 @@ namespace upolynomial {
|
|||
|
||||
// left child
|
||||
set(sz, p, p_aux);
|
||||
compose_2n_p_x_div_2(p_aux.size(), p_aux.c_ptr());
|
||||
compose_2n_p_x_div_2(p_aux.size(), p_aux.data());
|
||||
normalize(p_aux);
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
p_stack.push_back(numeral());
|
||||
|
@ -2215,7 +2215,7 @@ namespace upolynomial {
|
|||
TRACE("upolynomial", tout << "polynomial has a 1/2 root\n";);
|
||||
roots.push_back(mpbq(1, 1));
|
||||
remove_one_half_root(sz, p, q);
|
||||
push_child_frames(q.size(), q.c_ptr(), p_stack, frame_stack);
|
||||
push_child_frames(q.size(), q.data(), p_stack, frame_stack);
|
||||
}
|
||||
else {
|
||||
push_child_frames(sz, p, p_stack, frame_stack);
|
||||
|
@ -2253,7 +2253,7 @@ namespace upolynomial {
|
|||
TRACE("upolynomial", tout << "1/2 is a root\n";);
|
||||
add_root(frame_stack, bqm, roots);
|
||||
remove_one_half_root(sz, p, q);
|
||||
push_child_frames(q.size(), q.c_ptr(), p_stack, frame_stack);
|
||||
push_child_frames(q.size(), q.data(), p_stack, frame_stack);
|
||||
}
|
||||
else {
|
||||
push_child_frames(sz, p, p_stack, frame_stack);
|
||||
|
@ -2291,14 +2291,14 @@ namespace upolynomial {
|
|||
scoped_numeral_vector aux_p(m());
|
||||
set(sz, p, aux_p);
|
||||
pos_k = std::max(neg_k, pos_k);
|
||||
compose_p_2k_x(sz, aux_p.c_ptr(), pos_k);
|
||||
compose_p_2k_x(sz, aux_p.data(), pos_k);
|
||||
|
||||
// p(x) := p(2^{pos_k} * x)
|
||||
// Since the desired positive roots of p(x) are in (0, 2^pos_k),
|
||||
TRACE("upolynomial", tout << "searching at (0, 1)\n";);
|
||||
unsigned old_roots_sz = roots.size();
|
||||
unsigned old_lowers_sz = lowers.size();
|
||||
drs_isolate_0_1_roots(sz, aux_p.c_ptr(), bqm, roots, lowers, uppers);
|
||||
drs_isolate_0_1_roots(sz, aux_p.data(), bqm, roots, lowers, uppers);
|
||||
SASSERT(lowers.size() == uppers.size());
|
||||
adjust_pos(bqm, roots, old_roots_sz, pos_k);
|
||||
adjust_pos(bqm, lowers, old_lowers_sz, pos_k);
|
||||
|
@ -2330,7 +2330,7 @@ namespace upolynomial {
|
|||
|
||||
TRACE("upolynomial",
|
||||
scoped_numeral U(m());
|
||||
root_upper_bound(p1.size(), p1.c_ptr(), U);
|
||||
root_upper_bound(p1.size(), p1.data(), U);
|
||||
unsigned U_k = m().log2(U) + 1;
|
||||
tout << "Cauchy U: 2^" << U_k << "\n";
|
||||
tout << "Knuth pos U: 2^" << knuth_positive_root_upper_bound(sz, p) << "\n";
|
||||
|
@ -2345,7 +2345,7 @@ namespace upolynomial {
|
|||
unsigned pos_k = m().log2(U) + 1;
|
||||
unsigned neg_k = pos_k;
|
||||
#endif
|
||||
drs_isolate_roots(p1.size(), p1.c_ptr(), neg_k, pos_k, bqm, roots, lowers, uppers);
|
||||
drs_isolate_roots(p1.size(), p1.data(), neg_k, pos_k, bqm, roots, lowers, uppers);
|
||||
}
|
||||
|
||||
// Frame for root isolation in sturm_isolate_roots.
|
||||
|
@ -2477,7 +2477,7 @@ namespace upolynomial {
|
|||
unsigned pos_k = m().log2(U) + 1;
|
||||
unsigned neg_k = pos_k;
|
||||
#endif
|
||||
sturm_isolate_roots_core(p1.size(), p1.c_ptr(), neg_k, pos_k, bqm, roots, lowers, uppers);
|
||||
sturm_isolate_roots_core(p1.size(), p1.data(), neg_k, pos_k, bqm, roots, lowers, uppers);
|
||||
}
|
||||
|
||||
// Isolate roots of a square free polynomial that does not have zero roots
|
||||
|
@ -2496,8 +2496,8 @@ namespace upolynomial {
|
|||
scoped_numeral_vector nz_p(m());
|
||||
remove_zero_roots(sz, p, nz_p);
|
||||
TRACE("upolynomial", tout << "after removing zero root:\n"; display(tout, nz_p); tout << "\n";);
|
||||
SASSERT(!has_zero_roots(nz_p.size(), nz_p.c_ptr()));
|
||||
sqf_nz_isolate_roots(nz_p.size(), nz_p.c_ptr(), bqm, roots, lowers, uppers);
|
||||
SASSERT(!has_zero_roots(nz_p.size(), nz_p.data()));
|
||||
sqf_nz_isolate_roots(nz_p.size(), nz_p.data(), bqm, roots, lowers, uppers);
|
||||
}
|
||||
else {
|
||||
sqf_nz_isolate_roots(sz, p, bqm, roots, lowers, uppers);
|
||||
|
@ -2510,7 +2510,7 @@ namespace upolynomial {
|
|||
scoped_numeral_vector sqf_p(m());
|
||||
square_free(sz, p, sqf_p);
|
||||
TRACE("upolynomial", tout << "square free part:\n"; display(tout, sqf_p); tout << "\n";);
|
||||
sqf_isolate_roots(sqf_p.size(), sqf_p.c_ptr(), bqm, roots, lowers, uppers);
|
||||
sqf_isolate_roots(sqf_p.size(), sqf_p.data(), bqm, roots, lowers, uppers);
|
||||
}
|
||||
|
||||
// Keep expanding the Sturm sequence starting at seq
|
||||
|
@ -2522,7 +2522,7 @@ namespace upolynomial {
|
|||
if (is_zero(r))
|
||||
return;
|
||||
normalize(r);
|
||||
seq.push(r.size(), r.c_ptr());
|
||||
seq.push(r.size(), r.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2538,7 +2538,7 @@ namespace upolynomial {
|
|||
scoped_numeral_vector p_prime(m());
|
||||
seq.push(m(), sz, p);
|
||||
derivative(sz, p, p_prime);
|
||||
seq.push(p_prime.size(), p_prime.c_ptr());
|
||||
seq.push(p_prime.size(), p_prime.data());
|
||||
sturm_seq_core(seq);
|
||||
}
|
||||
|
||||
|
@ -2547,8 +2547,8 @@ namespace upolynomial {
|
|||
scoped_numeral_vector p1p2(m());
|
||||
seq.push(m(), sz1, p1);
|
||||
derivative(sz1, p1, p1p2);
|
||||
mul(p1p2.size(), p1p2.c_ptr(), sz2, p2, p1p2);
|
||||
seq.push(p1p2.size(), p1p2.c_ptr());
|
||||
mul(p1p2.size(), p1p2.data(), sz2, p2, p1p2);
|
||||
seq.push(p1p2.size(), p1p2.data());
|
||||
sturm_seq_core(seq);
|
||||
}
|
||||
|
||||
|
@ -2563,7 +2563,7 @@ namespace upolynomial {
|
|||
unsigned sz = seq.size();
|
||||
derivative(seq.size(sz-1), seq.coeffs(sz-1), p_prime);
|
||||
normalize(p_prime);
|
||||
seq.push(p_prime.size(), p_prime.c_ptr());
|
||||
seq.push(p_prime.size(), p_prime.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace upolynomial {
|
|||
numeral_vector m_sqf_tmp2;
|
||||
numeral_vector m_pw_tmp;
|
||||
|
||||
static bool is_alias(numeral const * p, numeral_vector & buffer) { return buffer.c_ptr() != nullptr && buffer.c_ptr() == p; }
|
||||
static bool is_alias(numeral const * p, numeral_vector & buffer) { return buffer.data() != nullptr && buffer.data() == p; }
|
||||
void neg_core(unsigned sz1, numeral const * p1, numeral_vector & buffer);
|
||||
void add_core(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & buffer);
|
||||
void sub_core(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & buffer);
|
||||
|
@ -192,7 +192,7 @@ namespace upolynomial {
|
|||
\brief Copy p to buffer.
|
||||
*/
|
||||
void set(unsigned sz, numeral const * p, numeral_vector & buffer);
|
||||
void set(numeral_vector & target, numeral_vector const & source) { set(source.size(), source.c_ptr(), target); }
|
||||
void set(numeral_vector & target, numeral_vector const & source) { set(source.size(), source.data(), target); }
|
||||
|
||||
/**
|
||||
\brief Copy p to buffer.
|
||||
|
@ -206,42 +206,42 @@ namespace upolynomial {
|
|||
*/
|
||||
void get_primitive_and_content(unsigned f_sz, numeral const * f, numeral_vector & pp, numeral & cont);
|
||||
void get_primitive_and_content(numeral_vector const & f, numeral_vector & pp, numeral & cont) {
|
||||
get_primitive_and_content(f.size(), f.c_ptr(), pp, cont);
|
||||
get_primitive_and_content(f.size(), f.data(), pp, cont);
|
||||
}
|
||||
void get_primitive(numeral_vector const & f, numeral_vector & pp) {
|
||||
scoped_numeral cont(m());
|
||||
get_primitive_and_content(f.size(), f.c_ptr(), pp, cont);
|
||||
get_primitive_and_content(f.size(), f.data(), pp, cont);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief p := -p
|
||||
*/
|
||||
void neg(unsigned sz, numeral * p);
|
||||
void neg(numeral_vector & p) { neg(p.size(), p.c_ptr()); }
|
||||
void neg(numeral_vector & p) { neg(p.size(), p.data()); }
|
||||
|
||||
/**
|
||||
\brief buffer := -p
|
||||
*/
|
||||
void neg(unsigned sz, numeral const * p, numeral_vector & buffer);
|
||||
void neg(numeral_vector const & p, numeral_vector & p_neg) { neg(p.size(), p.c_ptr(), p_neg); }
|
||||
void neg(numeral_vector const & p, numeral_vector & p_neg) { neg(p.size(), p.data(), p_neg); }
|
||||
|
||||
/**
|
||||
\brief buffer := p1 + p2
|
||||
*/
|
||||
void add(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & buffer);
|
||||
void add(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { add(a.size(), a.c_ptr(), b.size(), b.c_ptr(), c); }
|
||||
void add(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { add(a.size(), a.data(), b.size(), b.data(), c); }
|
||||
|
||||
/**
|
||||
\brief buffer := p1 - p2
|
||||
*/
|
||||
void sub(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & buffer);
|
||||
void sub(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { sub(a.size(), a.c_ptr(), b.size(), b.c_ptr(), c); }
|
||||
void sub(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { sub(a.size(), a.data(), b.size(), b.data(), c); }
|
||||
|
||||
/**
|
||||
\brief buffer := p1 * p2
|
||||
*/
|
||||
void mul(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & buffer);
|
||||
void mul(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { mul(a.size(), a.c_ptr(), b.size(), b.c_ptr(), c); }
|
||||
void mul(numeral_vector const & a, numeral_vector const & b, numeral_vector & c) { mul(a.size(), a.data(), b.size(), b.data(), c); }
|
||||
|
||||
/**
|
||||
\brief r := p^k
|
||||
|
@ -252,7 +252,7 @@ namespace upolynomial {
|
|||
\brief buffer := dp/dx
|
||||
*/
|
||||
void derivative(unsigned sz1, numeral const * p, numeral_vector & buffer);
|
||||
void derivative(numeral_vector const & p, numeral_vector & d_p) { derivative(p.size(), p.c_ptr(), d_p); }
|
||||
void derivative(numeral_vector const & p, numeral_vector & d_p) { derivative(p.size(), p.data(), d_p); }
|
||||
|
||||
/**
|
||||
\brief Divide coefficients of p by their GCD
|
||||
|
@ -269,7 +269,7 @@ namespace upolynomial {
|
|||
This method assumes that every coefficient of p is a multiple of b, and b != 0.
|
||||
*/
|
||||
void div(unsigned sz, numeral * p, numeral const & b);
|
||||
void div(numeral_vector & p, numeral const & b) { div(p.size(), p.c_ptr(), b); }
|
||||
void div(numeral_vector & p, numeral const & b) { div(p.size(), p.data(), b); }
|
||||
|
||||
/**
|
||||
\brief Multiply the coefficients of p by b.
|
||||
|
@ -312,7 +312,7 @@ namespace upolynomial {
|
|||
}
|
||||
|
||||
void div_rem(numeral_vector const & p1, numeral_vector const & p2, numeral_vector & q, numeral_vector & r) {
|
||||
div_rem(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr(), q, r);
|
||||
div_rem(p1.size(), p1.data(), p2.size(), p2.data(), q, r);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,14 +343,14 @@ namespace upolynomial {
|
|||
\brief Return true if p2 divides p1.
|
||||
*/
|
||||
bool divides(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2);
|
||||
bool divides(numeral_vector const & p1, numeral_vector const & p2) { return divides(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr()); }
|
||||
bool divides(numeral_vector const & p1, numeral_vector const & p2) { return divides(p1.size(), p1.data(), p2.size(), p2.data()); }
|
||||
|
||||
/**
|
||||
\brief Return true if p2 divides p1, and store the quotient in q.
|
||||
*/
|
||||
bool exact_div(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & q);
|
||||
bool exact_div(numeral_vector const & p1, numeral_vector const & p2, numeral_vector & q) {
|
||||
return exact_div(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr(), q);
|
||||
return exact_div(p1.size(), p1.data(), p2.size(), p2.data(), q);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -360,7 +360,7 @@ namespace upolynomial {
|
|||
void mk_monic(unsigned sz, numeral * p, numeral & lc, numeral & lc_inv);
|
||||
void mk_monic(unsigned sz, numeral * p, numeral & lc) { numeral lc_inv; mk_monic(sz, p, lc, lc_inv); m().del(lc_inv); }
|
||||
void mk_monic(unsigned sz, numeral * p) { numeral lc, lc_inv; mk_monic(sz, p, lc, lc_inv); m().del(lc); m().del(lc_inv); }
|
||||
void mk_monic(numeral_vector & p) { mk_monic(p.size(), p.c_ptr()); }
|
||||
void mk_monic(numeral_vector & p) { mk_monic(p.size(), p.data()); }
|
||||
|
||||
/**
|
||||
\brief g := gcd(p1, p2)
|
||||
|
@ -370,10 +370,10 @@ namespace upolynomial {
|
|||
void euclid_gcd(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & g);
|
||||
void subresultant_gcd(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2, numeral_vector & g);
|
||||
void gcd(numeral_vector const & p1, numeral_vector const & p2, numeral_vector & g) {
|
||||
gcd(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr(), g);
|
||||
gcd(p1.size(), p1.data(), p2.size(), p2.data(), g);
|
||||
}
|
||||
void subresultant_gcd(numeral_vector const & p1, numeral_vector const & p2, numeral_vector & g) {
|
||||
subresultant_gcd(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr(), g);
|
||||
subresultant_gcd(p1.size(), p1.data(), p2.size(), p2.data(), g);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,7 +390,7 @@ namespace upolynomial {
|
|||
\brief Return true if p is a square-free polynomial.
|
||||
*/
|
||||
bool is_square_free(numeral_vector const & p) {
|
||||
return is_square_free(p.size(), p.c_ptr());
|
||||
return is_square_free(p.size(), p.data());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -453,20 +453,20 @@ namespace upolynomial {
|
|||
*/
|
||||
void ext_gcd(unsigned szA, numeral const * A, unsigned szB, numeral const * B, numeral_vector & U, numeral_vector & V, numeral_vector & D);
|
||||
void ext_gcd(numeral_vector const & A, numeral_vector const & B, numeral_vector & U, numeral_vector & V, numeral_vector & D) {
|
||||
ext_gcd(A.size(), A.c_ptr(), B.size(), B.c_ptr(), U, V, D);
|
||||
ext_gcd(A.size(), A.data(), B.size(), B.data(), U, V, D);
|
||||
}
|
||||
|
||||
bool eq(unsigned sz1, numeral const * p1, unsigned sz2, numeral const * p2);
|
||||
bool eq(numeral_vector const & p1, numeral_vector const & p2) { return eq(p1.size(), p1.c_ptr(), p2.size(), p2.c_ptr()); }
|
||||
bool eq(numeral_vector const & p1, numeral_vector const & p2) { return eq(p1.size(), p1.data(), p2.size(), p2.data()); }
|
||||
|
||||
std::ostream& display(std::ostream & out, unsigned sz, numeral const * p, char const * var_name = "x", bool use_star = false) const;
|
||||
std::ostream& display(std::ostream & out, numeral_vector const & p, char const * var_name = "x") const { return display(out, p.size(), p.c_ptr(), var_name); }
|
||||
std::ostream& display(std::ostream & out, numeral_vector const & p, char const * var_name = "x") const { return display(out, p.size(), p.data(), var_name); }
|
||||
std::ostream& display_star(std::ostream & out, unsigned sz, numeral const * p) { return display(out, sz, p, "x", true); }
|
||||
std::ostream& display_star(std::ostream & out, numeral_vector const & p) { return display_star(out, p.size(), p.c_ptr()); }
|
||||
std::ostream& display_star(std::ostream & out, numeral_vector const & p) { return display_star(out, p.size(), p.data()); }
|
||||
|
||||
std::ostream& display_smt2(std::ostream & out, unsigned sz, numeral const * p, char const * var_name = "x") const;
|
||||
std::ostream& display_smt2(std::ostream & out, numeral_vector const & p, char const * var_name = "x") const {
|
||||
return display_smt2(out, p.size(), p.c_ptr(), var_name);
|
||||
return display_smt2(out, p.size(), p.data(), var_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -531,7 +531,7 @@ namespace upolynomial {
|
|||
/**
|
||||
\brief Return the vector of coefficients for the i-th polynomial in the sequence.
|
||||
*/
|
||||
numeral const * coeffs(unsigned i) const { return m_seq_coeffs.c_ptr() + m_begins[i]; }
|
||||
numeral const * coeffs(unsigned i) const { return m_seq_coeffs.data() + m_begins[i]; }
|
||||
|
||||
/**
|
||||
\brief Return the size of the i-th polynomial in the sequence.
|
||||
|
@ -643,33 +643,33 @@ namespace upolynomial {
|
|||
\brief p(x) := p(x+1)
|
||||
*/
|
||||
void translate(unsigned sz, numeral * p);
|
||||
void translate(unsigned sz, numeral const * p, numeral_vector & buffer) { set(sz, p, buffer); translate(sz, buffer.c_ptr()); }
|
||||
void translate(unsigned sz, numeral const * p, numeral_vector & buffer) { set(sz, p, buffer); translate(sz, buffer.data()); }
|
||||
|
||||
/**
|
||||
\brief p(x) := p(x+2^k)
|
||||
*/
|
||||
void translate_k(unsigned sz, numeral * p, unsigned k);
|
||||
void translate_k(unsigned sz, numeral const * p, unsigned k, numeral_vector & buffer) { set(sz, p, buffer); translate_k(sz, buffer.c_ptr(), k); }
|
||||
void translate_k(unsigned sz, numeral const * p, unsigned k, numeral_vector & buffer) { set(sz, p, buffer); translate_k(sz, buffer.data(), k); }
|
||||
|
||||
/**
|
||||
\brief p(x) := p(x+c)
|
||||
*/
|
||||
void translate_z(unsigned sz, numeral * p, numeral const & c);
|
||||
void translate_z(unsigned sz, numeral const * p, numeral const & c, numeral_vector & buffer) { set(sz, p, buffer); translate_z(sz, buffer.c_ptr(), c); }
|
||||
void translate_z(unsigned sz, numeral const * p, numeral const & c, numeral_vector & buffer) { set(sz, p, buffer); translate_z(sz, buffer.data(), c); }
|
||||
|
||||
/**
|
||||
\brief p(x) := p(x+b) where b = c/2^k
|
||||
buffer := (2^k)^n * p(x + c/(2^k))
|
||||
*/
|
||||
void translate_bq(unsigned sz, numeral * p, mpbq const & b);
|
||||
void translate_bq(unsigned sz, numeral const * p, mpbq const & b, numeral_vector & buffer) { set(sz, p, buffer); translate_bq(sz, buffer.c_ptr(), b); }
|
||||
void translate_bq(unsigned sz, numeral const * p, mpbq const & b, numeral_vector & buffer) { set(sz, p, buffer); translate_bq(sz, buffer.data(), b); }
|
||||
|
||||
/**
|
||||
\brief p(x) := p(x+b) where b = c/d
|
||||
buffer := d^n * p(x + c/d)
|
||||
*/
|
||||
void translate_q(unsigned sz, numeral * p, mpq const & b);
|
||||
void translate_q(unsigned sz, numeral const * p, mpq const & b, numeral_vector & buffer) { set(sz, p, buffer); translate_q(sz, buffer.c_ptr(), b); }
|
||||
void translate_q(unsigned sz, numeral const * p, mpq const & b, numeral_vector & buffer) { set(sz, p, buffer); translate_q(sz, buffer.data(), b); }
|
||||
|
||||
/**
|
||||
\brief p(x) := 2^n*p(x/2) where n = sz-1
|
||||
|
@ -905,7 +905,7 @@ namespace upolynomial {
|
|||
This can happen when limits (e.g., on the search space size) are set in params.
|
||||
*/
|
||||
bool factor(unsigned sz, numeral const * p, factors & r, factor_params const & params = factor_params());
|
||||
bool factor(numeral_vector const & p, factors & r, factor_params const & params = factor_params()) { return factor(p.size(), p.c_ptr(), r, params); }
|
||||
bool factor(numeral_vector const & p, factors & r, factor_params const & params = factor_params()) { return factor(p.size(), p.data(), r, params); }
|
||||
|
||||
std::ostream& display(std::ostream & out, unsigned sz, numeral const * p, char const * var_name = "x", bool use_star = false) const {
|
||||
return core_manager::display(out, sz, p, var_name);
|
||||
|
|
|
@ -261,9 +261,9 @@ void zp_square_free_factor(zp_manager & upm, numeral_vector const & f, zp_factor
|
|||
// trim and get the make it monic if not already
|
||||
SASSERT(f.size() > 1);
|
||||
scoped_numeral_vector T_0(nm);
|
||||
upm.set(f.size(), f.c_ptr(), T_0);
|
||||
upm.set(f.size(), f.data(), T_0);
|
||||
scoped_numeral constant(nm);
|
||||
upm.mk_monic(T_0.size(), T_0.c_ptr(), constant);
|
||||
upm.mk_monic(T_0.size(), T_0.data(), constant);
|
||||
sq_free_factors.set_constant(constant);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "Initial factors: " << sq_free_factors << endl;
|
||||
|
@ -285,21 +285,21 @@ void zp_square_free_factor(zp_manager & upm, numeral_vector const & f, zp_factor
|
|||
TRACE("polynomial::factorization::bughunt", tout << "k = 0" << endl;);
|
||||
|
||||
// T_0_d = T_0'
|
||||
upm.derivative(T_0.size(), T_0.c_ptr(), T_0_d);
|
||||
upm.derivative(T_0.size(), T_0.data(), T_0_d);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T_0_d = T_0.derivative(x)" << endl;
|
||||
tout << "T_0_d == "; upm.display(tout, T_0_d); tout << endl;
|
||||
);
|
||||
|
||||
// T = gcd(T_0, T_0')
|
||||
upm.gcd(T_0.size(), T_0.c_ptr(), T_0_d.size(), T_0_d.c_ptr(), T);
|
||||
upm.gcd(T_0.size(), T_0.data(), T_0_d.size(), T_0_d.data(), T);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T = T_0.gcd(T_0_d)" << endl;
|
||||
tout << "T == "; upm.display(tout, T); tout << endl;
|
||||
);
|
||||
|
||||
// V = T_0 / T
|
||||
upm.div(T_0.size(), T_0.c_ptr(), T.size(), T.c_ptr(), V);
|
||||
upm.div(T_0.size(), T_0.data(), T.size(), T.data(), V);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "V = T_0.quo_rem(T)[0]" << endl;
|
||||
tout << "V == "; upm.display(tout, V); tout << endl;
|
||||
|
@ -310,7 +310,7 @@ void zp_square_free_factor(zp_manager & upm, numeral_vector const & f, zp_factor
|
|||
if ((++k) % p == 0) {
|
||||
++ k;
|
||||
// T = T/V
|
||||
upm.div(T.size(), T.c_ptr(), V.size(), V.c_ptr(), T);
|
||||
upm.div(T.size(), T.data(), V.size(), V.data(), T);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T = T.quo_rem(V)[0]" << endl;
|
||||
tout << "T == "; upm.display(tout, T); tout << endl;
|
||||
|
@ -320,14 +320,14 @@ void zp_square_free_factor(zp_manager & upm, numeral_vector const & f, zp_factor
|
|||
// [compute A_ek]
|
||||
|
||||
// W = gcd(T, V)
|
||||
upm.gcd(T.size(), T.c_ptr(), V.size(), V.c_ptr(), W);
|
||||
upm.gcd(T.size(), T.data(), V.size(), V.data(), W);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "W = T.gcd(V)" << endl;
|
||||
upm.display(tout, W); tout << endl;
|
||||
);
|
||||
|
||||
// A_ek = V/W
|
||||
upm.div(V.size(), V.c_ptr(), W.size(), W.c_ptr(), A_ek);
|
||||
upm.div(V.size(), V.data(), W.size(), W.data(), A_ek);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "A_ek = V.quo_rem(W)[0]" << endl;
|
||||
tout << "A_ek == "; upm.display(tout, A_ek); tout << endl;
|
||||
|
@ -341,7 +341,7 @@ void zp_square_free_factor(zp_manager & upm, numeral_vector const & f, zp_factor
|
|||
);
|
||||
|
||||
// T = T/V
|
||||
upm.div(T.size(), T.c_ptr(), V.size(), V.c_ptr(), T);
|
||||
upm.div(T.size(), T.data(), V.size(), V.data(), T);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T = T.quo_rem(V)[0]" << endl;
|
||||
tout << "T == "; upm.display(tout, T); tout << endl;
|
||||
|
@ -471,13 +471,13 @@ bool zp_factor_square_free_berlekamp(zp_manager & upm, numeral_vector const & f,
|
|||
zpm.dec(v_k[0]);
|
||||
|
||||
// get the gcd
|
||||
upm.gcd(v_k.size(), v_k.c_ptr(), current_factor.size(), current_factor.c_ptr(), gcd);
|
||||
upm.gcd(v_k.size(), v_k.data(), current_factor.size(), current_factor.data(), gcd);
|
||||
|
||||
// if the gcd is 1, or the gcd is f, we just ignore it
|
||||
if (gcd.size() != 1 && gcd.size() != current_factor.size()) {
|
||||
|
||||
// get the divisor also (no need to normalize the div, both are monic)
|
||||
upm.div(current_factor.size(), current_factor.c_ptr(), gcd.size(), gcd.c_ptr(), div);
|
||||
upm.div(current_factor.size(), current_factor.data(), gcd.size(), gcd.data(), div);
|
||||
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "current_factor = "; upm.display(tout, current_factor); tout << endl;
|
||||
|
@ -529,8 +529,8 @@ bool check_hansel_lift(z_manager & upm, numeral_vector const & C,
|
|||
|
||||
// test1: check that C = A_lifted * B_lifted (mod b*r)
|
||||
scoped_mpz_vector test1(nm);
|
||||
upm.mul(A_lifted.size(), A_lifted.c_ptr(), B_lifted.size(), B_lifted.c_ptr(), test1);
|
||||
upm.sub(C.size(), C.c_ptr(), test1.size(), test1.c_ptr(), test1);
|
||||
upm.mul(A_lifted.size(), A_lifted.data(), B_lifted.size(), B_lifted.data(), test1);
|
||||
upm.sub(C.size(), C.data(), test1.size(), test1.data(), test1);
|
||||
to_zp_manager(br_upm, test1);
|
||||
if (!test1.empty()) {
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
|
@ -607,8 +607,8 @@ void hensel_lift(z_manager & upm, numeral const & a, numeral const & b, numeral
|
|||
// by (2) C = AB (mod b), hence (C - AB) is divisible by b
|
||||
// define thus let f = (C - AB)/b in Z_r
|
||||
scoped_numeral_vector f(upm.m());
|
||||
upm.mul(A.size(), A.c_ptr(), B.size(), B.c_ptr(), f);
|
||||
upm.sub(C.size(), C.c_ptr(), f.size(), f.c_ptr(), f);
|
||||
upm.mul(A.size(), A.data(), B.size(), B.data(), f);
|
||||
upm.sub(C.size(), C.data(), f.size(), f.data(), f);
|
||||
upm.div(f, b);
|
||||
to_zp_manager(r_upm, f);
|
||||
TRACE("polynomial::factorization",
|
||||
|
@ -637,29 +637,29 @@ void hensel_lift(z_manager & upm, numeral const & a, numeral const & b, numeral
|
|||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "V == "; upm.display(tout, V); tout << endl;
|
||||
);
|
||||
r_upm.mul(V.size(), V.c_ptr(), f.size(), f.c_ptr(), Vf);
|
||||
r_upm.mul(V.size(), V.data(), f.size(), f.data(), Vf);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "Vf = V*f" << endl;
|
||||
tout << "Vf == "; upm.display(tout, Vf); tout << endl;
|
||||
);
|
||||
r_upm.div_rem(Vf.size(), Vf.c_ptr(), A.size(), A.c_ptr(), t, S);
|
||||
r_upm.div_rem(Vf.size(), Vf.data(), A.size(), A.data(), t, S);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "[t, S] = Vf.quo_rem(A)" << endl;
|
||||
tout << "t == "; upm.display(tout, t); tout << endl;
|
||||
tout << "S == "; upm.display(tout, S); tout << endl;
|
||||
);
|
||||
scoped_numeral_vector T(r_upm.m()), tmp(r_upm.m());
|
||||
r_upm.mul(U.size(), U.c_ptr(), f.size(), f.c_ptr(), T); // T = fU
|
||||
r_upm.mul(U.size(), U.data(), f.size(), f.data(), T); // T = fU
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T == U*f" << endl;
|
||||
tout << "T == "; upm.display(tout, T); tout << endl;
|
||||
);
|
||||
r_upm.mul(B.size(), B.c_ptr(), t.size(), t.c_ptr(), tmp); // tmp = Bt
|
||||
r_upm.mul(B.size(), B.data(), t.size(), t.data(), tmp); // tmp = Bt
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "tmp = B*t" << endl;
|
||||
tout << "tmp == "; upm.display(tout, tmp); tout << endl;
|
||||
);
|
||||
r_upm.add(T.size(), T.c_ptr(), tmp.size(), tmp.c_ptr(), T); // T = Uf + Bt
|
||||
r_upm.add(T.size(), T.data(), tmp.size(), tmp.data(), T); // T = Uf + Bt
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "T = B*tmp" << endl;
|
||||
tout << "T == "; upm.display(tout, T); tout << endl;
|
||||
|
@ -668,8 +668,8 @@ void hensel_lift(z_manager & upm, numeral const & a, numeral const & b, numeral
|
|||
// set the result, A1 = A + b*S, B1 = B + b*T (now we compute in Z[x])
|
||||
upm.mul(S, b);
|
||||
upm.mul(T, b);
|
||||
upm.add(A.size(), A.c_ptr(), S.size(), S.c_ptr(), A_lifted);
|
||||
upm.add(B.size(), B.c_ptr(), T.size(), T.c_ptr(), B_lifted);
|
||||
upm.add(A.size(), A.data(), S.size(), S.data(), A_lifted);
|
||||
upm.add(B.size(), B.data(), T.size(), T.data(), B_lifted);
|
||||
|
||||
CASSERT("polynomial::factorizatio::bughunt", check_hansel_lift(upm, C, a, b, r, A, B, A_lifted, B_lifted));
|
||||
}
|
||||
|
@ -680,10 +680,10 @@ bool check_quadratic_hensel(zp_manager & zpe_upm, numeral_vector const & U, nume
|
|||
// compute UA+BV expecting to get 1 (in Z_pe[x])
|
||||
scoped_mpz_vector tmp1(nm);
|
||||
scoped_mpz_vector tmp2(nm);
|
||||
zpe_upm.mul(U.size(), U.c_ptr(), A.size(), A.c_ptr(), tmp1);
|
||||
zpe_upm.mul(V.size(), V.c_ptr(), B.size(), B.c_ptr(), tmp2);
|
||||
zpe_upm.mul(U.size(), U.data(), A.size(), A.data(), tmp1);
|
||||
zpe_upm.mul(V.size(), V.data(), B.size(), B.data(), tmp2);
|
||||
scoped_mpz_vector one(nm);
|
||||
zpe_upm.add(tmp1.size(), tmp1.c_ptr(), tmp2.size(), tmp2.c_ptr(), one);
|
||||
zpe_upm.add(tmp1.size(), tmp1.data(), tmp2.size(), tmp2.data(), one);
|
||||
if (one.size() != 1 || !nm.is_one(one[0])) {
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "sage: R.<x> = Zmod(" << nm.to_string(zpe_upm.m().p()) << ")['x']" << endl;
|
||||
|
@ -724,7 +724,7 @@ void hensel_lift_quadratic(z_manager& upm, numeral_vector const & C,
|
|||
|
||||
// get the U, V, such that A*U + B*V = 1 (mod p)
|
||||
scoped_mpz_vector U(nm), V(nm), D(nm);
|
||||
zp_upm.ext_gcd(A.size(), A.c_ptr(), B.size(), B.c_ptr(), U, V, D);
|
||||
zp_upm.ext_gcd(A.size(), A.data(), B.size(), B.data(), U, V, D);
|
||||
SASSERT(D.size() == 1 && zp_upm.m().is_one(D[0]));
|
||||
|
||||
// we start lifting from (a = p, b = p, r = p)
|
||||
|
@ -762,10 +762,10 @@ void hensel_lift_quadratic(z_manager& upm, numeral_vector const & C,
|
|||
scoped_mpz_vector tmp1(nm), g(nm);
|
||||
g.push_back(numeral());
|
||||
nm.set(g.back(), 1); // g = 1
|
||||
upm.mul(A_lifted.size(), A_lifted.c_ptr(), U.size(), U.c_ptr(), tmp1); // tmp1 = AU
|
||||
upm.sub(g.size(), g.c_ptr(), tmp1.size(), tmp1.c_ptr(), g); // g = 1 - UA
|
||||
upm.mul(B_lifted.size(), B_lifted.c_ptr(), V.size(), V.c_ptr(), tmp1); // tmp1 = BV
|
||||
upm.sub(g.size(), g.c_ptr(), tmp1.size(), tmp1.c_ptr(), g); // g = 1 - UA - VB
|
||||
upm.mul(A_lifted.size(), A_lifted.data(), U.size(), U.data(), tmp1); // tmp1 = AU
|
||||
upm.sub(g.size(), g.data(), tmp1.size(), tmp1.data(), g); // g = 1 - UA
|
||||
upm.mul(B_lifted.size(), B_lifted.data(), V.size(), V.data(), tmp1); // tmp1 = BV
|
||||
upm.sub(g.size(), g.data(), tmp1.size(), tmp1.data(), g); // g = 1 - UA - VB
|
||||
upm.div(g, pe);
|
||||
to_zp_manager(zpe_upm, g);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
|
@ -775,17 +775,17 @@ void hensel_lift_quadratic(z_manager& upm, numeral_vector const & C,
|
|||
|
||||
// compute the S, T
|
||||
scoped_mpz_vector S(nm), T(nm), t(nm), tmp2(nm);
|
||||
zpe_upm.mul(g.size(), g.c_ptr(), V.size(), V.c_ptr(), tmp1); // tmp1 = gV
|
||||
zpe_upm.div_rem(tmp1.size(), tmp1.c_ptr(), A.size(), A.c_ptr(), t, T); // T = gV - tA, deg(T) < deg(A)
|
||||
zpe_upm.mul(g.size(), g.c_ptr(), U.size(), U.c_ptr(), tmp1); // tmp1 = gU
|
||||
zpe_upm.mul(t.size(), t.c_ptr(), B.size(), B.c_ptr(), tmp2); // tmp2 = tB
|
||||
zpe_upm.add(tmp1.size(), tmp1.c_ptr(), tmp2.size(), tmp2.c_ptr(), S);
|
||||
zpe_upm.mul(g.size(), g.data(), V.size(), V.data(), tmp1); // tmp1 = gV
|
||||
zpe_upm.div_rem(tmp1.size(), tmp1.data(), A.size(), A.data(), t, T); // T = gV - tA, deg(T) < deg(A)
|
||||
zpe_upm.mul(g.size(), g.data(), U.size(), U.data(), tmp1); // tmp1 = gU
|
||||
zpe_upm.mul(t.size(), t.data(), B.size(), B.data(), tmp2); // tmp2 = tB
|
||||
zpe_upm.add(tmp1.size(), tmp1.data(), tmp2.size(), tmp2.data(), S);
|
||||
|
||||
// now update U = U + a*S and V = V + a*T
|
||||
upm.mul(S.size(), S.c_ptr(), pe);
|
||||
upm.mul(T.size(), T.c_ptr(), pe);
|
||||
upm.add(U.size(), U.c_ptr(), S.size(), S.c_ptr(), U);
|
||||
upm.add(V.size(), V.c_ptr(), T.size(), T.c_ptr(), V); // deg(V) < deg(A), deg(T) < deg(A) => deg(V') < deg(A)
|
||||
upm.mul(S.size(), S.data(), pe);
|
||||
upm.mul(T.size(), T.data(), pe);
|
||||
upm.add(U.size(), U.data(), S.size(), S.data(), U);
|
||||
upm.add(V.size(), V.data(), T.size(), T.data(), V); // deg(V) < deg(A), deg(T) < deg(A) => deg(V') < deg(A)
|
||||
|
||||
// we go quadratic
|
||||
zpe_upm.m().set_p_sq();
|
||||
|
@ -891,7 +891,7 @@ void hensel_lift(z_manager & upm, numeral_vector const & f, zp_factors const & z
|
|||
scoped_mpz_vector A(nm), B(nm), C(nm), f_parts(nm); // these will all be in Z_p
|
||||
|
||||
// copy of f, that we'll be cutting parts of
|
||||
upm.set(f.size(), f.c_ptr(), f_parts);
|
||||
upm.set(f.size(), f.data(), f_parts);
|
||||
|
||||
// F_k are factors mod Z_p, A_k the factors mod p^e
|
||||
// the invariant we keep is that:
|
||||
|
@ -902,7 +902,7 @@ void hensel_lift(z_manager & upm, numeral_vector const & f, zp_factors const & z
|
|||
SASSERT(zp_fs.get_degree(i) == 1); // p was chosen so that f is square-free
|
||||
|
||||
// F_i = A (mod Z_p)
|
||||
zp_upm.set(zp_fs[i].size(), zp_fs[i].c_ptr(), A);
|
||||
zp_upm.set(zp_fs[i].size(), zp_fs[i].data(), A);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "A = "; upm.display(tout, A); tout << endl;
|
||||
);
|
||||
|
@ -923,7 +923,7 @@ void hensel_lift(z_manager & upm, numeral_vector const & f, zp_factors const & z
|
|||
);
|
||||
|
||||
// we take B to be what's left from C and A
|
||||
zp_upm.div(C.size(), C.c_ptr(), A.size(), A.c_ptr(), B);
|
||||
zp_upm.div(C.size(), C.data(), A.size(), A.data(), B);
|
||||
TRACE("polynomial::factorization::bughunt",
|
||||
tout << "B = "; upm.display(tout, B); tout << endl;
|
||||
);
|
||||
|
@ -944,7 +944,7 @@ void hensel_lift(z_manager & upm, numeral_vector const & f, zp_factors const & z
|
|||
}
|
||||
|
||||
// take the lifted A out of f_parts
|
||||
zpe_upm.div(f_parts.size(), f_parts.c_ptr(), A.size(), A.c_ptr(), f_parts);
|
||||
zpe_upm.div(f_parts.size(), f_parts.data(), A.size(), A.data(), f_parts);
|
||||
|
||||
// add the lifted factor (kills A)
|
||||
zpe_fs.push_back_swap(A, 1);
|
||||
|
@ -1029,12 +1029,12 @@ bool factor_square_free(z_manager & upm, numeral_vector const & f, factors & fs,
|
|||
// This method assumes f is primitive. Thus, the content of f must be one
|
||||
DEBUG_CODE({
|
||||
scoped_numeral f_cont(nm);
|
||||
nm.gcd(f.size(), f.c_ptr(), f_cont);
|
||||
nm.gcd(f.size(), f.data(), f_cont);
|
||||
SASSERT(f.size() == 0 || nm.is_one(f_cont));
|
||||
});
|
||||
|
||||
scoped_numeral_vector f_pp(nm);
|
||||
upm.set(f.size(), f.c_ptr(), f_pp);
|
||||
upm.set(f.size(), f.data(), f_pp);
|
||||
|
||||
// make sure the leading coefficient is positive
|
||||
if (!f_pp.empty() && nm.is_neg(f_pp[f_pp.size() - 1])) {
|
||||
|
@ -1103,11 +1103,11 @@ bool factor_square_free(z_manager & upm, numeral_vector const & f, factors & fs,
|
|||
tout << "sage: f_pp_zp = "; zp_upm.display(tout, f_pp_zp, "x_p"); tout << endl;
|
||||
);
|
||||
|
||||
if (!zp_upm.is_square_free(f_pp_zp.size(), f_pp_zp.c_ptr()))
|
||||
if (!zp_upm.is_square_free(f_pp_zp.size(), f_pp_zp.data()))
|
||||
continue;
|
||||
|
||||
// we make it monic
|
||||
zp_upm.mk_monic(f_pp_zp.size(), f_pp_zp.c_ptr());
|
||||
zp_upm.mk_monic(f_pp_zp.size(), f_pp_zp.data());
|
||||
|
||||
// found a candidate, factorize in Z_p and add back the constant
|
||||
zp_factors current_fs(zp_upm);
|
||||
|
|
|
@ -345,9 +345,9 @@ namespace upolynomial {
|
|||
void left(numeral_vector & out) const {
|
||||
SASSERT(m_current_size > 0);
|
||||
zp_manager & upm = m_factors.upm();
|
||||
upm.set(m_factors[m_current[0]].size(), m_factors[m_current[0]].c_ptr(), out);
|
||||
upm.set(m_factors[m_current[0]].size(), m_factors[m_current[0]].data(), out);
|
||||
for (int i = 1; i < m_current_size; ++ i) {
|
||||
upm.mul(out.size(), out.c_ptr(), m_factors[m_current[i]].size(), m_factors[m_current[i]].c_ptr(), out);
|
||||
upm.mul(out.size(), out.data(), m_factors[m_current[i]].size(), m_factors[m_current[i]].data(), out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,9 +401,9 @@ namespace upolynomial {
|
|||
if (selection_i >= m_current.size() || (int) current < m_current[selection_i]) {
|
||||
SASSERT(m_factors.get_degree(current) == 1);
|
||||
if (out.empty()) {
|
||||
upm.set(m_factors[current].size(), m_factors[current].c_ptr(), out);
|
||||
upm.set(m_factors[current].size(), m_factors[current].data(), out);
|
||||
} else {
|
||||
upm.mul(out.size(), out.c_ptr(), m_factors[current].size(), m_factors[current].c_ptr(), out);
|
||||
upm.mul(out.size(), out.data(), m_factors[current].size(), m_factors[current].data(), out);
|
||||
}
|
||||
current ++;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue