opycleid.q_categoryaction

This module defines the basic classes needed for building morphisms in , the 2-category of finite sets and quantale-valued relations between them, where is a given quantale. Quantale number are encapsulated in an appropriate class in order to provide the two basic operations of the quantale, namely the supremum and the monoid operation. Three quantales are implemented in opycleid.q_categoryaction: the interval quantale, the multiplicative quantale, and the linear order quantale with three elements. Custom quantales can also be written and used in QMorphism classes as long as they follow the same principles.

MultQ

opycleid.q_categoryaction.MultQ(x)

Defines a value in the multiplicative quantale. The multiplicative quantale is the complete lattice of ordered reals in the interval [0,1] with max as the supremum, and ordinary multiplication as the monoid operation.

Arguments

  • x: a float number in the interval [0,1].

Raises an exception if the value is not in the interval [0,1].


Static Methods

Unit

Unit()

Returns the unit of the multiplicative quantale for the monoid operation, the real value 1.0, as an instance of MultQ.


Zero

Zero()

Returns the zero of the multiplicative quantale for the monoid operation, the real value 0.0, as an instance of MultQ.


Methods

mul

Overloads the * operator in order to represent the monoid operation. A typical use is MultQ * MultQ. Raises an exception if the two classes are not instances of MultQ


add

Overloads the + operator in order to represent the quantale supremum. A typical use is MultQ + MultQ. Raises an exception if the two classes are not instances of MultQ


eq

Overloads the == operator.. A typical use is MultQ == MultQ. Returns True if the quantale numbers are the same, False otherwise. Raises an exception if the two classes are not instances of MultQ


lt

Overloads the < operator.. A typical use is MultQ < MultQ. Returns True if the lhs quantale number is strictly inferior to the rhs, according to the lattice structure of the quantale. In the multiplicative quantale, this coincides with the natural order of reals in the interval [0,1]. Raises an exception if the two classes are not instances of MultQ


le

Overloads the <= operator.. A typical use is MultQ <= MultQ. Returns True if the lhs quantale number is inferior or equal to the rhs, according to the lattice structure of the quantale. In the multiplicative quantale, this coincides with the natural order of reals in the interval [0,1]. Raises an exception if the two classes are not instances of MultQ


str

Overloads Python str to return the real number as a string.


IntvQ

opycleid.q_categoryaction.IntvQ(x)

Defines a value in the interval quantale. The interval quantale is the complete lattice of ordered reals in the interval [0,1] with max as the supremum, and min as the monoid operation.

Arguments

  • x: a float number in the interval [0,1].

Raises an exception if the value is not in the interval [0,1].


Static Methods

Unit

Unit()

Returns the unit of the interval quantale for the monoid operation, the real value 1.0, as an instance of IntvQ.


Zero

Zero()

Returns the zero of the interval quantale for the monoid operation, the real value 0.0, as an instance of IntvQ.


Methods

mul

Overloads the * operator in order to represent the monoid operation. A typical use is IntvQ * IntvQ. Raises an exception if the two classes are not instances of IntvQ


add

Overloads the + operator in order to represent the quantale supremum. A typical use is IntvQ + IntvQ. Raises an exception if the two classes are not instances of IntvQ


eq

Overloads the == operator.. A typical use is IntvQ == IntvQ. Returns True if the quantale numbers are the same, False otherwise. Raises an exception if the two classes are not instances of IntvQ


lt

Overloads the < operator.. A typical use is IntvQ < IntvQ. Returns True if the lhs quantale number is strictly inferior to the rhs, according to the lattice structure of the quantale. In the multiplicative quantale, this coincides with the natural order of reals in the interval [0,1]. Raises an exception if the two classes are not instances of IntvQ


le

Overloads the <= operator.. A typical use is IntvQ <= IntvQ. Returns True if the lhs quantale number is inferior or equal to the rhs, according to the lattice structure of the quantale. In the multiplicative quantale, this coincides with the natural order of reals in the interval [0,1]. Raises an exception if the two classes are not instances of IntvQ


str

Overloads Python str to return the real number as a string.


Lin3Q

opycleid.q_categoryaction.Lin3Q(x)

Defines a value in the linear order quantale with three elements. It is a sub-quantale of the interval quantale where the only possible values are 0, 1/2, or 1. As a Python class, it is a subclass of IntvQ.

Arguments

  • x: a float number being either 0, 1/2, or 1.

Raises an exception if the value is not one of the values above.


Static Methods

Unit

Unit()

Returns the unit of the linear order quantale with three elements for the monoid operation, the real value 1.0, as an instance of Lin3Q.


Zero

Zero()

Returns the zero of the linear order quantale with three elements for the monoid operation, the real value 0.0, as an instance of Lin3Q.


QMorphism

opycleid.categoryaction.QMorphism(name,source,target,qtype=None,mapping=None)

Defines a category morphism between two category objects in the category for a quantale . It is defined by its source, its target, a given quantale, and a relation between the source sets and the target sets.

Arguments

  • name: a string used to name the morphism.
  • source: an instance of opycleid.categoryaction.CatObject representing the source of the morphism.
  • target: an instance of opycleid.categoryaction.CatObject representing the target of the morphism.
  • qtype: a class opycleid.categoryaction.MultQ,opycleid.categoryaction.IntvQ, opycleid.categoryaction.Lin3Q, or any similarly defined class representing the quantale used for the morphism.
  • mapping: an optional argument representing the mapping between the source and the target. It can be given either in matrix form, as a NumPy array of quantale classes, or as a dictionary.

Raises an exception if the source or the target are not instances of opycleid.categoryaction.CatObject, or if the quantale type is not specified.


Methods

set_name

set_name(name)

Sets the name of the morphism to name.


set_to_identity

set_to_identity()

If the source and target are identical, sets the morphism to be the identity on this category object, i.e. the relation between the corresponding sets is the identity function. Raises an exception if the source and the target are not identical.


set_mapping

set_mapping(mapping)

Defines the relation between the source sets and the target sets. The argument mapping should be a dictionary, whose keys are elements in the source set, and whose values are lists of pairs. For each pair, the first term should be an element in the target set corresponding to one of the images of the source elements by the given relation, the second term should be a number representing the quantale value between the key and the first term.

The quantale values are converted internally in a matrix of QMorphism.qtype classes.


set_mapping_matrix

set_mapping_matrix(matrix)

Defines the relation between the source sets and the target sets using a matrix description. The argument mapping should be a NumPy array of type QMorphism.qtype. The rows of this matrix corresponds to the elements of the target sets, and the columns corresponds to the elements of the source sets, in both cases indexed as in the corresponding CatObject. Use only if you are sure about the correspondence between elements and element indices.


get_mapping

get_mapping()

Returns the relation defined by this morphism as a dictionary, whose keys are elements in the source set, and whose values are lists of pairs. In each pair, the first term corresponds to an element in the target set corresponding to one of the images of the key, and the second term is the corresponding quantale value between them, given as a Python number.


get_mapping_matrix

get_mapping_matrix()

Returns the relation defined by this morphism as a NumPy array of type QMorphism.qtype.


str

Overloads Python str to return a string description of the morphism, including its source, target, and the relation between them.


call

Makes the current instance callable. A typical use is QMorphism(elem) where elem is a string representing an element in the source set. Returns a list of pairs. In each pair, the first term corresponds to an element in the target set corresponding to one of the images of the argument, and the second term is the corresponding quantale value between them, given as a Python number, if that value is non-zero.


mul

Overloads the * operator in order to represent morphism composition. A typical use is QMorphism_2 * QMorphism_1. Raises an exception if the two morphisms use different quantales. If the target of QMorphism_1 is identical to the source of QMorphism_2, this returns the corresponding composite morphism. Otherwise, the two morphisms are not composable and None is returned.


pow

Overloads the ** operator in order to represent morphism iterated multiplication. A typical use is QMorphism ** int. If QMorphism is an endomorphism, i.e. its target is the same object as its source, this returns the corresponding iterated morphism. Otherwise, an exception will be raised.


eq

Overloads the == operator in order to check for morphism equality. A typical use is QMorphism_2 == QMorphism_1. Returns True if the sources, targets, and relations of both morphisms are equal. Raises an exception if the two morphisms use different quantales.


le

Overloads the <= operator in order to check for morphism inclusion. A typical use is QMorphism_2 <= QMorphism_1. Returns True if the sources, and targets of both morphisms are equal, and if the relation of QMorphism_2 is equal or included in the relation of QMorphism_1. Raises an exception if the two morphisms use different quantales.


lt

Overloads the < operator in order to check for strict morphism inclusion. A typical use is QMorphism_2 < QMorphism_1. Returns True if the sources, and targets of both morphisms are equal, and if the relation of QMorphism_2 is non-trivially included in the relation of QMorphism_1 (i.e. it is included but not equal). Raises an exception if the two morphisms use different quantales.


CategoryQAction

opycleid.categoryaction.CategoryQAction(qtype=None,objects=None,generators=None,generate=True)

Defines a category action object, i.e. a faithful functor , where is a small category, and is the 2-category of finite sets and quantale-valued relations. Instances of this class store internally

  • a dictionary of opycleid.categoryaction.CatObject instances, indexed by their name
  • a dictionary of opycleid.categoryaction.QMorphism instances, indexed by their name, corresponding to the generators of the category,
  • a dictionary of opycleid.categoryaction.QMorphism instances, indexed by their name, corresponding to all the operations of the category.

Arguments

  • qtype: a class opycleid.categoryaction.MultQ,opycleid.categoryaction.IntvQ, opycleid.categoryaction.Lin3Q, or any similarly defined class representing the quantale used for the morphism. If none is given, an exception will be raised.
  • objects: optional argument. A list of opycleid.categoryaction.CatObject instances with distinct names representing the objects in the category.
  • generators: optional argument. A list of opycleid.categoryaction.QMorphism instances with distinct names (an exception will be raised if this is not the case) representing the generators of the category.
  • generate: boolean, optional argument. If objects and generators are given at instantiation, specifies whether the category should immediately be generated.

Methods

set_objects

set_objects(list_objects)

The argument list_objects should be a list of opycleid.categoryaction.CatObject instances. Calling this method stores the CatObject instances in the internal dictionary, and resets the generators and operations of the category. The objects must have distinct elements and distinct names; an exception will be raised if this is not the case.


get_objects()

get_objects()

Returns the objects in this category, as a list of tuples (String,CatObject), where the CatObject instance is an object of the category, and String corresponds to its name.


set_generators

set_generators(list_morphisms)

The argument list_morphisms should be a list of opycleid.categoryaction.QMorphism instances with distinct names (an exception will be raised if this is not the case). Calling this method will erase the previous internal dictionaries of generators and morphisms (but not objects). The internal dictionary of generators is then updated with the instances of list_morphisms.


generate_category

generate_category()

Generates the category from the internal dictionary of generators. This means that for any operation and any generator of this category, the composite operation will be added to the internal dictionary of operations, if not already present, until the generation is complete.


get_generators()

get_generators()

Returns the objects in this category, as a list of tuples (String,QMorphism), where the QMorphism instance is a generator morphism of the category, and String corresponds to its name.


get_morphisms()

get_morphisms()

Returns the objects in this category, as a list of tuples (String,QMorphism), where the QMorphism instance is a morphism of the category, and String corresponds to its name.


rename_operation

rename_operation(name,new_name)

The arguments name and new_name are the name of a category operation, and the specified new name respectively. Renames an operation in the category.


rewrite_operations

rewrite_operations()

Rewrite/simplify operation names in the category. Calling this method will examine all operation names, trying to identify repeated instances of the names of the generators, and simplifying them to "([name]^p)" where p is the corresponding power.


mult

mult(operation_2,operation_1)

The arguments operation_2 and operation_1 are the names of category operations. Returns the name of the composite operation if present, or None if the category operations are not composable.


apply_operation

apply_operation(name,elem)

The argument name is the name of a category operation, and the argument elem is an element in its source set. Returns the images of elem by the category operation with name name, along with their associated quantale values.


get_operation

get_operation(elem_1,elem_2)

The arguments elem_1 and elem_2 are elements in the objects of the category. Returns all the operations in the category such that elem_2 is the image of elem_1 by with a non-zero quantale value.


get_description

get_description(name)

Returns a string description of the morphism with name name.