TermBase#

class discopy.biclosed.TermBase(name, dom, cod, **params)[source]#

Bases: Box

A term in the internal language of biclosed categories.

Parameters:
  • name (str)

  • dom (Ty)

  • cod (Ty)

dom#

The tensor of the types for each free variable.

Type:

Ty

cod#

The type of a term, i.e. the codomain of its morphism.

Type:

Ty

freevars#

The list of free variables.

Type:

Ty

functor#

The functor to evaluate the term, id by default.

Type:

Functor

Note

Constant terms can be instantiated from any diagram, if the domain is not empty (i.e. the diagram is a process not a state) then the constant is a given a function type with the argument coming either the left or right:

>>> X, Y = Ty("X"), Ty("Y")
>>> x, f, g = X("x"), (X >> Y)("f"), (Y << X)("g")

Terms can be the Application of a function to an argument from its left >> or right << with the type inferred automatically e.g.

>>> xf, gx = x(f, left=True), g(x)
>>> assert xf.cod == Y == gx.cod

Applying a biclosed type to a function yields an Abstraction e.g.

>>> f_, g_ = X(lambda y, left=True: y(f, left=True)), X(lambda y: g(y))
>>> assert f.cod == f_.cod == X >> Y and g.cod == g_.cod == Y << X

Terms are required to be linear and planar, they can be drawn as diagrams:

>>> N, S = Ty("N"), Ty("S")
>>> Alice, loves, Bob = N("Alice"), ((N >> S) << N)("loves"), N("Bob")
>>> Alice(loves(Bob), left=True).draw(
...     doctest='docs/_static/biclosed/alice-loves-bob.svg',
...     margins=(.3, 0), figsize=(5, 4))
abstract eval()[source]#

The evaluation of a Functor on a term gives a morphism in its codomain. By default, this is the identity functor on the free biclosed category, i.e. terms are compiled to diagrams with constants as boxes.

Parameters:

functor (Functor)

Return type:

BiclosedCategory

abstract map(context)[source]#

The image of a term under a Functor whose codomain objects are biclosed types, i.e. a term in the codomain’s internal language rather than a morphism.

Parameters:
Return type:

Term

draw(**kwargs)[source]#

Drawing a term by evaluating it in the free biclosed category.

to_closed()[source]#

Translate the term into the internal language of a closed category.