Example #1
0
void print_egraph_conflict(FILE *f, egraph_t *egraph, ivector_t *expl_vector) {
  void *atom;
  uint32_t i, n;
  literal_t l;
  bvar_t v;

  n = expl_vector->size;
  for (i=0; i<n; i++) {
    l = expl_vector->data[i];
    v = var_of(l);
    if (bvar_has_atom(egraph->core, v)) {
      atom = bvar_atom(egraph->core, v);
      switch (atom_tag(atom)) {
      case EGRAPH_ATM_TAG:
	if (is_neg(l)) fputs("(not ", f);
	print_eterm(f, egraph, ((atom_t *) untag_atom(atom))->eterm);
	if (is_neg(l)) fputc(')', f);
	break;

      default:
	print_literal(f, l);
	break;
      }
    } else {
      print_literal(f, l);
    }
    if (i+1 < n) {
      fputc(' ', f);
    }
  }
  fflush(f);
}
Example #2
0
char		*ft_itoa(int n)
{
	char	*str;
	size_t	i;
	size_t	neg;

	neg = is_neg(n);
	i = len_str(n);
	str = ft_strnew(neg + i + 1);
	if (n == -2147483648)
		return (ft_strcpy(str, "-2147483648"));
	if (is_neg(n))
		n = n * -1;
	if (str)
	{
		if (!n)
			str[0] = '0';
		while (n)
		{
			str[--i + neg] = (n % 10) + '0';
			n = n / 10;
		}
		if (neg)
			str[0] = '-';
	}
	return (str);
}
Example #3
0
template<class T, class Policies> inline
interval<T, Policies> div_non_zero(const interval<T, Policies>& x,
                                   const interval<T, Policies>& y)
{
    // assert(!in_zero(y));
    typename Policies::rounding rnd;
    typedef interval<T, Policies> I;
    const T& xl = x.lower();
    const T& xu = x.upper();
    const T& yl = y.lower();
    const T& yu = y.upper();
    if (is_neg(xu))
        if (is_neg(yu))
            return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true);
        else
            return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true);
    else if (is_neg(xl))
        if (is_neg(yu))
            return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true);
        else
            return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true);
    else if (is_neg(yu))
        return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true);
    else
        return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true);
}
Example #4
0
template<class T, class Policies> inline
interval<T, Policies> div_zero_part1(const interval<T, Policies>& x,
                                     const interval<T, Policies>& y, bool& b)
{
    // assert(y.lower() < 0 && y.upper() > 0);
    if (is_zero(x.lower()) && is_zero(x.upper()))
    {
        b = false;
        return x;
    }
    typename Policies::rounding rnd;
    typedef interval<T, Policies> I;
    const T& xl = x.lower();
    const T& xu = x.upper();
    const T& yl = y.lower();
    const T& yu = y.upper();
    typedef typename I::checking checking;
    const T& inf = checking::inf();
    if (is_neg(xu))
    {
        b = true;
        return I(-inf, rnd.div_up(xu, yu), true);
    }
    else if (is_neg(xl))
    {
        b = false;
        return I(-inf, inf, true);
    }
    else
    {
        b = true;
        return I(-inf, rnd.div_up(xl, yl), true);
    }
}
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");
    }
}
Example #6
0
/*
 * Print literal l in DIMACS format
 * - l is 2 * v + s with 0 <= v < nvars and s=0 or s=1
 * - 0 is not allowed as a variable in DIMACS so we
 *   convert variable v to DIMACS var (v+1)
 */
void dimacs_print_literal(FILE *f, literal_t l) {
  bvar_t v;

  v = var_of(l);
  if (is_neg(l)) fputc('-', f);
  fprintf(f, "%"PRId32, v+1);
}
Example #7
0
void print_egraph_atom_of_literal(FILE *f, egraph_t *egraph, literal_t l) {
  void *atom;
  bvar_t v;

  v = var_of(l);
  assert(bvar_has_atom(egraph->core, v));
  atom = bvar_atom(egraph->core, v);
  assert(atom_tag(atom) == EGRAPH_ATM_TAG);
  if (is_neg(l)) {
    fputs("(not ", f);
  }
  print_eterm(f, egraph, ((atom_t *) untag_atom(atom))->eterm);
  if (is_neg(l)) {
    fputc(')', f);
  }
}
Example #8
0
static zword find_word(zword dictionarytable, const char *word, int length)
{
  zbyte zsciibuffer[12];
  int entry_length, word_length;
  int num_entries;
  void *p;

  entry_length = LOBYTE(dictionarytable);
  dictionarytable++;
  num_entries = LOWORD(dictionarytable);
  dictionarytable+=ZWORD_SIZE;

  if(zversion <= 3)
    word_length = 4;
  else
    word_length = 6;

  encodezscii(zsciibuffer, word_length, word_length, word, length);

  dictentry_len = word_length;
  
  if(is_neg(num_entries)) {  /* Unordered dictionary */
    num_entries = neg(num_entries);
    p = n_lfind(zsciibuffer, z_memory + dictionarytable, &num_entries,
		entry_length, cmpdictentry);
  } else {                   /* Ordered dictionary */
    p = n_bsearch(zsciibuffer, z_memory + dictionarytable, num_entries,
		  entry_length, cmpdictentry);
  }
  if(p)
    return ((zbyte *) p) - z_memory;

  return 0;
}
Example #9
0
char		*ft_itoa_base(intmax_t n, int base)
{
	int		i;
	int		len;
	int		neg;
	char	*str;
	char	*cmp;

	cmp = init(&neg, &i);
	len = ft_get_len(n, base);
	is_neg(&neg, &n);
	if (n == 0)
		return (ft_strdup("0"));
	if (neg && !(str = (char *)malloc(sizeof(char) * (len + 1))))
		return (NULL);
	else
		return (ft_neg(n, base, len));
	str[len + 1] = 0;
	while (len + 1)
	{
		str[len] = cmp[n % base];
		n = n / base;
		len--;
	}
	if (str[0] == '0')
		str = ft_strsub(str, 1, ft_strlen(str) - 1);
	return (str);
}
Example #10
0
 subpaving::ineq * mk_ineq(expr * a) {
     bool neg = false;
     while (m().is_not(a, a))
         neg = !neg;
     bool lower;
     bool open  = false;
     if (m_autil.is_le(a)) {
         lower = false;
     }
     else if (m_autil.is_ge(a)) {
         lower = true;
     }
     else {
         throw tactic_exception("unsupported atom");
     }
     if (neg) {
         lower = !lower;
         open  = !open;
     }
     rational _k;
     if (!m_autil.is_numeral(to_app(a)->get_arg(1), _k))
         throw tactic_exception("use simplify tactic with option :arith-lhs true");
     scoped_mpq k(m_qm);
     k = _k.to_mpq();
     scoped_mpz n(m_qm), d(m_qm);
     subpaving::var x = m_e2s->internalize_term(to_app(a)->get_arg(0), n, d);
     m_qm.mul(d, k, k);
     m_qm.div(k, n, k);
     if (is_neg(n))
         lower = !lower;
     TRACE("subpaving_tactic", tout << x << " " << k << " " << lower << " " << open << "\n";);
Example #11
0
void mpfx_manager::set_core(mpfx & n, mpq_manager<SYNCH> & m, mpq const & v) {
    if (m.is_int(v)) {
        set_core(n, m, v.numerator());
    }
    else {
        allocate_if_needed(n);
        _scoped_numeral<mpz_manager<SYNCH> > tmp(m);
        n.m_sign = is_neg(n);
        m.mul2k(v.numerator(), 8 * sizeof(unsigned) * m_frac_part_sz, tmp);
        m.abs(tmp);
        if ((n.m_sign == 1) != m_to_plus_inf && !m.divides(v.denominator(), tmp)) {
            m.div(tmp, v.denominator(), tmp);
            m.inc(tmp);
        }
        else {
            m.div(tmp, v.denominator(), tmp);
        }
        m_tmp_digits.reset();
        m.decompose(tmp, m_tmp_digits);
        unsigned sz = m_tmp_digits.size();
        if (sz > m_total_sz)
            throw overflow_exception();
        unsigned * w = words(n);
        ::copy(sz, m_tmp_digits.c_ptr(), m_total_sz, w);
    }
    SASSERT(check(n));
}
Example #12
0
void mpq_manager<SYNCH>::display_decimal(std::ostream & out, mpq const & a, unsigned prec) {
    mpz n1, d1, v1;
    get_numerator(a, n1);
    get_denominator(a, d1);
    if (is_neg(a)) {
        out << "-";
        neg(n1);
    }
    mpz ten(10);
    div(n1, d1, v1);
    display(out, v1);
    rem(n1, d1, n1);
    if (is_zero(n1))
        goto end; // number is an integer
    out << ".";
    for (unsigned i = 0; i < prec; i++) {
        mul(n1, ten, n1);
        div(n1, d1, v1);
        SASSERT(lt(v1, ten));
        display(out, v1);
        rem(n1, d1, n1);
        if (is_zero(n1))
            goto end; // number is precise
    }
    out << "?";
 end:
    del(ten); del(n1); del(d1); del(v1);
}
Example #13
0
File: num.cpp Project: avigad/lean
bool is_signed_num(expr const & e) {
    if (is_num(e))
        return true;
    else if (auto r = is_neg(e))
        return is_num(*r);
    else
        return false;
}
Example #14
0
void mpq::floor() {
    if (is_integer())
        return;
    bool neg = is_neg();
    mpz_tdiv_q(mpq_numref(m_val), mpq_numref(m_val), mpq_denref(m_val));
    mpz_set_ui(mpq_denref(m_val), 1);
    if (neg)
        mpz_sub_ui(mpq_numref(m_val), mpq_numref(m_val), 1);
}
Example #15
0
template<class T, class Policies> inline
interval<T, Policies> div_positive(const interval<T, Policies>& x, const T& yu)
{
    // assert(yu > T(0));
    if (is_zero(x)) return x;
    typename Policies::rounding rnd;
    typedef interval<T, Policies> I;
    const T& xl = x.lower();
    const T& xu = x.upper();
    typedef typename Policies::checking checking;
    const T& inf = checking::inf();
    if (is_neg(xu))
        return I(-inf, rnd.div_up(xu, yu), true);
    else if (is_neg(xl))
        return I(-inf, inf, true);
    else
        return I(rnd.div_down(xl, yu), inf, true);
}
Example #16
0
void print_bv_solver_atom_of_literal(FILE *f, bv_solver_t *solver, literal_t l) {
  void *atm;
  bvar_t v;
  int32_t id;

  v = var_of(l);
  assert(bvar_has_atom(solver->core, v));
  atm = bvar_atom(solver->core, v);
  assert(atom_tag(atm) == BV_ATM_TAG);
  id = bvatom_tagged_ptr2idx(atm);

  if (is_neg(l)) {
    fputs("(not ", f);
  }
  print_bv_solver_atom(f, solver, id);
  if (is_neg(l)) {
    fputc(')', f);
  }
}
Example #17
0
void mpq_manager<SYNCH>::floor(mpq const & a, mpz & f) {
    if (is_int(a)) {
        set(f, a.m_num);
        return;
    }
    bool is_neg_num = is_neg(a.m_num);
    machine_div(a.m_num, a.m_den, f);
    if (is_neg_num)
        sub(f, this->mk_z(1), f);
}
Example #18
0
bool mpfx_manager::is_uint64(mpfx const & a) const {
    if (!is_int(a) || is_neg(a))
        return false;
    if (is_zero(a) || m_int_part_sz <= 2)
        return true;
    unsigned * w = words(a);
    for (unsigned i = m_frac_part_sz + 2; i < m_total_sz; i++)
        if (w[i] != 0)
            return false;
    return true;
}
Example #19
0
void print_simplex_atom_of_literal(FILE *f, simplex_solver_t *solver, literal_t l) {
  void *atm;
  arith_atom_t *a;
  bvar_t v;
  int32_t i;

  v = var_of(l);
  assert(bvar_has_atom(solver->core, v));
  atm = bvar_atom(solver->core, v);
  assert(atom_tag(atm) == ARITH_ATM_TAG);
  i = arithatom_tagged_ptr2idx(atm);
  a = arith_atom(&solver->atbl, i);
  assert(a->boolvar == v);

  if (is_neg(l)) {
    fputs("(not ", f);
  }
  print_arith_atom(f, &solver->vtbl, a);
  if (is_neg(l)) {
    fputc(')', f);
  }
}
Example #20
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;
}
Example #21
0
template<class T, class Policies> inline
interval<T, Policies> div_negative(const T& x, const T& yl)
{
    // assert(yl < T(0));
    typedef interval<T, Policies> I;
    if (is_zero(x)) return I(0, 0, true);
    typename Policies::rounding rnd;
    typedef typename Policies::checking checking;
    const T& inf = checking::inf();
    if (is_neg(x))
        return I(rnd.div_down(x, yl), inf, true);
    else
        return I(-inf, rnd.div_up(x, yl), true);
}
Example #22
0
template<class T, class Policies> inline
interval<T, Policies> div_zero_part2(const interval<T, Policies>& x,
                                     const interval<T, Policies>& y)
{
    // assert(y.lower() < 0 && y.upper() > 0 && (div_zero_part1(x, y, b), b));
    typename Policies::rounding rnd;
    typedef interval<T, Policies> I;
    typedef typename I::checking checking;
    const T& inf = checking::inf();
    if (is_neg(x.upper()))
        return I(rnd.div_down(x.upper(), y.lower()), inf, true);
    else
        return I(rnd.div_down(x.lower(), y.upper()), inf, true);
}
Example #23
0
/*
 * Pseudo literal s: print the literal mapped to s
 */
static void print_pseudo_literal(FILE *f, remap_table_t *table, literal_t s) {
  if (s != null_literal) {
    s = remap_table_find(table, s);
  }
  if (s == null_literal) {
    fputs("?", f);
  } else if (s == true_literal) {
    fputs("t", f);
  } else if (s == false_literal) {
    fputs("f", f);
  } else {
    if (is_neg(s)) fputc('~', f);
    fprintf(f, "p!%"PRId32, var_of(s));
  }
}
Example #24
0
bool mpfx_manager::is_int64(mpfx const & a) const {
    if (!is_int(a))
        return false;
    if (is_zero(a) || m_int_part_sz <= 1)
        return true;
    unsigned * w = words(a);
    w += m_frac_part_sz;
    if (w[1] < 0x80000000u || (w[1] == 0x80000000u && is_neg(a))) {
        for (unsigned i = 2; i < m_int_part_sz; i++)
            if (w[i] != 0)
                return false;
        return true;
    }
    else {
        return false;
    }
}
Example #25
0
/*
 * Literal
 */
void print_literal(FILE *f, literal_t l) {
  if (l < 0) {
    if (l == null_literal) {
      //      fputs("null_literal", f);
      fputs("nil", f);
    } else {
      fprintf(f, "LIT%"PRId32, l);
    }
  } else if (l == true_literal) {
    fputs("tt", f);
  } else if (l == false_literal) {
    fputs("ff", f);
  } else {
    if (is_neg(l)) fputc('~', f);
    fprintf(f, "p!%"PRId32, var_of(l));
  }
}
Example #26
0
int				print_with_precision(t_formater *fmt, t_printf *pf)
{
	int			is_nega;
	int			ret;

	ret = 0;
	is_nega = pf->fmt_str[0] == '-' ? 1 : 0;
	if (is_nega)
		pf->prefix = ft_strdup("-");
	if (is_signed(fmt) && fmt->flag & F_BLANK && !is_neg(pf->fmt_str))
	{
		ret += ft_putchar(' ');
		fmt->width -= 1;
	}
	ret += print_w_pres3(fmt, pf);
	return (ret);
}
Example #27
0
File: num.cpp Project: avigad/lean
static optional<mpz> to_num(expr const & e, bool first) {
    if (is_zero(e)) {
        return first ? some(mpz(0)) : optional<mpz>();
    } else if (is_one(e)) {
        return some(mpz(1));
    } else if (auto a = is_bit0(e)) {
        if (auto r = to_num(*a, false))
            return some(2*(*r));
    } else if (auto a = is_bit1(e)) {
        if (auto r = to_num(*a, false))
            return some(2*(*r)+1);
    } else if (auto a = is_neg(e)) {
        if (auto r = to_num(*a, false))
            return some(neg(*r));
    }
    return optional<mpz>();
}
Example #28
0
int             my_getnbr(char *str)
{
  int           i;
  int           nbr;

  nbr = 0;
  i = 0;
  while (is_num(str[i]) == 0)
    i++;
  while (is_num(str[i]) == 1)
    {
      nbr = ((nbr * 10) + (str[i] - 48));
      i++;
    }
  if (is_neg(str) == 1)
    nbr = -nbr;
  return (nbr);
}
Example #29
0
File: main.c Project: d5h/gah
const char *
valstr(struct val *v)
{
  static char buf[SLEN(v->bits) + 2];
  char *p = buf + sizeof buf - 1;
  valbits_t bits = v->bits;
  int neg = is_neg(v);

  if (neg)
    bits = ~bits + 1;

  *p = '\0';
  do
    *--p = '0' + bits % 10;
  while (bits /= 10);

  if (v->bits && neg)
    *--p = '-';

  return p;
}
Example #30
0
int       my_getnbr(char *str)
{
  int     nombre;
  int     i;
  int     neg;
  int     b;

  neg = is_neg(str);
  i = 0;
  b = 0;
  while ((*str >= '0' && *str <= '9') || ((*str == '+' || *str == '-') && !b))
  {
    if (*str >= '0' && *str <= '9')
      b = 1;
    str++;
    i++;
  }
  str--;
  nombre = convert_number(str, i, neg);
  return (nombre);
}