Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Last active March 23, 2020 21:19
Show Gist options
  • Save Risto-Stevcev/ba05f0d1538e7c71338418e05f35f383 to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/ba05f0d1538e7c71338418e05f35f383 to your computer and use it in GitHub Desktop.
What the difference is between relations, operations, and functions
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Relations\n",
"\n",
"Relations are a subset of a cartesian product of two sets (the domain and codomain)\n",
"\n",
"- They _might not_ have an arrow for every element in the domain (ie: `d`)\n",
"- They can have _multiple_ arrows coming out of a single element in the domain to multiple elements in the codomain (ie: `b` `->` `2`, `3`)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.42.3 (0)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"310pt\" height=\"221pt\"\n",
" viewBox=\"0.00 0.00 310.00 221.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 217)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-217 306,-217 306,4 -4,4\"/>\n",
"<g id=\"clust1\" class=\"cluster\">\n",
"<title>clusterD</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"8,-130 8,-205 294,-205 294,-130 8,-130\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-189.8\" font-family=\"Times,serif\" font-size=\"14.00\">domain</text>\n",
"</g>\n",
"<g id=\"clust2\" class=\"cluster\">\n",
"<title>clusterC</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"40,-8 40,-122 262,-122 262,-8 40,-8\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-106.8\" font-family=\"Times,serif\" font-size=\"14.00\">codomain</text>\n",
"</g>\n",
"<g id=\"clust3\" class=\"cluster\">\n",
"<title>clusterI</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"112,-16 112,-91 254,-91 254,-16 112,-16\"/>\n",
"<text text-anchor=\"middle\" x=\"183\" y=\"-75.8\" font-family=\"Times,serif\" font-size=\"14.00\">image</text>\n",
"</g>\n",
"<!-- a -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>a</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"259\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"259\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"219\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"219\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- a&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>a&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M252.92,-137.99C246.43,-119.79 236.03,-90.7 228.46,-69.49\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"231.66,-68.04 225,-59.8 225.07,-70.4 231.66,-68.04\"/>\n",
"</g>\n",
"<!-- b -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>b</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"187\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"187\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
"</g>\n",
"<!-- b&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>b&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M191.86,-137.99C197.06,-119.79 205.37,-90.7 211.43,-69.49\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"214.82,-70.38 214.2,-59.8 208.09,-68.46 214.82,-70.38\"/>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"147\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"147\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- b&#45;&gt;3 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>b&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M180.92,-137.99C174.43,-119.79 164.03,-90.7 156.46,-69.49\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"159.66,-68.04 153,-59.8 153.07,-70.4 159.66,-68.04\"/>\n",
"</g>\n",
"<!-- c -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>c</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"115\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n",
"</g>\n",
"<!-- c&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>c&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M119.86,-137.99C125.06,-119.79 133.37,-90.7 139.43,-69.49\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"142.82,-70.38 142.2,-59.8 136.09,-68.46 142.82,-70.38\"/>\n",
"</g>\n",
"<!-- d -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>d</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"43\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"75\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"75\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x7f0c5c790eb0>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from graphviz import Digraph\n",
"\n",
"g = Digraph('G')\n",
"g.attr(compound='true')\n",
"\n",
"with g.subgraph(name='clusterD') as c:\n",
" c.attr(label='domain')\n",
" c.node('a')\n",
" c.node('b', color=\"blue\")\n",
" c.node('c')\n",
" c.node('d', color=\"blue\")\n",
"\n",
"with g.subgraph(name='clusterC') as c:\n",
" c.attr(label='codomain')\n",
" c.node('1')\n",
" with c.subgraph(name='clusterI') as c:\n",
" c.attr(label='image')\n",
" c.node('2', color=\"blue\")\n",
" c.node('3', color=\"blue\")\n",
"\n",
"g.edge('a', '2')\n",
"g.edge('b', '2', color=\"blue\")\n",
"g.edge('b', '3', color=\"blue\")\n",
"g.edge('c', '3')\n",
" \n",
"g"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Operations\n",
"\n",
"- More constrained than `relations`: a specific type of relation where _every_ element in the domain maps to some element in the codomain.\n",
"- They can have multiple arrows coming out from a single element in the domain to multiple elements in the codomain (ie: `b` `->` `2`, `3`)\n",
"- Common example of this behavior is the `√` operator, where every input has two outputs, positive and negative (ex: `√100` = `10` _and_ `-10`)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.42.3 (0)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"310pt\" height=\"221pt\"\n",
" viewBox=\"0.00 0.00 310.00 221.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 217)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-217 306,-217 306,4 -4,4\"/>\n",
"<g id=\"clust1\" class=\"cluster\">\n",
"<title>clusterD</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"8,-130 8,-205 294,-205 294,-130 8,-130\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-189.8\" font-family=\"Times,serif\" font-size=\"14.00\">domain</text>\n",
"</g>\n",
"<g id=\"clust2\" class=\"cluster\">\n",
"<title>clusterC</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"8,-8 8,-122 230,-122 230,-8 8,-8\"/>\n",
"<text text-anchor=\"middle\" x=\"119\" y=\"-106.8\" font-family=\"Times,serif\" font-size=\"14.00\">codomain</text>\n",
"</g>\n",
"<g id=\"clust3\" class=\"cluster\">\n",
"<title>clusterI</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"80,-16 80,-91 222,-91 222,-16 80,-16\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-75.8\" font-family=\"Times,serif\" font-size=\"14.00\">image</text>\n",
"</g>\n",
"<!-- a -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>a</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"259\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"259\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"187\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"187\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- a&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>a&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M248.68,-138.95C236.71,-120.32 216.82,-89.38 202.87,-67.69\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"205.65,-65.54 197.3,-59.02 199.76,-69.32 205.65,-65.54\"/>\n",
"</g>\n",
"<!-- b -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>b</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"187\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"187\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
"</g>\n",
"<!-- b&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>b&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M187,-137.99C187,-120.06 187,-91.56 187,-70.44\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"190.5,-70.17 187,-60.17 183.5,-70.17 190.5,-70.17\"/>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"115\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- b&#45;&gt;3 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>b&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M169.85,-141.78C163.36,-136.18 156.28,-129.27 151,-122 139.37,-105.99 130.21,-85.64 124.03,-69.59\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"127.15,-67.94 120.41,-59.76 120.58,-70.36 127.15,-67.94\"/>\n",
"</g>\n",
"<!-- c -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>c</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"115\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n",
"</g>\n",
"<!-- c&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>c&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M115,-137.99C115,-120.06 115,-91.56 115,-70.44\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"118.5,-70.17 115,-60.17 111.5,-70.17 118.5,-70.17\"/>\n",
"</g>\n",
"<!-- d -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>d</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"43\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n",
"</g>\n",
"<!-- d&#45;&gt;3 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>d&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M61.99,-142.95C69.64,-137.33 78.05,-130.1 84,-122 95.45,-106.41 103.31,-86.04 108.25,-69.89\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"111.7,-70.56 111.08,-59.98 104.97,-68.63 111.7,-70.56\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"43\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x7f0c5c7be4f0>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from graphviz import Digraph\n",
"\n",
"g = Digraph('G')\n",
"g.attr(compound='true')\n",
"\n",
"with g.subgraph(name='clusterD', comment='foo') as c:\n",
" c.attr(label='domain')\n",
" c.node('a')\n",
" c.node('b', color=\"blue\")\n",
" c.node('c')\n",
" c.node('d')\n",
"\n",
"with g.subgraph(name='clusterC') as c:\n",
" c.attr(label='codomain')\n",
" c.node('1')\n",
" with c.subgraph(name='clusterI') as c:\n",
" c.attr(label='image')\n",
" c.node('2', color=\"blue\")\n",
" c.node('3', color=\"blue\")\n",
"\n",
"g.edge('a', '2')\n",
"g.edge('b', '2', color=\"blue\")\n",
"g.edge('b', '3', color=\"blue\")\n",
"g.edge('c', '3')\n",
"g.edge('d', '3')\n",
"\n",
"g"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Functions\n",
"\n",
"- Type of relation where _every_ element in the domain maps to some element in the codomain.\n",
"- More constrained than `operations`: unlike operations, an element in the domain can only have _one_ arrow going to an element in the codomain. However, multiple elements in the domain can point to the same element in the codomain (ie: `a`, `b`, `c` `->` `2`).\n",
"- It may be one-to-one and/or onto.\n",
"- The codomain and image might not be the same (unless it's a bijection). Some elements in the codomain may not be reached."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.42.3 (0)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"346pt\" height=\"221pt\"\n",
" viewBox=\"0.00 0.00 346.00 221.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 217)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-217 342,-217 342,4 -4,4\"/>\n",
"<g id=\"clust1\" class=\"cluster\">\n",
"<title>clusterD</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"44,-130 44,-205 330,-205 330,-130 44,-130\"/>\n",
"<text text-anchor=\"middle\" x=\"187\" y=\"-189.8\" font-family=\"Times,serif\" font-size=\"14.00\">domain</text>\n",
"</g>\n",
"<g id=\"clust2\" class=\"cluster\">\n",
"<title>clusterC</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"8,-8 8,-122 230,-122 230,-8 8,-8\"/>\n",
"<text text-anchor=\"middle\" x=\"119\" y=\"-106.8\" font-family=\"Times,serif\" font-size=\"14.00\">codomain</text>\n",
"</g>\n",
"<g id=\"clust3\" class=\"cluster\">\n",
"<title>clusterI</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"80,-16 80,-91 222,-91 222,-16 80,-16\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-75.8\" font-family=\"Times,serif\" font-size=\"14.00\">image</text>\n",
"</g>\n",
"<!-- a -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>a</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"295\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"295\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"187\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"187\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- a&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>a&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M280.88,-140.36C262.37,-121.16 229.72,-87.3 208.22,-65.01\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"210.58,-62.41 201.12,-57.65 205.54,-67.27 210.58,-62.41\"/>\n",
"</g>\n",
"<!-- b -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>b</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"223\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"223\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
"</g>\n",
"<!-- b&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>b&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M217.53,-137.99C211.68,-119.79 202.33,-90.7 195.52,-69.49\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"198.79,-68.25 192.4,-59.8 192.13,-70.39 198.79,-68.25\"/>\n",
"</g>\n",
"<!-- c -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>c</title>\n",
"<ellipse fill=\"none\" stroke=\"blue\" cx=\"151\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"151\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n",
"</g>\n",
"<!-- c&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>c&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"blue\" d=\"M156.47,-137.99C162.32,-119.79 171.67,-90.7 178.48,-69.49\"/>\n",
"<polygon fill=\"blue\" stroke=\"blue\" points=\"181.87,-70.39 181.6,-59.8 175.21,-68.25 181.87,-70.39\"/>\n",
"</g>\n",
"<!-- d -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>d</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"79\" cy=\"-156\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"79\" y=\"-152.3\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"115\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"115\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- d&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>d&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M84.47,-137.99C90.32,-119.79 99.67,-90.7 106.48,-69.49\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"109.87,-70.39 109.6,-59.8 103.21,-68.25 109.87,-70.39\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"43\" cy=\"-42\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"43\" y=\"-38.3\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x7f0c5c7be730>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from graphviz import Digraph\n",
"\n",
"g = Digraph('G')\n",
"g.attr(compound='true')\n",
"\n",
"with g.subgraph(name='clusterD', comment='foo') as c:\n",
" c.attr(label='domain')\n",
" c.node('a', color=\"blue\")\n",
" c.node('b', color=\"blue\")\n",
" c.node('c', color=\"blue\")\n",
" c.node('d')\n",
"\n",
"with g.subgraph(name='clusterC') as c:\n",
" c.attr(label='codomain')\n",
" c.node('1')\n",
" with c.subgraph(name='clusterI') as c:\n",
" c.attr(label='image')\n",
" c.node('2', color=\"blue\")\n",
" c.node('3')\n",
"\n",
"g.edge('a', '2', color=\"blue\")\n",
"g.edge('b', '2', color=\"blue\")\n",
"g.edge('c', '2', color=\"blue\")\n",
"g.edge('d', '3')\n",
"\n",
"g"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment