@@ -52,8 +52,8 @@ module LAoP.Matrix.Internal
52 -- * Primitives
52 -- * Primitives
58 -- * Auxiliary type families
58 -- * Auxiliary type families
@@ -96,12 +96,12 @@ module LAoP.Matrix.Internal
98 -- * Biproduct approach
98 -- * Biproduct approach
99− -- ** Split
99+ -- ** Fork
101 -- *** Projections
101 -- *** Projections
104− -- ** Junc
104+ -- ** Join
106 -- *** Injections
106 -- *** Injections
@@ -115,8 +115,8 @@ module LAoP.Matrix.Internal
115 -- | Note that given the restrictions imposed it is not possible to
115 -- | Note that given the restrictions imposed it is not possible to
116 -- implement the standard type classes present in standard Haskell.
116 -- implement the standard type classes present in standard Haskell.
117 -- *** Matrix pairing projections
117 -- *** Matrix pairing projections
121 -- *** Matrix pairing
121 -- *** Matrix pairing
@@ -127,10 +127,10 @@ module LAoP.Matrix.Internal
128 -- | Note that given the restrictions imposed it is not possible to
128 -- | Note that given the restrictions imposed it is not possible to
129 -- implement the standard type classes present in standard Haskell.
129 -- implement the standard type classes present in standard Haskell.
135 -- * Matrix printing
135 -- * Matrix printing
@@ -171,8 +171,8 @@ import Prelude hiding ((.))
171data Matrix e cols rows where
171data Matrix e cols rows where
172 Empty :: Matrix e Void Void
172 Empty :: Matrix e Void Void
173 One :: e -> Matrix e () ()
173 One :: e -> Matrix e () ()
174− Junc :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
174+ Join :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
175− Split :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
175+ Fork :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
177deriving instance (Show e) => Show (Matrix e cols rows)
177deriving instance (Show e) => Show (Matrix e cols rows)
@@ -226,7 +226,7 @@ type Trivial a = FromNat (Count a) ~ a
226-- implementation is 'undefined'. However 'comp' can be and this partial
226-- implementation is 'undefined'. However 'comp' can be and this partial
227-- class implementation exists just to make the code more readable.
227-- class implementation exists just to make the code more readable.
229−-- Please use 'identity' instead.
229+-- Please use 'iden' instead.
230instance (Num e) => Category (Matrix e) where
230instance (Num e) => Category (Matrix e) where
231 id = undefined
231 id = undefined
232 (.) = comp
232 (.) = comp
@@ -234,16 +234,16 @@ instance (Num e) => Category (Matrix e) where
234instance NFData e => NFData (Matrix e cols rows) where
234instance NFData e => NFData (Matrix e cols rows) where
235 rnf Empty = ()
235 rnf Empty = ()
236 rnf (One e) = rnf e
236 rnf (One e) = rnf e
237− rnf (Junc a b) = rnf a `seq` rnf b
237+ rnf (Join a b) = rnf a `seq` rnf b
238− rnf (Split a b) = rnf a `seq` rnf b
238+ rnf (Fork a b) = rnf a `seq` rnf b
240instance Eq e => Eq (Matrix e cols rows) where
240instance Eq e => Eq (Matrix e cols rows) where
241 Empty == Empty = True
241 Empty == Empty = True
242 (One a) == (One b) = a == b
242 (One a) == (One b) = a == b
243− (Junc a b) == (Junc c d) = a == c && b == d
243+ (Join a b) == (Join c d) = a == c && b == d
244− (Split a b) == (Split c d) = a == c && b == d
244+ (Fork a b) == (Fork c d) = a == c && b == d
245− x@(Split _ _) == y@(Junc _ _) = x == abideJS y
245+ x@(Fork _ _) == y@(Join _ _) = x == abideJS y
246− x@(Junc _ _) == y@(Split _ _) = abideJS x == y
246+ x@(Join _ _) == y@(Fork _ _) = abideJS x == y
248instance Num e => Num (Matrix e cols rows) where
248instance Num e => Num (Matrix e cols rows) where
@@ -255,21 +255,21 @@ instance Num e => Num (Matrix e cols rows) where
256 abs Empty = Empty
256 abs Empty = Empty
257 abs (One a) = One (abs a)
257 abs (One a) = One (abs a)
258− abs (Junc a b) = Junc (abs a) (abs b)
258+ abs (Join a b) = Join (abs a) (abs b)
259− abs (Split a b) = Split (abs a) (abs b)
259+ abs (Fork a b) = Fork (abs a) (abs b)
261 signum Empty = Empty
261 signum Empty = Empty
262 signum (One a) = One (signum a)
262 signum (One a) = One (signum a)
263− signum (Junc a b) = Junc (signum a) (signum b)
263+ signum (Join a b) = Join (signum a) (signum b)
264− signum (Split a b) = Split (signum a) (signum b)
264+ signum (Fork a b) = Fork (signum a) (signum b)
266instance Ord e => Ord (Matrix e cols rows) where
266instance Ord e => Ord (Matrix e cols rows) where
267 Empty <= Empty = True
267 Empty <= Empty = True
268 (One a) <= (One b) = a <= b
268 (One a) <= (One b) = a <= b
269− (Junc a b) <= (Junc c d) = (a <= c) && (b <= d)
269+ (Join a b) <= (Join c d) = (a <= c) && (b <= d)
270− (Split a b) <= (Split c d) = (a <= c) && (b <= d)
270+ (Fork a b) <= (Fork c d) = (a <= c) && (b <= d)
271− x@(Split _ _) <= y@(Junc _ _) = x <= abideJS y
271+ x@(Fork _ _) <= y@(Join _ _) = x <= abideJS y
272− x@(Junc _ _) <= y@(Split _ _) = abideJS x <= y
272+ x@(Join _ _) <= y@(Fork _ _) = abideJS x <= y
274-- Primitives
274-- Primitives
@@ -281,25 +281,25 @@ empty = Empty
281one :: e -> Matrix e () ()
281one :: e -> Matrix e () ()
284−-- | Matrix 'Junc' constructor
284+-- | Matrix 'Join' constructor
285−junc :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
285+join :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
286−junc = Junc
286+join = Join
288infixl 3 |||
288infixl 3 |||
290−-- | Matrix 'Junc' constructor
290+-- | Matrix 'Join' constructor
291(|||) :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
291(|||) :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
292−(|||) = Junc
292+(|||) = Join
294−-- | Matrix 'Split' constructor
294+-- | Matrix 'Fork' constructor
295−split :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
295+fork :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
296−split = Split
296+fork = Fork
298infixl 2 ===
298infixl 2 ===
300−-- | Matrix 'Split' constructor
300+-- | Matrix 'Fork' constructor
301(===) :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
301(===) :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
302−(===) = Split
302+(===) = Fork
304-- Construction
304-- Construction
@@ -321,23 +321,23 @@ instance {-# OVERLAPPING #-} FromLists e () () where
321 fromLists _ = error "Wrong dimensions"
321 fromLists _ = error "Wrong dimensions"
323instance {-# OVERLAPPING #-} (FromLists e cols ()) => FromLists e (Either () cols) () where
323instance {-# OVERLAPPING #-} (FromLists e cols ()) => FromLists e (Either () cols) () where
324− fromLists [h : t] = Junc (One h) (fromLists [t])
324+ fromLists [h : t] = Join (One h) (fromLists [t])
325 fromLists _ = error "Wrong dimensions"
325 fromLists _ = error "Wrong dimensions"
327instance {-# OVERLAPPABLE #-} (FromLists e a (), FromLists e b (), Countable a) => FromLists e (Either a b) () where
327instance {-# OVERLAPPABLE #-} (FromLists e a (), FromLists e b (), Countable a) => FromLists e (Either a b) () where
328 fromLists [l] =
328 fromLists [l] =
329 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
329 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
330− in Junc (fromLists [take rowsA l]) (fromLists [drop rowsA l])
330+ in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
331 fromLists _ = error "Wrong dimensions"
331 fromLists _ = error "Wrong dimensions"
333instance {-# OVERLAPPING #-} (FromLists e () rows) => FromLists e () (Either () rows) where
333instance {-# OVERLAPPING #-} (FromLists e () rows) => FromLists e () (Either () rows) where
334− fromLists ([h] : t) = Split (One h) (fromLists t)
334+ fromLists ([h] : t) = Fork (One h) (fromLists t)
335 fromLists _ = error "Wrong dimensions"
335 fromLists _ = error "Wrong dimensions"
337instance {-# OVERLAPPABLE #-} (FromLists e () a, FromLists e () b, Countable a) => FromLists e () (Either a b) where
337instance {-# OVERLAPPABLE #-} (FromLists e () a, FromLists e () b, Countable a) => FromLists e () (Either a b) where
338 fromLists l@([_] : _) =
338 fromLists l@([_] : _) =
339 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
339 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
340− in Split (fromLists (take rowsA l)) (fromLists (drop rowsA l))
340+ in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
341 fromLists _ = error "Wrong dimensions"
341 fromLists _ = error "Wrong dimensions"
343instance {-# OVERLAPPABLE #-} (FromLists e (Either a b) c, FromLists e (Either a b) d, Countable c) => FromLists e (Either a b) (Either c d) where
343instance {-# OVERLAPPABLE #-} (FromLists e (Either a b) c, FromLists e (Either a b) d, Countable c) => FromLists e (Either a b) (Either c d) where
@@ -346,7 +346,7 @@ instance {-# OVERLAPPABLE #-} (FromLists e (Either a b) c, FromLists e (Either a
346 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
346 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
347 condition = all (== lh) (map length t)
347 condition = all (== lh) (map length t)
348 in if lh > 0 && condition
348 in if lh > 0 && condition
349− then Split (fromLists (take rowsC l)) (fromLists (drop rowsC l))
349+ then Fork (fromLists (take rowsC l)) (fromLists (drop rowsC l))
350 else error "Not all rows have the same length"
350 else error "Not all rows have the same length"
352-- | Matrix builder function. Constructs a matrix provided with
352-- | Matrix builder function. Constructs a matrix provided with
@@ -376,7 +376,7 @@ row = fromLists . (: [])
377-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
377-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
378-- types @a@ or @b@ allows.
378-- types @a@ or @b@ allows.
379−fromF ::
379+fromF' ::
380 forall a b cols rows e.
380 forall a b cols rows e.
381 ( Liftable e a b,
381 ( Liftable e a b,
382 CountableDimensions cols rows,
382 CountableDimensions cols rows,
@@ -384,7 +384,7 @@ fromF ::
385 (a -> b) ->
385 (a -> b) ->
386 Matrix e cols rows
386 Matrix e cols rows
387−fromF f =
387+fromF' f =
388 let minA = minBound @a
388 let minA = minBound @a
389 maxA = maxBound @a
389 maxA = maxBound @a
390 minB = minBound @b
390 minB = minBound @b
@@ -405,7 +405,7 @@ fromF f =
406-- | Lifts functions to matrices with dimensions matching @a@ and @b@
406-- | Lifts functions to matrices with dimensions matching @a@ and @b@
407-- cardinality's.
407-- cardinality's.
408−fromF' ::
408+fromF ::
409 forall a b e.
409 forall a b e.
410 ( Liftable e a b,
410 ( Liftable e a b,
411 CountableDimensionsN a b,
411 CountableDimensionsN a b,
@@ -413,7 +413,7 @@ fromF' ::
414 (a -> b) ->
414 (a -> b) ->
415 Matrix e (Normalize a) (Normalize b)
415 Matrix e (Normalize a) (Normalize b)
416−fromF' f =
416+fromF f =
417 let minA = minBound @a
417 let minA = minBound @a
418 maxA = maxBound @a
418 maxA = maxBound @a
419 minB = minBound @b
419 minB = minBound @b
@@ -438,8 +438,8 @@ fromF' f =
438toLists :: Matrix e cols rows -> [[e]]
438toLists :: Matrix e cols rows -> [[e]]
439toLists Empty = []
439toLists Empty = []
440toLists (One e) = [[e]]
440toLists (One e) = [[e]]
441−toLists (Split l r) = toLists l ++ toLists r
441+toLists (Fork l r) = toLists l ++ toLists r
442−toLists (Junc l r) = zipWith (++) (toLists l) (toLists r)
442+toLists (Join l r) = zipWith (++) (toLists l) (toLists r)
444-- | Converts a matrix to a list of elements.
444-- | Converts a matrix to a list of elements.
445toList :: Matrix e cols rows -> [e]
445toList :: Matrix e cols rows -> [e]
@@ -474,12 +474,12 @@ bang =
474 let c = fromInteger $ natVal (Proxy :: Proxy (Count cols))
474 let c = fromInteger $ natVal (Proxy :: Proxy (Count cols))
475 in fromLists [take c [1, 1 ..]]
475 in fromLists [take c [1, 1 ..]]
477−-- Identity Matrix
477+-- iden Matrix
479−-- | Identity matrix.
479+-- | iden matrix.
480−identity :: (Num e, FromLists e cols cols, Countable cols) => Matrix e cols cols
480+iden :: (Num e, FromLists e cols cols, Countable cols) => Matrix e cols cols
481−identity = matrixBuilder (bool 0 1 . uncurry (==))
481+iden = matrixBuilder (bool 0 1 . uncurry (==))
482−{-# NOINLINE identity #-}
482+{-# NOINLINE iden #-}
484-- Matrix composition (MMM)
484-- Matrix composition (MMM)
@@ -490,13 +490,13 @@ identity = matrixBuilder (bool 0 1 . uncurry (==))
490comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
490comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
491comp Empty Empty = Empty
491comp Empty Empty = Empty
492comp (One a) (One b) = One (a * b)
492comp (One a) (One b) = One (a * b)
493−comp (Junc a b) (Split c d) = comp a c + comp b d -- Divide-and-conquer law
493+comp (Join a b) (Fork c d) = comp a c + comp b d -- Divide-and-conquer law
494−comp (Split a b) c = Split (comp a c) (comp b c) -- Split fusion law
494+comp (Fork a b) c = Fork (comp a c) (comp b c) -- Fork fusion law
495−comp c (Junc a b) = Junc (comp c a) (comp c b) -- Junc fusion law
495+comp c (Join a b) = Join (comp c a) (comp c b) -- Join fusion law
496{-# NOINLINE comp #-}
496{-# NOINLINE comp #-}
497{-# RULES
497{-# RULES
498− "comp/identity1" forall m. comp m identity = m ;
498+ "comp/iden1" forall m. comp m iden = m ;
499− "comp/identity2" forall m. comp identity m = m
499+ "comp/iden2" forall m. comp iden m = m
502-- Projections
502-- Projections
@@ -504,16 +504,16 @@ comp c (Junc a b) = Junc (comp c a) (comp c b) -- Junc fusion law
504-- | Biproduct first component projection
504-- | Biproduct first component projection
505p1 :: forall e m n. (Num e, CountableDimensions n m, FromLists e n m, FromLists e m m) => Matrix e (Either m n) m
505p1 :: forall e m n. (Num e, CountableDimensions n m, FromLists e n m, FromLists e m m) => Matrix e (Either m n) m
507− let iden = identity :: Matrix e m m
507+ let iden = iden :: Matrix e m m
508 zero = zeros :: Matrix e n m
508 zero = zeros :: Matrix e n m
509− in junc iden zero
509+ in join iden zero
511-- | Biproduct second component projection
511-- | Biproduct second component projection
512p2 :: forall e m n. (Num e, CountableDimensions n m, FromLists e m n, FromLists e n n) => Matrix e (Either m n) n
512p2 :: forall e m n. (Num e, CountableDimensions n m, FromLists e m n, FromLists e n n) => Matrix e (Either m n) n
514− let iden = identity :: Matrix e n n
514+ let iden = iden :: Matrix e n n
515 zero = zeros :: Matrix e m n
515 zero = zeros :: Matrix e m n
516− in junc zero iden
516+ in join zero iden
518-- Injections
518-- Injections
@@ -564,19 +564,19 @@ infixl 5 -|-
564 Matrix e n k ->
564 Matrix e n k ->
565 Matrix e m j ->
565 Matrix e m j ->
566 Matrix e (Either n m) (Either k j)
566 Matrix e (Either n m) (Either k j)
567−(-|-) a b = Junc (i1 . a) (i2 . b)
567+(-|-) a b = Join (i1 . a) (i2 . b)
569-- Khatri Rao Product and projections
569-- Khatri Rao Product and projections
571-- | Khatri Rao product first component projection matrix.
571-- | Khatri Rao product first component projection matrix.
573 forall e m k .
573 forall e m k .
575 CountableDimensions k m,
575 CountableDimensions k m,
576 FromLists e (Normalize (m, k)) m,
576 FromLists e (Normalize (m, k)) m,
577 CountableN (m, k)
577 CountableN (m, k)
578 ) => Matrix e (Normalize (m, k)) m
578 ) => Matrix e (Normalize (m, k)) m
579−kp1 = matrixBuilder f
579+fstM = matrixBuilder f
581 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
581 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
@@ -584,14 +584,14 @@ kp1 = matrixBuilder f
584 | otherwise = 0
584 | otherwise = 0
586-- | Khatri Rao product second component projection matrix.
586-- | Khatri Rao product second component projection matrix.
588 forall e m k .
588 forall e m k .
590 CountableDimensions k m,
590 CountableDimensions k m,
591 FromLists e (Normalize (m, k)) k,
591 FromLists e (Normalize (m, k)) k,
592 CountableN (m, k)
592 CountableN (m, k)
593 ) => Matrix e (Normalize (m, k)) k
593 ) => Matrix e (Normalize (m, k)) k
594−kp2 = matrixBuilder f
594+sndM = matrixBuilder f
596 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
596 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
@@ -603,9 +603,9 @@ kp2 = matrixBuilder f
603-- NOTE: That this is not a true categorical product, see for instance:
603-- NOTE: That this is not a true categorical product, see for instance:
606−-- | kp1 . khatri a b == a
606+-- | fstM . khatri a b == a
607-- khatri a b ==> |
607-- khatri a b ==> |
608−-- | kp2 . khatri a b == b
608+-- | sndM . khatri a b == b
611-- __Emphasis__ on the implication symbol.
611-- __Emphasis__ on the implication symbol.
@@ -618,9 +618,9 @@ khatri ::
618 FromLists e (Normalize (a, b)) b
618 FromLists e (Normalize (a, b)) b
619 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (Normalize (a, b))
619 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (Normalize (a, b))
620khatri a b =
620khatri a b =
621− let kp1' = kp1 @e @a @b
621+ let fstM' = fstM @e @a @b
622− kp2' = kp2 @e @a @b
622+ sndM' = sndM @e @a @b
623− in (tr kp1') . a * (tr kp2') . b
623+ in (tr fstM') . a * (tr sndM') . b
625-- Product Bifunctor (Kronecker)
625-- Product Bifunctor (Kronecker)
@@ -640,39 +640,39 @@ infixl 4 ><
641 => Matrix e m p -> Matrix e n q -> Matrix e (Normalize (m, n)) (Normalize (p, q))
641 => Matrix e m p -> Matrix e n q -> Matrix e (Normalize (m, n)) (Normalize (p, q))
642(><) a b =
642(><) a b =
643− let kp1' = kp1 @e @m @n
643+ let fstM' = fstM @e @m @n
644− kp2' = kp2 @e @m @n
644+ sndM' = sndM @e @m @n
645− in khatri (a . kp1') (b . kp2')
645+ in khatri (a . fstM') (b . sndM')
647−-- Matrix abide Junc Split
647+-- Matrix abide Join Fork
649−-- | Matrix "abiding" followin the 'Junc'-'Split' abide law.
649+-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
654−-- 'Junc' ('Split' a c) ('Split' b d) == 'Split' ('Junc' a b) ('Junc' c d)
654+-- 'Join' ('Fork' a c) ('Fork' b d) == 'Fork' ('Join' a b) ('Join' c d)
656abideJS :: Matrix e cols rows -> Matrix e cols rows
656abideJS :: Matrix e cols rows -> Matrix e cols rows
657−abideJS (Junc (Split a c) (Split b d)) = Split (Junc (abideJS a) (abideJS b)) (Junc (abideJS c) (abideJS d)) -- Junc-Split abide law
657+abideJS (Join (Fork a c) (Fork b d)) = Fork (Join (abideJS a) (abideJS b)) (Join (abideJS c) (abideJS d)) -- Join-Fork abide law
658abideJS Empty = Empty
658abideJS Empty = Empty
659abideJS (One e) = One e
659abideJS (One e) = One e
660−abideJS (Junc a b) = Junc (abideJS a) (abideJS b)
660+abideJS (Join a b) = Join (abideJS a) (abideJS b)
661−abideJS (Split a b) = Split (abideJS a) (abideJS b)
661+abideJS (Fork a b) = Fork (abideJS a) (abideJS b)
663−-- Matrix abide Split Junc
663+-- Matrix abide Fork Join
665−-- | Matrix "abiding" followin the 'Split'-'Junc' abide law.
665+-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
668−-- 'Split' ('Junc' a b) ('Junc' c d) == 'Junc' ('Split' a c) ('Split' b d)
668+-- 'Fork' ('Join' a b) ('Join' c d) == 'Join' ('Fork' a c) ('Fork' b d)
670abideSJ :: Matrix e cols rows -> Matrix e cols rows
670abideSJ :: Matrix e cols rows -> Matrix e cols rows
671−abideSJ (Split (Junc a b) (Junc c d)) = Junc (Split (abideSJ a) (abideSJ c)) (Split (abideSJ b) (abideSJ d)) -- Split-Junc abide law
671+abideSJ (Fork (Join a b) (Join c d)) = Join (Fork (abideSJ a) (abideSJ c)) (Fork (abideSJ b) (abideSJ d)) -- Fork-Join abide law
672abideSJ Empty = Empty
672abideSJ Empty = Empty
673abideSJ (One e) = One e
673abideSJ (One e) = One e
674−abideSJ (Junc a b) = Junc (abideSJ a) (abideSJ b)
674+abideSJ (Join a b) = Join (abideSJ a) (abideSJ b)
675−abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
675+abideSJ (Fork a b) = Fork (abideSJ a) (abideSJ b)
677-- Matrix transposition
677-- Matrix transposition
@@ -680,17 +680,17 @@ abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
680tr :: Matrix e cols rows -> Matrix e rows cols
680tr :: Matrix e cols rows -> Matrix e rows cols
681tr Empty = Empty
681tr Empty = Empty
682tr (One e) = One e
682tr (One e) = One e
683−tr (Junc a b) = Split (tr a) (tr b)
683+tr (Join a b) = Fork (tr a) (tr b)
684−tr (Split a b) = Junc (tr a) (tr b)
684+tr (Fork a b) = Join (tr a) (tr b)
686-- Selective 'select' operator
686-- Selective 'select' operator
688-- | Selective functors 'select' operator equivalent inspired by the
688-- | Selective functors 'select' operator equivalent inspired by the
689-- ArrowMonad solution presented in the paper.
689-- ArrowMonad solution presented in the paper.
690select :: (Num e, FromLists e b b, Countable b) => Matrix e cols (Either a b) -> Matrix e a b -> Matrix e cols b
690select :: (Num e, FromLists e b b, Countable b) => Matrix e cols (Either a b) -> Matrix e a b -> Matrix e cols b
691−select (Split a b) y = y . a + b -- Divide-and-conquer law
691+select (Fork a b) y = y . a + b -- Divide-and-conquer law
692−select (Junc (Split a c) (Split b d)) y = junc (y . a + c) (y . b + d) -- Pattern matching + DnC law
692+select (Join (Fork a c) (Fork b d)) y = join (y . a + c) (y . b + d) -- Pattern matching + DnC law
693−select m y = junc y identity . m
693+select m y = join y iden . m
@@ -711,7 +711,7 @@ branch x l r = f x `select` g l `select` r
712 f :: (Num e, Countable a, CountableDimensions b c, FromLists e a b, FromLists e c b, FromLists e b b, FromLists e b a, FromLists e a a)
712 f :: (Num e, Countable a, CountableDimensions b c, FromLists e a b, FromLists e c b, FromLists e b b, FromLists e b a, FromLists e a a)
713 => Matrix e cols (Either a b) -> Matrix e cols (Either a (Either b c))
713 => Matrix e cols (Either a b) -> Matrix e cols (Either a (Either b c))
714− f m = split (tr i1) (i1 . tr i2) . m
714+ f m = fork (tr i1) (i1 . tr i2) . m
715 g :: (Num e, CountableDimensions b c, FromLists e b c, FromLists e c c) => Matrix e a c -> Matrix e a (Either b c)
715 g :: (Num e, CountableDimensions b c, FromLists e b c, FromLists e c c) => Matrix e a c -> Matrix e a (Either b c)
716 g m = i2 . m
716 g m = i2 . m
@@ -731,7 +731,7 @@ cond ::
733 (a -> Bool) -> Matrix e cols rows -> Matrix e cols rows -> Matrix e cols rows
733 (a -> Bool) -> Matrix e cols rows -> Matrix e cols rows -> Matrix e cols rows
734−cond p f g = junc f g . grd p
734+cond p f g = join f g . grd p
737 ( Trivial q,
737 ( Trivial q,
@@ -746,7 +746,7 @@ grd ::
748 (a -> Bool) -> Matrix e q (Either q q)
748 (a -> Bool) -> Matrix e q (Either q q)
749−grd f = split (corr f) (corr (not . f))
749+grd f = fork (corr f) (corr (not . f))
752 forall e a q .
752 forall e a q .
@@ -758,8 +758,8 @@ corr ::
758 Liftable e a Bool
758 Liftable e a Bool
760 => (a -> Bool) -> Matrix e q q
760 => (a -> Bool) -> Matrix e q q
761−corr p = let f = fromF p :: Matrix e q ()
761+corr p = let f = fromF' p :: Matrix e q ()
762− in khatri f (identity :: Matrix e q q)
762+ in khatri f (iden :: Matrix e q q)
764-- Pretty print
764-- Pretty print
@@ -819,10 +819,10 @@ prettyPrint = putStrLn . pretty
819zipWithM :: (e -> f -> g) -> Matrix e cols rows -> Matrix f cols rows -> Matrix g cols rows
819zipWithM :: (e -> f -> g) -> Matrix e cols rows -> Matrix f cols rows -> Matrix g cols rows
820zipWithM f Empty Empty = Empty
820zipWithM f Empty Empty = Empty
821zipWithM f (One a) (One b) = One (f a b)
821zipWithM f (One a) (One b) = One (f a b)
822−zipWithM f (Junc a b) (Junc c d) = Junc (zipWithM f a c) (zipWithM f b d)
822+zipWithM f (Join a b) (Join c d) = Join (zipWithM f a c) (zipWithM f b d)
823−zipWithM f (Split a b) (Split c d) = Split (zipWithM f a c) (zipWithM f b d)
823+zipWithM f (Fork a b) (Fork c d) = Fork (zipWithM f a c) (zipWithM f b d)
824−zipWithM f x@(Split _ _) y@(Junc _ _) = zipWithM f x (abideJS y)
824+zipWithM f x@(Fork _ _) y@(Join _ _) = zipWithM f x (abideJS y)
825−zipWithM f x@(Junc _ _) y@(Split _ _) = zipWithM f (abideJS x) y
825+zipWithM f x@(Join _ _) y@(Fork _ _) = zipWithM f (abideJS x) y
827-- Relational operators functions
827-- Relational operators functions
@@ -845,51 +845,51 @@ negateM :: Relation cols rows -> Relation cols rows
845negateM Empty = Empty
845negateM Empty = Empty
846negateM (One (Nat 0)) = One (Nat 1)
846negateM (One (Nat 0)) = One (Nat 1)
847negateM (One (Nat 1)) = One (Nat 0)
847negateM (One (Nat 1)) = One (Nat 0)
848−negateM (Junc a b) = Junc (negateM a) (negateM b)
848+negateM (Join a b) = Join (negateM a) (negateM b)
849−negateM (Split a b) = Split (negateM a) (negateM b)
849+negateM (Fork a b) = Fork (negateM a) (negateM b)
851-- | Relational addition
851-- | Relational addition
852orM :: Relation cols rows -> Relation cols rows -> Relation cols rows
852orM :: Relation cols rows -> Relation cols rows -> Relation cols rows
853orM Empty Empty = Empty
853orM Empty Empty = Empty
854orM (One a) (One b) = One (fromBool (toBool a || toBool b))
854orM (One a) (One b) = One (fromBool (toBool a || toBool b))
855−orM (Junc a b) (Junc c d) = Junc (orM a c) (orM b d)
855+orM (Join a b) (Join c d) = Join (orM a c) (orM b d)
856−orM (Split a b) (Split c d) = Split (orM a c) (orM b d)
856+orM (Fork a b) (Fork c d) = Fork (orM a c) (orM b d)
857−orM x@(Split _ _) y@(Junc _ _) = orM x (abideJS y)
857+orM x@(Fork _ _) y@(Join _ _) = orM x (abideJS y)
858−orM x@(Junc _ _) y@(Split _ _) = orM (abideJS x) y
858+orM x@(Join _ _) y@(Fork _ _) = orM (abideJS x) y
860-- | Relational multiplication
860-- | Relational multiplication
861andM :: Relation cols rows -> Relation cols rows -> Relation cols rows
861andM :: Relation cols rows -> Relation cols rows -> Relation cols rows
862andM Empty Empty = Empty
862andM Empty Empty = Empty
863andM (One a) (One b) = One (fromBool (toBool a && toBool b))
863andM (One a) (One b) = One (fromBool (toBool a && toBool b))
864−andM (Junc a b) (Junc c d) = Junc (andM a c) (andM b d)
864+andM (Join a b) (Join c d) = Join (andM a c) (andM b d)
865−andM (Split a b) (Split c d) = Split (andM a c) (andM b d)
865+andM (Fork a b) (Fork c d) = Fork (andM a c) (andM b d)
866−andM x@(Split _ _) y@(Junc _ _) = andM x (abideJS y)
866+andM x@(Fork _ _) y@(Join _ _) = andM x (abideJS y)
867−andM x@(Junc _ _) y@(Split _ _) = andM (abideJS x) y
867+andM x@(Join _ _) y@(Fork _ _) = andM (abideJS x) y
869-- | Relational subtraction
869-- | Relational subtraction
870subM :: Relation cols rows -> Relation cols rows -> Relation cols rows
870subM :: Relation cols rows -> Relation cols rows -> Relation cols rows
871subM Empty Empty = Empty
871subM Empty Empty = Empty
872subM (One a) (One b) = if a - b < nat 0 then One (nat 0) else One (a - b)
872subM (One a) (One b) = if a - b < nat 0 then One (nat 0) else One (a - b)
873−subM (Junc a b) (Junc c d) = Junc (subM a c) (subM b d)
873+subM (Join a b) (Join c d) = Join (subM a c) (subM b d)
874−subM (Split a b) (Split c d) = Split (subM a c) (subM b d)
874+subM (Fork a b) (Fork c d) = Fork (subM a c) (subM b d)
875−subM x@(Split _ _) y@(Junc _ _) = subM x (abideJS y)
875+subM x@(Fork _ _) y@(Join _ _) = subM x (abideJS y)
876−subM x@(Junc _ _) y@(Split _ _) = subM (abideJS x) y
876+subM x@(Join _ _) y@(Fork _ _) = subM (abideJS x) y
878-- | Matrix relational composition.
878-- | Matrix relational composition.
879compRel :: Relation cr rows -> Relation cols cr -> Relation cols rows
879compRel :: Relation cr rows -> Relation cols cr -> Relation cols rows
880compRel Empty Empty = Empty
880compRel Empty Empty = Empty
881compRel (One a) (One b) = One (fromBool (toBool a && toBool b))
881compRel (One a) (One b) = One (fromBool (toBool a && toBool b))
882−compRel (Junc a b) (Split c d) = orM (compRel a c) (compRel b d) -- Divide-and-conquer law
882+compRel (Join a b) (Fork c d) = orM (compRel a c) (compRel b d) -- Divide-and-conquer law
883−compRel (Split a b) c = Split (compRel a c) (compRel b c) -- Split fusion law
883+compRel (Fork a b) c = Fork (compRel a c) (compRel b c) -- Fork fusion law
884−compRel c (Junc a b) = Junc (compRel c a) (compRel c b) -- Junc fusion law
884+compRel c (Join a b) = Join (compRel c a) (compRel c b) -- Join fusion law
886-- | Matrix relational right division
886-- | Matrix relational right division
887divR :: Relation b c -> Relation b a -> Relation a c
887divR :: Relation b c -> Relation b a -> Relation a c
888divR Empty Empty = Empty
888divR Empty Empty = Empty
889divR (One a) (One b) = One (fromBool (not (toBool b) || toBool a)) -- b implies a
889divR (One a) (One b) = One (fromBool (not (toBool b) || toBool a)) -- b implies a
890−divR (Junc a b) (Junc c d) = andM (divR a c) (divR b d)
890+divR (Join a b) (Join c d) = andM (divR a c) (divR b d)
891−divR (Split a b) c = Split (divR a c) (divR b c)
891+divR (Fork a b) c = Fork (divR a c) (divR b c)
892−divR c (Split a b) = Junc (divR c a) (divR c b)
892+divR c (Fork a b) = Join (divR c a) (divR c b)
894-- | Matrix relational left division
894-- | Matrix relational left division
895divL :: Relation c b -> Relation a b -> Relation a c
895divL :: Relation c b -> Relation a b -> Relation a c
@@ -905,7 +905,7 @@ divS s r = divL r s `intersection` divR (tr r) (tr s)
906-- NOTE: Be careful to not ask for a relation bigger than the cardinality of
906-- NOTE: Be careful to not ask for a relation bigger than the cardinality of
907-- types @a@ or @b@ allows.
907-- types @a@ or @b@ allows.
908−fromFRel ::
908+fromFRel' ::
909 forall a b cols rows.
909 forall a b cols rows.
910 ( Liftable Boolean a b,
910 ( Liftable Boolean a b,
911 CountableDimensions cols rows,
911 CountableDimensions cols rows,
@@ -913,7 +913,7 @@ fromFRel ::
914 (a -> b) ->
914 (a -> b) ->
915 Relation cols rows
915 Relation cols rows
916−fromFRel f =
916+fromFRel' f =
917 let minA = minBound @a
917 let minA = minBound @a
918 maxA = maxBound @a
918 maxA = maxBound @a
919 minB = minBound @b
919 minB = minBound @b
@@ -934,7 +934,7 @@ fromFRel f =
935-- | Lifts functions to relations with dimensions matching @a@ and @b@
935-- | Lifts functions to relations with dimensions matching @a@ and @b@
936-- cardinality's.
936-- cardinality's.
937−fromFRel' ::
937+fromFRel ::
938 forall a b.
938 forall a b.
939 ( Liftable Boolean a b,
939 ( Liftable Boolean a b,
940 CountableDimensionsN a b,
940 CountableDimensionsN a b,
@@ -942,7 +942,7 @@ fromFRel' ::
943 (a -> b) ->
943 (a -> b) ->
944 Relation (Normalize a) (Normalize b)
944 Relation (Normalize a) (Normalize b)
945−fromFRel' f =
945+fromFRel f =
946 let minA = minBound @a
946 let minA = minBound @a
947 maxA = maxBound @a
947 maxA = maxBound @a
948 minB = minBound @b
948 minB = minBound @b