@@ -1075,7 +1075,12 @@ namespace lp {
10751075 }
10761076
10771077 template <typename K>
1078- mpq gcd_of_coeffs (const K& k) {
1078+ mpq gcd_of_coeffs (const K& k, bool check_for_one) {
1079+ if (check_for_one)
1080+ for (const auto & p : k)
1081+ if (p.coeff ().is_one () || p.coeff ().is_minus_one ())
1082+ return mpq (1 );
1083+
10791084 mpq g (0 );
10801085 for (const auto & p : k) {
10811086 SASSERT (p.coeff ().is_int ());
@@ -1125,10 +1130,10 @@ namespace lp {
11251130 // If there is no conflict the entry is divided, normalized, by gcd.
11261131 // The function returns true if and only if there is no conflict. In the case of a conflict a branch
11271132 // can be returned as well.
1128- bool normalize_e_by_gcd (unsigned ei) {
1133+ bool normalize_e_by_gcd (unsigned ei, mpq& g ) {
11291134 mpq & e = m_sum_of_fixed[ei];
11301135 TRACE (" dioph_eq" , print_entry (ei, tout) << std::endl;);
1131- mpq g = gcd_of_coeffs (m_e_matrix.m_rows [ei]);
1136+ g = gcd_of_coeffs (m_e_matrix.m_rows [ei], false );
11321137 if (g.is_zero () || g.is_one ()) {
11331138 SASSERT (g.is_one () || e.is_zero ());
11341139 return true ;
@@ -1159,20 +1164,6 @@ namespace lp {
11591164 return false ;
11601165 }
11611166
1162- // iterate over F: return true if no conflict is found and false otherwise
1163- bool normalize_by_gcd () {
1164- for (unsigned l = 0 ; l < m_e_matrix.row_count (); l++) {
1165- if (!belongs_to_f (l)) continue ;
1166- if (!normalize_e_by_gcd (l)) {
1167- SASSERT (entry_invariant (l));
1168- m_conflict_index = l;
1169- return false ;
1170- }
1171- SASSERT (entry_invariant (l));
1172- }
1173- return true ;
1174- }
1175-
11761167 void init_term_from_constraint (term_o& t, const lar_base_constraint& c) {
11771168 for (const auto & p : c.coeffs ()) {
11781169 t.add_monomial (p.first , p.second );
@@ -1438,7 +1429,7 @@ namespace lp {
14381429 SASSERT (
14391430 fix_vars (term_to_tighten + open_ml (m_term_with_index.to_term ())) ==
14401431 term_to_lar_solver (remove_fresh_vars (create_term_from_ind_c ())));
1441- mpq g = gcd_of_coeffs (m_indexed_work_vector);
1432+ mpq g = gcd_of_coeffs (m_indexed_work_vector, true );
14421433 TRACE (" dioph_eq" , tout << " after process_q_with_S\n t:" ;
14431434 print_term_o (create_term_from_ind_c (), tout) << std::endl;
14441435 tout << " g:" << g << std::endl;
@@ -1578,23 +1569,10 @@ namespace lp {
15781569 }
15791570
15801571 lia_move process_f () {
1581- bool progress = true ;
1582- while (progress) {
1583- if (!normalize_by_gcd ()) {
1584- if (m_report_branch) {
1585- lra.stats ().m_dio_branch_from_proofs ++;
1586- m_report_branch = false ;
1587- return lia_move::branch;
1588- } else {
1589- lra.stats ().m_dio_normalize_conflicts ++;
1590- }
1591- return lia_move::conflict;
1592- }
1593- progress = rewrite_eqs ();
1594- if (m_conflict_index != UINT_MAX) {
1595- lra.stats ().m_dio_rewrite_conflicts ++;
1596- return lia_move::conflict;
1597- }
1572+ while (rewrite_eqs ()) {}
1573+ if (m_conflict_index != UINT_MAX) {
1574+ lra.stats ().m_dio_rewrite_conflicts ++;
1575+ return lia_move::conflict;
15981576 }
15991577 return lia_move::undef;
16001578 }
@@ -1956,7 +1934,7 @@ namespace lp {
19561934 return ret;
19571935 }
19581936 SASSERT (ret == lia_move::undef);
1959- m_max_number_of_iterations = std::max (( unsigned )5 , ( unsigned ) m_max_number_of_iterations/2 ) ;
1937+ m_max_number_of_iterations = ( unsigned )m_max_number_of_iterations/2 ;
19601938
19611939 return lia_move::undef;
19621940 }
@@ -2336,13 +2314,28 @@ namespace lp {
23362314 return false ;
23372315 }
23382316 }
2317+
23392318 auto [ahk, k, k_sign] = find_minimal_abs_coeff (ei);
23402319 if (ahk.is_one ()) {
23412320 TRACE (" dioph_eq" , tout << " push to S:\n " ; print_entry (ei, tout););
23422321 move_entry_from_f_to_s (k, ei);
23432322 eliminate_var_in_f (ei, k, k_sign);
23442323 return true ;
23452324 }
2325+ mpq gcd;
2326+ if (!normalize_e_by_gcd (ei, gcd)) {
2327+ m_conflict_index = ei;
2328+ return false ;
2329+ }
2330+ if (!gcd.is_one ()){
2331+ ahk /= gcd;
2332+ if (ahk.is_one ()) {
2333+ TRACE (" dioph_eq" , tout << " push to S:\n " ; print_entry (ei, tout););
2334+ move_entry_from_f_to_s (k, ei);
2335+ eliminate_var_in_f (ei, k, k_sign);
2336+ return true ;
2337+ }
2338+ }
23462339
23472340 if (n == 0 || the_smallest_ahk > ahk) {
23482341 n = 1 ;
@@ -2358,7 +2351,7 @@ namespace lp {
23582351 kh_sign = k_sign;
23592352 }
23602353 }
2361- if (h == - 1 ) return false ;
2354+ if (h == UINT_MAX ) return false ;
23622355 SASSERT (!the_smallest_ahk.is_one ());
23632356 fresh_var_step (h, kh, the_smallest_ahk * mpq (kh_sign));
23642357 return true ;
0 commit comments