Skip to content

Commit aa6dae8

Browse files
committed
do not refactor again multivariate polynomials
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 3db21b9 commit aa6dae8

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

src/nlsat/levelwise.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ namespace nlsat {
298298
TRACE(lws, tout << "resultant: "; ::nlsat::display(tout, m_solver, r); tout << std::endl;);
299299
if (is_zero(r)) {
300300
TRACE(lws, tout << "fail\n";);
301-
m_fail = true;
301+
fail();
302302
return false;
303303
}
304304
for_each_distinct_factor(r, [&](const polynomial::polynomial_ref &f) {
@@ -323,7 +323,7 @@ namespace nlsat {
323323
collect_roots_for_ps(ps_of_n_level, root_vals);
324324
if (!add_adjacent_resultants(root_vals)) {
325325
TRACE(lws, tout << "fail\n";);
326-
m_fail = true;
326+
fail();
327327
}
328328
}
329329

@@ -566,7 +566,7 @@ namespace nlsat {
566566
for_each_distinct_factor(disc, [&](polynomial::polynomial_ref f) {
567567
if (coeffs_are_zeroes_on_sample(f, m_pm, sample(), m_am)) {
568568
TRACE(lws, tout << "fail\n";);
569-
m_fail = true; // ambiguous multiplicity -- not handled yet
569+
fail(); // ambiguous multiplicity -- not handled yet
570570
return;
571571
}
572572
mk_prop(prop_enum::ord_inv, f);
@@ -586,7 +586,7 @@ namespace nlsat {
586586
for_each_distinct_factor(lc, [&](polynomial::polynomial_ref f) {
587587
if (coeffs_are_zeroes_on_sample(f, m_pm, sample(), m_am)) {
588588
TRACE(lws, tout << "fail\n";);
589-
m_fail = true;
589+
fail();
590590
return;
591591
}
592592
else
@@ -604,13 +604,13 @@ namespace nlsat {
604604
bool precondition_on_an_del(const property& p) {
605605
if (!p.m_poly) {
606606
TRACE(lws, tout << "apply_pre: an_del with null poly -> fail" << std::endl;);
607-
m_fail = true;
607+
fail();
608608
return false;
609609
}
610610
// If p is nullified on the sample for its level we must abort (Rule 4.1)
611611
if (coeffs_are_zeroes_on_sample(p.m_poly, m_pm, sample(), m_am)) {
612612
TRACE(lws, display(tout << "p:", p) << "\n"; tout << "Rule 4.1: polynomial nullified at sample -> failing" << std::endl;);
613-
m_fail = true;
613+
fail();
614614
return false;
615615
}
616616
return true;
@@ -724,7 +724,7 @@ namespace nlsat {
724724
// basic sanity checks
725725
if (!p.m_poly) {
726726
TRACE(lws, tout << "apply_pre_non_null_fallback: null poly -> fail" << std::endl;);
727-
m_fail = true;
727+
fail();
728728
return;
729729
}
730730

@@ -744,7 +744,7 @@ namespace nlsat {
744744
// (ambiguous multiplicity) -> fail per instruction
745745
if (sign(disc, sample(), m_am) == 0) {
746746
TRACE(lws, tout << "apply_pre_non_null_fallback: discriminant vanishes at sample -> failing" << std::endl;);
747-
m_fail = true;
747+
fail();
748748
return;
749749
}
750750
// If discriminant is non-constant, add sign-invariance requirement for it
@@ -835,7 +835,7 @@ or
835835
}
836836
catch (z3_exception const& ex) {
837837
TRACE(lws, tout << "isolate_roots failed: " << ex.what() << "\n";);
838-
m_fail = true;
838+
fail();
839839
return;
840840
}
841841
if (roots.size() == 0) {
@@ -870,7 +870,7 @@ or
870870
polynomial_ref res = resultant(polynomial_ref(I.l, m_pm), p.m_poly, m_level);
871871
if (m_pm.is_zero(res)) {
872872
TRACE(lws, tout << "fail\n";);
873-
m_fail = true;
873+
fail();
874874
return;
875875
}
876876
// Factor the resultant and add ord_inv for each distinct non-constant factor
@@ -974,7 +974,11 @@ or
974974
}
975975

976976
bool have_representation() const { return m_rel.empty() == false; }
977-
977+
978+
void fail() {
979+
m_fail = true;
980+
}
981+
978982
void apply_pre_ir_ord(const property& p) {
979983
/*Rule 4.9. Let i ∈ N, R ⊆ Ri, s ∈ Ri, and ≼ be an indexed root ordering of level i + 1.
980984
Assume that ξ.p is irreducible for all ξ ∈ dom(≼), and that ≼ matches s.
@@ -991,15 +995,17 @@ or
991995
SASSERT(max_var(a) == max_var(b) && max_var(b) == m_level) ;
992996

993997
polynomial_ref r(m_pm);
998+
enable_trace("lws");
994999
r = resultant(polynomial_ref(a, m_pm), polynomial_ref(b, m_pm), m_level);
1000+
TRACE(lws, tout << "resultant of (" << pair.first << "," << pair.second << "):";
1001+
::nlsat::display(tout, m_solver, a) << "\n";
1002+
::nlsat::display(tout,m_solver, b)<< "\nresultant:"; ::nlsat::display(tout, m_solver, r) << "\n");
1003+
disable_trace("lws");
9951004
if (m_pm.is_zero(r)) {
9961005
TRACE(lws, tout << "fail\n";);
997-
m_fail = true;
1006+
fail();
9981007
return;
9991008
}
1000-
TRACE(lws, tout << "resultant of (" << pair.first << "," << pair.second << "):";
1001-
::nlsat::display(tout, m_solver, a) << "\n";
1002-
::nlsat::display(tout,m_solver, b)<< "\nresultant:"; ::nlsat::display(tout, m_solver, r) << "\n");
10031009
for_each_distinct_factor(r, [this](const polynomial_ref& f) {mk_prop(ord_inv, f);});
10041010
}
10051011
}

src/nlsat/nlsat_common.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,7 @@ namespace nlsat {
2323
*/
2424
void factor(polynomial_ref & p, polynomial::cache& cache, polynomial_ref_vector & fs) {
2525
TRACE(nlsat_factor, tout << "factor\n" << p << "\n";);
26-
fs.reset();
27-
// Use a todo list to iteratively factor polynomials until every
28-
// polynomial in fs is irreducible (cache.factor returns a single factor).
29-
// Start with the input polynomial on the queue.
30-
polynomial_ref_vector todo(fs.m());
31-
todo.push_back(p.get());
32-
for (unsigned idx = 0; idx < todo.size(); ++idx) {
33-
polynomial_ref_vector tmp(fs.m());
34-
polynomial_ref cur_ref(todo.get(idx), fs.m());
35-
cache.factor(cur_ref.get(), tmp);
36-
if (tmp.size() == 1) {
37-
// single factor -> consider it irreducible and add to output
38-
fs.push_back(tmp.get(0));
39-
}
40-
else {
41-
// Only multivariate factors are queued for further factoring.
42-
// Univariate factors are considered final and pushed directly to the output vector `fs`.
43-
for (unsigned i = 0; i < tmp.size(); ++i) {
44-
if (polynomial::manager::is_univariate(tmp.get(i)))
45-
fs.push_back(tmp.get(i));
46-
else
47-
todo.push_back(tmp.get(i));
48-
}
49-
}
50-
}
51-
TRACE(nlsat_factor, tout << fs.size() << " factors:\n";
52-
::nlsat::display(tout, fs.m(), fs, polynomial::display_var_proc()) << "\n";
53-
);
26+
fs.reset();
27+
cache.factor(p.get(), fs);
5428
}
5529
}

0 commit comments

Comments
 (0)