proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.KnuthBendix.NormalForms

Description

Regular languages of normal forms for finite typed presentations. After successful completion, avoiding the rules' left sides gives exactly one word per arrow. A finite automaton recognises these words; object types restrict its transitions to composable generators. Declared objects absent from the alphabet are isolated, with just their identity arrow.

Synopsis

Compilation

data Generator (p :: CAT k) where Source Github #

A generator in the finite alphabet, with evidence for connecting its ports. Reflection is local to this alphabet; completion itself needs only EqGen.

Constructors

Generator :: forall {k} {p :: CAT k} (a :: k) (b :: k). (Ob' a, Ob' b, Typeable a, Typeable b) => p a b -> Generator p 

data NormalForms (p :: CAT k) Source Github #

A normal-form acceptor. Its states remember the longest suffix which is a proper prefix of a forbidden word, as in the Aho–Corasick construction. Words are read in execution order, opposite to the displayed path spine.

compile :: forall {k} (p :: CAT k). EqGen p => [SomeOb k] -> [Generator p] -> Completion p -> Maybe (NormalForms p) Source Github #

Compile a finite object universe, alphabet and successful completion. List all objects, including isolated ones. Every generator endpoint must be declared. Duplicate objects are removed. The alphabet must contain every generator in the completed rules, including their right sides; it may also contain generators absent from the equations. Duplicates are removed. Returns Nothing for an incomplete system, an undeclared endpoint or a missing rule generator.

>>> import Proarrow.Category.Instance.Unit (Unit(..))
>>> import Proarrow.Category.Instance.Paths (pathLength)
>>> let done = KB.complete (KB.Limits 4 20) [] :: KB.Completion Unit
>>> let forms = maybe (error "compilation failed") id (compile [Some @'()] [Generator Unit] done)
>>> cardinality @'() @'() forms
Just Infinite
>>> fmap (map pathLength . take 4) (enumerate @'() @'() forms)
Just [0,1,2,3]
>>> let discrete = maybe (error "compilation failed") id (compile [Some @'()] [] done)
>>> cardinality @'() @'() discrete
Just (Finite 1)

Hom-sets

enumerate :: forall {k} (a :: k) (b :: k) (p :: CAT k). (Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> Maybe [('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)] Source Github #

Every normal arrow between the requested objects, in nondecreasing word length. Infinite hom-sets are enumerated fairly; finite and empty ones terminate. An undeclared endpoint gives Nothing. Paths are constructed raw, independently of any Rewrite instance.

data Cardinality Source Github #

Number of arrows in a hom-set. Infinite means a cycle lies on an accepted route, not merely that the presentation contains a cycle.

Constructors

Finite Natural 
Infinite 

cardinality :: forall {k} (a :: k) (b :: k) (p :: CAT k). (Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> Maybe Cardinality Source Github #

Count the arrows, or return Nothing for an undeclared endpoint.

cardinalitiesFrom :: forall {k} (a :: k) (p :: CAT k). (Ob' a, Typeable a) => NormalForms p -> Maybe [(SomeOb k, Cardinality)] Source Github #

Count all hom-sets out of the given source in one traversal of its reachable automaton. Results follow the declared object order and include empty hom-sets. An undeclared source gives Nothing.

cardinalitiesTo :: forall {k} (b :: k) (p :: CAT k). (Ob' b, Typeable b) => NormalForms p -> Maybe [(SomeOb k, Cardinality)] Source Github #

Count all hom-sets into the given target. Results follow the declared object order and include empty hom-sets. An undeclared target gives Nothing.

renderDot :: forall {k} (a :: k) (b :: k) (p :: CAT k). (Ob' a, Ob' b, Typeable a, Typeable b, Show2 p) => NormalForms p -> Maybe String Source Github #

Render the productive automaton for a → b as Graphviz DOT. Node labels show the current object and remembered suffix in execution order. An incoming arrow marks the start, and double circles mark states where a word may end. An empty hom-set produces an empty graph. An undeclared endpoint gives Nothing.

Cancellation

isEpi :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe Bool Source Github #

Test right cancellation against every object of the compiled presentation. Returns Nothing for an undeclared endpoint, a generator outside the alphabet, or when an infinite hom-set leaves cancellation undecided.

isMono :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe Bool Source Github #

Test left cancellation. The object universe and result have the same interpretation as in isEpi.

data EpiMonoFactorization (p :: CAT k) (a :: k) (b :: k) where Source Github #

An epic arrow followed by a monic arrow, or a definitive negative result for the declared presentation.

Constructors

EpiMonoFactorization :: forall {k} {p :: CAT k} {a :: k} {b :: k} (x :: k). (Ob' x, Typeable x) => (('PTH a :: PATHS p) ~> ('PTH x :: PATHS p)) -> (('PTH x :: PATHS p) ~> ('PTH b :: PATHS p)) -> EpiMonoFactorization p a b 
NoEpiMonoFactorization :: forall {k} (p :: CAT k) (a :: k) (b :: k). EpiMonoFactorization p a b 

epiMonoFactorization :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe (EpiMonoFactorization p a b) Source Github #

Find an epi–mono factorisation, with both legs in normal form. Returns Nothing for an undeclared endpoint, a generator outside the alphabet, or when infinite hom-sets leave the existence of a factorisation undecided.

Limits and colimits

terminalObjects :: forall {k} (p :: CAT k). NormalForms p -> [SomeOb k] Source Github #

Terminal objects of the compiled presentation.

initialObjects :: forall {k} (p :: CAT k). NormalForms p -> [SomeOb k] Source Github #

Initial objects of the compiled presentation.

data Cone (p :: CAT k) (a :: k) (b :: k) where Source Github #

A cone with an apex and two outgoing legs, as returned by binaryProducts and pullbacks.

Constructors

Cone :: forall {k} {p :: CAT k} {a :: k} {b :: k} (x :: k). (Ob' x, Typeable x) => (('PTH x :: PATHS p) ~> ('PTH a :: PATHS p)) -> (('PTH x :: PATHS p) ~> ('PTH b :: PATHS p)) -> Cone p a b 

data Cocone (p :: CAT k) (a :: k) (b :: k) where Source Github #

A cocone with an apex and two incoming legs, as returned by binaryCoproducts and pushouts.

Constructors

Cocone :: forall {k} {p :: CAT k} {a :: k} {b :: k} (x :: k). (Ob' x, Typeable x) => (('PTH a :: PATHS p) ~> ('PTH x :: PATHS p)) -> (('PTH b :: PATHS p) ~> ('PTH x :: PATHS p)) -> Cocone p a b 

binaryProducts :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> Maybe [Cone p a b] Source Github #

Find every binary product cone for the given objects, in terms of normal paths. An empty list means no such cone exists in the presentation. Returns Nothing if an endpoint is undeclared or a candidate that passes the hom-set count check requires testing an infinite hom-set.

binaryCoproducts :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> Maybe [Cocone p a b] Source Github #

Find every binary coproduct cocone for the given objects. The result has the same interpretation as in binaryProducts.

data Equalizer (p :: CAT k) (a :: k) where Source Github #

An equalizer with its apex and inclusion into the source of the parallel arrows.

Constructors

Equalizer :: forall {k} {p :: CAT k} {a :: k} (x :: k). (Ob' x, Typeable x) => (('PTH x :: PATHS p) ~> ('PTH a :: PATHS p)) -> Equalizer p a 

equalizers :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe [Equalizer p a] Source Github #

Find every equalizer of two parallel paths. Returns Nothing for an undeclared endpoint, a generator outside the alphabet, or an infinite hom-set into the common source that prevents enumerating equalizing arrows. An empty list means no equalizer exists in the declared presentation.

data Coequalizer (p :: CAT k) (b :: k) where Source Github #

A coequalizer with its apex and quotient from the target of the parallel arrows.

Constructors

Coequalizer :: forall {k} {p :: CAT k} {b :: k} (x :: k). (Ob' x, Typeable x) => (('PTH b :: PATHS p) ~> ('PTH x :: PATHS p)) -> Coequalizer p b 

coequalizers :: forall {k} (a :: k) (b :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> (('PTH a :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe [Coequalizer p b] Source Github #

Find every coequalizer of two parallel paths. The result has the dual interpretation to equalizers, testing hom-sets out of the common target.

pullbacks :: forall {k} (a :: k) (b :: k) (c :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b, Typeable c) => NormalForms p -> (('PTH a :: PATHS p) ~> ('PTH c :: PATHS p)) -> (('PTH b :: PATHS p) ~> ('PTH c :: PATHS p)) -> Maybe [Cone p a b] Source Github #

Find every pullback of two paths with a common target. An empty list means no pullback exists. Returns Nothing for an undeclared endpoint, a generator outside the alphabet, or an infinite hom-set that prevents enumerating the pairs of compatible arrows.

pushouts :: forall {k} (a :: k) (b :: k) (c :: k) (p :: CAT k). (EqGen p, Ob' a, Ob' b, Typeable a, Typeable b, Typeable c) => NormalForms p -> (('PTH c :: PATHS p) ~> ('PTH a :: PATHS p)) -> (('PTH c :: PATHS p) ~> ('PTH b :: PATHS p)) -> Maybe [Cocone p a b] Source Github #

Find every pushout of two paths with a common source. The result has the dual interpretation to pullbacks.