{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Math.FiniteCategory
(
FiniteCategory(..),
arrows,
arFrom,
arTo,
arFrom2,
arTo2,
arrowsWithoutId,
arFromWithoutId,
arToWithoutId,
arFrom2WithoutId,
arTo2WithoutId,
identities,
isEpic,
isMonic,
isTerminal,
isInitial,
terminalObjects,
initialObjects,
genArrows,
genArFrom,
genArTo,
genArFrom2,
genArTo2,
genArrowsWithoutId,
genArFromWithoutId,
genArToWithoutId,
genArFrom2WithoutId,
genArTo2WithoutId,
bruteForceDecompose,
pprintFiniteCategory,
module Math.Category
)
where
import Data.WeakSet (Set)
import qualified Data.WeakSet as Set
import Data.WeakSet.Safe
import Data.List (elemIndex, intercalate)
import Math.Category
import Math.IO.PrettyPrint
import Control.Monad (join)
class (Category c m o) => FiniteCategory c m o | c -> m, m -> o where
ob :: c -> Set o
arrows :: (FiniteCategory c m o, Morphism m o) => c -> Set m
arrows :: forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
arrows c
c = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
arTo :: (FiniteCategory c m o, Morphism m o) => c -> o -> Set m
arTo :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
arTo c
c o
t = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ (\o
s -> c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c o
s o
t) (o -> Set m) -> Set o -> Set (Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
arTo2 :: (FiniteCategory c m o, Morphism m o) => c -> Set o -> Set m
arTo2 :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
arTo2 c
c Set o
ts = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set o
ts
arFrom :: (FiniteCategory c m o, Morphism m o) => c -> o -> Set m
arFrom :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
arFrom c
c o
s = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c o
s (o -> Set m) -> Set o -> Set (Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
arFrom2 :: (FiniteCategory c m o, Morphism m o) => c -> Set o -> Set m
arFrom2 :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
arFrom2 c
c Set o
ss = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set o
ss Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
arrowsWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set m
arrowsWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set m
arrowsWithoutId c
c = (m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c) (c -> Set m
forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
arrows c
c)
arToWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Set m
arToWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Set m
arToWithoutId c
c o
t = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
arTo c
c o
t
arTo2WithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o -> Set m
arTo2WithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o -> Set m
arTo2WithoutId c
c Set o
ts = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> Set o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
arTo2 c
c Set o
ts
arFromWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Set m
arFromWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Set m
arFromWithoutId c
c o
s = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
arFrom c
c o
s
arFrom2WithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o -> Set m
arFrom2WithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o -> Set m
arFrom2WithoutId c
c Set o
ss = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> Set o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
arFrom2 c
c Set o
ss
genArrows :: (FiniteCategory c m o, Morphism m o) => c -> Set m
genArrows :: forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
genArrows c
c = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
genAr c
c (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
genArTo :: (FiniteCategory c m o, Morphism m o) => c -> o -> Set m
genArTo :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArTo c
c o
t = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ (\o
s -> c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
genAr c
c o
s o
t) (o -> Set m) -> Set o -> Set (Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
genArTo2 :: (FiniteCategory c m o, Morphism m o) => c -> Set o -> Set m
genArTo2 :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
genArTo2 c
c Set o
ts = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ (c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
genAr c
c) (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Set o
ts
genArFrom :: (FiniteCategory c m o, Morphism m o) => c -> o -> Set m
genArFrom :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArFrom c
c o
s = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ (c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
genAr c
c o
s) (o -> Set m) -> Set o -> Set (Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
genArFrom2 :: (FiniteCategory c m o, Morphism m o) => c -> Set o -> Set m
genArFrom2 :: forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
genArFrom2 c
c Set o
ss = Set (Set m) -> Set m
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Set (Set m) -> Set m) -> Set (Set m) -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
genAr c
c (o -> o -> Set m) -> Set o -> Set (o -> Set m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set o
ss Set (o -> Set m) -> Set o -> Set (Set m)
forall a b. Set (a -> b) -> Set a -> Set b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
genArrowsWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set m
genArrowsWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set m
genArrowsWithoutId c
c = (m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c) (c -> Set m
forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
genArrows c
c)
genArToWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Set m
genArToWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Set m
genArToWithoutId c
c o
t = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArTo c
c o
t
genArTo2WithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o -> Set m
genArTo2WithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o -> Set m
genArTo2WithoutId c
c Set o
ts = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> Set o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
genArTo2 c
c Set o
ts
genArFromWithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Set m
genArFromWithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Set m
genArFromWithoutId c
c o
s = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArFrom c
c o
s
genArFrom2WithoutId :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o -> Set m
genArFrom2WithoutId :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o -> Set m
genArFrom2WithoutId c
c Set o
ss = ((m -> Bool) -> Set m -> Set m
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> m -> Bool
forall c m o.
(Category c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isNotIdentity c
c)) (Set m -> Set m) -> Set m -> Set m
forall a b. (a -> b) -> a -> b
$ c -> Set o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> Set o -> Set m
genArFrom2 c
c Set o
ss
identities :: (FiniteCategory c m o, Morphism m o) => c -> Set m
identities :: forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
identities c
c = c -> o -> m
forall c m o. (Category c m o, Morphism m o) => c -> o -> m
identity c
c (o -> m) -> Set o -> Set m
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c
isInitial :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Bool
isInitial :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Bool
isInitial c
cat o
obj = let
morphisms :: o -> Set m
morphisms o
t = c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
cat o
obj o
t
condition :: o -> Bool
condition o
t = (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Set m -> Bool
forall a. Set a -> Bool
Set.null (Set m -> Bool) -> Set m -> Bool
forall a b. (a -> b) -> a -> b
$ o -> Set m
morphisms o
t) Bool -> Bool -> Bool
&& (Set Bool -> Bool
Set.and ((Set m -> m
forall a. Set a -> a
anElement (o -> Set m
morphisms o
t) m -> m -> Bool
forall a. Eq a => a -> a -> Bool
==) (m -> Bool) -> Set m -> Set Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> o -> Set m
morphisms o
t))
in
Set Bool -> Bool
Set.and (Set Bool -> Bool) -> Set Bool -> Bool
forall a b. (a -> b) -> a -> b
$ o -> Bool
condition (o -> Bool) -> Set o -> Set Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
cat
initialObjects :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o
initialObjects :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o
initialObjects c
cat = (o -> Bool) -> Set o -> Set o
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> o -> Bool
forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Bool
isInitial c
cat) (c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
cat)
isTerminal :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> o -> Bool
isTerminal :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Bool
isTerminal c
cat o
obj = let
morphisms :: o -> Set m
morphisms o
s = c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
cat o
s o
obj
condition :: o -> Bool
condition o
s = (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Set m -> Bool
forall a. Set a -> Bool
Set.null (Set m -> Bool) -> Set m -> Bool
forall a b. (a -> b) -> a -> b
$ o -> Set m
morphisms o
s) Bool -> Bool -> Bool
&& (Set Bool -> Bool
Set.and ((Set m -> m
forall a. Set a -> a
anElement (o -> Set m
morphisms o
s) m -> m -> Bool
forall a. Eq a => a -> a -> Bool
==) (m -> Bool) -> Set m -> Set Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> o -> Set m
morphisms o
s))
in
Set Bool -> Bool
Set.and (Set Bool -> Bool) -> Set Bool -> Bool
forall a b. (a -> b) -> a -> b
$ o -> Bool
condition (o -> Bool) -> Set o -> Set Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
cat
terminalObjects :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Set o
terminalObjects :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> Set o
terminalObjects c
cat = (o -> Bool) -> Set o -> Set o
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (c -> o -> Bool
forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> o -> Bool
isTerminal c
cat) (c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
cat)
isMonic :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> m -> Bool
isMonic :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isMonic c
c m
f = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [m
f m -> m -> m
forall m o. Morphism m o => m -> m -> m
@ m
g m -> m -> Bool
forall a. Eq a => a -> a -> Bool
/= m
f m -> m -> m
forall m o. Morphism m o => m -> m -> m
@ m
h Bool -> Bool -> Bool
|| m
g m -> m -> Bool
forall a. Eq a => a -> a -> Bool
== m
h| o
x <- Set o -> [o]
forall a. Eq a => Set a -> [a]
setToList (Set o -> [o]) -> Set o -> [o]
forall a b. (a -> b) -> a -> b
$ c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c, m
g <- Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList (Set m -> [m]) -> Set m -> [m]
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c o
x (m -> o
forall m o. Morphism m o => m -> o
source m
f), m
h <- Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList (Set m -> [m]) -> Set m -> [m]
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c o
x (m -> o
forall m o. Morphism m o => m -> o
source m
f)]
isEpic :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> m -> Bool
isEpic :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m, Eq o) =>
c -> m -> Bool
isEpic c
c m
f = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [m
g m -> m -> m
forall m o. Morphism m o => m -> m -> m
@ m
f m -> m -> Bool
forall a. Eq a => a -> a -> Bool
/= m
h m -> m -> m
forall m o. Morphism m o => m -> m -> m
@ m
f Bool -> Bool -> Bool
|| m
g m -> m -> Bool
forall a. Eq a => a -> a -> Bool
== m
h | o
x <- Set o -> [o]
forall a. Eq a => Set a -> [a]
setToList (Set o -> [o]) -> Set o -> [o]
forall a b. (a -> b) -> a -> b
$ c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c, m
g <- Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList (Set m -> [m]) -> Set m -> [m]
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c (m -> o
forall m o. Morphism m o => m -> o
target m
f) o
x, m
h <- Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList (Set m -> [m]) -> Set m -> [m]
forall a b. (a -> b) -> a -> b
$ c -> o -> o -> Set m
forall c m o.
(Category c m o, Morphism m o) =>
c -> o -> o -> Set m
ar c
c (m -> o
forall m o. Morphism m o => m -> o
target m
f) o
x]
bruteForce :: (FiniteCategory c m o, Morphism m o, Eq m) => c -> m -> [[m]] -> [m]
bruteForce :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m) =>
c -> m -> [[m]] -> [m]
bruteForce c
c m
m [[m]]
l = if Maybe Int
index Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Int
forall a. Maybe a
Nothing then c -> m -> [[m]] -> [m]
forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m) =>
c -> m -> [[m]] -> [m]
bruteForce c
c m
m ([[[m]]] -> [[m]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([m] -> [[m]]
pathToAugmentedPaths ([m] -> [[m]]) -> [[m]] -> [[[m]]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[m]]
l)) else [[m]]
l [[m]] -> Int -> [m]
forall a. HasCallStack => [a] -> Int -> a
!! Int
i where
index :: Maybe Int
index = m -> [m] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex m
m ([m] -> m
forall m o. Morphism m o => [m] -> m
compose ([m] -> m) -> [[m]] -> [m]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[m]]
l)
Just Int
i = Maybe Int
index
leavingMorph :: [b] -> [m]
leavingMorph [b]
path = (Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList(Set m -> [m]) -> (o -> Set m) -> o -> [m]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArFrom c
c)) (o -> [m]) -> o -> [m]
forall a b. (a -> b) -> a -> b
$ b -> o
forall m o. Morphism m o => m -> o
target(b -> o) -> ([b] -> b) -> [b] -> o
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[b] -> b
forall a. HasCallStack => [a] -> a
head ([b] -> o) -> [b] -> o
forall a b. (a -> b) -> a -> b
$ [b]
path
pathToAugmentedPaths :: [m] -> [[m]]
pathToAugmentedPaths [m]
path = ([m] -> [m]
forall {b}. Morphism b o => [b] -> [m]
leavingMorph [m]
path) [m] -> (m -> [[m]]) -> [[m]]
forall a b. [a] -> (a -> [b]) -> [b]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\m
x -> [(m
xm -> [m] -> [m]
forall a. a -> [a] -> [a]
:[m]
path)] )
bruteForceDecompose :: (FiniteCategory c m o, Morphism m o, Eq m) => c -> m -> [m]
bruteForceDecompose :: forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m) =>
c -> m -> [m]
bruteForceDecompose c
c m
m = c -> m -> [[m]] -> [m]
forall c m o.
(FiniteCategory c m o, Morphism m o, Eq m) =>
c -> m -> [[m]] -> [m]
bruteForce c
c m
m ((m -> [m] -> [m]
forall a. a -> [a] -> [a]
:[]) (m -> [m]) -> [m] -> [[m]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Set m -> [m]
forall a. Eq a => Set a -> [a]
setToList (Set m -> [m]) -> Set m -> [m]
forall a b. (a -> b) -> a -> b
$ c -> o -> Set m
forall c m o.
(FiniteCategory c m o, Morphism m o) =>
c -> o -> Set m
genArFrom c
c (m -> o
forall m o. Morphism m o => m -> o
source m
m)))
pprintFiniteCategory :: (FiniteCategory c m o, Morphism m o, PrettyPrint c, PrettyPrint m, PrettyPrint o, Eq m, Eq o) => Int -> c -> String
pprintFiniteCategory :: forall c m o.
(FiniteCategory c m o, Morphism m o, PrettyPrint c, PrettyPrint m,
PrettyPrint o, Eq m, Eq o) =>
Int -> c -> String
pprintFiniteCategory Int
v c
c = String
"Category : " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> c -> String
forall a. PrettyPrint a => Int -> a -> String
pprint Int
v c
c String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n\nObjects :\n\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" (Set String -> [String]
forall a. Eq a => Set a -> [a]
setToList (Set String -> [String]) -> Set String -> [String]
forall a b. (a -> b) -> a -> b
$ Int -> o -> String
forall a. PrettyPrint a => Int -> a -> String
pprint Int
v (o -> String) -> Set o -> Set String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set o
forall c m o. FiniteCategory c m o => c -> Set o
ob c
c)) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\n\nArrows :\n\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" (Set String -> [String]
forall a. Eq a => Set a -> [a]
setToList (Set String -> [String]) -> Set String -> [String]
forall a b. (a -> b) -> a -> b
$ Int -> m -> String
forall a. PrettyPrint a => Int -> a -> String
pprint Int
v (m -> String) -> Set m -> Set String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> Set m
forall c m o. (FiniteCategory c m o, Morphism m o) => c -> Set m
arrows c
c))