{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DataKinds #-}
module OAlg.Entity.Matrix.Entries
(
Entries(..), etsxs, etsEmpty, etsAdd, etsMlt, etsJoin
, etscr, etsrc, crets, rcets
, etsElimZeros
, etsMapCov, etsMapCnt
, Row(..), rowxs, rowEmpty, rowIsEmpty, rowHead, rowTail
, rowFilter, rowMapShift, rowAppend, rowInterlace
, rowElimZeros, rowSwap, rowAdd, rowMltl, rowShear, rowScale
, Col(..), colxs, colEmpty, colIsEmpty, colHead, colTail
, colFilter, colMapShift, colAppend, colInterlace
, colElimZeros, colSwap, colAdd, colMltr, colShear, colScale
, crHeadColAt, crHeadRowAt
, coEntries, coEntriesInv
) where
import Control.Monad as M
import Data.Foldable
import Data.List (map,sortBy,filter,(++))
import OAlg.Prelude
import OAlg.Data.Variant
import OAlg.Structure.Oriented
import OAlg.Structure.Multiplicative
import OAlg.Structure.Additive
import OAlg.Structure.Distributive
import OAlg.Structure.Number
import OAlg.Structure.Operational
import OAlg.Entity.Sequence
import OAlg.Hom.Distributive
newtype Row j x = Row (PSequence j x) deriving (Row j x -> Row j x -> Bool
(Row j x -> Row j x -> Bool)
-> (Row j x -> Row j x -> Bool) -> Eq (Row j x)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall j x. (Eq x, Eq j) => Row j x -> Row j x -> Bool
$c== :: forall j x. (Eq x, Eq j) => Row j x -> Row j x -> Bool
== :: Row j x -> Row j x -> Bool
$c/= :: forall j x. (Eq x, Eq j) => Row j x -> Row j x -> Bool
/= :: Row j x -> Row j x -> Bool
Eq,Row j x -> Statement
(Row j x -> Statement) -> Validable (Row j x)
forall a. (a -> Statement) -> Validable a
forall j x.
(Show x, Show j, Validable x, Validable j, Eq x, Typeable x,
Typeable j, Ord j) =>
Row j x -> Statement
$cvalid :: forall j x.
(Show x, Show j, Validable x, Validable j, Eq x, Typeable x,
Typeable j, Ord j) =>
Row j x -> Statement
valid :: Row j x -> Statement
Validable,(forall a b. (a -> b) -> Row j a -> Row j b)
-> (forall a b. a -> Row j b -> Row j a) -> Functor (Row j)
forall a b. a -> Row j b -> Row j a
forall a b. (a -> b) -> Row j a -> Row j b
forall j a b. a -> Row j b -> Row j a
forall j a b. (a -> b) -> Row j a -> Row j b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall j a b. (a -> b) -> Row j a -> Row j b
fmap :: forall a b. (a -> b) -> Row j a -> Row j b
$c<$ :: forall j a b. a -> Row j b -> Row j a
<$ :: forall a b. a -> Row j b -> Row j a
M.Functor,Row j x -> N
(Row j x -> N) -> LengthN (Row j x)
forall x. (x -> N) -> LengthN x
forall j x. Row j x -> N
$clengthN :: forall j x. Row j x -> N
lengthN :: Row j x -> N
LengthN)
instance (Show x,Show j) => Show (Row j x) where
show :: Row j x -> String
show (Row (PSequence [(x, j)]
xs)) = String
"Row " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [(x, j)] -> String
forall a. Show a => a -> String
show [(x, j)]
xs
instance Ord j => Sequence (Row j) j x where
list :: forall (p :: * -> *). p j -> Row j x -> [(x, j)]
list p j
_ = Row j x -> [(x, j)]
forall j x. Row j x -> [(x, j)]
rowxs
Row PSequence j x
xs ?? :: Row j x -> j -> Maybe x
?? j
j = PSequence j x
xs PSequence j x -> j -> Maybe x
forall (s :: * -> *) i x. Sequence s i x => s x -> i -> Maybe x
?? j
j
instance Ord j => Opr (Permutation j) (Row j x) where Row PSequence j x
xs <* :: Row j x -> Permutation j -> Row j x
<* Permutation j
p = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row (PSequence j x
xs PSequence j x -> Permutation j -> PSequence j x
forall f x. Opr f x => x -> f -> x
<* Permutation j
p)
instance (Entity x, Entity j, Ord j) => TotalOpr (Permutation j) (Row j x)
instance (Entity x, Entity j, Ord j) => PermutableSequence (Row j) j x where
permuteBy :: forall (p :: * -> *) w.
p j
-> (w -> w -> Ordering)
-> (x -> w)
-> Row j x
-> (Row j x, Permutation j)
permuteBy p j
f w -> w -> Ordering
c x -> w
w (Row PSequence j x
xs) = (PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row PSequence j x
xs',Permutation j
p) where (PSequence j x
xs',Permutation j
p) = p j
-> (w -> w -> Ordering)
-> (x -> w)
-> PSequence j x
-> (PSequence j x, Permutation j)
forall (p :: * -> *) w.
p j
-> (w -> w -> Ordering)
-> (x -> w)
-> PSequence j x
-> (PSequence j x, Permutation j)
forall (s :: * -> *) i x (p :: * -> *) w.
PermutableSequence s i x =>
p i
-> (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation i)
permuteBy p j
f w -> w -> Ordering
c x -> w
w PSequence j x
xs
instance ApplicativeG (Row i) (->) (->) where amapG :: forall x y. (x -> y) -> Row i x -> Row i y
amapG = (x -> y) -> Row i x -> Row i y
forall x y. (x -> y) -> Row i x -> Row i y
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
M.fmap
rowxs :: Row j x -> [(x,j)]
rowxs :: forall j x. Row j x -> [(x, j)]
rowxs (Row PSequence j x
xs) = PSequence j x -> [(x, j)]
forall i x. PSequence i x -> [(x, i)]
psqxs PSequence j x
xs
rowEmpty :: Row j x
rowEmpty :: forall j x. Row j x
rowEmpty = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row PSequence j x
forall i x. PSequence i x
psqEmpty
rowIsEmpty :: Row j x -> Bool
rowIsEmpty :: forall j x. Row j x -> Bool
rowIsEmpty (Row PSequence j x
rw) = PSequence j x -> Bool
forall i x. PSequence i x -> Bool
psqIsEmpty PSequence j x
rw
rowHead :: Row j x -> (x,j)
rowHead :: forall j x. Row j x -> (x, j)
rowHead (Row PSequence j x
xs) = PSequence j x -> (x, j)
forall i x. PSequence i x -> (x, i)
psqHead PSequence j x
xs
rowTail :: Row j x -> Row j x
rowTail :: forall j x. Row j x -> Row j x
rowTail (Row PSequence j x
xs) = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row (PSequence j x -> PSequence j x
forall i x. PSequence i x -> PSequence i x
psqTail PSequence j x
xs)
rowFilter :: (x -> Bool) -> Row j x -> Row j x
rowFilter :: forall x j. (x -> Bool) -> Row j x -> Row j x
rowFilter x -> Bool
p (Row PSequence j x
xs) = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row (PSequence j x -> Row j x) -> PSequence j x -> Row j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> Bool) -> PSequence j x -> PSequence j x
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter x -> Bool
p PSequence j x
xs
rowMapShift :: Number j => j -> ((x,j) -> y) -> Row j x -> Row j y
rowMapShift :: forall j x y. Number j => j -> ((x, j) -> y) -> Row j x -> Row j y
rowMapShift j
o (x, j) -> y
f (Row PSequence j x
xs) = PSequence j y -> Row j y
forall j x. PSequence j x -> Row j x
Row (PSequence j y -> Row j y) -> PSequence j y -> Row j y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ j -> ((x, j) -> y) -> PSequence j x -> PSequence j y
forall i x y.
Number i =>
i -> ((x, i) -> y) -> PSequence i x -> PSequence i y
psqMapShift j
o (x, j) -> y
f PSequence j x
xs
rowAppend :: Row j x -> Row j x -> Row j x
rowAppend :: forall j x. Row j x -> Row j x -> Row j x
rowAppend (Row PSequence j x
xs) (Row PSequence j x
ys) = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row (PSequence j x -> Row j x) -> PSequence j x -> Row j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence j x -> PSequence j x -> PSequence j x
forall i x. PSequence i x -> PSequence i x -> PSequence i x
psqAppend PSequence j x
xs PSequence j x
ys
rowInterlace :: Ord j
=> (x -> y -> z) -> (x -> z) -> (y -> z) -> Row j x -> Row j y -> Row j z
rowInterlace :: forall j x y z.
Ord j =>
(x -> y -> z)
-> (x -> z) -> (y -> z) -> Row j x -> Row j y -> Row j z
rowInterlace x -> y -> z
(+) x -> z
xz y -> z
yz (Row PSequence j x
xs) (Row PSequence j y
ys) = PSequence j z -> Row j z
forall j x. PSequence j x -> Row j x
Row (PSequence j z -> Row j z) -> PSequence j z -> Row j z
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence j x
-> PSequence j y
-> PSequence j z
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace x -> y -> z
(+) x -> z
xz y -> z
yz PSequence j x
xs PSequence j y
ys
rowElimZeros :: Additive a => Row i a -> Row i a
rowElimZeros :: forall a i. Additive a => Row i a -> Row i a
rowElimZeros (Row PSequence i a
rw) = PSequence i a -> Row i a
forall j x. PSequence j x -> Row j x
Row (PSequence i a -> Row i a) -> PSequence i a -> Row i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (a -> Bool) -> PSequence i a -> PSequence i a
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter (Bool -> Bool
forall b. Boolean b => b -> b
not(Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
.a -> Bool
forall a. Additive a => a -> Bool
isZero) PSequence i a
rw
rowAdd :: (Additive a, Ord j) => Row j a -> Row j a -> Row j a
rowAdd :: forall a j. (Additive a, Ord j) => Row j a -> Row j a -> Row j a
rowAdd (Row PSequence j a
a) (Row PSequence j a
b) = Row j a -> Row j a
forall a i. Additive a => Row i a -> Row i a
rowElimZeros (Row j a -> Row j a) -> Row j a -> Row j a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence j a -> Row j a
forall j x. PSequence j x -> Row j x
Row (PSequence j a -> Row j a) -> PSequence j a -> Row j a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> PSequence j a
-> PSequence j a
-> PSequence j a
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace a -> a -> a
forall a. Additive a => a -> a -> a
(+) a -> a
forall x. x -> x
id a -> a
forall x. x -> x
id PSequence j a
a PSequence j a
b
rowSwap :: Ord j => j -> j -> Row j x -> Row j x
rowSwap :: forall j x. Ord j => j -> j -> Row j x -> Row j x
rowSwap j
k j
l (Row PSequence j x
rw) = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row (PSequence j x -> Row j x) -> PSequence j x -> Row j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ j -> j -> PSequence j x -> PSequence j x
forall i a. Ord i => i -> i -> PSequence i a -> PSequence i a
psqSwap j
k j
l PSequence j x
rw
rowMltl :: Distributive a => a -> Row j a -> Row j a
rowMltl :: forall a j. Distributive a => a -> Row j a -> Row j a
rowMltl a
a = Row j a -> Row j a
forall a i. Additive a => Row i a -> Row i a
rowElimZeros (Row j a -> Row j a) -> (Row j a -> Row j a) -> Row j a -> Row j a
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. (a -> a) -> Row j a -> Row j a
forall a b. (a -> b) -> Row j a -> Row j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
aa -> a -> a
forall c. Multiplicative c => c -> c -> c
*)
rowShear :: Ord j
=> (Maybe x -> s -> Maybe x) -> (Maybe x -> Maybe x -> Maybe x)
-> j -> j -> s -> s -> s -> s
-> Row j x -> Row j x
rowShear :: forall j x s.
Ord j =>
(Maybe x -> s -> Maybe x)
-> (Maybe x -> Maybe x -> Maybe x)
-> j
-> j
-> s
-> s
-> s
-> s
-> Row j x
-> Row j x
rowShear Maybe x -> s -> Maybe x
(<*) Maybe x -> Maybe x -> Maybe x
(+) j
k j
l s
s s
t s
u s
v (Row PSequence j x
xs) = PSequence j x -> Row j x
forall j x. PSequence j x -> Row j x
Row ((Maybe x -> Maybe x -> Maybe x, j)
-> (Maybe x -> Maybe x -> Maybe x, j)
-> PSequence j x
-> PSequence j x
forall i a.
Ord i =>
(Maybe a -> Maybe a -> Maybe a, i)
-> (Maybe a -> Maybe a -> Maybe a, i)
-> PSequence i a
-> PSequence i a
psqShear (Maybe x -> Maybe x -> Maybe x
sk,j
k) (Maybe x -> Maybe x -> Maybe x
sl,j
l) PSequence j x
xs) where
sk :: Maybe x -> Maybe x -> Maybe x
sk Maybe x
xk Maybe x
xl = (Maybe x
xkMaybe x -> s -> Maybe x
<*s
s) Maybe x -> Maybe x -> Maybe x
+ (Maybe x
xlMaybe x -> s -> Maybe x
<*s
u)
sl :: Maybe x -> Maybe x -> Maybe x
sl Maybe x
xk Maybe x
xl = (Maybe x
xkMaybe x -> s -> Maybe x
<*s
t) Maybe x -> Maybe x -> Maybe x
+ (Maybe x
xlMaybe x -> s -> Maybe x
<*s
v)
rowScale :: Ord j
=> (x -> s -> Maybe x)
-> j -> s
-> Row j x -> Row j x
rowScale :: forall j x s.
Ord j =>
(x -> s -> Maybe x) -> j -> s -> Row j x -> Row j x
rowScale x -> s -> Maybe x
(<*) j
j s
s Row j x
rw
= (Maybe x -> x) -> Row j (Maybe x) -> Row j x
forall a b. (a -> b) -> Row j a -> Row j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe x -> x
forall a. HasCallStack => Maybe a -> a
fromJust
(Row j (Maybe x) -> Row j x) -> Row j (Maybe x) -> Row j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Maybe x -> Bool) -> Row j (Maybe x) -> Row j (Maybe x)
forall x j. (x -> Bool) -> Row j x -> Row j x
rowFilter Maybe x -> Bool
forall a. Maybe a -> Bool
isJust
(Row j (Maybe x) -> Row j (Maybe x))
-> Row j (Maybe x) -> Row j (Maybe x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> s -> Maybe x)
-> (x -> Maybe x)
-> (s -> Maybe x)
-> Row j x
-> Row j s
-> Row j (Maybe x)
forall j x y z.
Ord j =>
(x -> y -> z)
-> (x -> z) -> (y -> z) -> Row j x -> Row j y -> Row j z
rowInterlace x -> s -> Maybe x
(<*) x -> Maybe x
forall a. a -> Maybe a
Just (Maybe x -> s -> Maybe x
forall b a. b -> a -> b
const Maybe x
forall a. Maybe a
Nothing) Row j x
rw (PSequence j s -> Row j s
forall j x. PSequence j x -> Row j x
Row ([(s, j)] -> PSequence j s
forall i x. [(x, i)] -> PSequence i x
PSequence [(s
s,j
j)]))
newtype Col i x = Col (PSequence i x) deriving (Col i x -> Col i x -> Bool
(Col i x -> Col i x -> Bool)
-> (Col i x -> Col i x -> Bool) -> Eq (Col i x)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall i x. (Eq x, Eq i) => Col i x -> Col i x -> Bool
$c== :: forall i x. (Eq x, Eq i) => Col i x -> Col i x -> Bool
== :: Col i x -> Col i x -> Bool
$c/= :: forall i x. (Eq x, Eq i) => Col i x -> Col i x -> Bool
/= :: Col i x -> Col i x -> Bool
Eq,Col i x -> Statement
(Col i x -> Statement) -> Validable (Col i x)
forall a. (a -> Statement) -> Validable a
forall i x.
(Show x, Show i, Validable x, Validable i, Eq x, Typeable x,
Typeable i, Ord i) =>
Col i x -> Statement
$cvalid :: forall i x.
(Show x, Show i, Validable x, Validable i, Eq x, Typeable x,
Typeable i, Ord i) =>
Col i x -> Statement
valid :: Col i x -> Statement
Validable,(forall a b. (a -> b) -> Col i a -> Col i b)
-> (forall a b. a -> Col i b -> Col i a) -> Functor (Col i)
forall a b. a -> Col i b -> Col i a
forall a b. (a -> b) -> Col i a -> Col i b
forall i a b. a -> Col i b -> Col i a
forall i a b. (a -> b) -> Col i a -> Col i b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall i a b. (a -> b) -> Col i a -> Col i b
fmap :: forall a b. (a -> b) -> Col i a -> Col i b
$c<$ :: forall i a b. a -> Col i b -> Col i a
<$ :: forall a b. a -> Col i b -> Col i a
M.Functor,Col i x -> N
(Col i x -> N) -> LengthN (Col i x)
forall x. (x -> N) -> LengthN x
forall i x. Col i x -> N
$clengthN :: forall i x. Col i x -> N
lengthN :: Col i x -> N
LengthN)
instance (Show x,Show i) => Show (Col i x) where
show :: Col i x -> String
show (Col (PSequence [(x, i)]
xs)) = String
"Col " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [(x, i)] -> String
forall a. Show a => a -> String
show [(x, i)]
xs
instance Ord i => Sequence (Col i) i x where
list :: forall (p :: * -> *). p i -> Col i x -> [(x, i)]
list p i
_ = Col i x -> [(x, i)]
forall i x. Col i x -> [(x, i)]
colxs
Col PSequence i x
xs ?? :: Col i x -> i -> Maybe x
?? i
i = PSequence i x
xs PSequence i x -> i -> Maybe x
forall (s :: * -> *) i x. Sequence s i x => s x -> i -> Maybe x
?? i
i
instance Ord i => Opr (Permutation i) (Col i x) where Col PSequence i x
xs <* :: Col i x -> Permutation i -> Col i x
<* Permutation i
p = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (PSequence i x
xs PSequence i x -> Permutation i -> PSequence i x
forall f x. Opr f x => x -> f -> x
<* Permutation i
p)
instance (Entity x, Entity i, Ord i) => TotalOpr (Permutation i) (Col i x)
instance (Entity x, Entity i, Ord i) => PermutableSequence (Col i) i x where
permuteBy :: forall (p :: * -> *) w.
p i
-> (w -> w -> Ordering)
-> (x -> w)
-> Col i x
-> (Col i x, Permutation i)
permuteBy p i
f w -> w -> Ordering
c x -> w
w (Col PSequence i x
xs) = (PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col PSequence i x
xs',Permutation i
p) where (PSequence i x
xs',Permutation i
p) = p i
-> (w -> w -> Ordering)
-> (x -> w)
-> PSequence i x
-> (PSequence i x, Permutation i)
forall (p :: * -> *) w.
p i
-> (w -> w -> Ordering)
-> (x -> w)
-> PSequence i x
-> (PSequence i x, Permutation i)
forall (s :: * -> *) i x (p :: * -> *) w.
PermutableSequence s i x =>
p i
-> (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation i)
permuteBy p i
f w -> w -> Ordering
c x -> w
w PSequence i x
xs
instance ApplicativeG (Col i) (->) (->) where
amapG :: forall x y. (x -> y) -> Col i x -> Col i y
amapG = (x -> y) -> Col i x -> Col i y
forall x y. (x -> y) -> Col i x -> Col i y
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
M.fmap
colxs :: Col i x -> [(x,i)]
colxs :: forall i x. Col i x -> [(x, i)]
colxs (Col PSequence i x
xs) = PSequence i x -> [(x, i)]
forall i x. PSequence i x -> [(x, i)]
psqxs PSequence i x
xs
colEmpty :: Col i x
colEmpty :: forall i x. Col i x
colEmpty = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col PSequence i x
forall i x. PSequence i x
psqEmpty
colIsEmpty :: Col i x -> Bool
colIsEmpty :: forall i x. Col i x -> Bool
colIsEmpty (Col PSequence i x
cl) = PSequence i x -> Bool
forall i x. PSequence i x -> Bool
psqIsEmpty PSequence i x
cl
colHead :: Col i x -> (x,i)
colHead :: forall i x. Col i x -> (x, i)
colHead (Col PSequence i x
xs) = PSequence i x -> (x, i)
forall i x. PSequence i x -> (x, i)
psqHead PSequence i x
xs
colTail :: Col i x -> Col i x
colTail :: forall i x. Col i x -> Col i x
colTail (Col PSequence i x
xs) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (PSequence i x -> PSequence i x
forall i x. PSequence i x -> PSequence i x
psqTail PSequence i x
xs)
colFilter :: (x -> Bool) -> Col i x -> Col i x
colFilter :: forall x i. (x -> Bool) -> Col i x -> Col i x
colFilter x -> Bool
p (Col PSequence i x
xs) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (PSequence i x -> Col i x) -> PSequence i x -> Col i x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> Bool) -> PSequence i x -> PSequence i x
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter x -> Bool
p PSequence i x
xs
colMapShift :: Number i => i -> ((x,i) -> y) -> Col i x -> Col i y
colMapShift :: forall i x y. Number i => i -> ((x, i) -> y) -> Col i x -> Col i y
colMapShift i
o (x, i) -> y
f (Col PSequence i x
xs) = PSequence i y -> Col i y
forall i x. PSequence i x -> Col i x
Col (PSequence i y -> Col i y) -> PSequence i y -> Col i y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ i -> ((x, i) -> y) -> PSequence i x -> PSequence i y
forall i x y.
Number i =>
i -> ((x, i) -> y) -> PSequence i x -> PSequence i y
psqMapShift i
o (x, i) -> y
f PSequence i x
xs
colAppend :: Col i x -> Col i x -> Col i x
colAppend :: forall i x. Col i x -> Col i x -> Col i x
colAppend (Col PSequence i x
xs) (Col PSequence i x
ys) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (PSequence i x -> PSequence i x -> PSequence i x
forall i x. PSequence i x -> PSequence i x -> PSequence i x
psqAppend PSequence i x
xs PSequence i x
ys)
colInterlace :: Ord i
=> (x -> y -> z) -> (x -> z) -> (y -> z) -> Col i x -> Col i y -> Col i z
colInterlace :: forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z) -> (y -> z) -> Col i x -> Col i y -> Col i z
colInterlace x -> y -> z
(+) x -> z
xz y -> z
yz (Col PSequence i x
xs) (Col PSequence i y
ys) = PSequence i z -> Col i z
forall i x. PSequence i x -> Col i x
Col (PSequence i z -> Col i z) -> PSequence i z -> Col i z
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace x -> y -> z
(+) x -> z
xz y -> z
yz PSequence i x
xs PSequence i y
ys
colElimZeros :: Additive a => Col i a -> Col i a
colElimZeros :: forall a i. Additive a => Col i a -> Col i a
colElimZeros (Col PSequence i a
rw) = PSequence i a -> Col i a
forall i x. PSequence i x -> Col i x
Col (PSequence i a -> Col i a) -> PSequence i a -> Col i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (a -> Bool) -> PSequence i a -> PSequence i a
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter (Bool -> Bool
forall b. Boolean b => b -> b
not(Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
.a -> Bool
forall a. Additive a => a -> Bool
isZero) PSequence i a
rw
colSwap :: Ord i => i -> i -> Col i x -> Col i x
colSwap :: forall i x. Ord i => i -> i -> Col i x -> Col i x
colSwap i
k i
l (Col PSequence i x
rws) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (i -> i -> PSequence i x -> PSequence i x
forall i a. Ord i => i -> i -> PSequence i a -> PSequence i a
psqSwap i
k i
l PSequence i x
rws)
colAdd :: (Additive a, Ord i) => Col i a -> Col i a -> Col i a
colAdd :: forall a i. (Additive a, Ord i) => Col i a -> Col i a -> Col i a
colAdd (Col PSequence i a
a) (Col PSequence i a
b) = Col i a -> Col i a
forall a i. Additive a => Col i a -> Col i a
colElimZeros (Col i a -> Col i a) -> Col i a -> Col i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence i a -> Col i a
forall i x. PSequence i x -> Col i x
Col (PSequence i a -> Col i a) -> PSequence i a -> Col i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> PSequence i a
-> PSequence i a
-> PSequence i a
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace a -> a -> a
forall a. Additive a => a -> a -> a
(+) a -> a
forall x. x -> x
id a -> a
forall x. x -> x
id PSequence i a
a PSequence i a
b
colShear :: Ord i
=> (s -> Maybe x -> Maybe x) -> (Maybe x -> Maybe x -> Maybe x)
-> i -> i -> s -> s -> s -> s
-> Col i x -> Col i x
colShear :: forall i s x.
Ord i =>
(s -> Maybe x -> Maybe x)
-> (Maybe x -> Maybe x -> Maybe x)
-> i
-> i
-> s
-> s
-> s
-> s
-> Col i x
-> Col i x
colShear s -> Maybe x -> Maybe x
(*>) Maybe x -> Maybe x -> Maybe x
(+) i
k i
l s
s s
t s
u s
v (Col PSequence i x
xs) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col ((Maybe x -> Maybe x -> Maybe x, i)
-> (Maybe x -> Maybe x -> Maybe x, i)
-> PSequence i x
-> PSequence i x
forall i a.
Ord i =>
(Maybe a -> Maybe a -> Maybe a, i)
-> (Maybe a -> Maybe a -> Maybe a, i)
-> PSequence i a
-> PSequence i a
psqShear (Maybe x -> Maybe x -> Maybe x
sk,i
k) (Maybe x -> Maybe x -> Maybe x
sl,i
l) PSequence i x
xs) where
sk :: Maybe x -> Maybe x -> Maybe x
sk Maybe x
xk Maybe x
xl = (s
ss -> Maybe x -> Maybe x
*>Maybe x
xk) Maybe x -> Maybe x -> Maybe x
+ (s
ts -> Maybe x -> Maybe x
*>Maybe x
xl)
sl :: Maybe x -> Maybe x -> Maybe x
sl Maybe x
xk Maybe x
xl = (s
us -> Maybe x -> Maybe x
*>Maybe x
xk) Maybe x -> Maybe x -> Maybe x
+ (s
vs -> Maybe x -> Maybe x
*>Maybe x
xl)
colScale :: Ord i
=> (s -> x -> Maybe x)
-> i -> s
-> Col i x -> Col i x
colScale :: forall i s x.
Ord i =>
(s -> x -> Maybe x) -> i -> s -> Col i x -> Col i x
colScale s -> x -> Maybe x
(*>) i
i s
s Col i x
cl
= (Maybe x -> x) -> Col i (Maybe x) -> Col i x
forall a b. (a -> b) -> Col i a -> Col i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe x -> x
forall a. HasCallStack => Maybe a -> a
fromJust
(Col i (Maybe x) -> Col i x) -> Col i (Maybe x) -> Col i x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Maybe x -> Bool) -> Col i (Maybe x) -> Col i (Maybe x)
forall x i. (x -> Bool) -> Col i x -> Col i x
colFilter Maybe x -> Bool
forall a. Maybe a -> Bool
isJust
(Col i (Maybe x) -> Col i (Maybe x))
-> Col i (Maybe x) -> Col i (Maybe x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (s -> x -> Maybe x)
-> (s -> Maybe x)
-> (x -> Maybe x)
-> Col i s
-> Col i x
-> Col i (Maybe x)
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z) -> (y -> z) -> Col i x -> Col i y -> Col i z
colInterlace s -> x -> Maybe x
(*>) (Maybe x -> s -> Maybe x
forall b a. b -> a -> b
const Maybe x
forall a. Maybe a
Nothing) x -> Maybe x
forall a. a -> Maybe a
Just (PSequence i s -> Col i s
forall i x. PSequence i x -> Col i x
Col ([(s, i)] -> PSequence i s
forall i x. [(x, i)] -> PSequence i x
PSequence [(s
s,i
i)])) Col i x
cl
colMltr :: Distributive a => Col i a -> a -> Col i a
colMltr :: forall a i. Distributive a => Col i a -> a -> Col i a
colMltr Col i a
cl a
a = Col i a -> Col i a
forall a i. Additive a => Col i a -> Col i a
colElimZeros (Col i a -> Col i a) -> Col i a -> Col i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (a -> a) -> Col i a -> Col i a
forall a b. (a -> b) -> Col i a -> Col i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> a
forall c. Multiplicative c => c -> c -> c
*a
a) Col i a
cl
coCol :: Col i x -> Row i (Op x)
coCol :: forall i x. Col i x -> Row i (Op x)
coCol (Col PSequence i x
cl) = PSequence i (Op x) -> Row i (Op x)
forall j x. PSequence j x -> Row j x
Row (PSequence i (Op x) -> Row i (Op x))
-> PSequence i (Op x) -> Row i (Op x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> Op x) -> PSequence i x -> PSequence i (Op x)
forall a b. (a -> b) -> PSequence i a -> PSequence i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap x -> Op x
forall x. x -> Op x
Op PSequence i x
cl
coColInv :: Row i (Op x) -> Col i x
coColInv :: forall i x. Row i (Op x) -> Col i x
coColInv (Row PSequence i (Op x)
rw) = PSequence i x -> Col i x
forall i x. PSequence i x -> Col i x
Col (PSequence i x -> Col i x) -> PSequence i x -> Col i x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Op x -> x) -> PSequence i (Op x) -> PSequence i x
forall a b. (a -> b) -> PSequence i a -> PSequence i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Op x -> x
forall x. Op x -> x
fromOp PSequence i (Op x)
rw
type instance Dual (Row j (Col i x)) = Col j (Row i (Op x))
coRowCol :: Row j (Col i x) -> Dual (Row j (Col i x))
coRowCol :: forall j i x. Row j (Col i x) -> Dual (Row j (Col i x))
coRowCol (Row PSequence j (Col i x)
cls) = PSequence j (Row i (Op x)) -> Col j (Row i (Op x))
forall i x. PSequence i x -> Col i x
Col (PSequence j (Row i (Op x)) -> Col j (Row i (Op x)))
-> PSequence j (Row i (Op x)) -> Col j (Row i (Op x))
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Col i x -> Row i (Op x))
-> PSequence j (Col i x) -> PSequence j (Row i (Op x))
forall a b. (a -> b) -> PSequence j a -> PSequence j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Col i x -> Row i (Op x)
forall i x. Col i x -> Row i (Op x)
coCol PSequence j (Col i x)
cls
coRowColInv :: Dual (Row j (Col i x)) -> Row j (Col i x)
coRowColInv :: forall j i x. Dual (Row j (Col i x)) -> Row j (Col i x)
coRowColInv (Col PSequence j (Row i (Op x))
rws) = PSequence j (Col i x) -> Row j (Col i x)
forall j x. PSequence j x -> Row j x
Row (PSequence j (Col i x) -> Row j (Col i x))
-> PSequence j (Col i x) -> Row j (Col i x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Row i (Op x) -> Col i x)
-> PSequence j (Row i (Op x)) -> PSequence j (Col i x)
forall a b. (a -> b) -> PSequence j a -> PSequence j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Row i (Op x) -> Col i x
forall i x. Row i (Op x) -> Col i x
coColInv PSequence j (Row i (Op x))
rws
newtype Entries i j x = Entries (PSequence (i,j) x)
deriving (Entries i j x -> Entries i j x -> Bool
(Entries i j x -> Entries i j x -> Bool)
-> (Entries i j x -> Entries i j x -> Bool) -> Eq (Entries i j x)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall i j x.
(Eq x, Eq i, Eq j) =>
Entries i j x -> Entries i j x -> Bool
$c== :: forall i j x.
(Eq x, Eq i, Eq j) =>
Entries i j x -> Entries i j x -> Bool
== :: Entries i j x -> Entries i j x -> Bool
$c/= :: forall i j x.
(Eq x, Eq i, Eq j) =>
Entries i j x -> Entries i j x -> Bool
/= :: Entries i j x -> Entries i j x -> Bool
Eq,Eq (Entries i j x)
Eq (Entries i j x) =>
(Entries i j x -> Entries i j x -> Ordering)
-> (Entries i j x -> Entries i j x -> Bool)
-> (Entries i j x -> Entries i j x -> Bool)
-> (Entries i j x -> Entries i j x -> Bool)
-> (Entries i j x -> Entries i j x -> Bool)
-> (Entries i j x -> Entries i j x -> Entries i j x)
-> (Entries i j x -> Entries i j x -> Entries i j x)
-> Ord (Entries i j x)
Entries i j x -> Entries i j x -> Bool
Entries i j x -> Entries i j x -> Ordering
Entries i j x -> Entries i j x -> Entries i j x
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall i j x. (Ord x, Ord i, Ord j) => Eq (Entries i j x)
forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Bool
forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Ordering
forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Entries i j x
$ccompare :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Ordering
compare :: Entries i j x -> Entries i j x -> Ordering
$c< :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Bool
< :: Entries i j x -> Entries i j x -> Bool
$c<= :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Bool
<= :: Entries i j x -> Entries i j x -> Bool
$c> :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Bool
> :: Entries i j x -> Entries i j x -> Bool
$c>= :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Bool
>= :: Entries i j x -> Entries i j x -> Bool
$cmax :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Entries i j x
max :: Entries i j x -> Entries i j x -> Entries i j x
$cmin :: forall i j x.
(Ord x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Entries i j x
min :: Entries i j x -> Entries i j x -> Entries i j x
Ord,Entries i j x -> Statement
(Entries i j x -> Statement) -> Validable (Entries i j x)
forall a. (a -> Statement) -> Validable a
forall i j x.
(Show x, Show i, Show j, Validable x, Validable i, Validable j,
Eq x, Typeable x, Typeable i, Typeable j, Ord i, Ord j) =>
Entries i j x -> Statement
$cvalid :: forall i j x.
(Show x, Show i, Show j, Validable x, Validable i, Validable j,
Eq x, Typeable x, Typeable i, Typeable j, Ord i, Ord j) =>
Entries i j x -> Statement
valid :: Entries i j x -> Statement
Validable,(forall a b. (a -> b) -> Entries i j a -> Entries i j b)
-> (forall a b. a -> Entries i j b -> Entries i j a)
-> Functor (Entries i j)
forall a b. a -> Entries i j b -> Entries i j a
forall a b. (a -> b) -> Entries i j a -> Entries i j b
forall i j a b. a -> Entries i j b -> Entries i j a
forall i j a b. (a -> b) -> Entries i j a -> Entries i j b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall i j a b. (a -> b) -> Entries i j a -> Entries i j b
fmap :: forall a b. (a -> b) -> Entries i j a -> Entries i j b
$c<$ :: forall i j a b. a -> Entries i j b -> Entries i j a
<$ :: forall a b. a -> Entries i j b -> Entries i j a
M.Functor,Entries i j x -> N
(Entries i j x -> N) -> LengthN (Entries i j x)
forall x. (x -> N) -> LengthN x
forall i j x. Entries i j x -> N
$clengthN :: forall i j x. Entries i j x -> N
lengthN :: Entries i j x -> N
LengthN)
instance (Show x, Show i, Show j) => Show (Entries i j x) where
show :: Entries i j x -> String
show Entries i j x
ets = String
"Entries" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ([(x, i, j)] -> String
forall a. Show a => a -> String
show ([(x, i, j)] -> String) -> [(x, i, j)] -> String
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ Entries i j x -> [(x, i, j)]
forall i j x. Entries i j x -> [(x, i, j)]
etsxs Entries i j x
ets)
instance ApplicativeG (Entries i j) (->) (->) where amapG :: forall x y. (x -> y) -> Entries i j x -> Entries i j y
amapG = (x -> y) -> Entries i j x -> Entries i j y
forall x y. (x -> y) -> Entries i j x -> Entries i j y
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
M.fmap
etsxs :: Entries i j x -> [(x,i,j)]
etsxs :: forall i j x. Entries i j x -> [(x, i, j)]
etsxs (Entries PSequence (i, j) x
xs) = ((x, (i, j)) -> (x, i, j)) -> [(x, (i, j))] -> [(x, i, j)]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,(i
i,j
j)) -> (x
x,i
i,j
j)) ([(x, (i, j))] -> [(x, i, j)]) -> [(x, (i, j))] -> [(x, i, j)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x -> [(x, (i, j))]
forall i x. PSequence i x -> [(x, i)]
psqxs PSequence (i, j) x
xs
etsEmpty :: Entries i j x
etsEmpty :: forall i j x. Entries i j x
etsEmpty = PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries PSequence (i, j) x
forall i x. PSequence i x
psqEmpty
etsElimZeros :: Additive x => Entries i j x -> Entries i j x
etsElimZeros :: forall x i j. Additive x => Entries i j x -> Entries i j x
etsElimZeros (Entries PSequence (i, j) x
xs) = PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries ((x -> Bool) -> PSequence (i, j) x -> PSequence (i, j) x
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter (Bool -> Bool
forall b. Boolean b => b -> b
not (Bool -> Bool) -> (x -> Bool) -> x -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. x -> Bool
forall a. Additive a => a -> Bool
isZero) PSequence (i, j) x
xs)
etsAdd :: (Additive x, Ord i, Ord j) => Entries i j x -> Entries i j x -> Entries i j x
etsAdd :: forall x i j.
(Additive x, Ord i, Ord j) =>
Entries i j x -> Entries i j x -> Entries i j x
etsAdd (Entries PSequence (i, j) x
xs) (Entries PSequence (i, j) x
ys)
= PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries (PSequence (i, j) x -> Entries i j x)
-> PSequence (i, j) x -> Entries i j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> Bool) -> PSequence (i, j) x -> PSequence (i, j) x
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter (Bool -> Bool
forall b. Boolean b => b -> b
not (Bool -> Bool) -> (x -> Bool) -> x -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. x -> Bool
forall a. Additive a => a -> Bool
isZero) (PSequence (i, j) x -> PSequence (i, j) x)
-> PSequence (i, j) x -> PSequence (i, j) x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> x -> x)
-> (x -> x)
-> (x -> x)
-> PSequence (i, j) x
-> PSequence (i, j) x
-> PSequence (i, j) x
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace x -> x -> x
forall a. Additive a => a -> a -> a
(+) x -> x
forall x. x -> x
id x -> x
forall x. x -> x
id PSequence (i, j) x
xs PSequence (i, j) x
ys
instance (Transposable x, Ord n) => Transposable (Entries n n x) where
transpose :: Entries n n x -> Entries n n x
transpose (Entries PSequence (n, n) x
xs) = PSequence (n, n) x -> Entries n n x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries
(PSequence (n, n) x -> Entries n n x)
-> PSequence (n, n) x -> Entries n n x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(x, (n, n))] -> PSequence (n, n) x
forall i x. [(x, i)] -> PSequence i x
PSequence
([(x, (n, n))] -> PSequence (n, n) x)
-> [(x, (n, n))] -> PSequence (n, n) x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (n, n)) -> (x, (n, n)) -> Ordering)
-> [(x, (n, n))] -> [(x, (n, n))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((x, (n, n)) -> (n, n)) -> (x, (n, n)) -> (x, (n, n)) -> Ordering
forall i a. Ord i => (a -> i) -> a -> a -> Ordering
fcompare (x, (n, n)) -> (n, n)
forall a b. (a, b) -> b
snd)
([(x, (n, n))] -> [(x, (n, n))]) -> [(x, (n, n))] -> [(x, (n, n))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (n, n)) -> (x, (n, n))) -> [(x, (n, n))] -> [(x, (n, n))]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,(n
i,n
j)) -> (x -> x
forall x. Transposable x => x -> x
transpose x
x,(n
j,n
i)))
([(x, (n, n))] -> [(x, (n, n))]) -> [(x, (n, n))] -> [(x, (n, n))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (n, n) x -> [(x, (n, n))]
forall i x. PSequence i x -> [(x, i)]
psqxs (PSequence (n, n) x -> [(x, (n, n))])
-> PSequence (n, n) x -> [(x, (n, n))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (n, n) x
xs
type instance Dual (Entries i j x) = Entries j i (Op x)
coEntries :: (Ord i, Ord j) => Entries i j x -> Dual (Entries i j x)
coEntries :: forall i j x.
(Ord i, Ord j) =>
Entries i j x -> Dual (Entries i j x)
coEntries (Entries PSequence (i, j) x
xs) = PSequence (j, i) (Op x) -> Entries j i (Op x)
forall i j x. PSequence (i, j) x -> Entries i j x
Entries
(PSequence (j, i) (Op x) -> Entries j i (Op x))
-> PSequence (j, i) (Op x) -> Entries j i (Op x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(Op x, (j, i))] -> PSequence (j, i) (Op x)
forall i x. [(x, i)] -> PSequence i x
PSequence
([(Op x, (j, i))] -> PSequence (j, i) (Op x))
-> [(Op x, (j, i))] -> PSequence (j, i) (Op x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((Op x, (j, i)) -> (Op x, (j, i)) -> Ordering)
-> [(Op x, (j, i))] -> [(Op x, (j, i))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((Op x, (j, i)) -> (j, i))
-> (Op x, (j, i)) -> (Op x, (j, i)) -> Ordering
forall i a. Ord i => (a -> i) -> a -> a -> Ordering
fcompare (Op x, (j, i)) -> (j, i)
forall a b. (a, b) -> b
snd)
([(Op x, (j, i))] -> [(Op x, (j, i))])
-> [(Op x, (j, i))] -> [(Op x, (j, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (i, j)) -> (Op x, (j, i)))
-> [(x, (i, j))] -> [(Op x, (j, i))]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,(i
i,j
j)) -> (x -> Op x
forall x. x -> Op x
Op x
x,(j
j,i
i)))
([(x, (i, j))] -> [(Op x, (j, i))])
-> [(x, (i, j))] -> [(Op x, (j, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x -> [(x, (i, j))]
forall i x. PSequence i x -> [(x, i)]
psqxs (PSequence (i, j) x -> [(x, (i, j))])
-> PSequence (i, j) x -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x
xs
coEntriesInv :: (Ord i, Ord j) => Dual (Entries i j x) -> Entries i j x
coEntriesInv :: forall i j x.
(Ord i, Ord j) =>
Dual (Entries i j x) -> Entries i j x
coEntriesInv (Entries PSequence (j, i) (Op x)
xs') = PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries
(PSequence (i, j) x -> Entries i j x)
-> PSequence (i, j) x -> Entries i j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(x, (i, j))] -> PSequence (i, j) x
forall i x. [(x, i)] -> PSequence i x
PSequence
([(x, (i, j))] -> PSequence (i, j) x)
-> [(x, (i, j))] -> PSequence (i, j) x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (i, j)) -> (x, (i, j)) -> Ordering)
-> [(x, (i, j))] -> [(x, (i, j))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((x, (i, j)) -> (i, j)) -> (x, (i, j)) -> (x, (i, j)) -> Ordering
forall i a. Ord i => (a -> i) -> a -> a -> Ordering
fcompare (x, (i, j)) -> (i, j)
forall a b. (a, b) -> b
snd)
([(x, (i, j))] -> [(x, (i, j))]) -> [(x, (i, j))] -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((Op x, (j, i)) -> (x, (i, j)))
-> [(Op x, (j, i))] -> [(x, (i, j))]
forall a b. (a -> b) -> [a] -> [b]
map (\(Op x
x,(j
j,i
i)) -> (x
x,(i
i,j
j)))
([(Op x, (j, i))] -> [(x, (i, j))])
-> [(Op x, (j, i))] -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (\(PSequence [(Op x, (j, i))]
xs) -> [(Op x, (j, i))]
xs) (PSequence (j, i) (Op x) -> [(Op x, (j, i))])
-> PSequence (j, i) (Op x) -> [(Op x, (j, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (j, i) (Op x)
xs'
etsMapCov :: HomDistributiveDisjunctive h
=> Variant2 Covariant h x y -> Entries i j x -> Entries i j y
etsMapCov :: forall (h :: * -> * -> *) x y i j.
HomDistributiveDisjunctive h =>
Variant2 'Covariant h x y -> Entries i j x -> Entries i j y
etsMapCov (Covariant2 h x y
h) (Entries PSequence (i, j) x
xs) = case Struct (ObjectClass h) y -> Struct Dst y
forall s x. Transformable s Dst => Struct s x -> Struct Dst x
tauDst (h x y -> Struct (ObjectClass h) y
forall x y. h x y -> Struct (ObjectClass h) y
forall (m :: * -> * -> *) x y.
Morphism m =>
m x y -> Struct (ObjectClass m) y
range h x y
h) of
Struct Dst y
Struct -> Entries i j y -> Entries i j y
forall x i j. Additive x => Entries i j x -> Entries i j x
etsElimZeros (Entries i j y -> Entries i j y) -> Entries i j y -> Entries i j y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) y -> Entries i j y
forall i j x. PSequence (i, j) x -> Entries i j x
Entries (PSequence (i, j) y -> Entries i j y)
-> PSequence (i, j) y -> Entries i j y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (x -> y) -> PSequence (i, j) x -> PSequence (i, j) y
forall (h :: * -> * -> *) (f :: * -> *) x y.
Applicative1 h f =>
h x y -> f x -> f y
amap1 (h x y -> x -> y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
amap h x y
h) PSequence (i, j) x
xs
etsMapCnt :: (HomDistributiveDisjunctive h, Ord i, Ord j)
=> Variant2 Contravariant h x y -> Entries i j x -> Entries j i y
etsMapCnt :: forall (h :: * -> * -> *) i j x y.
(HomDistributiveDisjunctive h, Ord i, Ord j) =>
Variant2 'Contravariant h x y -> Entries i j x -> Entries j i y
etsMapCnt (Contravariant2 h x y
h) (Entries PSequence (i, j) x
xs) = case Struct (ObjectClass h) y -> Struct Dst y
forall s x. Transformable s Dst => Struct s x -> Struct Dst x
tauDst (Struct (ObjectClass h) y -> Struct Dst y)
-> Struct (ObjectClass h) y -> Struct Dst y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ h x y -> Struct (ObjectClass h) y
forall x y. h x y -> Struct (ObjectClass h) y
forall (m :: * -> * -> *) x y.
Morphism m =>
m x y -> Struct (ObjectClass m) y
range h x y
h of
Struct Dst y
Struct -> Entries j i y -> Entries j i y
forall x i j. Additive x => Entries i j x -> Entries i j x
etsElimZeros
(Entries j i y -> Entries j i y) -> Entries j i y -> Entries j i y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (j, i) y -> Entries j i y
forall i j x. PSequence (i, j) x -> Entries i j x
Entries
(PSequence (j, i) y -> Entries j i y)
-> PSequence (j, i) y -> Entries j i y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(y, (j, i))] -> PSequence (j, i) y
forall i x. [(x, i)] -> PSequence i x
PSequence
([(y, (j, i))] -> PSequence (j, i) y)
-> [(y, (j, i))] -> PSequence (j, i) y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((y, (j, i)) -> (y, (j, i)) -> Ordering)
-> [(y, (j, i))] -> [(y, (j, i))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((y, (j, i)) -> (j, i)) -> (y, (j, i)) -> (y, (j, i)) -> Ordering
forall i a. Ord i => (a -> i) -> a -> a -> Ordering
fcompare (y, (j, i)) -> (j, i)
forall a b. (a, b) -> b
snd)
([(y, (j, i))] -> [(y, (j, i))]) -> [(y, (j, i))] -> [(y, (j, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (i, j)) -> (y, (j, i))) -> [(x, (i, j))] -> [(y, (j, i))]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,(i
i,j
j)) -> (h x y -> x -> y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
amap h x y
h x
x,(j
j,i
i)))
([(x, (i, j))] -> [(y, (j, i))]) -> [(x, (i, j))] -> [(y, (j, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x -> [(x, (i, j))]
forall i x. PSequence i x -> [(x, i)]
psqxs (PSequence (i, j) x -> [(x, (i, j))])
-> PSequence (i, j) x -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x
xs
etscr :: Eq i => Entries i j x -> Col i (Row j x)
etscr :: forall i j x. Eq i => Entries i j x -> Col i (Row j x)
etscr (Entries PSequence (i, j) x
xs) = PSequence i (Row j x) -> Col i (Row j x)
forall i x. PSequence i x -> Col i x
Col (PSequence i (Row j x) -> Col i (Row j x))
-> PSequence i (Row j x) -> Col i (Row j x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(Row j x, i)] -> PSequence i (Row j x)
forall i x. [(x, i)] -> PSequence i x
PSequence ([(Row j x, i)] -> PSequence i (Row j x))
-> [(Row j x, i)] -> PSequence i (Row j x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (i, j) x -> [(Row j x, i)]
forall {y} {b} {x}. Eq y => PSequence (y, b) x -> [(Row b x, y)]
cr PSequence (i, j) x
xs where
cr :: PSequence (y, b) x -> [(Row b x, y)]
cr (PSequence []) = []
cr PSequence (y, b) x
xs = (Row b x
l,y
i) (Row b x, y) -> [(Row b x, y)] -> [(Row b x, y)]
forall a. a -> [a] -> [a]
: PSequence (y, b) x -> [(Row b x, y)]
cr PSequence (y, b) x
r where
(PSequence [(x, (y, b))]
ls,PSequence (y, b) x
r) = ((x, (y, b)) -> Bool)
-> PSequence (y, b) x -> (PSequence (y, b) x, PSequence (y, b) x)
forall x i.
((x, i) -> Bool) -> PSequence i x -> (PSequence i x, PSequence i x)
psqSplitWhile ((y -> y -> Bool
forall a. Eq a => a -> a -> Bool
==y
i) (y -> Bool) -> ((x, (y, b)) -> y) -> (x, (y, b)) -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. (x, (y, b)) -> y
forall {a} {a} {b}. (a, (a, b)) -> a
ix) PSequence (y, b) x
xs
ix :: (a, (a, b)) -> a
ix (a
_,(a
i,b
_)) = a
i
i :: y
i = (x, (y, b)) -> y
forall {a} {a} {b}. (a, (a, b)) -> a
ix ((x, (y, b)) -> y) -> (x, (y, b)) -> y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence (y, b) x -> (x, (y, b))
forall i x. PSequence i x -> (x, i)
psqHead PSequence (y, b) x
xs
l :: Row b x
l = PSequence b x -> Row b x
forall j x. PSequence j x -> Row j x
Row (PSequence b x -> Row b x) -> PSequence b x -> Row b x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(x, b)] -> PSequence b x
forall i x. [(x, i)] -> PSequence i x
PSequence ([(x, b)] -> PSequence b x) -> [(x, b)] -> PSequence b x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((x, (y, b)) -> (x, b)) -> [(x, (y, b))] -> [(x, b)]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,(y
_,b
j)) -> (x
x,b
j)) ([(x, (y, b))] -> [(x, b)]) -> [(x, (y, b))] -> [(x, b)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(x, (y, b))]
ls
etsrc :: (Ord i, Ord j) => Entries i j x -> Row j (Col i x)
etsrc :: forall i j x. (Ord i, Ord j) => Entries i j x -> Row j (Col i x)
etsrc = Dual (Row j (Col i x)) -> Row j (Col i x)
Col j (Row i (Op x)) -> Row j (Col i x)
forall j i x. Dual (Row j (Col i x)) -> Row j (Col i x)
coRowColInv (Col j (Row i (Op x)) -> Row j (Col i x))
-> (Entries i j x -> Col j (Row i (Op x)))
-> Entries i j x
-> Row j (Col i x)
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. Entries j i (Op x) -> Col j (Row i (Op x))
forall i j x. Eq i => Entries i j x -> Col i (Row j x)
etscr (Entries j i (Op x) -> Col j (Row i (Op x)))
-> (Entries i j x -> Entries j i (Op x))
-> Entries i j x
-> Col j (Row i (Op x))
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. Entries i j x -> Dual (Entries i j x)
Entries i j x -> Entries j i (Op x)
forall i j x.
(Ord i, Ord j) =>
Entries i j x -> Dual (Entries i j x)
coEntries
etsMlt :: (Distributive x, Ord k) => Col i (Row k x) -> Row j (Col k x) -> Col i (Row j x)
etsMlt :: forall x k i j.
(Distributive x, Ord k) =>
Col i (Row k x) -> Row j (Col k x) -> Col i (Row j x)
etsMlt (Col PSequence i (Row k x)
rws) (Row PSequence j (Col k x)
cls) = PSequence i (Row j x) -> Col i (Row j x)
forall i x. PSequence i x -> Col i x
Col PSequence i (Row j x)
rws' where
rws' :: PSequence i (Row j x)
rws' = (Row k x -> Row j x)
-> PSequence i (Row k x) -> PSequence i (Row j x)
forall a b. (a -> b) -> PSequence i a -> PSequence i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Row k x -> PSequence j (Col k x) -> Row j x
forall {y} {i} {j}.
(Additive y, Ord i, Multiplicative y) =>
Row i y -> PSequence j (Col i y) -> Row j y
<*PSequence j (Col k x)
cls) PSequence i (Row k x)
rws
Row i y
rw <* :: Row i y -> PSequence j (Col i y) -> Row j y
<* PSequence j (Col i y)
cls
= PSequence j y -> Row j y
forall j x. PSequence j x -> Row j x
Row
(PSequence j y -> Row j y) -> PSequence j y -> Row j y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Maybe y -> y) -> PSequence j (Maybe y) -> PSequence j y
forall a b. (a -> b) -> PSequence j a -> PSequence j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe y -> y
forall a. HasCallStack => Maybe a -> a
fromJust
(PSequence j (Maybe y) -> PSequence j y)
-> PSequence j (Maybe y) -> PSequence j y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Maybe y -> Bool) -> PSequence j (Maybe y) -> PSequence j (Maybe y)
forall x i. (x -> Bool) -> PSequence i x -> PSequence i x
psqFilter Maybe y -> Bool
forall a. Maybe a -> Bool
isJust
(PSequence j (Maybe y) -> PSequence j (Maybe y))
-> PSequence j (Maybe y) -> PSequence j (Maybe y)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Col i y -> Maybe y)
-> PSequence j (Col i y) -> PSequence j (Maybe y)
forall a b. (a -> b) -> PSequence j a -> PSequence j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Row i y
rwRow i y -> Col i y -> Maybe y
forall {y} {i}.
(Additive y, Ord i, Multiplicative y) =>
Row i y -> Col i y -> Maybe y
<*>) PSequence j (Col i y)
cls
Row PSequence i y
rw <*> :: Row i y -> Col i y -> Maybe y
<*> Col PSequence i y
cl
= (Maybe y -> Maybe y -> Maybe y)
-> Maybe y -> PSequence i (Maybe y) -> Maybe y
forall b a. (b -> a -> b) -> b -> PSequence i a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Maybe y -> Maybe y -> Maybe y
forall {a}. Additive a => Maybe a -> Maybe a -> Maybe a
add Maybe y
forall a. Maybe a
Nothing
(PSequence i (Maybe y) -> Maybe y)
-> PSequence i (Maybe y) -> Maybe y
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (y -> y -> Maybe y)
-> (y -> Maybe y)
-> (y -> Maybe y)
-> PSequence i y
-> PSequence i y
-> PSequence i (Maybe y)
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z)
-> (y -> z)
-> PSequence i x
-> PSequence i y
-> PSequence i z
psqInterlace y -> y -> Maybe y
forall {a}. (Multiplicative a, Additive a) => a -> a -> Maybe a
mlt (Maybe y -> y -> Maybe y
forall b a. b -> a -> b
const Maybe y
forall a. Maybe a
Nothing) (Maybe y -> y -> Maybe y
forall b a. b -> a -> b
const Maybe y
forall a. Maybe a
Nothing) PSequence i y
rw PSequence i y
cl
mlt :: a -> a -> Maybe a
mlt a
x a
y = if a -> Bool
forall a. Additive a => a -> Bool
isZero a
xy then Maybe a
forall a. Maybe a
Nothing else (a -> Maybe a
forall a. a -> Maybe a
Just a
xy) where xy :: a
xy = a
xa -> a -> a
forall c. Multiplicative c => c -> c -> c
*a
y
add :: Maybe a -> Maybe a -> Maybe a
add Maybe a
Nothing Maybe a
y = Maybe a
y
add Maybe a
x Maybe a
Nothing = Maybe a
x
add (Just a
x) (Just a
y) = if a -> Bool
forall a. Additive a => a -> Bool
isZero a
xy then Maybe a
forall a. Maybe a
Nothing else (a -> Maybe a
forall a. a -> Maybe a
Just a
xy) where xy :: a
xy = a
xa -> a -> a
forall a. Additive a => a -> a -> a
+a
y
crets :: Col i (Row j x) -> Entries i j x
crets :: forall i j x. Col i (Row j x) -> Entries i j x
crets (Col PSequence i (Row j x)
rws) = PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries (PSequence (i, j) x -> Entries i j x)
-> PSequence (i, j) x -> Entries i j x
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(x, (i, j))] -> PSequence (i, j) x
forall i x. [(x, i)] -> PSequence i x
PSequence [(x, (i, j))]
ets where
ets :: [(x, (i, j))]
ets = [[(x, (i, j))]] -> [(x, (i, j))]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([[(x, (i, j))]] -> [(x, (i, j))])
-> [[(x, (i, j))]] -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ ((Row j x, i) -> [(x, (i, j))])
-> [(Row j x, i)] -> [[(x, (i, j))]]
forall a b. (a -> b) -> [a] -> [b]
map (\(Row j x
rw,i
i) -> (i -> Row j x -> [(x, (i, j))]
forall {a} {i} {x}. a -> Row i x -> [(x, (a, i))]
xijs i
i Row j x
rw)) ([(Row j x, i)] -> [[(x, (i, j))]])
-> [(Row j x, i)] -> [[(x, (i, j))]]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence i (Row j x) -> [(Row j x, i)]
forall i x. PSequence i x -> [(x, i)]
psqxs PSequence i (Row j x)
rws
xijs :: a -> Row i x -> [(x, (a, i))]
xijs a
i (Row PSequence i x
xj) = ((x, i) -> (x, (a, i))) -> [(x, i)] -> [(x, (a, i))]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,i
j) -> (x
x,(a
i,i
j))) ([(x, i)] -> [(x, (a, i))]) -> [(x, i)] -> [(x, (a, i))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ PSequence i x -> [(x, i)]
forall i x. PSequence i x -> [(x, i)]
psqxs PSequence i x
xj
rcets :: (Ord i, Ord j) => Row j (Col i x) -> Entries i j x
rcets :: forall i j x. (Ord i, Ord j) => Row j (Col i x) -> Entries i j x
rcets = PSequence (i, j) x -> Entries i j x
forall i j x. PSequence (i, j) x -> Entries i j x
Entries (PSequence (i, j) x -> Entries i j x)
-> (Row j (Col i x) -> PSequence (i, j) x)
-> Row j (Col i x)
-> Entries i j x
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. (x -> x -> x) -> [(x, (i, j))] -> PSequence (i, j) x
forall i x. Ord i => (x -> x -> x) -> [(x, i)] -> PSequence i x
psequence (((x, x) -> x) -> x -> x -> x
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (x, x) -> x
forall a b. (a, b) -> a
fst) ([(x, (i, j))] -> PSequence (i, j) x)
-> (Row j (Col i x) -> [(x, (i, j))])
-> Row j (Col i x)
-> PSequence (i, j) x
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. [(Col i x, j)] -> [(x, (i, j))]
forall i x j. [(Col i x, j)] -> [(x, (i, j))]
ets ([(Col i x, j)] -> [(x, (i, j))])
-> (Row j (Col i x) -> [(Col i x, j)])
-> Row j (Col i x)
-> [(x, (i, j))]
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. Row j (Col i x) -> [(Col i x, j)]
forall j x. Row j x -> [(x, j)]
rowxs where
ets :: [(Col i x,j)] -> [(x,(i,j))]
ets :: forall i x j. [(Col i x, j)] -> [(x, (i, j))]
ets = [[(x, (i, j))]] -> [(x, (i, j))]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([[(x, (i, j))]] -> [(x, (i, j))])
-> ([(Col i x, j)] -> [[(x, (i, j))]])
-> [(Col i x, j)]
-> [(x, (i, j))]
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. ((Col i x, j) -> [(x, (i, j))])
-> [(Col i x, j)] -> [[(x, (i, j))]]
forall a b. (a -> b) -> [a] -> [b]
map (\(Col i x
cl,j
j) -> ((x, i) -> (x, (i, j))) -> [(x, i)] -> [(x, (i, j))]
forall a b. (a -> b) -> [a] -> [b]
map (\(x
x,i
i) -> (x
x,(i
i,j
j))) ([(x, i)] -> [(x, (i, j))]) -> [(x, i)] -> [(x, (i, j))]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ Col i x -> [(x, i)]
forall i x. Col i x -> [(x, i)]
colxs Col i x
cl)
etsJoin :: (i ~ N, j ~ N)
=> ProductSymbol i -> ProductSymbol j -> Entries i j (Entries i j x) -> Entries i j x
etsJoin :: forall i j x.
(i ~ N, j ~ N) =>
ProductSymbol i
-> ProductSymbol j -> Entries i j (Entries i j x) -> Entries i j x
etsJoin ProductSymbol i
r ProductSymbol j
c Entries i j (Entries i j x)
es = Col i (Row j x) -> Entries i j x
forall i j x. Col i (Row j x) -> Entries i j x
crets Col i (Row j x)
Col N (Row N x)
es' where
es' :: Col N (Row N x)
es' = [(i, N)]
-> [(i, N)] -> [(Row N (Entries N N x), N)] -> Col N (Row N x)
forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
[(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
join (i -> [(i, N)] -> [(i, N)]
forall {t} {b}. Additive t => t -> [(t, b)] -> [(t, b)]
accum i
0 (ProductSymbol i -> [(i, N)]
forall x. ProductSymbol x -> [(x, N)]
psyxs ProductSymbol i
r))
(i -> [(i, N)] -> [(i, N)]
forall {t} {b}. Additive t => t -> [(t, b)] -> [(t, b)]
accum i
0 (ProductSymbol i -> [(i, N)]
forall x. ProductSymbol x -> [(x, N)]
psyxs ProductSymbol i
ProductSymbol j
c))
(Col i (Row j (Entries i j x)) -> [(Row N (Entries N N x), N)]
Col N (Row N (Entries N N x)) -> [(Row N (Entries N N x), N)]
forall i x. Col i x -> [(x, i)]
colxs (Col i (Row j (Entries i j x)) -> [(Row N (Entries N N x), N)])
-> Col i (Row j (Entries i j x)) -> [(Row N (Entries N N x), N)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ Entries i j (Entries i j x) -> Col i (Row j (Entries i j x))
forall i j x. Eq i => Entries i j x -> Col i (Row j x)
etscr Entries i j (Entries i j x)
es)
accum :: t -> [(t, b)] -> [(t, b)]
accum t
_ [] = []
accum t
o ((t
d,b
i):[(t, b)]
dis) = (t
o,b
i)(t, b) -> [(t, b)] -> [(t, b)]
forall a. a -> [a] -> [a]
:t -> [(t, b)] -> [(t, b)]
accum (t
ot -> t -> t
forall a. Additive a => a -> a -> a
+t
d) [(t, b)]
dis
join :: (i ~ N, j ~ N, o ~ N)
=> [(o,i)] -> [(o,j)]
-> [(Row j (Entries i j x),i)] -> Col i (Row j x)
join :: forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
[(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
join [(o, i)]
_ [(o, j)]
_ [] = Col i (Row j x)
forall i x. Col i x
colEmpty
join ((o
_,i
i):[(o, i)]
ois) [(o, j)]
ojs rws :: [(Row j (Entries i j x), i)]
rws@((Row j (Entries i j x)
_,i
i'):[(Row j (Entries i j x), i)]
_) | i
i i -> i -> Bool
forall a. Ord a => a -> a -> Bool
< i
i' = [(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
[(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
join [(o, i)]
ois [(o, j)]
ojs [(Row j (Entries i j x), i)]
rws
join ((o
o,i
_):[(o, i)]
ois) [(o, j)]
ojs ((Row j (Entries i j x)
rw,i
_):[(Row j (Entries i j x), i)]
rws) = o -> [(o, j)] -> Row j (Entries i j x) -> Col i (Row j x)
forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
o -> [(o, j)] -> Row j (Entries i j x) -> Col i (Row j x)
joinRow o
o [(o, j)]
ojs Row j (Entries i j x)
rw
Col i (Row j x) -> Col i (Row j x) -> Col i (Row j x)
forall i x. Col i x -> Col i x -> Col i x
`colAppend` [(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
[(o, i)]
-> [(o, j)] -> [(Row j (Entries i j x), i)] -> Col i (Row j x)
join [(o, i)]
ois [(o, j)]
ojs [(Row j (Entries i j x), i)]
rws
joinRow :: (i ~ N, j ~ N, o ~ N)
=> o -> [(o,j)] -> Row j (Entries i j x) -> Col i (Row j x)
joinRow :: forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
o -> [(o, j)] -> Row j (Entries i j x) -> Col i (Row j x)
joinRow o
oi [(o, j)]
ojs Row j (Entries i j x)
rw = (Col N (Row N x) -> Col N (Row N x) -> Col N (Row N x))
-> Col N (Row N x) -> [Col N (Row N x)] -> Col N (Row N x)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Col N (Row N x) -> Col N (Row N x) -> Col N (Row N x)
forall i j x.
Ord i =>
Col i (Row j x) -> Col i (Row j x) -> Col i (Row j x)
(||) Col N (Row N x)
forall i x. Col i x
colEmpty ([Col i (Row j x)] -> Col i (Row j x))
-> [Col i (Row j x)] -> Col i (Row j x)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ o -> [(o, j)] -> Row j (Entries i j x) -> [Col i (Row j x)]
forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
o -> [(o, j)] -> Row j (Entries i j x) -> [Col i (Row j x)]
rwShift o
oi [(o, j)]
ojs Row j (Entries i j x)
rw
rwShift :: (i ~ N, j ~ N, o ~ N)
=> o -> [(o,j)] -> Row j (Entries i j x) -> [Col i (Row j x)]
rwShift :: forall i j o x.
(i ~ N, j ~ N, o ~ N) =>
o -> [(o, j)] -> Row j (Entries i j x) -> [Col i (Row j x)]
rwShift o
oi [(o, j)]
ojs Row j (Entries i j x)
rw = [(j, j)] -> [(Entries o j x, j)] -> [Col o (Row j x)]
shRow [(j, j)]
[(o, j)]
ojs (Row j (Entries o j x) -> [(Entries o j x, j)]
forall j x. Row j x -> [(x, j)]
rowxs Row j (Entries i j x)
Row j (Entries o j x)
rw) where
shRow :: [(j, j)] -> [(Entries o j x, j)] -> [Col o (Row j x)]
shRow [(j, j)]
_ [] = []
shRow ((j
_,j
j):[(j, j)]
ojs) rw :: [(Entries o j x, j)]
rw@((Entries o j x
_,j
j'):[(Entries o j x, j)]
_) | j
j j -> j -> Bool
forall a. Ord a => a -> a -> Bool
< j
j' = [(j, j)] -> [(Entries o j x, j)] -> [Col o (Row j x)]
shRow [(j, j)]
ojs [(Entries o j x, j)]
rw
shRow ((j
oj,j
_):[(j, j)]
ojs) ((Entries o j x
xs,j
_):[(Entries o j x, j)]
rw) = o -> j -> Col o (Row j x) -> Col o (Row j x)
forall {j} {i} {y}.
(Number i, Number j) =>
i -> j -> Col i (Row j y) -> Col i (Row j y)
shColRow o
oi j
oj (Entries o j x -> Col o (Row j x)
forall i j x. Eq i => Entries i j x -> Col i (Row j x)
etscr Entries o j x
xs) Col o (Row j x) -> [Col o (Row j x)] -> [Col o (Row j x)]
forall a. a -> [a] -> [a]
: [(j, j)] -> [(Entries o j x, j)] -> [Col o (Row j x)]
shRow [(j, j)]
ojs [(Entries o j x, j)]
rw
shColRow :: i -> j -> Col i (Row j y) -> Col i (Row j y)
shColRow i
oi j
oj = i
-> ((Row j y, i) -> Row j y) -> Col i (Row j y) -> Col i (Row j y)
forall i x y. Number i => i -> ((x, i) -> y) -> Col i x -> Col i y
colMapShift i
oi (j -> ((y, j) -> y) -> Row j y -> Row j y
forall j x y. Number j => j -> ((x, j) -> y) -> Row j x -> Row j y
rowMapShift j
oj (y, j) -> y
forall a b. (a, b) -> a
fst (Row j y -> Row j y)
-> ((Row j y, i) -> Row j y) -> (Row j y, i) -> Row j y
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. (Row j y, i) -> Row j y
forall a b. (a, b) -> a
fst)
(||) :: Ord i => Col i (Row j x) -> Col i (Row j x) -> Col i (Row j x)
|| :: forall i j x.
Ord i =>
Col i (Row j x) -> Col i (Row j x) -> Col i (Row j x)
(||) = (Row j x -> Row j x -> Row j x)
-> (Row j x -> Row j x)
-> (Row j x -> Row j x)
-> Col i (Row j x)
-> Col i (Row j x)
-> Col i (Row j x)
forall i x y z.
Ord i =>
(x -> y -> z)
-> (x -> z) -> (y -> z) -> Col i x -> Col i y -> Col i z
colInterlace Row j x -> Row j x -> Row j x
forall j x. Row j x -> Row j x -> Row j x
rowAppend Row j x -> Row j x
forall x. x -> x
id Row j x -> Row j x
forall x. x -> x
id
crHeadColAt :: Eq j => j -> Col i (Row j a) -> Col i a
crHeadColAt :: forall j i a. Eq j => j -> Col i (Row j a) -> Col i a
crHeadColAt j
j Col i (Row j a)
rws
= PSequence i a -> Col i a
forall i x. PSequence i x -> Col i x
Col (PSequence i a -> Col i a) -> PSequence i a -> Col i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ [(a, i)] -> PSequence i a
forall i x. [(x, i)] -> PSequence i x
PSequence
([(a, i)] -> PSequence i a) -> [(a, i)] -> PSequence i a
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (((a, j), i) -> (a, i)) -> [((a, j), i)] -> [(a, i)]
forall a b. (a -> b) -> [a] -> [b]
map (\((a
a,j
_),i
i) -> (a
a,i
i))
([((a, j), i)] -> [(a, i)]) -> [((a, j), i)] -> [(a, i)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (((a, j), i) -> Bool) -> [((a, j), i)] -> [((a, j), i)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((j
jj -> j -> Bool
forall a. Eq a => a -> a -> Bool
==)(j -> Bool) -> (((a, j), i) -> j) -> ((a, j), i) -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
.(a, j) -> j
forall a b. (a, b) -> b
snd((a, j) -> j) -> (((a, j), i) -> (a, j)) -> ((a, j), i) -> j
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
.((a, j), i) -> (a, j)
forall a b. (a, b) -> a
fst)
([((a, j), i)] -> [((a, j), i)]) -> [((a, j), i)] -> [((a, j), i)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ Col i (a, j) -> [((a, j), i)]
forall i x. Col i x -> [(x, i)]
colxs
(Col i (a, j) -> [((a, j), i)]) -> Col i (a, j) -> [((a, j), i)]
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Row j a -> (a, j)) -> Col i (Row j a) -> Col i (a, j)
forall a b. (a -> b) -> Col i a -> Col i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Row j a -> (a, j)
forall j x. Row j x -> (x, j)
rowHead
(Col i (Row j a) -> Col i (a, j))
-> Col i (Row j a) -> Col i (a, j)
forall (h :: * -> * -> *) x y. Applicative h => h x y -> x -> y
$ (Row j a -> Bool) -> Col i (Row j a) -> Col i (Row j a)
forall x i. (x -> Bool) -> Col i x -> Col i x
colFilter (Bool -> Bool
forall b. Boolean b => b -> b
not (Bool -> Bool) -> (Row j a -> Bool) -> Row j a -> Bool
forall y z x. (y -> z) -> (x -> y) -> x -> z
forall (c :: * -> * -> *) y z x.
Category c =>
c y z -> c x y -> c x z
. Row j a -> Bool
forall j x. Row j x -> Bool
rowIsEmpty) Col i (Row j a)
rws
crHeadRowAt :: Eq i => i -> Col i (Row j a) -> Row j a
crHeadRowAt :: forall i j a. Eq i => i -> Col i (Row j a) -> Row j a
crHeadRowAt i
i Col i (Row j a)
rws = if i
i i -> i -> Bool
forall a. Eq a => a -> a -> Bool
== i
i' then Row j a
rw else Row j a
forall j x. Row j x
rowEmpty where
(Row j a
rw,i
i') = Col i (Row j a) -> (Row j a, i)
forall i x. Col i x -> (x, i)
colHead Col i (Row j a)
rws