modlineq: Modular System of Linear Equation Solver (MLE)

modlineqR Documentation

Modular System of Linear Equation Solver (MLE)

Description

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.

Usage

modlineq(a, b, n, no.sol = 0L)

Arguments

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.

Details

For a, b, and c integer scalars, it is just a wrapper function to call modlin.

Value

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.

Examples

## 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

genomaths/GenomAutomorphism documentation built on May 10, 2024, 12:11 a.m.