static void printBvParameterizedOp(std::ostream& out, TNode n) throw();
static void printFpParameterizedOp(std::ostream& out, TNode n) throw();
+static void toStreamRational(std::ostream& out, const Rational& r, bool decimal) throw();
+
void Smt2Printer::toStream(std::ostream& out, TNode n,
int toDepth, bool types, size_t dag) const throw() {
if(dag != 0) {
out << smtKindString(n.getConst<Chain>().getOperator());
break;
case kind::CONST_RATIONAL: {
- Rational r = n.getConst<Rational>();
- if(r < 0) {
- if(r.isIntegral()) {
- out << "(- " << -r << ')';
- } else {
- out << "(- (/ " << (-r).getNumerator() << ' ' << (-r).getDenominator() << "))";
- }
- } else {
- if(r.isIntegral()) {
- out << r;
- } else {
- out << "(/ " << r.getNumerator() << ' ' << r.getDenominator() << ')';
- }
- }
+ const Rational& r = n.getConst<Rational>();
+ toStreamRational(out, r, false);
+ // Rational r = n.getConst<Rational>();
+ // if(r < 0) {
+ // if(r.isIntegral()) {
+ // out << "(- " << -r << ')';
+ // } else {
+ // out << "(- (/ " << (-r).getNumerator() << ' ' << (-r).getDenominator() << "))";
+ // }
+ // } else {
+ // if(r.isIntegral()) {
+ // out << r;
+ // } else {
+ // out << "(/ " << r.getNumerator() << ' ' << r.getDenominator() << ')';
+ // }
+ // }
break;
}
n[0].getType().isInteger()) {
// Special case, in model output integer constants that should be
// Real-sorted are wrapped in a type ascription. Handle that here.
- toStream(out, n[0], -1, false);
- out << ".0";
+
+ // Note: This is Tim making a guess about Morgan's Code.
+ Assert(n[0].getKind() == kind::CONST_RATIONAL);
+ toStreamRational(out, n[0].getConst<Rational>(), true);
+
+ //toStream(out, n[0], -1, false);
+ //out << ".0";
+
return;
}
out << "(as ";
out << "(define-fun " << n << " () "
<< n.getType() << " ";
if(val.getType().isInteger() && n.getType().isReal() && !n.getType().isInteger()) {
- out << val << ".0";
+ //toStreamReal(out, val, true);
+ toStreamRational(out, val.getConst<Rational>(), true);
+ //out << val << ".0";
} else {
out << val;
}
out << ") " << type << " " << formula << ")";
}
+static void toStreamRational(std::ostream& out, const Rational& r, bool decimal) throw() {
+ bool neg = r.sgn() < 0;
+
+ // TODO:
+ // We are currently printing (- (/ 5 3))
+ // instead of (/ (- 5) 3) which is what is in the SMT-LIB value in the theory definition.
+ // Before switching, I'll keep to what was there and send an email.
+
+ // Tim: Apologies for the ifs on one line but in this case they are cleaner.
+
+ if (neg) { out << "(- "; }
+
+ if(r.isIntegral()) {
+ if (neg) {
+ out << (-r);
+ }else {
+ out << r;
+ }
+ if (decimal) { out << ".0"; }
+ }else{
+ out << "(/ ";
+ if(neg) {
+ Rational abs_r = (-r);
+ out << abs_r.getNumerator();
+ if(decimal) { out << ".0"; }
+ out << ' ' << abs_r.getDenominator();
+ if(decimal) { out << ".0"; }
+ }else{
+ out << r.getNumerator();
+ if(decimal) { out << ".0"; }
+ out << ' ' << r.getDenominator();
+ if(decimal) { out << ".0"; }
+ }
+ out << ')';
+ }
+
+ if (neg) { out << ')';}
+
+ // if(r < 0) {
+ // Rational abs_r = -r;
+ // if(r.isIntegral()) {
+ // out << "(- " << abs_r << ')';
+ // } else {
+ // out << "(- (/ " << (-r).getNumerator() << ' ' << (-r).getDenominator() << "))";
+ // }
+ // } else {
+ // if(r.isIntegral()) {
+ // out << r;
+ // } else {
+ // out << "(/ " << r.getNumerator() << ' ' << r.getDenominator() << ')';
+ // }
+ // }
+}
+
+
static void toStream(std::ostream& out, const DeclareTypeCommand* c) throw() {
out << "(declare-sort " << c->getSymbol() << " " << c->getArity() << ")";
}
--- /dev/null
+; COMMAND-LINE:
+; EXPECT: sat
+; EXPECT: ((pos_int 5) (pos_real_int_value 3.0) (pos_rat (/ 1 3)) (zero 0.0) (neg_rat (- (/ 2 3))) (neg_real_int_value (- 2.0)) (neg_int (- 6)))
+(set-info :smt-lib-version 2.0)
+(set-option :produce-models true)
+(set-logic QF_LIRA)
+
+; This output changes if the smt2 printer output for Reals_Ints changes.
+
+(declare-fun pos_int () Int)
+(declare-fun pos_real_int_value () Real)
+(declare-fun pos_rat () Real)
+(declare-fun zero () Real)
+(declare-fun neg_rat () Real)
+(declare-fun neg_real_int_value () Real)
+(declare-fun neg_int () Int)
+
+(assert (= pos_int 5))
+(assert (= pos_real_int_value 3))
+(assert (= pos_rat (/ 1 3)))
+(assert (= zero 0))
+(assert (= neg_rat (/ (- 2) 3)))
+(assert (= neg_real_int_value (- 2)))
+(assert (= neg_int (- 6)))
+
+(check-sat)
+(get-value (pos_int pos_real_int_value pos_rat zero neg_rat neg_real_int_value neg_int))
\ No newline at end of file
--- /dev/null
+; COMMAND-LINE:
+; EXPECT: sat
+; EXPECT: ((pos_int 3.0) (pos_rat (/ 1 3)) (zero 0.0) (neg_rat (- (/ 2 3))) (neg_int (- 2.0)))
+(set-info :smt-lib-version 2.0)
+(set-option :produce-models true)
+(set-logic QF_LRA)
+
+; This output changes if the smt2 printer output for Reals changes.
+(declare-fun pos_int () Real)
+(declare-fun pos_rat () Real)
+(declare-fun zero () Real)
+(declare-fun neg_rat () Real)
+(declare-fun neg_int () Real)
+
+(assert (= pos_int 3))
+(assert (= pos_rat (/ 1 3)))
+(assert (= zero 0))
+(assert (= neg_rat (/ (- 2) 3)))
+(assert (= neg_int (- 2)))
+
+(check-sat)
+(get-value (pos_int pos_rat zero neg_rat neg_int))
\ No newline at end of file