/** \brief Auxiliary function for is_pseudo_predicate_macro. It detects the pattern (= (f X) t) */ bool macro_util::is_pseudo_head(expr * n, unsigned num_decls, app * & head, app * & t) { if (!m_manager.is_eq(n)) return false; expr * lhs = to_app(n)->get_arg(0); expr * rhs = to_app(n)->get_arg(1); if (!is_ground(lhs) && !is_ground(rhs)) return false; sort * s = m_manager.get_sort(lhs); if (m_manager.is_uninterp(s)) return false; sort_size sz = s->get_num_elements(); if (sz.is_finite() && sz.size() == 1) return false; if (is_macro_head(lhs, num_decls)) { head = to_app(lhs); t = to_app(rhs); return true; } if (is_macro_head(rhs, num_decls)) { head = to_app(rhs); t = to_app(lhs); return true; } return false; }
/** \brief Check whether the variable in t1 occurs in t2. */ bool lpo::occurs(expr_offset const & t1, expr_offset const & t2) { SASSERT(is_var(t1.get_expr())); if (is_ground(t2.get_expr())) return false; m_todo.reset(); m_todo.push_back(t2); while (!m_todo.empty()) { expr_offset t = m_todo.back(); m_todo.pop_back(); t = find(t); expr * n = t.get_expr(); if (is_ground(n)) continue; unsigned offset = t.get_offset(); unsigned j; switch (n->get_kind()) { case AST_VAR: if (t == t1) return true; break; case AST_APP: j = to_app(n)->get_num_args(); while (j > 0) { --j; expr * arg = to_app(n)->get_arg(j); if (!is_ground(arg)) m_todo.push_back(expr_offset(arg, offset)); } break; default: UNREACHABLE(); } } return false; }
/** \brief Find bounds of the form (<= x k) (<= (+ x (* -1 y)) k) (<= (+ x (* -1 t)) k) (<= (+ t (* -1 x)) k) x and y are a bound variables, t is a ground term and k is a numeral It also detects >=, and the atom can be negated. */ bool elim_bounds::is_bound(expr * n, var * & lower, var * & upper) { upper = 0; lower = 0; bool neg = false; if (m_manager.is_not(n)) { n = to_app(n)->get_arg(0); neg = true; } bool le = false; if (m_util.is_le(n)) { SASSERT(m_util.is_numeral(to_app(n)->get_arg(1))); n = to_app(n)->get_arg(0); le = true; } else if (m_util.is_ge(n)) { SASSERT(m_util.is_numeral(to_app(n)->get_arg(1))); n = to_app(n)->get_arg(0); le = false; } else { return false; } if (neg) le = !le; if (is_var(n)) { upper = to_var(n); } else if (m_util.is_add(n) && to_app(n)->get_num_args() == 2) { expr * arg1 = to_app(n)->get_arg(0); expr * arg2 = to_app(n)->get_arg(1); if (is_var(arg1)) upper = to_var(arg1); else if (!is_ground(arg1)) return false; rational k; bool is_int; if (m_util.is_mul(arg2) && m_util.is_numeral(to_app(arg2)->get_arg(0), k, is_int) && k.is_minus_one()) { arg2 = to_app(arg2)->get_arg(1); if (is_var(arg2)) lower = to_var(arg2); else if (!is_ground(arg2)) return false; // not supported } else { return false; // not supported } } else { return false; } if (!le) std::swap(upper, lower); return true; }
/** \brief Find bounds of the form (<= x k) (<= (+ x (* -1 y)) k) (<= (+ x (* -1 t)) k) (<= (+ t (* -1 x)) k) x and y are a bound variables, t is a ground term and k is a numeral It also detects >=, and the atom can be negated. */ bool elim_bounds_cfg::is_bound(expr * n, var * & lower, var * & upper) { upper = nullptr; lower = nullptr; bool neg = false; if (m.is_not(n)) { n = to_app(n)->get_arg(0); neg = true; } expr* l = nullptr, *r = nullptr; bool le = false; if (m_util.is_le(n, l, r) && m_util.is_numeral(r)) { n = l; le = true; } else if (m_util.is_ge(n, l, r) && m_util.is_numeral(r)) { n = l; le = false; } else { return false; } if (neg) le = !le; if (is_var(n)) { upper = to_var(n); } else if (m_util.is_add(n, l, r)) { expr * arg1 = l; expr * arg2 = r; if (is_var(arg1)) upper = to_var(arg1); else if (!is_ground(arg1)) return false; rational k; bool is_int; if (m_util.is_mul(arg2) && m_util.is_numeral(to_app(arg2)->get_arg(0), k, is_int) && k.is_minus_one()) { arg2 = to_app(arg2)->get_arg(1); if (is_var(arg2)) lower = to_var(arg2); else if (!is_ground(arg2)) return false; // not supported } else { return false; // not supported } } else { return false; } if (!le) std::swap(upper, lower); return true; }
func_entry::func_entry(ast_manager & m, unsigned arity, expr * const * args, expr * result): m_args_are_values(true), m_result(result) { SASSERT(is_ground(result)); m.inc_ref(result); for (unsigned i = 0; i < arity; i++) { expr * arg = args[i]; SASSERT(is_ground(arg)); if (!m.is_value(arg)) m_args_are_values = false; m.inc_ref(arg); m_args[i] = arg; } }
void complex_literal_selection::operator()(clause * cls) { // look for x != y unsigned num = cls->get_num_literals(); for (unsigned i = 0; i < num; i++) { literal & l = cls->get_literal(i); if (l.sign() && m_manager.is_eq(l.atom()) && is_var(to_app(l.atom())->get_arg(0)) && is_var(to_app(l.atom())->get_arg(1))) { cls->select_literal(i); return; } } // look for min ground neg literal bool found = false; unsigned target = UINT_MAX; unsigned best_count = UINT_MAX; for (unsigned i = 0; i < num; i++) { literal & l = cls->get_literal(i); if (l.sign() && is_ground(l.atom())) { unsigned count = get_symbol_count(l.atom()); if (count < best_count) { found = true; target = i; best_count = count; } } } if (found) { cls->select_literal(target); return; } diff_literal_selection::operator()(cls); }
/* Incrementally find ground level from 3d noise */ s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision) { // Start a bit fuzzy to make averaging lower precision values // more useful s16 level = myrand_range(-precision/2, precision/2); s16 dec[] = {31000, 100, 20, 4, 1, 0}; s16 i; for(i = 1; dec[i] != 0 && precision <= dec[i]; i++) { // First find non-ground by going upwards // Don't stop in caves. { s16 max = level+dec[i-1]*2; v3s16 p(p2d.X, level, p2d.Y); for(; p.Y < max; p.Y += dec[i]) { if(!is_ground(seed, p)) { level = p.Y; break; } } } // Then find ground by going downwards from there. // Go in caves, too, when precision is 1. { s16 min = level-dec[i-1]*2; v3s16 p(p2d.X, level, p2d.Y); for(; p.Y>min; p.Y-=dec[i]) { bool ground = is_ground(seed, p); /*if(dec[i] == 1 && is_cave(seed, p)) ground = false;*/ if(ground) { level = p.Y; break; } } } } // This is more like the actual ground level level += dec[i-1]/2; return level; }
void operator()(app * n) { // We do not need to track dependencies on constants ... if (n->get_num_args()==0) return; if (m_ng_only && is_ground(n)) return; // ... and interpreted function symbols func_decl * d = n->get_decl(); if (d->get_family_id() == null_family_id) { m_set.insert(d); } }
void quick_checker::collector::collect(expr * n, func_decl * f, unsigned idx) { if (is_quantifier(n)) return; if (is_var(n)) return; if (is_ground(n)) return; entry e(n, f, idx); if (m_cache.contains(e)) return; m_cache.insert(e); collect_core(to_app(n), f, idx); }
/** \brief Return true if the interpretation represents the constant function. */ bool func_interp::is_constant() const { if (is_partial()) return false; if (!is_ground(m_else)) return false; ptr_vector<func_entry>::const_iterator it = m_entries.begin(); ptr_vector<func_entry>::const_iterator end = m_entries.end(); for (; it != end; ++it) { func_entry * curr = *it; if (curr->get_result() != m_else) return false; } return true; }
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) { if (num == 0) return BR_FAILED; family_id fid = f->get_family_id(); if (fid == null_family_id) return BR_FAILED; for (unsigned i = 0; i < num; i++) { if (!is_ground(args[i])) return BR_FAILED; // non-ground terms are not handled. } app * u = nullptr; if (fid == m().get_basic_family_id()) u = process_basic_app(f, num, args); else if (fid == m_a_util.get_family_id()) u = process_arith_app(f, num, args); else if (fid == m_bv_util.get_family_id()) u = process_bv_app(f, num, args); else if (fid == m_ar_util.get_family_id()) u = process_array_app(f, num, args); else if (fid == m_dt_util.get_family_id()) u = process_datatype_app(f, num, args); if (u == nullptr) return BR_FAILED; result = u; if (m_produce_proofs) { expr * s = m().mk_app(f, num, args); expr * eq = m().mk_eq(s, u); proof * pr1 = m().mk_def_intro(eq); result_pr = m().mk_apply_def(s, u, pr1); } return BR_DONE; }
void ray_cast(t_raycaster *r, t_map *map) { int counting; int hit; hit = 0; counting = 100; while (hit == 0 && counting--) { if ((r->side = r->side_dist.x >= r->side_dist.y) == 0) { r->side_dist.x += r->delta_dist.x; r->map.x += r->step.x; } else { r->side_dist.y += r->delta_dist.y; r->map.y += r->step.y; } hit = !is_ground(tile_at_index(map, r->map.x, r->map.y)); } inspect_wall(r); }
static void move_unit(game_t * game,int key) { int new_x; int new_y; int side; int target_tile; uint8_t move_flag; encounter_t * enc; unit_t * unit; unit_list_t * ulist; if(selected_group==NULL) { return; } ulist = (unit_list_t *)selected_group->data; unit = (unit_t*)ulist->data; new_x = unit->x; new_y = unit->y; side = unit->side; switch( key ) { case SDLK_ESCAPE: return; case SDLK_KP_1: new_x--; new_y++; break; case SDLK_KP_2: new_y++; break; case SDLK_KP_3: new_x++; new_y++; break; case SDLK_KP_4: new_x--; break; case SDLK_KP_6: new_x++; break; case SDLK_KP_7: new_x--; new_y--; break; case SDLK_KP_8: new_y--; break; case SDLK_KP_9: new_x++; new_y--; break; default: return; break; } if(new_x<0) { new_x = DEF_MAP_W-1; } if(new_x>=DEF_MAP_W) { new_x = 0; } if(new_y<0) { new_y = 0; } if(new_y>=DEF_MAP_H) { new_y = DEF_MAP_H-1; } /* Test destination tile cost and event */ target_tile = game->map->side[side].tile[new_x][new_y]; /* FIXME only take first unit flag into account */ move_flag = unit->def->move_flag; /* Type of tile : cost */ if(!is_ground(target_tile)) { if( (move_flag & MOVE_SWIM) || (move_flag & MOVE_SAIL)) { ulist = (unit_list_t *)selected_group->data; while(ulist!= NULL) { unit = (unit_t*)ulist->data; unit->x = new_x; unit->y = new_y; ulist=ulist->next; } } } else { ulist = (unit_list_t *)selected_group->data; while(ulist!= NULL) { unit = (unit_t*)ulist->data; unit->x = new_x; unit->y = new_y; ulist=ulist->next; } } /* Encounter ? */ if( (enc=is_encounter_present(game,new_x,new_y,unit->side)) ) { if(enc->unit) { screen_combat(local_render,game,(unit_list_t **)&selected_group->data,&enc->unit,new_x,new_y,unit->side); } } remove_dead_groups(game); /* Avoid blinking while moving */ blink_state=1; blink_time=SDL_GetTicks(); }