Skip to content

Commit

Permalink
fix #6467
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Dec 14, 2022
1 parent cd3d38c commit 9054e72
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
25 changes: 14 additions & 11 deletions src/muz/base/dl_rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,39 +1013,42 @@ namespace datalog {
}
}

void rule::display(context & ctx, std::ostream & out) const {
void rule::display(context & ctx, std::ostream & out, bool compact) const {
ast_manager & m = ctx.get_manager();
out << m_name.str () << ":\n";
if (!compact)
out << m_name.str () << ":\n";
output_predicate(ctx, m_head, out);
if (m_tail_size == 0) {
out << ".\n";
out << ".";
if (!compact)
out << "\n";
return;
}
out << " :- ";
for (unsigned i = 0; i < m_tail_size; i++) {
if (i > 0)
out << ",";
out << "\n ";
if (!compact)
out << "\n";
out << " ";
if (is_neg_tail(i))
out << "not ";
app * t = get_tail(i);
if (ctx.is_predicate(t)) {
if (ctx.is_predicate(t))
output_predicate(ctx, t, out);
}
else {
else
out << mk_pp(t, m);
}
}
out << '.';
if (ctx.output_profile()) {
out << " {";
output_profile(out);
out << '}';
}
out << '\n';
if (m_proof) {
if (!compact)
out << '\n';
if (m_proof)
out << mk_pp(m_proof, m) << '\n';
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/muz/base/dl_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ namespace datalog {

void get_vars(ast_manager& m, ptr_vector<sort>& sorts) const;

void display(context & ctx, std::ostream & out) const;
void display(context & ctx, std::ostream & out, bool compact = false) const;

/**
\brief Return the name(s) associated with this rule. Plural for preprocessed (e.g. obtained by inlining) rules.
Expand Down
23 changes: 11 additions & 12 deletions src/muz/base/dl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,32 +320,31 @@ namespace datalog {
unsigned_vector & res, bool & identity);

template<class T>
void permutate_by_cycle(T & container, unsigned cycle_len, const unsigned * permutation_cycle) {
if (cycle_len<2) {
void permute_by_cycle(T& container, unsigned cycle_len, const unsigned * permutation_cycle) {
if (cycle_len < 2)
return;
}
auto aux = container[permutation_cycle[0]];
for (unsigned i=1; i<cycle_len; i++) {
container[permutation_cycle[i-1]]=container[permutation_cycle[i]];
}
container[permutation_cycle[cycle_len-1]]=aux;
verbose_stream() << "xx " << cycle_len << "\n";
for (unsigned i = 1; i < cycle_len; i++)
container[permutation_cycle[i-1]] = container[permutation_cycle[i]];
container[permutation_cycle[cycle_len-1]] = aux;
}

template<class T, class M>
void permutate_by_cycle(ref_vector<T,M> & container, unsigned cycle_len, const unsigned * permutation_cycle) {
void permute_by_cycle(ref_vector<T,M> & container, unsigned cycle_len, const unsigned * permutation_cycle) {
if (cycle_len<2) {
return;
}
verbose_stream() << "ptr\n";
T * aux = container.get(permutation_cycle[0]);
for (unsigned i=1; i<cycle_len; i++) {
for (unsigned i=1; i < cycle_len; i++) {
container.set(permutation_cycle[i-1], container.get(permutation_cycle[i]));
}
container.set(permutation_cycle[cycle_len-1], aux);
}

template<class T>
void permutate_by_cycle(T & container, const unsigned_vector & permutation_cycle) {
permutate_by_cycle(container, permutation_cycle.size(), permutation_cycle.data());
void permute_by_cycle(T & container, const unsigned_vector & permutation_cycle) {
permute_by_cycle(container, permutation_cycle.size(), permutation_cycle.data());
}


Expand Down
2 changes: 1 addition & 1 deletion src/muz/rel/dl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace datalog {
SASSERT(cycle_len>=2);
result=src;

permutate_by_cycle(result, cycle_len, permutation_cycle);
permute_by_cycle(result, cycle_len, permutation_cycle);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/muz/rel/dl_finite_product_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ namespace datalog {
unsigned sig_sz = r.get_signature().size();
unsigned_vector permutation;
add_sequence(0, sig_sz, permutation);
permutate_by_cycle(permutation, cycle_len, permutation_cycle);
permute_by_cycle(permutation, cycle_len, permutation_cycle);

unsigned_vector table_permutation;

Expand Down
37 changes: 20 additions & 17 deletions src/muz/rel/dl_mk_explanations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,16 @@ namespace datalog {
m_union_decl(mk_explanations::get_union_decl(get_context()), get_ast_manager()) {}

~explanation_relation_plugin() override {
for (unsigned i = 0; i < m_pool.size(); ++i) {
for (unsigned j = 0; j < m_pool[i].size(); ++j) {
for (unsigned i = 0; i < m_pool.size(); ++i)
for (unsigned j = 0; j < m_pool[i].size(); ++j)
dealloc(m_pool[i][j]);
}
}
}

bool can_handle_signature(const relation_signature & s) override {
unsigned n=s.size();
for (unsigned i=0; i<n; i++) {
if (!get_context().get_decl_util().is_rule_sort(s[i])) {
for (unsigned i=0; i<n; i++)
if (!get_context().get_decl_util().is_rule_sort(s[i]))
return false;
}
}
return true;
}

Expand All @@ -105,9 +101,10 @@ namespace datalog {
relation_intersection_filter_fn * mk_filter_by_negation_fn(const relation_base & t,
const relation_base & negated_obj, unsigned joined_col_cnt,
const unsigned * t_cols, const unsigned * negated_cols) override;
relation_intersection_filter_fn * mk_filter_by_intersection_fn(const relation_base & t,
const relation_base & src, unsigned joined_col_cnt,
const unsigned * t_cols, const unsigned * src_cols) override;
relation_intersection_filter_fn * mk_filter_by_intersection_fn(
const relation_base & t,
const relation_base & src, unsigned joined_col_cnt,
const unsigned * t_cols, const unsigned * src_cols) override;

};

Expand Down Expand Up @@ -150,7 +147,8 @@ namespace datalog {
void assign_data(const relation_fact & f) {
m_empty = false;

unsigned n=get_signature().size();
verbose_stream() << "assign data " << f << "\n";
unsigned n = get_signature().size();
SASSERT(f.size()==n);
m_data.reset();
m_data.append(n, f.data());
Expand All @@ -161,11 +159,13 @@ namespace datalog {
m_data.resize(get_signature().size());
}
void unite_with_data(const relation_fact & f) {
verbose_stream() << "unite data " << f << "\n";

if (empty()) {
assign_data(f);
return;
}
unsigned n=get_signature().size();
unsigned n = get_signature().size();
SASSERT(f.size()==n);
for (unsigned i=0; i<n; i++) {
SASSERT(!is_undefined(i));
Expand All @@ -186,6 +186,7 @@ namespace datalog {
void to_formula(expr_ref& fml) const override {
ast_manager& m = fml.get_manager();
fml = m.mk_eq(m.mk_var(0, m_data[0]->get_sort()), m_data[0]);
verbose_stream() << "FORMULA " << fml << "\n";
}

bool is_undefined(unsigned col_idx) const {
Expand Down Expand Up @@ -339,6 +340,7 @@ namespace datalog {
if (!r.empty()) {
relation_fact proj_data = r.m_data;
project_out_vector_columns(proj_data, m_removed_cols);
verbose_stream() << "project\n";
res->assign_data(proj_data);
}
return res;
Expand All @@ -365,9 +367,9 @@ namespace datalog {

explanation_relation * res = static_cast<explanation_relation *>(plugin.mk_empty(get_result_signature()));
if (!r.empty()) {
relation_fact permutated_data = r.m_data;
permutate_by_cycle(permutated_data, m_cycle);
res->assign_data(permutated_data);
relation_fact permuted_data = r.m_data;
permute_by_cycle(dynamic_cast<app_ref_vector&>(permuted_data), m_cycle);
res->assign_data(permuted_data);
}
return res;
}
Expand Down Expand Up @@ -406,6 +408,7 @@ namespace datalog {
}
else {
if (tgt.empty()) {
verbose_stream() << "union\n";
tgt.assign_data(src.m_data);
if (delta && delta->empty()) {
delta->assign_data(src.m_data);
Expand Down Expand Up @@ -704,7 +707,7 @@ namespace datalog {
symbol mk_explanations::get_rule_symbol(rule * r) {
if (r->name() == symbol::null) {
std::stringstream sstm;
r->display(m_context, sstm);
r->display(m_context, sstm, true);
std::string res = sstm.str();
res = res.substr(0, res.find_last_not_of('\n')+1);
return symbol(res.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/muz/rel/dl_relation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ namespace datalog {
}

void modify_fact(table_fact & f) const override {
permutate_by_cycle(f, m_cycle);
permute_by_cycle(f, m_cycle);
}

table_base * operator()(const table_base & t) override {
Expand Down
4 changes: 2 additions & 2 deletions src/muz/rel/dl_sieve_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ namespace datalog {
unsigned sig_sz = r.get_signature().size();
unsigned_vector permutation;
add_sequence(0, sig_sz, permutation);
permutate_by_cycle(permutation, cycle_len, permutation_cycle);
permute_by_cycle(permutation, cycle_len, permutation_cycle);

bool inner_identity;
unsigned_vector inner_permutation;
collect_sub_permutation(permutation, r.m_sig2inner, inner_permutation, inner_identity);

bool_vector result_inner_cols = r.m_inner_cols;
permutate_by_cycle(result_inner_cols, cycle_len, permutation_cycle);
permute_by_cycle(result_inner_cols, cycle_len, permutation_cycle);

relation_signature result_sig;
relation_signature::from_rename(r.get_signature(), cycle_len, permutation_cycle, result_sig);
Expand Down

0 comments on commit 9054e72

Please sign in to comment.