carl
24.04
Computer ARithmetic Library
Variable_Create.cpp
Go to the documentation of this file.
1
#include <cassert>
2
3
#include <
carl-arith/core/Variable.h
>
4
#include <
carl-arith/core/VariablePool.h
>
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
*/
31
carl::Variable
a =
carl::fresh_real_variable
(
"x"
);
32
carl::Variable
b =
carl::fresh_integer_variable
(
"y"
);
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
*/
44
carl::Variable
c =
carl::fresh_integer_variable
();
45
carl::Variable
d =
carl::fresh_real_variable
(
"d"
);
46
carl::Variable
e =
carl::fresh_real_variable
();
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
}
Variable.h
VariablePool.h
main
int main()
Definition:
Variable_Create.cpp:6
carl::VariableType::VT_REAL
@ VT_REAL
carl::VariableType::VT_INT
@ VT_INT
carl::fresh_real_variable
Variable fresh_real_variable() noexcept
Definition:
VariablePool.h:198
carl::fresh_integer_variable
Variable fresh_integer_variable() noexcept
Definition:
VariablePool.h:204
carl::Variable
A Variable represents an algebraic variable that can be used throughout carl.
Definition:
Variable.h:85
carl::Variable::name
std::string name() const
Retrieves the name of the variable.
Definition:
Variable.cpp:8
carl::Variable::type
constexpr VariableType type() const noexcept
Retrieves the type of the variable.
Definition:
Variable.h:131
examples
tutorial
Variable_Create.cpp
Generated by
1.9.1