FiniteCategories-0.6.4.0: Finite categories and usual categorical constructions on them.
CopyrightGuillaume Sabbagh 2022
LicenseGPL-3
Maintainerguillaumesabbagh@protonmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Math.FiniteCategories.CompositionGraph

Description

A CompositionGraph is the free category generated by a multidigraph quotiented by an equivalence relation on the paths of the graphs. A multidigraph is a directed multigraph which means that edges are oriented and there can be multiple arrows between two objects.

The equivalence relation is given by a map on paths of the graph.

Morphisms from different composition graphs should not be composed or compared, if they are, the behavior is undefined.

When taking subcategories of a composition graph, the composition law might lead to morphisms not existing anymore. It is not a problem because they are equivalent, it is only counterintuitive for human readability.

Note that a CompositionGraph is a FiniteCategory because it can implement an ob function, however a loop in the graph could compose infinitely many times. We can consider that only "well formed" CompositionGraphs are finite. See also SafeCompositionGraph to ensure there is no infinite loop in the compositionGraph.

Synopsis

Types for composition graph morphism

type RawPath a b = [Arrow a b] Source #

A RawPath is a list of arrows, arrows should be compatible.

type Path a b = (a, RawPath a b) Source #

A Path is a RawPath with a source specified.

An empty path is an identity in a free category. Therefore, it is useful to keep the source when the path is empty because there is one identity for each node of the graph. (We need to differentiate identites for each node.)

data CGMorphism a b Source #

The datatype CGMorphism is the type of composition graph morphisms.

It is a path with a composition law, it is necessary to keep the composition law of the composition graph in every morphism of the graph because we need it to compose two morphisms and the morphisms compose independently of the composition graph.

Constructors

CGMorphism 

Fields

Instances

Instances details
(PrettyPrint a, PrettyPrint b, Eq a, Eq b) => PrettyPrint (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

pprint :: Int -> CGMorphism a b -> String Source #

pprintWithIndentations :: Int -> Int -> String -> CGMorphism a b -> String Source #

pprintIndent :: Int -> CGMorphism a b -> String Source #

(Simplifiable a, Simplifiable b, Eq a, Eq b) => Simplifiable (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

simplify :: CGMorphism a b -> CGMorphism a b #

Generic (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Associated Types

type Rep (CGMorphism a b) :: Type -> Type

Methods

from :: CGMorphism a b -> Rep (CGMorphism a b) x

to :: Rep (CGMorphism a b) x -> CGMorphism a b

(Show a, Show b) => Show (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

showsPrec :: Int -> CGMorphism a b -> ShowS

show :: CGMorphism a b -> String

showList :: [CGMorphism a b] -> ShowS

(Eq a, Eq b) => Eq (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

(==) :: CGMorphism a b -> CGMorphism a b -> Bool

(/=) :: CGMorphism a b -> CGMorphism a b -> Bool

(Eq a, Eq b) => Morphism (CGMorphism a b) a Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

(@) :: CGMorphism a b -> CGMorphism a b -> CGMorphism a b Source #

(@?) :: CGMorphism a b -> CGMorphism a b -> Maybe (CGMorphism a b) Source #

source :: CGMorphism a b -> a Source #

target :: CGMorphism a b -> a Source #

(Eq a, Eq b) => Category (CompositionGraph a b) (CGMorphism a b) a Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

identity :: CompositionGraph a b -> a -> CGMorphism a b Source #

ar :: CompositionGraph a b -> a -> a -> Set (CGMorphism a b) Source #

genAr :: CompositionGraph a b -> a -> a -> Set (CGMorphism a b) Source #

decompose :: CompositionGraph a b -> CGMorphism a b -> [CGMorphism a b] Source #

(Eq a, Eq b) => FiniteCategory (CompositionGraph a b) (CGMorphism a b) a Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

ob :: CompositionGraph a b -> Set a Source #

(FiniteCategory c m o, Morphism m o, Eq c, Eq m, Eq o, FiniteCategory cIndex mIndex oIndex, Morphism mIndex oIndex, Eq oIndex, Eq mIndex) => CocompleteCategory (FinCat c m o) (FinFunctor c m o) c (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) cIndex mIndex oIndex Source #

Note that computing a ColimitCategory is MUCH slower than computing a LimitCategory as coequalizers of categories are trickier than equalizers of categories. We can only compute colimits of CompositionGraphs as coequalizing might create new formal morphisms when gluing two objects. Therefore colimit transforms all given categories into CompositionGraphs. If you already have a CompositionGraph, consider using colimitOfCompositionGraphs instead of colimit.

Instance details

Defined in Math.FiniteCategories.ColimitCategory

Methods

colimit :: Diagram cIndex mIndex oIndex (FinCat c m o) (FinFunctor c m o) c -> Cocone cIndex mIndex oIndex (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) Source #

coprojectBase :: Diagram cIndex mIndex oIndex (FinCat c m o) (FinFunctor c m o) c -> Diagram (FinCat c m o) (FinFunctor c m o) c (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) Source #

(Eq n, Eq e) => HasCoequalizers (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) Source # 
Instance details

Defined in Math.FiniteCategories.ColimitCategory

(Eq e, Eq n, Eq oIndex) => HasCoproducts (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) (FinCat (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (FinFunctor (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) oIndex Source # 
Instance details

Defined in Math.FiniteCategories.ColimitCategory

Methods

coproduct :: Diagram (DiscreteCategory oIndex) (DiscreteMorphism oIndex) oIndex (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) -> Cocone (DiscreteCategory oIndex) (DiscreteMorphism oIndex) oIndex (FinCat (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (FinFunctor (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) Source #

type Rep (CGMorphism a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

type Rep (CGMorphism a b) = D1 ('MetaData "CGMorphism" "Math.FiniteCategories.CompositionGraph" "FiniteCategories-0.6.4.0-inplace" 'False) (C1 ('MetaCons "CGMorphism" 'PrefixI 'True) (S1 ('MetaSel ('Just "path") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Path a b)) :*: S1 ('MetaSel ('Just "compositionLaw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CompositionLaw a b))))

Functions for composition graph morphism

getLabel :: CGMorphism a b -> Maybe b Source #

Return Just the label of a CompositionGraph non identity generator, Nothing if the morphism is not a non identity generator.

unsafeGetLabel :: CGMorphism a b -> b Source #

Unsafe version of getLabel. Throws an error if a problem happens.

getMorphismFromLabel :: Eq b => CompositionGraph a b -> b -> Maybe (CGMorphism a b) Source #

Return Just a morphism with a given label. If several morphisms share the same label, returns the first one found. O(n)

unsafeGetMorphismFromLabel :: Eq b => CompositionGraph a b -> b -> CGMorphism a b Source #

Return a morphism with a given label. If several morphisms share the same label, returns the first one found. If no one was found throws an error. O(n)

cgmorphismToArrow :: CGMorphism a b -> Maybe (Arrow a b) Source #

Return Just the Arrow of a CompositionGraph non identity generator, Nothing if the morphism is not a non identity generator.

arrowToCGMorphism :: (Eq a, Eq b) => CompositionGraph a b -> Arrow a b -> Maybe (CGMorphism a b) Source #

Given a composition graph, transform an Arrow into a CGMorphism if this CGMorphism is in the composition graph, return Nothing otherwise. O(e)

Composition graph

type CompositionLaw a b = Map (RawPath a b) (RawPath a b) Source #

A CompositionLaw is a Map that maps raw paths to smaller raw paths in order to simplify paths so that they don't compose infinitely many times when there is a cycle.

length (law |!| p) <= length p

data CompositionGraph a b Source #

A CompositionGraph is a graph with a composition law such that the free category generated by the graph quotiented out by the composition law gives a FiniteCategory.

CompositionGraph is private, use the smart constructors compositionGraph or unsafeCompositionGraph to instantiate one.

Instances

Instances details
(PrettyPrint a, PrettyPrint b, Eq a, Eq b) => PrettyPrint (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

pprint :: Int -> CompositionGraph a b -> String Source #

pprintWithIndentations :: Int -> Int -> String -> CompositionGraph a b -> String Source #

pprintIndent :: Int -> CompositionGraph a b -> String Source #

(Simplifiable a, Simplifiable b, Eq a, Eq b) => Simplifiable (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Generic (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Associated Types

type Rep (CompositionGraph a b) :: Type -> Type

Methods

from :: CompositionGraph a b -> Rep (CompositionGraph a b) x

to :: Rep (CompositionGraph a b) x -> CompositionGraph a b

(Show a, Show b) => Show (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

showsPrec :: Int -> CompositionGraph a b -> ShowS

show :: CompositionGraph a b -> String

showList :: [CompositionGraph a b] -> ShowS

(Eq a, Eq b) => Eq (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

(==) :: CompositionGraph a b -> CompositionGraph a b -> Bool

(/=) :: CompositionGraph a b -> CompositionGraph a b -> Bool

(Eq a, Eq b) => Category (CompositionGraph a b) (CGMorphism a b) a Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

identity :: CompositionGraph a b -> a -> CGMorphism a b Source #

ar :: CompositionGraph a b -> a -> a -> Set (CGMorphism a b) Source #

genAr :: CompositionGraph a b -> a -> a -> Set (CGMorphism a b) Source #

decompose :: CompositionGraph a b -> CGMorphism a b -> [CGMorphism a b] Source #

(Eq a, Eq b) => FiniteCategory (CompositionGraph a b) (CGMorphism a b) a Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

Methods

ob :: CompositionGraph a b -> Set a Source #

(FiniteCategory c m o, Morphism m o, Eq c, Eq m, Eq o, FiniteCategory cIndex mIndex oIndex, Morphism mIndex oIndex, Eq oIndex, Eq mIndex) => CocompleteCategory (FinCat c m o) (FinFunctor c m o) c (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) cIndex mIndex oIndex Source #

Note that computing a ColimitCategory is MUCH slower than computing a LimitCategory as coequalizers of categories are trickier than equalizers of categories. We can only compute colimits of CompositionGraphs as coequalizing might create new formal morphisms when gluing two objects. Therefore colimit transforms all given categories into CompositionGraphs. If you already have a CompositionGraph, consider using colimitOfCompositionGraphs instead of colimit.

Instance details

Defined in Math.FiniteCategories.ColimitCategory

Methods

colimit :: Diagram cIndex mIndex oIndex (FinCat c m o) (FinFunctor c m o) c -> Cocone cIndex mIndex oIndex (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) Source #

coprojectBase :: Diagram cIndex mIndex oIndex (FinCat c m o) (FinFunctor c m o) c -> Diagram (FinCat c m o) (FinFunctor c m o) c (FinCat (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (FinFunctor (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) (CGMorphism (Colimit oIndex o) (Colimit oIndex m)) (Colimit oIndex o)) (CompositionGraph (Colimit oIndex o) (Colimit oIndex m)) Source #

(Eq n, Eq e) => HasCoequalizers (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) Source # 
Instance details

Defined in Math.FiniteCategories.ColimitCategory

(Eq e, Eq n, Eq oIndex) => HasCoproducts (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) (FinCat (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (FinFunctor (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) oIndex Source # 
Instance details

Defined in Math.FiniteCategories.ColimitCategory

Methods

coproduct :: Diagram (DiscreteCategory oIndex) (DiscreteMorphism oIndex) oIndex (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) -> Cocone (DiscreteCategory oIndex) (DiscreteMorphism oIndex) oIndex (FinCat (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (FinFunctor (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) (CGMorphism (Colimit oIndex n) (Colimit oIndex e)) (Colimit oIndex n)) (CompositionGraph (Colimit oIndex n) (Colimit oIndex e)) Source #

type Rep (CompositionGraph a b) Source # 
Instance details

Defined in Math.FiniteCategories.CompositionGraph

type Rep (CompositionGraph a b) = D1 ('MetaData "CompositionGraph" "Math.FiniteCategories.CompositionGraph" "FiniteCategories-0.6.4.0-inplace" 'False) (C1 ('MetaCons "CompositionGraph" 'PrefixI 'True) (S1 ('MetaSel ('Just "support") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Graph a b)) :*: S1 ('MetaSel ('Just "law") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CompositionLaw a b))))

support :: CompositionGraph a b -> Graph a b Source #

The generating graph (or support) of the composition graph.

law :: CompositionGraph a b -> CompositionLaw a b Source #

The composition law of the composition graph.

Construction

compositionGraph :: (Eq a, Eq b) => Graph a b -> CompositionLaw a b -> Either (FiniteCategoryError (CGMorphism a b) a) (CompositionGraph a b) Source #

Smart constructor of CompositionGraph.

If the CompositionGraph constructed is valid, return Right the composition graph, otherwise return Left a FiniteCategoryError.

unsafeCompositionGraph :: Graph a b -> CompositionLaw a b -> CompositionGraph a b Source #

Unsafe constructor of CompositionGraph for performance purposes. It does not check the structure of the CompositionGraph.

Use this constructor only if the CompositionGraph is necessarily well formed.

finiteCategoryToCompositionGraph :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o, Eq n, Eq e) => (m -> e) -> (o -> n) -> c -> Diagram c m o (CompositionGraph n e) (CGMorphism n e) n Source #

Transforms any FiniteCategory into a CompositionGraph.

The two functions given allow to modify nodes and edges label. The two functions given should be injective, it is your responsability to ensure it.

The CompositionGraph will take more space in memory compared to the original category because the composition law is stored as a Map.

Returns an isofunctor as a Diagram from the original category to the created CompositionGraph.

If you only want the CompositionGraph, take the tgt of the Diagram.

finiteCategoryToCompositionGraph2 :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Diagram c m o (CompositionGraph o m) (CGMorphism o m) o Source #

Specialized finiteCategoryToCompositionGraph with two identities.

diagramToDiagramOfCompositionGraphs :: (FiniteCategory c1 m1 o1, Morphism m1 o1, Eq m1, Eq o1, Eq n1, Eq e1, FiniteCategory c2 m2 o2, Morphism m2 o2, Eq m2, Eq o2, Eq n2, Eq e2) => (m1 -> e1) -> (o1 -> n1) -> (m2 -> e2) -> (o2 -> n2) -> Diagram c1 m1 o1 c2 m2 o2 -> Diagram (CompositionGraph n1 e1) (CGMorphism n1 e1) n1 (CompositionGraph n2 e2) (CGMorphism n2 e2) n2 Source #

Transforms an arbitrary Diagram into a Diagram of CompositionGraphs. See finiteCategoryToCompositionGraph.

diagramToDiagramOfCompositionGraphs2 :: (FiniteCategory c1 m1 o1, Morphism m1 o1, Eq m1, Eq o1, FiniteCategory c2 m2 o2, Morphism m2 o2, Eq m2, Eq o2) => Diagram c1 m1 o1 c2 m2 o2 -> Diagram (CompositionGraph o1 m1) (CGMorphism o1 m1) o1 (CompositionGraph o2 m2) (CGMorphism o2 m2) o2 Source #

Specialized diagramToDiagramOfCompositionGraphs with four identities.

unsafeReadCGString :: String -> CG Source #

Unsafe version of readCGString which does not check the structure of the result CompositionGraph.

readCGString :: String -> Either (FiniteCategoryError (CGMorphism Text Text) Text) CG Source #

Read a .cg string to create a CompositionGraph.

A .cg string follows the following rules :

  1. Every character of a line following a "#" character are ignored.
  2. Each line defines either an object, a morphism or a composition law entry.
  3. The following strings are reserved : " -","-> "," = ", "<ID>", "<ID>", "<SRC>", "<SRC>", "<TGT>", "</TGT>", " => "
  4. To define an object, write a line containing its name.
  5. To define an arrow, the syntax "source_object -name_of_morphism-> target_object" is used, where "source_object", "target_object" and "name_of_morphism" should be replaced.
  6. 1. If an object mentionned in an arrow does not exist, it is created.
  7. 2. The spaces are important.
  8. To define a composition law entry, the syntax "source_object1 -name_of_first_morphism-> middle_object -name_of_second_morphism-> target_object1 = source_object2 -name_of_composite_morphism-> target_object2" is used, where "source_object1", "name_of_first_morphism", "middle_object", "name_of_second_morphism", "target_object1", "source_object2", "name_of_composite_morphism", "target_object2" should be replaced.
  9. 1 If an object mentionned does not exist, it is created.
  10. 2 If a morphism mentionned does not exist, it is created.
  11. 3 You can use the tag <ID/> or <ID> in order to map a morphism to an identity.

unsafeReadCGFile :: String -> IO CG Source #

Unsafe version of readCGFile which does not check the structure of the resulting CompositionGraph.

readCGFile :: String -> IO (Either (FiniteCategoryError (CGMorphism Text Text) Text) CG) Source #

Read a .cg file to create a CompositionGraph.

A .cg file follows the following rules :

  1. Every character of a line following a "#" character are ignored.
  2. Each line defines either an object, a morphism or a composition law entry.
  3. The following strings are reserved : " -","-> "," = ", "<ID>", "<ID>", "<SRC>", "<SRC>", "<TGT>", "</TGT>", " => "
  4. To define an object, write a line containing its name.
  5. To define an arrow, the syntax "source_object -name_of_morphism-> target_object" is used, where "source_object", "target_object" and "name_of_morphism" should be replaced.
  6. 1. If an object mentionned in an arrow does not exist, it is created.
  7. 2. The spaces are important.
  8. To define a composition law entry, the syntax "source_object1 -name_of_first_morphism-> middle_object -name_of_second_morphism-> target_object1 = source_object2 -name_of_composite_morphism-> target_object2" is used, where "source_object1", "name_of_first_morphism", "middle_object", "name_of_second_morphism", "target_object1", "source_object2", "name_of_composite_morphism", "target_object2" should be replaced.
  9. 1 If an object mentionned does not exist, it is created.
  10. 2 If a morphism mentionned does not exist, it is created.
  11. 3 You can use the tag <ID/> or <ID> in order to map a morphism to an identity.

Transformation

mapOnObjects :: (Eq n1, Eq e) => (n1 -> n2) -> CompositionGraph n1 e -> CompositionGraph n2 e Source #

Map a function on objects of the CompositionGraph.

mapOnObjects2 :: (Eq n1, Eq e) => (n1 -> n2) -> CompositionGraph n1 e -> Diagram (CompositionGraph n1 e) (CGMorphism n1 e) n1 (CompositionGraph n2 e) (CGMorphism n2 e) n2 Source #

Map a function on objects of the CompositionGraph, return the diagram from the original CompositionGraph to the new one.

mapOnArrows :: (Eq n, Eq e1) => (e1 -> e2) -> CompositionGraph n e1 -> CompositionGraph n e2 Source #

Map a function on arrows of the CompositionGraph.

mapOnArrows2 :: (Eq n, Eq e1) => (e1 -> e2) -> CompositionGraph n e1 -> Diagram (CompositionGraph n e1) (CGMorphism n e1) n (CompositionGraph n e2) (CGMorphism n e2) n Source #

Map a function on arrows of the CompositionGraph, return the diagram from the original CompositionGraph to the new one.

Serialization

writeCGString :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => CompositionGraph a b -> String Source #

Transform a composition graph into a string following the .cg convention.

writeCGFile :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => CompositionGraph a b -> String -> IO () Source #

Saves a composition graph into a file located at a given path.

Construction of diagrams

unsafeReadCGDString :: String -> CGD Source #

Unsafe version of readCGDString which does not check the structure of the resulting Diagram.

readCGDString :: String -> Either (DiagramError CG (CGMorphism Text Text) Text CG (CGMorphism Text Text) Text) CGD Source #

Read a .cgd string and returns a diagram. A .cgd string obeys the following rules :

  1. There is a line "<SRC>" and a line "</SRC>".
  2. 1 Between these two lines, the source composition graph is defined as in a cg file.
  3. There is a line "<TGT>" and a line "</TGT>".
  4. 1 Between these two lines, the target composition graph is defined as in a cg file.
  5. After the two previously described sections, you can declare the maps between objects and morphisms.
  6. 1 You map an object to another with the following syntax : "object1 => object2".
  7. 2 You map a morphism to another with the following syntax : "objSrc1 -arrowSrc1-> objSrc2 => objTgt1 -arrowTgt1-> objTgt2".
  8. 3 You can map a morphism to an identity with the following syntax : "objSrc1 -arrowSrc1-> objSrc2 => ID", note however that the source of the morphism objSrc1 should be mapped to an object AFTER this declaration in order to identify which identity it is mapped to. So a complete example would be "objSrc1 -arrowSrc1-> objSrc2 => IDnobjSrc1 => objTgt1"
  9. You don't have to (and you shouldn't) specify maps from identities, nor maps from composite arrows.

unsafeReadCGDFile :: String -> IO CGD Source #

Unsafe version readCGDFile which does not check the structure of the resulting Diagram.

readCGDFile :: String -> IO (Either (DiagramError CG (CGMorphism Text Text) Text CG (CGMorphism Text Text) Text) CGD) Source #

Read a .cgd file and returns a diagram. A .cgd file obeys the following rules :

  1. There is a line "<SRC>" and a line "</SRC>".
  2. 1 Between these two lines, the source composition graph is defined as in a cg file.
  3. There is a line "<TGT>" and a line "</TGT>".
  4. 1 Between these two lines, the target composition graph is defined as in a cg file.
  5. Outside of the two previously described sections, you can declare the maps between objects and morphisms.
  6. 1 You map an object to another with the following syntax : "object1 => object2".
  7. 2 You map a morphism to another with the following syntax : "objSrc1 -arrowSrc1-> objSrc2 => objTgt1 -arrowTgt1-> objTgt2".
  8. You don't have to (and you shouldn't) specify maps from identities, nor maps from composite arrows.

Serialization of diagrams

writeCGDString :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (CompositionGraph a1 b1) (CGMorphism a1 b1) a1 (CompositionGraph a2 b2) (CGMorphism a2 b2) a2 -> String Source #

Transform a composition graph diagram into a string following the .cgd convention.

writeCGDFile :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (CompositionGraph a1 b1) (CGMorphism a1 b1) a1 (CompositionGraph a2 b2) (CGMorphism a2 b2) a2 -> String -> IO () Source #

Saves a composition graph diagram into a file located at a given path.

Random composition graph

constructRandomCompositionGraph Source #

Arguments

:: RandomGen g 
=> Int

Number of arrows of the random composition graph.

-> Int

Number of monoidification attempts, a bigger number will produce more morphisms that will compose but the function will be slower.

-> Int

Perseverance : how much we pursure an attempt far away to find a law that works, a bigger number will make the attemps more successful, but slower. (When in doubt put 4.)

-> g

Random generator.

-> (CompositionGraph Int Int, g) 

Generates a random composition graph.

We use the fact that a category is a generalized monoid.

We try to create a composition law of a monoid greedily.

To get a category, we begin with a category with all arrows seperated and not composing with each other. It is equivalent to the monoid with an empty composition law.

Then, a monoidification attempt is the following algorihm :

  1. Pick two objects, merge them.
  2. While there are composite morphisms, try to merge them with generating arrows.
  3. If it fails, don't change the composition graph.
  4. Else return the new composition graph

A monoidification attempt takes a valid category and outputs a valid category, furthermore, the number of arrows is constant and the number of objects is decreasing (not strictly).

defaultConstructRandomCompositionGraph :: RandomGen g => g -> (CompositionGraph Int Int, g) Source #

Creates a random composition graph with default random values.

The number of arrows will be in the interval [1, 20].

defaultConstructRandomDiagram :: RandomGen g => g -> (Diagram (CompositionGraph Int Int) (CGMorphism Int Int) Int (CompositionGraph Int Int) (CGMorphism Int Int) Int, g) Source #

Constructs two random composition graphs and choose a random diagram between the two.