Functor#

class discopy.biclosed.Functor(ob_map=None, ar_map=None, dom=None, cod=None, colour_map=None)[source]#

Bases: discopy.monoidal.Functor

A biclosed functor is a monoidal functor that preserves evaluation and currying.

Parameters:
  • ob_map (Mapping[Ty, Ty]) – Map from atomic Ty to cod.ob.

  • ar_map (Mapping[Box, Diagram]) – Map from Box to cod.

  • cod (Category) – The codomain of the functor.

  • dom (C0)

Note

When the codomain objects are biclosed types, the functor sends terms to terms rather than evaluating them to morphisms:

>>> X, Y = Ty("X"), Ty("Y")
>>> f, x = (Y << X)("f"), X("x")
>>> F = Functor(ob_map={X: Ty("A"), Y: Ty("B")},
...             ar_map={f: (Ty("B") << Ty("A"))("g"), x: Ty("A")("a")})
>>> assert F(f(x)) == F(f)(F(x))

The image of a term is checked to have the image of its type:

>>> Functor(ob_map={X: Ty("A"), Y: Ty("B")}, ar_map={f: Ty("A")("a")})(f)
Traceback (most recent call last):
    ...
discopy.utils.AxiomError: Expected a term of type (B << A) for ...
dom#

alias of Diagram

cod#

alias of Diagram

map_variable(variable, context)[source]#

The image of a variable, of the image of its type, renamed with underscores until it differs from the images already in the context.

Parameters:
  • variable (Variable) – The variable to map.

  • context (dict) – The images of the variables bound so far.

Return type:

Variable

map_term(term, context=None)[source]#

The image of a term, a term in the internal language of the codomain, checked to have the image of its type and exactly the images of its free variables, in order when the codomain is planar.

Parameters:
  • term (TermBase) – The term to map.

  • context (dict) – The images of the free variables, fresh ones by default.

Return type:

TermBase