libutilitaspy.categories.categories

This module is provides a representation for categories from Category Theory.

For a definition of categories, see
http://en.wikipedia.org/wiki/Category_theory
and
http://en.wikipedia.org/wiki/Category_(mathematics)
class libutilitaspy.categories.categories.Object(obj=None, category=None)[source]

Instances of this class represent objects in some category.

class libutilitaspy.categories.categories.Arrow(source, target, label=None, category=None)[source]

Instances of this class represent arrows or morphisms between objects in some category.

dual()[source]

Warning: this does not compute inverse functions.

compose(other)[source]

Returns the composition of this arrow with another arrow, where this arrow goes first.

Parameters:other (Arrow) – some arrow
Returns:self.category.composite(self, other)
class libutilitaspy.categories.categories.Category(object_class, arrow_class)[source]

Instances of this class are intended to represent categories.

A category consists of:
  1. a class O of objects A, B, ...

  2. a class M of arrows (or morphisms) between objects f, g, ...

    where f:A \to B is an arrow with source A and target B, in which case we define src(f) = A and trg(f) = B

  3. a composition operation \circ between arrows

  4. an ‘identity’ arrow {id}_{A} for each object A

And it must satisfy the following:

  1. for every pair of arrows f and g, if the target of f is the source of g, then their composition, written g \circ f, exists, and is an arrow whose source is the source of f and whose target is the target of g. In short:

    if f:A \to B \in M and g:B \to C \in M then g \circ f:A \to C \in M

  2. for each object A, the identity arrow {id}_{A}:A \to A is the identity with respect to composition. This is,

    1. for any arrow f:A \to B \in M, f \circ {id}_{A} = f
    2. for any arrow g:B \to A \in M, {id}_{A} \circ g = g
  3. Composition is associative: for any arrows f:A \to B, g:B \to C, h:C \to D f \circ (g \circ h) = (f \circ g) \circ h

Instances of the Category class are intended to implement these categories, where objects are any Python objects and arrows are instances of the Arrow class (or any subclass).

This class is intended to be subclassed. In particular, a subclass should implement the composition and identity methods. Then to obtain the composition, a user calls the composite() method and to obtaind the identity, the user calls the ident() method of this class.

The composite() method is normally called via the Arrow.__mul__() method so if f:A \to B \in M and g:B \to C \in M then we can obtain g \circ f:A \to C \in
M by calling:

g * f

instead of:

cat.composite(f,g)

The constructor creates a category whose objects and arrows belong to the given classes.

Parameters:
  • object_class (subclass of Object) –
  • arrow_class (subclass of Arrow) –
composite(f, g, memoize=True)[source]

Returns the arrow g * f. Note that this intends to be f first, then g: f: A -> B and g: B -> C, then g * f == f >> g : A -> C

Note: it does not apply the composition, just computes and returns the composite arrow.

ident(obj, memoize=True)[source]

Returns the identity arrow of the object given. This method however, does not check that the arrow is indeed the identity.

hom(A, B)[source]

Should return the set of all arrows between A and B

colimit(diagram)[source]

Abstract method: should compute the colimit of the diagram in the category.

class libutilitaspy.categories.categories.FiniteCategory(object_class, arrow_class, objects=None, arrows=None)[source]

Instances of this subclass of Category make the assumption that the sets of objects and arrows are finite.

hom(A, B)[source]

Should return the set of all arrows between A and B

close()[source]

Compute the closure: generates all compositions and identities.

TODO: check whether this indeed computes the closure: add_edge adds new edges to self.arrows, but does this guarantee that all newly added edges will be traversed? If not, we may replace it with something like this:

arrow_list = list(self.arrows) new_arrows = [] for f in arrow_list:

for g in f.target.outgoing:
new_arrow = self.compose(f, g) new_arrows.append(new_arrow) arrow_list.append(new_arrow)
for f in new_arrows:
self.add_edge(f)

Previous topic

libutilitaspy.categories.finite_sets

Next topic

libutilitaspy.categories.diagrams

This Page