carl  24.04
Computer ARithmetic Library
Variable_Create.cpp
Go to the documentation of this file.
1 #include <cassert>
2 
5 
6 int main() {
7  /*
8  * A carl::Variable object represents a single variable.
9  * A variable can have any type from carl::VariableType:
10  * - Real (VT_REAL)
11  * - Integer (VT_INT)
12  * - Boolean (VT_BOOL)
13  * - Uninterpreted (VT_UNINTERPRETED)
14  *
15  * A variable object consists only of a single unsigned variable, which
16  * encodes the following properties:
17  * - Rank
18  * - Id
19  * - Type
20  *
21  * The id is a unique identifier. All variables with the same id are
22  * considered equal. The id will directly be used for comparison.
23  * The rank can be used to change the default ordering at runtime, that is
24  * to impose an ordering that differs from the ordering of the ids.
25  * The type encodes the variable type.
26  *
27  * Usually, variables should be created using the carl::VariablePool.
28  * The VariablePool makes sure that a new variable gets a fresh consecutive
29  * ID and stores variable names.
30  */
33 
34  assert(a.type() == carl::VariableType::VT_REAL);
35  assert(a.name() == "x");
36  assert(b.type() == carl::VariableType::VT_INT);
37  assert(b.name() == "y");
38 
39  /*
40  * You can create anonymous variables by omitting the first argument.
41  * The variables will be printed in any output as "x_<id>" in this case.
42  * You can also omit the second argument, in this case the type is VT_REAL.
43  */
47 
48  assert(c.type() == carl::VariableType::VT_INT);
49  assert(d.name() == "d");
50  assert(e.type() == carl::VariableType::VT_REAL);
51 
52  /*
53  * As a variable objects technically consists of a single unsigned, most
54  * compilers should optimize and avoid the overhead of actually constructing
55  * objects. In this case, it may make a difference if you have
56  * - carl::Variable
57  * - const carl::Variable&
58  * as a function argument. Usually, carl::Variable should be preferred.
59  */
60 }
int main()
Variable fresh_real_variable() noexcept
Definition: VariablePool.h:198
Variable fresh_integer_variable() noexcept
Definition: VariablePool.h:204
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
std::string name() const
Retrieves the name of the variable.
Definition: Variable.cpp:8
constexpr VariableType type() const noexcept
Retrieves the type of the variable.
Definition: Variable.h:131