carl  24.04
Computer ARithmetic Library
FormulaContent.tpp
Go to the documentation of this file.
1 
2 namespace carl {
3 
4  template<typename Pol>
5  FormulaContent<Pol>::FormulaContent(FormulaType _type, size_t _id):
6  mHash(std::hash<Constraint<Pol>>()(Constraint<Pol>(_type == FormulaType::TRUE))),
7  mId( _id ),
8  mType(_type),
9  mContent(Constraint<Pol>(_type == FormulaType::TRUE))
10  {
11  assert(_type == FormulaType::TRUE || _type == FormulaType::FALSE);
12  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << _type);
13  }
14 
15  template<typename Pol>
16  FormulaContent<Pol>::FormulaContent(Variable _variable):
17  mHash(std::hash<Variable>()(_variable)),
18  mContent(_variable)
19  {
20  switch (_variable.type()) {
21  case VariableType::VT_BOOL:
22  mType = BOOL;
23  break;
24  default:
25  assert(false);
26  }
27  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << _variable);
28  }
29 
30  template<typename Pol>
31  FormulaContent<Pol>::FormulaContent(Constraint<Pol>&& _constraint):
32  mHash( std::hash<Constraint<Pol>>()(_constraint) ),
33  mType(FormulaType::CONSTRAINT),
34  mContent(std::move(_constraint))
35  {
36  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << std::get<Constraint<Pol>>(mContent));
37  }
38 
39  template<typename Pol>
40  FormulaContent<Pol>::FormulaContent(VariableComparison<Pol>&& _variableComparison):
41  mHash(std::hash<VariableComparison<Pol>>()(_variableComparison)),
42  mType(FormulaType::VARCOMPARE),
43  mContent(std::move(_variableComparison))
44  {
45  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << std::get<VariableComparison<Pol>>(mContent));
46  }
47 
48  template<typename Pol>
49  FormulaContent<Pol>::FormulaContent(VariableAssignment<Pol>&& _variableAssignment):
50  mHash(std::hash<VariableAssignment<Pol>>()(_variableAssignment)),
51  mType(FormulaType::VARASSIGN),
52  mContent(std::move(_variableAssignment))
53  {
54  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << std::get<VariableAssignment<Pol>>(mContent));
55  }
56 
57  template<typename Pol>
58  FormulaContent<Pol>::FormulaContent(BVConstraint&& _constraint):
59  mHash( ((size_t) _constraint.id()) << (sizeof(size_t)*4) ),
60  mType(FormulaType::BITVECTOR),
61  mContent(std::move(_constraint))
62  {
63  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << std::get<BVConstraint>(mContent));
64  }
65 
66 
67  template<typename Pol>
68  FormulaContent<Pol>::FormulaContent( UEquality&& _ueq ):
69  mHash( std::hash<UEquality>()( _ueq ) ),
70  mType(FormulaType::UEQ),
71  mContent(std::move(_ueq))
72  {
73  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << std::get<UEquality>(mContent));
74  }
75 
76  template<typename Pol>
77  FormulaContent<Pol>::FormulaContent(FormulaType _type, Formula<Pol>&& _subformula):
78  mHash( ((size_t)NOT << 5) ^ _subformula.hash() ),
79  mType(_type),
80  mContent(std::move(_subformula))
81  {
82  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << _type << " " << std::get<Formula<Pol>>(mContent));
83  }
84 
85  template<typename Pol>
86  FormulaContent<Pol>::FormulaContent(FormulaType _type, const std::initializer_list<Formula<Pol>>& _subformula):
87  FormulaContent(_type, std::move(Formulas<Pol>(_subformula.begin(), _subformula.end())))
88  {}
89 
90  template<typename Pol>
91  FormulaContent<Pol>::FormulaContent(FormulaType _type, Formulas<Pol>&& _subformulas):
92  mHash( (size_t)_type ),
93  mType( _type ),
94  mContent( std::move(_subformulas) )
95  {
96  assert( !std::get<Formulas<Pol>>(mContent).empty() );
97  assert( is_nary() );
98  std::get<Formulas<Pol>>(mContent).shrink_to_fit();
99  for (const auto& subformula: std::get<Formulas<Pol>>(mContent)) {
100  carl::hash_add(mHash, subformula.hash());
101  }
102  CARL_LOG_DEBUG("carl.formula", "Created " << *this << " from " << _type << " " << std::get<Formulas<Pol>>(mContent));
103  }
104 
105  template<typename Pol>
106  FormulaContent<Pol>::FormulaContent(FormulaType _type, std::vector<carl::Variable>&& _vars, const Formula<Pol>& _term):
107  ///@todo Construct reasonable hash
108  mHash( _term.hash() ),
109  mType(_type),
110  mContent(QuantifierContent<Pol>(std::move(_vars), std::move(Formula<Pol>(_term))))
111  {
112  assert(_type == FormulaType::EXISTS || _type == FormulaType::FORALL);
113  }
114 
115  template<typename Pol>
116  bool FormulaContent<Pol>::operator==(const FormulaContent& _content) const {
117  CARL_LOG_TRACE("carl.formula", *this << " == " << _content << " (" << mId << " / " << _content.mId << ")");
118  if (mId != 0 && _content.mId != 0) return mId == _content.mId;
119  if (mType != _content.mType) return false;
120  if (mType == FormulaType::TRUE || mType == FormulaType::FALSE) {
121  return true;
122  } else {
123  return mContent == _content.mContent;
124  }
125  }
126 }