modlineq | R Documentation |
If a, b
, and c
are integer vectors, this function
try to find, at each coordinate, the solution of the MLE
a x = b
mod n
. If the MLE a x = b mod n
has not
solutions (see modlin
), the value reported for the
coordinate will be 0 and the corresponding translation.
modlineq(a, b, n, no.sol = 0L)
a |
An integer or a vector of integers. |
b |
An integer or a vector of integers. |
n |
An integer or a vector of integers. |
no.sol |
Values to return when the equation is not solvable or yield the value 0. Default is 0. |
For a, b
, and c
integer scalars, it is just a
wrapper function to call modlin
.
If the solution is exact, then a numerical vector will be returned, otherwise, if there is not exact solution for some coordinate, the a list carrying the element on the diagonal matrix and a translation vector will be returned.
## Set the vector x, y, and m.
x <- c(9,32,24,56,60,27,28,5)
y <- c(8,1,0,56,60,0,28,2)
modulo <- c(64,125,64,64,64,64,64,64)
## Try to solve the modular equation a x = b mod n
m <- modlineq(a = x, b = y, n = modulo)
m
## Or in matrix form
diag(m)
## The reverse mapping is an affine transformation
mt <- modlineq(a = y, b = x, n = modulo, no.sol = 1L)
mt
## That is, vector 'x' is revovered with the transformaiton
(y %*% diag(mt$diag) + mt$translation) %% modulo
# Or
cat("\n---- \n")
(y %*% diag(mt$diag) + mt$translation) %% modulo == x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.