static void tst3() {
    unsynch_mpq_manager m; 
    scoped_mpq a(m);      
    SASSERT(is_zero(m, a, EN_NUMERAL));
    SASSERT(!is_zero(m, a, EN_PLUS_INFINITY));
    SASSERT(!is_zero(m, a, EN_MINUS_INFINITY));
    SASSERT(!is_pos(m, a, EN_NUMERAL));
    SASSERT(is_pos(m, a, EN_PLUS_INFINITY));
    SASSERT(!is_pos(m, a, EN_MINUS_INFINITY));
    SASSERT(!is_infinite(EN_NUMERAL));
    SASSERT(is_infinite(EN_PLUS_INFINITY));
    SASSERT(is_infinite(EN_MINUS_INFINITY));
    SASSERT(!is_neg(m, a, EN_NUMERAL));
    SASSERT(!is_neg(m, a, EN_PLUS_INFINITY));
    SASSERT(is_neg(m, a, EN_MINUS_INFINITY));
    m.set(a, 10);
    SASSERT(!is_zero(m, a, EN_NUMERAL));
    SASSERT(is_pos(m, a, EN_NUMERAL));
    SASSERT(!is_neg(m, a, EN_NUMERAL));
    SASSERT(!is_infinite(EN_NUMERAL));
    m.set(a, -5);
    SASSERT(!is_zero(m, a, EN_NUMERAL));
    SASSERT(!is_pos(m, a, EN_NUMERAL));
    SASSERT(is_neg(m, a, EN_NUMERAL));
    SASSERT(!is_infinite(EN_NUMERAL));
    ext_numeral_kind ak;
    ak = EN_MINUS_INFINITY;
    reset(m, a, ak);
    SASSERT(is_zero(m, a, EN_NUMERAL));
    {
        std::ostringstream buffer;        
        display(buffer, m, a, ak); 
        SASSERT(buffer.str() == "0");
    }
    {
        std::ostringstream buffer;        
        m.set(a, -10);
        display(buffer, m, a, ak); 
        SASSERT(buffer.str() == "-10");
    }
    {
        std::ostringstream buffer;        
        display(buffer, m, a, EN_PLUS_INFINITY); 
        SASSERT(buffer.str() == "oo");
    }
    {
        std::ostringstream buffer;        
        display(buffer, m, a, EN_MINUS_INFINITY); 
        SASSERT(buffer.str() == "-oo");
    }
}
Exemple #2
0
void SplitLP::getSolution(stomap* sol, strvec q, int kind, bool withzeroes) const{
    MtxLP::getSolution(sol, q, kind, (kind == CONT) ? true : withzeroes);
    if (kind == CONT){
        strvec del(2 * sol->size());
        strvec pos(sol->size());
        strvec::iterator pt = pos.begin(), dt = del.begin();
        string name;
        int d = 0;
        for (stomap::iterator it = sol->begin(); it != sol->end(); ++it){
            name = it->first;
            if (is_pos(name))
                *pt++ = name;
            else {
                *pt++ = get_opp_name(name);
                *dt++ = name;
                d++;
            }
        }
        striset posset(pos.begin(), pos.end());
        for (striset::iterator pt = posset.begin(); pt != posset.end(); ++pt){
            name = *pt;
            double val = getColValue(name) - getColValue(get_opp_name(name));
            if (withzeroes || !is_zero(val))
                (*sol)[name] = val;
            else {
                *dt++ = name;
                d++;
            }
        }
        dt = del.begin();
        for (int i = 0; i <= d; i++)
            sol->erase(*dt++);
    }
 }
Exemple #3
0
void mpq::ceil() {
    if (is_integer())
        return;
    bool pos = is_pos();
    mpz_tdiv_q(mpq_numref(m_val), mpq_numref(m_val), mpq_denref(m_val));
    mpz_set_ui(mpq_denref(m_val), 1);
    if (pos)
        mpz_add_ui(mpq_numref(m_val), mpq_numref(m_val), 1);
}
Exemple #4
0
void mpq_manager<SYNCH>::ceil(mpq const & a, mpz & c) {
    if (is_int(a)) {
        set(c, a.m_num);
        return;
    }
    bool is_pos_num = is_pos(a.m_num);
    machine_div(a.m_num, a.m_den, c);
    if (is_pos_num)
        add(c, this->mk_z(1), c);
}
Exemple #5
0
bool
quanton::ck_charge(brain& brn){
#ifdef FULL_DEBUG
	BRAIN_CK_0(	(is_pos()) || 
			(! has_charge()) || 
			(is_neg()) );
	BRAIN_CK_0(	(qu_inverse->is_pos()) || 
			(! qu_inverse->has_charge()) || 
			(qu_inverse->is_neg()) );
	BRAIN_CK_0(negate_trinary(get_charge()) == qu_inverse->get_charge());
#endif
	return true;
}
Exemple #6
0
/*
 * raises: EOF_ERROR
 */
static void cmpdi_read_i(InStream *is, uchar *b, int len)
{
    CompoundInStream *cis = is->d.cis;
    off_t start = is_pos(is);

    if ((start + len) > cis->length) {
        RAISE(EOF_ERROR, "Tried to read past end of file. File length is "
              "<%"F_OFF_T_PFX"d> and tried to read to <%"F_OFF_T_PFX"d>",
              cis->length, start + len);
    }

    is_seek(cis->sub, cis->offset + start);
    is_read_bytes(cis->sub, b, len);
}
Exemple #7
0
static void fsi_read_i(InStream *is, uchar *path, int len)
{
    int fd = is->file.fd;
    off_t pos = is_pos(is);
    if (pos != lseek(fd, 0, SEEK_CUR)) {
        lseek(fd, pos, SEEK_SET);
    }
    if (read(fd, path, len) != len) {
        /* win: the wrong value can be returned for some reason so double check */
        if (lseek(fd, 0, SEEK_CUR) != (pos + len)) {
            RAISE(IO_ERROR, "couldn't read %d chars from %s: <%s>",
                  len, path, strerror(errno));
        }
    }
}
Exemple #8
0
/*
 * Print assignment
 */
void print_boolean_assignment(FILE *f, smt_core_t *core) {
  prop_stack_t *stack;
  uint32_t i, n;
  literal_t l;

  stack = &core->stack;
  n = stack->top;
  for (i=0; i<n; i++) {
    l = stack->lit[i];
    fputc(' ', f);
    if (is_pos(l)) fputc(' ', f);
    print_literal(f, l);
    fprintf(f, " level = %"PRIu32"\n", core->level[var_of(l)]);
  }
}
Exemple #9
0
void lar_solver::print_canonic_left_side(const canonic_left_side & c, std::ostream & out) {
    bool first = true;
    for (auto & it : c.m_coeffs) {
        auto val = it.first;
        if (first) {
            first = false;
        } else {
            if (val.is_pos()) {
                out << " + ";
            } else {
                out << " - ";
                val = -val;
            }
        }
        if (val != numeric_traits<mpq>::one())
            out << T_to_string(val);
        out << get_variable_name(it.second);
    }
}
Exemple #10
0
void SplitLP::getConversion(stomap* comp, bool withzeroes) const{
    strvec externals = getExternals();
    for (strvec::iterator xi = externals.begin(); xi != externals.end(); ++xi){
        string xname = *xi;
        stomap *rsto = getRowSto(xname);
        string txname = rsto->begin()->first;   //getTransporterName(rsto, dir);
        string txopp = get_opp_name(txname);
        if(!is_pos(txname)){
            string mid = txname;
            txname = txopp;
            txopp = mid;
        }
        double coef = (*rsto)[txname];
        double flux = getColValue(txname) - getColValue(txopp);
        double conv = coef * flux * vmax;
        if (withzeroes || !is_zero(conv))
            (*comp)[xname] = conv;
        delete rsto;
    }
}
Exemple #11
0
void lar_solver::print_left_side_of_constraint(const lar_base_constraint * c, std::ostream & out) {
    bool first = true;
    for (auto & it : c->get_left_side_coefficients()) {
        auto val = it.first;
        if (numeric_traits<mpq>::is_zero(val)) continue;
        if (first) {
            first = false;
        } else {
            if (val.is_pos()) {
                out << " + ";
            } else {
                out << " - ";
                val = -val;
            }
        }

        if (val != numeric_traits<mpq>::one())
            out << val;
        out << get_variable_name(it.second);
    }
}
Exemple #12
0
static bool valid_watched_lit(rule_inst_table_t *rule_inst_table, samp_literal_t lit,
		atom_table_t *atom_table) {
	valid_clause_list(&rule_inst_table->watched[lit]);

	bool lit_true = (is_pos(lit) && assigned_true(atom_table->assignment[var_of(lit)]))
	             || (is_neg(lit) && assigned_false(atom_table->assignment[var_of(lit)]));
	assert(is_empty_clause_list(&rule_inst_table->watched[lit]) || lit_true);
	if (!is_empty_clause_list(&rule_inst_table->watched[lit]) && !lit_true) {
		return false;
	}

	samp_clause_t *ptr;
	samp_clause_t *cls;
	for (ptr = rule_inst_table->watched[lit].head;
			ptr != rule_inst_table->watched[lit].tail;
			ptr = next_clause_ptr(ptr)) {
		cls = ptr->link;
		assert(clause_contains_lit(cls, lit));
		if (!clause_contains_lit(cls, lit))
			return false;
	}
	return true;
}
Exemple #13
0
/// Checks is real is negative.
/// Kind of a sign function returning a bool.
inline bool is_neg(const Real& value)
{
  return !is_pos(value);
}
Exemple #14
0
string SplitLP::get_opp_name(string name)const{
    return is_pos(name) ? NEG_TAG + name : name.substr(1);
}