Delete text.html

This commit is contained in:
boris 2019-02-15 19:21:23 +02:00 committed by GitHub
parent 7834ab2b04
commit a8dbad1c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,62 +0,0 @@
<h1 id="from-sets-to-categories">From Sets to Categories</h1>
<p>In this chapter we will continue with set theory and at the same time we will start exploring categories.</p>
<h1 id="products">Products</h1>
<p>In the previous chapter, we needed a way to make a set that is a composite of other sets that we already have. For example when we discussed mathematical functions, we couldn&#39;t define <strong>+</strong> and <strong>-</strong> functions, because we only knew about functions that take one argument. When we talked about programming, we talked about the primitive types, <code>Char</code> and <code>Number</code>, and we mentioned that most of the types are composite types. So how do we construct those?</p>
<p>The simplest composite type, of the sets <strong>B</strong>, which contains <strong>b</strong>&#39;s and the set<strong>Y</strong>, which contains <strong>y</strong>&#39;s is the the <em>product</em> or <strong>B</strong> and <strong>Y</strong>.</p>
<p><img src="product_parts.svg" alt="Product parts"></p>
<p>It is the set of <em>pairs</em> of <strong>b</strong>&#39;s and <strong>y</strong>&#39;s.</p>
<p><img src="product.svg" alt="Product"></p>
<p>The product is denoted <strong>B x Y</strong> and it comes equipped with two functions for retrieving the <strong>b</strong> and the <strong>y</strong> from each <strong>(b, y)</strong>.</p>
<p>Question: Why is this called a product? Hint: How many elements does it have?</p>
<h2 id="products-as-objects">Products as Objects</h2>
<p>We established that in programming sets resemble types and functions resemble functions. Products, in this case, are like stripped-out <em>classes</em> (also called <em>records</em> or <em>structs</em>). The composite sets (the ones which form the product) are just the class&#39;s fields (also called <em>members</em>). The functions for accessing them are like what programmers call <em>getter methods</em>.</p>
<p>For example the famous OOP example of <code>Person</code> class with <code>name</code> and <code>age</code> fields is nothing more than a product of the set of strings, and the sets of numbers (we still haven&#39;t defined strings and lists in terms of set theory but we will get to that). Objects with more than two values can be expressed as products the composites of which are themselves products.</p>
<h2 id="using-products-to-define-numeric-operations">Using Products to Define Numeric Operations</h2>
<p>Products can also be used for expressing functions which take more than one argument. For example, &quot;plus&quot; and &quot;minus&quot;, are functions from the set of products of two numbers to the set of numbers. (so <strong>+: R x R → R</strong>). Of course, we cannot draw the function itself, even partly, because it has too much arrows and it would look messy.</p>
<p>Joking, here it is.</p>
<p><img src="plus.svg" alt="The plus function"></p>
<p>Note that there are languages where the <em>pair</em> datastructure (also called a <em>tuple</em>) is a first-level construct, and multi-argument functions are really implemented in this way. </p>
<h2 id="defining-products-in-terms-of-sets-">Defining products in Terms of Sets </h2>
<p>Now we will define the abstract concept of a product of two sets sets in terms of sets themselves. It is not hard: the product of two sets <strong>Y</strong> and <strong>B</strong> is just the set of all possible <em>ordered pairs</em>, which contain one element of the set <strong>Y</strong> and one element of the set <strong>B</strong>. Or formally speaking <strong>Y x B = { (y, b) }</strong> where <strong>y ∈ Y, b ∈ B</strong> (<strong></strong> means &quot;is an element of&quot;).</p>
<p><img src="pair.svg" alt="A pair"></p>
<p>The real challenge is defining what a pair means in terms of sets. Note that the pair have to be <em>ordered</em>, so it cannot be just a set of the elements (formally speaking <strong>A x B ≠ B x A for all A and B </strong>). Some mathematical operations such as addition and multiplication don&#39;t care about order, but others, such as subtraction, do. And in programming we have the ability to assign names to each member of an object, which accomplishes the same purpose as ordering does for pairs.</p>
<p>So the pair must be ordered, and sets aren&#39;t. Turns out that that hasn&#39;t stopped mathematicians from coming up with multiple ingenious ways to represent an ordered pair using sets. Let&#39;s see them, just for fun. Here is the first one, which was discovered by Norbert Wiener in 1914. The definition is notable for its smart use of the uniqueness of the empty set. </p>
<p><img src="pair_as_set_2.svg" alt="A pair, represented by sets"></p>
<p>The next one was discovered in the same year by Felix Hausdorff. In order to use that one, we just have to define &quot;1&quot;, and &quot;2&quot; first.</p>
<p><img src="pair_as_set_3.svg" alt="A pair, represented by sets"></p>
<p>Discovered in 1921 Kazimierz Kuratowski, this one uses just the component of the pair.</p>
<p><img src="pair_as_set_1.svg" alt="A pair, represented by sets"></p>
<h2 id="defining-products-in-terms-of-functions-">Defining products in Terms of Functions </h2>
<p>In the previous chapter we provided a definition of a product by <em>zooming in</em> the individual elements of the sets and seeing what they can be made of. This gave us a <em>low-level</em> view of products. This time we will try to do the opposite - be as oblivious to the contents of our sets as possible. Instead of zooming in we will <em>zoom out</em>, and try define the product in terms of functions and functional composition. Effectively we will be working at a <em>higher level</em> of abstraction.</p>
<p>So let&#39;s begin with an external diagram, showing the definition of the product. Disclaimer: I know that this is a somewhat weird notation, but don&#39;t worry, we will not be using it for very long.</p>
<p><img src="product_external.svg" alt="Product, external diagram"></p>
<p>This diagram already contains the first piece of the puzzle if we have a set <strong>G</strong> which is the product of sets <strong>Y</strong> and <strong>B</strong>, then we should also have functions which give us back the elements of the product, so <strong>G → Y</strong> and <strong>G → B</strong>. </p>
<p>This definition is not complete, however, because the product of <strong>G</strong> and <strong>B</strong> is not the only set for which such functions can be defined. For example a set of triples of <strong>Y x B x R</strong> for some random element <strong>R</strong> also qualifies. And if there is a function from <strong>G</strong> to <strong>B</strong> then the set <strong>G</strong> itself meets our condition for being the product, because it is connected to <strong>B</strong> and to itself. </p>
<p>Depending on our specific case there can be many other other such objects.</p>
<p><img src="product_candidates.svg" alt="Product, external diagram"></p>
<p>So how do we set apart all those &quot;imposter&quot; products from the one true product? Simple - they all can be converted to it. This is true, because by definition the pair is nothing more than the sum of its elements, and by definition each impostor can be converted to both elements of the pair.</p>
<p>More formally, in order for a set <strong>I</strong> to serve as an impostor for the product of <strong>B</strong> and <strong>Y</strong> and there should be two functions, which we will call <strong>b: I → B</strong> and <strong>y: I → Y</strong>. In order to prove that <strong>I</strong> is an impostor we need a function <strong>I → B x Y</strong>. That function is simply (programmers will understand this best) <strong>(a) → b(a) x y(a)</strong> for each <strong>a:I</strong>.</p>
<p><img src="products_morphisms.svg" alt="Product, external diagram"></p>
<p>Notice that this definition does not rule out the sets which are isomorphic to the product - when we represents things using functions, the isomorphism is equality.</p>
<h1 id="sum">Sum</h1>
<p>We will now study a construct that is pretty similar to the product, but at the same time it is very different. Similar because, like the product, it is a relation between two sets which allows you to unite them into one, without erasing their structure. Different because it encodes a different type of relation between them - a product encodes an <strong>AND</strong> relation between two sets, while the sum encodes an <strong>OR</strong> relation. For example, a parent is either a mother of a father of a child, so the set of parent&#39;s is a sum set of the sets of mothers and fathers. </p>
<p><img src="coproduct.svg" alt="Sum or coproduct"></p>
<p>Notice that the when a given object is an element of both sets, then it appears in the sum twice. This is why this type of sum of two sets is also called a <em>disjoint union</em>.</p>
<h2 id="defining-sums-in-terms-of-sets">Defining Sums in Terms of Sets</h2>
<p>Simply put, a sum of two sets is a set that contains all elements from the first set and all elements from the second one. But, as with the product, it is not so straightforward to represent sums in terms of sets. For example if two sets can have the same element as a member, their sum will have that element twice which is not permitted, because a set cannot contain the same element twice.</p>
<p>As with the product, the solution is to put some extra structure.</p>
<p><img src="coproduct_member.svg" alt="A member of a coproduct"></p>
<p>Like with the product, there is a low-level way to express a sum using sets alone. Incidentally, we can use pairs.</p>
<p><img src="coproduct_member_set.svg" alt="A member of a coproduct, examined"></p>
<h2 id="defining-sums-in-terms-of-functions">Defining Sums in Terms of Functions</h2>
<p>You might already suspect, the interesting part is expressing the sum of two sets using functions. To do that we have to go back to the conceptual part of the definition. The sum expresses an <strong>OR</strong> relation between two things. A simple property of every <strong>OR</strong> relation is that if something is an <strong>A</strong> that something is also <strong>A OR B</strong>, and the same if it is <strong>B</strong>. For example if I am <em>a man</em>, I am also <em>a man OR a woman</em>. This is what <strong>OR</strong> means, right?</p>
<p>This relationship can be expressed as a function. Two functions actually - one for each set that takes part in the relation.</p>
<p><img src="coproduct_external.svg" alt="Coproduct, external diagram"></p>
<p>Why can it be expressed as a function? Because it is a <em>many-to-one</em> relationship (<em>one-to-one</em> if you want to be precise).</p>
<p>You might already notice that this definition is pretty similar to the previous one, and the similarities don&#39;t end here - here again we have sets that can be thought as <em>impostor</em> sums - ones for which these functions exists, but which aren&#39;t real sums, where by &quot;real sum&quot; we mean a set which expresses the <em>OR</em> relation and does just that (so no additional structure). </p>
<p><img src="product_candidates.svg" alt="Coproduct, external diagram"></p>
<p>What are we saying with this, if we apply it to the example, is simply that if parents are either mothers or fathers, then there exist a functions <strong>mothers → parents</strong> and <strong>fathers → parents</strong>.</p>
<p><img src="coproduct_morphisms.svg" alt="Coproduct, external diagram"></p>
<h1 id="duality">Duality</h1>
<p>If we have to compare the sum or the product, we can say that:</p>
<p>The <em>product</em> of two sets is related to an element of the first one <em>and</em> one element of the second one.<br> A <em>sum</em> of two sets is related to an element of the first one <em>or</em> one element of the second one.</p>