TermBase#
- class discopy.biclosed.TermBase(name, dom, cod, **params)[source]#
Bases:
BoxA term in the internal language of biclosed categories.
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
Applicationof 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
Abstractione.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( ... path='docs/_static/biclosed/alice-loves-bob.png', ... margins=(.3, 0), figsize=(5, 4))