Skip to content

Commit

Permalink
add 'distinct' to MCMT
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejan Jovanovic committed Sep 29, 2020
1 parent 643788c commit 750ff79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/mcmt/mcmt.g
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ term returns [expr::term_ref t = expr::term_ref()]
t = STATE->tm().mk_term(expr::TERM_NOT, t);
}
')'
// Sally syntactic sugar functions
| '(' 'distinct' term_list[children] ')' { t = STATE->mk_distinct(children); }
;

let_assignments
Expand Down
14 changes: 14 additions & 0 deletions src/parser/mcmt/mcmt_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ expr::term_ref mcmt_state::mk_cond(const std::vector<expr::term_ref>& children)
return result;
}

expr::term_ref mcmt_state::mk_distinct(const std::vector<expr::term_ref>& children) {
assert(children.size() >= 2);

std::vector<expr::term_ref> conjuncts;
for (unsigned i = 0; i < children.size(); ++ i) {
for (unsigned j = i + 1; j < children.size(); ++ j) {
term_ref eq = tm().mk_term(expr::TERM_EQ, children[i], children[j]);
conjuncts.push_back(tm().mk_not(eq));
}
}
return tm().mk_and(conjuncts);
}


bool mcmt_state::lsal_extensions() const {
return ctx().get_options().get_bool("lsal-extensions");
}
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mcmt/mcmt_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class mcmt_state {
*/
expr::term_ref mk_cond(const std::vector<expr::term_ref>& children);

/** Make a distinct term */
expr::term_ref mk_distinct(const std::vector<expr::term_ref>& children);

/** Get the string of a token begin parsed */
static
std::string token_text(pANTLR3_COMMON_TOKEN token);
Expand Down

0 comments on commit 750ff79

Please sign in to comment.