Skip to content

Commit

Permalink
Move tbv to util
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobR authored and NikolajBjorner committed Aug 1, 2022
1 parent a89be68 commit 79ee543
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/muz/ddnf/ddnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Revision History:
#include "muz/base/dl_context.h"
#include "ast/scoped_proof.h"
#include "ast/bv_decl_plugin.h"
#include "muz/rel/tbv.h"
#include "util/tbv.h"
#include <iostream>

namespace datalog {
Expand Down
1 change: 0 additions & 1 deletion src/muz/rel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ z3_add_component(rel
doc.cpp
karr_relation.cpp
rel_context.cpp
tbv.cpp
udoc_relation.cpp
COMPONENT_DEPENDENCIES
muz
Expand Down
34 changes: 29 additions & 5 deletions src/muz/rel/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,36 @@ void doc_manager::check_equiv(ast_manager& m, expr* fml1, expr* fml2) {
SASSERT(res == l_false);
}


expr_ref doc_manager::to_formula(ast_manager & m, tbv const& src) {
expr_ref result(m);
expr_ref_vector conj(m);
for (unsigned i = 0; i < num_tbits(); ++i) {
switch (src[i]) {
case BIT_0:
conj.push_back(m.mk_not(m.mk_const(symbol(i), m.mk_bool_sort())));
break;
case BIT_1:
conj.push_back(m.mk_const(symbol(i), m.mk_bool_sort()));
break;
default:
break;
}
}
result = mk_and(m, conj.size(), conj.data());
return result;
}

expr_ref doc_manager::mk_var(ast_manager & m, unsigned i) {
return expr_ref(m.mk_const(symbol(i), m.mk_bool_sort()), m);
}

expr_ref doc_manager::to_formula(ast_manager& m, doc const& src) {
expr_ref result(m);
expr_ref_vector conj(m);
conj.push_back(tbvm().to_formula(m, src.pos()));
conj.push_back(to_formula(m, src.pos()));
for (unsigned i = 0; i < src.neg().size(); ++i) {
conj.push_back(m.mk_not(tbvm().to_formula(m, src.neg()[i])));
conj.push_back(m.mk_not(to_formula(m, src.neg()[i])));
}
result = mk_and(m, conj.size(), conj.data());
return result;
Expand All @@ -712,9 +736,9 @@ void doc_manager::project_expand(expr_ref& fml, bit_vector const& to_delete) {
for (unsigned i = 0; i < num_tbits(); ++i) {
if (to_delete.get(i)) {
expr_safe_replace rep1(m), rep2(m);
rep1.insert(tbvm().mk_var(m, i), m.mk_true());
rep1.insert(mk_var(m, i), m.mk_true());
rep1(fml, tmp1);
rep2.insert(tbvm().mk_var(m, i), m.mk_false());
rep2.insert(mk_var(m, i), m.mk_false());
rep2(fml, tmp2);
if (tmp1 == tmp2) {
fml = tmp1;
Expand All @@ -731,7 +755,7 @@ void doc_manager::project_rename(expr_ref& fml, bit_vector const& to_delete) {
expr_safe_replace rep(m);
for (unsigned i = 0, j = 0; i < num_tbits(); ++i) {
if (!to_delete.get(i)) {
rep.insert(tbvm().mk_var(m, j), tbvm().mk_var(m, i));
rep.insert(mk_var(m, j), mk_var(m, i));
++j;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/muz/rel/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Revision History:

#pragma once

#include "muz/rel/tbv.h"
#include "util/tbv.h"
#include "util/union_find.h"
#include "util/buffer.h"

#include "ast/ast.h"

class doc;
template<typename M, typename T> class union_bvec;
Expand Down Expand Up @@ -101,6 +101,8 @@ class doc_manager {
void project_rename(expr_ref& fml, bit_vector const& to_delete);
void project_expand(expr_ref& fml, bit_vector const& to_delete);
expr_ref to_formula(ast_manager& m, doc const& src);
expr_ref to_formula(ast_manager& m, tbv const& src);
expr_ref mk_var(ast_manager& m, unsigned i);
void check_equiv(ast_manager& m, expr* fml1, expr* fml2);
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/ddnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2015 Microsoft Corporation
--*/

#include "muz/ddnf/ddnf.h"
#include "muz/rel/tbv.h"
#include "util/tbv.h"
#include <iostream>
#include <fstream>
#include <list>
Expand Down
2 changes: 1 addition & 1 deletion src/test/tbv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright (c) 2015 Microsoft Corporation
--*/

#include "muz/rel/tbv.h"
#include "util/tbv.h"
#include <iostream>

static void tst1(unsigned num_bits) {
Expand Down
1 change: 1 addition & 0 deletions src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ z3_add_component(util
state_graph.cpp
statistics.cpp
symbol.cpp
tbv.cpp
timeit.cpp
timeout.cpp
trace.cpp
Expand Down
26 changes: 1 addition & 25 deletions src/muz/rel/tbv.cpp → src/util/tbv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ Revision History:
--*/

#include "muz/rel/tbv.h"
#include "util/tbv.h"
#include "util/hashtable.h"
#include "ast/ast_util.h"


static bool s_debug_alloc = false;
Expand Down Expand Up @@ -301,26 +300,3 @@ std::ostream& tbv_manager::display(std::ostream& out, tbv const& b) const {
if (num_tbits() == 0) return out << "[]";
return display(out, b, num_tbits()-1, 0);
}

expr_ref tbv_manager::to_formula(ast_manager& m, tbv const& src) {
expr_ref result(m);
expr_ref_vector conj(m);
for (unsigned i = 0; i < num_tbits(); ++i) {
switch (src[i]) {
case BIT_0:
conj.push_back(m.mk_not(m.mk_const(symbol(i), m.mk_bool_sort())));
break;
case BIT_1:
conj.push_back(m.mk_const(symbol(i), m.mk_bool_sort()));
break;
default:
break;
}
}
result = mk_and(m, conj.size(), conj.data());
return result;
}

expr_ref tbv_manager::mk_var(ast_manager& m, unsigned i) {
return expr_ref(m.mk_const(symbol(i), m.mk_bool_sort()), m);
}
5 changes: 1 addition & 4 deletions src/muz/rel/tbv.h → src/util/tbv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Revision History:
#pragma once

#include "util/fixed_bit_vector.h"
#include "util/bit_vector.h"
#include "util/rational.h"
#include "ast/ast.h"

class tbv;

Expand Down Expand Up @@ -84,10 +84,7 @@ class tbv_manager {
void set(tbv& dst, tbv const& other, unsigned hi, unsigned lo);
void set(tbv& dst, unsigned index, tbit value);


static void debug_alloc();
expr_ref to_formula(ast_manager& m, tbv const& src);
expr_ref mk_var(ast_manager& m, unsigned i);
};

class tbv: private fixed_bit_vector {
Expand Down

0 comments on commit 79ee543

Please sign in to comment.