mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 03:45:51 +00:00
BDD vectors: add subtract and quot_rem, move finite domain abstraction out of bdd_manager (#5201)
* Coding style * Simplify bddv class * mk_eq: run loop from below * Add unit test for bddv unsigned comparison * Add test that shows contains_num/find_num fail after reordering * Add BDD vector subtraction * Call apply_rec in mk_ite_rec instead of apply * Question about mk_quant * Implement quot_rem over BDD vectors * Move shl/shr to bddv * Make unit test smaller * Add class dd::fdd to manage association between BDDs and numbers * Remove contains_num/find_num from bdd_manager
This commit is contained in:
parent
bc695a5a97
commit
77350d97da
10 changed files with 494 additions and 301 deletions
69
src/math/dd/dd_fdd.h
Normal file
69
src/math/dd/dd_fdd.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*++
|
||||
Copyright (c) 2021 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
dd_fdd
|
||||
|
||||
Abstract:
|
||||
|
||||
Finite domain abstraction for using BDDs as sets of integers, inspired by BuDDy's fdd module.
|
||||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2021-04-20
|
||||
Jakob Rath 2021-04-20
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
#include "math/dd/dd_bdd.h"
|
||||
#include "util/vector.h"
|
||||
#include "util/rational.h"
|
||||
|
||||
namespace dd {
|
||||
|
||||
enum class find_t { empty, singleton, multiple };
|
||||
std::ostream& operator<<(std::ostream& out, find_t x);
|
||||
|
||||
/**
|
||||
* Finite domain abstraction over BDDs.
|
||||
*/
|
||||
class fdd {
|
||||
unsigned_vector m_pos2var; // pos -> BDD var
|
||||
unsigned_vector m_var2pos; // var -> pos (pos = place number in the bit representation, 0 is LSB's place)
|
||||
// bdd_manager* m; // NOTE: currently unused
|
||||
bddv m_var;
|
||||
|
||||
static unsigned_vector seq(unsigned count) {
|
||||
unsigned_vector result;
|
||||
for (unsigned i = 0; i < count; ++i)
|
||||
result.push_back(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned var2pos(unsigned var) const;
|
||||
|
||||
public:
|
||||
/** Initialize FDD using BDD variables from 0 to num_bits-1. */
|
||||
fdd(bdd_manager& manager, unsigned num_bits) : fdd(manager, seq(num_bits)) { }
|
||||
fdd(bdd_manager& manager, unsigned_vector const& vars) : fdd(manager, unsigned_vector(vars)) { }
|
||||
fdd(bdd_manager& manager, unsigned_vector&& vars);
|
||||
|
||||
unsigned num_bits() const { return m_pos2var.size(); }
|
||||
unsigned_vector const& bdd_vars() const { return m_pos2var; }
|
||||
|
||||
bddv const& var() const { return m_var; }
|
||||
|
||||
/** Checks whether the integer val is contained in the BDD when viewed as set of integers.
|
||||
* Precondition: the bdd only contains variables managed by this fdd.
|
||||
*/
|
||||
bool contains(bdd b, rational const& val) const;
|
||||
|
||||
/** Returns an integer contained in the BDD, if any, and whether the BDD is a singleton.
|
||||
* Precondition: the bdd only contains variables managed by this fdd.
|
||||
*/
|
||||
find_t find(bdd b, rational& out_val) const;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue