3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-06 17:44:08 +00:00
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2024-08-15 17:14:03 -10:00 committed by Lev Nachmanson
parent a5dd59fdfb
commit abf29b57aa
9 changed files with 999 additions and 903 deletions

View file

@ -2,6 +2,7 @@ z3_add_component(lp
SOURCES SOURCES
core_solver_pretty_printer.cpp core_solver_pretty_printer.cpp
dense_matrix.cpp dense_matrix.cpp
dioph_eq.cpp
emonics.cpp emonics.cpp
factorization.cpp factorization.cpp
factorization_factory_imp.cpp factorization_factory_imp.cpp

64
src/math/lp/dioph_eq.cpp Normal file
View file

@ -0,0 +1,64 @@
#include "math/lp/dioph_eq.h"
#include "math/lp/int_solver.h"
#include "math/lp/lar_solver.h"
#include "math/lp/lp_utils.h"
namespace lp {
struct imp {
int_solver& lia;
lar_solver& lra;
imp(int_solver& lia, lar_solver& lra): lia(lia), lra(lra) {}
vector<lar_term> m_e;
void init() {
int n_of_rows = lra.r_basis().size();
unsigned skipped = 0;
for (unsigned i = 0; i < lra.r_basis().size(); i++) {
auto & row = lra.get_row(i);
lar_term t;
bool is_int = true;
for (const auto & p : row) {
if (!lia.column_is_int(p.var()))
is_int = false;
}
if (is_int) {
lar_term t;
const auto lcm = get_denominators_lcm(row);
for (const auto & p: row) {
t.add_monomial(lcm * p.coeff(), p.var());
}
m_e.push_back(t);
} else {
skipped ++;
}
}
if (m_e.size() > 0) {
std::cout << "collected " << m_e.size() << ", skipped " << skipped << "\n";
for (const auto & t: m_e) {
lra.print_term(t, std::cout) << "\n";
}
std::cout << "________________________\n";
}
}
lia_move check() {
init();
return lia_move::undef;
}
};
// Constructor definition
dioph_eq::dioph_eq(int_solver& lia): lia(lia) {
m_imp = alloc(imp, lia, lia.lra);
}
dioph_eq::~dioph_eq() {
dealloc(m_imp);
}
lia_move dioph_eq::check() {
return m_imp->check();
}
}

32
src/math/lp/dioph_eq.h Normal file
View file

@ -0,0 +1,32 @@
/*++
Copyright (c) 2024 Microsoft Corporation
Module Name:
diophantine equations
Abstract:
Following "A Practical Approach to Satisfiability Modulo Linear Integer Arithmetic"
by Alberto Griggio(griggio@fbk.eu)
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#pragma once
#include "math/lp/lia_move.h"
namespace lp {
struct imp;
class int_solver;
class dioph_eq {
int_solver& lia;
imp* m_imp;
public:
dioph_eq(int_solver& lia);
~dioph_eq();
lia_move check();
};
}

View file

@ -100,14 +100,7 @@ namespace lp {
} }
return true; return true;
} }
static mpq get_denominators_lcm(const row_strip<mpq> & row) {
mpq r(1);
for (auto & c : row)
r = lcm(r, denominator(c.coeff()));
return r;
}
bool int_gcd_test::gcd_test_for_row(const static_matrix<mpq, numeric_pair<mpq>> & A, unsigned i) { bool int_gcd_test::gcd_test_for_row(const static_matrix<mpq, numeric_pair<mpq>> & A, unsigned i) {
auto const& row = A.m_rows[i]; auto const& row = A.m_rows[i];
unsigned basic_var = lra.r_basis()[i]; unsigned basic_var = lra.r_basis()[i];

File diff suppressed because it is too large Load diff

View file

@ -40,7 +40,7 @@ class int_solver {
friend class int_gcd_test; friend class int_gcd_test;
friend class hnf_cutter; friend class hnf_cutter;
friend struct imp; friend struct imp;
friend class dioph_eq;
lar_solver& lra; lar_solver& lra;
lar_core_solver& lrac; lar_core_solver& lrac;
imp* m_imp; imp* m_imp;

View file

@ -18,6 +18,8 @@ Revision History:
--*/ --*/
#pragma once #pragma once
#include <string>
#include "util/debug.h"
namespace lp { namespace lp {
enum class lia_move { enum class lia_move {
sat, sat,

View file

@ -26,6 +26,13 @@ Revision History:
#include "math/lp/lp_primal_core_solver.h" #include "math/lp/lp_primal_core_solver.h"
#include "math/lp/lar_solver.h" #include "math/lp/lar_solver.h"
namespace lp { namespace lp {
mpq get_denominators_lcm(const row_strip<mpq> & row) {
mpq r(1);
for (auto & c : row)
r = lcm(r, denominator(c.coeff()));
return r;
}
template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::mpq>::get_domain(); template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::mpq>::get_domain();
template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::get_domain(); template std::set<std::pair<unsigned, unsigned>> lp::static_matrix<lp::mpq, lp::numeric_pair<lp::mpq> >::get_domain();
template void static_matrix<mpq, mpq>::add_column_to_vector(mpq const&, unsigned int, mpq*) const; template void static_matrix<mpq, mpq>::add_column_to_vector(mpq const&, unsigned int, mpq*) const;

View file

@ -45,6 +45,8 @@ typedef vector<column_cell> column_strip;
template <typename T> template <typename T>
using row_strip = vector<row_cell<T>>; using row_strip = vector<row_cell<T>>;
mpq get_denominators_lcm(const row_strip<mpq> & row);
template <typename T> template <typename T>
std::ostream& operator<<(std::ostream& out, const row_strip<T>& r) { std::ostream& operator<<(std::ostream& out, const row_strip<T>& r) {
for (auto const& c : r) for (auto const& c : r)