on master help sign in
Renamed:
399c102Armando Santos
app/Benchmarks.hs+5−5
@@ -28,16 +28,16 @@ selectM2 ::
28 T.FromListsN e b b,
28 T.FromListsN e b b,
29 CountableN b
29 CountableN b
30 ) => Matrix e cols (Either a b) -> Matrix e a b -> Matrix e cols b
30 ) => 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
32
32
33selectD2 ::
33selectD2 ::
34 ( FromListsN b b,
34 ( FromListsN b b,
35 CountableN b
35 CountableN b
36 ) => Dist (Either a b) -> Matrix Prob a b -> Dist b
36 ) => 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)
38
38
39−-- Composition with identity
39+-- Composition with iden
40−compId m = comp identity m
40+compId m = comp iden m
41
41
42randomDist :: forall a . (Countable a, FromListsN () a) => Gen (Dist a)
42randomDist :: forall a . (Countable a, FromListsN () a) => Gen (Dist a)
43randomDist = do
43randomDist = do
@@ -162,7 +162,7 @@ benchmark = defaultMain [
162 , bench "NF - 200x200" $ nf (comp m31) m32
162 , bench "NF - 200x200" $ nf (comp m31) m32
163 ],
163 ],
164 bgroup "200x200 - RULES" [
164 bgroup "200x200 - RULES" [
165− bench "No rules - 200x200" $ nf (comp m21) identity
165+ bench "No rules - 200x200" $ nf (comp m21) iden
166 , bench "Rules - 200x200" $ nf compId m21
166 , bench "Rules - 200x200" $ nf compId m21
167 ] ],
167 ] ],
168 env setupEnv2 $ \ ~(m21, m40, dist, dist2, dl1, dl2) -> bgroup "Matrix vs List - `select`" [
168 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
32firstChoice = col [1/3, 2/3]
32firstChoice = col [1/3, 2/3]
33
33
34secondChoice :: Matrix Double Outcome Outcome
34secondChoice :: Matrix Double Outcome Outcome
35−secondChoice = fromF' switch
35+secondChoice = fromF switch
36
36
37-- Dice sum
37-- Dice sum
38
38
@@ -41,7 +41,7 @@ type SS = Natural 1 6 -- Sample Space
41sumSS :: SS -> SS -> Natural 2 12
41sumSS :: SS -> SS -> Natural 2 12
42sumSS = coerceNat (+)
42sumSS = coerceNat (+)
43
43
44−sumSSM = fromF' (uncurry sumSS)
44+sumSSM = fromF (uncurry sumSS)
45
45
46condition :: (Int, Int) -> Int -> Int
46condition :: (Int, Int) -> Int -> Int
47condition (fst, snd) thrd = if fst == snd
47condition (fst, snd) thrd = if fst == snd
@@ -51,7 +51,7 @@ condition (fst, snd) thrd = if fst == snd
51conditionSS :: (SS, SS) -> SS -> Natural 3 18
51conditionSS :: (SS, SS) -> SS -> Natural 3 18
52conditionSS = coerceNat2 condition
52conditionSS = coerceNat2 condition
53
53
54−conditionalThrows = fromF' (uncurry conditionSS) . khatri (khatri die die) die
54+conditionalThrows = fromF (uncurry conditionSS) . khatri (khatri die die) die
55
55
56die :: Matrix Double () SS
56die :: Matrix Double () SS
57die = col $ map (const (1/6)) [nat @1 @6 1 .. nat 6]
57die = 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]]
75grass :: Matrix Double (S, R) G
75grass :: Matrix Double (S, R) G
76grass = fromLists [[1, 0.2, 0.1, 0.01], [0, 0.8, 0.9, 0.99]]
76grass = fromLists [[1, 0.2, 0.1, 0.01], [0, 0.8, 0.9, 0.99]]
77
77
78−tag f = khatri f identity
78+tag f = khatri f iden
79
79
80state g s r = tag g `comp` tag s `comp` r
80state g s r = tag g `comp` tag s `comp` r
81
81
82grass_wet :: Matrix Double () (G, (S, R)) -> Matrix Double One One
82grass_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
84
84
85rainning :: Matrix Double (G, (S, R)) One
85rainning :: Matrix Double (G, (S, R)) One
86−rainning = row [0,1] . kp2 . kp2
86+rainning = row [0,1] . sndM . sndM
87
87
88-- Alcuin Puzzle
88-- Alcuin Puzzle
89
89
@@ -106,21 +106,21 @@ cross LeftB = RightB
106cross RightB = LeftB
106cross RightB = LeftB
107
107
108crossR :: R.Relation Bank Bank
108crossR :: R.Relation Bank Bank
109−crossR = R.fromF' cross
109+crossR = R.fromF cross
110
110
111-- | Initial state, everyone in the left bank
111-- | Initial state, everyone in the left bank
112locationLeft :: Being -> Bank
112locationLeft :: Being -> Bank
113locationLeft _ = LeftB
113locationLeft _ = LeftB
114
114
115locationLeftR :: R.Relation Being Bank
115locationLeftR :: R.Relation Being Bank
116−locationLeftR = R.fromF' locationLeft
116+locationLeftR = R.fromF locationLeft
117
117
118-- | Initial state, everyone in the right bank
118-- | Initial state, everyone in the right bank
119locationRight :: Being -> Bank
119locationRight :: Being -> Bank
120locationRight _ = RightB
120locationRight _ = RightB
121
121
122locationRightR :: R.Relation Being Bank
122locationRightR :: R.Relation Being Bank
123−locationRightR = R.fromF' locationRight
123+locationRightR = R.fromF locationRight
124
124
125-- Properties
125-- Properties
126
126
@@ -137,7 +137,7 @@ inv :: R.Relation Being Bank -> Bool
137inv w = (w `R.comp` canEat w) `R.sse` (w `R.comp` farmer)
137inv w = (w `R.comp` canEat w) `R.sse` (w `R.comp` farmer)
138 where
138 where
139 farmer :: R.Relation Being Being
139 farmer :: R.Relation Being Being
140− farmer = R.fromF' (const Farmer)
140+ farmer = R.fromF (const Farmer)
141
141
142-- Arbitrary state
142-- Arbitrary state
143bankState :: Being -> Bank -> Bool
143bankState :: 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
35 -> Matrix Float Question Student
35 -> Matrix Float Question Student
36 -> Matrix Float Student One
36 -> Matrix Float Student One
37 -> Matrix Float (Either Question Results) (Either One Student)
37 -> 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)
39 where
39 where
40 rExam = m `comp` tr w
40 rExam = m `comp` tr w
41 rTest = tr t
41 rTest = tr t
src/LAoP/Dist/Internal.hs+1−1
@@ -118,7 +118,7 @@ branchD ::
118 => Dist (Either a b) -> Matrix Prob a c -> Matrix Prob b c -> Dist c
118 => Dist (Either a b) -> Matrix Prob a c -> Matrix Prob b c -> Dist c
119branchD x l r = f x `selectD` g l `selectD` r
119branchD x l r = f x `selectD` g l `selectD` r
120 where
120 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)
122 g m = i2 `comp` m
122 g m = i2 `comp` m
123
123
124-- | Branch on a Boolean value, skipping unnecessary computations.
124-- | Branch on a Boolean value, skipping unnecessary computations.
src/LAoP/Matrix/Internal.hs+123−123
@@ -52,8 +52,8 @@ module LAoP.Matrix.Internal
52 -- * Primitives
52 -- * Primitives
53 empty,
53 empty,
54 one,
54 one,
55− junc,
55+ join,
56− split,
56+ fork,
57
57
58 -- * Auxiliary type families
58 -- * Auxiliary type families
59 FromNat,
59 FromNat,
@@ -96,12 +96,12 @@ module LAoP.Matrix.Internal
96 zipWithM,
96 zipWithM,
97
97
98 -- * Biproduct approach
98 -- * Biproduct approach
99− -- ** Split
99+ -- ** Fork
100 (===),
100 (===),
101 -- *** Projections
101 -- *** Projections
102 p1,
102 p1,
103 p2,
103 p2,
104− -- ** Junc
104+ -- ** Join
105 (|||),
105 (|||),
106 -- *** Injections
106 -- *** Injections
107 i1,
107 i1,
@@ -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
118− kp1,
118+ fstM,
119− kp2,
119+ sndM,
120
120
121 -- *** Matrix pairing
121 -- *** Matrix pairing
122 khatri,
122 khatri,
@@ -127,10 +127,10 @@ module LAoP.Matrix.Internal
127
127
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.
130− identity,
130+ iden,
131 comp,
131 comp,
132− fromF,
133 fromF',
132 fromF',
133+ fromF,
134
134
135 -- * Matrix printing
135 -- * Matrix printing
136 pretty,
136 pretty,
@@ -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)
176
176
177deriving instance (Show e) => Show (Matrix e cols rows)
177deriving instance (Show e) => Show (Matrix e cols rows)
178
178
@@ -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.
228--
228--
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
239
239
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
247
247
248instance Num e => Num (Matrix e cols rows) where
248instance Num e => Num (Matrix e cols rows) where
249
249
@@ -255,21 +255,21 @@ instance Num e => Num (Matrix e cols rows) where
255
255
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)
260
260
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)
265
265
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
273
273
274-- Primitives
274-- Primitives
275
275
@@ -281,25 +281,25 @@ empty = Empty
281one :: e -> Matrix e () ()
281one :: e -> Matrix e () ()
282one = One
282one = One
283
283
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
287
287
288infixl 3 |||
288infixl 3 |||
289
289
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
293
293
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
297
297
298infixl 2 ===
298infixl 2 ===
299
299
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
303
303
304-- Construction
304-- Construction
305
305
@@ -321,23 +321,23 @@ instance {-# OVERLAPPING #-} FromLists e () () where
321 fromLists _ = error "Wrong dimensions"
321 fromLists _ = error "Wrong dimensions"
322
322
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"
326
326
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"
332
332
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"
336
336
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"
342
342
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"
351
351
352-- | Matrix builder function. Constructs a matrix provided with
352-- | Matrix builder function. Constructs a matrix provided with
@@ -376,7 +376,7 @@ row = fromLists . (: [])
376--
376--
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 ::
384 ) =>
384 ) =>
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 =
405
405
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' ::
413 ) =>
413 ) =>
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)
443
443
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 ..]]
476
476
477−-- Identity Matrix
477+-- iden Matrix
478
478
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 #-}
483
483
484-- Matrix composition (MMM)
484-- Matrix composition (MMM)
485
485
@@ -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
500#-}
500#-}
501
501
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
506p1 =
506p1 =
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
510
510
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
513p2 =
513p2 =
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
517
517
518-- Injections
518-- Injections
519
519
@@ -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)
568
568
569-- Khatri Rao Product and projections
569-- Khatri Rao Product and projections
570
570
571-- | Khatri Rao product first component projection matrix.
571-- | Khatri Rao product first component projection matrix.
572−kp1 ::
572+fstM ::
573 forall e m k .
573 forall e m k .
574 ( Num e,
574 ( Num e,
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
580 where
580 where
581 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
581 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
582 f (x, y)
582 f (x, y)
@@ -584,14 +584,14 @@ kp1 = matrixBuilder f
584 | otherwise = 0
584 | otherwise = 0
585
585
586-- | Khatri Rao product second component projection matrix.
586-- | Khatri Rao product second component projection matrix.
587−kp2 ::
587+sndM ::
588 forall e m k .
588 forall e m k .
589 ( Num e,
589 ( Num e,
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
595 where
595 where
596 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
596 offset = fromInteger (natVal (Proxy :: Proxy (Count k)))
597 f (x, y)
597 f (x, y)
@@ -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:
604--
604--
605-- @
605-- @
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
609-- @
609-- @
610--
610--
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
624
624
625-- Product Bifunctor (Kronecker)
625-- Product Bifunctor (Kronecker)
626
626
@@ -640,39 +640,39 @@ infixl 4 ><
640 )
640 )
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')
646
646
647−-- Matrix abide Junc Split
647+-- Matrix abide Join Fork
648
648
649−-- | Matrix "abiding" followin the 'Junc'-'Split' abide law.
649+-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
650--
650--
651-- Law:
651-- Law:
652--
652--
653-- @
653-- @
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)
655-- @
655-- @
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)
662
662
663−-- Matrix abide Split Junc
663+-- Matrix abide Fork Join
664
664
665−-- | Matrix "abiding" followin the 'Split'-'Junc' abide law.
665+-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
666--
666--
667-- @
667-- @
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)
669-- @
669-- @
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)
676
676
677-- Matrix transposition
677-- Matrix transposition
678
678
@@ -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)
685
685
686-- Selective 'select' operator
686-- Selective 'select' operator
687
687
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
694
694
695branch ::
695branch ::
696 ( Num e,
696 ( Num e,
@@ -711,7 +711,7 @@ branch x l r = f x `select` g l `select` r
711 where
711 where
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
717
717
@@ -731,7 +731,7 @@ cond ::
731 )
731 )
732 =>
732 =>
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
735
735
736grd ::
736grd ::
737 ( Trivial q,
737 ( Trivial q,
@@ -746,7 +746,7 @@ grd ::
746 )
746 )
747 =>
747 =>
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))
750
750
751corr ::
751corr ::
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
759 )
759 )
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)
763
763
764-- Pretty print
764-- Pretty print
765
765
@@ -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
826
826
827-- Relational operators functions
827-- Relational operators functions
828
828
@@ -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)
850
850
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
859
859
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
868
868
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
877
877
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
885
885
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)
893
893
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)
905--
905--
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 ::
913 ) =>
913 ) =>
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 =
934
934
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' ::
942 ) =>
942 ) =>
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
src/LAoP/Matrix/Nat.hs+34−34
@@ -69,8 +69,8 @@ module LAoP.Matrix.Nat
69 -- * Primitives
69 -- * Primitives
70 empty,
70 empty,
71 one,
71 one,
72− junc,
72+ join,
73− split,
73+ fork,
74
74
75 -- * Auxiliary type families
75 -- * Auxiliary type families
76 I.FromNat,
76 I.FromNat,
@@ -112,12 +112,12 @@ module LAoP.Matrix.Nat
112 zipWithM,
112 zipWithM,
113
113
114 -- * Biproduct approach
114 -- * Biproduct approach
115− -- ** Split
115+ -- ** Fork
116 (===),
116 (===),
117 -- *** Projections
117 -- *** Projections
118 p1,
118 p1,
119 p2,
119 p2,
120− -- ** Junc
120+ -- ** Join
121 (|||),
121 (|||),
122 -- *** Injections
122 -- *** Injections
123 i1,
123 i1,
@@ -131,8 +131,8 @@ module LAoP.Matrix.Nat
131 -- | Note that given the restrictions imposed it is not possible to
131 -- | Note that given the restrictions imposed it is not possible to
132 -- implement the standard type classes present in standard Haskell.
132 -- implement the standard type classes present in standard Haskell.
133 -- *** Matrix pairing projections
133 -- *** Matrix pairing projections
134− kp1,
134+ fstM,
135− kp2,
135+ sndM,
136
136
137 -- *** Matrix pairing
137 -- *** Matrix pairing
138 khatri,
138 khatri,
@@ -143,10 +143,10 @@ module LAoP.Matrix.Nat
143
143
144 -- | Note that given the restrictions imposed it is not possible to
144 -- | Note that given the restrictions imposed it is not possible to
145 -- implement the standard type classes present in standard Haskell.
145 -- implement the standard type classes present in standard Haskell.
146− identity,
146+ iden,
147 comp,
147 comp,
148− fromF,
149 fromF',
148 fromF',
149+ fromF,
150
150
151 -- * Matrix printing
151 -- * Matrix printing
152 pretty,
152 pretty,
@@ -179,7 +179,7 @@ type TrivialP a b = I.FromNat (a * b) ~ I.FromNat (I.Count (I.FromNa
179-- implementation is 'undefined'. However 'comp' can be and this partial
179-- implementation is 'undefined'. However 'comp' can be and this partial
180-- class implementation exists just to make the code more readable.
180-- class implementation exists just to make the code more readable.
181--
181--
182−-- Please use 'identity' instead.
182+-- Please use 'iden' instead.
183instance (Num e) => C.Category (Matrix e) where
183instance (Num e) => C.Category (Matrix e) where
184 id = undefined
184 id = undefined
185 (.) = comp
185 (.) = comp
@@ -192,12 +192,12 @@ empty = M I.Empty
192one :: e -> Matrix e 1 1
192one :: e -> Matrix e 1 1
193one = M . I.One
193one = M . I.One
194
194
195−junc ::
195+join ::
196 (TrivialE a b) =>
196 (TrivialE a b) =>
197 Matrix e a rows ->
197 Matrix e a rows ->
198 Matrix e b rows ->
198 Matrix e b rows ->
199 Matrix e (a + b) rows
199 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)
201
201
202infixl 3 |||
202infixl 3 |||
203(|||) ::
203(|||) ::
@@ -205,14 +205,14 @@ infixl 3 |||
205 Matrix e a rows ->
205 Matrix e a rows ->
206 Matrix e b rows ->
206 Matrix e b rows ->
207 Matrix e (a + b) rows
207 Matrix e (a + b) rows
208−(|||) = junc
208+(|||) = join
209
209
210−split ::
210+fork ::
211 (TrivialE a b) =>
211 (TrivialE a b) =>
212 Matrix e cols a ->
212 Matrix e cols a ->
213 Matrix e cols b ->
213 Matrix e cols b ->
214 Matrix e cols (a + b)
214 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)
216
216
217infixl 2 ===
217infixl 2 ===
218(===) ::
218(===) ::
@@ -220,7 +220,7 @@ infixl 2 ===
220 Matrix e cols a ->
220 Matrix e cols a ->
221 Matrix e cols b ->
221 Matrix e cols b ->
222 Matrix e cols (a + b)
222 Matrix e cols (a + b)
223−(===) = split
223+(===) = fork
224
224
225-- Construction
225-- Construction
226
226
@@ -238,7 +238,7 @@ col = M . I.col
238row :: (I.FromLists e (I.FromNat cols) ()) => [e] -> Matrix e cols 1
238row :: (I.FromLists e (I.FromNat cols) ()) => [e] -> Matrix e cols 1
239row = M . I.row
239row = M . I.row
240
240
241−fromF ::
241+fromF' ::
242 ( Liftable e a b,
242 ( Liftable e a b,
243 CountableN cols,
243 CountableN cols,
244 CountableN rows,
244 CountableN rows,
@@ -246,9 +246,9 @@ fromF ::
246 ) =>
246 ) =>
247 (a -> b) ->
247 (a -> b) ->
248 Matrix e cols rows
248 Matrix e cols rows
249−fromF = M . I.fromF
249+fromF' = M . I.fromF'
250
250
251−fromF' ::
251+fromF ::
252 ( Liftable e a b,
252 ( Liftable e a b,
253 CountableNz a,
253 CountableNz a,
254 CountableNz b,
254 CountableNz b,
@@ -256,7 +256,7 @@ fromF' ::
256 ) =>
256 ) =>
257 (a -> b) ->
257 (a -> b) ->
258 Matrix e (I.Count a) (I.Count b)
258 Matrix e (I.Count a) (I.Count b)
259−fromF' = undefined -- M . I.fromF'
259+fromF = undefined -- M . I.fromF
260
260
261-- Conversion
261-- Conversion
262
262
@@ -296,12 +296,12 @@ bang ::
296 Matrix e cols 1
296 Matrix e cols 1
297bang = M I.bang
297bang = M I.bang
298
298
299−-- Identity Matrix
299+-- iden Matrix
300
300
301−identity ::
301+iden ::
302 (Num e, FromListsN e cols cols, CountableN cols) =>
302 (Num e, FromListsN e cols cols, CountableN cols) =>
303 Matrix e cols cols
303 Matrix e cols cols
304−identity = M I.identity
304+iden = M I.iden
305
305
306-- Matrix composition (MMM)
306-- Matrix composition (MMM)
307
307
@@ -377,7 +377,7 @@ infixl 5 -|-
377(-|-) (M a) (M b) = M ((I.-|-) a b)
377(-|-) (M a) (M b) = M ((I.-|-) a b)
378
378
379-- | Khatri Rao Product and projections
379-- | Khatri Rao Product and projections
380−kp1 ::
380+fstM ::
381 forall e m k .
381 forall e m k .
382 ( Num e,
382 ( Num e,
383 CountableDimensionsN m k,
383 CountableDimensionsN m k,
@@ -385,9 +385,9 @@ kp1 ::
385 FromListsN e (m * k) m,
385 FromListsN e (m * k) m,
386 TrivialP m k
386 TrivialP m k
387 ) => Matrix e (m * k) m
387 ) => 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))
389
389
390−kp2 ::
390+sndM ::
391 forall e m k.
391 forall e m k.
392 ( Num e,
392 ( Num e,
393 CountableDimensionsN k m,
393 CountableDimensionsN k m,
@@ -395,7 +395,7 @@ kp2 ::
395 CountableN (m * k),
395 CountableN (m * k),
396 TrivialP m k
396 TrivialP m k
397 ) => Matrix e (m * k) k
397 ) => 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))
399
399
400khatri ::
400khatri ::
401 forall e cols a b.
401 forall e cols a b.
@@ -407,9 +407,9 @@ khatri ::
407 TrivialP a b
407 TrivialP a b
408 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a * b)
408 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a * b)
409khatri a b =
409khatri a b =
410− let kp1' = kp1 @e @a @b
410+ let fstM' = fstM @e @a @b
411− kp2' = kp2 @e @a @b
411+ sndM' = sndM @e @a @b
412− in comp (tr kp1') a * comp (tr kp2') b
412+ in comp (tr fstM') a * comp (tr sndM') b
413
413
414-- | Product Bifunctor (Kronecker)
414-- | Product Bifunctor (Kronecker)
415infixl 4 ><
415infixl 4 ><
@@ -428,15 +428,15 @@ infixl 4 ><
428 TrivialP p q
428 TrivialP p q
429 ) => Matrix e m p -> Matrix e n q -> Matrix e (m * n) (p * q)
429 ) => Matrix e m p -> Matrix e n q -> Matrix e (m * n) (p * q)
430(><) a b =
430(><) a b =
431− let kp1' = kp1 @e @m @n
431+ let fstM' = fstM @e @m @n
432− kp2' = kp2 @e @m @n
432+ sndM' = sndM @e @m @n
433− in khatri (comp a kp1') (comp b kp2')
433+ in khatri (comp a fstM') (comp b sndM')
434
434
435−-- | Matrix abide Junc Split
435+-- | Matrix abide Join Fork
436abideJS :: Matrix e cols rows -> Matrix e cols rows
436abideJS :: Matrix e cols rows -> Matrix e cols rows
437abideJS (M m) = M (I.abideJS m)
437abideJS (M m) = M (I.abideJS m)
438
438
439−-- | Matrix abide Split Junc
439+-- | Matrix abide Fork Join
440abideSJ :: Matrix e cols rows -> Matrix e cols rows
440abideSJ :: Matrix e cols rows -> Matrix e cols rows
441abideSJ (M m) = M (I.abideSJ m)
441abideSJ (M m) = M (I.abideSJ m)
442
442
src/LAoP/Matrix/Type.hs+51−51
@@ -73,8 +73,8 @@ module LAoP.Matrix.Type
73 -- * Primitives
73 -- * Primitives
74 empty,
74 empty,
75 one,
75 one,
76− junc,
76+ join,
77− split,
77+ fork,
78
78
79 -- * Auxiliary type families
79 -- * Auxiliary type families
80 I.FromNat,
80 I.FromNat,
@@ -129,12 +129,12 @@ module LAoP.Matrix.Type
129 zipWithM,
129 zipWithM,
130
130
131 -- * Biproduct approach
131 -- * Biproduct approach
132− -- ** Split
132+ -- ** Fork
133 (===),
133 (===),
134 -- *** Projections
134 -- *** Projections
135 p1,
135 p1,
136 p2,
136 p2,
137− -- ** Junc
137+ -- ** Join
138 (|||),
138 (|||),
139 -- *** Injections
139 -- *** Injections
140 i1,
140 i1,
@@ -148,8 +148,8 @@ module LAoP.Matrix.Type
148 -- | Note that given the restrictions imposed it is not possible to
148 -- | Note that given the restrictions imposed it is not possible to
149 -- implement the standard type classes present in standard Haskell.
149 -- implement the standard type classes present in standard Haskell.
150 -- *** Matrix pairing projections
150 -- *** Matrix pairing projections
151− kp1,
151+ fstM,
152− kp2,
152+ sndM,
153
153
154 -- *** Matrix pairing
154 -- *** Matrix pairing
155 khatri,
155 khatri,
@@ -160,10 +160,10 @@ module LAoP.Matrix.Type
160
160
161 -- | Note that given the restrictions imposed it is not possible to
161 -- | Note that given the restrictions imposed it is not possible to
162 -- implement the standard type classes present in standard Haskell.
162 -- implement the standard type classes present in standard Haskell.
163− identity,
163+ iden,
164 comp,
164 comp,
165− fromF,
166 fromF',
165 fromF',
166+ fromF,
167
167
168 -- * Relation
168 -- * Relation
169 toRel,
169 toRel,
@@ -202,7 +202,7 @@ type TrivialP a b = I.Normalize (a, b) ~ I.Normalize (I.Normalize a,
202-- implementation is 'undefined'. However 'comp' can be and this partial
202-- implementation is 'undefined'. However 'comp' can be and this partial
203-- class implementation exists just to make the code more readable.
203-- class implementation exists just to make the code more readable.
204--
204--
205−-- Please use 'identity' instead.
205+-- Please use 'iden' instead.
206instance (Num e) => C.Category (Matrix e) where
206instance (Num e) => C.Category (Matrix e) where
207 id = undefined
207 id = undefined
208 (.) = comp
208 (.) = comp
@@ -216,7 +216,7 @@ bimapM ::
216 FromListsN e d c,
216 FromListsN e d c,
217 FromListsN e b a
217 FromListsN e b a
218 ) => (a -> b) -> (c -> d) -> Matrix e a c -> Matrix e b d
218 ) => (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)
220
220
221-- | Zero type alias
221-- | Zero type alias
222type Zero = Void
222type Zero = Void
@@ -234,35 +234,35 @@ empty = M I.Empty
234one :: e -> Matrix e One One
234one :: e -> Matrix e One One
235one = M . I.One
235one = M . I.One
236
236
237−-- | Matrix 'Junc' constructor
237+-- | Matrix 'Join' constructor
238−junc ::
238+join ::
239 Matrix e a rows ->
239 Matrix e a rows ->
240 Matrix e b rows ->
240 Matrix e b rows ->
241 Matrix e (Either a b) rows
241 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)
243
243
244infixl 3 |||
244infixl 3 |||
245−-- | Matrix 'Junc' constructor
245+-- | Matrix 'Join' constructor
246(|||) ::
246(|||) ::
247 Matrix e a rows ->
247 Matrix e a rows ->
248 Matrix e b rows ->
248 Matrix e b rows ->
249 Matrix e (Either a b) rows
249 Matrix e (Either a b) rows
250−(|||) = junc
250+(|||) = join
251
251
252−-- | Matrix 'Split' constructor
252+-- | Matrix 'Fork' constructor
253−split ::
253+fork ::
254 Matrix e cols a ->
254 Matrix e cols a ->
255 Matrix e cols b ->
255 Matrix e cols b ->
256 Matrix e cols (Either a b)
256 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)
258
258
259infixl 2 ===
259infixl 2 ===
260−-- | Matrix 'Split' constructor
260+-- | Matrix 'Fork' constructor
261(===) ::
261(===) ::
262 Matrix e cols a ->
262 Matrix e cols a ->
263 Matrix e cols b ->
263 Matrix e cols b ->
264 Matrix e cols (Either a b)
264 Matrix e cols (Either a b)
265−(===) = split
265+(===) = fork
266
266
267-- Functor hierarchy
267-- Functor hierarchy
268
268
@@ -274,7 +274,7 @@ fmapM ::
274 )
274 )
275 =>
275 =>
276 (a -> b) -> Matrix e c a -> Matrix e c b
276 (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
278
278
279-- | Applicative instance equivalent 'unit' function,
279-- | Applicative instance equivalent 'unit' function,
280unitM :: (Num e) => Matrix e () ()
280unitM :: (Num e) => Matrix e () ()
@@ -336,23 +336,23 @@ row = M . I.row
336--
336--
337-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
337-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
338-- types @a@ or @b@ allows.
338-- types @a@ or @b@ allows.
339−fromF ::
339+fromF' ::
340 ( Liftable e a b,
340 ( Liftable e a b,
341 CountableDimensionsN cols rows,
341 CountableDimensionsN cols rows,
342 FromListsN e rows cols
342 FromListsN e rows cols
343 ) =>
343 ) =>
344 (a -> b) -> Matrix e cols rows
344 (a -> b) -> Matrix e cols rows
345−fromF = M . I.fromF
345+fromF' = M . I.fromF'
346
346
347-- | Lifts functions to matrices with dimensions matching @a@ and @b@
347-- | Lifts functions to matrices with dimensions matching @a@ and @b@
348-- cardinality's.
348-- cardinality's.
349−fromF' ::
349+fromF ::
350 ( Liftable e a b,
350 ( Liftable e a b,
351 CountableDimensionsN a b,
351 CountableDimensionsN a b,
352 FromListsN e b a
352 FromListsN e b a
353 ) =>
353 ) =>
354 (a -> b) -> Matrix e a b
354 (a -> b) -> Matrix e a b
355−fromF' = M . I.fromF'
355+fromF = M . I.fromF
356
356
357-- | Lifts relation functions to Boolean Matrix
357-- | Lifts relation functions to Boolean Matrix
358toRel ::
358toRel ::
@@ -418,16 +418,16 @@ point ::
418 CountableN a,
418 CountableN a,
419 FromListsN e a One
419 FromListsN e a One
420 ) => a -> Matrix e One a
420 ) => a -> Matrix e One a
421−point = fromF' . const
421+point = fromF . const
422
422
423−-- Identity Matrix
423+-- iden Matrix
424
424
425−-- | Identity matrix
425+-- | iden matrix
426−identity ::
426+iden ::
427 (Num e, FromListsN e a a, CountableN a) =>
427 (Num e, FromListsN e a a, CountableN a) =>
428 Matrix e a a
428 Matrix e a a
429−identity = M I.identity
429+iden = M I.iden
430−{-# NOINLINE identity #-}
430+{-# NOINLINE iden #-}
431
431
432-- Matrix composition (MMM)
432-- Matrix composition (MMM)
433
433
@@ -439,8 +439,8 @@ comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
439comp (M a) (M b) = M (I.comp a b)
439comp (M a) (M b) = M (I.comp a b)
440{-# NOINLINE comp #-}
440{-# NOINLINE comp #-}
441{-# RULES
441{-# RULES
442− "comp/identity1" forall m. comp m identity = m ;
442+ "comp/iden1" forall m. comp m iden = m ;
443− "comp/identity2" forall m. comp identity m = m
443+ "comp/iden2" forall m. comp iden m = m
444#-}
444#-}
445
445
446-- | Biproduct first component projection
446-- | Biproduct first component projection
@@ -528,7 +528,7 @@ infixl 5 -|-
528-- Khatri Rao Product and projections
528-- Khatri Rao Product and projections
529
529
530-- | Khatri Rao product first component projection matrix.
530-- | Khatri Rao product first component projection matrix.
531−kp1 ::
531+fstM ::
532 forall e m k .
532 forall e m k .
533 ( Num e,
533 ( Num e,
534 CountableDimensionsN m k,
534 CountableDimensionsN m k,
@@ -536,10 +536,10 @@ kp1 ::
536 FromListsN e (m, k) m,
536 FromListsN e (m, k) m,
537 TrivialP m k
537 TrivialP m k
538 ) => Matrix e (m, k) m
538 ) => 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))
540
540
541-- | Khatri Rao product second component projection matrix.
541-- | Khatri Rao product second component projection matrix.
542−kp2 ::
542+sndM ::
543 forall e m k.
543 forall e m k.
544 ( Num e,
544 ( Num e,
545 CountableDimensionsN k m,
545 CountableDimensionsN k m,
@@ -547,16 +547,16 @@ kp2 ::
547 FromListsN e (m, k) k,
547 FromListsN e (m, k) k,
548 TrivialP m k
548 TrivialP m k
549 ) => Matrix e (m, k) k
549 ) => 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))
551
551
552-- | Khatri Rao Matrix product also known as matrix pairing.
552-- | Khatri Rao Matrix product also known as matrix pairing.
553--
553--
554-- NOTE: That this is not a true categorical product, see for instance:
554-- NOTE: That this is not a true categorical product, see for instance:
555--
555--
556-- @
556-- @
557−-- | kp1 `comp` khatri a b == a
557+-- | fstM `comp` khatri a b == a
558-- khatri a b ==> |
558-- khatri a b ==> |
559−-- | kp2 `comp` khatri a b == b
559+-- | sndM `comp` khatri a b == b
560-- @
560-- @
561--
561--
562-- __Emphasis__ on the implication symbol.
562-- __Emphasis__ on the implication symbol.
@@ -570,9 +570,9 @@ khatri ::
570 TrivialP a b
570 TrivialP a b
571 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a, b)
571 ) => Matrix e cols a -> Matrix e cols b -> Matrix e cols (a, b)
572khatri a b =
572khatri a b =
573− let kp1' = kp1 @e @a @b
573+ let fstM' = fstM @e @a @b
574− kp2' = kp2 @e @a @b
574+ sndM' = sndM @e @a @b
575− in comp (tr kp1') a * comp (tr kp2') b
575+ in comp (tr fstM') a * comp (tr sndM') b
576
576
577-- Product Bifunctor (Kronecker)
577-- Product Bifunctor (Kronecker)
578
578
@@ -593,30 +593,30 @@ infixl 4 ><
593 TrivialP p q
593 TrivialP p q
594 ) => Matrix e m p -> Matrix e n q -> Matrix e (m, n) (p, q)
594 ) => Matrix e m p -> Matrix e n q -> Matrix e (m, n) (p, q)
595(><) a b =
595(><) a b =
596− let kp1' = kp1 @e @m @n
596+ let fstM' = fstM @e @m @n
597− kp2' = kp2 @e @m @n
597+ sndM' = sndM @e @m @n
598− in khatri (comp a kp1') (comp b kp2')
598+ in khatri (comp a fstM') (comp b sndM')
599
599
600−-- Matrix abide Junc Split
600+-- Matrix abide Join Fork
601
601
602−-- | Matrix "abiding" followin the 'Junc'-'Split' abide law.
602+-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
603--
603--
604-- Law:
604-- Law:
605--
605--
606-- @
606-- @
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)
608-- @
608-- @
609abideJS :: Matrix e cols rows -> Matrix e cols rows
609abideJS :: Matrix e cols rows -> Matrix e cols rows
610abideJS (M m) = M (I.abideJS m)
610abideJS (M m) = M (I.abideJS m)
611
611
612−-- Matrix abide Split Junc
612+-- Matrix abide Fork Join
613
613
614−-- | Matrix "abiding" followin the 'Split'-'Junc' abide law.
614+-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
615--
615--
616-- Law:
616-- Law:
617--
617--
618-- @
618-- @
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)
620-- @
620-- @
621abideSJ :: Matrix e cols rows -> Matrix e cols rows
621abideSJ :: Matrix e cols rows -> Matrix e cols rows
622abideSJ (M m) = M (I.abideSJ m)
622abideSJ (M m) = M (I.abideSJ m)
src/LAoP/Relation.hs+5−5
@@ -43,9 +43,9 @@ module LAoP.Relation
43 -- * Primitives
43 -- * Primitives
44 empty,
44 empty,
45 one,
45 one,
46− junc,
46+ join,
47 (|||),
47 (|||),
48− split,
48+ fork,
49 (===),
49 (===),
50
50
51 -- * Auxiliary type families
51 -- * Auxiliary type families
@@ -108,8 +108,8 @@ module LAoP.Relation
108 splitR,
108 splitR,
109
109
110 -- ** Projections
110 -- ** Projections
111− p1,
111+ fstR,
112− p2,
112+ sndR,
113 -- ** Bifunctor
113 -- ** Bifunctor
114 (><),
114 (><),
115 -- * Relational coproduct
115 -- * Relational coproduct
@@ -148,7 +148,7 @@ module LAoP.Relation
148 cond,
148 cond,
149
149
150 -- * Relational composition and lifting
150 -- * Relational composition and lifting
151− identity,
151+ iden,
152 comp,
152 comp,
153 fromF,
153 fromF,
154 fromF',
154 fromF',
src/LAoP/Relation/Internal.hs+62−62
@@ -53,9 +53,9 @@ module LAoP.Relation.Internal
53 -- * Primitives
53 -- * Primitives
54 empty,
54 empty,
55 one,
55 one,
56− junc,
56+ join,
57 (|||),
57 (|||),
58− split,
58+ fork,
59 (===),
59 (===),
60
60
61 -- * Auxiliary type families
61 -- * Auxiliary type families
@@ -66,8 +66,8 @@ module LAoP.Relation.Internal
66 -- * Matrix construction and conversion
66 -- * Matrix construction and conversion
67 I.FromLists,
67 I.FromLists,
68 fromLists,
68 fromLists,
69− fromF,
70 fromF',
69 fromF',
70+ fromF,
71 toRel,
71 toRel,
72 toLists,
72 toLists,
73 toList,
73 toList,
@@ -118,8 +118,8 @@ module LAoP.Relation.Internal
118 splitR,
118 splitR,
119
119
120 -- ** Projections
120 -- ** Projections
121− p1,
121+ fstR,
122− p2,
122+ sndR,
123 -- ** Bifunctor
123 -- ** Bifunctor
124 (><),
124 (><),
125 -- * Relational coproduct
125 -- * Relational coproduct
@@ -158,10 +158,10 @@ module LAoP.Relation.Internal
158 cond,
158 cond,
159
159
160 -- * Relational composition and lifting
160 -- * Relational composition and lifting
161− identity,
161+ iden,
162 comp,
162 comp,
163− fromF,
164 fromF',
163 fromF',
164+ fromF,
165
165
166 -- ** Relational application
166 -- ** Relational application
167 pointAp,
167 pointAp,
@@ -205,19 +205,19 @@ type TrivialP a b = I.Normalize (a, b) ~ I.Normalize (I.Normalize a,
205-- implementation is 'undefined'. However 'comp' can be and this partial
205-- implementation is 'undefined'. However 'comp' can be and this partial
206-- class implementation exists just to make the code more readable.
206-- class implementation exists just to make the code more readable.
207--
207--
208−-- Please use 'identity' instead.
208+-- Please use 'iden' instead.
209instance C.Category Relation where
209instance C.Category Relation where
210 id = undefined
210 id = undefined
211 (.) = comp
211 (.) = comp
212
212
213instance Num (Relation a b) where
213instance Num (Relation a b) where
214− -- | Matrix addition becomes Boolean matrix disjunction
214+ -- | Matrix addition becomes Boolean matrix disjointion
215 (R a) + (R b) = R (I.orM a b)
215 (R a) + (R b) = R (I.orM a b)
216
216
217 -- | Matrix subtraction becomes Relational subtraction
217 -- | Matrix subtraction becomes Relational subtraction
218 (R a) - (R b) = R (I.subM a b)
218 (R a) - (R b) = R (I.subM a b)
219
219
220− -- | Matrix multiplication becomes Boolean matrix conjunction
220+ -- | Matrix multiplication becomes Boolean matrix conjointion
221 (R a) * (R b) = R (I.andM a b)
221 (R a) * (R b) = R (I.andM a b)
222
222
223 -- | Matrix negation becomes Boolean matrix negation
223 -- | Matrix negation becomes Boolean matrix negation
@@ -237,33 +237,33 @@ empty = R I.Empty
237one :: Boolean -> Relation One One
237one :: Boolean -> Relation One One
238one = R . I.One
238one = R . I.One
239
239
240−-- | Boolean Matrix 'Junc' constructor, also known as relational coproduct.
240+-- | Boolean Matrix 'Join' constructor, also known as relational coproduct.
241--
241--
242-- See 'eitherR'.
242-- See 'eitherR'.
243−junc :: Relation a c -> Relation b c -> Relation (Either a b) c
243+join :: Relation a c -> Relation b c -> Relation (Either a b) c
244−junc (R a) (R b) = R (I.Junc a b)
244+join (R a) (R b) = R (I.Join a b)
245
245
246infixl 3 |||
246infixl 3 |||
247−-- | Boolean Matrix 'Junc' constructor
247+-- | Boolean Matrix 'Join' constructor
248--
248--
249-- See 'eitherR'.
249-- See 'eitherR'.
250(|||) ::
250(|||) ::
251 Relation a c ->
251 Relation a c ->
252 Relation b c ->
252 Relation b c ->
253 Relation (Either a b) c
253 Relation (Either a b) c
254−(|||) = junc
254+(|||) = join
255
255
256−-- | Boolean Matrix 'Split' constructor, also known as relational product.
256+-- | Boolean Matrix 'Fork' constructor, also known as relational product.
257−split :: Relation c a -> Relation c b -> Relation c (Either a b)
257+fork :: Relation c a -> Relation c b -> Relation c (Either a b)
258−split (R a) (R b) = R (I.Split a b)
258+fork (R a) (R b) = R (I.Fork a b)
259
259
260infixl 2 ===
260infixl 2 ===
261−-- | Boolean Matrix 'Split' constructor
261+-- | Boolean Matrix 'Fork' constructor
262(===) ::
262(===) ::
263 Relation c a ->
263 Relation c a ->
264 Relation c b ->
264 Relation c b ->
265 Relation c (Either a b)
265 Relation c (Either a b)
266−(===) = split
266+(===) = fork
267
267
268-- Construction
268-- Construction
269
269
@@ -283,23 +283,23 @@ relationBuilder = R . I.matrixBuilder
283--
283--
284-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
284-- NOTE: Be careful to not ask for a matrix bigger than the cardinality of
285-- types @a@ or @b@ allows.
285-- types @a@ or @b@ allows.
286−fromF ::
286+fromF' ::
287 ( Liftable a b,
287 ( Liftable a b,
288 CountableDimensionsN c d,
288 CountableDimensionsN c d,
289 FromListsN d c
289 FromListsN d c
290 )
290 )
291 => (a -> b) -> Relation c d
291 => (a -> b) -> Relation c d
292−fromF f = R (I.fromFRel f)
292+fromF' f = R (I.fromFRel' f)
293
293
294-- | Lifts functions to matrices with dimensions matching @a@ and @b@
294-- | Lifts functions to matrices with dimensions matching @a@ and @b@
295-- cardinality's.
295-- cardinality's.
296−fromF' ::
296+fromF ::
297 ( Liftable a b,
297 ( Liftable a b,
298 CountableDimensionsN a b,
298 CountableDimensionsN a b,
299 FromListsN b a
299 FromListsN b a
300 )
300 )
301 => (a -> b) -> Relation a b
301 => (a -> b) -> Relation a b
302−fromF' f = R (I.fromFRel' f)
302+fromF f = R (I.fromFRel f)
303
303
304-- | Lifts relation functions to 'Relation'
304-- | Lifts relation functions to 'Relation'
305toRel ::
305toRel ::
@@ -412,18 +412,18 @@ point ::
412 CountableN a,
412 CountableN a,
413 FromListsN a One
413 FromListsN a One
414 ) => a -> Relation One a
414 ) => a -> Relation One a
415−point = fromF' . const
415+point = fromF . const
416
416
417−-- Identity Matrix
417+-- iden Matrix
418
418
419−-- | Identity matrix
419+-- | iden matrix
420--
420--
421-- @
421-- @
422−-- 'identity' ``comp`` r == r == r ``comp`` 'identity'
422+-- 'iden' ``comp`` r == r == r ``comp`` 'iden'
423-- @
423-- @
424−identity ::
424+iden ::
425 (FromListsN a a, CountableN a) => Relation a a
425 (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 (==))
427
427
428-- | Relational composition
428-- | Relational composition
429--
429--
@@ -530,7 +530,7 @@ iff r s = r == s
530
530
531-- | Relational intersection
531-- | Relational intersection
532--
532--
533−-- Lifts pointwise conjunction.
533+-- Lifts pointwise conjointion.
534--
534--
535-- @
535-- @
536-- (r ``intersection`` s) ``intersection`` t == r ``intersection`` (s ``intersection`` t)
536-- (r ``intersection`` s) ``intersection`` t == r ``intersection`` (s ``intersection`` t)
@@ -541,7 +541,7 @@ intersection a b = a * b
541
541
542-- | Relational union
542-- | Relational union
543--
543--
544−-- Lifts pointwise disjunction.
544+-- Lifts pointwise disjointion.
545--
545--
546-- @
546-- @
547-- (r ``union`` s) ``union`` t == r `'union' (s ``union`` t)
547-- (r ``union`` s) ``union`` t == r `'union' (s ``union`` t)
@@ -658,13 +658,13 @@ bijection r = injection r && surjection r
658
658
659-- Properties of relations
659-- Properties of relations
660
660
661−-- | A 'Relation' @r@ is 'reflexive' 'iff' @'identity' ``sse`` r@
661+-- | A 'Relation' @r@ is 'reflexive' 'iff' @'iden' ``sse`` r@
662reflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
662reflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
663−reflexive r = identity <= r
663+reflexive r = iden <= r
664
664
665−-- | A 'Relation' @r@ is 'coreflexive' 'iff' @r ``sse`` 'identity'@
665+-- | A 'Relation' @r@ is 'coreflexive' 'iff' @r ``sse`` 'iden'@
666coreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
666coreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
667−coreflexive r = r <= identity
667+coreflexive r = r <= iden
668
668
669-- | A 'Relation' @r@ is 'transitive' 'iff' @(r ``comp`` r) ``sse`` r@
669-- | A 'Relation' @r@ is 'transitive' 'iff' @(r ``comp`` r) ``sse`` r@
670transitive :: Relation a a -> Bool
670transitive :: Relation a a -> Bool
@@ -674,13 +674,13 @@ transitive r = (r `comp` r) `sse` r
674symmetric :: Relation a a -> Bool
674symmetric :: Relation a a -> Bool
675symmetric r = r == conv r
675symmetric r = r == conv r
676
676
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'@
678antiSymmetric :: (CountableN a, FromListsN a a) => Relation a a -> Bool
678antiSymmetric :: (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
680
680
681−-- | A 'Relation' @r@ is 'irreflexive' 'iff' @(r ``intersection`` 'identity') == 'zeros'@
681+-- | A 'Relation' @r@ is 'irreflexive' 'iff' @(r ``intersection`` 'iden') == 'zeros'@
682irreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
682irreflexive :: (CountableN a, FromListsN a a) => Relation a a -> Bool
683−irreflexive r = (r `intersection` identity) == zeros
683+irreflexive r = (r `intersection` iden) == zeros
684
684
685-- | A 'Relation' @r@ is 'connected' 'iff' @(r ``union`` 'conv' r) == 'ones'@
685-- | A 'Relation' @r@ is 'connected' 'iff' @(r ``union`` 'conv' r) == 'ones'@
686connected :: (CountableN a, FromListsN a a) => Relation a a -> Bool
686connected :: (CountableN a, FromListsN a a) => Relation a a -> Bool
@@ -718,9 +718,9 @@ difunctional r = r `comp` conv r `comp` r == r
718-- NOTE: That this is not a true categorical product, see for instance:
718-- NOTE: That this is not a true categorical product, see for instance:
719--
719--
720-- @
720-- @
721−-- | 'p1' ``comp`` 'splitR' a b ``sse`` a
721+-- | 'fstR' ``comp`` 'splitR' a b ``sse`` a
722-- 'splitR' a b <=> |
722-- 'splitR' a b <=> |
723−-- | 'p2' ``comp`` 'splitR' a b ``sse`` b
723+-- | 'sndR' ``comp`` 'splitR' a b ``sse`` b
724-- @
724-- @
725--
725--
726-- __Emphasis__ on the 'sse'.
726-- __Emphasis__ on the 'sse'.
@@ -747,9 +747,9 @@ splitR (R f) (R g) = R (I.khatri f g)
747-- | Relational pairing first component projection
747-- | Relational pairing first component projection
748--
748--
749-- @
749-- @
750−-- 'p1' ``comp`` 'splitR' r s ``sse`` r
750+-- 'fstR' ``comp`` 'splitR' r s ``sse`` r
751-- @
751-- @
752−p1 ::
752+fstR ::
753 forall a b .
753 forall a b .
754 ( CountableDimensionsN a b,
754 ( CountableDimensionsN a b,
755 CountableN (a, b),
755 CountableN (a, b),
@@ -757,14 +757,14 @@ p1 ::
757 TrivialP a b
757 TrivialP a b
758 )
758 )
759 => Relation (a, b) a
759 => 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))
761
761
762-- | Relational pairing second component projection
762-- | Relational pairing second component projection
763--
763--
764-- @
764-- @
765−-- 'p2' ``comp`` 'splitR' r s ``sse`` s
765+-- 'sndR' ``comp`` 'splitR' r s ``sse`` s
766-- @
766-- @
767−p2 ::
767+sndR ::
768 forall a b .
768 forall a b .
769 ( CountableDimensionsN a b,
769 ( CountableDimensionsN a b,
770 CountableN (a, b),
770 CountableN (a, b),
@@ -772,7 +772,7 @@ p2 ::
772 TrivialP a b
772 TrivialP a b
773 )
773 )
774 => Relation (a, b) b
774 => 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))
776
776
777-- Relational pairing functor
777-- Relational pairing functor
778
778
@@ -780,7 +780,7 @@ infixl 4 ><
780-- | Relational pairing functor
780-- | Relational pairing functor
781--
781--
782-- @
782-- @
783−-- r '><' s == 'splitR' (r ``comp`` p1) (s ``comp`` p2)
783+-- r '><' s == 'splitR' (r ``comp`` fstR) (s ``comp`` sndR)
784-- (r '><' s) ``comp`` (p '><' q) == (r ``comp`` p) '><' (s ``comp`` q)
784-- (r '><' s) ``comp`` (p '><' q) == (r ``comp`` p) '><' (s ``comp`` q)
785-- @
785-- @
786(><) ::
786(><) ::
@@ -815,12 +815,12 @@ infixl 4 ><
815-- 'eitherR' ('splitR' r s) ('splitR' t v) == 'splitR' ('eitherR' r t) ('eitherR' s v)
815-- 'eitherR' ('splitR' r s) ('splitR' t v) == 'splitR' ('eitherR' r t) ('eitherR' s v)
816-- @
816-- @
817eitherR :: Relation a c -> Relation b c -> Relation (Either a b) c
817eitherR :: Relation a c -> Relation b c -> Relation (Either a b) c
818−eitherR = junc
818+eitherR = join
819
819
820-- | Relational coproduct first component injection
820-- | Relational coproduct first component injection
821--
821--
822-- @
822-- @
823−-- 'img' 'i1' ``union`` 'img' 'i2' == 'identity'
823+-- 'img' 'i1' ``union`` 'img' 'i2' == 'iden'
824-- 'i1' ``comp`` 'i2' = 'zeros'
824-- 'i1' ``comp`` 'i2' = 'zeros'
825-- @
825-- @
826i1 ::
826i1 ::
@@ -834,7 +834,7 @@ i1 = R I.i1
834-- | Relational coproduct second component injection
834-- | Relational coproduct second component injection
835--
835--
836-- @
836-- @
837−-- 'img' 'i1' ``union`` 'img' 'i2' == 'identity'
837+-- 'img' 'i1' ``union`` 'img' 'i2' == 'iden'
838-- 'i1' ``comp`` 'i2' = 'zeros'
838-- 'i1' ``comp`` 'i2' = 'zeros'
839-- @
839-- @
840i2 ::
840i2 ::
@@ -883,7 +883,7 @@ trans ::
883 TrivialP c b
883 TrivialP c b
884 )
884 )
885 => Relation (a, b) c -> Relation a (c, b)
885 => 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
887
887
888-- | Relational 'untrans'
888-- | Relational 'untrans'
889--
889--
@@ -904,12 +904,12 @@ untrans ::
904 TrivialP c b
904 TrivialP c b
905 )
905 )
906 => Relation a (c, b) -> Relation (a, b) c
906 => 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)
908
908
909-- | Transforms predicate @p@ into a correflexive relation.
909-- | Transforms predicate @p@ into a correflexive relation.
910--
910--
911-- @
911-- @
912−-- 'predR' ('const' True) == 'identity'
912+-- 'predR' ('const' True) == 'iden'
913-- 'predR' ('const' False) == 'zeros'
913-- 'predR' ('const' False) == 'zeros'
914-- @
914-- @
915--
915--
@@ -924,14 +924,14 @@ predR ::
924 FromListsN Bool a
924 FromListsN Bool a
925 )
925 )
926 => Relation a Bool -> Relation a a
926 => 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
928
928
929-- | Equalizes functions @f@ and @g@.
929-- | Equalizes functions @f@ and @g@.
930-- That is, @'equalizer' f g@ is the largest coreflexive
930-- That is, @'equalizer' f g@ is the largest coreflexive
931-- that restricts @g@ so that @f@ and @g@ yield the same outputs.
931-- that restricts @g@ so that @f@ and @g@ yield the same outputs.
932--
932--
933-- @
933-- @
934−-- 'equalizer' r r == 'identity'
934+-- 'equalizer' r r == 'iden'
935-- 'equalizer' ('point' True) ('point' False) == 'zeros'
935-- 'equalizer' ('point' True) ('point' False) == 'zeros'
936-- @
936-- @
937equalizer ::
937equalizer ::
@@ -939,7 +939,7 @@ equalizer ::
939 FromListsN a a
939 FromListsN a a
940 )
940 )
941 => Relation a b -> Relation a b -> Relation a a
941 => 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
943
943
944-- | Relational conditional guard.
944-- | Relational conditional guard.
945--
945--
@@ -969,22 +969,22 @@ cond p r s = eitherR r s `comp` guard p
969-- | Relational domain.
969-- | Relational domain.
970--
970--
971-- For injective relations, 'domain' and 'ker'nel coincide,
971-- 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.
973domain ::
973domain ::
974 ( CountableN a,
974 ( CountableN a,
975 FromListsN a a
975 FromListsN a a
976 ) => Relation a b -> Relation a a
976 ) => Relation a b -> Relation a a
977−domain r = ker r `intersection` identity
977+domain r = ker r `intersection` iden
978
978
979-- | Relational range.
979-- | Relational range.
980--
980--
981-- For functions, 'range' and 'img' (image) coincide,
981-- 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@.
983range ::
983range ::
984 ( CountableN b,
984 ( CountableN b,
985 FromListsN b b
985 FromListsN b b
986 ) => Relation a b -> Relation b b
986 ) => Relation a b -> Relation b b
987−range r = img r `intersection` identity
987+range r = img r `intersection` iden
988
988
989-- Relation pretty print
989-- Relation pretty print
990
990