carl
24.04
Computer ARithmetic Library
|
A Variable represents an algebraic variable that can be used throughout carl. More...
#include <Variable.h>
Public Types | |
using | Arg = const Variable & |
Argument type for variables being function arguments. More... | |
Public Member Functions | |
constexpr | Variable ()=default |
Default constructor, constructing a variable, which is considered as not an actual variable. More... | |
constexpr std::size_t | id () const noexcept |
Retrieves the id of the variable. More... | |
constexpr VariableType | type () const noexcept |
Retrieves the type of the variable. More... | |
std::string | name () const |
Retrieves the name of the variable. More... | |
std::string | safe_name () const |
Retrieves a unique name of the variable of the form <type><id> . More... | |
constexpr std::size_t | rank () const noexcept |
Retrieves the rank of the variable. More... | |
Static Public Attributes | |
static constexpr std::size_t | BITSIZE = CHAR_BIT * sizeof(std::size_t) |
Number of bits available for the content. More... | |
static constexpr std::size_t | RESERVED_FOR_TYPE = 3 |
Number of bits reserved for the type. More... | |
static constexpr std::size_t | RESERVED_FOR_RANK = 4 |
Number of bits reserved for the rank. More... | |
static constexpr std::size_t | RESERVED = RESERVED_FOR_RANK + RESERVED_FOR_TYPE |
Overall number of bits reserved. More... | |
static constexpr std::size_t | AVAILABLE = BITSIZE - RESERVED |
Number of bits available for the id. More... | |
static const Variable | NO_VARIABLE = Variable() |
Instance of an invalid variable. More... | |
Private Member Functions | |
Variable (std::size_t id, VariableType type=VariableType::VT_REAL, std::size_t rank=0) noexcept | |
Private constructor to be used by the VariablePool. More... | |
Private Attributes | |
friend | VariablePool |
std::size_t | mContent = 0 |
The content of the variable. More... | |
Friends | |
Comparison operators | |
bool | operator== (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
bool | operator!= (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
bool | operator< (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
bool | operator<= (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
bool | operator> (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
bool | operator>= (Variable lhs, Variable rhs) noexcept |
Compares two variables. More... | |
A Variable represents an algebraic variable that can be used throughout carl.
Variables are basically bitvectors that contain [rank | id | type]
, called content.
id
is the identifier of this variable.type
is the variable type.rank
is zero be default, but can be used to create a custom variable ordering, as the comparison operators compare the whole content. The id
and the type
together form a unique identifier for a variable. If the VariablePool is used to construct variables (and we advise to do so), the id's will be consecutive starting with one for each variable type. The rank
is meant to change the variable order when passing a set of variables to another context, for example a function. A single variable (identified by id
and type
) should not occur with two different rank
values in the same context and hence such a comparison should never take place.A variable with id zero is considered invalid. It can be used as a default argument and can be compared to Variable::NO_VARIABLE. Such a variable can only be constructed using the default constructor and its content will always be zero.
Although not templated, we keep the whole class inlined for efficiency purposes. Note that this way, any decent compiler removes the overhead introduced, while having gained strong type-definitions and thus the ability to provide operator overloading.
Moreover, notice that for small classes like this, pass-by-value could be faster than pass-by-ref. However, this depends much on the capabilities of the compiler.
Definition at line 85 of file Variable.h.
using carl::Variable::Arg = const Variable& |
Argument type for variables being function arguments.
Definition at line 89 of file Variable.h.
|
inlineexplicitprivatenoexcept |
Private constructor to be used by the VariablePool.
id | The identifier of the variable. |
type | The type. |
rank | The rank. |
Definition at line 105 of file Variable.h.
|
constexprdefault |
Default constructor, constructing a variable, which is considered as not an actual variable.
Such an invalid variable is stored in NO_VARIABLE, so use this if you need a default value for a variable.
|
inlineconstexprnoexcept |
Retrieves the id of the variable.
Definition at line 123 of file Variable.h.
std::string carl::Variable::name | ( | ) | const |
Retrieves the name of the variable.
Definition at line 8 of file Variable.cpp.
|
inlineconstexprnoexcept |
Retrieves the rank of the variable.
Definition at line 153 of file Variable.h.
std::string carl::Variable::safe_name | ( | ) | const |
Retrieves a unique name of the variable of the form <type><id>
.
While <type>
consists of lowercase letters, <id>
is a decimal number. This unique name is meant to be used wherever a unique but notationally simple identifier is required, for example when interfacing with other systems.
Definition at line 11 of file Variable.cpp.
|
inlineconstexprnoexcept |
Retrieves the type of the variable.
Definition at line 131 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 173 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 176 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 179 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 170 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 182 of file Variable.h.
Compares two variables.
Note that for performance reasons, we compare the whole content of the variable (including the rank).
Note that the variable order is not the order of the variable id. We consider variables greater, if they are defined earlier, i.e. if they have a smaller id. Hence, the variables order and the order of the variable ids are reversed.
lhs | First variable. |
rhs | Second variable. |
lhs ~ rhs
, ~
being the relation that is checked. Definition at line 185 of file Variable.h.
Number of bits available for the id.
Definition at line 200 of file Variable.h.
|
staticconstexpr |
Number of bits available for the content.
Definition at line 191 of file Variable.h.
|
private |
The content of the variable.
In order to keep a variable object small, this is the only data member. All other data (like names or alike) are stored in the VariablePool.
Definition at line 97 of file Variable.h.
Instance of an invalid variable.
Definition at line 203 of file Variable.h.
|
staticconstexpr |
Overall number of bits reserved.
Definition at line 197 of file Variable.h.
|
staticconstexpr |
Number of bits reserved for the rank.
Definition at line 195 of file Variable.h.
|
staticconstexpr |
Number of bits reserved for the type.
Definition at line 193 of file Variable.h.
|
private |
Definition at line 86 of file Variable.h.