Copyright | Guillaume Sabbagh 2022 |
---|---|
License | GPL-3 |
Maintainer | guillaumesabbagh@protonmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A SafeCompositionGraph
is a CompositionGraph
where infinite loops are prevented.
The readSCGFile
function is the most important for ease of use.
Synopsis
- data SCGMorphism a b = SCGMorphism {
- pathS :: Path a b
- compositionLawS :: CompositionLaw a b
- maxNbCycles :: Int
- getLabelS :: SCGMorphism a b -> Maybe b
- data SafeCompositionGraph a b
- supportS :: SafeCompositionGraph a b -> Graph a b
- lawS :: SafeCompositionGraph a b -> CompositionLaw a b
- maxCycles :: SafeCompositionGraph a b -> Int
- safeCompositionGraph :: (Eq a, Eq b) => Graph a b -> CompositionLaw a b -> Int -> Either (FiniteCategoryError (SCGMorphism a b) a) (SafeCompositionGraph a b)
- unsafeSafeCompositionGraph :: Graph a b -> CompositionLaw a b -> Int -> SafeCompositionGraph a b
- readSCGString :: String -> Either (FiniteCategoryError (SCGMorphism Text Text) Text) SCG
- unsafeReadSCGString :: String -> SCG
- readSCGFile :: String -> IO (Either (FiniteCategoryError (SCGMorphism Text Text) Text) SCG)
- unsafeReadSCGFile :: String -> IO SCG
- safeCompositionGraphFromCompositionGraph :: Int -> CompositionGraph a b -> SafeCompositionGraph a b
- compositionGraphFromSafeCompositionGraph :: SafeCompositionGraph a b -> CompositionGraph a b
- writeSCGString :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => SafeCompositionGraph a b -> String
- writeSCGFile :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => SafeCompositionGraph a b -> String -> IO ()
- unsafeReadSCGDString :: String -> SCGD
- readSCGDString :: String -> Either (DiagramError SCG (SCGMorphism Text Text) Text SCG (SCGMorphism Text Text) Text) SCGD
- unsafeReadSCGDFile :: String -> IO SCGD
- readSCGDFile :: String -> IO (Either (DiagramError SCG (SCGMorphism Text Text) Text SCG (SCGMorphism Text Text) Text) SCGD)
- writeSCGDString :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (SafeCompositionGraph a1 b1) (SCGMorphism a1 b1) a1 (SafeCompositionGraph a2 b2) (SCGMorphism a2 b2) a2 -> String
- writeSCGDFile :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (SafeCompositionGraph a1 b1) (SCGMorphism a1 b1) a1 (SafeCompositionGraph a2 b2) (SCGMorphism a2 b2) a2 -> String -> IO ()
- constructRandomSafeCompositionGraph :: RandomGen g => Int -> Int -> Int -> g -> Int -> (SafeCompositionGraph Int Int, g)
- defaultConstructRandomSafeCompositionGraph :: RandomGen g => g -> (SafeCompositionGraph Int Int, g)
- defaultConstructRandomSafeDiagram :: RandomGen g => g -> (Diagram (SafeCompositionGraph Int Int) (SCGMorphism Int Int) Int (SafeCompositionGraph Int Int) (SCGMorphism Int Int) Int, g)
Types for a morphism of safe composition graph
data SCGMorphism a b Source #
The type SCGMorphism
is the type of SafeCompositionGraph
s morphisms.
It is just like a CGMorphism
, we also store the maximum number of cycles.
SCGMorphism | |
|
Instances
(PrettyPrint a, PrettyPrint b, Eq a, Eq b) => PrettyPrint (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph pprint :: Int -> SCGMorphism a b -> String Source # pprintWithIndentations :: Int -> Int -> String -> SCGMorphism a b -> String Source # pprintIndent :: Int -> SCGMorphism a b -> String Source # | |
(Simplifiable a, Simplifiable b, Eq a, Eq b) => Simplifiable (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph simplify :: SCGMorphism a b -> SCGMorphism a b # | |
Generic (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph type Rep (SCGMorphism a b) :: Type -> Type from :: SCGMorphism a b -> Rep (SCGMorphism a b) x to :: Rep (SCGMorphism a b) x -> SCGMorphism a b | |
(Show a, Show b) => Show (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph showsPrec :: Int -> SCGMorphism a b -> ShowS show :: SCGMorphism a b -> String showList :: [SCGMorphism a b] -> ShowS | |
(Eq a, Eq b) => Eq (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph (==) :: SCGMorphism a b -> SCGMorphism a b -> Bool (/=) :: SCGMorphism a b -> SCGMorphism a b -> Bool | |
(Eq a, Eq b) => Morphism (SCGMorphism a b) a Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph (@) :: SCGMorphism a b -> SCGMorphism a b -> SCGMorphism a b Source # (@?) :: SCGMorphism a b -> SCGMorphism a b -> Maybe (SCGMorphism a b) Source # source :: SCGMorphism a b -> a Source # target :: SCGMorphism a b -> a Source # | |
(Eq a, Eq b) => Category (SafeCompositionGraph a b) (SCGMorphism a b) a Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph identity :: SafeCompositionGraph a b -> a -> SCGMorphism a b Source # ar :: SafeCompositionGraph a b -> a -> a -> Set (SCGMorphism a b) Source # genAr :: SafeCompositionGraph a b -> a -> a -> Set (SCGMorphism a b) Source # decompose :: SafeCompositionGraph a b -> SCGMorphism a b -> [SCGMorphism a b] Source # | |
(Eq a, Eq b) => FiniteCategory (SafeCompositionGraph a b) (SCGMorphism a b) a Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph ob :: SafeCompositionGraph a b -> Set a Source # | |
type Rep (SCGMorphism a b) Source # | |
Defined in Math.FiniteCategories.SafeCompositionGraph type Rep (SCGMorphism a b) = D1 ('MetaData "SCGMorphism" "Math.FiniteCategories.SafeCompositionGraph" "FiniteCategories-0.6.1.0-inplace" 'False) (C1 ('MetaCons "SCGMorphism" 'PrefixI 'True) (S1 ('MetaSel ('Just "pathS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Path a b)) :*: (S1 ('MetaSel ('Just "compositionLawS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CompositionLaw a b)) :*: S1 ('MetaSel ('Just "maxNbCycles") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))) |
Functions for morphism
getLabelS :: SCGMorphism a b -> Maybe b Source #
Return the label of a SafeCompositionGraph
generator.
Safe composition graph
data SafeCompositionGraph a b Source #
A SafeCompositionGraph
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
. It has a maximum number of composition for loops.
SafeCompositionGraph
is private, use the smart constructors safeCompositionGraph
or unsafeSafeCompositionGraph
to instantiate one.
Instances
Getters
supportS :: SafeCompositionGraph a b -> Graph a b Source #
The generating graph of the safe composition graph.
lawS :: SafeCompositionGraph a b -> CompositionLaw a b Source #
The composition law of the safe composition graph.
maxCycles :: SafeCompositionGraph a b -> Int Source #
The maximum number of times a cycle can be composed with itself.
Construction
safeCompositionGraph :: (Eq a, Eq b) => Graph a b -> CompositionLaw a b -> Int -> Either (FiniteCategoryError (SCGMorphism a b) a) (SafeCompositionGraph a b) Source #
Smart constructor of SafeCompositionGraph
.
If the SafeCompositionGraph
constructed is valid, returns Right
the composition graph, otherwise returns Left a FiniteCategoryError
.
unsafeSafeCompositionGraph :: Graph a b -> CompositionLaw a b -> Int -> SafeCompositionGraph a b Source #
Unsafe constructor of SafeCompositionGraph
for performance purposes. It does not check the structure of the SafeCompositionGraph
.
Use this constructor only if the SafeCompositionGraph
is necessarily well formed.
readSCGString :: String -> Either (FiniteCategoryError (SCGMorphism Text Text) Text) SCG Source #
Read a .scg string to create a SafeCompositionGraph
.
A .scg 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>", "<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/> in order to map a morphism to an identity.
- The first line of the should be a number, this number determines the maximum number of cycles.
unsafeReadSCGString :: String -> SCG Source #
Unsafe version of readSCGString
which does not check the structure of the resulting SafeCompositionGraph
.
readSCGFile :: String -> IO (Either (FiniteCategoryError (SCGMorphism Text Text) Text) SCG) Source #
Read a .scg file to create a SafeCompositionGraph
.
A .scg 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>", "<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/> in order to map a morphism to an identity.
- The first line of the should be a number, this number determines the maximum number of cycles.
unsafeReadSCGFile :: String -> IO SCG Source #
Unsafe version of readSCGFile
which does not check the structure of the resulting SafeCompositionGraph
.
safeCompositionGraphFromCompositionGraph :: Int -> CompositionGraph a b -> SafeCompositionGraph a b Source #
Transform a CompositionGraph
into a SafeCompositionGraph
given a maximum number of loops.
compositionGraphFromSafeCompositionGraph :: SafeCompositionGraph a b -> CompositionGraph a b Source #
Transform a SafeCompositionGraph
into a CompositionGraph
.
Serialization
writeSCGString :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => SafeCompositionGraph a b -> String Source #
Transform a composition graph into a string following the .scg convention.
writeSCGFile :: (PrettyPrint a, PrettyPrint b, Eq a, Eq b) => SafeCompositionGraph a b -> String -> IO () Source #
Saves a safe composition graph into a file located at a given path.
Construction of diagrams
unsafeReadSCGDString :: String -> SCGD Source #
Unsafe version of readCGDString
which does not check the structure of the resulting Diagram
.
readSCGDString :: String -> Either (DiagramError SCG (SCGMorphism Text Text) Text SCG (SCGMorphism Text Text) Text) SCGD Source #
Read a .scgd string and returns a diagram. A .scgd 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 scg file.
- There is a line "<TGT>" and a line "</TGT>".
- 1 Between these two lines, the target composition graph is defined as in a scg 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.
unsafeReadSCGDFile :: String -> IO SCGD Source #
Unsafe version readSCGDFile
which does not check the structure of the resulting Diagram
.
readSCGDFile :: String -> IO (Either (DiagramError SCG (SCGMorphism Text Text) Text SCG (SCGMorphism Text Text) Text) SCGD) Source #
Read a .scgd file and returns a diagram. A .scgd 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 scg file.
- There is a line "<TGT>" and a line "</TGT>".
- 1 Between these two lines, the target composition graph is defined as in a scg 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
writeSCGDString :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (SafeCompositionGraph a1 b1) (SCGMorphism a1 b1) a1 (SafeCompositionGraph a2 b2) (SCGMorphism a2 b2) a2 -> String Source #
Transform a safe composition graph diagram into a string following the .scgd convention.
writeSCGDFile :: (PrettyPrint a1, PrettyPrint b1, Eq a1, Eq b1, PrettyPrint a2, PrettyPrint b2, Eq a2, Eq b2) => Diagram (SafeCompositionGraph a1 b1) (SCGMorphism a1 b1) a1 (SafeCompositionGraph a2 b2) (SCGMorphism a2 b2) a2 -> String -> IO () Source #
Saves a safe composition graph diagram into a file located at a given path.
Random safe composition graph
constructRandomSafeCompositionGraph 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. |
-> Int | The maximum number of loops of the SafeCompositionGraph |
-> (SafeCompositionGraph Int Int, g) |
Generates a random CompositionGraph
and transforms it into a SafeCompositionGraph
(see constructRandomCompositionGraph
).
defaultConstructRandomSafeCompositionGraph :: RandomGen g => g -> (SafeCompositionGraph Int Int, g) Source #
Creates a random safe composition graph with default random values.
The number of arrows will be in the interval [1, 20].
The max number of loops is set to 100 as it is almost impossible to have a greater number of loops with monoidification attempts.
defaultConstructRandomSafeDiagram :: RandomGen g => g -> (Diagram (SafeCompositionGraph Int Int) (SCGMorphism Int Int) Int (SafeCompositionGraph Int Int) (SCGMorphism Int Int) Int, g) Source #
Constructs two random safe composition graphs and choose a random diagram between the two.
The max number of loops is set to 100 as it is almost impossible to have a greater number of loops with monoidification attempts.