Package jsl.utilities.math
Class ArithmeticMod
- java.lang.Object
-
- jsl.utilities.math.ArithmeticMod
-
public class ArithmeticMod extends java.lang.Object
This class provides facilities to compute multiplications of scalars, of vectors and of matrices modulo m. All algorithms are present in three different versions. These allow operations on `double`, `int` and `long`. The `int` and `long` versions work exactly like the `double` ones. This class comes from: https://github.com/umontreal-simul/ssj package umontreal.ssj.util.ArithmeticMod with some updates. It is used to facilitate creation of random number streams
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
matMatModM(double[][] A, double[][] B, double[][] C, double m)
Computes (A times B) mod m and puts the result in `C`.static void
matMatModM(int[][] A, int[][] B, int[][] C, int m)
Exactly like matMatModM(double[][],double[][],double[][],double) using `double`, but with `int` instead of `double`.static void
matMatModM(long[][] A, long[][] B, long[][] C, long m)
Exactly like matMatModM(double[][],double[][],double[][],double) using `double`, but with `long` instead of `double`.static void
matPowModM(double[][] A, double[][] B, double m, int c)
Computes (A raised to c) mod m and puts the result in `B`.static void
matPowModM(int[][] A, int[][] B, int m, int c)
Exactly like matPowModM(double[][],double[][],double,int) using `double`, but with `int` instead of `double`.static void
matPowModM(long[][] A, long[][] B, long m, int c)
Exactly like matPowModM(double[][],double[][],double,int) using `double`, but with `long` instead of `double`.static void
matTwoPowModM(double[][] A, double[][] B, double m, int e)
Computes (A raised to (2 to e)) mod m and puts the result in `B`.static void
matTwoPowModM(int[][] A, int[][] B, int m, int e)
Exactly like matTwoPowModM(double[][],double[][],double,int) using `double`, but with `int` instead of `double`.static void
matTwoPowModM(long[][] A, long[][] B, long m, int e)
Exactly like matTwoPowModM(double[][],double[][],double,int) using `double`, but with `long` instead of `double`.static void
matVecModM(double[][] A, double[] s, double[] v, double m)
Computes the result of (A times s) mod m and puts the result in `v`.static void
matVecModM(int[][] A, int[] s, int[] v, int m)
Exactly like matVecModM(double[][],double[],double[],double) using `double`, but with `int` instead of `double`.static void
matVecModM(long[][] A, long[] s, long[] v, long m)
Exactly like matVecModM(double[][],double[],double[],double) using `double`, but with `long` instead of `double`.static double
multModM(double a, double s, double c, double m)
Computes (a x s + c) mod m.static int
multModM(int a, int s, int c, int m)
Computes (a times s + c) mod m.static long
multModM(long a, long s, long c, long m)
Computes (a times s + c) mod m.
-
-
-
Method Detail
-
multModM
public static double multModM(double a, double s, double c, double m)
Computes (a x s + c) mod m. Where `m` must be smaller than 2 to the 35. Works also if `s` or `c` are negative. The result is always positive (and thus always between 0 and `m` - 1).- Parameters:
a
- the first factor of the multiplications
- the second factor of the multiplicationc
- the second term of the additionm
- the modulus- Returns:
- the result of the multiplication and the addition modulo `m`
-
matVecModM
public static void matVecModM(double[][] A, double[] s, double[] v, double m)
Computes the result of (A times s) mod m and puts the result in `v`. Where `s` and `v` are both column vectors. This method works even if `s` = `v`.- Parameters:
A
- the multiplication matrixs
- the multiplied vectorv
- the result of the multiplicationm
- the modulus
-
matMatModM
public static void matMatModM(double[][] A, double[][] B, double[][] C, double m)
Computes (A times B) mod m and puts the result in `C`. Works even if `A` = `C`, `B` = `C` or `A` = `B` = `C`.- Parameters:
A
- the first factor of the multiplicationB
- the second factor of the multiplicationC
- the result of the multiplicationm
- the modulus
-
matTwoPowModM
public static void matTwoPowModM(double[][] A, double[][] B, double m, int e)
Computes (A raised to (2 to e)) mod m and puts the result in `B`. B = A^{2^e} Works even if `A` = `B`.- Parameters:
A
- the matrix to raise to a powerB
- the result of exponentiationm
- the moduluse
- the log_2 of the exponent
-
matPowModM
public static void matPowModM(double[][] A, double[][] B, double m, int c)
Computes (A raised to c) mod m and puts the result in `B`. Works even if `A` = `B`.- Parameters:
A
- the matrix to raise to a powerB
- the result of the exponentiationm
- the modulusc
- the exponent
-
multModM
public static int multModM(int a, int s, int c, int m)
Computes (a times s + c) mod m. Works also if `s` or `c` are negative. The result is always positive (and thus always between 0 and `m` - 1).- Parameters:
a
- the first factor of the multiplications
- the second factor of the multiplicationc
- the second term of the additionm
- the modulus- Returns:
- the result of the multiplication and the addition modulo `m`
-
matVecModM
public static void matVecModM(int[][] A, int[] s, int[] v, int m)
Exactly like matVecModM(double[][],double[],double[],double) using `double`, but with `int` instead of `double`.- Parameters:
A
- the multiplication matrixs
- the multiplied vectorv
- the result of the multiplicationm
- the modulus
-
matMatModM
public static void matMatModM(int[][] A, int[][] B, int[][] C, int m)
Exactly like matMatModM(double[][],double[][],double[][],double) using `double`, but with `int` instead of `double`.- Parameters:
A
- the first factor of the multiplicationB
- the second factor of the multiplicationC
- the result of the multiplicationm
- the modulus
-
matTwoPowModM
public static void matTwoPowModM(int[][] A, int[][] B, int m, int e)
Exactly like matTwoPowModM(double[][],double[][],double,int) using `double`, but with `int` instead of `double`.- Parameters:
A
- the matrix to raise to a powerB
- the result of exponentiationm
- the moduluse
- the log_2 of the exponent
-
matPowModM
public static void matPowModM(int[][] A, int[][] B, int m, int c)
Exactly like matPowModM(double[][],double[][],double,int) using `double`, but with `int` instead of `double`.- Parameters:
A
- the matrix to raise to a powerB
- the result of the exponentiationm
- the modulusc
- the exponent
-
multModM
public static long multModM(long a, long s, long c, long m)
Computes (a times s + c) mod m. Works also if `s` or `c` are negative. The result is always positive (and thus always between 0 and `m` - 1).- Parameters:
a
- the first factor of the multiplications
- the second factor of the multiplicationc
- the second term of the additionm
- the modulus- Returns:
- the result of the multiplication and the addition modulo `m`
-
matVecModM
public static void matVecModM(long[][] A, long[] s, long[] v, long m)
Exactly like matVecModM(double[][],double[],double[],double) using `double`, but with `long` instead of `double`.- Parameters:
A
- the multiplication matrixs
- the multiplied vectorv
- the result of the multiplicationm
- the modulus
-
matMatModM
public static void matMatModM(long[][] A, long[][] B, long[][] C, long m)
Exactly like matMatModM(double[][],double[][],double[][],double) using `double`, but with `long` instead of `double`.- Parameters:
A
- the first factor of the multiplicationB
- the second factor of the multiplicationC
- the result of the multiplicationm
- the modulus
-
matTwoPowModM
public static void matTwoPowModM(long[][] A, long[][] B, long m, int e)
Exactly like matTwoPowModM(double[][],double[][],double,int) using `double`, but with `long` instead of `double`.- Parameters:
A
- the matrix to raise to a powerB
- the result of exponentiationm
- the moduluse
- the log_2 of the exponent
-
matPowModM
public static void matPowModM(long[][] A, long[][] B, long m, int c)
Exactly like matPowModM(double[][],double[][],double,int) using `double`, but with `long` instead of `double`.- Parameters:
A
- the matrix to raise to a powerB
- the result of the exponentiationm
- the modulusc
- the exponent
-
-