SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Substitution.cpp
Go to the documentation of this file.
1 /**
2  * Class to create a substitution object.
3  * @author Florian Corzilius
4  * @since 2010-05-11
5  * @version 2013-10-23
6  */
7 
8 #include "Substitution.h"
9 
10 namespace smtrat {
11 namespace vs
12 {
13  Substitution::Substitution( const carl::Variable& _variable, const Type& _type, carl::PointerSet<Condition>&& _oConditions, smtrat::ConstraintsT&& _sideCondition ):
14  mVariable( _variable ),
15  mpTerm( new smtrat::SqrtEx() ),
16  mType( _type ),
17  mpTermVariables( nullptr ),
18  mOriginalConditions( std::move( _oConditions ) ),
19  mSideCondition( std::move(_sideCondition) )
20  {
21  if( mType == PLUS_EPSILON && mVariable.type() == carl::VariableType::VT_INT )
22  {
23  *mpTerm = *mpTerm + smtrat::SqrtEx(Poly(1));
24  mType = NORMAL;
25  }
26  }
27 
28  Substitution::Substitution( const carl::Variable& _variable, const smtrat::SqrtEx& _term, const Type& _type, carl::PointerSet<Condition>&& _oConditions, smtrat::ConstraintsT&& _sideCondition ):
29  mVariable( _variable ),
30  mpTerm( new smtrat::SqrtEx( _term ) ),
31  mType( _type ),
32  mpTermVariables( nullptr ),
33  mOriginalConditions( std::move( _oConditions ) ),
34  mSideCondition( std::move( _sideCondition ) )
35  {
36  if( mType == PLUS_EPSILON && mVariable.type() == carl::VariableType::VT_INT )
37  {
38  *mpTerm = *mpTerm + smtrat::SqrtEx(Poly(1));
39  mType = NORMAL;
40  }
41  }
42 
44  mVariable( _sub.variable() ),
45  mpTerm( new smtrat::SqrtEx( _sub.term() ) ),
46  mType( _sub.type() ),
47  mpTermVariables( _sub.mpTermVariables == nullptr ? nullptr : new carl::Variables( *_sub.mpTermVariables ) ),
48  mOriginalConditions( _sub.originalConditions() ),
49  mSideCondition( _sub.sideCondition() )
50  {}
51 
53  {
54  if( mpTermVariables != nullptr )
55  delete mpTermVariables;
56  delete mpTerm;
57  }
58 
59  unsigned Substitution::valuate( bool _preferMinusInf ) const
60  {
61  if( _preferMinusInf )
62  {
63  if( type() == MINUS_INFINITY || type() == PLUS_INFINITY )
64  return 9;
65  else if( type() == NORMAL )
66  {
67  if( term().is_constant() )
68  return 8;
69  else
70  {
71  if( term().has_sqrt() )
72  return 4;
73  else
74  {
75  if( term().denominator().is_constant() )
76  return 6;
77  else
78  return 5;
79  }
80  }
81  }
82  else
83  {
84  if( term().is_constant() )
85  return 7;
86  else
87  {
88  if( term().has_sqrt() )
89  return 1;
90  else
91  {
92  if( term().denominator().is_constant() )
93  return 3;
94  else
95  return 2;
96  }
97  }
98  }
99  }
100  else
101  {
102  if( type() == MINUS_INFINITY || type() == PLUS_INFINITY )
103  return 1;
104  else if( type() == NORMAL )
105  {
106  if( term().is_constant() )
107  return 9;
108  else
109  {
110  if( term().has_sqrt() )
111  return 5;
112  else
113  {
114  if( term().denominator().is_constant() )
115  return 7;
116  else
117  return 6;
118  }
119  }
120  }
121  else
122  {
123  if( term().is_constant() )
124  return 8;
125  else
126  {
127  if( term().has_sqrt() )
128  return 2;
129  else
130  {
131  if( term().denominator().is_constant() )
132  return 4;
133  else
134  return 3;
135  }
136  }
137  }
138  }
139  }
140 
141  bool Substitution::operator==( const Substitution& _substitution ) const
142  {
143  if( variable() == _substitution.variable() )
144  {
145  if( type() == _substitution.type() )
146  {
147  if( term() == _substitution.term() )
148  {
149  if( sideCondition() == _substitution.sideCondition() )
150  return true;
151  else
152  return false;
153  }
154  else
155  return false;
156  }
157  else
158  return false;
159  }
160  else
161  return false;
162  }
163 
164  std::ostream& operator<<(std::ostream& os, const Substitution& s) {
165  os << "[" << s.variable() << " -> ";
166  switch (s.type()) {
168  os << s.term() << "]"; break;
170  os << s.term() << " + epsilon]"; break;
172  os << "-infinity]"; break;
174  os << "+infinity]"; break;
176  os << "invalid]"; break;
177  default:
178  assert(false);
179  os << "unknown]"; break;
180  }
181  return os;
182  }
183 
184  void Substitution::print( bool _withOrigins, bool _withSideConditions, std::ostream& _out, const std::string& _init ) const
185  {
186  _out << _init << *this;
187  if( _withOrigins )
188  {
189  _out << " from {";
190  for( auto oCond = originalConditions().begin(); oCond != originalConditions().end(); ++oCond )
191  {
192  if( oCond != originalConditions().begin() )
193  _out << ", ";
194  _out << (**oCond).constraint();
195  }
196  _out << "}";
197  }
198  if( _withSideConditions && !sideCondition().empty() )
199  {
200  _out << " if ";
201  for( auto sCons = sideCondition().begin(); sCons != sideCondition().end(); ++sCons )
202  {
203  if( sCons != sideCondition().begin() )
204  _out << " and ";
205  _out << *sCons;
206  }
207  }
208  _out << std::endl;
209  }
210 } // end namspace vs
211 }
Type
The type of a substitution.
Definition: Substitution.h:23
void print(bool _withOrigins=false, bool _withSideConditions=false, std::ostream &_out=std::cout, const std::string &_init="") const
Prints this substitution on the given stream, with some additional information.
~Substitution()
The destructor.
carl::Variable mVariable
The variable to substitute.
Definition: Substitution.h:29
carl::Variables * mpTermVariables
The variables occurring in the term to substitute for.
Definition: Substitution.h:35
bool operator==(const Substitution &) const
const smtrat::SqrtEx & term() const
Definition: Substitution.h:83
const smtrat::ConstraintsT & sideCondition() const
Definition: Substitution.h:134
const carl::Variable & variable() const
Definition: Substitution.h:75
smtrat::SqrtEx * mpTerm
The pointer (if != NULL) to the square root term to substitute the variable for.
Definition: Substitution.h:31
const carl::PointerSet< Condition > & originalConditions() const
Definition: Substitution.h:126
Substitution(const carl::Variable &_variable, const Type &_type, carl::PointerSet< Condition > &&_oConditions, smtrat::ConstraintsT &&_sideCondition=smtrat::ConstraintsT())
Constructs a substitution with no square root term to map to.
unsigned valuate(bool _preferMinusInf=true) const
const Type & type() const
Definition: Substitution.h:110
bool is_constant(const T &t)
Checks whether the constraint is constant, i.e.
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
std::ostream & operator<<(std::ostream &_out, const Condition &_condition)
Definition: Condition.cpp:246
Class to create the formulas for axioms.
carl::Constraints< Poly > ConstraintsT
Definition: types.h:31
carl::SqrtEx< Poly > SqrtEx
Definition: model.h:22
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25