vm_obj nat_decidable_lt(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { return mk_vm_bool(cidx(a1) < cidx(a2)); } else { return mk_vm_bool(to_mpz1(a1) < to_mpz2(a2)); } }
static expr *expr2(int critical) { expr *e, *f; e = expr3(critical); if (!e) return NULL; while (i == '&') { i = scan(scpriv, tokval); f = expr3(critical); if (!f) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { nasm_error(ERR_NONFATAL, "`&' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) e = unknown_expr(); else e = scalarvect(reloc_value(e) & reloc_value(f)); } return e; }
vm_obj nat_has_decidable_eq(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { return mk_vm_bool(cidx(a1) == cidx(a2)); } else { return mk_vm_bool(to_mpz1(a1) == to_mpz2(a2)); } }
static expr *expr3(int critical) { expr *e, *f; e = expr4(critical); if (!e) return NULL; while (i == TOKEN_SHL || i == TOKEN_SHR) { int j = i; i = scan(scpriv, tokval); f = expr4(critical); if (!f) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { nasm_error(ERR_NONFATAL, "shift operator may only be applied to" " scalar values"); } else if (is_just_unknown(e) || is_just_unknown(f)) { e = unknown_expr(); } else switch (j) { case TOKEN_SHL: e = scalarvect(reloc_value(e) << reloc_value(f)); break; case TOKEN_SHR: e = scalarvect(((uint64_t)reloc_value(e)) >> reloc_value(f)); break; } } return e; }
vm_obj nat_add(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { return mk_vm_nat(cidx(a1) + cidx(a2)); } else { return mk_vm_mpz(to_mpz1(a1) + to_mpz2(a2)); } }
static expr *rexp1(int critical) { expr *e, *f; e = rexp2(critical); if (!e) return NULL; while (i == TOKEN_DBL_XOR) { i = scan(scpriv, tokval); f = rexp2(critical); if (!f) return NULL; if (!(is_simple(e) || is_just_unknown(e)) || !(is_simple(f) || is_just_unknown(f))) { nasm_error(ERR_NONFATAL, "`^' operator may only be applied to" " scalar values"); } if (is_just_unknown(e) || is_just_unknown(f)) e = unknown_expr(); else e = scalarvect((int64_t)(!reloc_value(e) ^ !reloc_value(f))); } return e; }
vm_obj nat_mul(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { unsigned long long r = static_cast<unsigned long long>(cidx(a1)) * static_cast<unsigned long long>(cidx(a2)); if (r < LEAN_MAX_SMALL_NAT) { return mk_vm_simple(r); } } return mk_vm_mpz(to_mpz1(a1) * to_mpz2(a2)); }
vm_obj put_nat(vm_obj const & n, vm_obj const &) { if (is_simple(n)) std::cout << cidx(n); else std::cout << to_mpz(n); return mk_vm_unit(); }
TEST(Graph, MakeSimple) { Graph G(5); // replace by "random graph" G.add_edge(0, 1); G.add_edge(0, 1); G.add_edge(1, 0); G.add_edge(2, 1); G.add_edge(4, 1); G.add_edge(1, 4); G.add_edge(0, 1); G.add_edge(2, 3); G.add_edge(3, 2); G.add_edge(3, 2); G.add_edge(4, 0); G.add_edge(0, 0); G.add_edge(0, 0); G.add_edge(1, 1); G.add_edge(2, 2); G.add_edge(3, 3); ASSERT_FALSE(is_simple(G)); G.make_simple(); for (auto v : G.vertices()) { std::set<int> neighbors; for (auto u : G.neighbors(v)) { ASSERT_TRUE(u != v); // no loops neighbors.insert(u); } ASSERT_EQ(neighbors.size(), G.degree(v)); } }
// Check for: // SAVE_LAYER // SAVE // CLIP_RECT // DRAW_BITMAP_RECT_TO_RECT // RESTORE // RESTORE // where the saveLayer's color can be moved into the drawBitmapRect static bool check_1(SkDebugCanvas* canvas, int curCommand) { if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || canvas->getSize() <= curCommand+5 || SAVE != canvas->getDrawCommandAt(curCommand+1)->getType() || CLIP_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+3)->getType() || RESTORE != canvas->getDrawCommandAt(curCommand+4)->getType() || RESTORE != canvas->getDrawCommandAt(curCommand+5)->getType()) { return false; } SkSaveLayerCommand* saveLayer = (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); SkDrawBitmapRectCommand* dbmr = (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3); const SkPaint* saveLayerPaint = saveLayer->paint(); SkPaint* dbmrPaint = dbmr->paint(); // For this optimization we only fold the saveLayer and drawBitmapRect // together if the saveLayer's draw is simple (i.e., no fancy effects) and // and the only difference in the colors is that the saveLayer's can have // an alpha while the drawBitmapRect's is opaque. // TODO: it should be possible to fold them together even if they both // have different non-255 alphas but this is low priority since we have // never seen that case // If either operation lacks a paint then the collapse is trivial SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque return NULL == saveLayerPaint || NULL == dbmrPaint || (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); }
static int is_simple(EXPRESSION *expr) { if (is_atomic(expr)) return 1; if (is_binary_op(expr)) { return is_atomic(tree_get_child(expr, 0)) && is_atomic(tree_get_child(expr, 1)); } if (tree_is_type(expr, EXPR_CALL)) { return is_atomic(tree_get_child(expr, 1)); } if (tree_is_type(expr, EXPR_TUPLE)) { int i; for (i = 0; i < tree_num_children(expr); i++) if (!is_simple(tree_get_child(expr, i))) return 0; return 1; } return 0; }
// Check for: // SAVE_LAYER // DRAW_BITMAP_RECT_TO_RECT // RESTORE // where the saveLayer's color can be moved into the drawBitmapRect static bool check_0(SkDebugCanvas* canvas, int curCommand) { if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || canvas->getSize() <= curCommand+2 || DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || RESTORE != canvas->getDrawCommandAt(curCommand+2)->getType()) { return false; } SkSaveLayerCommand* saveLayer = (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand); SkDrawBitmapRectCommand* dbmr = (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1); const SkPaint* saveLayerPaint = saveLayer->paint(); SkPaint* dbmrPaint = dbmr->paint(); // For this optimization we only fold the saveLayer and drawBitmapRect // together if the saveLayer's draw is simple (i.e., no fancy effects) // and the only difference in the colors is their alpha value SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaque // If either operation lacks a paint then the collapse is trivial return NULL == saveLayerPaint || NULL == dbmrPaint || (is_simple(*saveLayerPaint) && dbmrColor == layerColor); }
vm_obj nat_succ(vm_obj const & a) { if (is_simple(a)) { return mk_vm_nat(cidx(a) + 1); } else { return mk_vm_mpz(to_mpz1(a) + 1); } }
vm_obj put_nat(vm_obj const & n, vm_obj const &) { if (is_simple(n)) get_global_ios().get_regular_stream() << cidx(n); else get_global_ios().get_regular_stream() << to_mpz(n); return mk_vm_unit(); }
optional<head_index> get_head_index(unsigned num, transition const * ts, expr const & a) { if (is_simple(num, ts)) { expr n = expand_pp_pattern(num, ts, a); if (!is_var(n)) return some(head_index(n)); } return optional<head_index>(); }
vm_obj nat_sub(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { unsigned v1 = cidx(a1); unsigned v2 = cidx(a2); if (v2 > v1) return mk_vm_simple(0); else return mk_vm_nat(v1 - v2); } else { mpz const & v1 = to_mpz1(a1); mpz const & v2 = to_mpz2(a2); if (v2 > v1) return mk_vm_simple(0); else return mk_vm_nat(v1 - v2); } }
vm_obj nat_mod(vm_obj const & a1, vm_obj const & a2) { if (is_simple(a1) && is_simple(a2)) { unsigned v1 = cidx(a1); unsigned v2 = cidx(a2); if (v2 == 0) return a1; else return mk_vm_nat(v1 % v2); } else { mpz const & v1 = to_mpz1(a1); mpz const & v2 = to_mpz2(a2); if (v2 == 0) return a1; else return mk_vm_nat(v1 % v2); } }
vm_obj nat_to_string(vm_obj const & a) { std::ostringstream out; if (is_simple(a)) { out << cidx(a); } else { out << to_mpz(a); } return to_obj(out.str()); }
static mpz const & to_mpz2(vm_obj const & o) { if (is_simple(o)) { mpz & r = get_mpz2(); r = cidx(o); return r; } else { return to_mpz(o); } }
optional<unsigned> try_to_unsigned(vm_obj const & o) { if (is_simple(o)) { return optional<unsigned>(cidx(o)); } else { mpz const & v = to_mpz(o); if (v.is_unsigned_int()) return optional<unsigned>(v.get_unsigned_int()); else return optional<unsigned>(); } }
// meta_constant level.instantiate : level → list (name × level) → list level vm_obj level_instantiate(vm_obj const & o, vm_obj const & lst) { level const & l = to_level(o); buffer<name> ns; buffer<level> ls; vm_obj it = lst; while (!is_simple(it)) { vm_obj const & h = cfield(it, 0); ns.push_back(to_name(cfield(h, 0))); ls.push_back(to_level(cfield(h, 1))); it = cfield(it, 1); } return to_obj(instantiate(l, to_list(ns), to_list(ls))); }
void lex_stream_t::implementation_t::parse_token(char c) { stream_lex_token_t result; if (!( is_number(c, result) || is_identifier_or_keyword(c, result) || is_comment(c, result) || is_string(c,result) || is_compound(c, result) || is_simple(c, result))) { throw_parser_exception("Syntax Error"); } put_token(adobe::move(result)); }
TEST(Graph, RemoveVertex) { int n = 5; Graph G = graphs::Complete(n + 1); G.remove_vertex(2); ASSERT_EQ(G.num_vertices(), n); ASSERT_EQ(G.num_edges(), n*(n - 1)/2); for (auto v : G.vertices()) { ASSERT_EQ(G.degree(v), n - 1); } ASSERT_TRUE(is_simple(G)); ASSERT_TRUE(is_connected(G)); }
/* * Needle is based on haystack if both contain a long enough common * substring and needle would be too simple for a password with the * substring removed. */ static int is_based(passwdqc_params_t *params, const char *haystack, const char *needle, const char *original) { char *scratch; int length; int i, j; const char *p; int match; if (!params->match_length) /* disabled */ return 0; if (params->match_length < 0) /* misconfigured */ return 1; if (strstr(haystack, needle)) /* based on haystack entirely */ return 1; scratch = NULL; length = strlen(needle); for (i = 0; i <= length - params->match_length; i++) for (j = params->match_length; i + j <= length; j++) { match = 0; for (p = haystack; *p; p++) if (*p == needle[i] && !strncmp(p, &needle[i], j)) { match = 1; if (!scratch) { if (!(scratch = malloc(length + 1))) return 1; } memcpy(scratch, original, i); memcpy(&scratch[i], &original[i + j], length + 1 - (i + j)); if (is_simple(params, scratch)) { clean(scratch); return 1; } } if (!match) break; } clean(scratch); return 0; }
vm_obj nat_repeat(vm_obj const &, vm_obj const & f, vm_obj const & n, vm_obj const & a) { if (is_simple(n)) { unsigned _n = cidx(n); vm_obj r = a; for (unsigned i = 0; i < _n ; i++) { r = invoke(f, mk_vm_simple(i), r); } return r; } else { mpz _n = to_mpz(n); mpz i(0); vm_obj r = a; while (i < _n) { r = invoke(f, mk_vm_nat(i), r); i++; } return r; } }
unsigned list_cases_on(vm_obj const & o, buffer<vm_obj> & data) { if (is_simple(o)) { return 0; } else if (is_constructor(o)) { data.append(csize(o), cfields(o)); return 1; } else { lean_assert(is_external(o)); if (auto l = dynamic_cast<vm_list<name>*>(to_external(o))) { return list_cases_on_core(l->m_val, data); } else if (auto l = dynamic_cast<vm_list<expr>*>(to_external(o))) { return list_cases_on_core(l->m_val, data); } else if (auto l = dynamic_cast<vm_list<level>*>(to_external(o))) { return list_cases_on_core(l->m_val, data); } else { lean_unreachable(); } } }
int main() { long N; bool flag = false; printf("Enter N: "); scanf("%ld",&N); fflush(stdin); flag = is_simple(N); if(flag) { printf("Yes!"); } else { printf("No!"); } _getch(); }
complex_item* types_visitor::deserialize_complex_item() { uint type; is->read((char*)&type, sizeof(uint)); complex_item* ci = create_complex_item(type); simple_item* new_si; if(is_simple(type)) { new_si = deserialize_simple_item(type); ci->type = COMPLEX_SIMPLE; ci->data._simple = new_si; return ci; } vector< complex_item* >* new_tuple; set< complex_item* >* new_bag; map< simple_item*, complex_item* >* new_map; (void)new_tuple; (void)new_bag; (void)new_map; switch(type) { case COMPLEX_TUPLE: new_tuple = deserialize_tuple(); ci->type = COMPLEX_TUPLE; ci->data._tuple = new_tuple; break; case COMPLEX_BAG: new_bag = deserialize_bag(); ci->type = COMPLEX_BAG; ci->data._bag = new_bag; break; case COMPLEX_MAP: new_map = deserialize_map(); ci->type = COMPLEX_MAP; ci->data._map = new_map; break; default: cerr << "encountered unknown type"; break; // TODO: throw something here } return ci; }
/** \brief Given \c a, an expression that is the denotation of an expression, if \c a is a variable, then use the actions in the transitions \c ts to expand \c a. The idea is to produce a head symbol we can use to decide whether the notation should be considered during pretty printing. \see get_head_index */ static expr expand_pp_pattern(unsigned num, transition const * ts, expr const & a) { lean_assert(is_simple(num, ts)); if (!is_var(a)) return a; return replace(a, [&](expr const & e) { if (is_var(e)) { unsigned vidx = var_idx(e); unsigned i = num; unsigned offset = 0; while (i > 0) { --i; action const & act = ts[i].get_action(); switch (act.kind()) { case action_kind::Binder: case action_kind::Binders: case action_kind::Skip: break; case action_kind::Ext: case action_kind::LuaExt: lean_unreachable(); case action_kind::Expr: if (vidx == 0) return none_expr(); offset++; vidx--; break; case action_kind::Exprs: if (vidx == 0) return some_expr(lift_free_vars(act.get_rec(), offset)); offset++; vidx--; break; case action_kind::ScopedExpr: if (vidx == 0) return some_expr(lift_free_vars(act.get_rec(), offset)); offset++; vidx--; break; } } return none_expr(); } else { return none_expr(); } }); }
/** Implement two different signatures: 1) throwable -> options -> format 2) throwable -> unit -> format */ vm_obj throwable_to_format(vm_obj const & _ex, vm_obj const & _opts) { throwable * ex = to_throwable(_ex); if (!ex) return to_obj(format("null-exception")); if (auto kex = dynamic_cast<ext_exception*>(ex)) { if (is_simple(_opts)) { io_state_stream ios = tout(); formatter fmt = ios.get_formatter(); return to_obj(kex->pp(fmt)); } else { options opts = to_options(_opts); scope_trace_env scope1(opts); io_state_stream ios = tout(); formatter fmt = ios.get_formatter(); return to_obj(kex->pp(fmt)); } } else if (auto fex = dynamic_cast<formatted_exception*>(ex)) { return to_obj(fex->pp()); } else { return to_obj(format(ex->what())); } }