Tour of the C++ Interface

Contents

Tour of the C++ Interface#

There are two main objects in exact-real. Modules, defined in module.hpp, and their elements, defined in element.hpp.

To work with exact-real, you first need to select a coefficient ring over which your module will live. Currently implemented are the ring of integers, the field of rationals, and real-embedded number fields.

To create a module over this coefficient ring, you need to select generators for your module. The most important such generators are a fixed rational number such as 1 and random transcendental numbers.

Once a coefficient ring and the generators have been selected, elements can be created and arithmetic with them can be performed.

Example#

We want to construct a module over the field of rational real numbers. We include the required headers and create our coefficient ring:

#include <exact-real/rational_field.hpp>
#include <exact-real/real_number.hpp>
#include <exact-real/module.hpp>
#include <exact-real/element.hpp>

exactreal::RationalField Q;

We fix our generators, one is a random real number in the interval (0, 1).

auto a = exactreal::RealNumber::rational(1);
auto b = exactreal::RealNumber::random();

We construct the module generated by these reals:

auto M = exactreal::Module<exactreal::RationalField>::make({a, b}, Q);

We construct some elements in this module, namely its generators:

auto x = M->gen(0);
auto y = M->gen(1);

We perform some arithmetic in this module:

std::cout << 2*x;
// -> 2

y + x - y == x
// -> true

Note that we can also multiply elements, however the result then typically lives in a larger module:

(y * y).module() == M
// -> false

Divisions are supported when the result can be determined exactly:

(y * y).truediv(y) == y
// -> true

Otherwise, only :cpp:func;`floor division <exactreal::Element::floordiv>` is possible:

x.floordiv(y) >= 1
// -> true