Rational algebra¶
RationalAlgebra is the field of rational numbers as a
member of the algebra hierarchy, computed exactly on rational tensors.
rationals
¶
The field of rational numbers, computed exactly.
RationalAlgebra is the semiring (ℚ, +, ·, 0, 1) of the algebra
hierarchy whose elements are exact: every operation takes and returns
RationalTensor values, whose sums,
products, differences, and quotients carry no rounding. A finite model
composed in it (a chain of stochastic matrices, the sum over the worlds of a
finite enumeration) yields the exact rational its float counterpart only
approximates, which is what makes an expected value statable exactly in a
test.
An operand that is not already rational enters by the reading every exact
computation uses (quivers.core.exact): integer and truth entries exactly,
and a floating entry as the shortest decimal that rounds to it, so the float
0.1 is the rational 1/10.
RationalAlgebra
¶
Bases: RealAlgebra
The field of rational numbers (ℚ, +, ·), computed exactly.
It is the subfield of quivers.core.algebras.RealAlgebra whose
elements are exact: the operations are the real ones, applied to
rational tensors, so a sum or product of rationals is its exact value
and a quotient by a nonzero rational is too. Every operand is read by
as_rational first.
tensor_op
¶
join
¶
The exact sum over axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, which is 0 over no terms. |
Source code in src/quivers/core/rationals.py
join_pair
¶
meet
¶
The exact minimum, refused over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reduced axis has size zero. |
Source code in src/quivers/core/rationals.py
negate
¶
subtract
¶
divide
¶
The exact quotient a / b.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, with no zero element.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/rationals.py
contains
¶
Membership in ℚ.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Whether each entry is a rational number: every entry of a rational, integer, or truth tensor, and every finite entry of a floating one. |
Source code in src/quivers/core/rationals.py
as_rational
¶
as_rational(t: Tensor) -> RationalTensor
A tensor's entries as exact rationals.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
A rational, integer, truth, or floating tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RationalTensor
|
The same numbers, a floating entry read as its shortest decimal. |
| RAISES | DESCRIPTION |
|---|---|
InexactOperation
|
If a floating entry is infinite or not a number, which no rational is. |