3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 19:35:50 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-01-02 18:02:53 -08:00
parent bd5670a30b
commit 40a4326ad4
20 changed files with 860 additions and 465 deletions

View file

@ -91,3 +91,28 @@ std::ostream& bit_matrix::display(std::ostream& out) {
return out;
}
/*
produce a sequence of bits forming a Gray code.
- All 2^n bit-sequences are covered.
- The Hamming distance between two entries it one.
*/
unsigned_vector bit_matrix::gray(unsigned n) {
SASSERT(n < 32);
if (n == 0) {
return unsigned_vector();
}
else if (n == 1) {
unsigned_vector v;
v.push_back(0);
v.push_back(1);
return v;
}
else {
auto v = gray(n-1);
auto w = v;
w.reverse();
for (auto & u : v) u |= (1 << (n-1));
v.append(w);
return v;
}
}