Copyright | Guillaume Sabbagh 2022 |
---|---|
License | GPL-3 |
Maintainer | guillaumesabbagh@protonmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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" CompositionGraph
s are finite. See also SafeCompositionGraph
to ensure there is no infinite loop in the compositionGraph
.
Synopsis
- type RawPath a b = [Arrow a b]
- type Path a b = (a, RawPath a b)
- data CGMorphism a b = CGMorphism {
- path :: Path a b
- compositionLaw :: CompositionLaw a b
- getLabel :: CGMorphism a b -> Maybe b
- unsafeGetLabel :: CGMorphism a b -> b
- getMorphismFromLabel :: Eq b => CompositionGraph a b -> b -> Maybe (CGMorphism a b)
- unsafeGetMorphismFromLabel :: Eq b => CompositionGraph a b -> b -> CGMorphism a b
- cgmorphismToArrow :: CGMorphism a b -> Maybe (Arrow a b)
- arrowToCGMorphism :: (Eq a, Eq b) => CompositionGraph a b -> Arrow a b -> Maybe (CGMorphism a b)
- unsafeCGMorphismToArrow :: CGMorphism a b -> Arrow a b
- unsafeArrowToCGMorphism :: CompositionGraph a b -> Arrow a b -> CGMorphism a b
- type CompositionLaw a b = Map (RawPath a b) (RawPath a b)
- data CompositionGraph a b
- support :: CompositionGraph a b -> Graph a b
- law :: CompositionGraph a b -> CompositionLaw a b
- compositionGraph :: (Eq a, Eq b) => Graph a b -> CompositionLaw a b -> Either (FiniteCategoryError (CGMorphism a b) a) (CompositionGraph a b)
- unsafeCompositionGraph :: Graph a b -> CompositionLaw a b -> CompositionGraph a b
- emptyCompositionGraph :: CompositionGraph a b
- 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
- finiteCategoryToCompositionGraph2 :: (FiniteCategory c m o, Morphism m o, Eq m, Eq o) => c -> Diagram c m o (CompositionGraph o m) (CGMorphism o m) o
- 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
- 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
- unsafeReadCGString :: String -> CG
- readCGString :: String -> Either (FiniteCategoryError (CGMorphism Text Text) Text) CG
- unsafeReadCGFile :: String -> IO CG
- readCGFile :: String -> IO (Either (FiniteCategoryError (CGMorphism Text Text) Text) CG)
- mapOnObjects :: (Eq n1, Eq e) => (n1 -> n2) -> CompositionGraph n1 e -> CompositionGraph n2 e
- 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
- mapOnArrows :: (Eq n, Eq e1) => (e1 -> e2) -> CompositionGraph n e1 -> CompositionGraph n e2
- 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
- writeCGString :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => CompositionGraph a b -> String
- writeCGFile :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => CompositionGraph a b -> String -> IO ()
- unsafeReadCGDString :: String -> CGD
- readCGDString :: String -> Either (DiagramError CG (CGMorphism Text Text) Text CG (CGMorphism Text Text) Text) CGD
- unsafeReadCGDFile :: String -> IO CGD
- readCGDFile :: String -> IO (Either (DiagramError CG (CGMorphism Text Text) Text CG (CGMorphism Text Text) Text) CGD)
- 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
- 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 ()
- constructRandomCompositionGraph :: RandomGen g => Int -> Int -> Int -> g -> (CompositionGraph Int Int, g)
- defaultConstructRandomCompositionGraph :: RandomGen g => g -> (CompositionGraph Int Int, g)
- defaultConstructRandomDiagram :: RandomGen g => g -> (Diagram (CompositionGraph Int Int) (CGMorphism Int Int) Int (CompositionGraph Int Int) (CGMorphism Int Int) Int, g)
Types for composition graph morphism
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.
CGMorphism | |
|
Instances
(PrettyPrint a, PrettyPrint b, Eq a, Eq b) => PrettyPrint (CGMorphism a b) Source # | |
Defined in Math.FiniteCategories.CompositionGraph 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 # | |
Defined in Math.FiniteCategories.CompositionGraph simplify :: CGMorphism a b -> CGMorphism a b # | |
Generic (CGMorphism a b) Source # | |
Defined in Math.FiniteCategories.CompositionGraph type Rep (CGMorphism a b) :: Type -> Type 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 # | |
Defined in Math.FiniteCategories.CompositionGraph 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 # | |
Defined in Math.FiniteCategories.CompositionGraph (==) :: CGMorphism a b -> CGMorphism a b -> Bool (/=) :: CGMorphism a b -> CGMorphism a b -> Bool | |
(Eq a, Eq b) => Morphism (CGMorphism a b) a Source # | |
Defined in Math.FiniteCategories.CompositionGraph (@) :: 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 # | |
Defined in Math.FiniteCategories.CompositionGraph 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 # | |
Defined in Math.FiniteCategories.CompositionGraph 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 |
Defined in Math.FiniteCategories.ColimitCategory 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 # | |
Defined in Math.FiniteCategories.ColimitCategory coequalize :: Diagram Parallel ParallelAr ParallelOb (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) -> Cocone Parallel ParallelAr ParallelOb (FinCat (CompositionGraph n e) (CGMorphism n e) n) (FinFunctor (CompositionGraph n e) (CGMorphism n e) n) (CompositionGraph n e) Source # | |
(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 # | |
Defined in Math.FiniteCategories.ColimitCategory 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 # | |
Defined in Math.FiniteCategories.CompositionGraph type Rep (CGMorphism a b) = D1 ('MetaData "CGMorphism" "Math.FiniteCategories.CompositionGraph" "FiniteCategories-0.6.3.1-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)
unsafeCGMorphismToArrow :: CGMorphism a b -> Arrow a b Source #
Unsafe version of cgmorphismToArrow
.
unsafeArrowToCGMorphism :: CompositionGraph a b -> Arrow a b -> CGMorphism a b Source #
Unsafe version of arrowToCGMorphism
. O(1)
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
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.
emptyCompositionGraph :: CompositionGraph a b Source #
The empty CompositionGraph
.
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 CompositionGraph
s. 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 :
- Every character of a line following a "#" character are ignored.
- Each line defines either an object, a morphism or a composition law entry.
- The following strings are reserved : " -","-> "," = ", "<ID>", "<ID>", "<SRC>", "<SRC>", "<TGT>", "</TGT>", " => "
- To define an object, write a line containing its name.
- 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.
- 1. If an object mentionned in an arrow does not exist, it is created.
- 2. The spaces are important.
- 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.
- 1 If an object mentionned does not exist, it is created.
- 2 If a morphism mentionned does not exist, it is created.
- 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 :
- Every character of a line following a "#" character are ignored.
- Each line defines either an object, a morphism or a composition law entry.
- The following strings are reserved : " -","-> "," = ", "<ID>", "<ID>", "<SRC>", "<SRC>", "<TGT>", "</TGT>", " => "
- To define an object, write a line containing its name.
- 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.
- 1. If an object mentionned in an arrow does not exist, it is created.
- 2. The spaces are important.
- 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.
- 1 If an object mentionned does not exist, it is created.
- 2 If a morphism mentionned does not exist, it is created.
- 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 :
- There is a line "<SRC>" and a line "</SRC>".
- 1 Between these two lines, the source composition graph is defined as in a cg file.
- There is a line "<TGT>" and a line "</TGT>".
- 1 Between these two lines, the target composition graph is defined as in a cg file.
- After the two previously described sections, you can declare the maps between objects and morphisms.
- 1 You map an object to another with the following syntax : "object1 => object2".
- 2 You map a morphism to another with the following syntax : "objSrc1 -arrowSrc1-> objSrc2 => objTgt1 -arrowTgt1-> objTgt2".
- 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"
- 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 :
- There is a line "<SRC>" and a line "</SRC>".
- 1 Between these two lines, the source composition graph is defined as in a cg file.
- There is a line "<TGT>" and a line "</TGT>".
- 1 Between these two lines, the target composition graph is defined as in a cg file.
- Outside of the two previously described sections, you can declare the maps between objects and morphisms.
- 1 You map an object to another with the following syntax : "object1 => object2".
- 2 You map a morphism to another with the following syntax : "objSrc1 -arrowSrc1-> objSrc2 => objTgt1 -arrowTgt1-> objTgt2".
- 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 #
:: 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 :
- Pick two objects, merge them.
- While there are composite morphisms, try to merge them with generating arrows.
- If it fails, don't change the composition graph.
- 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.