25 std::optional<typet> itype;
29 for(std::vector<monomialt>::iterator m_it=
monomials.begin();
33 for(std::vector<monomialt::termt>::iterator t_it=m_it->terms.begin();
34 t_it!=m_it->terms.end();
37 if(!itype.has_value())
39 itype=t_it->var.type();
48 for(std::vector<monomialt>::iterator m_it=
monomials.begin();
52 int coeff=m_it->coeff;
63 for(std::vector<monomialt::termt>::iterator t_it=m_it->terms.begin();
64 t_it!=m_it->terms.end();
67 for(
unsigned int i=0; i < t_it->exp; i++)
102 if(expr.
id()==ID_symbol)
108 term.
var=symbol_expr;
110 monomial.
terms.push_back(term);
115 else if(expr.
id()==ID_plus ||
116 expr.
id()==ID_minus ||
125 if(expr.
id()==ID_minus)
130 else if(expr.
id()==ID_plus)
134 else if(expr.
id()==ID_mult)
146 else if(expr.
id()==ID_typecast)
156 throw "couldn't polynomialize";
162 for(std::vector<monomialt>::iterator m_it=
monomials.begin();
166 for(std::vector<monomialt::termt>::iterator t_it=m_it->terms.begin();
167 t_it!=m_it->terms.end();
170 if(substitution.find(t_it->var)!=substitution.end())
184 std::vector<monomialt>::iterator it, jt;
185 std::vector<monomialt> new_monomials;
194 int res=it->compare(*jt);
200 new_monomial.
coeff += jt->coeff;
202 if(new_monomial.
coeff!=0)
204 new_monomials.push_back(new_monomial);
214 new_monomials.push_back(*it);
219 new_monomials.push_back(*jt);
230 new_monomials.push_back(*it);
236 new_monomials.push_back(*jt);
255 for(std::vector<monomialt>::iterator it=
monomials.begin();
265 std::vector<monomialt> my_monomials=
monomials;
268 for(std::vector<monomialt>::iterator it=my_monomials.begin();
269 it!=my_monomials.end();
272 for(std::vector<monomialt>::iterator jt=other.
monomials.begin();
278 product.
coeff=it->coeff * jt->coeff;
286 std::vector<monomialt::termt>::iterator t1, t2;
288 t1=it->terms.begin();
289 t2=jt->terms.begin();
291 while(t1!=it->terms.end() && t2 != jt->terms.end())
300 term.
exp=t1->exp + t2->exp;
318 product.
terms.push_back(term);
323 while(t1!=it->terms.end())
325 product.
terms.push_back(*t1);
329 while(t2!=jt->terms.end())
331 product.
terms.push_back(*t2);
345 std::vector<termt>::iterator it, jt;
348 jt=other.
terms.begin();
352 while(it!=
terms.end() && jt != other.
terms.end())
354 unsigned int e1=it->exp;
355 unsigned int e2=it->exp;
356 int res=it->var.compare(jt->var);
370 INVARIANT(it->var == jt->var,
"must match");
390 if(it==
terms.end() && jt == other.
terms.end())
395 else if(it!=
terms.end() && jt == other.
terms.end())
400 else if(it==
terms.end() && jt != other.
terms.end())
413 for(std::vector<monomialt>::iterator it=
monomials.begin();
417 if(it->contains(var))
419 maxd=std::max(maxd, it->degree());
439 for(std::vector<monomialt>::iterator it=
monomials.begin();
460 for(std::vector<termt>::iterator it=
terms.begin();
473 if(var.
id()!=ID_symbol)
479 for(std::vector<termt>::iterator it=
terms.begin();
Base class for all expressions.
bool is_constant() const
Return whether the expression is a constant.
int compare(const irept &i) const
defines ordering on the internal representation comments are ignored
const irep_idt & id() const
std::vector< termt > terms
int compare(monomialt &other)
bool contains(const exprt &var)
Binary multiplication Associativity is not specified.
The plus expression Associativity is not specified.
void substitute(substitutiont &substitution)
void from_expr(const exprt &expr)
std::vector< monomialt > monomials
int coeff(const exprt &expr)
void add(polynomialt &other)
int max_degree(const exprt &var)
Expression to hold a symbol (variable)
Semantic type conversion.
The unary minus expression.
std::map< exprt, exprt > substitutiont
#define UNREACHABLE
This should be used to mark dead code.
API to expression classes.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
typet join_types(const typet &t1, const typet &t2)
Return the smallest type that both t1 and t2 can be cast to without losing information.