Diagram#

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

Bases: discopy.markov.Diagram

A feedback diagram is a markov diagram with a delay() endofunctor and a feedback() operator.

Parameters:
  • inside (monoidal.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.

Example

>>> x = Ty('x')
>>> zero = Box('0', Ty(), x.head)
>>> rand = Box('rand', Ty(), x)
>>> plus = Box('+', x @ x, x)
>>> walk = (rand.delay() @ x.delay() >> zero @ plus.delay()
...         >> FollowedBy(x) >> Copy(x)).feedback()
>>> walk.draw(path="docs/_static/feedback/feedback-random-walk.png",
...           figsize=(5, 5), margins=(0.25, 0.01))
../_images/feedback-random-walk.png
ty_factory#

alias of Ty

layer_factory#

alias of Layer

delay(n_steps=1)[source]#

The delay of a feedback diagram.

feedback(dom=None, cod=None, mem=None)[source]#

Syntactic sugar for Feedback.

classmethod wait(dom)[source]#

Wait one time step, i.e. Swap(x, x.delay()).feedback().

Example

>>> x = Ty('x')
>>> assert Diagram.wait(x) == Swap(x, x.delay()).feedback()
>>> Diagram.wait(x).draw(path="docs/_static/feedback/wait.png")
../_images/wait.png
Parameters:

dom (Ty) –

Return type:

Diagram

property time_step: int#

The time step of a diagram is defined only if it is in fact a box.

This is used for checking equality between boxes and diagrams.

Example

>>> f = Box('f', 'x', 'y')
>>> assert f.delay(42).time_step == 42
property head#

Syntactic sugar for Head.

property tail#

Syntactic sugar for Tail.

property d#

delay.

Type:

Syntactic sugar for meth

braid_factory#

alias of Swap

copy_factory#

alias of Copy

factory#

alias of Diagram

feedback_factory#

alias of Feedback

followed_by#

alias of FollowedBy

merge_factory#

alias of Merge