3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-10 19:27:06 +00:00
z3/lib/expr2polynomial.h
Leonardo de Moura e9eab22e5c Z3 sources
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-02 11:35:25 -07:00

94 lines
2.3 KiB
C++

/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
expr2polynomial.h
Abstract:
Translator from Z3 expressions into multivariate polynomials (and back).
Author:
Leonardo (leonardo) 2011-12-23
Notes:
--*/
#ifndef _EXPR2POLYNOMIAL_H_
#define _EXPR2POLYNOMIAL_H_
#include"ast.h"
#include"polynomial.h"
class expr2var;
class expr2polynomial {
struct imp;
imp * m_imp;
public:
expr2polynomial(ast_manager & am, polynomial::manager & pm, expr2var * e2v);
virtual ~expr2polynomial();
ast_manager & m() const;
polynomial::manager & pm() const;
/**
\brief Convert a Z3 expression into a polynomial in Z[x0, ..., x_n].
Since Z3 expressions may be representing polynomials in Q[x0, ..., x_n],
the method also returns a "denominator" d.
Thus, we have that n is equal to p/d
\remark Return false if t is not an integer or real expression.
\pre The only supported operators are MUL, ADD, SUB, UMINUS, TO_REAL, TO_INT, POWER (with constants)
*/
bool to_polynomial(expr * t, polynomial::polynomial_ref & p, polynomial::scoped_numeral & d);
/**
\brief Convert a polynomial into a Z3 expression.
\remark If the polynomial has one real variable, then the resultant
expression is an real expression. Otherwise, it is an integer
*/
void to_expr(polynomial::polynomial_ref const & p, bool use_power, expr_ref & r);
/**
\brief Return true if t was encoded as a variable by the translator.
*/
bool is_var(expr * t) const;
/**
\brief Return the mapping from expressions to variables
*/
expr2var const & get_mapping() const;
/**
\brief Cancel/Interrupt execution.
*/
void set_cancel(bool f);
/**
\brief Return true if the variable is associated with an expression of integer sort.
*/
virtual bool is_int(polynomial::var x) const = 0;
protected:
virtual polynomial::var mk_var(bool is_int) = 0;
};
class default_expr2polynomial : public expr2polynomial {
svector<bool> m_is_int;
public:
default_expr2polynomial(ast_manager & am, polynomial::manager & pm);
virtual ~default_expr2polynomial();
virtual bool is_int(polynomial::var x) const;
protected:
virtual polynomial::var mk_var(bool is_int);
};
#endif