h&#"2      !"#$%&'()*+,-./01 Safe-Inferred 23(c) 2017-2022 Andrew LelechenkoMIT/Andrew Lelechenko  Safe-Inferred1;0modThis data type represents  https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_modulo_nintegers modulo m", equipped with useful instances.For example, 3 :: 3 10 stands for the class of integers congruent to 6 3 \bmod 10 \colon \ldots {D17}, D7, 3, 13, 23 \ldots :set -XDataKinds*3 + 8 :: Mod 10 -- 3 + 8 = 11 D 1 (mod 10)1Note: " 0 has no inhabitants, eventhough  \mathbb{Z}/0\mathbb{Z}  is technically isomorphic to  \mathbb{Z} .modThe canonical representative of the residue class, always between 0 and  m - 1  (inclusively).:set -XDataKinds -1 :: Mod 109modIf an argument is  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, return its modular inverse. Otherwise return 4.:set -XDataKinds0invertMod 3 :: Mod 10 -- 3 * 7 = 21 D 1 (mod 10)Just 71invertMod 4 :: Mod 10 -- 4 and 10 are not coprimeNothingmodDrop-in replacement for 5 with much better performance. Negative powers are allowed, but may throw 6, if an argument is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus.:set -XDataKinds.3 ^% 4 :: Mod 10 -- 3 ^ 4 = 81 D 1 (mod 10)1.3 ^% (-1) :: Mod 10 -- 3 * 7 = 21 D 1 (mod 10)7/4 ^% (-1) :: Mod 10 -- 4 and 10 are not coprime(*** Exception: divide by zeromodNo validation checks are performed; reading untrusted data may corrupt internal invariants.modNo validation checks are performed; reading untrusted data may corrupt internal invariants.modNo validation checks are performed; reading untrusted data may corrupt internal invariants.7modUnboxed vectors of  cause more nursery allocations than boxed ones, but reduce pressure on the garbage collector, especially for large vectors.8modUnboxed vectors of  cause more nursery allocations than boxed ones, but reduce pressure on the garbage collector, especially for large vectors.modNo validation checks are performed; reading untrusted data may corrupt internal invariants.modNo validation checks are performed; reading untrusted data may corrupt internal invariants. mod%Division by a residue, which is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, throws 6. Consider using  for non-prime moduli. mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  1https://en.wikipedia.org/wiki/Field_(mathematics)field.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m2, otherwise division by a residue, which is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, throws 6. Consider using  for non-prime moduli. mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  .https://en.wikipedia.org/wiki/Euclidean_domainEuclidean domain.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m%, otherwise we try to do our best: 9 x y returns any z such that  x == y * z, :% is not always 0, and both can throw 6. mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  (https://en.wikipedia.org/wiki/GCD_domain GCD domain . However, ; and <* are still meaningful even for composite m1, corresponding to a sum and an intersection of  1https://en.wikipedia.org/wiki/Ideal_(ring_theory)ideals.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m , otherwise = x y tries to return any Just z such that  x == y * z.mod-Wrapping behaviour, similar to the existing instance > ?.8(c) 2017-2022 Andrew LelechenkoMIT/Andrew Lelechenko  Safe-Inferred1;?"modThis data type represents  https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_modulo_nintegers modulo m", equipped with useful instances.For example, 3 :: 3 10 stands for the class of integers congruent to 6 3 \bmod 10 \colon \ldots {D17}, D7, 3, 13, 23 \ldots :set -XDataKinds*3 + 8 :: Mod 10 -- 3 + 8 = 11 D 1 (mod 10)1Note: " 0 has no inhabitants, eventhough  \mathbb{Z}/0\mathbb{Z}  is technically isomorphic to  \mathbb{Z} .modThe canonical representative of the residue class, always between 0 and  m - 1  (inclusively).:set -XDataKinds -1 :: Mod 109modIf an argument is  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, return its modular inverse. Otherwise return 4.:set -XDataKinds0invertMod 3 :: Mod 10 -- 3 * 7 = 21 D 1 (mod 10)Just 71invertMod 4 :: Mod 10 -- 4 and 10 are not coprimeNothing@mod6Extended binary gcd. The second argument must be odd.Amod+ge x y returns 1 is x >= y and 0 otherwise.modDrop-in replacement for  with a bit better performance. Negative powers are allowed, but may throw 6, if an argument is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus.:set -XDataKinds.3 ^% 4 :: Mod 10 -- 3 ^ 4 = 81 D 1 (mod 10)1.3 ^% (-1) :: Mod 10 -- 3 * 7 = 21 D 1 (mod 10)7/4 ^% (-1) :: Mod 10 -- 4 and 10 are not coprime(*** Exception: divide by zeromodNo validation checks are performed; reading untrusted data may corrupt internal invariants.modNo validation checks are performed; reading untrusted data may corrupt internal invariants.modNo validation checks are performed; reading untrusted data may corrupt internal invariants. mod%Division by a residue, which is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, throws 6. Consider using  for non-prime moduli.!mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  1https://en.wikipedia.org/wiki/Field_(mathematics)field.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m2, otherwise division by a residue, which is not  .https://en.wikipedia.org/wiki/Coprime_integerscoprime with the modulus, throws 6. Consider using  for non-prime moduli."mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  .https://en.wikipedia.org/wiki/Euclidean_domainEuclidean domain.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m%, otherwise we try to do our best: 9 x y returns any z such that  x == y * z, :% is not always 0, and both can throw 6.#mod m is not even an  -https://en.wikipedia.org/wiki/Integral_domainintegral domain for  .https://en.wikipedia.org/wiki/Composite_number composite m, much less a  (https://en.wikipedia.org/wiki/GCD_domain GCD domain . However, ; and <* are still meaningful even for composite m1, corresponding to a sum and an intersection of  1https://en.wikipedia.org/wiki/Ideal_(ring_theory)ideals.!The instance is lawful only for  *https://en.wikipedia.org/wiki/Prime_numberprime m , otherwise = x y tries to return any Just z such that  x == y * z.*mod-Wrapping behaviour, similar to the existing instance > ?.0modNo validation checks are performed; reading untrusted data may corrupt internal invariants.1modNo validation checks are performed; reading untrusted data may corrupt internal invariants.8           !"#$%#&#'()*+,-+,.+,/+,0+,1#2345678"mod-0.2.0.0-FAjAzEDJd5n5f9NXRNKy1eData.Mod Data.Mod.WordData.Mod.CompatPrelude^ModunMod invertMod^%$fVectorVectorMod$fMVectorMVectorMod $fUnboxMod $fPrimMod $fStorableMod$fFractionalMod $fFieldMod$fEuclideanMod$fGcdDomainMod $fRingMod $fSemiringMod$fNumMod $fBoundedMod $fEnumMod $fRealMod $fReadMod $fShowMod $fNFDataMod$fEqMod$fOrdMod $fGenericModghc-primGHC.Prim timesWord2# remWord2#base GHC.MaybeNothingGHC.RealGHC.Exception.Type DivideByZeroD:R:VectorMod0D:R:MVectorsMod0$semirings-0.6-FDSWy2RrznQ2q3n2IxlKEJData.EuclideanquotremgcdlcmdivideGHC.ReadRead GHC.TypesIntinvertModWordOddge