21 #include <type_traits>
34 #ifdef USE_CLN_NUMBERS
39 template<
typename Pol>
42 *
this <<
"(not (= " << c.
lhs() <<
" 0))";
44 *
this <<
"(" << c.
relation() <<
" " << c.
lhs() <<
" 0)";
48 template<
typename Pol>
56 return std::get<MultivariateRoot<Pol>>(c.
value());
61 *
this <<
"(" << c.
relation() <<
" " << (c.
negated() ?
"true" :
"false") <<
" " << c.
var() <<
" (root " << iroot.poly() <<
" " << iroot.k() <<
" " << iroot.var() <<
"))";
65 template<
typename Pol>
75 *
this <<
"(" << f.
type();
108 CARL_LOG_ERROR(
"carl.smtlibstream",
"Printing exists or forall is not implemented yet.");
115 template<
typename Rational,
typename Poly>
117 *
this <<
"(model " << std::endl;
118 for (
const auto& m: model) {
119 auto value = m.second;
121 *
this <<
"\t(define-fun " << m.first <<
" () ";
122 if (m.first.is_variable()) {
123 *
this << m.first.asVariable().type() << std::endl;
124 }
else if (m.first.isBVVariable()) {
125 *
this << m.first.asBVVariable().sort() << std::endl;
126 }
else if (m.first.isUVariable()) {
127 *
this << m.first.asUVariable().domain() << std::endl;
128 }
else if (m.first.isFunction()) {
131 CARL_LOG_ERROR(
"carl.smtlibstream",
"Encountered an unknown type of ModelVariable: " << m.first);
135 value.visit([
this](
const auto& v){ this->
write(v); });
136 *
this << std::endl <<
"\t)" << std::endl;
138 *
this <<
")" << std::endl;
141 template<
typename Rational>
144 *
this << ran.
value();
149 auto denominator = p.coprime_factor();
150 if ((denominator < 0) == (p.lcoeff() > 0)) denominator *= -1;
153 *
this <<
"(root-of-with-interval ";
154 const auto& coeffs = p.coefficients();
155 auto it = coeffs.begin();
156 *
this <<
"(coeffs " << *it;
158 for (; it != coeffs.end(); it++) {
167 template<
typename Rational,
typename Poly>
173 }
else if (mv.
isRAN()) {
182 void write(
const Monomial::Content::value_type& m) {
183 if (m.second == 0) *
this <<
"1";
184 else if (m.second == 1) *
this << m.first;
187 for (std::size_t i = 0; i < m.second; ++i) *
this <<
" " << m.first;
204 template<
typename Coeff>
210 for (
auto it = mp.
rbegin(); it != mp.
rend(); ++it) {
228 template<
typename Coeff>
242 *
this <<
"(not (= " << ueq.
lhs() <<
" " << ueq.
rhs() <<
"))";
244 *
this <<
"(= " << ueq.
lhs() <<
" " << ueq.
rhs() <<
")";
251 for (
const auto& a : ufi.
args()) {
257 template<
typename Coeff>
262 for (std::size_t i = 0; i < up.
coefficients().size(); ++i) {
265 if (
exp == 0) *
this <<
" " << coeff;
289 default: *
this <<
"?";
break;
294 if (b) *
this <<
"true";
295 else *
this <<
"false";
306 *
this <<
"; " << c << std::endl;
310 *
this <<
"(set-logic " << l <<
")" << std::endl;
314 *
this <<
"(declare-sort " << s <<
" " << s.
arity() <<
")" << std::endl;
319 *
this <<
"(declare-fun " << uf.
name() <<
" (";
320 for (
const auto& d : uf.
domain()) {
324 *
this << uf.
codomain() <<
")" << std::endl;
328 *
this <<
"(declare-fun " << v <<
" () " << v.
type() <<
")" << std::endl;
336 *
this <<
"(declare-fun " << v <<
" () " << v.
domain() <<
")" << std::endl;
339 void declare(
const std::set<UninterpretedFunction>& ufs) {
340 for (
const auto& uf: ufs) {
346 for (
const auto& v: vars) {
351 void declare(
const std::set<BVVariable>& bvvs) {
352 for (
const auto& bv: bvvs) {
357 void declare(
const std::set<UVariable>& uvs) {
358 for (
const auto& uv: uvs) {
363 void initialize(
Logic l,
const carlVariables& vars,
const std::set<UninterpretedFunction>& ufs = {},
const std::set<BVVariable>& bvvs = {},
const std::set<UVariable>& uvs = {}) {
365 std::set<Sort> sorts;
366 for (
const auto& v: bvvs) {
367 sorts.insert(v.sort());
369 for (
const auto& v: uvs) {
370 sorts.insert(v.domain());
372 for (
const auto& s: sorts) {
382 template<
typename Pol>
385 std::set<UninterpretedFunction> ufs;
386 std::set<BVVariable> bvvs;
387 std::set<UVariable> uvs;
388 for (
const auto& f: formulas) {
398 void setInfo(
const std::string& name,
const std::string& value) {
399 *
this <<
"(set-info :" << name <<
" " << value <<
")" << std::endl;
403 void setOption(
const std::string& name,
const std::string& value) {
404 *
this <<
"(set-option :" << name <<
" " << value <<
")" << std::endl;
408 template<
typename Pol>
410 *
this <<
"(assert " << formula <<
")" << std::endl;
414 template<
typename Pol>
416 *
this <<
"(minimize " << objective <<
")" << std::endl;
421 *
this <<
"(check-sat)" << std::endl;
426 *
this <<
"(get-assertions)" << std::endl;
431 *
this <<
"(get-model)" << std::endl;
436 *
this <<
"(echo \"" <<
str <<
"\")" << std::endl;
441 *
this <<
"(reset)" << std::endl;
446 *
this <<
"(exit)" << std::endl;
452 write(
static_cast<const std::decay_t<T>&
>(t));
481 template<
typename Pol>
491 template<
typename Pol>
505 template<
typename Pol,
typename... Args>
511 template<
typename... Args>
516 template<
typename... Args>
525 template<
typename... Args>
#define CARL_LOG_ERROR(channel, msg)
MultivariatePolynomial< Rational > Pol
std::string toString(Relation r)
carlVariables uninterpreted_variables(const T &t)
T tuple_accumulate(Tuple &&t, T &&init, F &&f)
Implements a functional fold (similar to std::accumulate) for std::tuple.
std::optional< BasicConstraint< Poly > > as_constraint(const VariableComparison< Poly > &f)
Convert this variable comparison "v < root(..)" into a simpler polynomial (in)equality against zero "...
Interval< Number > exp(const Interval< Number > &i)
void uninterpreted_functions(const Formula< Pol > &f, std::set< UninterpretedFunction > &ufs)
carlVariables bitvector_variables(const T &t)
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
VariableType
Several types of variables are supported.
void visit(const Formula< Pol > &formula, Visitor func)
Recursively calls func on every subformula.
bool is_integer(const Interval< Number > &n)
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
detail::SMTLIBOutputContainer< Args... > asSMTLIB(Args &&... args)
Generic shorthand to write arbitrary data to an SMTLIBStream and return the result.
std::ostream & operator<<(std::ostream &os, const MapleStream &ms)
detail::SMTLIBScriptContainer< Pol > outputSMTLIB(Logic l, std::initializer_list< Formula< Pol >> formulas, Args &&... args)
Shorthand to allow writing SMTLIB scripts in one line.
std::ostream & operator<<(std::ostream &os, const SMTLIBScriptContainer< Pol > &sc)
Actually write an SMTLIBScriptContainer to an std::ostream.
auto & get(const std::string &name)
A Variable represents an algebraic variable that can be used throughout carl.
std::string name() const
Retrieves the name of the variable.
constexpr VariableType type() const noexcept
Retrieves the type of the variable.
static variable_type_filter excluding(std::initializer_list< VariableType > i)
carlVariables filter(variable_type_filter &&f) const
typename Poly::RootType RAN
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
const std::variant< MR, RAN > & value() const
Relation relation() const
This class represents a univariate polynomial with coefficients of an arbitrary type.
bool is_constant() const
Checks whether the polynomial is constant with respect to the main variable.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
Variable main_var() const
Retrieves the main variable of this polynomial.
NumberType constant_part() const
Returns the constant part of this polynomial.
The general-purpose multivariate polynomial class.
const Term< Coeff > & lterm() const
The leading term.
std::size_t nr_terms() const
Calculate the number of terms.
The general-purpose monomials.
std::shared_ptr< const Monomial > Arg
const Content & exponents() const
Coefficient & coeff()
Get the coefficient.
Monomial::Arg & monomial()
Get the monomial.
const auto & value() const
const auto & interval() const
const auto & polynomial() const
Represent a polynomial (in)equality against zero.
Relation relation() const
Represent a BitVector-Variable.
Variable variable() const
Represent an SMT formula, which can be an atom for some background theory or a boolean combination of...
const VariableAssignment< Pol > & variable_assignment() const
const Formula & subformula() const
const VariableComparison< Pol > & variable_comparison() const
carl::Variable::Arg boolean() const
const Constraint< Pol > & constraint() const
const Formulas< Pol > & subformulas() const
const BVConstraint & bv_constraint() const
const UEquality & u_equality() const
Represent a collection of assignments/mappings from variables to values.
const ModelValue< Rational, Poly > & evaluated(const typename Map::key_type &key) const
Return the ModelValue for the given key, evaluated if it's a ModelSubstitution and evaluatable,...
Represent a sum type/variant over the different kinds of values that can be assigned to the different...
const Poly::RootType & asRAN() const
const Rational & asRational() const
Implements a sort (for defining types of variables and functions).
std::size_t arity() const
Implements an uninterpreted equality, that is an equality of either two uninterpreted function instan...
const UTerm & rhs() const
const UTerm & lhs() const
Implements an uninterpreted function instance.
const UninterpretedFunction & uninterpretedFunction() const
const std::vector< UTerm > & args() const
Implements an uninterpreted function.
const std::string & name() const
const std::vector< Sort > & domain() const
Implements an uninterpreted term, that is either an uninterpreted variable or an uninterpreted functi...
const auto & asVariant() const
Implements an uninterpreted variable.
Allows to print carl data structures in SMTLIB syntax.
void declare(const std::set< UVariable > &uvs)
Declare a set of uninterpreted variables.
void write(const Constraint< Pol > &c)
void exit()
Exit via exit.
std::stringstream mStream
void comment(const std::string &c)
Writes a comment.
void declare(UVariable v)
Declare an uninterpreted variable via declare-fun.
void declare(const carlVariables &vars)
Declare a set of variables.
void reset()
Reset via reset.
void write(const UnivariatePolynomial< Coeff > &up)
void assertFormula(const Formula< Pol > &formula)
Assert a formula via assert.
void write(const ModelValue< Rational, Poly > &mv)
void initialize(Logic l, std::initializer_list< Formula< Pol >> formulas)
Generic initializer including the logic and variables and functions from a set of formulas.
auto content() const
Return the underlying stream buffer.
void declare(Variable v)
Declare a fresh variable via declare-fun.
void write(const UEquality &ueq)
void write(const VariableComparison< Pol > &c)
void declare(const std::set< UninterpretedFunction > &ufs)
Declare a set of functions.
void write(const Monomial::Content::value_type &m)
void write(const UTerm &t)
void declare(BVVariable v)
Declare a bitvector variable via declare-fun.
void write(const Model< Rational, Poly > &model)
SMTLIBStream & operator<<(T &&t)
Write some data to this stream.
void checkSat()
Check satisfiability via check-sat.
SMTLIBStream & operator<<(std::ostream &(*os)(std::ostream &))
Write io operators (like std::endl) directly to the underlying stream.
void echo(const std::string &str)
Echo via echo.
void write(const Variable &v)
void declare(Sort s)
Declare a sort via declare-sort.
void write(const MultivariatePolynomial< Coeff > &mp)
void write(const Formula< Pol > &f)
void write(const UFInstance &ufi)
void getModel()
Print model via get-model.
void getAssertions()
Print assertions via get-assertions.
void write(const mpz_class &n)
void setInfo(const std::string &name, const std::string &value)
Set information via set-info.
void minimize(const Pol &objective)
Minimize an objective via custom minimize.
void write(const mpq_class &n)
void write(const IntRepRealAlgebraicNumber< Rational > &ran)
void declare(UninterpretedFunction uf)
Declare a fresh function via declare-fun.
void write(const Monomial::Arg &m)
auto str() const
Return the written data as a string.
void write(const Monomial &m)
void write(const Term< Coeff > &t)
void initialize(Logic l, const carlVariables &vars, const std::set< UninterpretedFunction > &ufs={}, const std::set< BVVariable > &bvvs={}, const std::set< UVariable > &uvs={})
Generic initializer including the logic, a set of variables and a set of functions.
void setOption(const std::string &name, const std::string &value)
Set option via set-option.
void declare(Logic l)
Declare a logic via set-logic.
void declare(const std::set< BVVariable > &bvvs)
Declare a set of bitvector variables.
void write(const VariableType &vt)
Shorthand to allow writing SMTLIB scripts in one line.
SMTLIBScriptContainer(Logic l, std::initializer_list< Formula< Pol >> f, const Pol &objective, bool getModel=false)
std::initializer_list< Formula< Pol > > mFormulas
SMTLIBScriptContainer(Logic l, std::initializer_list< Formula< Pol >> f, bool getModel=false)
std::tuple< Args... > mData
SMTLIBOutputContainer(Args &&... args)