Class fmpq
extends virtual class flint
.
It represents vectors of arbitrary precision rational numbers.
Elements are specified by a pair of arbitrary precision signed
integers: a numerator and a positive, coprime denominator. There is
no representation for R's missing value NA_integer_
.
## Class generator functionsfmpq(x = 0L, length = 0L, names = NULL, num = 0L, den = 1L)
fmpq.array(x = 0L, dim = length(x), dimnames = NULL, num = 0L, den = 1L)
An fmpq
vector, possibly an array; see ‘Details’.
an atomic or flint
vector containing data for
conversion to fmpq
.
a numeric vector of length one giving the length of the return
value. If that exceeds the length of x
, then x
is
recycled. Non-integer values are rounded in the direction of zero.
the names
slot of the return value, either NULL
or a
character vector of equal length. Non-character names
are
coerced to character.
the dim
slot of the return value, an integer vector of
nonzero length. If the product exceeds the length of x
, then
x
is recycled. Non-integer numeric dim
are coerced to
integer.
the dimnames
slot of the return value, either NULL
or
a list of length equal to the length of dim
. The components
are either NULL
or character vectors of length given by
dim
. Non-character vector components of dimnames
are
coerced to character.
atomic or flint
vectors containing data for
conversion to fmpz
. Use these instead of
x
for initialization “by parts” (numerator and
denominator).
Real numbers and real parts of complex numbers are converted exactly, as floating-point numbers are rational by definition. Imaginary parts of complex numbers are discarded.
Character strings are converted using function mpq_set_str
from
the GNU MP library with argument base
set
to 0; see https://gmplib.org/manual/Initializing-Rationals.
An error is signaled if elements of num
, den
, or
x
are NaN
, -Inf
, or Inf
or if elements of
den
are 0.
.xData
, dim
, dimnames
, names
inherited from virtual class flint
.
!
signature(x = "fmpq")
:
equivalent to (but faster than) x == 0
.
%*%
, crossprod
, tcrossprod
signature(x = "fmpq", y = "fmpq")
:
signature(x = "fmpq", y = "ANY")
:
signature(x = "ANY", y = "fmpq")
:
matrix products. The “other” operand must be atomic or
inherit from virtual class flint
.
crossprod
and tcrossprod
behave as if y = x
when y
is missing or NULL
. Operands are promoted as
necessary and must be conformable (have compatible dimensions).
Non-array operands of length k
are handled as 1-by-k
or k
-by-1 matrices depending on the call.
+
signature(e1 = "fmpq", e2 = "missing")
:
returns a copy of the argument.
-
signature(e1 = "fmpq", e2 = "missing")
:
returns the negation of the argument.
Complex
signature(z = "fmpq")
:
mathematical functions of one argument; see
S4groupGeneric
. Member functions requiring
promotion to a floating-point type may not be implemented.
Math
signature(x = "fmpq")
:
mathematical functions of one argument; see
S4groupGeneric
. Member functions requiring
promotion to a floating-point type may not be implemented.
Math2
signature(x = "fmpq")
:
decimal rounding according to a second argument digits
; see
S4groupGeneric
. There are just two member
member functions: round
, signif
.
Ops
signature(e1 = "fmpq", e2 = "fmpq")
:
signature(e1 = "fmpq", e2 = "ANY")
:
signature(e1 = "ANY", e2 = "fmpq")
:
binary arithmetic, comparison, and logical operators; see
S4groupGeneric
. The “other” operand
must be atomic or inherit from virtual class
flint
. Operands are promoted as necessary.
Array operands must be conformable (have identical dimensions).
Non-array operands are recycled.
Summary
signature(x = "fmpq")
:
univariate summary statistics; see
S4groupGeneric
. The return value is a
logical vector of length 1 (any
, all
) or an
fmpq
vector of length 1 or 2 (sum
, prod
,
min
, max
, range
).
anyNA
signature(x = "fmpq")
:
returns FALSE
, as fmpq
has no representation for
NaN
.
as.vector
signature(x = "fmpq")
:
returns as.vector(y, mode)
, where y
is a double
vector containing the result of converting each element of
x
to the range of double, rounding if the value is not
exactly representable in double precision. The rounding mode is
to the nearest representable number in the direction of zero,
unless the element exceeds .Machine[["double.xmax"]]
in
absolute value, in which case -Inf
or Inf
is
introduced with a warning. Coercion to types "character"
,
"symbol"
(synonym "name"
), "pairlist"
,
"list"
, and "expression"
, which are not
“number-like”, is handled specially. See also
asVector
.
backsolve
signature(r = "fmpq", x = "fmpq")
:
signature(r = "fmpq", x = "ANY")
:
signature(r = "ANY", x = "fmpq")
:
solution of the triangular system op2(op1(r)) %*% y = x
,
where op1=ifelse(upper.tri, triu, tril)
and
op2=ifelse(transpose, t, identity)
and upper.tri
and
transpose
are optional logical arguments with default
values TRUE
and FALSE
, respectively. The
“other” operand must be atomic or inherit from virtual
class flint
. If x
is missing, then
the return value is the inverse of op2(op1(r))
, as if
x
were the identity matrix. Operands are promoted as
necessary and must be conformable (have compatible dimensions).
Non-array x
are handled as length(x)
-by-1 matrices.
If r
and (if not missing) x
are both formally
rational, then the solution is exact and the return value is an
fmpq
matrix.
chol
signature(x = "fmpq")
:
coerces x
to class arf
and
dispatches.
chol2inv
signature(x = "fmpq")
:
returns the inverse of the positive definite matrix whose upper
triangular Cholesky factor is the upper triangular part of
x
. The return value is the exact inverse, being computed
as tcrossprod(backsolve(x))
.
coerce
signature(from = "ANY", to = "fmpq")
:
returns the value of fmpq(from)
.
colSums
, colMeans
signature(x = "fmpq")
:
returns an fmpq
vector or array containing the column sums
or means of x
, defined as sums or means over dimensions
1:dims
.
colSums
signature(x = "fmpq")
:
returns an fmpq
vector or array containing the column sums
of x
, defined as sums over dimensions 1:dims
.
colMeans
signature(x = "fmpq")
:
returns an fmpq
vector or array containing
the column means of x
, defined as means over dimensions
1:dims
.
det
signature(x = "fmpq")
:
returns the determinant of x
as an fmpq
vector of
length 1.
determinant
signature(x = "fmpq")
:
returns a list with components modulus
and sign
specifying the determinant of x
, following the base
function, hence see determinant
. Note that
det(x)
and determinant(x, logarithm = FALSE)
are
exact, but determinant(x)
is not in general due to
rounding.
format
signature(x = "fmpq")
:
returns a character vector suitable for printing, using string
format "p/q"
. Optional arguments control the output; see
format-methods
.
is.finite
signature(x = "fmpq")
:
returns a logical vector whose elements are all TRUE
, as
fmpq
has no representation for NaN
, -Inf
, and
Inf
.
is.infinite
, is.na
, is.nan
signature(x = "fmpq")
:
returns a logical vector whose elements are all FALSE
, as
fmpq
has no representation for NaN
, -Inf
, and
Inf
.
is.unsorted
signature(x = "fmpq")
:
returns a logical indicating if x
is not sorted in
nondecreasing order (increasing order if optional argument
strictly
is set to TRUE
).
mean
signature(x = "fmpq")
:
returns the arithmetic mean. An error is signaled if the argument
length is 0, because the return type is fmpq
which cannot
represent the result of division by 0.
rowSums
, rowMeans
signature(x = "fmpq")
:
returns an fmpq
vector or array containing the row sums or
means of x
, defined as sums or means over dimensions
(dims+1):length(dim(x))
.
solve
signature(a = "fmpq", b = "fmpq")
:
signature(a = "fmpq", b = "ANY")
:
signature(a = "ANY", b = "fmpq")
:
solution of the general system a %*% x = b
. The
“other” operand must be atomic or inherit from virtual
class flint
. If b
is missing, then
the return value is the inverse of a
, as if b
were
the identity matrix. Operands are promoted as necessary and must
be conformable (have compatible dimensions). Non-array b
are handled as length(b)
-by-1 matrices. If a
and
(if not missing) b
are both formally rational, then the
solution is exact and the return value is an
fmpq
matrix.
The class generator function has six distinct usages:
fmpq()
fmpq(length=)
fmpq(x)
fmpq(x, length=)
fmpq(num=, den=)
fmpq(num=, den=, length=)
The first usage generates an empty vector. The second usage generates
a zero vector of the indicated length. The third usage converts
x
, preserving dimensions, dimension names, and names. The
fourth usage converts x
, recycling its elements to the
indicated length and discarding its dimensions, dimension names, and
names. The fifth and sixth usages, in which either of num
and
den
can be missing, use fmpz(num)
and
fmpz(den)
to separately initialize the numerators and
denominators of the fmpq
return value.
Attempts to recycle num
, den
, or x
of length zero
to nonzero length are an error.
Usage of fmpq.array
is modelled after array
.
The FLINT documentation of the underlying C type: https://flintlib.org/doc/fmpq.html
Virtual class flint
. Generic functions
Num
and Den
and their replacement forms
for getting and setting numerators and denominators.
showClass("fmpq")
showMethods(classes = "fmpq")
Run the code above in your browser using DataLab