{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies  #-}
{-# LANGUAGE TypeOperators #-}

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

{- |
Module      :  Internal.Modular
Copyright   :  (c) Alberto Ruiz 2015
License     :  BSD3
Stability   :  experimental

Proof of concept of statically checked modular arithmetic.

-}

module Internal.Modular(
    Mod, type (./.)
) where

import Internal.Vector
import Internal.Matrix hiding (size)
import Internal.Numeric
import Internal.Element
import Internal.Container
import Internal.Vectorized (prodI,sumI,prodL,sumL)
import Internal.LAPACK (multiplyI, multiplyL)
import Internal.Algorithms(luFact,LU(..))
import Internal.Util(Normed(..),Indexable(..),
                     gaussElim, gaussElim_1, gaussElim_2,
                     luST, luSolve', luPacked', magnit, invershur)
import Internal.ST(mutable)
#if MIN_VERSION_base(4,11,0)
import GHC.TypeLits hiding (Mod)
#else
import GHC.TypeLits
#endif
import Data.Proxy(Proxy)
import Foreign.ForeignPtr(castForeignPtr)
import Foreign.Storable
import Data.Ratio
import Data.Complex
import Control.DeepSeq ( NFData(..) )
#if MIN_VERSION_base(4,11,0)
import Prelude hiding ((<>))
#endif



-- | Wrapper with a phantom integer for statically checked modular arithmetic.
newtype Mod (n :: Nat) t = Mod {Mod n t -> t
unMod:: t}
  deriving (Ptr b -> Int -> IO (Mod n t)
Ptr b -> Int -> Mod n t -> IO ()
Ptr (Mod n t) -> IO (Mod n t)
Ptr (Mod n t) -> Int -> IO (Mod n t)
Ptr (Mod n t) -> Int -> Mod n t -> IO ()
Ptr (Mod n t) -> Mod n t -> IO ()
Mod n t -> Int
(Mod n t -> Int)
-> (Mod n t -> Int)
-> (Ptr (Mod n t) -> Int -> IO (Mod n t))
-> (Ptr (Mod n t) -> Int -> Mod n t -> IO ())
-> (forall b. Ptr b -> Int -> IO (Mod n t))
-> (forall b. Ptr b -> Int -> Mod n t -> IO ())
-> (Ptr (Mod n t) -> IO (Mod n t))
-> (Ptr (Mod n t) -> Mod n t -> IO ())
-> Storable (Mod n t)
forall b. Ptr b -> Int -> IO (Mod n t)
forall b. Ptr b -> Int -> Mod n t -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
forall (n :: Nat) t. Storable t => Ptr (Mod n t) -> IO (Mod n t)
forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Int -> IO (Mod n t)
forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Int -> Mod n t -> IO ()
forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Mod n t -> IO ()
forall (n :: Nat) t. Storable t => Mod n t -> Int
forall (n :: Nat) t b. Storable t => Ptr b -> Int -> IO (Mod n t)
forall (n :: Nat) t b.
Storable t =>
Ptr b -> Int -> Mod n t -> IO ()
poke :: Ptr (Mod n t) -> Mod n t -> IO ()
$cpoke :: forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Mod n t -> IO ()
peek :: Ptr (Mod n t) -> IO (Mod n t)
$cpeek :: forall (n :: Nat) t. Storable t => Ptr (Mod n t) -> IO (Mod n t)
pokeByteOff :: Ptr b -> Int -> Mod n t -> IO ()
$cpokeByteOff :: forall (n :: Nat) t b.
Storable t =>
Ptr b -> Int -> Mod n t -> IO ()
peekByteOff :: Ptr b -> Int -> IO (Mod n t)
$cpeekByteOff :: forall (n :: Nat) t b. Storable t => Ptr b -> Int -> IO (Mod n t)
pokeElemOff :: Ptr (Mod n t) -> Int -> Mod n t -> IO ()
$cpokeElemOff :: forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Int -> Mod n t -> IO ()
peekElemOff :: Ptr (Mod n t) -> Int -> IO (Mod n t)
$cpeekElemOff :: forall (n :: Nat) t.
Storable t =>
Ptr (Mod n t) -> Int -> IO (Mod n t)
alignment :: Mod n t -> Int
$calignment :: forall (n :: Nat) t. Storable t => Mod n t -> Int
sizeOf :: Mod n t -> Int
$csizeOf :: forall (n :: Nat) t. Storable t => Mod n t -> Int
Storable)

instance (NFData t) => NFData (Mod n t)
  where
    rnf :: Mod n t -> ()
rnf (Mod t
x) = t -> ()
forall a. NFData a => a -> ()
rnf t
x

infixr 5 ./.
type (./.) x n = Mod n x

instance (Integral t, Enum t, KnownNat m) => Enum (Mod m t)
  where
    toEnum :: Int -> Mod m t
toEnum = (t -> Int -> t) -> Int -> Mod m t
forall (m :: Nat) a b.
(Num b, KnownNat m) =>
(b -> a -> b) -> a -> Mod m b
l0 (\t
m Int
x -> Int -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> t) -> Int -> t
forall a b. (a -> b) -> a -> b
$ Int
x Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` (t -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
m))
    fromEnum :: Mod m t -> Int
fromEnum = t -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (t -> Int) -> (Mod m t -> t) -> Mod m t -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod

instance (Eq t, KnownNat m) => Eq (Mod m t)
  where
    Mod m t
a == :: Mod m t -> Mod m t -> Bool
== Mod m t
b = (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
a) t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
b)

instance (Ord t, KnownNat m) => Ord (Mod m t)
  where
    compare :: Mod m t -> Mod m t -> Ordering
compare Mod m t
a Mod m t
b = t -> t -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
a) (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
b)

instance (Integral t, Real t, KnownNat m) => Real (Mod m t)
  where
    toRational :: Mod m t -> Rational
toRational Mod m t
x = Mod m t -> Integer
forall a. Integral a => a -> Integer
toInteger Mod m t
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1

instance (Integral t, KnownNat m) => Integral (Mod m t)
  where
    toInteger :: Mod m t -> Integer
toInteger = t -> Integer
forall a. Integral a => a -> Integer
toInteger (t -> Integer) -> (Mod m t -> t) -> Mod m t -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod
    quotRem :: Mod m t -> Mod m t -> (Mod m t, Mod m t)
quotRem Mod m t
a Mod m t
b = (t -> Mod m t
forall (n :: Nat) t. t -> Mod n t
Mod t
q, t -> Mod m t
forall (n :: Nat) t. t -> Mod n t
Mod t
r)
      where
         (t
q,t
r) = t -> t -> (t, t)
forall a. Integral a => a -> a -> (a, a)
quotRem (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
a) (Mod m t -> t
forall (n :: Nat) t. Mod n t -> t
unMod Mod m t
b)

-- | this instance is only valid for prime m
instance (Integral t, Show t, Eq t, KnownNat m) => Fractional (Mod m t)
  where
    recip :: Mod m t -> Mod m t
recip Mod m t
x
        | Mod m t
xMod m t -> Mod m t -> Mod m t
forall a. Num a => a -> a -> a
*Mod m t
r Mod m t -> Mod m t -> Bool
forall a. Eq a => a -> a -> Bool
== Mod m t
1  = Mod m t
r
        | Bool
otherwise = [Char] -> Mod m t
forall a. HasCallStack => [Char] -> a
error ([Char] -> Mod m t) -> [Char] -> Mod m t
forall a b. (a -> b) -> a -> b
$ Mod m t -> [Char]
forall a. Show a => a -> [Char]
show Mod m t
x [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
" does not have a multiplicative inverse mod "[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++Integer -> [Char]
forall a. Show a => a -> [Char]
show Integer
m'
      where
        r :: Mod m t
r = Mod m t
xMod m t -> Integer -> Mod m t
forall a b. (Num a, Integral b) => a -> b -> a
^(Integer
m'Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
-Integer
2 :: Integer)
        m' :: Integer
m' = Integer -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Integer) -> (Proxy m -> Integer) -> Proxy m -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Integer) -> Proxy m -> Integer
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    fromRational :: Rational -> Mod m t
fromRational Rational
x = Integer -> Mod m t
forall a. Num a => Integer -> a
fromInteger (Rational -> Integer
forall a. Ratio a -> a
numerator Rational
x) Mod m t -> Mod m t -> Mod m t
forall a. Fractional a => a -> a -> a
/ Integer -> Mod m t
forall a. Num a => Integer -> a
fromInteger (Rational -> Integer
forall a. Ratio a -> a
denominator Rational
x)

l2 :: forall m a b c. (Num c, KnownNat m) => (c -> a -> b -> c) -> Mod m a -> Mod m b -> Mod m c
l2 :: (c -> a -> b -> c) -> Mod m a -> Mod m b -> Mod m c
l2 c -> a -> b -> c
f (Mod a
u) (Mod b
v) = c -> Mod m c
forall (n :: Nat) t. t -> Mod n t
Mod (c -> a -> b -> c
f c
m' a
u b
v)
  where
    m' :: c
m' = Integer -> c
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> c) -> (Proxy m -> Integer) -> Proxy m -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> c) -> Proxy m -> c
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)

l1 :: forall m a b . (Num b, KnownNat m) => (b -> a -> b) -> Mod m a -> Mod m b
l1 :: (b -> a -> b) -> Mod m a -> Mod m b
l1 b -> a -> b
f (Mod a
u) = b -> Mod m b
forall (n :: Nat) t. t -> Mod n t
Mod (b -> a -> b
f b
m' a
u)
  where
    m' :: b
m' = Integer -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> b) -> (Proxy m -> Integer) -> Proxy m -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> b) -> Proxy m -> b
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)

l0 :: forall m a b . (Num b, KnownNat m) => (b -> a -> b) -> a -> Mod m b
l0 :: (b -> a -> b) -> a -> Mod m b
l0 b -> a -> b
f a
u = b -> Mod m b
forall (n :: Nat) t. t -> Mod n t
Mod (b -> a -> b
f b
m' a
u)
  where
    m' :: b
m' = Integer -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> b) -> (Proxy m -> Integer) -> Proxy m -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> b) -> Proxy m -> b
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)


instance Show t => Show (Mod n t)
  where
    show :: Mod n t -> [Char]
show = t -> [Char]
forall a. Show a => a -> [Char]
show (t -> [Char]) -> (Mod n t -> t) -> Mod n t -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mod n t -> t
forall (n :: Nat) t. Mod n t -> t
unMod

instance (Integral t, KnownNat n) => Num (Mod n t)
  where
    + :: Mod n t -> Mod n t -> Mod n t
(+) = (t -> t -> t -> t) -> Mod n t -> Mod n t -> Mod n t
forall (m :: Nat) a b c.
(Num c, KnownNat m) =>
(c -> a -> b -> c) -> Mod m a -> Mod m b -> Mod m c
l2 (\t
m t
a t
b -> (t
a t -> t -> t
forall a. Num a => a -> a -> a
+ t
b) t -> t -> t
forall a. Integral a => a -> a -> a
`mod` (t -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
m))
    * :: Mod n t -> Mod n t -> Mod n t
(*) = (t -> t -> t -> t) -> Mod n t -> Mod n t -> Mod n t
forall (m :: Nat) a b c.
(Num c, KnownNat m) =>
(c -> a -> b -> c) -> Mod m a -> Mod m b -> Mod m c
l2 (\t
m t
a t
b -> (t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
b) t -> t -> t
forall a. Integral a => a -> a -> a
`mod` (t -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
m))
    (-) = (t -> t -> t -> t) -> Mod n t -> Mod n t -> Mod n t
forall (m :: Nat) a b c.
(Num c, KnownNat m) =>
(c -> a -> b -> c) -> Mod m a -> Mod m b -> Mod m c
l2 (\t
m t
a t
b -> (t
a t -> t -> t
forall a. Num a => a -> a -> a
- t
b) t -> t -> t
forall a. Integral a => a -> a -> a
`mod` (t -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
m))
    abs :: Mod n t -> Mod n t
abs = (t -> t -> t) -> Mod n t -> Mod n t
forall (m :: Nat) a b.
(Num b, KnownNat m) =>
(b -> a -> b) -> Mod m a -> Mod m b
l1 ((t -> t) -> t -> t -> t
forall a b. a -> b -> a
const t -> t
forall a. Num a => a -> a
abs)
    signum :: Mod n t -> Mod n t
signum = (t -> t -> t) -> Mod n t -> Mod n t
forall (m :: Nat) a b.
(Num b, KnownNat m) =>
(b -> a -> b) -> Mod m a -> Mod m b
l1 ((t -> t) -> t -> t -> t
forall a b. a -> b -> a
const t -> t
forall a. Num a => a -> a
signum)
    fromInteger :: Integer -> Mod n t
fromInteger = (t -> Integer -> t) -> Integer -> Mod n t
forall (m :: Nat) a b.
(Num b, KnownNat m) =>
(b -> a -> b) -> a -> Mod m b
l0 (\t
m Integer
x -> Integer -> t
forall a. Num a => Integer -> a
fromInteger Integer
x t -> t -> t
forall a. Integral a => a -> a -> a
`mod` (t -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
m))


instance KnownNat m => Element (Mod m I)
  where
    constantD :: Mod m I -> Int -> Vector (Mod m I)
constantD Mod m I
x Int
n = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (I -> Int -> Vector I
forall a. Element a => a -> Int -> Vector a
constantD (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
x) Int
n)
    extractR :: MatrixOrder
-> Matrix (Mod m I)
-> I
-> Vector I
-> I
-> Vector I
-> IO (Matrix (Mod m I))
extractR MatrixOrder
ord Matrix (Mod m I)
m I
mi Vector I
is I
mj Vector I
js = Matrix I -> Matrix (Mod m I)
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix t -> Matrix (Mod n t)
i2fM (Matrix I -> Matrix (Mod m I))
-> IO (Matrix I) -> IO (Matrix (Mod m I))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MatrixOrder
-> Matrix I -> I -> Vector I -> I -> Vector I -> IO (Matrix I)
forall a.
Element a =>
MatrixOrder
-> Matrix a -> I -> Vector I -> I -> Vector I -> IO (Matrix a)
extractR MatrixOrder
ord (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
m) I
mi Vector I
is I
mj Vector I
js
    setRect :: Int -> Int -> Matrix (Mod m I) -> Matrix (Mod m I) -> IO ()
setRect Int
i Int
j Matrix (Mod m I)
m Matrix (Mod m I)
x = Int -> Int -> Matrix I -> Matrix I -> IO ()
forall a. Element a => Int -> Int -> Matrix a -> Matrix a -> IO ()
setRect Int
i Int
j (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
m) (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
x)
    sortI :: Vector (Mod m I) -> Vector I
sortI = Vector I -> Vector I
forall a. (Element a, Ord a) => Vector a -> Vector I
sortI (Vector I -> Vector I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    sortV :: Vector (Mod m I) -> Vector (Mod m I)
sortV = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector (Mod m I))
-> (Vector (Mod m I) -> Vector I)
-> Vector (Mod m I)
-> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector I -> Vector I
forall a. (Element a, Ord a) => Vector a -> Vector a
sortV (Vector I -> Vector I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    compareV :: Vector (Mod m I) -> Vector (Mod m I) -> Vector I
compareV Vector (Mod m I)
u Vector (Mod m I)
v = Vector I -> Vector I -> Vector I
forall a. (Element a, Ord a) => Vector a -> Vector a -> Vector I
compareV (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
u) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
v)
    selectV :: Vector I
-> Vector (Mod m I)
-> Vector (Mod m I)
-> Vector (Mod m I)
-> Vector (Mod m I)
selectV Vector I
c Vector (Mod m I)
l Vector (Mod m I)
e Vector (Mod m I)
g = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector I -> Vector I -> Vector I -> Vector I
forall a.
Element a =>
Vector I -> Vector a -> Vector a -> Vector a -> Vector a
selectV Vector I
c (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
l) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
e) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
g))
    remapM :: Matrix I -> Matrix I -> Matrix (Mod m I) -> Matrix (Mod m I)
remapM Matrix I
i Matrix I
j Matrix (Mod m I)
m = Matrix I -> Matrix (Mod m I)
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix t -> Matrix (Mod n t)
i2fM (Matrix I -> Matrix I -> Matrix I -> Matrix I
forall t. Element t => Matrix I -> Matrix I -> Matrix t -> Matrix t
remap Matrix I
i Matrix I
j (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
m))
    rowOp :: Int
-> Mod m I -> Int -> Int -> Int -> Int -> Matrix (Mod m I) -> IO ()
rowOp Int
c Mod m I
a Int
i1 Int
i2 Int
j1 Int
j2 Matrix (Mod m I)
x = (I -> Ptr I -> I -> I -> I -> I -> Trans (Matrix I) (IO I))
-> Int -> I -> Int -> Int -> Int -> Int -> Matrix I -> IO ()
forall c a.
(TransArray c, Storable a) =>
(I -> Ptr a -> I -> I -> I -> I -> Trans c (IO I))
-> Int -> a -> Int -> Int -> Int -> Int -> c -> IO ()
rowOpAux (I -> RowOp I
c_rowOpMI I
m') Int
c (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
a) Int
i1 Int
i2 Int
j1 Int
j2 (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
x)
      where
        m' :: I
m' = Integer -> I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> I) -> (Proxy m -> Integer) -> Proxy m -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> I) -> Proxy m -> I
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    gemm :: Vector (Mod m I)
-> Matrix (Mod m I)
-> Matrix (Mod m I)
-> Matrix (Mod m I)
-> IO ()
gemm Vector (Mod m I)
u Matrix (Mod m I)
a Matrix (Mod m I)
b Matrix (Mod m I)
c = Trans
  (Vector I)
  (Trans (Matrix I) (Trans (Matrix I) (Trans (Matrix I) (IO I))))
-> Vector I -> Matrix I -> Matrix I -> Matrix I -> IO ()
forall c1 c c2 c3.
(TransArray c1, TransArray c, TransArray c2, TransArray c3) =>
Trans c3 (Trans c2 (Trans c1 (Trans c (IO I))))
-> c3 -> c2 -> c1 -> c -> IO ()
gemmg (I -> Tgemm I
c_gemmMI I
m') (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
u) (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
a) (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
b) (Matrix (Mod m I) -> Matrix I
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m I)
c)
      where
        m' :: I
m' = Integer -> I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> I) -> (Proxy m -> Integer) -> Proxy m -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> I) -> Proxy m -> I
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    reorderV :: Vector I -> Vector I -> Vector (Mod m I) -> Vector (Mod m I)
reorderV Vector I
strides Vector I
dims = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector (Mod m I))
-> (Vector (Mod m I) -> Vector I)
-> Vector (Mod m I)
-> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (I
 -> Ptr I
 -> I
 -> Ptr I
 -> Trans (Vector I) (I -> Ptr I -> I -> Ptr I -> IO I))
-> Vector I -> Vector I -> Vector I -> Vector I
forall c t a1 t1 a.
(TransArray c, Storable t, Storable a1, Storable t1, Storable a) =>
(I
 -> Ptr a
 -> I
 -> Ptr t1
 -> Trans c (I -> Ptr t -> I -> Ptr a1 -> IO I))
-> Vector t1 -> c -> Vector t -> Vector a1
reorderAux I
-> Ptr I
-> I
-> Ptr I
-> Trans (Vector I) (I -> Ptr I -> I -> Ptr I -> IO I)
Reorder I
c_reorderI Vector I
strides Vector I
dims (Vector I -> Vector I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i

instance KnownNat m => Element (Mod m Z)
  where
    constantD :: Mod m Z -> Int -> Vector (Mod m Z)
constantD Mod m Z
x Int
n = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Z -> Int -> Vector Z
forall a. Element a => a -> Int -> Vector a
constantD (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
x) Int
n)
    extractR :: MatrixOrder
-> Matrix (Mod m Z)
-> I
-> Vector I
-> I
-> Vector I
-> IO (Matrix (Mod m Z))
extractR MatrixOrder
ord Matrix (Mod m Z)
m I
mi Vector I
is I
mj Vector I
js = Matrix Z -> Matrix (Mod m Z)
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix t -> Matrix (Mod n t)
i2fM (Matrix Z -> Matrix (Mod m Z))
-> IO (Matrix Z) -> IO (Matrix (Mod m Z))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MatrixOrder
-> Matrix Z -> I -> Vector I -> I -> Vector I -> IO (Matrix Z)
forall a.
Element a =>
MatrixOrder
-> Matrix a -> I -> Vector I -> I -> Vector I -> IO (Matrix a)
extractR MatrixOrder
ord (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
m) I
mi Vector I
is I
mj Vector I
js
    setRect :: Int -> Int -> Matrix (Mod m Z) -> Matrix (Mod m Z) -> IO ()
setRect Int
i Int
j Matrix (Mod m Z)
m Matrix (Mod m Z)
x = Int -> Int -> Matrix Z -> Matrix Z -> IO ()
forall a. Element a => Int -> Int -> Matrix a -> Matrix a -> IO ()
setRect Int
i Int
j (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
m) (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
x)
    sortI :: Vector (Mod m Z) -> Vector I
sortI = Vector Z -> Vector I
forall a. (Element a, Ord a) => Vector a -> Vector I
sortI (Vector Z -> Vector I)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    sortV :: Vector (Mod m Z) -> Vector (Mod m Z)
sortV = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector Z -> Vector (Mod m Z))
-> (Vector (Mod m Z) -> Vector Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Z -> Vector Z
forall a. (Element a, Ord a) => Vector a -> Vector a
sortV (Vector Z -> Vector Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    compareV :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector I
compareV Vector (Mod m Z)
u Vector (Mod m Z)
v = Vector Z -> Vector Z -> Vector I
forall a. (Element a, Ord a) => Vector a -> Vector a -> Vector I
compareV (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
u) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
v)
    selectV :: Vector I
-> Vector (Mod m Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
selectV Vector I
c Vector (Mod m Z)
l Vector (Mod m Z)
e Vector (Mod m Z)
g = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector Z -> Vector Z -> Vector Z -> Vector Z
forall a.
Element a =>
Vector I -> Vector a -> Vector a -> Vector a -> Vector a
selectV Vector I
c (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
l) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
e) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
g))
    remapM :: Matrix I -> Matrix I -> Matrix (Mod m Z) -> Matrix (Mod m Z)
remapM Matrix I
i Matrix I
j Matrix (Mod m Z)
m = Matrix Z -> Matrix (Mod m Z)
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix t -> Matrix (Mod n t)
i2fM (Matrix I -> Matrix I -> Matrix Z -> Matrix Z
forall t. Element t => Matrix I -> Matrix I -> Matrix t -> Matrix t
remap Matrix I
i Matrix I
j (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
m))
    rowOp :: Int
-> Mod m Z -> Int -> Int -> Int -> Int -> Matrix (Mod m Z) -> IO ()
rowOp Int
c Mod m Z
a Int
i1 Int
i2 Int
j1 Int
j2 Matrix (Mod m Z)
x = (I -> Ptr Z -> I -> I -> I -> I -> Trans (Matrix Z) (IO I))
-> Int -> Z -> Int -> Int -> Int -> Int -> Matrix Z -> IO ()
forall c a.
(TransArray c, Storable a) =>
(I -> Ptr a -> I -> I -> I -> I -> Trans c (IO I))
-> Int -> a -> Int -> Int -> Int -> Int -> c -> IO ()
rowOpAux (Z -> RowOp Z
c_rowOpML Z
m') Int
c (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
a) Int
i1 Int
i2 Int
j1 Int
j2 (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
x)
      where
        m' :: Z
m' = Integer -> Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Z) -> (Proxy m -> Integer) -> Proxy m -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Z) -> Proxy m -> Z
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    gemm :: Vector (Mod m Z)
-> Matrix (Mod m Z)
-> Matrix (Mod m Z)
-> Matrix (Mod m Z)
-> IO ()
gemm Vector (Mod m Z)
u Matrix (Mod m Z)
a Matrix (Mod m Z)
b Matrix (Mod m Z)
c = Trans
  (Vector Z)
  (Trans (Matrix Z) (Trans (Matrix Z) (Trans (Matrix Z) (IO I))))
-> Vector Z -> Matrix Z -> Matrix Z -> Matrix Z -> IO ()
forall c1 c c2 c3.
(TransArray c1, TransArray c, TransArray c2, TransArray c3) =>
Trans c3 (Trans c2 (Trans c1 (Trans c (IO I))))
-> c3 -> c2 -> c1 -> c -> IO ()
gemmg (Z -> Tgemm Z
c_gemmML Z
m') (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
u) (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
a) (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
b) (Matrix (Mod m Z) -> Matrix Z
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod m Z)
c)
      where
        m' :: Z
m' = Integer -> Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Z) -> (Proxy m -> Integer) -> Proxy m -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Z) -> Proxy m -> Z
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    reorderV :: Vector I -> Vector I -> Vector (Mod m Z) -> Vector (Mod m Z)
reorderV Vector I
strides Vector I
dims = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector Z -> Vector (Mod m Z))
-> (Vector (Mod m Z) -> Vector Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (I
 -> Ptr I
 -> I
 -> Ptr I
 -> Trans (Vector I) (I -> Ptr Z -> I -> Ptr Z -> IO I))
-> Vector I -> Vector I -> Vector Z -> Vector Z
forall c t a1 t1 a.
(TransArray c, Storable t, Storable a1, Storable t1, Storable a) =>
(I
 -> Ptr a
 -> I
 -> Ptr t1
 -> Trans c (I -> Ptr t -> I -> Ptr a1 -> IO I))
-> Vector t1 -> c -> Vector t -> Vector a1
reorderAux I
-> Ptr I
-> I
-> Ptr I
-> Trans (Vector I) (I -> Ptr Z -> I -> Ptr Z -> IO I)
Reorder Z
c_reorderL Vector I
strides Vector I
dims (Vector Z -> Vector Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i


instance KnownNat m => CTrans (Mod m I)
instance KnownNat m => CTrans (Mod m Z)


instance KnownNat m => Container Vector (Mod m I)
  where
    conj' :: Vector (Mod m I) -> Vector (Mod m I)
conj' = Vector (Mod m I) -> Vector (Mod m I)
forall a. a -> a
id
    size' :: Vector (Mod m I) -> IndexOf Vector
size' = Vector (Mod m I) -> IndexOf Vector
forall t. Storable t => Vector t -> Int
dim
    scale' :: Mod m I -> Vector (Mod m I) -> Vector (Mod m I)
scale' Mod m I
s Vector (Mod m I)
x = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (I -> Vector I -> Vector I
forall t (c :: * -> *). Linear t c => t -> c t -> c t
scale (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
s) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
x))
    addConstant :: Mod m I -> Vector (Mod m I) -> Vector (Mod m I)
addConstant Mod m I
c Vector (Mod m I)
x = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (I -> Vector I -> Vector I
forall (c :: * -> *) e. Container c e => e -> c e -> c e
addConstant (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
c) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
x))
    add' :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
add' Vector (Mod m I)
a Vector (Mod m I)
b = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector I -> Vector I -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
add' (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
a) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
b))
    sub :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
sub Vector (Mod m I)
a Vector (Mod m I)
b = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector I -> Vector I -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
sub (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
a) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
b))
    mul :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
mul Vector (Mod m I)
a Vector (Mod m I)
b = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector I -> Vector I -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
mul (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
a) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
b))
    equal :: Vector (Mod m I) -> Vector (Mod m I) -> Bool
equal Vector (Mod m I)
u Vector (Mod m I)
v = Vector I -> Vector I -> Bool
forall (c :: * -> *) e. Container c e => c e -> c e -> Bool
equal (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
u) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
v)
    scalar' :: Mod m I -> Vector (Mod m I)
scalar' Mod m I
x = [Mod m I] -> Vector (Mod m I)
forall a. Storable a => [a] -> Vector a
fromList [Mod m I
x]
    konst' :: Mod m I -> IndexOf Vector -> Vector (Mod m I)
konst' Mod m I
x = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector (Mod m I))
-> (Int -> Vector I) -> Int -> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. I -> Int -> Vector I
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
x)
    build' :: IndexOf Vector -> ArgOf Vector (Mod m I) -> Vector (Mod m I)
build' IndexOf Vector
n ArgOf Vector (Mod m I)
f = Int -> (Mod m I -> Mod m I) -> Vector (Mod m I)
forall d f (c :: * -> *) e. Build d f c e => d -> f -> c e
build Int
IndexOf Vector
n (Mod m I -> Mod m I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Mod m I -> Mod m I) -> (Mod m I -> Mod m I) -> Mod m I -> Mod m I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgOf Vector (Mod m I)
Mod m I -> Mod m I
f)
    cmap' :: (Mod m I -> b) -> Vector (Mod m I) -> Vector b
cmap' = (Mod m I -> b) -> Vector (Mod m I) -> Vector b
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
mapVector
    atIndex' :: Vector (Mod m I) -> IndexOf Vector -> Mod m I
atIndex' Vector (Mod m I)
x IndexOf Vector
k = I -> Mod m I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector I -> IndexOf Vector -> I
forall (c :: * -> *) e. Container c e => c e -> IndexOf c -> e
atIndex (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
x) IndexOf Vector
k)
    minIndex' :: Vector (Mod m I) -> IndexOf Vector
minIndex'     = Vector I -> Int
forall (c :: * -> *) e. Container c e => c e -> IndexOf c
minIndex (Vector I -> Int)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    maxIndex' :: Vector (Mod m I) -> IndexOf Vector
maxIndex'     = Vector I -> Int
forall (c :: * -> *) e. Container c e => c e -> IndexOf c
maxIndex (Vector I -> Int)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    minElement' :: Vector (Mod m I) -> Mod m I
minElement'   = I -> Mod m I
forall (n :: Nat) t. t -> Mod n t
Mod (I -> Mod m I)
-> (Vector (Mod m I) -> I) -> Vector (Mod m I) -> Mod m I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector I -> I
forall (c :: * -> *) e. Container c e => c e -> e
minElement (Vector I -> I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    maxElement' :: Vector (Mod m I) -> Mod m I
maxElement'   = I -> Mod m I
forall (n :: Nat) t. t -> Mod n t
Mod (I -> Mod m I)
-> (Vector (Mod m I) -> I) -> Vector (Mod m I) -> Mod m I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector I -> I
forall (c :: * -> *) e. Container c e => c e -> e
maxElement (Vector I -> I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    sumElements' :: Vector (Mod m I) -> Mod m I
sumElements'  = I -> Mod m I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (I -> Mod m I)
-> (Vector (Mod m I) -> I) -> Vector (Mod m I) -> Mod m I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. I -> Vector I -> I
forall c a.
(TransRaw c (I -> Ptr a -> IO I)
 ~ (I -> Ptr I -> I -> Ptr I -> IO I),
 TransArray c, Storable a) =>
I -> c -> a
sumI I
m' (Vector I -> I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
      where
        m' :: I
m' = Integer -> I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> I) -> (Proxy m -> Integer) -> Proxy m -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> I) -> Proxy m -> I
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    prodElements' :: Vector (Mod m I) -> Mod m I
prodElements' = I -> Mod m I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (I -> Mod m I)
-> (Vector (Mod m I) -> I) -> Vector (Mod m I) -> Mod m I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. I -> Vector I -> I
prodI I
m' (Vector I -> I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
      where
        m' :: I
m' = Integer -> I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> I) -> (Proxy m -> Integer) -> Proxy m -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> I) -> Proxy m -> I
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    step' :: Vector (Mod m I) -> Vector (Mod m I)
step'         = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector (Mod m I))
-> (Vector (Mod m I) -> Vector I)
-> Vector (Mod m I)
-> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector I -> Vector I
forall e (c :: * -> *). (Ord e, Container c e) => c e -> c e
step (Vector I -> Vector I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    find' :: (Mod m I -> Bool) -> Vector (Mod m I) -> [IndexOf Vector]
find' = (Mod m I -> Bool) -> Vector (Mod m I) -> [IndexOf Vector]
forall t. Storable t => (t -> Bool) -> Vector t -> [Int]
findV
    assoc' :: IndexOf Vector
-> Mod m I -> [(IndexOf Vector, Mod m I)] -> Vector (Mod m I)
assoc' = IndexOf Vector
-> Mod m I -> [(IndexOf Vector, Mod m I)] -> Vector (Mod m I)
forall t1 (t2 :: * -> *).
(Storable t1, Foldable t2) =>
Int -> t1 -> t2 (Int, t1) -> Vector t1
assocV
    accum' :: Vector (Mod m I)
-> (Mod m I -> Mod m I -> Mod m I)
-> [(IndexOf Vector, Mod m I)]
-> Vector (Mod m I)
accum' = Vector (Mod m I)
-> (Mod m I -> Mod m I -> Mod m I)
-> [(IndexOf Vector, Mod m I)]
-> Vector (Mod m I)
forall t1 (t2 :: * -> *) t3.
(Storable t1, Foldable t2) =>
Vector t1 -> (t3 -> t1 -> t1) -> t2 (Int, t3) -> Vector t1
accumV
    ccompare' :: Vector (Mod m I) -> Vector (Mod m I) -> Vector I
ccompare' Vector (Mod m I)
a Vector (Mod m I)
b = Vector I -> Vector I -> Vector I
forall t (c :: * -> *). (Ord t, Container c t) => c t -> c t -> c I
ccompare (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
a) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
b)
    cselect' :: Vector I
-> Vector (Mod m I)
-> Vector (Mod m I)
-> Vector (Mod m I)
-> Vector (Mod m I)
cselect' Vector I
c Vector (Mod m I)
l Vector (Mod m I)
e Vector (Mod m I)
g = Vector I -> Vector (Mod m I)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector I -> Vector (Mod m I)) -> Vector I -> Vector (Mod m I)
forall a b. (a -> b) -> a -> b
$ Vector I -> Vector I -> Vector I -> Vector I -> Vector I
forall (c :: * -> *) t.
Container c t =>
c I -> c t -> c t -> c t -> c t
cselect Vector I
c (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
l) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
e) (Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m I)
g)
    scaleRecip :: Mod m I -> Vector (Mod m I) -> Vector (Mod m I)
scaleRecip Mod m I
s Vector (Mod m I)
x = Mod m I -> Vector (Mod m I) -> Vector (Mod m I)
forall (c :: * -> *) e. Container c e => e -> c e -> c e
scale' Mod m I
s ((Mod m I -> Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall b (c :: * -> *) e.
(Element b, Container c e) =>
(e -> b) -> c e -> c b
cmap Mod m I -> Mod m I
forall a. Fractional a => a -> a
recip Vector (Mod m I)
x)
    divide :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
divide Vector (Mod m I)
x Vector (Mod m I)
y = Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
mul Vector (Mod m I)
x ((Mod m I -> Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall b (c :: * -> *) e.
(Element b, Container c e) =>
(e -> b) -> c e -> c b
cmap Mod m I -> Mod m I
forall a. Fractional a => a -> a
recip Vector (Mod m I)
y)
    arctan2' :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
arctan2' = Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall a. HasCallStack => a
undefined
    cmod' :: Mod m I -> Vector (Mod m I) -> Vector (Mod m I)
cmod' Mod m I
m = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector I -> Vector (Mod m I))
-> (Vector (Mod m I) -> Vector I)
-> Vector (Mod m I)
-> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. I -> Vector I -> Vector I
forall (c :: * -> *) e.
(Container c e, Integral e) =>
e -> c e -> c e
cmod' (Mod m I -> I
forall (n :: Nat) t. Mod n t -> t
unMod Mod m I
m) (Vector I -> Vector I)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    fromInt' :: Vector I -> Vector (Mod m I)
fromInt' = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod
    toInt' :: Vector (Mod m I) -> Vector I
toInt'   = Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    fromZ' :: Vector Z -> Vector (Mod m I)
fromZ'   = Vector I -> Vector (Mod m I)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector I -> Vector (Mod m I))
-> (Vector Z -> Vector I) -> Vector Z -> Vector (Mod m I)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Z -> Vector I
forall (c :: * -> *) e. Container c e => c Z -> c e
fromZ'
    toZ' :: Vector (Mod m I) -> Vector Z
toZ'     = Vector I -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c Z
toZ' (Vector I -> Vector Z)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> Vector Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i

instance KnownNat m => Container Vector (Mod m Z)
  where
    conj' :: Vector (Mod m Z) -> Vector (Mod m Z)
conj' = Vector (Mod m Z) -> Vector (Mod m Z)
forall a. a -> a
id
    size' :: Vector (Mod m Z) -> IndexOf Vector
size' = Vector (Mod m Z) -> IndexOf Vector
forall t. Storable t => Vector t -> Int
dim
    scale' :: Mod m Z -> Vector (Mod m Z) -> Vector (Mod m Z)
scale' Mod m Z
s Vector (Mod m Z)
x = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Z -> Vector Z -> Vector Z
forall t (c :: * -> *). Linear t c => t -> c t -> c t
scale (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
s) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
x))
    addConstant :: Mod m Z -> Vector (Mod m Z) -> Vector (Mod m Z)
addConstant Mod m Z
c Vector (Mod m Z)
x = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Z -> Vector Z -> Vector Z
forall (c :: * -> *) e. Container c e => e -> c e -> c e
addConstant (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
c) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
x))
    add' :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
add' Vector (Mod m Z)
a Vector (Mod m Z)
b = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector Z -> Vector Z -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
add' (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
a) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
b))
    sub :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
sub Vector (Mod m Z)
a Vector (Mod m Z)
b = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector Z -> Vector Z -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
sub (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
a) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
b))
    mul :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
mul Vector (Mod m Z)
a Vector (Mod m Z)
b = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector Z -> Vector Z -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
mul (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
a) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
b))
    equal :: Vector (Mod m Z) -> Vector (Mod m Z) -> Bool
equal Vector (Mod m Z)
u Vector (Mod m Z)
v = Vector Z -> Vector Z -> Bool
forall (c :: * -> *) e. Container c e => c e -> c e -> Bool
equal (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
u) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
v)
    scalar' :: Mod m Z -> Vector (Mod m Z)
scalar' Mod m Z
x = [Mod m Z] -> Vector (Mod m Z)
forall a. Storable a => [a] -> Vector a
fromList [Mod m Z
x]
    konst' :: Mod m Z -> IndexOf Vector -> Vector (Mod m Z)
konst' Mod m Z
x = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector Z -> Vector (Mod m Z))
-> (Int -> Vector Z) -> Int -> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z -> Int -> Vector Z
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
x)
    build' :: IndexOf Vector -> ArgOf Vector (Mod m Z) -> Vector (Mod m Z)
build' IndexOf Vector
n ArgOf Vector (Mod m Z)
f = Int -> (Mod m Z -> Mod m Z) -> Vector (Mod m Z)
forall d f (c :: * -> *) e. Build d f c e => d -> f -> c e
build Int
IndexOf Vector
n (Mod m Z -> Mod m Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Mod m Z -> Mod m Z) -> (Mod m Z -> Mod m Z) -> Mod m Z -> Mod m Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgOf Vector (Mod m Z)
Mod m Z -> Mod m Z
f)
    cmap' :: (Mod m Z -> b) -> Vector (Mod m Z) -> Vector b
cmap' = (Mod m Z -> b) -> Vector (Mod m Z) -> Vector b
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
mapVector
    atIndex' :: Vector (Mod m Z) -> IndexOf Vector -> Mod m Z
atIndex' Vector (Mod m Z)
x IndexOf Vector
k = Z -> Mod m Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector Z -> IndexOf Vector -> Z
forall (c :: * -> *) e. Container c e => c e -> IndexOf c -> e
atIndex (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
x) IndexOf Vector
k)
    minIndex' :: Vector (Mod m Z) -> IndexOf Vector
minIndex'     = Vector Z -> Int
forall (c :: * -> *) e. Container c e => c e -> IndexOf c
minIndex (Vector Z -> Int)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    maxIndex' :: Vector (Mod m Z) -> IndexOf Vector
maxIndex'     = Vector Z -> Int
forall (c :: * -> *) e. Container c e => c e -> IndexOf c
maxIndex (Vector Z -> Int)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    minElement' :: Vector (Mod m Z) -> Mod m Z
minElement'   = Z -> Mod m Z
forall (n :: Nat) t. t -> Mod n t
Mod (Z -> Mod m Z)
-> (Vector (Mod m Z) -> Z) -> Vector (Mod m Z) -> Mod m Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Z -> Z
forall (c :: * -> *) e. Container c e => c e -> e
minElement (Vector Z -> Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    maxElement' :: Vector (Mod m Z) -> Mod m Z
maxElement'   = Z -> Mod m Z
forall (n :: Nat) t. t -> Mod n t
Mod (Z -> Mod m Z)
-> (Vector (Mod m Z) -> Z) -> Vector (Mod m Z) -> Mod m Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Z -> Z
forall (c :: * -> *) e. Container c e => c e -> e
maxElement (Vector Z -> Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    sumElements' :: Vector (Mod m Z) -> Mod m Z
sumElements'  = Z -> Mod m Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Z -> Mod m Z)
-> (Vector (Mod m Z) -> Z) -> Vector (Mod m Z) -> Mod m Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z -> Vector Z -> Z
forall c a.
(TransRaw c (I -> Ptr a -> IO I)
 ~ (I -> Ptr Z -> I -> Ptr Z -> IO I),
 TransArray c, Storable a) =>
Z -> c -> a
sumL Z
m' (Vector Z -> Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
      where
        m' :: Z
m' = Integer -> Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Z) -> (Proxy m -> Integer) -> Proxy m -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Z) -> Proxy m -> Z
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    prodElements' :: Vector (Mod m Z) -> Mod m Z
prodElements' = Z -> Mod m Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Z -> Mod m Z)
-> (Vector (Mod m Z) -> Z) -> Vector (Mod m Z) -> Mod m Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z -> Vector Z -> Z
prodL Z
m' (Vector Z -> Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
      where
        m' :: Z
m' = Integer -> Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Z) -> (Proxy m -> Integer) -> Proxy m -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Z) -> Proxy m -> Z
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)
    step' :: Vector (Mod m Z) -> Vector (Mod m Z)
step'         = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector Z -> Vector (Mod m Z))
-> (Vector (Mod m Z) -> Vector Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Z -> Vector Z
forall e (c :: * -> *). (Ord e, Container c e) => c e -> c e
step (Vector Z -> Vector Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    find' :: (Mod m Z -> Bool) -> Vector (Mod m Z) -> [IndexOf Vector]
find' = (Mod m Z -> Bool) -> Vector (Mod m Z) -> [IndexOf Vector]
forall t. Storable t => (t -> Bool) -> Vector t -> [Int]
findV
    assoc' :: IndexOf Vector
-> Mod m Z -> [(IndexOf Vector, Mod m Z)] -> Vector (Mod m Z)
assoc' = IndexOf Vector
-> Mod m Z -> [(IndexOf Vector, Mod m Z)] -> Vector (Mod m Z)
forall t1 (t2 :: * -> *).
(Storable t1, Foldable t2) =>
Int -> t1 -> t2 (Int, t1) -> Vector t1
assocV
    accum' :: Vector (Mod m Z)
-> (Mod m Z -> Mod m Z -> Mod m Z)
-> [(IndexOf Vector, Mod m Z)]
-> Vector (Mod m Z)
accum' = Vector (Mod m Z)
-> (Mod m Z -> Mod m Z -> Mod m Z)
-> [(IndexOf Vector, Mod m Z)]
-> Vector (Mod m Z)
forall t1 (t2 :: * -> *) t3.
(Storable t1, Foldable t2) =>
Vector t1 -> (t3 -> t1 -> t1) -> t2 (Int, t3) -> Vector t1
accumV
    ccompare' :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector I
ccompare' Vector (Mod m Z)
a Vector (Mod m Z)
b = Vector Z -> Vector Z -> Vector I
forall t (c :: * -> *). (Ord t, Container c t) => c t -> c t -> c I
ccompare (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
a) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
b)
    cselect' :: Vector I
-> Vector (Mod m Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
cselect' Vector I
c Vector (Mod m Z)
l Vector (Mod m Z)
e Vector (Mod m Z)
g = Vector Z -> Vector (Mod m Z)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector Z -> Vector (Mod m Z)) -> Vector Z -> Vector (Mod m Z)
forall a b. (a -> b) -> a -> b
$ Vector I -> Vector Z -> Vector Z -> Vector Z -> Vector Z
forall (c :: * -> *) t.
Container c t =>
c I -> c t -> c t -> c t -> c t
cselect Vector I
c (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
l) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
e) (Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod m Z)
g)
    scaleRecip :: Mod m Z -> Vector (Mod m Z) -> Vector (Mod m Z)
scaleRecip Mod m Z
s Vector (Mod m Z)
x = Mod m Z -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (c :: * -> *) e. Container c e => e -> c e -> c e
scale' Mod m Z
s ((Mod m Z -> Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall b (c :: * -> *) e.
(Element b, Container c e) =>
(e -> b) -> c e -> c b
cmap Mod m Z -> Mod m Z
forall a. Fractional a => a -> a
recip Vector (Mod m Z)
x)
    divide :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
divide Vector (Mod m Z)
x Vector (Mod m Z)
y = Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (c :: * -> *) e. Container c e => c e -> c e -> c e
mul Vector (Mod m Z)
x ((Mod m Z -> Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall b (c :: * -> *) e.
(Element b, Container c e) =>
(e -> b) -> c e -> c b
cmap Mod m Z -> Mod m Z
forall a. Fractional a => a -> a
recip Vector (Mod m Z)
y)
    arctan2' :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
arctan2' = Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall a. HasCallStack => a
undefined
    cmod' :: Mod m Z -> Vector (Mod m Z) -> Vector (Mod m Z)
cmod' Mod m Z
m = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector Z -> Vector (Mod m Z))
-> (Vector (Mod m Z) -> Vector Z)
-> Vector (Mod m Z)
-> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Z -> Vector Z -> Vector Z
forall (c :: * -> *) e.
(Container c e, Integral e) =>
e -> c e -> c e
cmod' (Mod m Z -> Z
forall (n :: Nat) t. Mod n t -> t
unMod Mod m Z
m) (Vector Z -> Vector Z)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    fromInt' :: Vector I -> Vector (Mod m Z)
fromInt' = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector Z -> Vector (Mod m Z))
-> (Vector I -> Vector Z) -> Vector I -> Vector (Mod m Z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector I -> Vector Z
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt'
    toInt' :: Vector (Mod m Z) -> Vector I
toInt'   = Vector Z -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt (Vector Z -> Vector I)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> Vector I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i
    fromZ' :: Vector Z -> Vector (Mod m Z)
fromZ'   = Vector Z -> Vector (Mod m Z)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod
    toZ' :: Vector (Mod m Z) -> Vector Z
toZ'     = Vector (Mod m Z) -> Vector Z
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i


instance (Storable t, Indexable (Vector t) t) => Indexable (Vector (Mod m t)) (Mod m t)
  where
    (!) = Vector (Mod m t) -> Int -> Mod m t
forall t. Storable t => Vector t -> Int -> t
(@>)

type instance RealOf (Mod n I) = I
type instance RealOf (Mod n Z) = Z

instance KnownNat m => Product (Mod m I) where
    norm2 :: Vector (Mod m I) -> RealOf (Mod m I)
norm2      = Vector (Mod m I) -> RealOf (Mod m I)
forall a. HasCallStack => a
undefined
    absSum :: Vector (Mod m I) -> RealOf (Mod m I)
absSum     = Vector (Mod m I) -> RealOf (Mod m I)
forall a. HasCallStack => a
undefined
    norm1 :: Vector (Mod m I) -> RealOf (Mod m I)
norm1      = Vector (Mod m I) -> RealOf (Mod m I)
forall a. HasCallStack => a
undefined
    normInf :: Vector (Mod m I) -> RealOf (Mod m I)
normInf    = Vector (Mod m I) -> RealOf (Mod m I)
forall a. HasCallStack => a
undefined
    multiply :: Matrix (Mod m I) -> Matrix (Mod m I) -> Matrix (Mod m I)
multiply   = (Matrix I -> Matrix I -> Matrix I)
-> Matrix (Mod m I) -> Matrix (Mod m I) -> Matrix (Mod m I)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Element t, Element t,
 Element (Mod m t), Element (Mod n t), Element (Mod n t)) =>
(Matrix t -> Matrix t -> Matrix t)
-> Matrix (Mod n t) -> Matrix (Mod n t) -> Matrix (Mod m t)
lift2m (I -> Matrix I -> Matrix I -> Matrix I
multiplyI I
m')
      where
        m' :: I
m' = Integer -> I
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> I) -> (Proxy m -> Integer) -> Proxy m -> I
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> I) -> Proxy m -> I
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)

instance KnownNat m => Product (Mod m Z) where
    norm2 :: Vector (Mod m Z) -> RealOf (Mod m Z)
norm2      = Vector (Mod m Z) -> RealOf (Mod m Z)
forall a. HasCallStack => a
undefined
    absSum :: Vector (Mod m Z) -> RealOf (Mod m Z)
absSum     = Vector (Mod m Z) -> RealOf (Mod m Z)
forall a. HasCallStack => a
undefined
    norm1 :: Vector (Mod m Z) -> RealOf (Mod m Z)
norm1      = Vector (Mod m Z) -> RealOf (Mod m Z)
forall a. HasCallStack => a
undefined
    normInf :: Vector (Mod m Z) -> RealOf (Mod m Z)
normInf    = Vector (Mod m Z) -> RealOf (Mod m Z)
forall a. HasCallStack => a
undefined
    multiply :: Matrix (Mod m Z) -> Matrix (Mod m Z) -> Matrix (Mod m Z)
multiply   = (Matrix Z -> Matrix Z -> Matrix Z)
-> Matrix (Mod m Z) -> Matrix (Mod m Z) -> Matrix (Mod m Z)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Element t, Element t,
 Element (Mod m t), Element (Mod n t), Element (Mod n t)) =>
(Matrix t -> Matrix t -> Matrix t)
-> Matrix (Mod n t) -> Matrix (Mod n t) -> Matrix (Mod m t)
lift2m (Z -> Matrix Z -> Matrix Z -> Matrix Z
multiplyL Z
m')
      where
        m' :: Z
m' = Integer -> Z
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Z) -> (Proxy m -> Integer) -> Proxy m -> Z
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> Z) -> Proxy m -> Z
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)

instance KnownNat m => Normed (Vector (Mod m I))
  where
    norm_0 :: Vector (Mod m I) -> R
norm_0 = Vector I -> R
forall a. Normed a => a -> R
norm_0 (Vector I -> R)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt
    norm_1 :: Vector (Mod m I) -> R
norm_1 = Vector I -> R
forall a. Normed a => a -> R
norm_1 (Vector I -> R)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt
    norm_2 :: Vector (Mod m I) -> R
norm_2 = Vector I -> R
forall a. Normed a => a -> R
norm_2 (Vector I -> R)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt
    norm_Inf :: Vector (Mod m I) -> R
norm_Inf = Vector I -> R
forall a. Normed a => a -> R
norm_Inf (Vector I -> R)
-> (Vector (Mod m I) -> Vector I) -> Vector (Mod m I) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt

instance KnownNat m => Normed (Vector (Mod m Z))
  where
    norm_0 :: Vector (Mod m Z) -> R
norm_0 = Vector Z -> R
forall a. Normed a => a -> R
norm_0 (Vector Z -> R)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c Z
toZ
    norm_1 :: Vector (Mod m Z) -> R
norm_1 = Vector Z -> R
forall a. Normed a => a -> R
norm_1 (Vector Z -> R)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c Z
toZ
    norm_2 :: Vector (Mod m Z) -> R
norm_2 = Vector Z -> R
forall a. Normed a => a -> R
norm_2 (Vector Z -> R)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c Z
toZ
    norm_Inf :: Vector (Mod m Z) -> R
norm_Inf = Vector Z -> R
forall a. Normed a => a -> R
norm_Inf (Vector Z -> R)
-> (Vector (Mod m Z) -> Vector Z) -> Vector (Mod m Z) -> R
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Mod m Z) -> Vector Z
forall (c :: * -> *) e. Container c e => c e -> c Z
toZ


instance KnownNat m => Numeric (Mod m I)
instance KnownNat m => Numeric (Mod m Z)

i2f :: Storable t => Vector t -> Vector (Mod n t)
i2f :: Vector t -> Vector (Mod n t)
i2f Vector t
v = ForeignPtr (Mod n t) -> Int -> Int -> Vector (Mod n t)
forall a. Storable a => ForeignPtr a -> Int -> Int -> Vector a
unsafeFromForeignPtr (ForeignPtr t -> ForeignPtr (Mod n t)
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr t
fp) (Int
i) (Int
n)
    where (ForeignPtr t
fp,Int
i,Int
n) = Vector t -> (ForeignPtr t, Int, Int)
forall a. Storable a => Vector a -> (ForeignPtr a, Int, Int)
unsafeToForeignPtr Vector t
v

f2i :: Storable t => Vector (Mod n t) -> Vector t
f2i :: Vector (Mod n t) -> Vector t
f2i Vector (Mod n t)
v = ForeignPtr t -> Int -> Int -> Vector t
forall a. Storable a => ForeignPtr a -> Int -> Int -> Vector a
unsafeFromForeignPtr (ForeignPtr (Mod n t) -> ForeignPtr t
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr (Mod n t)
fp) (Int
i) (Int
n)
    where (ForeignPtr (Mod n t)
fp,Int
i,Int
n) = Vector (Mod n t) -> (ForeignPtr (Mod n t), Int, Int)
forall a. Storable a => Vector a -> (ForeignPtr a, Int, Int)
unsafeToForeignPtr Vector (Mod n t)
v

f2iM :: (Element t, Element (Mod n t)) => Matrix (Mod n t) -> Matrix t
f2iM :: Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod n t)
m = Matrix (Mod n t)
m { xdat :: Vector t
xdat = Vector (Mod n t) -> Vector t
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i (Matrix (Mod n t) -> Vector (Mod n t)
forall t. Matrix t -> Vector t
xdat Matrix (Mod n t)
m) }

i2fM :: (Element t, Element (Mod n t)) => Matrix t -> Matrix (Mod n t)
i2fM :: Matrix t -> Matrix (Mod n t)
i2fM Matrix t
m = Matrix t
m { xdat :: Vector (Mod n t)
xdat = Vector t -> Vector (Mod n t)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Matrix t -> Vector t
forall t. Matrix t -> Vector t
xdat Matrix t
m) }

vmod :: forall m t. (KnownNat m, Storable t, Integral t, Numeric t) => Vector t -> Vector (Mod m t)
vmod :: Vector t -> Vector (Mod m t)
vmod = Vector t -> Vector (Mod m t)
forall t (n :: Nat). Storable t => Vector t -> Vector (Mod n t)
i2f (Vector t -> Vector (Mod m t))
-> (Vector t -> Vector t) -> Vector t -> Vector (Mod m t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Vector t -> Vector t
forall (c :: * -> *) e.
(Container c e, Integral e) =>
e -> c e -> c e
cmod' t
m'
  where
    m' :: t
m' = Integer -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> t) -> (Proxy m -> Integer) -> Proxy m -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy m -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy m -> t) -> Proxy m -> t
forall a b. (a -> b) -> a -> b
$ (Proxy m
forall a. HasCallStack => a
undefined :: Proxy m)

lift1 :: (Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector t -> Vector t
f Vector (Mod n t)
a   = Vector t -> Vector (Mod m t)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector t -> Vector t
f (Vector (Mod n t) -> Vector t
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod n t)
a))
lift2 :: (Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 Vector t -> Vector t -> Vector t
f Vector (Mod n t)
a Vector (Mod n t)
b = Vector t -> Vector (Mod m t)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Vector t -> Vector t -> Vector t
f (Vector (Mod n t) -> Vector t
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod n t)
a) (Vector (Mod n t) -> Vector t
forall t (n :: Nat). Storable t => Vector (Mod n t) -> Vector t
f2i Vector (Mod n t)
b))

lift2m :: (Matrix t -> Matrix t -> Matrix t)
-> Matrix (Mod n t) -> Matrix (Mod n t) -> Matrix (Mod m t)
lift2m Matrix t -> Matrix t -> Matrix t
f Matrix (Mod n t)
a Matrix (Mod n t)
b = (Vector t -> Vector (Mod m t)) -> Matrix t -> Matrix (Mod m t)
forall a b.
(Element a, Element b) =>
(Vector a -> Vector b) -> Matrix a -> Matrix b
liftMatrix Vector t -> Vector (Mod m t)
forall (m :: Nat) t.
(KnownNat m, Storable t, Integral t, Numeric t) =>
Vector t -> Vector (Mod m t)
vmod (Matrix t -> Matrix t -> Matrix t
f (Matrix (Mod n t) -> Matrix t
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod n t)
a) (Matrix (Mod n t) -> Matrix t
forall t (n :: Nat).
(Element t, Element (Mod n t)) =>
Matrix (Mod n t) -> Matrix t
f2iM Matrix (Mod n t)
b))

instance KnownNat m => Num (Vector (Mod m I))
  where
    + :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
(+) = (Vector I -> Vector I -> Vector I)
-> Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 Vector I -> Vector I -> Vector I
forall a. Num a => a -> a -> a
(+)
    * :: Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
(*) = (Vector I -> Vector I -> Vector I)
-> Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 Vector I -> Vector I -> Vector I
forall a. Num a => a -> a -> a
(*)
    (-) = (Vector I -> Vector I -> Vector I)
-> Vector (Mod m I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 (-)
    abs :: Vector (Mod m I) -> Vector (Mod m I)
abs = (Vector I -> Vector I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector I -> Vector I
forall a. Num a => a -> a
abs
    signum :: Vector (Mod m I) -> Vector (Mod m I)
signum = (Vector I -> Vector I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector I -> Vector I
forall a. Num a => a -> a
signum
    negate :: Vector (Mod m I) -> Vector (Mod m I)
negate = (Vector I -> Vector I) -> Vector (Mod m I) -> Vector (Mod m I)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector I -> Vector I
forall a. Num a => a -> a
negate
    fromInteger :: Integer -> Vector (Mod m I)
fromInteger Integer
x = Vector I -> Vector (Mod m I)
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt (Integer -> Vector I
forall a. Num a => Integer -> a
fromInteger Integer
x)

instance KnownNat m => Num (Vector (Mod m Z))
  where
    + :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
(+) = (Vector Z -> Vector Z -> Vector Z)
-> Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 Vector Z -> Vector Z -> Vector Z
forall a. Num a => a -> a -> a
(+)
    * :: Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
(*) = (Vector Z -> Vector Z -> Vector Z)
-> Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 Vector Z -> Vector Z -> Vector Z
forall a. Num a => a -> a -> a
(*)
    (-) = (Vector Z -> Vector Z -> Vector Z)
-> Vector (Mod m Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t t (n :: Nat) (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t, Storable t) =>
(Vector t -> Vector t -> Vector t)
-> Vector (Mod n t) -> Vector (Mod n t) -> Vector (Mod m t)
lift2 (-)
    abs :: Vector (Mod m Z) -> Vector (Mod m Z)
abs = (Vector Z -> Vector Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector Z -> Vector Z
forall a. Num a => a -> a
abs
    signum :: Vector (Mod m Z) -> Vector (Mod m Z)
signum = (Vector Z -> Vector Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector Z -> Vector Z
forall a. Num a => a -> a
signum
    negate :: Vector (Mod m Z) -> Vector (Mod m Z)
negate = (Vector Z -> Vector Z) -> Vector (Mod m Z) -> Vector (Mod m Z)
forall (m :: Nat) t t (n :: Nat).
(KnownNat m, Integral t, Numeric t, Storable t) =>
(Vector t -> Vector t) -> Vector (Mod n t) -> Vector (Mod m t)
lift1 Vector Z -> Vector Z
forall a. Num a => a -> a
negate
    fromInteger :: Integer -> Vector (Mod m Z)
fromInteger Integer
x = Vector Z -> Vector (Mod m Z)
forall (c :: * -> *) e. Container c e => c Z -> c e
fromZ (Integer -> Vector Z
forall a. Num a => Integer -> a
fromInteger Integer
x)

--------------------------------------------------------------------------------

instance (KnownNat m) => Testable (Matrix (Mod m I))
  where
    checkT :: Matrix (Mod m I) -> (Bool, IO ())
checkT Matrix (Mod m I)
_ = (Bool, IO ())
test

test :: (Bool, IO ())
test = (Bool
ok, IO ()
info)
  where
    v :: Vector (Mod 11 I)
v = [Mod 11 I] -> Vector (Mod 11 I)
forall a. Storable a => [a] -> Vector a
fromList [Mod 11 I
3,-Mod 11 I
5,Mod 11 I
75] :: Vector (Mod 11 I)
    m :: Matrix (Mod 11 I)
m = (Int
3Int -> Int -> [Mod 11 I] -> Matrix (Mod 11 I)
forall a. Storable a => Int -> Int -> [a] -> Matrix a
><Int
3) [Mod 11 I
1..]   :: Matrix (Mod 11 I)

    a :: Matrix I
a = (Int
3Int -> Int -> [I] -> Matrix I
forall a. Storable a => Int -> Int -> [a] -> Matrix a
><Int
3) [I
1,I
2 , I
3
               ,I
4,I
5 , I
6
               ,I
0,I
10,-I
3] :: Matrix I

    b :: Matrix I
b = (Int
3Int -> Int -> [I] -> Matrix I
forall a. Storable a => Int -> Int -> [a] -> Matrix a
><Int
2) [I
0..] :: Matrix I

    am :: Matrix (Mod 13 I)
am = Matrix I -> Matrix (Mod 13 I)
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt Matrix I
a :: Matrix (Mod 13 I)
    bm :: Matrix (Mod 13 I)
bm = Matrix I -> Matrix (Mod 13 I)
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt Matrix I
b :: Matrix (Mod 13 I)
    ad :: Matrix R
ad = Matrix I -> Matrix R
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt Matrix I
a :: Matrix Double
    bd :: Matrix R
bd = Matrix I -> Matrix R
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt Matrix I
b :: Matrix Double

    g :: Matrix I
g = (Int
3Int -> Int -> [I] -> Matrix I
forall a. Storable a => Int -> Int -> [a] -> Matrix a
><Int
3) (I -> [I]
forall a. a -> [a]
repeat (I
40000)) :: Matrix I
    gm :: Matrix (Mod 100000 I)
gm = Matrix I -> Matrix (Mod 100000 I)
forall (c :: * -> *) e. Container c e => c I -> c e
fromInt Matrix I
g :: Matrix (Mod 100000 I)

    lg :: Matrix Z
lg = (Int
3Int -> Int -> [Z] -> Matrix Z
forall a. Storable a => Int -> Int -> [a] -> Matrix a
><Int
3) (Z -> [Z]
forall a. a -> [a]
repeat (Z
3Z -> Z -> Z
forall a. Num a => a -> a -> a
*Z
10Z -> Int -> Z
forall a b. (Num a, Integral b) => a -> b -> a
^(Int
9::Int))) :: Matrix Z
    lgm :: Matrix (Mod 10000000000 Z)
lgm = Matrix Z -> Matrix (Mod 10000000000 Z)
forall (c :: * -> *) e. Container c e => c Z -> c e
fromZ Matrix Z
lg :: Matrix (Mod 10000000000 Z)

    gen :: Int -> Matrix t
gen  Int
n = t -> Vector t -> Int -> Int -> Matrix t
forall t. Storable t => t -> Vector t -> Int -> Int -> Matrix t
diagRect t
1 (t -> Int -> Vector t
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst t
5 Int
n) Int
n Int
n :: Numeric t => Matrix t
    
    rgen :: Int -> Matrix R
rgen Int
n = Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
n :: Matrix R
    cgen :: Int -> Matrix C
cgen Int
n = Matrix R -> Matrix (ComplexOf R)
forall t (c :: * -> *).
(Convert t, Complexable c) =>
c t -> c (ComplexOf t)
complex (Int -> Matrix R
rgen Int
n) Matrix C -> Matrix C -> Matrix C
forall a. Num a => a -> a -> a
+ Matrix C -> Matrix C
forall t. Element t => Matrix t -> Matrix t
fliprl (Matrix R -> Matrix (ComplexOf R)
forall t (c :: * -> *).
(Convert t, Complexable c) =>
c t -> c (ComplexOf t)
complex (Int -> Matrix R
rgen Int
n)) Matrix C -> Matrix C -> Matrix C
forall a. Num a => a -> a -> a
* C -> Matrix C
forall (c :: * -> *) e. Container c e => e -> c e
scalar (R
0R -> R -> C
forall a. a -> a -> Complex a
:+R
1) :: Matrix C
    sgen :: Int -> Matrix (SingleOf C)
sgen Int
n = Matrix C -> Matrix (SingleOf C)
forall t (c :: * -> *).
(Convert t, Complexable c) =>
c t -> c (SingleOf t)
single (Int -> Matrix C
cgen Int
n)
    
    checkGen :: Matrix t -> R
checkGen Matrix t
x = Vector t -> R
forall a. Normed a => a -> R
norm_Inf (Vector t -> R) -> Vector t -> R
forall a b. (a -> b) -> a -> b
$ Matrix t -> Vector t
forall t. Element t => Matrix t -> Vector t
flatten (Matrix t -> Vector t) -> Matrix t -> Vector t
forall a b. (a -> b) -> a -> b
$ Matrix t -> Matrix t
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t
invg Matrix t
x Matrix t -> Matrix t -> Matrix t
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix t
x Matrix t -> Matrix t -> Matrix t
forall a. Num a => a -> a -> a
- Int -> Matrix t
forall a. (Num a, Element a) => Int -> Matrix a
ident (Matrix t -> Int
forall t. Matrix t -> Int
rows Matrix t
x)
    
    invg :: Matrix t -> Matrix t
invg Matrix t
t = Matrix t -> Matrix t -> Matrix t
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t -> Matrix t
gaussElim Matrix t
t (Int -> Matrix t
forall a. (Num a, Element a) => Int -> Matrix a
ident (Matrix t -> Int
forall t. Matrix t -> Int
rows Matrix t
t))

    checkLU :: (t -> Bool) -> Matrix t -> R
checkLU t -> Bool
okf Matrix t
t = Vector t -> R
forall a. Normed a => a -> R
norm_Inf (Vector t -> R) -> Vector t -> R
forall a b. (a -> b) -> a -> b
$ Matrix t -> Vector t
forall t. Element t => Matrix t -> Vector t
flatten (Matrix t
l Matrix t -> Matrix t -> Matrix t
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix t
u Matrix t -> Matrix t -> Matrix t
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix t
p Matrix t -> Matrix t -> Matrix t
forall a. Num a => a -> a -> a
- Matrix t
t)
      where
        (Matrix t
l,Matrix t
u,Matrix t
p,t
_) = LU t -> (Matrix t, Matrix t, Matrix t, t)
forall t. Numeric t => LU t -> (Matrix t, Matrix t, Matrix t, t)
luFact (Matrix t -> [Int] -> LU t
forall t. Matrix t -> [Int] -> LU t
LU Matrix t
x' [Int]
p')
          where
            (Matrix t
x',[Int]
p') = (forall s. (Int, Int) -> STMatrix s t -> ST s [Int])
-> Matrix t -> (Matrix t, [Int])
forall t u.
Element t =>
(forall s. (Int, Int) -> STMatrix s t -> ST s u)
-> Matrix t -> (Matrix t, u)
mutable ((t -> Bool) -> (Int, Int) -> STMatrix s t -> ST s [Int]
forall t b s.
(Container Vector t, Num (Vector t), Fractional t) =>
(t -> Bool) -> (Int, b) -> STMatrix s t -> ST s [Int]
luST t -> Bool
okf) Matrix t
t

    checkSolve :: Matrix t -> R
checkSolve Matrix t
aa = Vector t -> R
forall a. Normed a => a -> R
norm_Inf (Vector t -> R) -> Vector t -> R
forall a b. (a -> b) -> a -> b
$ Matrix t -> Vector t
forall t. Element t => Matrix t -> Vector t
flatten (Matrix t
aa Matrix t -> Matrix t -> Matrix t
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix t
x Matrix t -> Matrix t -> Matrix t
forall a. Num a => a -> a -> a
- Matrix t
bb)
       where
         bb :: Matrix t
bb = Matrix t -> Matrix t
forall t. Element t => Matrix t -> Matrix t
flipud Matrix t
aa
         x :: Matrix t
x = LU t -> Matrix t -> Matrix t
forall t.
(Fractional t, Container Vector t) =>
LU t -> Matrix t -> Matrix t
luSolve' (Matrix t -> LU t
forall t.
(Container Vector t, Fractional t, Normed (Vector t),
 Num (Vector t)) =>
Matrix t -> LU t
luPacked' Matrix t
aa) Matrix t
bb

    tmm :: Matrix (Mod 19 I)
tmm = Mod 19 I -> Vector (Mod 19 I) -> Int -> Int -> Matrix (Mod 19 I)
forall t. Storable t => t -> Vector t -> Int -> Int -> Matrix t
diagRect Mod 19 I
1 ([Mod 19 I] -> Vector (Mod 19 I)
forall a. Storable a => [a] -> Vector a
fromList [Mod 19 I
2..Mod 19 I
6]) Int
5 Int
5 :: Matrix (Mod 19 I)

    info :: IO ()
info = do
        Vector (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print Vector (Mod 11 I)
v
        Matrix (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print Matrix (Mod 11 I)
m
        Matrix (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 11 I) -> Matrix (Mod 11 I)
forall m mt. Transposable m mt => m -> mt
tr Matrix (Mod 11 I)
m)
        Vector (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print (Vector (Mod 11 I) -> IO ()) -> Vector (Mod 11 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Vector (Mod 11 I)
vVector (Mod 11 I) -> Vector (Mod 11 I) -> Vector (Mod 11 I)
forall a. Num a => a -> a -> a
+Vector (Mod 11 I)
v
        Matrix (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 11 I) -> IO ()) -> Matrix (Mod 11 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 11 I)
mMatrix (Mod 11 I) -> Matrix (Mod 11 I) -> Matrix (Mod 11 I)
forall a. Num a => a -> a -> a
+Matrix (Mod 11 I)
m
        Matrix (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 11 I) -> IO ()) -> Matrix (Mod 11 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 11 I)
m Matrix (Mod 11 I) -> Matrix (Mod 11 I) -> Matrix (Mod 11 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 11 I)
m
        Vector (Mod 11 I) -> IO ()
forall a. Show a => a -> IO ()
print (Vector (Mod 11 I) -> IO ()) -> Vector (Mod 11 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 11 I)
m Matrix (Mod 11 I) -> Vector (Mod 11 I) -> Vector (Mod 11 I)
forall t. Numeric t => Matrix t -> Vector t -> Vector t
#> Vector (Mod 11 I)
v

        Matrix (Mod 13 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 13 I) -> IO ()) -> Matrix (Mod 13 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 13 I)
am Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t -> Matrix t
gaussElim Matrix (Mod 13 I)
am Matrix (Mod 13 I)
bm Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall a. Num a => a -> a -> a
- Matrix (Mod 13 I)
bm
        Matrix R -> IO ()
forall a. Show a => a -> IO ()
print (Matrix R -> IO ()) -> Matrix R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix R
ad Matrix R -> Matrix R -> Matrix R
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix R -> Matrix R -> Matrix R
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t -> Matrix t
gaussElim Matrix R
ad Matrix R
bd Matrix R -> Matrix R -> Matrix R
forall a. Num a => a -> a -> a
- Matrix R
bd

        Matrix I -> IO ()
forall a. Show a => a -> IO ()
print Matrix I
g
        Matrix I -> IO ()
forall a. Show a => a -> IO ()
print (Matrix I -> IO ()) -> Matrix I -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix I
g Matrix I -> Matrix I -> Matrix I
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix I
g
        Matrix (Mod 100000 I) -> IO ()
forall a. Show a => a -> IO ()
print Matrix (Mod 100000 I)
gm
        Matrix (Mod 100000 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 100000 I) -> IO ()) -> Matrix (Mod 100000 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 100000 I)
gm Matrix (Mod 100000 I)
-> Matrix (Mod 100000 I) -> Matrix (Mod 100000 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 100000 I)
gm

        Matrix Z -> IO ()
forall a. Show a => a -> IO ()
print Matrix Z
lg
        Matrix Z -> IO ()
forall a. Show a => a -> IO ()
print (Matrix Z -> IO ()) -> Matrix Z -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix Z
lg Matrix Z -> Matrix Z -> Matrix Z
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix Z
lg
        Matrix (Mod 10000000000 Z) -> IO ()
forall a. Show a => a -> IO ()
print Matrix (Mod 10000000000 Z)
lgm
        Matrix (Mod 10000000000 Z) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 10000000000 Z) -> IO ())
-> Matrix (Mod 10000000000 Z) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 10000000000 Z)
lgm Matrix (Mod 10000000000 Z)
-> Matrix (Mod 10000000000 Z) -> Matrix (Mod 10000000000 Z)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 10000000000 Z)
lgm
        
        [Char] -> IO ()
putStrLn [Char]
"checkGen"
        R -> IO ()
forall a. Show a => a -> IO ()
print (Matrix R -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R))
        R -> IO ()
forall a. Show a => a -> IO ()
print (Matrix Float -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float))
        R -> IO ()
forall a. Show a => a -> IO ()
print (Matrix C -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix C
cgen Int
5 :: Matrix C))
        R -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Complex Float) -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float)))
        Matrix (Mod 7 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 7 I) -> Matrix (Mod 7 I)
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t
invg (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5) :: Matrix (Mod 7 I))
        Matrix (Mod 7 Z) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 7 Z) -> Matrix (Mod 7 Z)
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t
invg (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5) :: Matrix (Mod 7 Z))
        
        (Matrix R, [Int]) -> IO ()
forall a. Show a => a -> IO ()
print ((Matrix R, [Int]) -> IO ()) -> (Matrix R, [Int]) -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall s. (Int, Int) -> STMatrix s R -> ST s [Int])
-> Matrix R -> (Matrix R, [Int])
forall t u.
Element t =>
(forall s. (Int, Int) -> STMatrix s t -> ST s u)
-> Matrix t -> (Matrix t, u)
mutable ((R -> Bool) -> (Int, Int) -> STMatrix s R -> ST s [Int]
forall t b s.
(Container Vector t, Num (Vector t), Fractional t) =>
(t -> Bool) -> (Int, b) -> STMatrix s t -> ST s [Int]
luST (Bool -> R -> Bool
forall a b. a -> b -> a
const Bool
True)) (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R)
        (Matrix (Mod 11 Z), [Int]) -> IO ()
forall a. Show a => a -> IO ()
print ((Matrix (Mod 11 Z), [Int]) -> IO ())
-> (Matrix (Mod 11 Z), [Int]) -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall s. (Int, Int) -> STMatrix s (Mod 11 Z) -> ST s [Int])
-> Matrix (Mod 11 Z) -> (Matrix (Mod 11 Z), [Int])
forall t u.
Element t =>
(forall s. (Int, Int) -> STMatrix s t -> ST s u)
-> Matrix t -> (Matrix t, u)
mutable ((Mod 11 Z -> Bool)
-> (Int, Int) -> STMatrix s (Mod 11 Z) -> ST s [Int]
forall t b s.
(Container Vector t, Num (Vector t), Fractional t) =>
(t -> Bool) -> (Int, b) -> STMatrix s t -> ST s [Int]
luST (Bool -> Mod 11 Z -> Bool
forall a b. a -> b -> a
const Bool
True)) (Int -> Matrix (Mod 11 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 11 Z))

        [Char] -> IO ()
putStrLn [Char]
"checkLU"
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (R -> Bool) -> Matrix R -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> R -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (Float -> Bool) -> Matrix Float -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Float -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (C -> Bool) -> Matrix C -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> C -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix C
cgen Int
5 :: Matrix C)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (Complex Float -> Bool) -> Matrix (Complex Float) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Complex Float -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float))
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (Mod 7 I -> Bool) -> Matrix (Mod 7 I) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Mod 7 I -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 I))
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ (Mod 7 Z -> Bool) -> Matrix (Mod 7 Z) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Mod 7 Z -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 Z))

        [Char] -> IO ()
putStrLn [Char]
"checkSolve"
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix R -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix Float -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix C -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix C
cgen Int
5 :: Matrix C)
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Complex Float) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float))
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 7 I) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 I))
        R -> IO ()
forall a. Show a => a -> IO ()
print (R -> IO ()) -> R -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 7 Z) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 Z))
        
        [Char] -> IO ()
putStrLn [Char]
"luSolve'"
        Matrix (Mod 19 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 19 I) -> IO ()) -> Matrix (Mod 19 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ LU (Mod 19 I) -> Matrix (Mod 19 I) -> Matrix (Mod 19 I)
forall t.
(Fractional t, Container Vector t) =>
LU t -> Matrix t -> Matrix t
luSolve' (Matrix (Mod 19 I) -> LU (Mod 19 I)
forall t.
(Container Vector t, Fractional t, Normed (Vector t),
 Num (Vector t)) =>
Matrix t -> LU t
luPacked' Matrix (Mod 19 I)
tmm) (Int -> Matrix (Mod 19 I)
forall a. (Num a, Element a) => Int -> Matrix a
ident (Matrix (Mod 19 I) -> Int
forall t. Matrix t -> Int
rows Matrix (Mod 19 I)
tmm))
        Matrix (Mod 19 I) -> IO ()
forall a. Show a => a -> IO ()
print (Matrix (Mod 19 I) -> IO ()) -> Matrix (Mod 19 I) -> IO ()
forall a b. (a -> b) -> a -> b
$ Matrix (Mod 19 I) -> Matrix (Mod 19 I)
forall t.
(Container Vector t, Fractional t, Num (Vector t), Product t) =>
Matrix t -> Matrix t
invershur Matrix (Mod 19 I)
tmm


    ok :: Bool
ok = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and
      [ Vector (Mod 11 I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt (Matrix (Mod 11 I)
m Matrix (Mod 11 I) -> Vector (Mod 11 I) -> Vector (Mod 11 I)
forall t. Numeric t => Matrix t -> Vector t -> Vector t
#> Vector (Mod 11 I)
v) Vector I -> Vector I -> Bool
forall a. Eq a => a -> a -> Bool
== I -> Vector I -> Vector I
forall e (c :: * -> *).
(Integral e, Container c e) =>
e -> c e -> c e
cmod I
11 (Matrix (Mod 11 I) -> Matrix I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt Matrix (Mod 11 I)
m Matrix I -> Vector I -> Vector I
forall t. Numeric t => Matrix t -> Vector t -> Vector t
#> Vector (Mod 11 I) -> Vector I
forall (c :: * -> *) e. Container c e => c e -> c I
toInt Vector (Mod 11 I)
v )
      , Matrix (Mod 13 I)
am Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall t.
(Fractional t, Num (Vector t), Ord t, Indexable (Vector t) t,
 Numeric t) =>
Matrix t -> Matrix t -> Matrix t
gaussElim_1 Matrix (Mod 13 I)
am Matrix (Mod 13 I)
bm Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Bool
forall a. Eq a => a -> a -> Bool
== Matrix (Mod 13 I)
bm
      , Matrix (Mod 13 I)
am Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall t.
(Eq t, Fractional t, Num (Vector t), Numeric t) =>
Matrix t -> Matrix t -> Matrix t
gaussElim_2 Matrix (Mod 13 I)
am Matrix (Mod 13 I)
bm Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Bool
forall a. Eq a => a -> a -> Bool
== Matrix (Mod 13 I)
bm
      , Matrix (Mod 13 I)
am Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Matrix (Mod 13 I)
forall t.
(Container Vector t, Eq t, Fractional t, Num (Vector t)) =>
Matrix t -> Matrix t -> Matrix t
gaussElim   Matrix (Mod 13 I)
am Matrix (Mod 13 I)
bm Matrix (Mod 13 I) -> Matrix (Mod 13 I) -> Bool
forall a. Eq a => a -> a -> Bool
== Matrix (Mod 13 I)
bm
      , (Matrix R -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-15
      , (Matrix Float -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
2E-7
      , (Matrix C -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix C
cgen Int
5 :: Matrix C)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-15
      , (Matrix (Complex Float) -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float))) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
3E-7
      , (Matrix (Mod 7 I) -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 I))) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , (Matrix (Mod 7 Z) -> R
forall t.
(Normed (Vector t), Container Vector t, Num (Vector t), Product t,
 Eq t, Fractional t) =>
Matrix t -> R
checkGen (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 Z))) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , ((R -> Bool) -> Matrix R -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> R -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
1E-10) (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
2E-15
      , ((Float -> Bool) -> Matrix Float -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Float -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
1E-5) (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-6
      , ((C -> Bool) -> Matrix C -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> C -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
1E-10) (Int -> Matrix C
cgen Int
5 :: Matrix C)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
5E-15
      , ((Complex Float -> Bool) -> Matrix (Complex Float) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Complex Float -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
1E-5) (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float))) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-6
      , ((Mod 7 I -> Bool) -> Matrix (Mod 7 I) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Mod 7 I -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 I))) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , ((Mod 7 Z -> Bool) -> Matrix (Mod 7 Z) -> R
forall t.
(Normed (Vector t), Numeric t, Fractional t, Num (Vector t)) =>
(t -> Bool) -> Matrix t -> R
checkLU (R -> Mod 7 Z -> Bool
forall t. (Element t, Normed (Vector t)) => R -> t -> Bool
magnit R
0) (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 Z))) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , Matrix R -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix R
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix R) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
2E-15
      , Matrix Float -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix Float
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix Float) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-6
      , Matrix C -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix C
cgen Int
5 :: Matrix C) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
4E-15
      , Matrix (Complex Float) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Complex Float)
sgen Int
5 :: Matrix (Complex Float)) R -> R -> Bool
forall a. Ord a => a -> a -> Bool
< R
1E-6
      , Matrix (Mod 7 I) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Mod 7 I)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 I)) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , Matrix (Mod 7 Z) -> R
forall t.
(Fractional t, Container Vector t, Normed (Vector t),
 Num (Vector t), Product t) =>
Matrix t -> R
checkSolve (Int -> Matrix (Mod 7 Z)
forall t. Numeric t => Int -> Matrix t
gen Int
5 :: Matrix (Mod 7 Z)) R -> R -> Bool
forall a. Eq a => a -> a -> Bool
== R
0
      , Vector (Mod 10 I) -> Mod 10 I
forall (c :: * -> *) e. Container c e => c e -> e
prodElements (Mod 10 I -> Int -> Vector (Mod 10 I)
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst (Mod 10 I
9:: Mod 10 I) (Int
12::Int)) Mod 10 I -> Mod 10 I -> Bool
forall a. Eq a => a -> a -> Bool
== [Mod 10 I] -> Mod 10 I
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Int -> Mod 10 I -> [Mod 10 I]
forall a. Int -> a -> [a]
replicate Int
12 (Mod 10 I
9:: Mod 10 I))
      , Matrix (Mod 100000 I)
gm Matrix (Mod 100000 I)
-> Matrix (Mod 100000 I) -> Matrix (Mod 100000 I)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 100000 I)
gm Matrix (Mod 100000 I) -> Matrix (Mod 100000 I) -> Bool
forall a. Eq a => a -> a -> Bool
== Mod 100000 I -> (Int, Int) -> Matrix (Mod 100000 I)
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst Mod 100000 I
0 (Int
3,Int
3)
      , Matrix (Mod 10000000000 Z)
lgm Matrix (Mod 10000000000 Z)
-> Matrix (Mod 10000000000 Z) -> Matrix (Mod 10000000000 Z)
forall (a :: * -> *) (b :: * -> *) (c :: * -> *) t.
(Mul a b c, Product t) =>
a t -> b t -> c t
<> Matrix (Mod 10000000000 Z)
lgm Matrix (Mod 10000000000 Z) -> Matrix (Mod 10000000000 Z) -> Bool
forall a. Eq a => a -> a -> Bool
== Mod 10000000000 Z -> (Int, Int) -> Matrix (Mod 10000000000 Z)
forall e d (c :: * -> *). Konst e d c => e -> d -> c e
konst Mod 10000000000 Z
0 (Int
3,Int
3)
      , Matrix (Mod 19 I) -> Matrix (Mod 19 I)
forall t.
(Container Vector t, Fractional t, Num (Vector t), Product t) =>
Matrix t -> Matrix t
invershur Matrix (Mod 19 I)
tmm Matrix (Mod 19 I) -> Matrix (Mod 19 I) -> Bool
forall a. Eq a => a -> a -> Bool
== LU (Mod 19 I) -> Matrix (Mod 19 I) -> Matrix (Mod 19 I)
forall t.
(Fractional t, Container Vector t) =>
LU t -> Matrix t -> Matrix t
luSolve' (Matrix (Mod 19 I) -> LU (Mod 19 I)
forall t.
(Container Vector t, Fractional t, Normed (Vector t),
 Num (Vector t)) =>
Matrix t -> LU t
luPacked' Matrix (Mod 19 I)
tmm) (Int -> Matrix (Mod 19 I)
forall a. (Num a, Element a) => Int -> Matrix a
ident (Matrix (Mod 19 I) -> Int
forall t. Matrix t -> Int
rows Matrix (Mod 19 I)
tmm))
      , LU (I ./. 2) -> Matrix (I ./. 2) -> Matrix (I ./. 2)
forall t.
(Fractional t, Container Vector t) =>
LU t -> Matrix t -> Matrix t
luSolve' (Matrix (I ./. 2) -> LU (I ./. 2)
forall t.
(Container Vector t, Fractional t, Normed (Vector t),
 Num (Vector t)) =>
Matrix t -> LU t
luPacked' (Matrix (I ./. 2) -> Matrix (I ./. 2)
forall m mt. Transposable m mt => m -> mt
tr (Matrix (I ./. 2) -> Matrix (I ./. 2))
-> Matrix (I ./. 2) -> Matrix (I ./. 2)
forall a b. (a -> b) -> a -> b
$ Int -> Matrix (I ./. 2)
forall a. (Num a, Element a) => Int -> Matrix a
ident Int
5 :: Matrix (I ./. 2))) (Int -> Matrix (I ./. 2)
forall a. (Num a, Element a) => Int -> Matrix a
ident Int
5) Matrix (I ./. 2) -> Matrix (I ./. 2) -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Matrix (I ./. 2)
forall a. (Num a, Element a) => Int -> Matrix a
ident Int
5
      ]