on master help sign in
Renamed:

Junc -> Join Split -> Fork kp1 -> fstM kp2 -> sndM identity -> iden fromF' -> fromF fromF -> fromF' (Relation) p1 -> fstR p2 -> fstR fromFRel' -> fromFRel fromFRel -> fromFRel'

commit399c1028b120b05925ce6f73534626f1a6eaed3e authorArmando Santos <armandoifsantos@gmail.com> dateThu 20 Feb 2020, 15:09 (7 years ago) parent63abc15
10 files changed+320−292
app/Benchmarks.hs+5−5 app/Examples.hs+10−10 app/Quantum.hs+28 app/Spreadsheets.hs+1−1 src/LAoP/Dist/Internal.hs+1−1 src/LAoP/Matrix/Internal.hs+123−123 src/LAoP/Matrix/Nat.hs+34−34 src/LAoP/Matrix/Type.hs+51−51 src/LAoP/Relation.hs+5−5 src/LAoP/Relation/Internal.hs+62−62
app/Benchmarks.hs+5−5
@@ -28,16 +28,16 @@ selectM2 ::
2828 T.FromListsN e b b,
2929 CountableN b
3030 ) => Matrix e cols (Either a b) -> Matrix e a b -> Matrix e cols b
31−selectM2 m y = junc y identity `comp` m
31+selectM2 m y = join y iden `comp` m
3232
3333selectD2 ::
3434 ( FromListsN b b,
3535 CountableN b
3636 ) => Dist (Either a b) -> Matrix Prob a b -> Dist b
37−selectD2 (D d) m = D (junc m identity `comp` d)
37+selectD2 (D d) m = D (join m iden `comp` d)
3838
39−-- Composition with identity
40−compId m = comp identity m
39+-- Composition with iden
40+compId m = comp iden m
4141
4242randomDist :: forall a . (Countable a, FromListsN () a) => Gen (Dist a)
4343randomDist = do
@@ -162,7 +162,7 @@ benchmark = defaultMain [
162162 , bench "NF - 200x200" $ nf (comp m31) m32
163163 ],
164164 bgroup "200x200 - RULES" [
165− bench "No rules - 200x200" $ nf (comp m21) identity
165+ bench "No rules - 200x200" $ nf (comp m21) iden
166166 , bench "Rules - 200x200" $ nf compId m21
167167 ] ],
168168 env setupEnv2 $ \ ~(m21, m40, dist, dist2, dl1, dl2) -> bgroup "Matrix vs List - `select`" [
app/Examples.hs+10−10
@@ -32,7 +32,7 @@ firstChoice :: Matrix Double () Outcome
3232firstChoice = col [1/3, 2/3]
3333
3434secondChoice :: Matrix Double Outcome Outcome
35−secondChoice = fromF' switch
35+secondChoice = fromF switch
3636
3737-- Dice sum
3838
@@ -41,7 +41,7 @@ type SS = Natural 1 6 -- Sample Space
4141sumSS :: SS -> SS -> Natural 2 12
4242sumSS = coerceNat (+)
4343
44−sumSSM = fromF' (uncurry sumSS)
44+sumSSM = fromF (uncurry sumSS)
4545
4646condition :: (Int, Int) -> Int -> Int
4747condition (fst, snd) thrd = if fst == snd
@@ -51,7 +51,7 @@ condition (fst, snd) thrd = if fst == snd
5151conditionSS :: (SS, SS) -> SS -> Natural 3 18
5252conditionSS = coerceNat2 condition
5353
54−conditionalThrows = fromF' (uncurry conditionSS) . khatri (khatri die die) die
54+conditionalThrows = fromF (uncurry conditionSS) . khatri (khatri die die) die
5555
5656die :: Matrix Double () SS
5757die = col $ map (const (1/6)) [nat @1 @6 1 .. nat 6]
@@ -75,15 +75,15 @@ sprinkler = fromLists [[0.6, 0.99], [0.4, 0.01]]
7575grass :: Matrix Double (S, R) G
7676grass = fromLists [[1, 0.2, 0.1, 0.01], [0, 0.8, 0.9, 0.99]]
7777
78−tag f = khatri f identity
78+tag f = khatri f iden
7979
8080state g s r = tag g `comp` tag s `comp` r
8181
8282grass_wet :: Matrix Double () (G, (S, R)) -> Matrix Double One One
83−grass_wet state = row [0,1] . kp1 . state
83+grass_wet state = row [0,1] . fstM . state
8484
8585rainning :: Matrix Double (G, (S, R)) One
86−rainning = row [0,1] . kp2 . kp2
86+rainning = row [0,1] . sndM . sndM
8787
8888-- Alcuin Puzzle
8989
@@ -106,21 +106,21 @@ cross LeftB = RightB
106106cross RightB = LeftB
107107
108108crossR :: R.Relation Bank Bank
109−crossR = R.fromF' cross
109+crossR = R.fromF cross
110110
111111-- | Initial state, everyone in the left bank
112112locationLeft :: Being -> Bank
113113locationLeft _ = LeftB
114114
115115locationLeftR :: R.Relation Being Bank
116−locationLeftR = R.fromF' locationLeft
116+locationLeftR = R.fromF locationLeft
117117
118118-- | Initial state, everyone in the right bank
119119locationRight :: Being -> Bank
120120locationRight _ = RightB
121121
122122locationRightR :: R.Relation Being Bank
123−locationRightR = R.fromF' locationRight
123+locationRightR = R.fromF locationRight
124124
125125-- Properties
126126
@@ -137,7 +137,7 @@ inv :: R.Relation Being Bank -> Bool
137137inv w = (w `R.comp` canEat w) `R.sse` (w `R.comp` farmer)
138138 where
139139 farmer :: R.Relation Being Being
140− farmer = R.fromF' (const Farmer)
140+ farmer = R.fromF (const Farmer)
141141
142142-- Arbitrary state
143143bankState :: Being -> Bank -> Bool
app/Quantum.hsnew file+28
@@ -0,0 +1,28 @@
1+{-# LANGUAGE StandaloneDeriving #-}
2+module Quantum where
3+
4+import LAoP.Matrix.Type
5+import Data.Complex
6+
7+deriving instance Ord a => Ord (Complex a)
8+
9+xor :: (Bool, Bool) -> Bool
10+xor (False, b) = b
11+xor (True, b) = not b
12+
13+ker :: Num e => Matrix e a b -> Matrix e a a
14+ker m = tr m `comp` m
15+
16+cnot :: Matrix (Complex Double) (Bool, Bool) (Bool, Bool)
17+cnot = khatri fstM (fromF xor)
18+
19+ccnot :: Matrix (Complex Double) ((Bool, Bool), Bool) ((Bool, Bool), Bool)
20+ccnot = khatri fstM (fromF f)
21+ where
22+ f = xor . (tp (uncurry (&&)) id)
23+ tp f g (a,b) = (f a, g b)
24+
25+had :: Matrix (Complex Double) Bool Bool
26+had = fromLists l
27+ where
28+ l = map (map (*(1/sqrt 2))) [[1, 1], [1, -1]]
app/Spreadsheets.hs+1−1
@@ -35,7 +35,7 @@ xls :: Matrix Float Question One
3535 -> Matrix Float Question Student
3636 -> Matrix Float Student One
3737 -> Matrix Float (Either Question Results) (Either One Student)
38−xls w m t = junc (split w m) (split zeros r)
38+xls w m t = join (fork w m) (fork zeros r)
3939 where
4040 rExam = m `comp` tr w
4141 rTest = tr t
src/LAoP/Dist/Internal.hs+1−1
@@ -118,7 +118,7 @@ branchD ::
118118 => Dist (Either a b) -> Matrix Prob a c -> Matrix Prob b c -> Dist c
119119branchD x l r = f x `selectD` g l `selectD` r
120120 where
121− f (D m) = D (split (tr i1) (i1 `comp` tr i2) `comp` m)
121+ f (D m) = D (fork (tr i1) (i1 `comp` tr i2) `comp` m)
122122 g m = i2 `comp` m
123123
124124-- | Branch on a Boolean value, skipping unnecessary computations.
src/LAoP/Matrix/Internal.hs+123−123
@@ -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
src/LAoP/Matrix/Nat.hs+34−34
@@ -69,8 +69,8 @@ module LAoP.Matrix.Nat
6969 -- * Primitives
7070 empty,
7171 one,
72− junc,
73− split,
72+ join,
73+ fork,
7474
7575 -- * Auxiliary type families
7676 I.FromNat,
@@ -112,12 +112,12 @@ module LAoP.Matrix.Nat
112112 zipWithM,
113113
114114 -- * Biproduct approach
115− -- ** Split
115+ -- ** Fork
116116 (===),
117117 -- *** Projections
118118 p1,
119119 p2,
120− -- ** Junc
120+ -- ** Join
121121 (|||),
122122 -- *** Injections
123123 i1,
@@ -131,8 +131,8 @@ module LAoP.Matrix.Nat
131131 -- | Note that given the restrictions imposed it is not possible to
132132 -- implement the standard type classes present in standard Haskell.
133133 -- *** Matrix pairing projections
134− kp1,
135− kp2,
134+ fstM,
135+ sndM,
136136
137137 -- *** Matrix pairing
138138 khatri,
@@ -143,10 +143,10 @@ module LAoP.Matrix.Nat
143143
144144 -- | Note that given the restrictions imposed it is not possible to
145145 -- implement the standard type classes present in standard Haskell.
146− identity,
146+ iden,
147147 comp,
148− fromF,
149148 fromF',
149+ fromF,
150150
151151 -- * Matrix printing
152152 pretty,
@@ -179,7 +179,7 @@ type TrivialP a b = I.FromNat (a * b) ~ I.FromNat (I.Count (I.FromNa
179179-- implementation is 'undefined'. However 'comp' can be and this partial
180180-- class implementation exists just to make the code more readable.
181181--
182−-- Please use 'identity' instead.
182+-- Please use 'iden' instead.
183183instance (Num e) => C.Category (Matrix e) where
184184 id = undefined
185185 (.) = comp
@@ -192,12 +192,12 @@ empty = M I.Empty
192192one :: e -> Matrix e 1 1
193193one = M . I.One
194194
195−junc ::
195+join ::
196196 (TrivialE a b) =>
197197 Matrix e a rows ->
198198 Matrix e b rows ->
199199 Matrix e (a + b) rows
200−junc (M a) (M b) = M (I.Junc a b)
200+join (M a) (M b) = M (I.Join a b)
201201
202202infixl 3 |||
203203(|||) ::
@@ -205,14 +205,14 @@ infixl 3 |||
205205 Matrix e a rows ->
206206 Matrix e b rows ->
207207 Matrix e (a + b) rows
208−(|||) = junc
208+(|||) = join
209209
210−split ::
210+fork ::
211211 (TrivialE a b) =>
212212 Matrix e cols a ->
213213 Matrix e cols b ->
214214 Matrix e cols (a + b)
215−split (M a) (M b) = M (I.Split a b)
215+fork (M a) (M b) = M (I.Fork a b)
216216
217217infixl 2 ===
218218(===) ::
@@ -220,7 +220,7 @@ infixl 2 ===
220220 Matrix e cols a ->
221221 Matrix e cols b ->
222222 Matrix e cols (a + b)
223−(===) = split
223+(===) = fork
224224
225225-- Construction
226226
@@ -238,7 +238,7 @@ col = M . I.col
238238row :: (I.FromLists e (I.FromNat cols) ()) => [e] -> Matrix e cols 1
239239row = M . I.row
240240
241−fromF ::
241+fromF' ::
242242 ( Liftable e a b,
243243 CountableN cols,
244244 CountableN rows,
@@ -246,9 +246,9 @@ fromF ::
246246 ) =>
247247 (a -> b) ->
248248 Matrix e cols rows
249−fromF = M . I.fromF
249+fromF' = M . I.fromF'
250250
251−fromF' ::
251+fromF ::
252252 ( Liftable e a b,
253253 CountableNz a,
254254 CountableNz b,
@@ -256,7 +256,7 @@ fromF' ::
256256 ) =>
257257 (a -> b) ->
258258 Matrix e (I.Count a) (I.Count b)
259−fromF' = undefined -- M . I.fromF'
259+fromF = undefined -- M . I.fromF
260260
261261-- Conversion
262262
@@ -296,12 +296,12 @@ bang ::
296296 Matrix e cols 1
297297bang = M I.bang
298298
299−-- Identity Matrix
299+-- iden Matrix
300300
301−identity ::
301+iden ::
302302 (Num e, FromListsN e cols cols, CountableN cols) =>
303303 Matrix e cols cols
304−identity = M I.identity
304+iden = M I.iden
305305
306306-- Matrix composition (MMM)
307307
@@ -377,7 +377,7 @@ infixl 5 -|-
377377(-|-) (M a) (M b) = M ((I.-|-) a b)
378378
379379-- | Khatri Rao Product and projections
380−kp1 ::
380+fstM ::
381381 forall e m k .
382382 ( Num e,
383383 CountableDimensionsN m k,
@@ -385,9 +385,9 @@ kp1 ::
385385 FromListsN e (m * k) m,
386386 TrivialP m k
387387 ) => Matrix e (m * k) m
388−kp1 = M (I.kp1 @e @(I.FromNat m) @(I.FromNat k))
388+fstM = M (I.fstM @e @(I.FromNat m) @(I.FromNat k))
389389
390−kp2 ::
390+sndM ::
391391 forall e m k.
392392 ( Num e,
393393 CountableDimensionsN k m,
@@ -395,7 +395,7 @@ kp2 ::
395395 CountableN (m * k),
396396 TrivialP m k
397397 ) => Matrix e (m * k) k
398−kp2 = M (I.kp2 @e @(I.FromNat m) @(I.FromNat k))
398+sndM = M (I.sndM @e @(I.FromNat m) @(I.FromNat k))
399399
400400khatri ::
401401 forall e cols a b.
@@ -407,9 +407,9 @@ khatri ::
407407 TrivialP a b
408408 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a * b)
409409khatri a b =
410− let kp1' = kp1 @e @a @b
411− kp2' = kp2 @e @a @b
412− in comp (tr kp1') a * comp (tr kp2') b
410+ let fstM' = fstM @e @a @b
411+ sndM' = sndM @e @a @b
412+ in comp (tr fstM') a * comp (tr sndM') b
413413
414414-- | Product Bifunctor (Kronecker)
415415infixl 4 ><
@@ -428,15 +428,15 @@ infixl 4 ><
428428 TrivialP p q
429429 ) => Matrix e m p -> Matrix e n q -> Matrix e (m * n) (p * q)
430430(><) a b =
431− let kp1' = kp1 @e @m @n
432− kp2' = kp2 @e @m @n
433− in khatri (comp a kp1') (comp b kp2')
431+ let fstM' = fstM @e @m @n
432+ sndM' = sndM @e @m @n
433+ in khatri (comp a fstM') (comp b sndM')
434434
435−-- | Matrix abide Junc Split
435+-- | Matrix abide Join Fork
436436abideJS :: Matrix e cols rows -> Matrix e cols rows
437437abideJS (M m) = M (I.abideJS m)
438438
439−-- | Matrix abide Split Junc
439+-- | Matrix abide Fork Join
440440abideSJ :: Matrix e cols rows -> Matrix e cols rows
441441abideSJ (M m) = M (I.abideSJ m)
442442
src/LAoP/Matrix/Type.hs+51−51
@@ -73,8 +73,8 @@ module LAoP.Matrix.Type
7373 -- * Primitives
7474 empty,
7575 one,
76− junc,
77− split,
76+ join,
77+ fork,
7878
7979 -- * Auxiliary type families
8080 I.FromNat,
@@ -129,12 +129,12 @@ module LAoP.Matrix.Type
129129 zipWithM,
130130
131131 -- * Biproduct approach
132− -- ** Split
132+ -- ** Fork
133133 (===),
134134 -- *** Projections
135135 p1,
136136 p2,
137− -- ** Junc
137+ -- ** Join
138138 (|||),
139139 -- *** Injections
140140 i1,
@@ -148,8 +148,8 @@ module LAoP.Matrix.Type
148148 -- | Note that given the restrictions imposed it is not possible to
149149 -- implement the standard type classes present in standard Haskell.
150150 -- *** Matrix pairing projections
151− kp1,
152− kp2,
151+ fstM,
152+ sndM,
153153
154154 -- *** Matrix pairing
155155 khatri,
@@ -160,10 +160,10 @@ module LAoP.Matrix.Type
160160
161161 -- | Note that given the restrictions imposed it is not possible to
162162 -- implement the standard type classes present in standard Haskell.
163− identity,
163+ iden,
164164 comp,
165− fromF,
166165 fromF',
166+ fromF,
167167
168168 -- * Relation
169169 toRel,
@@ -202,7 +202,7 @@ type TrivialP a b = I.Normalize (a, b) ~ I.Normalize (I.Normalize a,
202202-- implementation is 'undefined'. However 'comp' can be and this partial
203203-- class implementation exists just to make the code more readable.
204204--
205−-- Please use 'identity' instead.
205+-- Please use 'iden' instead.
206206instance (Num e) => C.Category (Matrix e) where
207207 id = undefined
208208 (.) = comp
@@ -216,7 +216,7 @@ bimapM ::
216216 FromListsN e d c,
217217 FromListsN e b a
218218 ) => (a -> b) -> (c -> d) -> Matrix e a c -> Matrix e b d
219−bimapM f g m = fromF' g `comp` m `comp` tr (fromF' f)
219+bimapM f g m = fromF g `comp` m `comp` tr (fromF f)
220220
221221-- | Zero type alias
222222type Zero = Void
@@ -234,35 +234,35 @@ empty = M I.Empty
234234one :: e -> Matrix e One One
235235one = M . I.One
236236
237−-- | Matrix 'Junc' constructor
238−junc ::
237+-- | Matrix 'Join' constructor
238+join ::
239239 Matrix e a rows ->
240240 Matrix e b rows ->
241241 Matrix e (Either a b) rows
242−junc (M a) (M b) = M (I.Junc a b)
242+join (M a) (M b) = M (I.Join a b)
243243
244244infixl 3 |||
245−-- | Matrix 'Junc' constructor
245+-- | Matrix 'Join' constructor
246246(|||) ::
247247 Matrix e a rows ->
248248 Matrix e b rows ->
249249 Matrix e (Either a b) rows
250−(|||) = junc
250+(|||) = join
251251
252−-- | Matrix 'Split' constructor
253−split ::
252+-- | Matrix 'Fork' constructor
253+fork ::
254254 Matrix e cols a ->
255255 Matrix e cols b ->
256256 Matrix e cols (Either a b)
257−split (M a) (M b) = M (I.Split a b)
257+fork (M a) (M b) = M (I.Fork a b)
258258
259259infixl 2 ===
260−-- | Matrix 'Split' constructor
260+-- | Matrix 'Fork' constructor
261261(===) ::
262262 Matrix e cols a ->
263263 Matrix e cols b ->
264264 Matrix e cols (Either a b)
265−(===) = split
265+(===) = fork
266266
267267-- Functor hierarchy
268268
@@ -274,7 +274,7 @@ fmapM ::
274274 )
275275 =>
276276 (a -> b) -> Matrix e c a -> Matrix e c b
277−fmapM f m = fromF' f `comp` m
277+fmapM f m = fromF f `comp` m
278278
279279-- | Applicative instance equivalent 'unit' function,
280280unitM :: (Num e) => Matrix e () ()
@@ -336,23 +336,23 @@ row = M . I.row
336336--
337337-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
338338-- types @a@ or @b@ allows.
339−fromF ::
339+fromF' ::
340340 ( Liftable e a b,
341341 CountableDimensionsN cols rows,
342342 FromListsN e rows cols
343343 ) =>
344344 (a -> b) -> Matrix e cols rows
345−fromF = M . I.fromF
345+fromF' = M . I.fromF'
346346
347347-- | Lifts functions to matrices with dimensions matching @a@ and @b@
348348-- cardinality's.
349−fromF' ::
349+fromF ::
350350 ( Liftable e a b,
351351 CountableDimensionsN a b,
352352 FromListsN e b a
353353 ) =>
354354 (a -> b) -> Matrix e a b
355−fromF' = M . I.fromF'
355+fromF = M . I.fromF
356356
357357-- | Lifts relation functions to Boolean Matrix
358358toRel ::
@@ -418,16 +418,16 @@ point ::
418418 CountableN a,
419419 FromListsN e a One
420420 ) => a -> Matrix e One a
421−point = fromF' . const
421+point = fromF . const
422422
423−-- Identity Matrix
423+-- iden Matrix
424424
425−-- | Identity matrix
426−identity ::
425+-- | iden matrix
426+iden ::
427427 (Num e, FromListsN e a a, CountableN a) =>
428428 Matrix e a a
429−identity = M I.identity
430−{-# NOINLINE identity #-}
429+iden = M I.iden
430+{-# NOINLINE iden #-}
431431
432432-- Matrix composition (MMM)
433433
@@ -439,8 +439,8 @@ comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
439439comp (M a) (M b) = M (I.comp a b)
440440{-# NOINLINE comp #-}
441441{-# RULES
442− "comp/identity1" forall m. comp m identity = m ;
443− "comp/identity2" forall m. comp identity m = m
442+ "comp/iden1" forall m. comp m iden = m ;
443+ "comp/iden2" forall m. comp iden m = m
444444#-}
445445
446446-- | Biproduct first component projection
@@ -528,7 +528,7 @@ infixl 5 -|-
528528-- Khatri Rao Product and projections
529529
530530-- | Khatri Rao product first component projection matrix.
531−kp1 ::
531+fstM ::
532532 forall e m k .
533533 ( Num e,
534534 CountableDimensionsN m k,
@@ -536,10 +536,10 @@ kp1 ::
536536 FromListsN e (m, k) m,
537537 TrivialP m k
538538 ) => Matrix e (m, k) m
539−kp1 = M (I.kp1 @e @(I.Normalize m) @(I.Normalize k))
539+fstM = M (I.fstM @e @(I.Normalize m) @(I.Normalize k))
540540
541541-- | Khatri Rao product second component projection matrix.
542−kp2 ::
542+sndM ::
543543 forall e m k.
544544 ( Num e,
545545 CountableDimensionsN k m,
@@ -547,16 +547,16 @@ kp2 ::
547547 FromListsN e (m, k) k,
548548 TrivialP m k
549549 ) => Matrix e (m, k) k
550−kp2 = M (I.kp2 @e @(I.Normalize m) @(I.Normalize k))
550+sndM = M (I.sndM @e @(I.Normalize m) @(I.Normalize k))
551551
552552-- | Khatri Rao Matrix product also known as matrix pairing.
553553--
554554-- NOTE: That this is not a true categorical product, see for instance:
555555--
556556-- @
557−-- | kp1 `comp` khatri a b == a
557+-- | fstM `comp` khatri a b == a
558558-- khatri a b ==> |
559−-- | kp2 `comp` khatri a b == b
559+-- | sndM `comp` khatri a b == b
560560-- @
561561--
562562-- __Emphasis__ on the implication symbol.
@@ -570,9 +570,9 @@ khatri ::
570570 TrivialP a b
571571 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a, b)
572572khatri a b =
573− let kp1' = kp1 @e @a @b
574− kp2' = kp2 @e @a @b
575− in comp (tr kp1') a * comp (tr kp2') b
573+ let fstM' = fstM @e @a @b
574+ sndM' = sndM @e @a @b
575+ in comp (tr fstM') a * comp (tr sndM') b
576576
577577-- Product Bifunctor (Kronecker)
578578
@@ -593,30 +593,30 @@ infixl 4 ><
593593 TrivialP p q
594594 ) => Matrix e m p -> Matrix e n q -> Matrix e (m, n) (p, q)
595595(><) a b =
596− let kp1' = kp1 @e @m @n
597− kp2' = kp2 @e @m @n
598− in khatri (comp a kp1') (comp b kp2')
596+ let fstM' = fstM @e @m @n
597+ sndM' = sndM @e @m @n
598+ in khatri (comp a fstM') (comp b sndM')
599599
600−-- Matrix abide Junc Split
600+-- Matrix abide Join Fork
601601
602−-- | Matrix "abiding" followin the 'Junc'-'Split' abide law.
602+-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
603603--
604604-- Law:
605605--
606606-- @
607−-- 'Junc' ('Split' a c) ('Split' b d) == 'Split' ('Junc' a b) ('Junc' c d)
607+-- 'Join' ('Fork' a c) ('Fork' b d) == 'Fork' ('Join' a b) ('Join' c d)
608608-- @
609609abideJS :: Matrix e cols rows -> Matrix e cols rows
610610abideJS (M m) = M (I.abideJS m)
611611
612−-- Matrix abide Split Junc
612+-- Matrix abide Fork Join
613613
614−-- | Matrix "abiding" followin the 'Split'-'Junc' abide law.
614+-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
615615--
616616-- Law:
617617--
618618-- @
619−-- 'Split' ('Junc' a b) ('Junc' c d) == 'Junc' ('Split' a c) ('Split' b d)
619+-- 'Fork' ('Join' a b) ('Join' c d) == 'Join' ('Fork' a c) ('Fork' b d)
620620-- @
621621abideSJ :: Matrix e cols rows -> Matrix e cols rows
622622abideSJ (M m) = M (I.abideSJ m)
src/LAoP/Relation.hs+5−5
@@ -43,9 +43,9 @@ module LAoP.Relation
4343 -- * Primitives
4444 empty,
4545 one,
46− junc,
46+ join,
4747 (|||),
48− split,
48+ fork,
4949 (===),
5050
5151 -- * Auxiliary type families
@@ -108,8 +108,8 @@ module LAoP.Relation
108108 splitR,
109109
110110 -- ** Projections
111− p1,
112− p2,
111+ fstR,
112+ sndR,
113113 -- ** Bifunctor
114114 (><),
115115 -- * Relational coproduct
@@ -148,7 +148,7 @@ module LAoP.Relation
148148 cond,
149149
150150 -- * Relational composition and lifting
151− identity,
151+ iden,
152152 comp,
153153 fromF,
154154 fromF',
src/LAoP/Relation/Internal.hs+62−62
@@ -53,9 +53,9 @@ module LAoP.Relation.Internal
5353 -- * Primitives
5454 empty,
5555 one,
56− junc,
56+ join,
5757 (|||),
58− split,
58+ fork,
5959 (===),
6060
6161 -- * Auxiliary type families
@@ -66,8 +66,8 @@ module LAoP.Relation.Internal
6666 -- * Matrix construction and conversion
6767 I.FromLists,
6868 fromLists,
69− fromF,
7069 fromF',
70+ fromF,
7171 toRel,
7272 toLists,
7373 toList,
@@ -118,8 +118,8 @@ module LAoP.Relation.Internal
118118 splitR,
119119
120120 -- ** Projections
121− p1,
122− p2,
121+ fstR,
122+ sndR,
123123 -- ** Bifunctor
124124 (><),
125125 -- * Relational coproduct
@@ -158,10 +158,10 @@ module LAoP.Relation.Internal
158158 cond,
159159
160160 -- * Relational composition and lifting
161− identity,
161+ iden,
162162 comp,
163− fromF,
164163 fromF',
164+ fromF,
165165
166166 -- ** Relational application
167167 pointAp,
@@ -205,19 +205,19 @@ type TrivialP a b = I.Normalize (a, b) ~ I.Normalize (I.Normalize a,
205205-- implementation is 'undefined'. However 'comp' can be and this partial
206206-- class implementation exists just to make the code more readable.
207207--
208−-- Please use 'identity' instead.
208+-- Please use 'iden' instead.
209209instance C.Category Relation where
210210 id = undefined
211211 (.) = comp
212212
213213instance Num (Relation a b) where
214− -- | Matrix addition becomes Boolean matrix disjunction
214+ -- | Matrix addition becomes Boolean matrix disjointion
215215 (R a) + (R b) = R (I.orM a b)
216216
217217 -- | Matrix subtraction becomes Relational subtraction
218218 (R a) - (R b) = R (I.subM a b)
219219
220− -- | Matrix multiplication becomes Boolean matrix conjunction
220+ -- | Matrix multiplication becomes Boolean matrix conjointion
221221 (R a) * (R b) = R (I.andM a b)
222222
223223 -- | Matrix negation becomes Boolean matrix negation
@@ -237,33 +237,33 @@ empty = R I.Empty
237237one :: Boolean -> Relation One One
238238one = R . I.One
239239
240−-- | Boolean Matrix 'Junc' constructor, also known as relational coproduct.
240+-- | Boolean Matrix 'Join' constructor, also known as relational coproduct.
241241--
242242-- See 'eitherR'.
243−junc :: Relation a c -> Relation b c -> Relation (Either a b) c
244−junc (R a) (R b) = R (I.Junc a b)
243+join :: Relation a c -> Relation b c -> Relation (Either a b) c
244+join (R a) (R b) = R (I.Join a b)
245245
246246infixl 3 |||
247−-- | Boolean Matrix 'Junc' constructor
247+-- | Boolean Matrix 'Join' constructor
248248--
249249-- See 'eitherR'.
250250(|||) ::
251251 Relation a c ->
252252 Relation b c ->
253253 Relation (Either a b) c
254−(|||) = junc
254+(|||) = join
255255
256−-- | Boolean Matrix 'Split' constructor, also known as relational product.
257−split :: Relation c a -> Relation c b -> Relation c (Either a b)
258−split (R a) (R b) = R (I.Split a b)
256+-- | Boolean Matrix 'Fork' constructor, also known as relational product.
257+fork :: Relation c a -> Relation c b -> Relation c (Either a b)
258+fork (R a) (R b) = R (I.Fork a b)
259259
260260infixl 2 ===
261−-- | Boolean Matrix 'Split' constructor
261+-- | Boolean Matrix 'Fork' constructor
262262(===) ::
263263 Relation c a ->
264264 Relation c b ->
265265 Relation c (Either a b)
266−(===) = split
266+(===) = fork
267267
268268-- Construction
269269
@@ -283,23 +283,23 @@ relationBuilder = R . I.matrixBuilder
283283--
284284-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
285285-- types @a@ or @b@ allows.
286−fromF ::
286+fromF' ::
287287 ( Liftable a b,
288288 CountableDimensionsN c d,
289289 FromListsN d c
290290 )
291291 => (a -> b) -> Relation c d
292−fromF f = R (I.fromFRel f)
292+fromF' f = R (I.fromFRel' f)
293293
294294-- | Lifts functions to matrices with dimensions matching @a@ and @b@
295295-- cardinality's.
296−fromF' ::
296+fromF ::
297297 ( Liftable a b,
298298 CountableDimensionsN a b,
299299 FromListsN b a
300300 )
301301 => (a -> b) -> Relation a b
302−fromF' f = R (I.fromFRel' f)
302+fromF f = R (I.fromFRel f)
303303
304304-- | Lifts relation functions to 'Relation'
305305toRel ::
@@ -412,18 +412,18 @@ point ::
412412 CountableN a,
413413 FromListsN a One
414414 ) => a -> Relation One a
415−point = fromF' . const
415+point = fromF . const
416416
417−-- Identity Matrix
417+-- iden Matrix
418418
419−-- | Identity matrix
419+-- | iden matrix
420420--
421421-- @
422−-- 'identity' ``comp`` r == r == r ``comp`` 'identity'
422+-- 'iden' ``comp`` r == r == r ``comp`` 'iden'
423423-- @
424−identity ::
424+iden ::
425425 (FromListsN a a, CountableN a) => Relation a a
426−identity = relationBuilder (bool (nat 0) (nat 1) . uncurry (==))
426+iden = relationBuilder (bool (nat 0) (nat 1) . uncurry (==))
427427
428428-- | Relational composition
429429--
@@ -530,7 +530,7 @@ iff r s = r == s
530530
531531-- | Relational intersection
532532--
533−-- Lifts pointwise conjunction.
533+-- Lifts pointwise conjointion.
534534--
535535-- @
536536-- (r ``intersection`` s) ``intersection`` t == r ``intersection`` (s ``intersection`` t)
@@ -541,7 +541,7 @@ intersection a b = a * b
541541
542542-- | Relational union
543543--
544−-- Lifts pointwise disjunction.
544+-- Lifts pointwise disjointion.
545545--
546546-- @
547547-- (r ``union`` s) ``union`` t == r `'union' (s ``union`` t)
@@ -658,13 +658,13 @@ bijection r = injection r && surjection r
658658
659659-- Properties of relations
660660
661−-- | A 'Relation' @r@ is 'reflexive' 'iff' @'identity' ``sse`` r@
661+-- | A 'Relation' @r@ is 'reflexive' 'iff' @'iden' ``sse`` r@
662662reflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
663−reflexive r = identity <= r
663+reflexive r = iden <= r
664664
665−-- | A 'Relation' @r@ is 'coreflexive' 'iff' @r ``sse`` 'identity'@
665+-- | A 'Relation' @r@ is 'coreflexive' 'iff' @r ``sse`` 'iden'@
666666coreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
667−coreflexive r = r <= identity
667+coreflexive r = r <= iden
668668
669669-- | A 'Relation' @r@ is 'transitive' 'iff' @(r ``comp`` r) ``sse`` r@
670670transitive :: Relation a a -> Bool
@@ -674,13 +674,13 @@ transitive r = (r `comp` r) `sse` r
674674symmetric :: Relation a a -> Bool
675675symmetric r = r == conv r
676676
677−-- | A 'Relation' @r@ is anti-symmetric 'iff' @(r ``intersection`` 'conv' r) ``sse`` 'identity'@
677+-- | A 'Relation' @r@ is anti-symmetric 'iff' @(r ``intersection`` 'conv' r) ``sse`` 'iden'@
678678antiSymmetric :: (CountableN a, FromListsN a a) => Relation a a -> Bool
679−antiSymmetric r = (r `intersection` conv r) `sse` identity
679+antiSymmetric r = (r `intersection` conv r) `sse` iden
680680
681−-- | A 'Relation' @r@ is 'irreflexive' 'iff' @(r ``intersection`` 'identity') == 'zeros'@
681+-- | A 'Relation' @r@ is 'irreflexive' 'iff' @(r ``intersection`` 'iden') == 'zeros'@
682682irreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
683−irreflexive r = (r `intersection` identity) == zeros
683+irreflexive r = (r `intersection` iden) == zeros
684684
685685-- | A 'Relation' @r@ is 'connected' 'iff' @(r ``union`` 'conv' r) == 'ones'@
686686connected :: (CountableN a, FromListsN a a) => Relation a a -> Bool
@@ -718,9 +718,9 @@ difunctional r = r `comp` conv r `comp` r == r
718718-- NOTE: That this is not a true categorical product, see for instance:
719719--
720720-- @
721−-- | 'p1' ``comp`` 'splitR' a b ``sse`` a
721+-- | 'fstR' ``comp`` 'splitR' a b ``sse`` a
722722-- 'splitR' a b <=> |
723−-- | 'p2' ``comp`` 'splitR' a b ``sse`` b
723+-- | 'sndR' ``comp`` 'splitR' a b ``sse`` b
724724-- @
725725--
726726-- __Emphasis__ on the 'sse'.
@@ -747,9 +747,9 @@ splitR (R f) (R g) = R (I.khatri f g)
747747-- | Relational pairing first component projection
748748--
749749-- @
750−-- 'p1' ``comp`` 'splitR' r s ``sse`` r
750+-- 'fstR' ``comp`` 'splitR' r s ``sse`` r
751751-- @
752−p1 ::
752+fstR ::
753753 forall a b .
754754 ( CountableDimensionsN a b,
755755 CountableN (a, b),
@@ -757,14 +757,14 @@ p1 ::
757757 TrivialP a b
758758 )
759759 => Relation (a, b) a
760−p1 = R (I.kp1 @Boolean @(I.Normalize a) @(I.Normalize b))
760+fstR = R (I.fstM @Boolean @(I.Normalize a) @(I.Normalize b))
761761
762762-- | Relational pairing second component projection
763763--
764764-- @
765−-- 'p2' ``comp`` 'splitR' r s ``sse`` s
765+-- 'sndR' ``comp`` 'splitR' r s ``sse`` s
766766-- @
767−p2 ::
767+sndR ::
768768 forall a b .
769769 ( CountableDimensionsN a b,
770770 CountableN (a, b),
@@ -772,7 +772,7 @@ p2 ::
772772 TrivialP a b
773773 )
774774 => Relation (a, b) b
775−p2 = R (I.kp2 @Boolean @(I.Normalize a) @(I.Normalize b))
775+sndR = R (I.sndM @Boolean @(I.Normalize a) @(I.Normalize b))
776776
777777-- Relational pairing functor
778778
@@ -780,7 +780,7 @@ infixl 4 ><
780780-- | Relational pairing functor
781781--
782782-- @
783−-- r '><' s == 'splitR' (r ``comp`` p1) (s ``comp`` p2)
783+-- r '><' s == 'splitR' (r ``comp`` fstR) (s ``comp`` sndR)
784784-- (r '><' s) ``comp`` (p '><' q) == (r ``comp`` p) '><' (s ``comp`` q)
785785-- @
786786(><) ::
@@ -815,12 +815,12 @@ infixl 4 ><
815815-- 'eitherR' ('splitR' r s) ('splitR' t v) == 'splitR' ('eitherR' r t) ('eitherR' s v)
816816-- @
817817eitherR :: Relation a c -> Relation b c -> Relation (Either a b) c
818−eitherR = junc
818+eitherR = join
819819
820820-- | Relational coproduct first component injection
821821--
822822-- @
823−-- 'img' 'i1' ``union`` 'img' 'i2' == 'identity'
823+-- 'img' 'i1' ``union`` 'img' 'i2' == 'iden'
824824-- 'i1' ``comp`` 'i2' = 'zeros'
825825-- @
826826i1 ::
@@ -834,7 +834,7 @@ i1 = R I.i1
834834-- | Relational coproduct second component injection
835835--
836836-- @
837−-- 'img' 'i1' ``union`` 'img' 'i2' == 'identity'
837+-- 'img' 'i1' ``union`` 'img' 'i2' == 'iden'
838838-- 'i1' ``comp`` 'i2' = 'zeros'
839839-- @
840840i2 ::
@@ -883,7 +883,7 @@ trans ::
883883 TrivialP c b
884884 )
885885 => Relation (a, b) c -> Relation a (c, b)
886−trans r = splitR r p2 `comp` conv p1
886+trans r = splitR r sndR `comp` conv fstR
887887
888888-- | Relational 'untrans'
889889--
@@ -904,12 +904,12 @@ untrans ::
904904 TrivialP c b
905905 )
906906 => Relation a (c, b) -> Relation (a, b) c
907−untrans s = p1 `comp` conv (splitR (conv s) p2)
907+untrans s = fstR `comp` conv (splitR (conv s) sndR)
908908
909909-- | Transforms predicate @p@ into a correflexive relation.
910910--
911911-- @
912−-- 'predR' ('const' True) == 'identity'
912+-- 'predR' ('const' True) == 'iden'
913913-- 'predR' ('const' False) == 'zeros'
914914-- @
915915--
@@ -924,14 +924,14 @@ predR ::
924924 FromListsN Bool a
925925 )
926926 => Relation a Bool -> Relation a a
927−predR p = identity `intersection` divisionF (fromF' (const True)) p
927+predR p = iden `intersection` divisionF (fromF (const True)) p
928928
929929-- | Equalizes functions @f@ and @g@.
930930-- That is, @'equalizer' f g@ is the largest coreflexive
931931-- that restricts @g@ so that @f@ and @g@ yield the same outputs.
932932--
933933-- @
934−-- 'equalizer' r r == 'identity'
934+-- 'equalizer' r r == 'iden'
935935-- 'equalizer' ('point' True) ('point' False) == 'zeros'
936936-- @
937937equalizer ::
@@ -939,7 +939,7 @@ equalizer ::
939939 FromListsN a a
940940 )
941941 => Relation a b -> Relation a b -> Relation a a
942−equalizer f g = identity `intersection` divisionF f g
942+equalizer f g = iden `intersection` divisionF f g
943943
944944-- | Relational conditional guard.
945945--
@@ -969,22 +969,22 @@ cond p r s = eitherR r s `comp` guard p
969969-- | Relational domain.
970970--
971971-- For injective relations, 'domain' and 'ker'nel coincide,
972−-- since @'ker' r ``sse`` 'identity'@ in such situations.
972+-- since @'ker' r ``sse`` 'iden'@ in such situations.
973973domain ::
974974 ( CountableN a,
975975 FromListsN a a
976976 ) => Relation a b -> Relation a a
977−domain r = ker r `intersection` identity
977+domain r = ker r `intersection` iden
978978
979979-- | Relational range.
980980--
981981-- For functions, 'range' and 'img' (image) coincide,
982−-- since @'img' f ``sse`` 'identity'@ for any @f@.
982+-- since @'img' f ``sse`` 'iden'@ for any @f@.
983983range ::
984984 ( CountableN b,
985985 FromListsN b b
986986 ) => Relation a b -> Relation b b
987−range r = img r `intersection` identity
987+range r = img r `intersection` iden
988988
989989-- Relation pretty print
990990