Crema di Mascarpone#

Inspired by Pawel’s blogpost Crema di Mascarpone and Diagrammatic Reasoning.

A simple recipe#

[1]:
from discopy import Ty, Box, Id

egg, white, yolk = Ty('egg'), Ty('white'), Ty('yolk')
sugar, mascarpone = Ty('sugar'), Ty('mascarpone')
yolky_paste, thick_paste = Ty('yolky_paste'), Ty('thick_paste')
crema_di_mascarpone = Ty('crema_di_mascarpone')

crack = Box('crack', egg, white @ yolk)
beat = Box('beat', yolk @ sugar, yolky_paste)
whisk = Box('whisk', white, white)
stir = Box('stir', yolky_paste @ mascarpone, thick_paste)
fold = Box('fold', white @ thick_paste, crema_di_mascarpone)


recipe = crack @ Id(sugar @ mascarpone)\
    >> whisk @ beat @ Id(mascarpone)\
    >> Id(white) @ stir\
    >> fold

recipe.draw(aspect='auto')
../_images/notebooks_crema-di-mascarpone_2_0.png

Cracking two eggs with a swap#

[2]:
from discopy import Swap

merge = lambda x: Box('merge', x @ x, x)

crack_two_eggs = crack @ crack\
    >> Id(white) @ Swap(yolk, white) @ Id(yolk)\
    >> merge(white) @ merge(yolk)

crack_two_eggs.draw()
../_images/notebooks_crema-di-mascarpone_4_0.png

Applying a substitution functor#

[3]:
from discopy import Functor

ob = lambda x: egg @ egg if x == egg else x
ar = lambda f: crack_two_eggs if f == crack else f
F = Functor(ob, ar)
F(recipe).draw(aspect='auto', figsize=(6, 6))
../_images/notebooks_crema-di-mascarpone_6_0.png