mirror of
https://github.com/Z3Prover/z3
synced 2025-04-28 19:35:50 +00:00
merging with the lp fork
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
cf695ab876
commit
b08f094620
44 changed files with 902 additions and 319 deletions
|
@ -320,100 +320,4 @@ template <typename T, typename X> bool permutation_matrix<T, X>::is_identity() c
|
|||
}
|
||||
|
||||
|
||||
#ifdef LEAN_DEBUG
|
||||
template <typename T, typename X>
|
||||
permutation_generator<T, X>::permutation_generator(unsigned n): m_n(n), m_current(n) {
|
||||
lean_assert(n > 0);
|
||||
if (n > 1) {
|
||||
m_lower = new permutation_generator(n - 1);
|
||||
} else {
|
||||
m_lower = nullptr;
|
||||
}
|
||||
|
||||
m_last = 0;
|
||||
}
|
||||
|
||||
template <typename T, typename X>
|
||||
permutation_generator<T, X>::permutation_generator(const permutation_generator & o): m_n(o.m_n), m_done(o.m_done), m_current(o.m_current), m_last(o.m_last) {
|
||||
if (m_lower != nullptr) {
|
||||
m_lower = new permutation_generator(o.m_lower);
|
||||
} else {
|
||||
m_lower = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X> bool
|
||||
permutation_generator<T, X>::move_next() {
|
||||
if (m_done) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lower == nullptr) {
|
||||
if (m_last == 0) {
|
||||
m_last++;
|
||||
return true;
|
||||
} else {
|
||||
m_done = true;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (m_last < m_n && m_last > 0) {
|
||||
m_current[m_last - 1] = m_current[m_last];
|
||||
m_current[m_last] = m_n - 1;
|
||||
m_last++;
|
||||
return true;
|
||||
} else {
|
||||
if (m_lower -> move_next()) {
|
||||
auto lower_curr = m_lower -> current();
|
||||
for ( unsigned i = 1; i < m_n; i++ ){
|
||||
m_current[i] = (*lower_curr)[i - 1];
|
||||
}
|
||||
m_current[0] = m_n - 1;
|
||||
m_last = 1;
|
||||
return true;
|
||||
} else {
|
||||
m_done = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename X>
|
||||
inline unsigned number_of_inversions(permutation_matrix<T, X> & p) {
|
||||
unsigned ret = 0;
|
||||
unsigned n = p.size();
|
||||
for (unsigned i = 0; i < n; i++) {
|
||||
for (unsigned j = i + 1; j < n; j++) {
|
||||
if (p[i] > p[j]) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T, typename X>
|
||||
T det_val_on_perm(permutation_matrix<T, X>* u, const matrix<T, X>& m) {
|
||||
unsigned n = m.row_count();
|
||||
T ret = numeric_traits<T>::one();
|
||||
for (unsigned i = 0; i < n; i++) {
|
||||
unsigned j = (*u)[i];
|
||||
ret *= m(i, j);
|
||||
}
|
||||
return ret * sign(*u);
|
||||
}
|
||||
|
||||
template <typename T, typename X>
|
||||
T determinant(const matrix<T, X>& m) {
|
||||
lean_assert(m.column_count() == m.row_count());
|
||||
unsigned n = m.row_count();
|
||||
permutation_generator<T, X> allp(n);
|
||||
T ret = numeric_traits<T>::zero();
|
||||
while (allp.move_next()){
|
||||
ret += det_val_on_perm(allp.current(), m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue