Diagram#
- class discopy.closed.Diagram(inside, dom, cod, _scan=True)[source]#
Bases:
discopy.markov.Diagram,discopy.biclosed.Diagram,discopy.abc.ClosedCategoryA closed diagram is both a markov and a biclosed diagram.
A diagram applied to another post-composes their tensor with an Eval.
- Parameters:
inside (tuple[Layer, ...])
dom (C0)
cod (C0)
- to_compact()[source]#
Open the curry bubbles into coevaluation and feedback, which stays a
Diagramas a closed category is traced: each curry becomes its argument followed byCoeval, traced over the curried wires, and each term is evaluated first.Example
>>> x, y, z = map(Ty, "xyz") >>> f = Box("f", x @ y, z) >>> assert f.curry().to_compact() == ( ... f >> Coeval(z << y, left=True)).trace()
- Return type:
- to_term()[source]#
Read a causal diagram as a term in fine-grain call-by-value style: one let statement per box in topological order with a variable for each wire, going through
Hypergraphso that the copy, discard and swap structure simplifies away into the spiders.The free variables of the term are the inputs that the diagram actually uses; a diagram with no box is a tuple of variables.
Example
>>> X, Y = Ty("X"), Ty("Y") >>> f, g = Box("f", X, Y @ Y), Box("g", Y @ Y, Y) >>> diagram = Diagram.copy(X) >> f @ Diagram.discard(X) >> g >>> print(diagram.to_term()) let(f(x0), lambda x1, x2: g(Tuple(x1, x2))) >>> assert Diagram.swap(X, Y).to_term()\ ... == Tuple(Variable("x1", Y), Variable("x0", X))
- Return type:
Term
- classmethod box_to_term(box, args)[source]#
The application of a box as a constant to variables for its inputs.
- copy_factory#
alias of
Copy
- permutation_factory#
alias of
Permutation
- swap_factory#
alias of
Swap
- trace_factory#
alias of
Trace