diff options
author | Aina Niemetz <aina.niemetz@gmail.com> | 2017-11-09 04:47:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-09 04:47:02 -0800 |
commit | a9cf481470c324a04f2254c5745eee26c45cb309 (patch) | |
tree | ad9065cae3e2728b41becc51697955e2ce8b26c1 /src/util/integer_gmp_imp.h | |
parent | 9444927c027e96f0fce22398611b97c274eff6b3 (diff) |
Add modular arithmetic operators. (#1321)
This adds functions on Integers to compute modular addition, multiplication and inverse.
This is required for the Gaussian Elimination preprocessing pass for BV.
Diffstat (limited to 'src/util/integer_gmp_imp.h')
-rw-r--r-- | src/util/integer_gmp_imp.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/integer_gmp_imp.h b/src/util/integer_gmp_imp.h index 5f676dbc5..9d63ea7f0 100644 --- a/src/util/integer_gmp_imp.h +++ b/src/util/integer_gmp_imp.h @@ -293,6 +293,7 @@ public: } } } + /** * Returns the quotient according to Boute's Euclidean definition. * See the documentation for euclidianQR. @@ -392,6 +393,30 @@ public: } /** + * Compute addition of this Integer x + y modulo m. + */ + Integer modAdd(const Integer& y, const Integer& m) const; + + /** + * Compute multiplication of this Integer x * y modulo m. + */ + Integer modMultiply(const Integer& y, const Integer& m) const; + + /** + * Compute modular inverse x^-1 of this Integer x modulo m with m > 0. + * Returns a value x^-1 with 0 <= x^-1 < m such that x * x^-1 = 1 modulo m + * if such an inverse exists, and -1 otherwise. + * + * Such an inverse only exists if + * - x is non-zero + * - x and m are coprime, i.e., if gcd (x, m) = 1 + * + * Note that if x and m are coprime, then x^-1 > 0 if m > 1 and x^-1 = 0 + * if m = 1 (the zero ring). + */ + Integer modInverse(const Integer& m) const; + + /** * All non-zero integers z, z.divide(0) * ! zero.divides(zero) */ |