Diagram#

class discopy.grammar.abstract.Diagram(inside, dom, cod, _scan=True)[source]#

Bases: discopy.closed.Diagram

An abstract diagram is a closed diagram with words as boxes, i.e. a derivation in an abstract categorial grammar.

The rules of a categorial grammar are its closed structure: application is evaluation, composition is the currying of two evaluations and crossed composition coincides with composition, since a closed category has one exponential.

Parameters:
  • inside (Layer) – The layers inside the diagram.

  • dom (Ty) – The domain of the diagram, i.e. its input.

  • cod (Ty) – The codomain of the diagram, i.e. its output.

ob#

alias of Ty

classmethod fa(left, right)[source]#

Forward application (left << right) @ right -> left.

Parameters:
  • left (Ty)

  • right (Ty)

Return type:

Diagram

classmethod ba(left, right)[source]#

Backward application left @ (left >> right) -> right.

Parameters:
  • left (Ty)

  • right (Ty)

Return type:

Diagram

classmethod fc(left, middle, right)[source]#

Forward composition (left << middle) @ (middle << right) -> left << right.

Parameters:
  • left (Ty)

  • middle (Ty)

  • right (Ty)

Return type:

Diagram

classmethod bc(left, middle, right)[source]#

Backward composition (left >> middle) @ (middle >> right) -> left >> right.

Parameters:
  • left (Ty)

  • middle (Ty)

  • right (Ty)

Return type:

Diagram

classmethod fx(left, middle, right)[source]#

Forward crossed composition, which coincides with fc().

Parameters:
  • left (Ty)

  • middle (Ty)

  • right (Ty)

Return type:

Diagram

classmethod bx(left, middle, right)[source]#

Backward crossed composition, which coincides with bc().

Parameters:
  • left (Ty)

  • middle (Ty)

  • right (Ty)

Return type:

Diagram

classmethod from_categorial(diagram)[source]#

The abstract diagram of a categorial diagram, or the abstract term of a categorial term, dropping planarity: left and right exponentials collapse, constants stay constants and words become boxes, crossed compositions become compositions and the composition and type-raising terms become lambda terms.

Parameters:

diagram (Diagram) – The categorial diagram or term to translate.

Return type:

Diagram

Example

>>> from discopy.grammar import categorial
>>> n, s = categorial.Ty("n"), categorial.Ty("s")
>>> Alice, loves, Bob = n("Alice"), ((n >> s) << n)("loves"), n("Bob")
>>> print(Diagram.from_categorial(Alice(loves(Bob), left=True)))
loves(Bob)(Alice)
coeval_factory#

alias of Coeval

copy_factory#

alias of Copy

curry_factory#

alias of Curry

discard_factory#

alias of Discard

eval_factory#

alias of Eval

factory#

alias of Diagram

functor_factory#

alias of Functor

permutation_factory#

alias of Permutation

sum_factory#

alias of Sum

swap_factory#

alias of Swap

trace_factory#

alias of Trace