3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-04 02:10:23 +00:00

additional str/re operators, remove encoding option from zstring

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-05-17 05:08:36 -07:00
parent b2bfb1faea
commit 34cc60410f
9 changed files with 210 additions and 44 deletions

View file

@ -771,6 +771,59 @@ void seq_axioms::add_le_axiom(expr* n) {
add_axiom(~lt, le);
}
/**
is_digit(e) <=> e = '0' or ... or e = '9'
*/
void seq_axioms::add_is_digit_axiom(expr* n) {
expr* e = nullptr;
VERIFY(seq.str.is_is_digit(n, e));
literal is_digit = mk_literal(n);
literal_vector digits;
digits.push_back(~is_digit);
for (unsigned i = 0; i < 10; ++i) {
unsigned d = '0' + i;
zstring str(1, &d);
expr_ref s(seq.str.mk_string(str), m);
m_rewrite(s); // if the solver depends on unit normal form
literal digit_i = mk_eq(e, s);
digits.push_back(digit_i);
add_axiom(~digit_i, is_digit);
}
// literals are marked relevant by add_axiom of binary clauses
ctx().mk_th_axiom(th.get_id(), digits);
}
/**
len(e) = 1 => 0 <= to_code(e) <= max_code
len(e) != 1 => to_code(e) = -1
*/
void seq_axioms::add_str_to_code_axiom(expr* n) {
expr* e = nullptr;
VERIFY(seq.str.is_to_code(n, e));
literal len_is1 = mk_eq(mk_len(e), a.mk_int(1));
add_axiom(~len_is1, mk_ge(n, 0));
add_axiom(~len_is1, mk_le(n, seq.str.max_char_value()));
add_axiom(len_is1, mk_eq(n, a.mk_int(-1)));
}
/**
0 <= e <= max_char => len(from_code(e)) = 1
0 <= e <= max_char => to_code(from_code(e)) = e
e < 0 or e > max_char => len(from_code(e)) = ""
*/
void seq_axioms::add_str_from_code_axiom(expr* n) {
expr* e = nullptr;
VERIFY(seq.str.is_from_code(n, e));
literal ge = mk_ge(e, 0);
literal le = mk_le(e, seq.str.max_char_value());
literal emp = mk_literal(seq.str.mk_is_empty(n));
add_axiom(~ge, ~le, mk_eq(mk_len(n), a.mk_int(1)));
add_axiom(~ge, ~le, mk_eq(seq.str.mk_to_code(n), e));
add_axiom(ge, emp);
add_axiom(le, emp);
}
/**
Unit is injective: