carl  24.04
Computer ARithmetic Library
Variables.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Visit.h"
5 
6 namespace carl{
7 
8 template<typename Pol>
9 void variables(const Formula<Pol>& f, carlVariables& vars) {
10  carl::visit(f,
11  [&vars](const Formula<Pol>& f) {
12  switch (f.type()) {
13  case FormulaType::BOOL:
14  vars.add(f.boolean());
15  break;
16  case FormulaType::CONSTRAINT:
17  carl::variables(f.constraint(), vars);
18  break;
19  case FormulaType::VARCOMPARE:
20  carl::variables(f.variable_comparison(), vars);
21  break;
22  case FormulaType::VARASSIGN:
23  carl::variables(f.variable_assignment(), vars);
24  break;
25  case FormulaType::BITVECTOR:
26  f.bv_constraint().gatherVariables(vars);
27  break;
28  case FormulaType::UEQ:
29  f.u_equality().gatherVariables(vars);
30  break;
31  case FormulaType::EXISTS:
32  case FormulaType::FORALL:
33  vars.add(f.quantified_variables().begin(),f.quantified_variables().end());
34  break;
35  default: break;
36  }
37  }
38  );
39 }
40 
41 template<typename Pol>
42 void uninterpreted_functions(const Formula<Pol>& f, std::set<UninterpretedFunction>& ufs) {
43  carl::visit(f,
44  [&ufs](const Formula<Pol>& f) {
45  if (f.type() == FormulaType::UEQ) {
46  f.u_equality().gatherUFs(ufs);
47  }
48  }
49  );
50 }
51 
52 template<typename Pol>
53 void uninterpreted_variables(const Formula<Pol>& f, std::set<UVariable>& uvs) {
54  carl::visit(f,
55  [&uvs](const Formula<Pol>& f) {
56  if (f.type() == FormulaType::UEQ) {
57  f.u_equality().gatherUVariables(uvs);
58  }
59  }
60  );
61 }
62 
63 template<typename Pol>
64 void bitvector_variables(const Formula<Pol>& f, std::set<BVVariable>& bvvs) {
65  carl::visit(f,
66  [&bvvs](const Formula<Pol>& f) {
67  if (f.type() == FormulaType::BITVECTOR) {
68  f.bv_constraint().gatherBVVariables(bvvs);
69  }
70  }
71  );
72 }
73 
74 /**
75  * Collects all constraint occurring in this formula.
76  * @param constraints The container to insert the constraint into.
77  */
78 template<typename Pol>
79 void arithmetic_constraints(const Formula<Pol>& f, std::vector<Constraint<Pol>>& constraints ) {
80  carl::visit(f,
81  [&constraints](const Formula<Pol>& f) {
82  switch (f.type()) {
83  case FormulaType::CONSTRAINT:
84  constraints.push_back(f.constraint());
85  break;
86  default: break;
87  }
88  }
89  );
90 }
91 
92 /**
93  * Collects all constraint occurring in this formula.
94  * @param constraints The container to insert the constraint into.
95  */
96 template<typename Pol>
97 void arithmetic_constraints(const Formula<Pol>& f, std::vector<Formula<Pol>>& constraints ) {
98  carl::visit(f,
99  [&constraints](const Formula<Pol>& f) {
100  switch (f.type()) {
101  case FormulaType::CONSTRAINT:
102  constraints.push_back(f);
103  break;
104  default: break;
105  }
106  }
107  );
108 }
109 
110 }
carl is the main namespace for the library.
@ BITVECTOR
carlVariables uninterpreted_variables(const T &t)
Definition: Variables.h:261
void uninterpreted_functions(const Formula< Pol > &f, std::set< UninterpretedFunction > &ufs)
Definition: Variables.h:42
carlVariables bitvector_variables(const T &t)
Definition: Variables.h:254
void visit(const Formula< Pol > &formula, Visitor func)
Recursively calls func on every subformula.
Definition: Visit.h:12
void arithmetic_constraints(const Formula< Pol > &f, std::vector< Constraint< Pol >> &constraints)
Collects all constraint occurring in this formula.
Definition: Variables.h:79
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62
Represent an SMT formula, which can be an atom for some background theory or a boolean combination of...
Definition: Formula.h:47
FormulaType type() const
Definition: Formula.h:254