ac-library-hs-1.2.6.0: Data structures and algorithms
Safe HaskellSafe-Inferred
LanguageGHC2021

AtCoder.Extra.Math.Montgomery64

Description

Fast modular multiplication for Word64 using Montgomery multiplication. If the modulus value is known to fit in 32 bits, use the AtCoder.Internal.Barrett module instead.

Since: 1.2.6.0

Synopsis

Montgomery64

data Montgomery64 Source #

Fast modular multiplication for Word64 using Montgomery64 multiplication.

Since: 1.2.6.0

Instances

Instances details
Show Montgomery64 Source #

Since: 1.2.6.0

Instance details

Defined in AtCoder.Extra.Math.Montgomery64

Eq Montgomery64 Source #

Since: 1.2.6.0

Instance details

Defined in AtCoder.Extra.Math.Montgomery64

Constructor

new :: forall a. KnownNat a => Proxy# a -> Montgomery64 Source #

\(O(1)\) Static, shared storage of Montgomery64.

Constraints

  • (m le 2^{62})
  • \(m\) is odd

Since: 1.2.6.0

fromVal :: Word64 -> Montgomery64 Source #

\(O(1)\) Creates a Montgomery64 for a modulus value \(m\) of type Word64 value.

Constraints

  • (m le 2^{62})
  • \(m\) is odd

Since: 1.2.6.0

Accessor

umod :: Montgomery64 -> Word64 Source #

\(O(1)\) Retrieves the modulus \(m\).

Since: 1.2.6.0

Montgomery form encoding

encode :: Montgomery64 -> Word64 -> Word64 Source #

\(O(1)\) Converts the given Word64 to Montgomery form.

Since: 1.2.6.0

decode :: Montgomery64 -> Word64 -> Word64 Source #

\(O(1)\) Retrieves the value from a Montgomery form of value.

Since: 1.2.6.0

reduce :: Montgomery64 -> Word128 -> Word64 Source #

\(O(1)\) Takes the mod in Montgomery form.

Since: 1.2.6.0

Calculations

addMod :: Word64 -> Word64 -> Word64 -> Word64 Source #

\(O(1)\) Calculates \(a + b \bmod m\) in the Montgomery form.

subMod :: Word64 -> Word64 -> Word64 -> Word64 Source #

\(O(1)\) Calculates \(a - b \bmod m\) in the Montgomery form.

mulMod :: Montgomery64 -> Word64 -> Word64 -> Word64 Source #

\(O(1)\) Calculates \(a^n \bmod m\) in the Montgomery form.

Since: 1.2.6.0

powMod :: HasCallStack => Montgomery64 -> Word64 -> Int -> Word64 Source #

\(O(w)\) Calculates \(a^n \bmod m\) in the Montgomery form.

Since: 1.2.6.0

eq :: Word64 -> Word64 -> Word64 -> Bool Source #

\(O(1)\) Compares two values of Montgomery form and returns whether they represent the same value.

Since: 1.2.6.0