# Domains¶

Domains are intented to allow for the interpretation and manipulation of values of different types (text, integers, tuples and so on) using an internal representation based on integers. In short, a domain provides ways to translate what we call domain values into internal values and vice-versa. With domains, we will be able to create algebras (and, consequently, matrices) capable of dealing with values other than integers, while keeping the internal operations only over integers.

Note

The data types to be used in a domain need at least to provide a weak strict ordering implementation (in the `operator<()` method), as internally we use the domain values as keys in a map.

For example, below we create a domain over strings:

```ct4l::Domain<std::string> domain {"T", "I", "F"};
```

What happens internally is that the value “T” is mapped into the value 0, “I” to the value 1 and “F” to the value 2. We can then use the methods `ct4l::Domain::to_domain()` and `ct4l::Domain::to_internal()` in order to translate values from one representation into the other:

```std::string internal_value_of_T = domain.to_internal("T"); // the value 0
int domain_value_of_1 = domain.to_domain(1); // the value "I"
```

These methods are also implemented over containers vector and set in the natural way.

Below we offer another example, in which the domain values are pairs of integers, something common when dealing with product algebras or matrices:

```using IntPair = std::pair<int, int>;

ct4l::Domain<IntPair> prod_domain = {
{0, 0},
{0, 1},
{1, 0},
{1, 1}
};
```

## API¶

template<typename `T`>
class `ct4l::``Domain`

Represents a domain, internally represented as integers.

Author

Vitor Greati

Public Functions

`Domain`(const decltype(_values) &values)

Construct a domain from a vector of values.

Parameters
• `values`: a vector of values

`Domain`(const std::initializer_list<T> &values)

Construct a domain from an initializer list.

Parameters
• `values`: a list of values

inline decltype(_values) `values`() const

The domain values.

Return

the domain values as given in the construction of the domain

inline std::set<T> `values_set`() const

Produce the values as a set.

Return

the set of domain values

inline decltype(_translation) `translation`() const

Truth-table translation of domain values into integers.

Return

the truth-table translation from domain values into integers

inline auto `size`() const

The domain size.

Return

the domain size

int `to_internal`(const T &v) const

Translate a domain value into the corresponding internal value.

Return

the corresponding internal value

Parameters
• `v`: the domain value to be translated

std::set<int> `to_internal`(const std::set<T> &vs) const

Apply to_internal(const T&) const component-wise in a set.

Return

the corresponding translation into internal values

Parameters
• `vs`: the values to be translated

std::vector<int> `to_internal`(const std::vector<T> &vs) const

Apply to_internal(const T&) const component-wise in a vector.

Return

the corresponding translation into internal values

Parameters
• `vs`: the values to be translated

T `to_domain`(const int &v) const

Translate an internal value into the corresponding domain value.

Return

the corresponding domain value

Parameters
• `v`: the internal value to be translated

std::set<T> `to_domain`(const std::set<int> &vs) const

Apply to_domain(const int&) const component-wise in a set.

Return

the corresponding translation

Parameters
• `vs`: the internal values to be translated

std::vector<T> `to_domain`(const std::vector<int> &vs) const

Apply to_domain(const int&) const component-wise in a vector.

Return

the corresponding translation

Parameters
• `vs`: the internal values to be translated

inline bool `operator==`(const Domain<T> &other) const

Equality of domains.

Parameters
• `other`: the other domain

inline bool `operator!=`(const Domain<T> &other) const

Non-equality of domains.

Parameters
• `other`: the other domain