Website/slides/talks/2018-2-DBCategoryTheory/index.html

501 lines
17 KiB
HTML
Raw Normal View History

2018-01-15 23:43:28 -05:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Category Theory for DB-ies</title>
<meta name="description" content="Mimir">
<meta name="author" content="Oliver Kennedy">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="../reveal.js-3.5.0/css/reveal.css">
<link rel="stylesheet" href="ubodin.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="../reveal.js-3.5.0/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? '../reveal.js-3.5.0/css/print/pdf.css' : '../reveal.js-3.5.0/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="../reveal.js-3.5.0/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="header">
<!-- Any Talk-Specific Header Content Goes Here -->
Category Theory for DB-ies
</div>
<div class="footer">
<!-- Any Talk-Specific Footer Content Goes Here -->
<div style="float: left; margin-top: 15px; ">
Exploring <u><b>O</b></u>nline <u><b>D</b></u>ata <u><b>In</b></u>teractions
</div>
<img src="graphics/FullText-white.png" height="40" style="float: right;"/>
</div>
<div class="slides">
<section>
<section>
<h2>Category Theory for DB-ies</h2>
2018-01-23 18:23:31 -05:00
<h4>(Or how I learned that mathematicians are bad at naming)<h4>
2018-01-15 23:43:28 -05:00
</section>
<section>
<img src="graphics/bake_pi.jpg" height="400px">
</section>
<section>
<p>People always say that SQL is "Declarative"</p>
</section>
<section>
<h3>Why is the following replacement ok?</h3>
<pre><code class="sql">
SELECT * FROM R WHERE A = 1 AND B = 2
</code></pre>
<pre><code class="sql">
SELECT * FROM (SELECT * FROM R WHERE A = 1) WHERE B = 2
</code></pre>
<p class="fragment">(and how is it the same as computing $x + 1 + 2$?)</p>
</section>
</section>
<section>
<section>
<h2>Addition is Cool</h2>
<p class="fragment" data-fragment-index="1">
<b class="fragment" data-fragment-index="4">Commutative</b>
$$a + b = b + a$$
</p>
<p class="fragment" data-fragment-index="2">
<b class="fragment" data-fragment-index="4">Associative</b>
$$(a + b) + c = a + (b + c)$$
</p>
<p class="fragment" data-fragment-index="3">
<b class="fragment" data-fragment-index="4">Neutral Element</b>
$$0 + a = a$$
</p>
</section>
<section>
<h2>Addition is Cool</h2>
<pre><code class="java">
public int add(int a, int b) { ... }
add(a, b) == add(b, a)
add(add(a, b), c) == add(a, add(b, c))
add(a, 0) == a
</code></pre>
</section>
<section>
<h2>Math is about Patterns</h2>
<table style="font-size: smaller;">
<tr><th>Commutativity</th><th>Associativity</th><th>Neutral Element</th></tr>
<tr>
<td>$a + b = b + a$</td>
<td>$(a + b) + c = a + (b + c)$</td>
<td>0</td>
</tr>
<tr class="fragment">
<td>$a \texttt{ AND } b = b \texttt{ AND } a$</td>
<td>$(a \texttt{ AND } b) \texttt{ AND } c = a \texttt{ AND } (b \texttt{ AND } c)$</td>
<td>TRUE</td>
</tr>
<tr class="fragment">
<td>$a \texttt{ OR } b = b \texttt{ OR } a$</td>
<td>$(a \texttt{ OR } b) \texttt{ OR } c = a \texttt{ OR } (b \texttt{ OR } c)$</td>
<td>FALSE</td>
</tr>
<tr class="fragment">
<td>$A \cup B = B \cup A$</td>
<td>$(A \cup B) \cup C = A \cup (B \cup C)$</td>
<td>$\emptyset$</td>
</tr>
<tr class="fragment" style="font-size: smaller">
<td>$min(A, B) = min(B, A)$</td>
<td>$min(min(A, B), C) = min(A, min(B, C))$</td>
<td>$\infty$</td>
</tr>
</table>
<p class="fragment">Mathematicians call this a <b>Group</b></p>
</section>
<section>
<pre><code class="java">
interface Group&lt;K&gt; {
public K getZero() { ... }
public K add(K a, K b) { ... }
}
</code></pre>
<br/>
<p class="fragment">
$$\left<\; K,\; +,\; 0\;\right>$$
</p>
</section>
<section>
$$\left<\; \mathbb R,\; +,\; 0\;\right>$$
$$\left<\; \mathbb N,\; +,\; 0\;\right>$$
$$\left<\; \mathbb B,\; \texttt{AND},\; \texttt{TRUE}\;\right>$$
$$\left<\; \mathbb B,\; \texttt{OR},\; \texttt{FALSE}\;\right>$$
2018-01-23 18:23:31 -05:00
$$\left<\; Set,\; \cup,\; \emptyset\;\right>$$
$$\left<\; Multiset,\; \uplus,\; \emptyset\;\right>$$
2018-01-15 23:43:28 -05:00
$$\left<\; \mathbb R,\; min,\; \infty;\right>$$
</section>
</section>
<section>
<section>
<h2>Fun With Groups</h2>
2018-01-23 18:23:31 -05:00
<p style="margin-top: 100px; margin-bottom: 200px;">
$$\left<\; Set,\; \cup,\; \emptyset\;\right>$$
$$\left<\; \mathbb N,\; max,\; -\infty\;\right>$$
</p>
</section>
<section>
<pre><code class="java">
class SetGroup implements Group&lt;Set&lt;int&gt;&gt; {
public Set&lt;int&gt; getZero() { return Collections.emptySet(); }
public Set&lt;int&gt; add(Set&lt;int&gt; a, Set&lt;int&gt; b) {
Set&lt;int&gt; tmp = new HashSet&lt;int&gt;(a);
tmp.addAll(b);
return tmp;
}
}
</code></pre>
</section>
<section>
<pre><code class="java">
class IntMaxGroup implements Group&lt;int&gt; {
public int getZero() { return Integer.MIN_VALUE; }
public int add(int a, int b) { return Integer.max(a, b) }
}
</code></pre>
</section>
<section>
<pre><code class="java">
public int SetMax(Set&lt;int&gt; set) {
int ret = Integer.MIN_VALUE
for(int i : set) {
ret = Integer.max(i, ret);
}
return ret;
}
</code></pre>
<p style="margin-top: 100px;" class="fragment">
$$\texttt{SetMax} : SetGroup \rightarrow IntGroup$$
</p>
</section>
<section>
<p>There's something really cool about <tt>SetMax</tt></p>
</section>
<section>
$$\texttt{SetMax}(A + B) \equiv \texttt{SetMax}(A) + \texttt{SetMax}(B)$$
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
class="fragment"
style="margin-top: 100px"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="151.58365mm"
height="91.03521mm"
viewBox="0 0 537.10742 322.5657"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="homomorphism.svg">
<defs
id="defs4">
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path4145"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 Z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
transform="matrix(-0.8,0,0,-0.8,-10,0)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-9"
style="overflow:visible"
inkscape:isstock="true">
<path
inkscape:connector-curvature="0"
id="path4145-3"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 Z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-3"
style="overflow:visible"
inkscape:isstock="true">
<path
inkscape:connector-curvature="0"
id="path4145-6"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 Z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend-3-2"
style="overflow:visible"
inkscape:isstock="true">
<path
inkscape:connector-curvature="0"
id="path4145-6-4"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 Z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.7817968"
inkscape:cx="209.1726"
inkscape:cy="257.5391"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1388"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-44.717777,-130.8663)">
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="110.61171"
y="164.94319"
id="text8050"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan8052"
x="110.61171"
y="164.94319">A, B</tspan></text>
<g
id="g8212"
class="fragment">
<path
class=""
inkscape:connector-curvature="0"
id="path4136"
d="m 167.27963,175.21935 282.85714,0"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend)" />
<text
sodipodi:linespacing="125%"
id="text8050-8"
y="160.02646"
x="418.22684"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
id="tspan8072"
y="160.02646"
x="418.22684"
sodipodi:role="line">A U B</tspan></text>
</g>
<g
id="g8229"
class="fragment">
<path
class=""
inkscape:connector-curvature="0"
id="path4136-5-0"
d="m 452.04327,174.53242 0,183.99325"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend-3-2)" />
<text
sodipodi:linespacing="125%"
id="text8050-8-3"
y="397.267"
x="378.56348"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
id="tspan8072-3"
y="397.267"
x="378.56348"
sodipodi:role="line">max(A U B)</tspan></text>
</g>
<g
id="g8248"
class="fragment">
<path
inkscape:connector-curvature="0"
id="path4136-1"
d="m 167.27963,359.39757 282.85714,0"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend-9)" />
<path
inkscape:connector-curvature="0"
id="path4136-5"
d="m 167.321,174.53242 0,183.99325"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend-3)" />
<text
sodipodi:linespacing="125%"
id="text8050-8-3-4"
y="398.15857"
x="44.717777"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
id="tspan8072-3-7"
y="398.15857"
x="44.717777"
sodipodi:role="line">max(max(A),</tspan><tspan
id="tspan8120"
y="448.15857"
x="44.717777"
sodipodi:role="line"> max(B))</tspan></text>
</g>
</g>
</svg>
<p class="fragment">Mathematicians call this a <b>homomorphism</b></p>
2018-01-15 23:43:28 -05:00
</section>
2018-01-23 18:23:31 -05:00
<section>
<pre><code class="sql">
SELECT MAX(x) FROM (SELECT * FROM R UNION S)
</code></pre>
<pre><code class="sql">
MAX( (SELECT MAX(x) FROM R), (SELECT MAX(x) FROM S) )
</code></pre>
</section>
2018-01-23 18:25:33 -05:00
<section>
</section>
2018-01-15 23:43:28 -05:00
</section>
</div></div>
<script src="../reveal.js-3.5.0/lib/js/head.min.js"></script>
<script src="../reveal.js-3.5.0/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/../reveal.js#configuration
Reveal.initialize({
controls: false,
progress: true,
history: true,
center: true,
slideNumber: true,
transition: 'fade', // none/fade/slide/convex/concave/zoom
// Optional ../reveal.js plugins
dependencies: [
{ src: '../reveal.js-3.5.0/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: '../reveal.js-3.5.0/plugin/math/math.js',
condition: function() { return true; },
mathjax: '../reveal.js-3.5.0/js/MathJax.js'
},
{ src: '../reveal.js-3.5.0/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '../reveal.js-3.5.0/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '../reveal.js-3.5.0/plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: '../reveal.js-3.5.0/plugin/zoom-js/zoom.js', async: true },
{ src: '../reveal.js-3.5.0/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>