{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Monoidal categories in lambeq\n", "\n", "In order to use the advanced features of `lambeq` and extend it, an understanding of {term}`monoidal categories ` and how it is implemented in the {py:mod}`lambeq.backend` is required.\n", "\n", "{download}`⬇️ Download code <../_code/monoidal.ipynb>`\n", "\n", "## Categories\n", "\n", "A *category* consists of a collection of *objects* $A, B, C, \\ldots$ and a collection of *morphisms* between objects of the form $f: A \\to B, g: B \\to C, h: C \\to D, \\ldots$, such that:\n", "\n", "* Morphisms with matching types compose. For example, $f: A \\to B$ and $g: B \\to C$ can compose to make $g \\circ f: A \\to C$, but not $f \\circ g$.\n", "* Morphisms compose in an associative way: $(h \\circ g) \\circ f = h \\circ (g \\circ f)$\n", "* Each object has an identity arrow: $1_B \\circ f = f = f \\circ 1_A$\n", "\n", "These definitions are implicitly encoded in this *commutative diagram*: any directed path between two specific objects represents equal morphisms.\n", "\n", "
\n", " \"drawing\"\n", "
\n", "\n", "For *free* {term}`categories `: we first define generating objects with the {py:class}`~lambeq.backend.grammar.Ty` class and generating morphisms with the {py:class}`~lambeq.backend.grammar.Box` class, then build composite morphisms by freely combining the generating morphisms using backward composition `>>` (then)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from lambeq.backend.grammar import Box, Id, Ty\n", "\n", "A, B, C, D = map(Ty, 'ABCD')\n", "\n", "f = Box('f', A, B)\n", "g = Box('g', B, C)\n", "h = Box('h', C, D)\n", "\n", "# the codomain of f and domain of g match, so f and g compose\n", "f >> g\n", "assert f.cod == g.dom == B\n", "\n", "# associativity\n", "assert f >> (g >> h) == f >> g >> h == (f >> g) >> h\n", "\n", "# identity\n", "assert Id(A) >> f == f.to_diagram() == f >> Id(B)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned above, in `lambeq` the generating morphisms are defined using the {py:class}`~lambeq.backend.grammar.Box` class. When morphisms are composed, they combine to become an {py:class}`~lambeq.backend.grammar.Diagram`. This explains the need for the {py:meth}`.grammar.Box.to_diagram` call above as `f` was declared as a {py:class}`.grammar.Box` instance and cannot be directly tested for equality with a {py:class}`.grammar.Diagram` instance. Compared to traditional category theory notation, `lambeq` prefers to use backwards composition `>>`, where `f >> g` should be read as \"`f` followed by `g`\"." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# only arrows that 'type-check' can be composed\n", "diagram = f >> g >> h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A {py:class}`~lambeq.backend.grammar.Diagram` behaves like a `List[Diagram]`: it can be indexed, sliced, or even reversed. Reversing a morphism actually performs the *dagger* operation, which is the abstract notion of a dagger in quantum mechanics and linear algebra." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "|Ty() @ [f; Ty(A) -> Ty(B)] @ Ty()| >> |Ty() @ [g; Ty(B) -> Ty(C)] @ Ty()| >> |Ty() @ [h; Ty(C) -> Ty(D)] @ Ty()|\n", "Indexing: |Ty() @ [f; Ty(A) -> Ty(B)] @ Ty()|\n", "Slicing: |Ty() @ [g; Ty(B) -> Ty(C)] @ Ty()| >> |Ty() @ [h; Ty(C) -> Ty(D)] @ Ty()|\n", "Reversing (dagger): |Ty() @ [h†; Ty(D) -> Ty(C)] @ Ty()| >> |Ty() @ [g†; Ty(C) -> Ty(B)] @ Ty()| >> |Ty() @ [f†; Ty(B) -> Ty(A)] @ Ty()|\n" ] } ], "source": [ "print(diagram)\n", "print(f'Indexing:', diagram[0])\n", "print(f'Slicing:', diagram[1:])\n", "print(f'Reversing (dagger):', diagram[::-1])" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Monoidal categories\n", "\n", "A *monoidal category* is a category equipped with the *monoidal product* $\\otimes$ and *monoidal unit* $I$ and has the following properties:\n", "\n", "* objects can be combined to return another object (e.g $A \\otimes B$)\n", "* morphisms can be combined to return another morphism ($(f: A \\to B) \\otimes (g: C \\to D) = f \\otimes g: A \\otimes C \\to B \\otimes D$).\n", "* $\\otimes$ is associative on objects: $(A \\otimes B) \\otimes C = A \\otimes (B \\otimes C)$\n", "* $\\otimes$ is associative on morphisms: $(f \\otimes g) \\otimes h = f \\otimes (g \\otimes h)$\n", "* $I$ is the identity on objects for $\\otimes$: $A \\otimes I= A = I \\otimes A$\n", "* $1_I$ is the identity on arrows for $\\otimes$: $f \\otimes 1_I = f = 1_I \\otimes f$\n", "\n", "For {term}`monoidal categories `: again, the generating objects are defined with the {py:class}`~lambeq.backend.grammar.Ty` class, and the generating morphisms with the {py:class}`~lambeq.backend.grammar.Box` class; the composite objects are built using `@` and the composite morphisms using `>>`." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from lambeq.backend.grammar import Box, Id, Ty\n", "\n", "A, B, C = Ty('A'), Ty('B'), Ty('C')\n", "\n", "f = Box('f', A, B)\n", "g = Box('g', B, C)\n", "h = Box('h', B, A)\n", "\n", "# combining types\n", "A @ B\n", "# combining boxes\n", "f @ g\n", "\n", "# associativity\n", "assert (A @ B) @ C == A @ B @ C == A @ (B @ C)\n", "assert (f @ g) @ h == f @ g @ h == f @ (g @ h) \n", "\n", "# monoidal unit\n", "assert A @ Ty() == A == Ty() @ A\n", "assert f @ Id(Ty()) == f.to_diagram() == Id(Ty()) @ f" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{term}`Monoidal categories ` have an elegant graphical calculus, which allow them to be drawn and manipulated graphically." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "|Ty() @ [x; Ty(A) -> Ty(A)] @ Ty(A)| >> |Ty() @ [y; Ty(A) @ Ty(A) -> Ty(B)] @ Ty()|\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgcAAAFACAYAAAAoFN9yAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMSwgaHR0cHM6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yMAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x = Box('x', A, A)\n", "y = Box('y', A @ A, B)\n", "\n", "diagram = x @ Id(A) >> y\n", "print(repr(diagram))\n", "diagram.draw(figsize=(5, 3))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A {py:class}`~lambeq.backend.grammar.Ty` can be indexed, sliced, or even reversed, just like a `List[Ty]`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A @ B @ C\n", "Ty(A) @ Ty(B) @ Ty(C)\n", "Indexing: A\n", "Slicing: B @ C\n", "Reversing: C @ B @ A\n" ] } ], "source": [ "t = A @ B @ C\n", "\n", "print(t)\n", "print(repr(t))\n", "\n", "print('Indexing:', t[0])\n", "print(f'Slicing:', t[1:])\n", "print(f'Reversing:', t[::-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, a {py:class}`.grammar.Diagram` behaves like a `List[Diagram]`, so it can be indexed, sliced, and reversed. Reversing a diagram performs the dagger operation." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "|Ty() @ [x; Ty(A) -> Ty(A)] @ Ty(A)| >> |Ty() @ [y; Ty(A) @ Ty(A) -> Ty(B)] @ Ty()|\n", "Indexing: |Ty() @ [x; Ty(A) -> Ty(A)] @ Ty(A)|\n", "Slicing: |Ty() @ [y; Ty(A) @ Ty(A) -> Ty(B)] @ Ty()|\n", "Reversing (dagger): |Ty() @ [y†; Ty(B) -> Ty(A) @ Ty(A)] @ Ty()| >> |Ty() @ [x†; Ty(A) -> Ty(A)] @ Ty(A)|\n", "\n", "Dagger operation:\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAwwAAAFACAYAAAARevtFAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMSwgaHR0cHM6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TBAAAAJAkGAAAgSTAAAABJggEAAEgSDAAAQJJgAAAAkgQDAACQJBgAAIAkwQAAACQJBgAAIEkwAAAASYIBAABIEgwAAECSYAAAAJIEAwAAkCQYAACAJMEAAAAkCQYAACBJMAAAAEmCAQAASCp0dXV15R4BAAD0TZ4wAAAASYIBAABIEgwAAECSYAAAAJIEAwAAkCQYAACAJMEAAAAkCQYAACBJMAAAAEmCAQAASBIMAABAkmAAAACSBAMAAJAkGAAAgCTBAAAAJAkGAAAgSTAAAABJggEAAEgSDAAAQJJgAAAAkgQDAACQJBgAAIAkwQAAACQJBgAAIEkwAAAASYIBAABIEgwAAECSYAAAAJIEAwAAkCQYAACAJMEAAAAkCQYAACBJMAAAAEmCAQAASPo/tUgIu47uyDMAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "print(diagram)\n", "print(f'Indexing:', diagram[0])\n", "print(f'Slicing:', diagram[1:])\n", "print(f'Reversing (dagger):', diagram[::-1])\n", "\n", "from lambeq.backend.drawing import draw_equation\n", "\n", "print('\\nDagger operation:')\n", "# boxes are drawn as trapeziums to demonstrate the reflection along the horizontal axis\n", "draw_equation(diagram, diagram[::-1], symbol='->', figsize=(8, 3), asymmetry=0.2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A {term}`monoidal category` equipped with a {py:class}`~lambeq.backend.grammar.Swap` is known as a {term}`symmetric monoidal category`. Nested swaps can be defined using the {py:meth}`~lambeq.backend.grammar.Diagram.swap` method." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIAAAAB4CAYAAAA6//q/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/SrBM8AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAH/ElEQVR4nO2dTUwTXRfH/x0qHwWECguK7qYJICay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qCAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lambeq.backend.grammar import Diagram, Swap\n", "\n", "Swap(A, B).draw(figsize=(1, 1), draw_as_pregroup=False)\n", "Diagram.swap(A @ B, C).draw(figsize=(2, 2), draw_as_pregroup=False)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "```{note}\n", "In a strict mathematical sense, the associativity and unit rules of $\\otimes$ in a {term}`monoidal category` only hold up to *isomorphism*. As a consequence, this definition requires extra morphisms such as unitors and associators, as well as complicated coherence conditions. Instead, `lambeq` strictly enforces the rules to hold up to equality, so such coherence conditions are unnecessary. This greatly simplifies its practical use.\n", "```\n", "\n", "## Rigid monoidal categories\n", "\n", "A *rigid category* is a monoidal category where every object $A$ has a *left adjoint* $A^l$ and *right adjoint* $A^r$. The left adjoint of the right adjoint of a type is equal to the type itself, and vice versa: $(A^r)^l = A = (A^l)^r$\n", "\n", "In `lambeq`, the {term}`adjoint` of a type {py:class}`~lambeq.backend.grammar.Ty` is obtained using the `.l` and `.r` properties:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A.l is represented as Ty(A).l\n", "A.r is represented as Ty(A).r\n" ] } ], "source": [ "from lambeq.backend.grammar import Box, Id, Ty\n", "\n", "A = Ty('A')\n", "\n", "print(A.l, 'is represented as', repr(A.l))\n", "print(A.r, 'is represented as', repr(A.r))\n", "\n", "assert A.r.l == A == A.l.r" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The key property of a {term}`rigid category` is the existence of {term}`cups ` and {term}`caps ` between an object and its {term}`adjoint`: these are special morphisms that are drawn as bent wires in diagrammatic notation." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAzMAAABeCAYAAAAXKUqvAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlc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K8ltxtxu7niaLe3tqWXuAOZxzZ2Obu/cydyx2Wyy2+1tzpvWj3X0iLRrmdN4ew7CDAAAAAAjcVwdAAAAgJEIMwAAAACMRJgBAAAAYCTCDAAAAAAjEWYAAAAAGIkwAwAAAMBIhBkAAAAARiLMAAAAADASYQYAAACAkQgzAAAAAIxEmAEAAABgJMIMAAAAACMRZgAAAAAYiTADAAAAwEj/BysTlHsF2FJqAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAzMAAABeCAYAAAAXKUqvAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/SrBM8AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAQxklEQVR4nO3dbWxTdRvH8V/XwRiDPSUIGzDEBIEhgtsynS/kSQWEYJB0hIiYSCAaEYgZUaPIQzQkEgMCb0SnBAOGNRohJAgJKLxgPGzAQMZwiYMOxkDcGA/rurY794v7bm8GG26w7fScfT/JCSttxlV69er5/c9p6zAMwxAAAAAAWEyU2QUAAAAAwMMgzAAAAACwJMIMAAAAAEsizAAAAACwJMIMAAAAAEsizAAAAACwJMIMAAAAAEsizAAAAACwJMIMAAAAAEsizAAAAACwJMIMAAAAAEsizAAAAACwJMIMAAAAAEuKNrsAdIympqZmm2EYrf7sdDrlcDgUFRUV3u69HBVFzgXwYG2dO5JanDXMHQDt9aC5E7ocDAZbnTXMHfshzHQBwzB0+/Zt1dTUqLa29r7txo0b8nq9amhokM/nC293X/636wKBQJtq6du3r27duvWvt4uOjlZMTEx469WrV4s/t3Zdr169lJiYqKSkpBa3+Ph4BgjQiQzD0M2bN1ucOXfPnbbOmJaua+vcaavQ3GnLjGnpcmxsbKtzJzk5WX379pXD4ejQmgH8X1NT07/OndD8aM8+zt3XtWXuxMfH6+bNm22qOTo6ut37OHdfbm3uJCcnKykpSX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fHkGTMmTPHuHz5stklwWJqamqMRYsWGVFRUUZ6errx22+/mV0SIlxhYaGRkZFhSDLmz59vXLt2zeySYDHXrl0z3nrrLUOSkZGRYRQWFppdEiLcgQMHjPT0dCMqKspYtGiRUVtba3ZJsJhLly4Zc+bMMSQZzz//vHHy5EmzS3pklo9ja9euVVZWlurq6nTgwAFt376dU4XQbklJSdq4caOKi4uVkJCgCRMmaPHixS1+4SewfPly5eTkyDAMHT58WN9++y2nCqHd+vXrp/z8fB0+fFiGYSgnJ0fLly83uyxEION/R34nTpyoxMREFRcXa+PGjbY6VQhdY+DAgdq+fbsOHDig2tpaZWZmau3atWaX9WjMzVKP5qeffjIkGXl5eUZjY6PZ5cAmgsGgsX79ekOSsX79erPLQYT5/vvvDUnG6tWrjUAgYHY5sIlAIGCsWrXKkGRs2bLF7HIQYdatWxd+TQoGg2aXA5tobGw08vLyDEnGzz//bHY5D82y75k5c+aMcnJy9Morr2jHjh28LwYdLi8vT+vWrdOvv/6ql156yexyEAEKCws1fvx4zZs3T5s3b2buoEMZhqEFCxbohx9+0MGDB/Xcc8+ZXRIiwL59+zR16lS9//771l9BR8QxDEO5ubnas2ePCgsLNXr0aLNLajfLhpnJkyfr8uXLOnr0qOLi4swuBzYUDAY1efJkeTwenT9/nh1XKDs7W1FRUTp06BAf7Y5O4fP59MILL8gwDB07dszscmAywzA0fPhwpaWlae/evXxIBDrFnTt39Oyzz2rgwIHau3ev2eW0myXfM3P9+nXt379fixYtIsig0zidTuXl5am8vFynT582uxyYrKKiQsePH9fSpUsJMug0MTExWrp0qY4fP64LFy6YXQ5MVlJSovLyci1btowgg04TFxend999V/v379c///xjdjntZskwU1RUFF41BzrTpEmT5HQ6dfjwYbNLgcmOHj0qScwddLopU6ZIko4cOWJyJTBbYWGhnE6nJk6caHYpsLkpU6YoGAzq+PHjZpfSbpYMMw0NDRo6dCif4oFO16NHD40aNUrBYNDsUmCyxsZG5g66RGJiooYOHarGxkazS4HJgsGgRo0axXefodOF5k5D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K29MLp06dNqAx2w2scQugFdJVIfo1zGBY8mdTtdis3N1c3btyw9XnBiAzJycn66KOPtGzZMrNLgYm++eYbLVy40Pbn3yMyOBwObd68WQsWLDC7FJho7dq1WrNmjWpqaswuBTZXV1enxMREFRQUyOVymV1Ou9jyyAwAAAAA+yPMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAASyLMAAAAALAkwgwAAAAAS7JkmElOTlZ2dracTqfZpaAbyMzMVEpKitllwGT9+vVTdna22WWgm8jOzla/fv3MLgMmS0lJUWZmptlloBtwOp3Kzs5WcnKy2aW0m8MwDMPsIgAAAACgvSx5ZAYAAAAACDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCSCDMAAAAALIkwAwAAAMCS/gMC+W0hQb/DwwAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lambeq.backend.grammar import Cap, Cup\n", "\n", "draw_equation(Cup(A.r, A.r.r), Cup(A, A.r), Cup(A.l, A), symbol='...', figsize=(8, 1))\n", "draw_equation(Cap(A.l, A.l.l), Cap(A, A.l), Cap(A.r, A), symbol='...', figsize=(8, 1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{term}`Cups ` and {term}`caps ` satisfy the so-called {term}`snake equations`:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Snake Equations - For any object A :\n" ] }, { "data": { "image/png": "iVBORw0KGgo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swUCgYDVIQAAAACgqzgzAwAAAMBIlBkAAAAARqLMAAAAADASZQYAAACAkSgzAAAAAIxEmQEAAABgJMoMAAAAACNRZgAAAAAYiTIDAAAAwEiUGQAAAABGoswAAAAAMBJlBgAAAICRKDMAAAAAjESZAQAAAGAkygwAAAAAI1FmAAAAABiJMgMAAADASJQZAAAAAEaizAAAAAAwEmUGAAAAgJEoMwAAAACMRJkBAAAAYCTKDAAAAAAjUWYAAAAAGOn/AMaf5yFSiFqOAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "snake1 = Id(A) @ Cap(A.r, A) >> Cup(A, A.r) @ Id(A)\n", "snake2 = Cap(A, A.l) @ Id(A) >> Id(A) @ Cup(A.l, A)\n", "\n", "assert snake1.normal_form() == Id(A) == snake2.normal_form()\n", "print('Snake Equations - For any object', A, ':')\n", "draw_equation(snake1, Id(A), snake2, figsize=(8, 2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{note}\n", "The {py:meth}`.grammar.Diagram.normal_form` method used above also applies on standard monoidal diagrams.\n", "```\n", "\n", "Nested {term}`cups ` and {term}`caps ` can be created using the {py:meth}`.grammar.Diagram.cups` and {py:meth}`.grammar.Diagram.caps` methods." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAC3CAYAAACsaM6NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/SrBM8AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAYXElEQVR4nO3df0yU9wHH8c/9gAMRUKkI+LP+Ap04J+q6Gn9FVzHo1orW1VDn5mY10aqJy2yWpVnWLpuNWdKgc8GzjNo60aXpZJnOOquLdWNSEZyOLf6q8sOfgJw/4O64/WG4FQEFHuG5O96v5Mn9eO45Pjw+j/e5793zYPH5fD4BAAAAnW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AAyhUAIAAMAQCiUAAAAMoVACAADAEAolAAAADKFQAgAAwBAKJQAAAAyhUAIAAMAQCiUAAAAMoVACAADAEAolAAAADKFQAgAAwBAKJQAAAAyhUAIAAMAQCiUAAAAMoVACAADAEAolAAAADKFQAgAAwBAKJQAAAAyhUAIAAMAQCiUAAAAMoVACAADAEAolAAAADKFQAkCIe+6555STkyO73W52lJAxfvx45eTkKCYmxuwoQECw+Hw+n9khAAAAELwYoQQAAIAhFEoAAAAYQqEEAACAIRRKAAAAGEKhBAAAgCEUSgAAABhCoQQAAIAhFEoAAAAYQqEEAACAIRRKAAAAGEKhBAAAgCEUSgAAABhCoQQAAIAhFEoAAAAYQqEEAACAIRRKAAAAGEKhBAAAgCEUSgAAABhCoQQAAIAhFEoAAAAYQqEEAACAIRRKAAAAGPI/JevmmdHqZEYAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lambeq.backend.grammar import Diagram\n", "\n", "A, B = Ty('A'), Ty('B')\n", "\n", "nested_cup = Diagram.cups(A @ B, (A @ B).r)\n", "nested_cap = Diagram.caps((A @ B).r, A @ B)\n", "\n", "nested_snake = Id(A @ B) @ nested_cap >> nested_cup @ Id(A @ B)\n", "\n", "assert nested_snake.normal_form() == Id(A @ B)\n", "draw_equation(nested_snake, nested_snake.normal_form())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0rc1" } }, "nbformat": 4, "nbformat_minor": 4 }