bool macro_util::is_arith_macro(expr * n, unsigned num_decls, app_ref & head, expr_ref & def, bool & inv) const { // TODO: obsolete... we should move to collect_arith_macro_candidates arith_simplifier_plugin * as = get_arith_simp(); if (!m_manager.is_eq(n) && !as->is_le(n) && !as->is_ge(n)) return false; expr * lhs = to_app(n)->get_arg(0); expr * rhs = to_app(n)->get_arg(1); if (!as->is_numeral(rhs)) return false; inv = false; ptr_buffer<expr> args; expr * h = 0; unsigned lhs_num_args; expr * const * lhs_args; if (is_add(lhs)) { lhs_num_args = to_app(lhs)->get_num_args(); lhs_args = to_app(lhs)->get_args(); } else { lhs_num_args = 1; lhs_args = &lhs; } for (unsigned i = 0; i < lhs_num_args; i++) { expr * arg = lhs_args[i]; expr * neg_arg; if (h == 0 && is_macro_head(arg, num_decls) && !is_forbidden(to_app(arg)->get_decl()) && !poly_contains_head(lhs, to_app(arg)->get_decl(), arg)) { h = arg; } else if (h == 0 && as->is_times_minus_one(arg, neg_arg) && is_macro_head(neg_arg, num_decls) && !is_forbidden(to_app(neg_arg)->get_decl()) && !poly_contains_head(lhs, to_app(neg_arg)->get_decl(), arg)) { h = neg_arg; inv = true; } else { args.push_back(arg); } } if (h == 0) return false; head = to_app(h); expr_ref tmp(m_manager); as->mk_add(args.size(), args.c_ptr(), tmp); if (inv) as->mk_sub(tmp, rhs, def); else as->mk_sub(rhs, tmp, def); return true; }
int check_password(char* password) { int i, j; int increasing = 1; int forbidden = 0; int pairs = 0; for (i = 0; i < LENGTH; i++) { if (is_forbidden(password[i])) { forbidden = 1; break; } if (increasing < 3) { /* haven't found increasing subsequence yet! */ increasing = 1; j = i; while (j < LENGTH - 1 && password[j] == password[j + 1] - 1) { increasing++; j++; } } /* there's not point in checking just last two characters */ if (!pairs && i < LENGTH - 3) { if (password[i] == password[i + 1]) { for (j = i + 2; j < LENGTH - 1; j++) { if (password[j] == password[j + 1] && password[i] != password[j]) pairs = 1; } } } } return !forbidden && increasing >= 3 && pairs; }
void operator()(app * n) { func_decl * decl = to_app(n)->get_decl(); if (is_forbidden(decl)) { warning_msg("'%s' cannot be used in patterns.", decl->get_name().str().c_str()); m_result = false; } }
/** \brief Return true if n is of the form (= t (f x_{k_1}, ..., x_{k_n})) OR (iff t (f x_{k_1}, ..., x_{k_n})) where is_macro_head((f x_{k_1}, ..., x_{k_n})) returns true AND t does not contain f AND f is not in forbidden_set In case of success head will contain (f x_{k_1}, ..., x_{k_n}) AND def will contain t */ bool macro_util::is_right_simple_macro(expr * n, unsigned num_decls, app * & head, expr * & def) const { if (m_manager.is_eq(n) || m_manager.is_iff(n)) { expr * lhs = to_app(n)->get_arg(0); expr * rhs = to_app(n)->get_arg(1); if (is_macro_head(rhs, num_decls) && !is_forbidden(to_app(rhs)->get_decl()) && !occurs(to_app(rhs)->get_decl(), lhs)) { head = to_app(rhs); def = lhs; return true; } } return false; }
/* returns next password without forbidden characters */ void next(char* password) { int i, j; for (j = 0; j < LENGTH; j++) { if (is_forbidden(password[j])) { break; } } for (i = LENGTH - 1; i >= 0; i--) { if (i > j) { /* if it's after the forbidden char, just set it to 'a' */ password[i] = 'a'; } else if (password[i] == 'z') { password[i] = 'a'; } else { password[i]++; break; } } }