Copyright | Guillaume Sabbagh 2021 |
---|---|
License | GPL-3 |
Maintainer | guillaumesabbagh@protonmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provide functions to generate randomly composition graphs. It is an easy and fast way to generate a lot of finite categories. It can be used to test functions, to generate examples or to test hypothesis.
Synopsis
- mkRandomCompositionGraph :: RandomGen g => Int -> Int -> Int -> g -> (CompositionGraph Int Int, g)
- defaultMkRandomCompositionGraph :: RandomGen g => g -> (CompositionGraph Int Int, g)
Documentation
mkRandomCompositionGraph 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).
defaultMkRandomCompositionGraph :: 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].