/** \brief External interface for the simplifier. A client will invoke operator()(s, r, p) to simplify s. The result is stored in r. When proof generation is enabled, a proof for the equivalence (or equisatisfiability) of s and r is stored in p. When proof generation is disabled, this method stores the "undefined proof" object in p. */ void simplifier::operator()(expr * s, expr_ref & r, proof_ref & p) { m_need_reset = true; reinitialize(); expr * s_orig = s; expr * old_s; expr * result; proof * result_proof; switch (m.proof_mode()) { case PGM_DISABLED: // proof generation is disabled. reduce_core(s); // after executing reduce_core, the result of the simplification is in the cache get_cached(s, result, result_proof); r = result; p = m.mk_undef_proof(); break; case PGM_COARSE: // coarse proofs... in this case, we do not produce a step by step (fine grain) proof to show the equivalence (or equisatisfiability) of s an r. m_subst_proofs.reset(); // m_subst_proofs is an auxiliary vector that is used to justify substitutions. See comment on method get_subst. reduce_core(s); get_cached(s, result, result_proof); r = result; if (result == s) p = m.mk_reflexivity(s); else { remove_duplicates(m_subst_proofs); p = m.mk_rewrite_star(s, result, m_subst_proofs.size(), m_subst_proofs.c_ptr()); } break; case PGM_FINE: // fine grain proofs... in this mode, every proof step (or most of them) is described. m_proofs.reset(); old_s = 0; // keep simplyfing until no further simplifications are possible. while (s != old_s) { TRACE("simplifier", tout << "simplification pass... " << s->get_id() << "\n";); TRACE("simplifier_loop", tout << mk_ll_pp(s, m) << "\n";); reduce_core(s); get_cached(s, result, result_proof); SASSERT(is_rewrite_proof(s, result, result_proof)); if (result_proof != 0) { m_proofs.push_back(result_proof); } old_s = s; s = result; }
static json_object * fetch_favorite(int folder_id) { char url[500]; char name[100]; snprintf(url, 499, "%s/video/bookmarks/folders/%d/items.json?per_page=20", api_root, folder_id); snprintf(name, 99, "fav-%d", folder_id); json_object *root = get_cached(url, name); return root; }
void bit2int::operator()(expr * m, expr_ref & result, proof_ref& p) { flush_cache(); expr_reduce emap(*this); for_each_ast(emap, m); result = get_cached(m); if (m_manager.proofs_enabled() && m != result.get()) { // TBD: rough p = m_manager.mk_rewrite(m, result); } TRACE("bit2int", tout << mk_pp(m, m_manager) << "======>\n" << mk_pp(result, m_manager) << "\n";);
static struct movie_list * load() { char url[500]; json_object *root, *folders, *folder; int i; provider->error_number = 0; snprintf(url, 499, "%s/video/bookmarks/folders.json?per_page=20", api_root); root = get_cached(url, "favorites"); if (provider->error_number != 0) return NULL; folders = get_data(root, "folders"); int folders_count = json_object_array_length(folders); int folder_id = 0; for (i = 0; i < folders_count; i++) { folder = json_object_array_get_idx(folders, i); if (folder == NULL) { sprintf(last_error, "Cannot get folder[%d]", i); provider->error_number = 1; return NULL; } const char *title = get_str(folder, "title"); if (strcmp(title, "serge") == 0) { folder_id = get_int(folder, "id"); break; } } if (folder_id == 0) { sprintf(last_error, "cannot get my favorite folder"); provider->error_number = 1; return NULL; } root = fetch_favorite(folder_id); if (provider->error_number != 0) return NULL; struct movie_list *list = parse_favorites(root); return list; }
static char * get_stream_url(struct movie_entry *e) { char url[1000]; char name[100]; json_object *root; json_object *obj; json_bool jres; const char *format_ext = (e->format == SF_MP4) ? "mp4" : "wmv"; provider->error_number = 0; if (e->format == SF_MP4) { snprintf(url, 499, "%svideo/media/%d/watch.json?format=%s&protocol=hls&bitrate=%d", api_root, e->id, format_ext, e->bitrate); } else { snprintf(url, 499, "%svideo/media/%d/watch.json?format=%s&bitrate=%d", api_root, e->id, format_ext, e->bitrate); } snprintf(name, 99, "stream-%d", e->id); logi("fetch %s to %s", url, name); root = get_cached(url, name); if (provider->error_number != 0) return NULL; int status = get_int(root, "status_code"); if (status != 200) { sprintf(last_error, "get stream status: %d", status); provider->error_number = 1; return NULL; } jres = json_object_object_get_ex(root, "data", &obj); if (jres == FALSE) { sprintf(last_error, "Cannot get stream data"); provider->error_number = 1; return NULL; } char *stream_url = strdup(get_str(obj, "url")); json_object_put(root); return stream_url; }
void distribute_forall::operator()(expr * f, expr_ref & result) { m_todo.reset(); flush_cache(); m_todo.push_back(f); while (!m_todo.empty()) { expr * e = m_todo.back(); if (visit_children(e)) { m_todo.pop_back(); reduce1(e); } } result = get_cached(f); SASSERT(result!=0); TRACE("distribute_forall", tout << mk_ll_pp(f, m_manager) << "======>\n" << mk_ll_pp(result, m_manager););
void distribute_forall::reduce1_quantifier(quantifier * q) { // This transformation is applied after skolemization/quantifier elimination. So, all quantifiers are universal. SASSERT(q->is_forall()); // This transformation is applied after basic pre-processing steps. // So, we can assume that // 1) All (and f1 ... fn) are already encoded as (not (or (not f1 ... fn))) // 2) All or-formulas are flat (or f1 (or f2 f3)) is encoded as (or f1 f2 f3) expr * e = get_cached(q->get_expr()); if (m_manager.is_not(e) && m_manager.is_or(to_app(e)->get_arg(0))) { // found target for simplification // (forall X (not (or F1 ... Fn))) // --> // (and (forall X (not F1)) // ... // (forall X (not Fn))) app * or_e = to_app(to_app(e)->get_arg(0)); unsigned num_args = or_e->get_num_args(); expr_ref_buffer new_args(m_manager); for (unsigned i = 0; i < num_args; i++) { expr * arg = or_e->get_arg(i); expr_ref not_arg(m_manager); // m_bsimp.mk_not applies basic simplifications. For example, if arg is of the form (not a), then it will return a. m_bsimp.mk_not(arg, not_arg); quantifier_ref tmp_q(m_manager); tmp_q = m_manager.update_quantifier(q, not_arg); expr_ref new_q(m_manager); elim_unused_vars(m_manager, tmp_q, new_q); new_args.push_back(new_q); } expr_ref result(m_manager); // m_bsimp.mk_and actually constructs a (not (or ...)) formula, // it will also apply basic simplifications. m_bsimp.mk_and(new_args.size(), new_args.c_ptr(), result); cache_result(q, result); } else { cache_result(q, m_manager.update_quantifier(q, e)); } }
void distribute_forall::reduce1_app(app * a) { SASSERT(a); unsigned num_args = a->get_num_args(); unsigned j = num_args; bool reduced = false; m_new_args.reserve(num_args); app * na = a; while(j > 0) { --j; SASSERT(is_cached(a->get_arg(j))); expr * c = get_cached(a->get_arg(j)); SASSERT(c!=0); if (c != a->get_arg(j)) reduced = true; m_new_args[j] = c; } if (reduced) { na = m_manager.mk_app(a->get_decl(), num_args, m_new_args.c_ptr()); } cache_result(a, na); }
static struct movie_entry * get_movie(int parent_id, int idx) { char url[500]; char name[100]; json_object *root, *children, *child; provider->error_number = 0; int page = (idx / 20) + 1; int pos_on_page = idx - (page - 1) * 20; snprintf(url, 499, "%s/video/media/%d/children.json?page=%d&per_page=20&order_by=on_air", api_root, parent_id, page); snprintf(name, 99, "child-%d-%d", parent_id, idx); logi("fetch %s to %s", url, name); root = get_cached(url, name); if (provider->error_number != 0) { return NULL; } children = get_data(root, "children"); int children_count = json_object_array_length(children); if (pos_on_page >= children_count) { sprintf(last_error, "cannot get child by idx %d", idx); provider->error_number = 1; return NULL; } child = json_object_array_get_idx(children, pos_on_page); struct movie_entry *e = create_movie(child); return e; }
const char* get_cached_groupname(gid_t gid) { return get_cached(&groupname, gid, bb_getgrgid); }
const char* get_cached_username(uid_t uid) { return get_cached(&username, uid, bb_getpwuid); }