@@ -52,8 +52,8 @@ module LAoP.Matrix.Internal
5252 -- * Primitives
5353 empty,
5454 one,
55− junc,
56− split,
55+ join,
56+ fork,
5757
5858 -- * Auxiliary type families
5959 FromNat,
@@ -96,12 +96,12 @@ module LAoP.Matrix.Internal
9696 zipWithM,
9797
9898 -- * Biproduct approach
99− -- ** Split
99+ -- ** Fork
100100 (===),
101101 -- *** Projections
102102 p1,
103103 p2,
104− -- ** Junc
104+ -- ** Join
105105 (|||),
106106 -- *** Injections
107107 i1,
@@ -115,8 +115,8 @@ module LAoP.Matrix.Internal
115115 -- | Note that given the restrictions imposed it is not possible to
116116 -- implement the standard type classes present in standard Haskell.
117117 -- *** Matrix pairing projections
118− kp1,
119− kp2,
118+ fstM,
119+ sndM,
120120
121121 -- *** Matrix pairing
122122 khatri,
@@ -127,10 +127,10 @@ module LAoP.Matrix.Internal
127127
128128 -- | Note that given the restrictions imposed it is not possible to
129129 -- implement the standard type classes present in standard Haskell.
130− identity,
130+ iden,
131131 comp,
132− fromF,
133132 fromF',
133+ fromF,
134134
135135 -- * Matrix printing
136136 pretty,
@@ -171,8 +171,8 @@ import Prelude hiding ((.))
171171data Matrix e cols rows where
172172 Empty :: Matrix e Void Void
173173 One :: e -> Matrix e () ()
174− Junc :: 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)
174+ Join :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
175+ Fork :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
176176
177177deriving instance (Show e) => Show (Matrix e cols rows)
178178
@@ -226,7 +226,7 @@ type Trivial a = FromNat (Count a) ~ a
226226-- implementation is 'undefined'. However 'comp' can be and this partial
227227-- class implementation exists just to make the code more readable.
228228--
229−-- Please use 'identity' instead.
229+-- Please use 'iden' instead.
230230instance (Num e) => Category (Matrix e) where
231231 id = undefined
232232 (.) = comp
@@ -234,16 +234,16 @@ instance (Num e) => Category (Matrix e) where
234234instance NFData e => NFData (Matrix e cols rows) where
235235 rnf Empty = ()
236236 rnf (One e) = rnf e
237− rnf (Junc a b) = rnf a `seq` rnf b
238− rnf (Split a b) = rnf a `seq` rnf b
237+ rnf (Join a b) = rnf a `seq` rnf b
238+ rnf (Fork a b) = rnf a `seq` rnf b
239239
240240instance Eq e => Eq (Matrix e cols rows) where
241241 Empty == Empty = True
242242 (One a) == (One b) = a == b
243− (Junc a b) == (Junc c d) = a == c && b == d
244− (Split a b) == (Split c d) = a == c && b == d
245− x@(Split _ _) == y@(Junc _ _) = x == abideJS y
246− x@(Junc _ _) == y@(Split _ _) = abideJS x == y
243+ (Join a b) == (Join c d) = a == c && b == d
244+ (Fork a b) == (Fork c d) = a == c && b == d
245+ x@(Fork _ _) == y@(Join _ _) = x == abideJS y
246+ x@(Join _ _) == y@(Fork _ _) = abideJS x == y
247247
248248instance Num e => Num (Matrix e cols rows) where
249249
@@ -255,21 +255,21 @@ instance Num e => Num (Matrix e cols rows) where
255255
256256 abs Empty = Empty
257257 abs (One a) = One (abs a)
258− abs (Junc a b) = Junc (abs a) (abs b)
259− abs (Split a b) = Split (abs a) (abs b)
258+ abs (Join a b) = Join (abs a) (abs b)
259+ abs (Fork a b) = Fork (abs a) (abs b)
260260
261261 signum Empty = Empty
262262 signum (One a) = One (signum a)
263− signum (Junc a b) = Junc (signum a) (signum b)
264− signum (Split a b) = Split (signum a) (signum b)
263+ signum (Join a b) = Join (signum a) (signum b)
264+ signum (Fork a b) = Fork (signum a) (signum b)
265265
266266instance Ord e => Ord (Matrix e cols rows) where
267267 Empty <= Empty = True
268268 (One a) <= (One b) = a <= b
269− (Junc a b) <= (Junc c d) = (a <= c) && (b <= d)
270− (Split a b) <= (Split c d) = (a <= c) && (b <= d)
271− x@(Split _ _) <= y@(Junc _ _) = x <= abideJS y
272− x@(Junc _ _) <= y@(Split _ _) = abideJS x <= y
269+ (Join a b) <= (Join c d) = (a <= c) && (b <= d)
270+ (Fork a b) <= (Fork c d) = (a <= c) && (b <= d)
271+ x@(Fork _ _) <= y@(Join _ _) = x <= abideJS y
272+ x@(Join _ _) <= y@(Fork _ _) = abideJS x <= y
273273
274274-- Primitives
275275
@@ -281,25 +281,25 @@ empty = Empty
281281one :: e -> Matrix e () ()
282282one = One
283283
284−-- | Matrix 'Junc' constructor
285−junc :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
286−junc = Junc
284+-- | Matrix 'Join' constructor
285+join :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
286+join = Join
287287
288288infixl 3 |||
289289
290−-- | Matrix 'Junc' constructor
290+-- | Matrix 'Join' constructor
291291(|||) :: Matrix e a rows -> Matrix e b rows -> Matrix e (Either a b) rows
292−(|||) = Junc
292+(|||) = Join
293293
294−-- | Matrix 'Split' constructor
295−split :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
296−split = Split
294+-- | Matrix 'Fork' constructor
295+fork :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
296+fork = Fork
297297
298298infixl 2 ===
299299
300−-- | Matrix 'Split' constructor
300+-- | Matrix 'Fork' constructor
301301(===) :: Matrix e cols a -> Matrix e cols b -> Matrix e cols (Either a b)
302−(===) = Split
302+(===) = Fork
303303
304304-- Construction
305305
@@ -321,23 +321,23 @@ instance {-# OVERLAPPING #-} FromLists e () () where
321321 fromLists _ = error "Wrong dimensions"
322322
323323instance {-# 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])
325325 fromLists _ = error "Wrong dimensions"
326326
327327instance {-# OVERLAPPABLE #-} (FromLists e a (), FromLists e b (), Countable a) => FromLists e (Either a b) () where
328328 fromLists [l] =
329329 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])
331331 fromLists _ = error "Wrong dimensions"
332332
333333instance {-# 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)
335335 fromLists _ = error "Wrong dimensions"
336336
337337instance {-# OVERLAPPABLE #-} (FromLists e () a, FromLists e () b, Countable a) => FromLists e () (Either a b) where
338338 fromLists l@([_] : _) =
339339 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))
341341 fromLists _ = error "Wrong dimensions"
342342
343343instance {-# 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
346346 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
347347 condition = all (== lh) (map length t)
348348 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))
350350 else error "Not all rows have the same length"
351351
352352-- | Matrix builder function. Constructs a matrix provided with
@@ -376,7 +376,7 @@ row = fromLists . (: [])
376376--
377377-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
378378-- types @a@ or @b@ allows.
379−fromF ::
379+fromF' ::
380380 forall a b cols rows e.
381381 ( Liftable e a b,
382382 CountableDimensions cols rows,
@@ -384,7 +384,7 @@ fromF ::
384384 ) =>
385385 (a -> b) ->
386386 Matrix e cols rows
387−fromF f =
387+fromF' f =
388388 let minA = minBound @a
389389 maxA = maxBound @a
390390 minB = minBound @b
@@ -405,7 +405,7 @@ fromF f =
405405
406406-- | Lifts functions to matrices with dimensions matching @a@ and @b@
407407-- cardinality's.
408−fromF' ::
408+fromF ::
409409 forall a b e.
410410 ( Liftable e a b,
411411 CountableDimensionsN a b,
@@ -413,7 +413,7 @@ fromF' ::
413413 ) =>
414414 (a -> b) ->
415415 Matrix e (Normalize a) (Normalize b)
416−fromF' f =
416+fromF f =
417417 let minA = minBound @a
418418 maxA = maxBound @a
419419 minB = minBound @b
@@ -438,8 +438,8 @@ fromF' f =
438438toLists :: Matrix e cols rows -> [[e]]
439439toLists Empty = []
440440toLists (One e) = [[e]]
441−toLists (Split l r) = toLists l ++ toLists r
442−toLists (Junc l r) = zipWith (++) (toLists l) (toLists r)
441+toLists (Fork l r) = toLists l ++ toLists r
442+toLists (Join l r) = zipWith (++) (toLists l) (toLists r)
443443
444444-- | Converts a matrix to a list of elements.
445445toList :: Matrix e cols rows -> [e]
@@ -474,12 +474,12 @@ bang =
474474 let c = fromInteger $ natVal (Proxy :: Proxy (Count cols))
475475 in fromLists [take c [1, 1 ..]]
476476
477−-- Identity Matrix
477+-- iden Matrix
478478
479−-- | Identity matrix.
480−identity :: (Num e, FromLists e cols cols, Countable cols) => Matrix e cols cols
481−identity = matrixBuilder (bool 0 1 . uncurry (==))
482−{-# NOINLINE identity #-}
479+-- | iden matrix.
480+iden :: (Num e, FromLists e cols cols, Countable cols) => Matrix e cols cols
481+iden = matrixBuilder (bool 0 1 . uncurry (==))
482+{-# NOINLINE iden #-}
483483
484484-- Matrix composition (MMM)
485485
@@ -490,13 +490,13 @@ identity = matrixBuilder (bool 0 1 . uncurry (==))
490490comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
491491comp Empty Empty = Empty
492492comp (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
494−comp (Split a b) c = Split (comp a c) (comp b c) -- Split fusion law
495−comp c (Junc a b) = Junc (comp c a) (comp c b) -- Junc fusion law
493+comp (Join a b) (Fork c d) = comp a c + comp b d -- Divide-and-conquer law
494+comp (Fork a b) c = Fork (comp a c) (comp b c) -- Fork fusion law
495+comp c (Join a b) = Join (comp c a) (comp c b) -- Join fusion law
496496{-# NOINLINE comp #-}
497497{-# RULES
498− "comp/identity1" forall m. comp m identity = m ;
499− "comp/identity2" forall m. comp identity m = m
498+ "comp/iden1" forall m. comp m iden = m ;
499+ "comp/iden2" forall m. comp iden m = m
500500#-}
501501
502502-- Projections
@@ -504,16 +504,16 @@ comp c (Junc a b) = Junc (comp c a) (comp c b) -- Junc fusion law
504504-- | Biproduct first component projection
505505p1 :: forall e m n. (Num e, CountableDimensions n m, FromLists e n m, FromLists e m m) => Matrix e (Either m n) m
506506p1 =
507− let iden = identity :: Matrix e m m
507+ let iden = iden :: Matrix e m m
508508 zero = zeros :: Matrix e n m
509− in junc iden zero
509+ in join iden zero
510510
511511-- | Biproduct second component projection
512512p2 :: forall e m n. (Num e, CountableDimensions n m, FromLists e m n, FromLists e n n) => Matrix e (Either m n) n
513513p2 =
514− let iden = identity :: Matrix e n n
514+ let iden = iden :: Matrix e n n
515515 zero = zeros :: Matrix e m n
516− in junc zero iden
516+ in join zero iden
517517
518518-- Injections
519519
@@ -564,19 +564,19 @@ infixl 5 -|-
564564 Matrix e n k ->
565565 Matrix e m j ->
566566 Matrix e (Either n m) (Either k j)
567−(-|-) a b = Junc (i1 . a) (i2 . b)
567+(-|-) a b = Join (i1 . a) (i2 . b)
568568
569569-- Khatri Rao Product and projections
570570
571571-- | Khatri Rao product first component projection matrix.
572−kp1 ::
572+fstM ::
573573 forall e m k .
574574 ( Num e,
575575 CountableDimensions k m,
576576 FromLists e (Normalize (m, k)) m,
577577 CountableN (m, k)
578578 ) => Matrix e (Normalize (m, k)) m
579−kp1 = matrixBuilder f
579+fstM = matrixBuilder f
580580 where
581581 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
582582 f (x, y)
@@ -584,14 +584,14 @@ kp1 = matrixBuilder f
584584 | otherwise = 0
585585
586586-- | Khatri Rao product second component projection matrix.
587−kp2 ::
587+sndM ::
588588 forall e m k .
589589 ( Num e,
590590 CountableDimensions k m,
591591 FromLists e (Normalize (m, k)) k,
592592 CountableN (m, k)
593593 ) => Matrix e (Normalize (m, k)) k
594−kp2 = matrixBuilder f
594+sndM = matrixBuilder f
595595 where
596596 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
597597 f (x, y)
@@ -603,9 +603,9 @@ kp2 = matrixBuilder f
603603-- NOTE: That this is not a true categorical product, see for instance:
604604--
605605-- @
606−-- | kp1 . khatri a b == a
606+-- | fstM . khatri a b == a
607607-- khatri a b ==> |
608−-- | kp2 . khatri a b == b
608+-- | sndM . khatri a b == b
609609-- @
610610--
611611-- __Emphasis__ on the implication symbol.
@@ -618,9 +618,9 @@ khatri ::
618618 FromLists e (Normalize (a, b)) b
619619 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (Normalize (a, b))
620620khatri a b =
621− let kp1' = kp1 @e @a @b
622− kp2' = kp2 @e @a @b
623− in (tr kp1') . a * (tr kp2') . b
621+ let fstM' = fstM @e @a @b
622+ sndM' = sndM @e @a @b
623+ in (tr fstM') . a * (tr sndM') . b
624624
625625-- Product Bifunctor (Kronecker)
626626
@@ -640,39 +640,39 @@ infixl 4 ><
640640 )
641641 => Matrix e m p -> Matrix e n q -> Matrix e (Normalize (m, n)) (Normalize (p, q))
642642(><) a b =
643− let kp1' = kp1 @e @m @n
644− kp2' = kp2 @e @m @n
645− in khatri (a . kp1') (b . kp2')
643+ let fstM' = fstM @e @m @n
644+ sndM' = sndM @e @m @n
645+ in khatri (a . fstM') (b . sndM')
646646
647−-- Matrix abide Junc Split
647+-- Matrix abide Join Fork
648648
649−-- | Matrix "abiding" followin the 'Junc'-'Split' abide law.
649+-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
650650--
651651-- Law:
652652--
653653-- @
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)
655655-- @
656656abideJS :: 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
658658abideJS Empty = Empty
659659abideJS (One e) = One e
660−abideJS (Junc a b) = Junc (abideJS a) (abideJS b)
661−abideJS (Split a b) = Split (abideJS a) (abideJS b)
660+abideJS (Join a b) = Join (abideJS a) (abideJS b)
661+abideJS (Fork a b) = Fork (abideJS a) (abideJS b)
662662
663−-- Matrix abide Split Junc
663+-- Matrix abide Fork Join
664664
665−-- | Matrix "abiding" followin the 'Split'-'Junc' abide law.
665+-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
666666--
667667-- @
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)
669669-- @
670670abideSJ :: 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
672672abideSJ Empty = Empty
673673abideSJ (One e) = One e
674−abideSJ (Junc a b) = Junc (abideSJ a) (abideSJ b)
675−abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
674+abideSJ (Join a b) = Join (abideSJ a) (abideSJ b)
675+abideSJ (Fork a b) = Fork (abideSJ a) (abideSJ b)
676676
677677-- Matrix transposition
678678
@@ -680,17 +680,17 @@ abideSJ (Split a b) = Split (abideSJ a) (abideSJ b)
680680tr :: Matrix e cols rows -> Matrix e rows cols
681681tr Empty = Empty
682682tr (One e) = One e
683−tr (Junc a b) = Split (tr a) (tr b)
684−tr (Split a b) = Junc (tr a) (tr b)
683+tr (Join a b) = Fork (tr a) (tr b)
684+tr (Fork a b) = Join (tr a) (tr b)
685685
686686-- Selective 'select' operator
687687
688688-- | Selective functors 'select' operator equivalent inspired by the
689689-- ArrowMonad solution presented in the paper.
690690select :: (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
692−select (Junc (Split a c) (Split b d)) y = junc (y . a + c) (y . b + d) -- Pattern matching + DnC law
693−select m y = junc y identity . m
691+select (Fork a b) y = y . a + b -- Divide-and-conquer 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 = join y iden . m
694694
695695branch ::
696696 ( Num e,
@@ -711,7 +711,7 @@ branch x l r = f x `select` g l `select` r
711711 where
712712 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)
713713 => 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
715715 g :: (Num e, CountableDimensions b c, FromLists e b c, FromLists e c c) => Matrix e a c -> Matrix e a (Either b c)
716716 g m = i2 . m
717717
@@ -731,7 +731,7 @@ cond ::
731731 )
732732 =>
733733 (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
735735
736736grd ::
737737 ( Trivial q,
@@ -746,7 +746,7 @@ grd ::
746746 )
747747 =>
748748 (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))
750750
751751corr ::
752752 forall e a q .
@@ -758,8 +758,8 @@ corr ::
758758 Liftable e a Bool
759759 )
760760 => (a -> Bool) -> Matrix e q q
761−corr p = let f = fromF p :: Matrix e q ()
762− in khatri f (identity :: Matrix e q q)
761+corr p = let f = fromF' p :: Matrix e q ()
762+ in khatri f (iden :: Matrix e q q)
763763
764764-- Pretty print
765765
@@ -819,10 +819,10 @@ prettyPrint = putStrLn . pretty
819819zipWithM :: (e -> f -> g) -> Matrix e cols rows -> Matrix f cols rows -> Matrix g cols rows
820820zipWithM f Empty Empty = Empty
821821zipWithM 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)
823−zipWithM f (Split a b) (Split c d) = Split (zipWithM f a c) (zipWithM f b d)
824−zipWithM f x@(Split _ _) y@(Junc _ _) = zipWithM f x (abideJS y)
825−zipWithM f x@(Junc _ _) y@(Split _ _) = zipWithM f (abideJS x) y
822+zipWithM f (Join a b) (Join c d) = Join (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@(Fork _ _) y@(Join _ _) = zipWithM f x (abideJS y)
825+zipWithM f x@(Join _ _) y@(Fork _ _) = zipWithM f (abideJS x) y
826826
827827-- Relational operators functions
828828
@@ -845,51 +845,51 @@ negateM :: Relation cols rows -> Relation cols rows
845845negateM Empty = Empty
846846negateM (One (Nat 0)) = One (Nat 1)
847847negateM (One (Nat 1)) = One (Nat 0)
848−negateM (Junc a b) = Junc (negateM a) (negateM b)
849−negateM (Split a b) = Split (negateM a) (negateM b)
848+negateM (Join a b) = Join (negateM a) (negateM b)
849+negateM (Fork a b) = Fork (negateM a) (negateM b)
850850
851851-- | Relational addition
852852orM :: Relation cols rows -> Relation cols rows -> Relation cols rows
853853orM Empty Empty = Empty
854854orM (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)
856−orM (Split a b) (Split c d) = Split (orM a c) (orM b d)
857−orM x@(Split _ _) y@(Junc _ _) = orM x (abideJS y)
858−orM x@(Junc _ _) y@(Split _ _) = orM (abideJS x) y
855+orM (Join a b) (Join c d) = Join (orM a c) (orM b d)
856+orM (Fork a b) (Fork c d) = Fork (orM a c) (orM b d)
857+orM x@(Fork _ _) y@(Join _ _) = orM x (abideJS y)
858+orM x@(Join _ _) y@(Fork _ _) = orM (abideJS x) y
859859
860860-- | Relational multiplication
861861andM :: Relation cols rows -> Relation cols rows -> Relation cols rows
862862andM Empty Empty = Empty
863863andM (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)
865−andM (Split a b) (Split c d) = Split (andM a c) (andM b d)
866−andM x@(Split _ _) y@(Junc _ _) = andM x (abideJS y)
867−andM x@(Junc _ _) y@(Split _ _) = andM (abideJS x) y
864+andM (Join a b) (Join c d) = Join (andM a c) (andM b d)
865+andM (Fork a b) (Fork c d) = Fork (andM a c) (andM b d)
866+andM x@(Fork _ _) y@(Join _ _) = andM x (abideJS y)
867+andM x@(Join _ _) y@(Fork _ _) = andM (abideJS x) y
868868
869869-- | Relational subtraction
870870subM :: Relation cols rows -> Relation cols rows -> Relation cols rows
871871subM Empty Empty = Empty
872872subM (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)
874−subM (Split a b) (Split c d) = Split (subM a c) (subM b d)
875−subM x@(Split _ _) y@(Junc _ _) = subM x (abideJS y)
876−subM x@(Junc _ _) y@(Split _ _) = subM (abideJS x) y
873+subM (Join a b) (Join c d) = Join (subM a c) (subM b d)
874+subM (Fork a b) (Fork c d) = Fork (subM a c) (subM b d)
875+subM x@(Fork _ _) y@(Join _ _) = subM x (abideJS y)
876+subM x@(Join _ _) y@(Fork _ _) = subM (abideJS x) y
877877
878878-- | Matrix relational composition.
879879compRel :: Relation cr rows -> Relation cols cr -> Relation cols rows
880880compRel Empty Empty = Empty
881881compRel (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
883−compRel (Split a b) c = Split (compRel a c) (compRel b c) -- Split fusion law
884−compRel c (Junc a b) = Junc (compRel c a) (compRel c b) -- Junc fusion law
882+compRel (Join a b) (Fork c d) = orM (compRel a c) (compRel b d) -- Divide-and-conquer law
883+compRel (Fork a b) c = Fork (compRel a c) (compRel b c) -- Fork fusion law
884+compRel c (Join a b) = Join (compRel c a) (compRel c b) -- Join fusion law
885885
886886-- | Matrix relational right division
887887divR :: Relation b c -> Relation b a -> Relation a c
888888divR Empty Empty = Empty
889889divR (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)
891−divR (Split a b) c = Split (divR a c) (divR b c)
892−divR c (Split a b) = Junc (divR c a) (divR c b)
890+divR (Join a b) (Join c d) = andM (divR a c) (divR b d)
891+divR (Fork a b) c = Fork (divR a c) (divR b c)
892+divR c (Fork a b) = Join (divR c a) (divR c b)
893893
894894-- | Matrix relational left division
895895divL :: 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)
905905--
906906-- NOTE: Be careful to not ask for a relation bigger than the cardinality of
907907-- types @a@ or @b@ allows.
908−fromFRel ::
908+fromFRel' ::
909909 forall a b cols rows.
910910 ( Liftable Boolean a b,
911911 CountableDimensions cols rows,
@@ -913,7 +913,7 @@ fromFRel ::
913913 ) =>
914914 (a -> b) ->
915915 Relation cols rows
916−fromFRel f =
916+fromFRel' f =
917917 let minA = minBound @a
918918 maxA = maxBound @a
919919 minB = minBound @b
@@ -934,7 +934,7 @@ fromFRel f =
934934
935935-- | Lifts functions to relations with dimensions matching @a@ and @b@
936936-- cardinality's.
937−fromFRel' ::
937+fromFRel ::
938938 forall a b.
939939 ( Liftable Boolean a b,
940940 CountableDimensionsN a b,
@@ -942,7 +942,7 @@ fromFRel' ::
942942 ) =>
943943 (a -> b) ->
944944 Relation (Normalize a) (Normalize b)
945−fromFRel' f =
945+fromFRel f =
946946 let minA = minBound @a
947947 maxA = maxBound @a
948948 minB = minBound @b