From 5fbf53e882985adbca0bb5a82e6670c30795f044 Mon Sep 17 00:00:00 2001 From: Boris Marinov Date: Sat, 25 Dec 2021 18:31:58 +0200 Subject: [PATCH] stuff --- _chapters/00_about.md | 90 +++-- _chapters/01_set.md | 4 +- _chapters/02_category.md | 26 +- _chapters/03_monoid.md | 58 ++-- _chapters/04_order.md | 224 +++++++----- _chapters/04_order/binary_relation.svg | 99 ++++++ .../04_order/binary_relation_product.svg | 186 ++++++++++ .../04_order/functor_programming_objects.svg | 309 +++++++++++++++++ _chapters/04_order/linear_order.svg | 246 +++++++------ _chapters/04_order/preorder_equivalence.svg | 98 ++---- _chapters/04_order/preorder_partial_order.svg | 305 +++++++++++++++++ _chapters/05_logic.md | 134 ++++---- _chapters/06_functors.md | 238 ++++++++----- _chapters/06_functors/constant_functor.svg | 323 ++++++++++++++++++ .../06_functors/endofunctor_programming.svg | 174 ++++++++-- .../functor_programming_morphisms.svg | 312 +++++++++++++++++ .../functor_programming_objects.svg | 215 ++++++++++++ _chapters/07_natural_transformations.md | 25 +- _chapters/08_adjunctions.md | 51 +++ _layouts/default.html | 10 +- dictionary.txt | 16 + 21 files changed, 2603 insertions(+), 540 deletions(-) create mode 100644 _chapters/04_order/binary_relation.svg create mode 100644 _chapters/04_order/binary_relation_product.svg create mode 100644 _chapters/04_order/functor_programming_objects.svg create mode 100644 _chapters/04_order/preorder_partial_order.svg create mode 100644 _chapters/06_functors/constant_functor.svg create mode 100644 _chapters/06_functors/functor_programming_morphisms.svg create mode 100644 _chapters/06_functors/functor_programming_objects.svg create mode 100644 _chapters/08_adjunctions.md diff --git a/_chapters/00_about.md b/_chapters/00_about.md index 8cc4bc8..e9bdeca 100644 --- a/_chapters/00_about.md +++ b/_chapters/00_about.md @@ -14,25 +14,83 @@ title: About {: style="text-align: right" } Tom Lehrer + + +The story behind this book +=== + +I was interested at math as a kid, but I was always messing up the calculations so I decided it was not my thing and and started pursuing other interests (among which writing and visual art.) + +A little later I got into programming and I found that this was similar to the part of mathematics that I enjoyed. I started using functional programming in an effort to explore the similarity and to improve myself as a developer. I discovered category theory a little later. + +Some 5 years ago I found myself jobless for a few months and decided to publish some of the diagrams that I drew as part of my the notes I kept when was reading "Category theory for scientists" by David Spivak. The effort resulted in a rough version of the first two chaptes of this book, which I published online. + +A few years after that some people found my notes and encouraged me write more. They were so nice that I forgot my imposter syndrome and got to work on the next several chapters. + +Who is this book for AKA The value of category theory +=== + +Ever since Newton's Principia, the discipline of mathematics was viewed in the somewhat demeaning position of "science and engineering's workhorse". According to this view, mathematics is only "useful" as a means for making it easier for scientists and engineers for making technological and and scientific advancements i.e. it is viewed as just a tool for solving "practical" problems. Which puts mathematicians in a weird and I'd say unique position of always having to defend what they do with respect to it's value for *other disciplines*. I again stress that this is something that would be considered absurd when it comes to any other discipline. Imagine for example, what would it look like if people were bashing *philosophical theories* for being too impractical in the way they are bashing mathematics, like, for example someone attacking Wittgenstein's picture theory of language by, saying: + +"All too well, but what can you do with that theory?" + +And at the other end of the line, some philosopher sweating: + +"Well, I am told it does have its applications is programming language theory..." + +Or someone bashing David Hume's extreme scepticism: + +"That's all fine and dandy, but your theory leaves us at square one in terms of our knowledge. What the hell are we expected to do from there?" + +So, who is this book for? If we rephrase this question as "Who *should* read this book", then the answer is nobody. Indeed, if you think in terms of "should" mathematics (or at least the type of mathematics that is reviewed here) won't help you much, although it is falsely advertised as solution to many problems. + +Let's take an example - many people claim that, Einstein's theories of relativity are essential for GPS to work properly because due to relativistic effects the clocks on GPS satellites should tick faster than identical clocks on the ground. + +They seem to think that if the theory didn't exist the engineers that developed the GPS would have faced this phenomena in the following way: + +> Engineer 1: Whoa, the clocks on the satellites are off by X nanoseconds! +> +> Engineer 2: But that's impossible! Our mathematical model predicts that they should be correct. +> +> Engineer 1: OK, so what do we do now? +> +> Engineer 2: I guess we need to drop this project until we have a viable mathematical model that describes time in the universe. + +Although I am not an expert in special relativity, I suspect that the way this conversation would have developed would be closer to the following: + +> Engineer 1: Whoa, the clocks on the satellites are off by X nanoseconds! +> +> Engineer 2: This is normal, there are many unknowns. +> +> Engineer 1: OK, so what do we do now? +> +> Engineer 2: Just adjust it by X and see if it works. Oh, and tell that to some physicist, they might find it interesting. + +With that I am not claiming that math is so insignificant, that it is not even good enough to serve as a tool for building stuff. Quite the contrary, I think that math is much more than just a simple tool. Thinking itself is mathematical. So going through any math texbook (and of course especially this one) would help you in ways that are much more vital than finding solutions to "complex" problems. + +And so "Who is this book for" is not to be read as who should, but who *can* read it. Then the answer is "anyone with some time and dedication to learn category theory". + About this book === -The discipline of mathematics has always suffered from the fact that it is viewed as "science's workhorse". According to this view, mathematics is only "useful" as a means for making it easier for scientists and engineers to do their job making technological and and scientific advancements i.e. it is viewed as a tool for solving problems. +Although many people don't subscribe to this view of mathematics specifically, we can see it encoded inside the structure of most mathematics textbooks - each chapter starts with an explanation of a concept, followed by some examples and then ends with a list of problems that this concept solves. -And although many people don't subsribe to this view specifically, we can see it encoded inside the structure of most mathematics text books - each chapter starts with an explanation of a concept, followed by some examples and then ends with a list of problems that this concept solves. +There is nothing wrong with this approach, but mathematics is so much more than solving problems. It was a the basis of a religious cult in ancient Greece (the Pythagoreans), it was seen by philosophers as means to understanding the laws which govern the universe. It was (and still is) a language, which can allow for people with different cultural backgrounds understand each other. And it is also art and a means of entertainment. -There is nothing wrong with this approach, but mathematics is so much more than solving problems. It was a the basis of a religious cult in ancient Grece (the Pythagoreans), it was seen by philosophers as means to understanding the laws which govern the universe. It was (and still is) a language, which can allow for people with different cultural backgrounds understand each other. And it was also art and a means of entertainment. - -Category theory embodies all these aspects of mathematics. It's visual language is, I think a very good grounds to writing a book where all of them shine - a book that is based not on solving of problems, but on exploration of concepts and on seeking connections between them. +Category theory embodies all these aspects of mathematics, so I think a very good grounds to writing a book where all of them shine - a book that is based not on solving of problems, but on exploration of concepts and on seeking connections between them. A book, that is, overall, pretty. About category theory === -The main reason I am interested in category theory is that it allows us to formalise some common concepts that we use in our daily (intellectual) lives. Much of our language is based on intuition as intuition is a very easy way to get your point across. However, that is part of the problem: sometimes intuition makes it *too easy* to communicate with someone, so easy that he might, in fact, understand things that you haven't actually said. For example, when I say that two things are equal, it would seem obvious to you what I mean, although it isn't obvious at all (how are they equal, at what context etc). +Like we said, the fundaments of mathematics are the fundaments of thought. Category theory allows us to formalize those fundaments that we use in our daily (intellectual) lives. -In such occasions we strive to use a more rigorous definition of what we are saying. This is a way to make it clearer and more understandable not only for our audience, but for ourselves. But providing such definition in natural language, which is designed to use intuition as a means of communication, is no easy task. +The way we think and talk is based on intuition that develops naturally and is very easy way to get our point across. However, that is part of the problem: sometimes intuition makes it *too easy* for us, to say something that can be interpreted in many ways, some of which are wrong. For example, when I say that two things are equal, it would seem obvious to you what I mean, although it isn't obvious at all (how are they equal, at what context etc). -It is in these situations that people often resort to diagrams to explain their thoughts. Diagrams are ubiquitous in science and mathematics because they are an understandable way to communicate a formal concept clearly. Category theory formalises the concept of a diagram and their components - arrows and objects and creates a language for presenting all kinds of ideas. In this sense, category theory is a way to unify knowledge, both mathematical and scientific, and to bring various modes of thinking in common therms. +It is in these situations that people often resort to *diagrams* to refine their thoughts. Diagrams (even more than formulas) are ubiquitous in science and mathematics their + +Category theory formalizes the concept of a diagram and their components - arrows and objects and creates a language for presenting all kinds of ideas. In this sense, category theory is a way to unify knowledge, both mathematical and scientific, and to bring various modes of thinking in common terms. + +As a consequence of that, category theory and diagrams are also a very understandable way to communicate a formal concept clearly. Something I hope to demonstrate in the following pages. Summary === @@ -51,22 +109,14 @@ The connecting between all these different disciplines is examined in chapter 6, In chapter 7 we review another more interesting and more advanced categorical concept the concept of a *natural transformation*. - - -Acknowledgements +Acknowledgments === Thanks to my wife Dimitrina, who is taking after our daughter while I sit here and write my book. -Thanks to my high-school arts teacher, Mrs Georgieva who told me that I have some tallent, but I have to work. +My daughter Daria, my "anti-author" who stayed seated on my knees when I was writing the second and third chapters and mercilessly deleted many sentences, most of them bad. + +Thanks to my high-school arts teacher, Mrs Georgieva who told me that I have some talent, but I have to work. Thanks to Prathyush Pramod who encouraged me to finish the book and is also helping me out with it. diff --git a/_chapters/01_set.md b/_chapters/01_set.md index 83e0258..6b5a023 100644 --- a/_chapters/01_set.md +++ b/_chapters/01_set.md @@ -366,7 +366,7 @@ If we have a one-one-function that connects sets that are of the same size (as i ![Opposite colors](isomorphism_one_one.svg) -Invertible functions are called *isomorphisms*. When there exists an invertible function between two sets we say that the sets are *isomorphic*. For example, because we have an invertible function that converts the temperature measured in *Celsius* to temperature measured in *Fahrenheit* and vise versa, we can say that the temperatures measured in Celsius and Fahrenheit are isomorphic. +Invertible functions are called *isomorphisms*. When there exists an invertible function between two sets we say that the sets are *isomorphic*. For example, because we have an invertable function that converts the temperature measured in *Celsius* to temperature measured in *Fahrenheit* and vise versa, we can say that the temperatures measured in Celsius and Fahrenheit are isomorphic. Isomorphism means "same form" in Greek (although actually their form is the only thing which is different between two isomorphic sets.) @@ -498,7 +498,7 @@ To understand how, let's think about how do you teach a person what a number is ![Two balls](number_two.svg) -When you do that, it would be important to highlight that you are not referring to only the left object, or only about the right one, but that we should consider both things as at once (i.e. both things as one), so if the person whom you are explaining happens to know what a set is, this piece of knowledge might come in handy. And also, being good teachers we might provide them with some more examples of sets of 2 things. +When you do that, it would be important to highlight that you are not refering to only the left object, or only about the right one, but that we should consider both things as at once (i.e. both things as one), so if the person whom you are explaining happens to know what a set is, this piece of knowledge might come in handy. And also, being good teachers we might provide them with some more examples of sets of 2 things. ![A set of two balls](number_two_sets.svg) diff --git a/_chapters/02_category.md b/_chapters/02_category.md index 6775ffe..e1f52fa 100644 --- a/_chapters/02_category.md +++ b/_chapters/02_category.md @@ -127,13 +127,13 @@ In category theory, this type of property that a given object might possess (par Sums === -We will now study a construct that is pretty similar to the product but at the same time 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. But different as it encodes a quite different type of relation - a product encodes an **AND** relation between two sets, while the sum encodes an **OR** relation. +We will now study a construct that is pretty similar to the product but at the same time 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. But different as it encodes a quite different type of relation - a product encodes an *and* relation between two sets, while the sum encodes an *or* relation. A sum of two sets $B$ and $Y$, denoted $B + Y$ is a set that contains *all elements from the first set combined with all elements from the second one*. ![Sum or coproduct](coproduct.svg) -We can immediately see the connection with the **OR** logical structure: For example, because a parent is either a mother or a father of a child, the set of all parents is the sum of the set of mothers and the set of fathers, or $P = M + F$. +We can immediately see the connection with the *or* logical structure: For example, because a parent is either a mother or a father of a child, the set of all parents is the sum of the set of mothers and the set of fathers, or $P = M + F$. Defining Sums in Terms of Sets @@ -152,9 +152,9 @@ But again, this distinction is only relevant only when the two sets have common Defining sums in terms of functions --- -As 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. We said that sums express an **OR** relation between two things. +As 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. We said that sums express an *or* relation between two things. -A property of every **OR** relation is that if something is an $A$ that something is also an $A \vee B$ , and same for $B$ (The $\vee$ symbol means **OR**, by the way). For example, if my hair is *brown*, then my hair is also *either blond or brown*. This is what **OR** means, right? This property can be expressed as a function, two functions actually - one for each set that takes part in the sum relation (for example, if parents are either mothers or fathers, then there surely exist functions $mothers → parents$ and $fathers → parents$.) +A property of every *or* relation is that if something is an $A$ that something is also an $A \vee B$ , and same for $B$ (The $\vee$ symbol means *or* by the way). For example, if my hair is *brown*, then my hair is also *either blond or brown*. This is what *or* means, right? This property can be expressed as a function, two functions actually - one for each set that takes part in the sum relation (for example, if parents are either mothers or fathers, then there surely exist functions $mothers → parents$ and $fathers → parents$.) ![Coproduct, external diagram](coproduct_external.svg) @@ -191,16 +191,16 @@ Interlude - De Morgan duality Now let's look at how the concepts of product and sum from the viewpoint of *logic*. We mentioned that: -- The *product* of two sets contains an element of the first one **AND** one element of the second one. -- A *sum* of two sets contains an element of the first one **OR** one element of the second one. +- The *product* of two sets contains an element of the first one *and* one element of the second one. +- A *sum* of two sets contains an element of the first one *or* one element of the second one. -When we view those sets as propositions, we discover the concept of the *product* ($\times$) corresponds exactly to the **AND** relation in logic (denoted $\land$.) From this viewpoint, the function $Y \times B \to Y$ can be viewed as instance of a logical rule of inference called *conjunction elimination* (also called *simplification*) stating that, $Y \land B \to Y$, for example, if your hair is partly blond and partly brown, then it is partly blond. +When we view those sets as propositions, we discover the concept of the *product* ($\times$) corresponds exactly to the *and* relation in logic (denoted $\land$.) From this viewpoint, the function $Y \times B \to Y$ can be viewed as instance of a logical rule of inference called *conjunction elimination* (also called *simplification*) stating that, $Y \land B \to Y$, for example, if your hair is partly blond and partly brown, then it is partly blond. -By the same token, the concept of a *sum* ($+$) corresponds the **OR** relation in logic (denoted $\lor$.) From this viewpoint, the function $Y \to Y + B$ can be viewed as instance of a logical rule of inference called *disjunction introduction*, stating that, $Y \to Y \lor B$ for example, if your hair is blond, it is either blond or brown. +By the same token, the concept of a *sum* ($+$) corresponds the *or* relation in logic (denoted $\lor$.) From this viewpoint, the function $Y \to Y + B$ can be viewed as instance of a logical rule of inference called *disjunction introduction*, stating that, $Y \to Y \lor B$ for example, if your hair is blond, it is either blond or brown. -This means, among other things, that the concepts of **AND** and **OR** are also dual - an idea which was put forward in the 19th century by the mathematician Augustus De Morgan and is henceforth known as *De Morgan duality*, and which is a predecessor to the modern idea of duality in category theory, that we examined before. +This means, among other things, that the concepts of *and* and *or* are also dual - an idea which was put forward in the 19th century by the mathematician Augustus De Morgan and is henceforth known as *De Morgan duality*, and which is a predecessor to the modern idea of duality in category theory, that we examined before. -This duality is subtly encoded in the logical symbols for **AND** and **OR** ($\land$ and $\lor$) - they are nothing but stylized-versions of the diagrams of products and coproducts. +This duality is subtly encoded in the logical symbols for *and* and *or* ($\land$ and $\lor$) - they are nothing but stylized-versions of the diagrams of products and coproducts. ![Coproduct and product](demorgan_duality.svg) @@ -212,7 +212,7 @@ $\neg(A \vee B) = \neg{A} \wedge \neg{B}$ You can read the second formula as, for example, if my hair is not blond *or* brown, this means that my hair is not blond *and* my hair is not brown, and vice versa (the connection work both ways) -Now we will go through the formulas and we would try to show that they are actually a simple corollary of the duality between **AND** and **OR**. +Now we will go through the formulas and we would try to show that they are actually a simple corollary of the duality between *and* and *or* Let's say we want to find the statement that is opposite of "blond *or* brown". @@ -224,7 +224,7 @@ $\neg{A} \vee \neg{B}$ However, this statement is clearly not the opposite of "blond *or* brown"(saying that my hair is not blond *or* not brown does in fact allow it to be blond and also allows for it to be brown, it just doesn't allow it to be both of these things.) -So what have we missed? Simple - although we replaced the propositions that constitute our proposition with their opposites, we didn't replace the operator that connects them - it is still **OR** for both propositions. So we must replace it with **OR**'s converse. As we said earlier, and as you can see by analyzing this example, this operator is **AND**. So the formula becomes "not blond *and* not brown". +So what have we missed? Simple - although we replaced the propositions that constitute our proposition with their opposites, we didn't replace the operator that connects them - it is still *or* for both propositions. So we must replace it with *or* converse. As we said earlier, and as you can see by analyzing this example, this operator is *and* So the formula becomes "not blond *and* not brown". $\neg{A} \wedge \neg{B}$ @@ -361,7 +361,7 @@ It's important to mark this morphism, because there can be (let's add the very i Isomorphism --- -Why do we need to define a morphism that does nothing? It's because morphisms are the basic building blocks of our language, and we need this one to be able to speak properly. For example, once we have the concept of identity morphism defined, we can have a category-theoretic definition of an *isomorphism* (which is important, because the concept of an isomorphism is very important for category theory). Like we said in the previous chapter, an isomorphism between two objects ($A$ and $B$) consists of two morphisms - ($A → B$. and $B → A$) such that their compositions are equivalent to the identity functions of the respective objects. Formally, objects $A$ and $B$ are isomorphic if there exist morphisms $f: A → B$ and $g: B → A$ such that $f \bullet g = id B$ and $g \bullet f = id A$. +Why do we need to define a morphism that does nothing? It's because morphisms are the basic building blocks of our language, and we need this one to be able to speak properly. For example, once we have the concept of identity morphism defined, we can have a category-theoretic definition of an *isomorphism* (which is important, because the concept of an isomorphism is very important for category theory). Like we said in the previous chapter, an isomorphism between two objects ($A$ and $B$) consists of two morphisms - ($A → B$. and $B → A$) such that their compositions are equivalent to the identity functions of the respective objects. Formally, objects $A$ and $B$ are isomorphic if there exist morphisms $f: A → B$ and $g: B → A$ such that $f \bullet g = id_{B}$ and $g \bullet f = id_{A}$. And here is the same thing expressed with a commuting diagram. diff --git a/_chapters/03_monoid.md b/_chapters/03_monoid.md index 30165cf..c83583c 100644 --- a/_chapters/03_monoid.md +++ b/_chapters/03_monoid.md @@ -11,15 +11,15 @@ Since we are done with categories, let's look at some other structures that are What are monoids === -Monoids are simpler than categories. A monoid is defined by a collection/set of elements, together with an *monoid operation* - a rule for combining two elements that and produces a third element one of the same kind. +Monoids are simpler than categories. A monoid is defined by a collection/set of elements (called the monoid's *underlying set*, together with an *monoid operation* - a rule for combining two elements that produces a third element one of the same kind. Let's take our familiar colorful balls. ![Balls](balls.svg) -We can define a monoid based on this set by defining a operation for "combining" two balls into one. An example of such operation would be blending the colors of the balls, as if we are mixing paint. +We can define a monoid based on this set by defining an operation for "combining" two balls into one. An example of such operation would be blending the colors of the balls, as if we are mixing paint. -![A operation for combining balls](balls_operation.svg) +![An operation for combining balls](balls_operation.svg) You can probably think of other ways to define such an operation. This will help you realize that there can be many ways to create a monoid from a given set of set elements i.e. the monoid is not the set itself, it is the set *together with the operation*. @@ -30,7 +30,7 @@ The monoid operation should, like functional composition, be *associative* i.e. ![Associativity in the color mixing operation](balls_associativity.svg) -When a operation is associative, this means we can use all kinds of algebraic operations to any sequence of terms (or in other words to apply equation reasoning), like for example we can replace any element with a set of elements from which it is composed of, or add a term that is present at both sides of an equation and retaining the equality of the existing terms. +When an operation is associative, this means we can use all kinds of algebraic operations to any sequence of terms (or in other words to apply equation reasoning), like for example we can replace any element with a set of elements from which it is composed of, or add a term that is present at both sides of an equation and retaining the equality of the existing terms. ![Associativity in the color mixing operation](balls_arithmetic.svg) @@ -70,11 +70,11 @@ Anyways, the natural numbers also form a monoid under multiplication as well. Monoids from boolean algebra --- -Thinking about operations that we covered, we may remember the boolean operations *AND* and *OR*. Both of them form monoids, which operate on the set, consisting of just two values $\{ True, False \}$. +Thinking about operations that we covered, we may remember the boolean operations *and* and *or*. Both of them form monoids, which operate on the set, consisting of just two values $\{ True, False \}$. -**Task:** Prove that $\land$ is associative by expanding the formula $(A \land B) \land C = A \land (B \land C)$ with all all possible values. Do the same for *OR*. +**Task:** Prove that $\land$ is associative by expanding the formula $(A \land B) \land C = A \land (B \land C)$ with all possible values. Do the same for *or*. -**Question:** Which are the identity elements of the *AND* and *OR* operations? +**Question:** Which are the identity elements of the *and* and *or* operations? Monoid operations in terms of set theory === @@ -116,7 +116,7 @@ All monoids that we examined so far are also *commutative*. We will see some non Groups --- -A group is a monoid such that for each of it's elements, there is another element which is the so called "inverse" of the first one where the element and its inverse cancel each other out when applied one after the other. Plain-english definitions like this make you appreciate mathematical formulas more - formally we say that for all elements $x$, there must exist $x'$ such that $x • x' = i$ ( where $i$ is the identity element). +A group is a monoid such that for each of it's elements, there is another element which is the so called "inverse" of the first one where the element and its inverse cancel each other out when applied one after the other. Plain-English definitions like this make you appreciate mathematical formulas more - formally we say that for all elements $x$, there must exist $x'$ such that $x • x' = i$ ( where $i$ is the identity element). If we view *monoids* as a means of modeling the effect of applying a set of (associative) actions, we use *groups* to model the effects of actions are also *reversible*. @@ -264,7 +264,7 @@ Product groups are still abelian, provided that the groups that form them are ab Fundamental theorem of Finite Abelian groups --- -Products provide one way to to create non-cyclic abelian groups - by creating a product of two or more cyclic groups. The fundamental theory of finite abelian groups is a result that tells us that *this is the only way* to produce non-cyclic abelian groups i.e. +Products provide one way to create non-cyclic abelian groups - by creating a product of two or more cyclic groups. The fundamental theory of finite abelian groups is a result that tells us that *this is the only way* to produce non-cyclic abelian groups i.e. > All abelian groups are either cyclic or products of cyclic groups. @@ -325,9 +325,9 @@ We began by defining a monoid as a set of composable *elements*. Then we saw tha Currying --- -When we defined monoids, we saw that their operations are two-argument functions. And we introduced a way for representing such functions using set theory - by uniting the two arguments into one using products. i.e. we showed that a function that accepts two arguments (say $A$ and $B$) and maps them into some result ($C$), can be thought as a mapping from the product of the sets of two arguments to the resutlt. So $A\times B\to C$. +When we defined monoids, we saw that their operations are two-argument functions. And we introduced a way for representing such functions using set theory - by uniting the two arguments into one using products. i.e. we showed that a function that accepts two arguments (say $A$ and $B$) and maps them into some result ($C$), can be thought as a mapping from the product of the sets of two arguments to the result. So $A\times B\to C$. -However, this is not the only way to represent multi-argument function set-theoretically - there is another, equally interesting way, that doesn't rely on any datastructures, but only on functions: that way is to have a function that maps the first of the two arguments (i.e. from $A$) to *another function* that maps the second argument to the final result (i.e. $B \to C$.) So $A\to B \to C$. +However, this is not the only way to represent multi-argument function set-theoretically - there is another, equally interesting way, that doesn't rely on any data structures, but only on functions: that way is to have a function that maps the first of the two arguments (i.e. from $A$) to *another function* that maps the second argument to the final result (i.e. $B \to C$.) So $A\to B \to C$. The practice of transforming a function that takes a pair of objects to a function that takes just one object and returns a function that takes another one is called *currying*. It is achieved by a higher-order function. Here is how such a function might be implemented. @@ -340,7 +340,7 @@ And equally important is the opposite function, which maps a curried function to const uncurry = (f:(a:A) => (b:B) => C) => (a:A, b:B ) => f(a)(b) ``` -There is a lot to say about these two functions, starting from the fact that its existence gives rise to an interesting relationship between the concept of a *product* and the concept of a *morphism* in category theory, called the *adjunction*. But we will cover this later. For now we are interested in the fact the the two function representations are isomorphic, formally $A\times B\to C\cong A\to B \to C$. +There is a lot to say about these two functions, starting from the fact that its existence gives rise to an interesting relationship between the concept of a *product* and the concept of a *morphism* in category theory, called the *adjunction*. But we will cover this later. For now we are interested in the fact the two function representations are isomorphic, formally $A\times B\to C\cong A\to B \to C$. By the way, this isomorphism can be represented in terms of programming as well. It is equivalent to the statement that the following function always returns `true` for any arguments, @@ -354,7 +354,7 @@ This is one part of the isomorphism, the other part is the equivalent function f Monoid elements as functions/permutations --- -Let's take a step back and examine the groups/monoids that we covered so far in the light of what we learned. We started off by representing group operation as a function from pairs. For example, the operation of a symmetric group,(let's take $Z_3$ as an example) are actions that converts two rotations to another another rotation. +Let's take a step back and examine the groups/monoids that we covered so far in the light of what we learned. We started off by representing group operation as a function from pairs. For example, the operation of a symmetric group,(let's take $Z_3$ as an example) are actions that converts two rotations to another rotation. ![The group of rotations in a triangle - group notation](symmetry_rotation_actions.svg) @@ -402,7 +402,7 @@ So, basically the functions that represent the elements of a monoid also form a Cayley's theorem --- -We saw how using currying we can represent the elements of any group as permutions that, also form a monoid. Cayley's theorem tells us that those two groups are isomorphic: +We saw how using currying we can represent the elements of any group as permutations that, also form a monoid. Cayley's theorem tells us that those two groups are isomorphic: > Any group is isomorphic to a permutation group. @@ -412,24 +412,24 @@ Formally, if we use $Perm$ to denote the permutation group then $Perm(A) \cong A Or in other words, representing the elements of a group as permutations actually yields a representation of the monoid itself (sometimes called it's standard representation.) -Cayley's theorem may not seem very impressibe, but that only shows how influental it has been as a result. +Cayley's theorem may not seem very impressive, but that only shows how influential it has been as a result. {% if site.distribution == 'print' %} Interlude: Symmetric groups --- -The most important thing that you have to know about the symmetric groups is that they are *not the same thing as symmetry groups*. Once we have that out of the way, we can understand what they actually are: given a natural number $n$, the symmetric group of $n$, denoted $\mathrm{S}_n$ (symmetric group of degree $n$) is the group of all possible permutations of a set with $n$ elements. The number of the elements of such groups is equal to are $1\times2\times3...\times n$ or $n!$ (n-factorial.) +The most important thing that you have to know about the symmetric groups is that they are *not the same thing as symmetry groups*. Once we have that out of the way, we can understand what they actually are: given a natural number $n$, the symmetric group of $n$, denoted $\mathrm{S}_n$ (symmetric group of degree $n$) is the group of all possible permutations of a set with $n$ elements. The number of the elements of such groups is equal to are $1\times 2\times 3...\times n$ or $n!$ (n-factorial.) So, for example the group $\mathrm{S}_1$ of permutations of the one-element set has just 1 element (because a 1-element set has no other functions to itself other than the identity function. ![The S1 symmetric group](s1.svg) -The group $\mathrm{S}_2$, has $1\times2=2$ elements (by the way, the colors are there to give you some intuition as to why the number of permutations of a $n$-element set is $n!$.) +The group $\mathrm{S}_2$, has $1 \times 2 = 2$ elements (by the way, the colors are there to give you some intuition as to why the number of permutations of a $n$-element set is $n!$.) ![The S2 symmetric group](s2.svg) -And with $\mathrm{S}_3$ we are already feeling the power of exponential (and even faster than exponential!) growth of the factorial function - it has $1\times2\times3=6$ elements. +And with $\mathrm{S}_3$ we are already feeling the power of exponential (and even faster than exponential!) growth of the factorial function - it has $1\times 2\times 3=6$ elements. ![The S3 symmetric group](s3.svg) @@ -463,7 +463,7 @@ But wait, if the monoids' underlying *sets* correspond to *objects* in category ![The group of rotations in a triangle - categorical notation](symmetry_rotation_category.svg) -The only difference between differend kind of monoids would be the number of morphisms that they have and the relationship between them. +The only difference between different monoids would be the number of morphisms that they have and the relationship between them. The intuition behind this representation from a category-theoretic standpoint is encompassed by the law of $closure$ that monoid and group operations have and that categories lack - it is the law stating that applying the operation (functional composition) on any two objects always yields the same object, e.g. no matter how do you flip a triangle, you'd still get a triangle. @@ -490,8 +490,6 @@ Categories provide a way to compose two morphisms with an appropriate type signa Philosophically, defining a monoid as a one-object category means corresponds to the view of monoids as a model of how a set of (associative) actions that are performed on a given object alter it's state. Provided that the object's state is determined solely by the actions that are performed on it, we can leave it out of the equation and concentrate on how the actions are combined. And as per usual, the actions (and elements) can be anything, from mixing colors in paint, or adding a quantities to a given set of things etc. -{% if site.distribution == 'print' %} - Group/monoid presentations --- @@ -505,7 +503,7 @@ This is so, because applying the generator again and again yields all elements o Finite cyclic groups/monoids are the same, except that their definition contains an additional law, stating that that once you compose the generator with itself $n$ number of times, you get identity morphism. For the cyclic group $Z_3$ (which can be visualized as the group of triangle rotations) this law states that composing the generator with itself $3$ times yields the identity morphism. -![Presentation of an finite cyclic monoid](finite_cyclic_presentation.svg) +![Presentation of a finite cyclic monoid](finite_cyclic_presentation.svg) Composing the group generator with itself, and then applying the law, yields the three morphisms of $Z_3$. @@ -521,7 +519,7 @@ To make the representation complete, we add the law for combining the two genera And then, if we start applying the two generators and follow the laws, we get the four elements. -![The elements of of Klein four](klein_four_presentation_elements.svg) +![The elements of Klein four](klein_four_presentation_elements.svg) The set of generators and laws that defines a given group is called the *presentation of a group*. Every group has a presentation. @@ -534,16 +532,22 @@ If you revisit the previous section you will notice that we already saw one such ![The free monoid with one generator](infinite_cyclic_presentation_elements.svg) -We can make a free monoid from the set of colorful balls - the monoid's elements would be all possible combinations of the balls. +We can make a free monoid from the set of colorful balls - the monoid's elements would be sequences of all possible combinations of the balls. ![The free monoid with the set of balls as a generators](balls_free.svg) -The free monoid is a special one - each element of the free monoid over a given set, can be converted to a corresponding element in any other other monoid that uses the same set by just applying the monoid's laws. For example, here is how the elements above would look like if we apply the laws of the color-mixing monoid. +The free monoid is a special one - each element of the free monoid over a given set, can be converted to a corresponding element in any any other monoid that uses the same set of generators by just applying the monoid's laws. For example, here is how the elements above would look like if we apply the laws of the color-mixing monoid. ![Converting the elements of the free monoid to the elements of the color-mixing monoid](balls_free_color_mixing.svg) **Task:** Write up the laws of the color-mixing monoid. -If we put out programmers' hat, we will see that the type of the free monoid under the set T (which we can denote as `FreeMonoid`) is isomorphic to the type `List` (or `Array`, if you prefer) and that the intuition behind the special property that we described above is actually very simple: keeping objects in a list allows you to convert them to any other structure i.e. when we want to perform some manipulation on a bunch of objects, but we don't know exactly what this manipulation is, we just keep a list of those objects until it's time to do it. +If we put out programmers' hat, we will see that the type of the free monoid under the set of generators T (which we can denote as `FreeMonoid`) is isomorphic to the type `List` (or `Array`, if you prefer) and that the intuition behind the special property that we described above is actually very simple: keeping objects in a list allows you to convert them to any other structure i.e. when we want to perform some manipulation on a bunch of objects, but we don't know exactly what this manipulation is, we just keep a list of those objects until it's time to do it. -{% endif %} +While the intuition behind free monoids seems simple enough, the formal definition is not our cup of tea... yet, simply because we have to cover more stuff. + +We understand that, being the most general of all monoids for a given set of generators, a free monoid can be converted to all of them. i.e. there exist a function from it to all of them. But what kind of function would that be? + +Plus, what about other monoids that also can have this property (that they are connected to any other monoids) Simple - they are the free monoid with some extra structure, so we can filter them out by using an universal property. + +But, what would this property be, (and what the hell are universal properties anyways?), tune in after a few chapters to find out. diff --git a/_chapters/04_order.md b/_chapters/04_order.md index b87ca3c..3b85637 100644 --- a/_chapters/04_order.md +++ b/_chapters/04_order.md @@ -6,22 +6,34 @@ title: Orders Orders === -Now let's talk about order. Given a set of objects, there can be numerous criteria, based on which to order them, and which depend on the objects themselves - size, weight, age, alphabetical order etc. +Given a set of objects, there can be numerous criteria, based on which to order them (depending on the objects themselves) - size, weight, age, alphabetical order etc. + +However, currently we are not interested in the *criteria* that we can use to order objects, but in the *nature of the relationships* that define order. Of which there can be several types as well. + +Mathematically, the order as a construct is represented (much like a monoid) by two two components. + +One is a *set of things* (e.g. colorful balls) which we sometimes call the order's *underlying set*. ![Balls](balls.svg) -However, as mathematicians we are not interested in the *criteria* that we can use to order objects, but in the *nature of the relationship* that defines the order. Of which there can be several types as well. +And the other is a *binary relation* between these things, which are often represented as arrows. -Mathematically we can represent order as a *set of things* (e.g. colorful balls) and *a binary relation* between these things (which we often represent as a bunch of arrows). Not all binary relationships are orders - only ones that fit certain criteria that we are going to examine as we review the different types of order. +![Binary relation](binary_relation.svg) + +Not all binary relationships are orders - only ones that fit certain criteria that we are going to examine as we review the different types of order. Linear order === -The most straightforward type of order that you think about is linear order i.e. one in which every object has its place depending on every other object. In this case the ordering criteria is completely deterministic and leaves no room for ambiguity in terms of which element comes before which. For example, ordering the colors by the length of their waves (or by how they appear in the rainbow). +Let's start with an example - the most straightforward type of order that you think og is *linear order* i.e. one in which every object has its place depending on every other object. In this case the ordering criteria is completely deterministic and leaves no room for ambiguity in terms of which element comes before which. For example, order of colors, sorted by the length of their light-waves (or by how they appear in the rainbow). ![Linear order](linear_order.svg) -In most programming languages, we can order objects linearly by providing a function which, given two objects, tells us which one of them is "bigger" (comes first) and which one is "smaller". +Using set theory, we can represent this order, as well as any other order, as a cartesian products of the order's underlying set with itself. + +![Binary relation as a product](binary_relation_product.svg) + +And in programming, orders are defined by providing a function which, given two objects, tells us which one of them is "bigger" (comes first) and which one is "smaller". It isn't hard to see that this function is actually a definition of a cartesian product. ``` [1, 3, 2].sort((a, b) => { @@ -33,25 +45,25 @@ In most programming languages, we can order objects linearly by providing a func }) ``` -But in order for such a function to really define an order (e.g. give the same output every time, independent of how the objects were shuffled initially), it has to obey several rules. +However (this is where it gets interesting) not all such functions (and not all cartesian products) define orders. To really define an order (e.g. give the same output every time, independent of how the objects were shuffled initially), functions have to obey several rules. -Incidentally, (or rather not incidentally at all), these rules are nearly equivalent to the mathematical laws that define the criteria of the relationship between elements in an order i.e. those are the rules that define which element can point to which. Let's review them. +Incidentally, (or rather not incidentally at all), these rules are nearly equivalent to the mathematical laws that define the criteria of the order relationship i.e. those are the rules that define which element can point to which. Let's review them. Reflexivity --- -Let's get the most boring law out of the way - each object has to be bigger or equal to itself, or **a ≤ a** (the relationship between elements in an order is commonly denoted as **≤** in formulas, but it can also be represented with a simple arrow from first object to the second). +Let's get the most boring law out of the way - each object has to be bigger or equal to itself, or $a ≤ a$ for all $a$ (the relationship between elements in an order is commonly denoted as $≤$ in formulas, but it can also be represented with an arrow from first object to the second.) ![Reflexivity](reflexivity.svg) -No special reason for this law to be so, except that the "base case" should be covered somehow. +Thre is no special reason for this law to exist, except that the "base case" should be covered somehow. We can formulate it the opposite way too and say that each object should *not* have the relationship to itself, in which case we would have a relation than resembles *bigger than*, as opposed to *bigger or equal to* and a slightly different type of order, sometimes called a *strict* order. Transitivity --- -The second law is maybe the least obvious, (but probably the most essential) - it states that if object **a** is bigger than object **b**, it is automatically bigger than all objects that are smaller than object **b** or **a ≤ b and b ≤ c ➞ a ≤ c**. +The second law is maybe the least obvious, (but probably the most essential) - it states that if object $a$ is bigger than object $b$, it is automatically bigger than all objects that are smaller than $b$ or $a ≤ b \land b ≤ c \to a ≤ c$. ![Transitivity](transitivity.svg) @@ -60,7 +72,7 @@ This is the law that to a large extend defines what an order is: if I am better Antisymmetry --- -The third law is called antisymmetry and it states that the function that defines the order should not give contradictory results (or in other words you have **x ≤ y** and **y ≤ x** only if **x = y**). +The third law is called antisymmetry. It states that the function that defines the order should not give contradictory results (or in other words you have $x ≤ y$ and $y ≤ x$ only if $x = y$). ![antisymmetry](antisymmetry.svg) @@ -69,53 +81,57 @@ It also means that no ties are permitted - either I am better than my grandmothe Totality --- -The last law is called *totality* (or *connexity*) and it mandates that all elements that belong to the order should be comparable - **a ≤ b or b ≤ a**. That is, for any two elements, one would always be "bigger" than the other. +The last law is called *totality* (or *connexity*) and it mandates that all elements that belong to the order should be comparable - $a ≤ b \lor b ≤ a$. That is, for any two elements, one would always be "bigger" than the other. -By the way, this law makes the reflexivity law redundant, as reflexivity is just a special case of totality when **a** and **b** are one and the same object, but I still want to present it for reasons that will become apparent soon. +By the way, this law makes the reflexivity law redundant, as reflexivity is just a special case of totality when $a$ and $b$ are one and the same object, but I still want to present it for reasons that will become apparent soon. ![connexity](connexity.svg) -You might say that this law is not as self-evident as the rest of them - if you think about different types of real-life objects that we typically order, you would probably think of some situations in which it does not apply. For example, if we aim to order all people based on soccer skills there are many ways in which we can rank a person compared to their friends their friend's friends etc. but there isn't a way to order groups of people who never played with one another. +Actually, here are the reasons: this law does not look so "set in stone" as the rest of them i.e. we can probably think of some situations in which it does not apply. For example, if we aim to order all people based on soccer skills there are many ways in which we can rank a person compared to their friends their friend's friends etc. but there isn't a way to order groups of people who never played with one another. -Orders that resemble the order of people based on their soccer skills in that they don't follow the totality law are called **partial orders** and they are actually much more interesting than linear orders (which are also called **total orders**, by the way). +Orders, like the order people based on their soccer skills, that don't follow the totality law are called *partial orders*, (and linear orders are also called *total orders*.) + +**Question:** Previously, we covered a relation that is pretty similar to this. Do you remember it? What is the difference? **Task:** Think about some orders that you know about and figure out whether they are partial or total. -But before we dive into the world of partial orders, let's say a few things about the numbers. +Partial orders are actually much more interesting than linear/total orders. But before we dive into them, let's say a few things about numbers. The order of natural numbers --- -Natural numbers form a linear order under the operation **bigger or equal to** (the symbol of which we have been using in our formulas). +Natural numbers form a linear order under the operation *bigger or equal to* (the symbol of which we have been using in our formulas.) ![numbers](numbers.svg) -In many ways, numbers are the quintessential order - every finite order of objects is isomorphic to a subset of the order of numbers, as we can map the first element of any order to the number **1**, the second one to the number **2** etc (and we can do the opposite operation as well). +In many ways, numbers are the quintessential order - every finite order of objects is isomorphic to a subset of the order of numbers, as we can map the first element of any order to the number $1$, the second one to the number $2$ etc (and we can do the opposite operation as well). -If we think about it, this isomorphism is actually closer to the everyday notion of order, than the proper definition (the one defined by the laws) - when most people think of order, they aren't thinking of a *transitive, antisymmetric* and *total* relation, but are rather thinking about criteria based on which they can decide which object comes first, which comes second etc. +If we think about it, this isomorphism is actually closer to the everyday notion of a linear order, than the one defined by the laws - when most people think of order, they aren't thinking of a *transitive, antisymmetric* and *total* relation, but are rather thinking about criteria based on which they can decide which object comes first, which comes second etc. So it's important to notice that the two are equivalent. ![Linear order isomorphisms](linear_order_isomorphism.svg) -From the fact that any finite order of objects is isomorphic to the natural numbers it also follows that all linear orders of the same magnitude are isomorphic to one another. +From the fact that any finite order of objects is isomorphic to the natural numbers, it also follows that all linear orders of the same magnitude are isomorphic to one another. -**Question:** If all orders are isomorphic with one another, why do we say that numbers are the quintessential order? - -So the linear order is a perfect order, but it is also (and I think that these theorems prove it) the most *boring* order ever, especially when looked from a category-theoretic viewpoint - all finite linear orders are just isomorphic to the natural numbers (by the way, most infinite orders are isomorphic to the natural numbers as well, with the exception of the ones for which Cantor's diagonal argument applies) and so all of their diagrams look the same way. +So, the linear order is simple, but it is also (and I think that this isomorphism proves it) the most *boring* order ever, especially when looked from a category-theoretic viewpoint - all finite linear orders (and most infinite ones) are just isomorphic to the natural numbers and so all of their diagrams look the same way. ![Linear order (general)](general_linear_order.svg) However, this is not the case with partial orders that we will look into next. + + Partial order === -Like linear orders, a partial orders consists of a set plus a relation, with the only difference that, although it still obeys the *reflexive, transitive* and the *antisymmetric* laws, the relation does not obey the law of *totality*, that is not all of the sets elements are necessarily ordered. I say "necessarily" because even if all elements are ordered, the partial order is still a partial order (just as a group is still a monoid) - all linear orders are also partial orders, but not the other way around (we can even create an *order of orders*, based on which is more general). +Like a linear order, a partial order consists of a set plus a relation, with the only difference that, although it still obeys the *reflexive, transitive* and the *antisymmetric* laws, the relation does not obey the law of *totality*, that is, not all of the sets elements are necessarily ordered. I say "necessarily" because even if all elements are ordered, it is still a partial order (just as a group is still a monoid) - all linear orders are also partial orders, but not the other way around. We can even create an *order of orders*, based on which is more general. + +Partial orders are also related to the concept of an *equivalence relations* that we covered in chapter 1, except that *symmetry* law is replaced with *antisymmetry*. If we revisit the example of the soccer players rank list, we can see that the first version that includes just **m**yself, my **g**randmother and her **f**riend is a linear order. ![Linear soccer player order](player_order_linear.svg) -However, including this **o**ther person whom none of us played yet, makes the hierarchy non-linear. +However, including this **o**ther person whom none of us played yet, makes the hierarchy non-linear i.e. a partial order. ![Soccer player order - leftover element](player_order_leftover.svg) @@ -124,25 +140,24 @@ This is the main difference between partial and total orders - partial orders ca Chains --- -Before, we said that all linear orders can be represented by the same chain-like diagram, we can reverse this statement and say that all diagrams that look something different than the said diagram represent partial orders (or preorders). An example of this is a partial order that contains a bunch of linearly-ordered subsets, e.g. in our soccer example, we can have separate groups of friends who play together and are ranked with each other, but not with anyone from other groups. +Before, we said that all linear orders can be represented by the same chain-like diagram, we can reverse this statement and say that all diagrams that look something different than the said diagram represent partial orders. An example of this is a partial order that contains a bunch of linearly-ordered subsets, e.g. in our soccer example we can have separate groups of friends who play together and are ranked with each other, but not with anyone from other groups. ![Soccer order - two hierarchies](player_order_two.svg) -The different linear orders that make up the partial order are called *chains*. There are two chains in this diagram **M ➞ G ➞ F** and **D ➞ O**. +The different linear orders that make up the partial order are called *chains*. There are two chains in this diagram $m \to g \to f$ and $d \to o$. -The chains in an order don't have to be completely disconnected from each other in order for it to be partial, they can be connected as long as the connections are not all *one-to-one* i.e. when the last element from one chain should not be connected to the first element of the other one (as this would effectively unite them into one chain). But there are other types of connections, like *one-to-many* and *many-to-one*. +The chains in an order don't have to be completely disconnected from each other in order for it to be partial. They can be connected as long as the connections are not all *one-to-one* i.e. ones when the last element from one chain is connected to the first element of the other one (this would effectively unite them into one chain.) ![Soccer order - two hierarchies and a join](player_order_two_join.svg) -The above set is not linearly-ordered - although the connection establishes the relationship between **D** and **G** (**D ≤ G**) and although the relationship between **F** and **G** is known as well (**F ≤ G**), the relationship between **D** and **F** is *not* known. Any element can be bigger than the other one. +The above set is not linearly-ordered. This is because, although we know that $d ≤ g$ and that $f ≤ g$, the relationship between $d$ and $f$ is *not* known - any element can be bigger than the other one. - -Greatest and least +Greatest and least objects --- -Although partial orders don't give us definitive answer to who is better than who, some of them still can give us an answer to the more important question (in sports, as well as in other domains), namely *who is number one*, who is the champion, the player who is better than anyone else, or more generally the element that is bigger than any other element. +Although partial orders don't give us a definitive answer to "Who is better than who?", some of them still can give us an answer to the more important question (in sports, as well as in other domains), namely "Who is number one?" i.e. who is the champion, the player who is better than anyone else. Or, more generally, the element that is bigger than all other elements. -We call such elements the *greatest element* and some (not all) partial orders do have such element - in our last diagram **M** is the greatest element, in this diagram, the green element is the biggest one. +We call such element the *greatest element*. Some (not all) partial orders do have such element - in our last diagram $m$ is the greatest element, in this diagram, the green element is the biggest one. ![Join diagram with one more element](join_additional_element.svg) @@ -159,13 +174,13 @@ The *least upper bound* of two elements that are connected as part of an order i ![Join](join.svg) -There can be multiple elements bigger than **A** and **B** (all elements that are bigger than **C** are also bigger than **A** and **B**), but only one of them is a join. Formally, the join of **A** and **B** is defined as the smallest element **C** that is bigger than both **A** and **B** (i.e. for which **A ≤ C**, and **B ≤ C**. +There can be multiple elements bigger than $a$ and $b$ (all elements that are bigger than $c$ are also bigger than $a$ and $b$), but only one of them is a join. Formally, the join of $a$ and $b$ is defined as the smallest element that is bigger than both $a$ and $b$ (i.e. smallest $c$ for which $a ≤ c$, and $b ≤ c$.) ![Join with other elements](join_other_elements.svg) -Given any two elements in which one is bigger than the other (e.g. **A ≤ B**), the join is the bigger element (in this case **B**). +Given any two elements in which one is bigger than the other (e.g. $a ≤ b$), the join is the bigger element (in this case $b$). -In a totally ordered set, the *join* of any subset of elements is just their the *greatest* element. +In a linear orders, the *join* of any two elements is just the bigger element. Like with the greatest element, if two elements have several upper bounds that are equally big, then none of them is a *join* (a join must be unique). @@ -186,35 +201,35 @@ Given two elements, the biggest element that is smaller than both of them is cal The same rules as for the joins apply. -Interlude: Hasse diagrams +Hasse diagrams --- -In this section, we use what are called "Hasse diagrams" - they are much like our usual diagrams, however they have an additional rule that is followed - "bigger" elements are always positioned above smaller ones. +The diagrams that we use in this section are called "Hasse diagrams" and they work much like our usual diagrams, however they have an additional rule that is followed - "bigger" elements are always positioned above smaller ones. In terms of arrows, the rule means that if you add an arrow to a point, the point *to* which the arrow points must always be above the one *from* which it points. ![A join diagram](hasse.svg) -This arrangement allows us to compare any two points by just seeing which one is above the other e.g. to spot the *join* of two elements, you just have to identify the ones they connect to and see which one is lowest. +This arrangement allows us to compare any two points by just seeing which one is above the other e.g. we can determine the *join* of two elements, by just identifying the elements that they connect to and see which one is lowest. Color order --- -We all know many examples of total orders (any form of chart or ranking is a total order), but there are probably not so many obvious examples of partial orders that we can think of off the top of our head. So let's see some. In addition to providing a little context, this will help us understand joins and see why are they significant. +We all know many examples of total orders (any form of chart or ranking is a total order), but there are probably not so many obvious examples of partial orders that we can think of off the top of our head. So let's see some. This will gives us some context, and will help us understand what joins are. -To stay true to our form, let's revisit our color-mixing monoid and create a color-mixing partial order in which all colors point to colors that contain them. +To stay true to our form, let's revisit our color-mixing monoid and create a *color-mixing partial order* in which all colors point to colors that contain them. ![A color mixing poset](color_mixing_poset.svg) -If you go through it, you will notice that the join of any two colors is the color that they make up. Nice, right? +If you go through it, you will notice that the join of any two colors is the color that they make up when mixed. Nice, right? ![Join in a color mixing poset](color_mixing_poset_join.svg) Numbers by division --- -When we order numbers by "bigger or equal to", they form a total order (*the* total order even). But numbers can also form a partial order, for example if we order them by the relationship of which divides which, like if **A** divides **B**, then **A** is before **B** e.g. because **2 * 5 = 10**, **2** and **5** come before **10** (but **3**, for example does not). +We saw that when we order numbers by "bigger or equal to", they form a linear order (*the* linear order even.) But numbers can also form a partial order, for example they form a partial order if we order them by which divides which, i.e. if $a$ divides $b$, then $a$ is before $b$ e.g. because $2 \times 5 = 10$, $2$ and $5$ come before $10$ (but $3$, for example, does not come before $10$.) ![Divides poset](divides_poset.svg) @@ -227,60 +242,61 @@ And the *meet* (the opposite of join) of two numbers is their *greatest common d Inclusion order --- -Given a collection of all possible sets containing a combination of a given set of elements (like for example our colorful balls)... +Given a collection of all possible sets containing a combination of a given set of elements... ![A color mixing poset, ordered by inclusion](color_mixing_poset_inclusion_subsets.svg) -We can define what is called the *inclusion order* of those sets, in which **A** comes before **B** if **A** *includes* **B**, or (to use the proper term), if **B** is a *subset* of **A**. +...we can define what is called the *inclusion order* of those sets, in which $a$ comes before $b$ if $a$ *includes* $b$, or in other words if $b$ is a *subset* of $a$. ![A color mixing poset, ordered by inclusion](color_mixing_poset_inclusion.svg) -Note that the *join* operation in an inclusion order is the set union, and the *meet* operation as set intersection. +In this case the *join* operation of two sets is their *union*, and the *meet* operation is their set *intersection*. -This diagram might remind you of something, because if we take the colors that are in each of its set and mix it into one color, we get the color-blending partial order that we saw earlier. +This diagram might remind you of something - if we take the colors that are contained in each set and mix them into one color, we get the color-blending partial order that we saw earlier. ![A color mixing poset, ordered by inclusion](color_mixing_poset_blend.svg) -The order example with the number dividers is also isomorphic to an inclusion order - the inclusion order of all possible sets of *prime* numbers, including repeating ones (or alternatively the set of all *prime powers*). This is confirmed by the fundamental theory of arithmetic, which states that every number can be written as a product of primes in exactly one way. +The order example with the number dividers is also isomorphic to an inclusion order, namely the inclusion order of all possible sets of *prime* numbers, including repeating ones (or alternatively the set of all *prime powers*). This is confirmed by the fundamental theory of arithmetic, which states that every number can be written as a product of primes in exactly one way. ![Divides poset](divides_poset_inclusion.svg) Order isomorphisms --- -We mentioned order isomorphisms several times already so this is about time to elaborate a bit about what they are. Take the isomorphism between the number partial order and the prime inclusion order as an example. Like an isomorphism between any two sets, it is comprised of two functions: +We mentioned order isomorphisms several times already so this is about time to elaborate on what they are. Take the isomorphism between the number partial order and the prime inclusion order as an example. Like an isomorphism between any two sets, it is comprised of two functions: - One function from the prime inclusion order, to the number order (which in this case is just the *multiplication* of all the elements in the set) - One function from the number order to the prime inclusion order (which is an operation called *prime factorization* of a number, consisting of finding the set of prime numbers that result in that number when multiplied with one another). ![Divides poset](divides_poset_isomorphism.svg) -For sets, an isomorphism means just that the functions are inverse of each other. But as orders, besides being sets, have the arrows that connect them there is an additional requirement for a pair of functions to form an isomorphism - to be an isomorphism, a function has *to respect those arrows, in other words should be *order preserving*. More specifically, applying the function (let's call it F) to any two elements in one set (**a** and **b**) should result in two elements that have the same corresponding order in the other set (so **a ≤ b** iff **F(a) ≤ F(b)**. +When we talk about sets, an isomorphism means just a reversible function. But as orders, besides having their underlying sets, have the arrows that connect them, there is an additional requirement for a pair of functions to form an isomorphism - to be an isomorphism, a function has to *respect those arrows*, in other words it should be *order preserving*. More specifically, applying the function (let's call it F) to any two elements in one set ($a$ and $b$) should result in two elements that have the same corresponding order in the other set (so $a ≤ b$ if $F(a) ≤ F(b)$. Birkhoff's representation theorem --- -So far, we saw two different partial orders, one based on color mixing, and one based on number division, which can be represented by the inclusion orders of all possible combinations of sets of some *basic elements* (the primary colors in the first case, and the prime numbers (or prime powers) in the second one.) Many other partial orders can be defined in this way. Which ones exactly, is a question that is answered by an amazing result called *Birkhoff's representation theorem*. They are the partial orders that meet the following two criteria: +So far, we saw two different partial orders, one based on color mixing, and one based on number division, that can be represented by the inclusion orders of all possible combinations of sets of some *basic elements* (the primary colors in the first case, and the prime numbers (or prime powers) in the second one.) Many other partial orders can be defined in this way. Which ones exactly, is a question that is answered by an amazing result called *Birkhoff's representation theorem*. They are the *finite* partial orders that meet the following two criteria: -1. All elements have *joins* and *meets* (those partial orders are called *lattices*, by the way) -2. Those *meet* and *join* operations *distribute* over one another, that is if we denote joins as meets as **∨** or **∧**, then **x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z)** (those are called *distributive lattices*.) +1. All elements have *joins* and *meets*. +2. Those *meet* and *join* operations *distribute* over one another, that is if we denote joins as meets as $∨$ or $∧$, then $x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z)$. -(Just to note that this result is only proven for *finite* lattices, so it might not be valid for the numbers all the way to infinity. But it would be valid for any subset of them.) -I won't go into details about this result, I would only mention that the "prime" elements with which we can construct the inclusion order are the ones that are not the *join* of any other elements (for that reason, they are also called *join-irreducible* elements.) +The partial orders that meet the first criteria are called *lattices*. The ones that meet the second one are called distributive lattices. + +And the "prime" elements which we use to construct the inclusion order are the elements that are not the *join* of any other elements. They are also called *join-irreducible* elements. By the way, the partial orders that are *not* distributive lattices are also isomorphic to inclusion orders, it is just that they are isomorphic to inclusion orders that do not contain all possible combinations of elements. - - Lattices === -In the previous section we mentioned what *lattices* are - they are partial orders, in which every two elements have a *join* and a *meet*. So every lattice is also partial order, but not every partial order is a lattice (we will see even more members of this hierarchy). Most partial orders that are created based on some sort of rule, like the ones from the previous section, are also lattices when they are drawn in full, for example the color-mixing order. +We will now review the orders for which Birkhoff's theorem applies i.e. the *lattices*. Lattices are partial orders, in which every two elements have a *join* and a *meet*. So every lattice is also partial order, but not every partial order is a lattice (we will see even more members of this hierarchy). + +Most partial orders that are created based on some sort of rule are distributive lattices, like for example the partial orders from the previous section are also distributive lattices when they are drawn in full, for example the color-mixing order. ![A color mixing lattice](color_mixing_lattice.svg) -Notice that when drawing our color-mixing lattice, we added the black ball at the top and the white one at the bottom. We did that because otherwise the top three elements wouldn't have a *join* element, and the bottom three wouldn't have a *meet*. +Notice that we added the black ball at the top and the white one at the bottom. We did that because otherwise the top three elements wouldn't have a *join* element, and the bottom three wouldn't have a *meet*. Bounded lattices --- @@ -289,7 +305,9 @@ Our color-mixing lattice, has a *greatest element* (the black ball) and a *least **Task:** Prove that all finite lattices are bounded. -Semilattices and trees +{% if site.distribution == 'print' %} + +Interlude - semilattices and trees --- Lattices are partial orders that have both *join* *and* *meet* for each pair of elements. Partial orders that just have *join* (and no *meet*), or just have *meet* and no *join* are called *semilattices*. More specifically, partial orders that have *meet* for every pair of elements are called *meet-semilattices*. @@ -312,6 +330,9 @@ The implications of the tendency to use trees to model everything as opposed to > In simplicity of structure the tree is comparable to the compulsive desire for neatness and order that insists the candlesticks on a mantelpiece be perfectly straight and perfectly symmetrical about the center. The semilattice, by comparison, is the structure of a complex fabric; it is the structure of living things, of great paintings and symphonies. +{%endif%} + + diff --git a/_chapters/06_functors.md b/_chapters/06_functors.md index 51b5713..29137ba 100644 --- a/_chapters/06_functors.md +++ b/_chapters/06_functors.md @@ -16,14 +16,14 @@ So far, we saw many different categories and category types. Let's review them b The category of sets --- -We began (in chapters 1 and 2) by reviewing the mother of all categories - *the category of sets* which is not only the prototype of a category, but it contains many other categories, such as the category of types in a programming languages. +We began by reviewing the mother of all categories - *the category of sets* which is not only the archetype of a category, but it contains many other categories, such as the category of types in a programming languages. ![The category of sets](category_sets.svg) -Category types +Special types of categories --- -We learned that they are special types of categories, like categories thatghave just one *object* (monoids, groups) and categories that have only one *morphism* between any two objects (preorders, partial orders). +We also learned about some special types of categories that have some special properties like categories that have just one *object* (monoids, groups) and categories that have only one *morphism* between any two objects (preorders, partial orders.) ![Types of categories](category_types.svg) @@ -37,54 +37,55 @@ We also defined a lot of *categories based on different things*, like the ones b Finite categories --- -And most importantly, we saw some categories that are *completely made up and have no value whatsoever*, such as my made-up soccer hierarchy. We call those *finite categories*. Although few the finite categories are useful by themselves, the idea of finite categories is important - we can draw any combination of points and arrows and call it a category, in the same way that we can construct a set out of every combination of objects. +And most importantly, we saw some categories that are *completely made up and have no value whatsoever*, such as my made-up soccer hierarchy. We call those *finite categories*. Although they are not useful by themselves, the idea of finite categories is important - we can draw any combination of points and arrows and call it a category, in the same way that we can construct a set out of every combination of objects. ![Finite categories](finite_categories.svg) -For future reference, let's see some examples of finite categories. The simplest category is **0** (enjoy the minimalism of this diagram.) +For future reference, let's see some examples of finite categories. The simplest category is $0$ (enjoy the minimalism of this diagram.) ![The finite category 0](finite_zero.svg) -The next simplest category is **1** - it is comprised of one object no morphism besides its identity morphism (as usual, we don't take note of the identity morphisms unless they are rellevant.) +The next simplest category is $1$ - it is comprised of one object no morphism besides its identity morphism (as usual, we don't draw or in general take note of the identity morphisms unless they are rellevant.) ![the finite category 1](finite_one.svg) -If we increment the number of objects to two, we see a couple of more interesting categories, like for example the category **2** containing two objects and one morphism. +If we increment the number of objects to two, we see a couple of more interesting categories, like for example the category $2$ containing two objects and one morphism. ![the finite category 2](finite_two.svg) **Task:** There are just two more categories that have 2 objects and at most one morphism between two objects, draw them. -And finally the category **3** has 3 objects and also 3 morphisms (one of which is the composition of the other two.) +And finally the category $3$ has 3 objects and also 3 morphisms (one of which is the composition of the other two.) ![the finite category 3](finite_three.svg) -Categorical Isomorphisms +Isomorphisms === -Many of the categories we saw have similarities between one another, as for example both the color-mixing order and categories that represent logic have greatest and least objects. To pinpoint such similarities and understand what they mean, we specify formal ways to connect categories to one another. In chapter 1 we talked about set isomorphisms, which establish an equivalence between sets. If you remember, a set isomorphism is a *two-way function* between two sets or, alternatively it can be seen as two "twin" functions each of which equals identity when composed with the other. +Many of the categories we saw have similarities between one another, as for example both the color-mixing order and categories that represent logic have greatest and least objects. To pinpoint such similarities and understand what they mean, we specify formal ways to connect categories with one another. + +In chapter 1 we talked about set isomorphisms, which establish an equivalence between sets, if you remember, a set isomorphism is a *two-way function* between two sets, which can alternatively be viewed as two "twin" functions each of which equals identity when composed with the other. ![Set isomorphism](set_isomorphism.svg) -Then, in chapter 4, we mentioned order isomorphisms and saw that they are the same thing as set isomorphisms, but with one extra condition - aside from being there, the functions that define the isomorphism have to preserve the order of the elements i.e. all elements have to have the same arrows pointing to and from them. Or more formally put: **a** and **b**, **a ≤ b** iff **F(a) ≤ F(b)**. +Then, in chapter 4, we mentioned order isomorphisms and saw that they are the same thing as set isomorphisms, but with one extra condition - aside from being there, the functions that define the isomorphism have to preserve the order of the elements i.e. all elements have to have the same arrows pointing to and from them. Or more formally put, for any $a$ and $b$ if we have $a ≤ b$ we should also have $F(a) ≤ F(b)$ (and vise versa.) ![Order isomorphism](order_isomorphism.svg) -We can extend this definition to work for categories as well. However, unlike orders, categories can have more than one morphism between two objects, so the definition is a little more complex. - -It is the following: given two categories, an isomorphism between them is an invertible function between the underlying sets of objects, *and* an invertible function between the morphisms that connect them, which maps each morphism to a morphism with the same signature (the "signature" of a function is just its source and target, so two functions have the same signature if they have the same source and target sets). +We can extend this definition to work for categories that have more than one morphism between two objects. The definition is a little more complex, but not a lot. It is the following: given two categories, an isomorphism between them is an invertible function between the underlying sets of objects, *and* an invertible function between the morphisms that connect them, which maps each morphism to a morphism with the same signature (or the same source and target) ![Category isomorphism](category_isomorphism.svg) -Although a little more complex, this definition is the same as the one we have for orders - it is just that when dealing with categories, we have to account for the fact that we can have more than one morphism between two objects and so we need to explicitly specify which one corresponds to which. +If we examine it closely we will see that, although a little bit more complex, this definition is equivalent to the one we have for orders - it is just that when we can have more than one morphism between two given objects we need to explicitly specify which morphism corresponds to which in the other category. ![Category isomorphism](category_order_isomorphism.svg) -In order theory we only need to verify that the corresponding morphism actually exist (this is guaranteed by the *order-preserving* condition.) +And when the categories that we connect with one another can potentially have just one morphism, we only need to connect the objects and to verify that the corresponding morphism actually exist in the other category (this is guaranteed by the *order-preserving* condition.) + ![Order isomorphism](category_order_isomorphism_2.svg) -As you see, categorical isomorphisms are easy to define, however they are very *hard to find* in practice - the only one that comes to mind to me is the Curry-Howard-Lambek isomorphism from the last chapter. And the reason for that is simple - if two categories are isomorphic, they basically contain the same data and it would be more accurate to refer to them as different *representations* of the same category than as separate categories. +As you see, categorical isomorphisms are not hard to define, however they are very *hard to find* in practice - the only one that comes to mind to me is the Curry-Howard-Lambek isomorphism from the last chapter. And the reason they are so rare is simple - if two categories are isomorphic, they basically contain the same data and it would be more accurate to refer to them as different *representations* of the same category than as separate categories. -**Task:** Although it's trivial, we didn't prove that the first functor law (the one about the preservation of identities always holds. Interestingly enough, for groups/monoids it actually follows from the second law. Try to prove that. Start with the definition of the identity function. +$Task:$ Although it's trivial, we didn't prove that the first functor law (the one about the preservation of identities always holds. Interestingly enough, for groups/monoids it actually follows from the second law. Try to prove that. Start with the definition of the identity function. Functors in orders === -And now let's talk about one concept that is completely unrelated to functors, nudge-nudge (I know you are probably tired of this but hey, bad jokes are better than no jokes at all.) In the theory of orders, we have functions between orders (which is unsurprising, as orders, like monoids/groups, are based on sets.) And one very interesting type of such function, which has applications in calculus and analysis, is a *monotonic function* (also called *monotone map*). This is a function between two orders that *preserves the order* of the elements. So a function **F** is monotonic when for every **a** and **b** in the source order, if **a ≤ b** then **F(a) ≤ F(b)**. +And now let's talk about one concept that is completely unrelated to functors, nudge-nudge (I know you are probably tired of this but hey, bad jokes are better than no jokes at all.) In the theory of orders, we have functions between orders (which is unsurprising, as orders, like monoids/groups, are based on sets.) And one very interesting type of such function, which has applications in calculus and analysis, is a *monotonic function* (also called *monotone map*). This is a function between two orders that *preserves the order* of the elements. So a function $F$ is monotonic when for every $a$ and $b$ in the source order, if $a ≤ b$ then $F(a) ≤ F(b)$. For example, the function that maps the current time to the distance travelled by some object is monotonoc because the distance travelled increases (or stays the same) as time increases. @@ -364,22 +384,13 @@ Functor laws It is not hard to see that monotone maps obey the first functor law - identities are the only morphisms that go between a given object and itself. -And the second law also follows from the fact that there is only one morphism with a given signature. Suppose we have a monotone map. Suppose that in the source order we have two morphisms **f :: a ➞ b** and **g :: b ➞ c**. Then, in the target order would contain morphisms that correspond to those two: **F(f): F(a) ➞ F(b)** **F(g): F(b) ➞ F(c)** +And the second law also follows from the fact that there is only one morphism with a given signature. Suppose we have a monotone map. Suppose that in the source order we have two morphisms $f :: a ➞ b$ and $g :: b ➞ c$. Then, in the target order would contain morphisms that correspond to those two: $F(f): F(a) ➞ F(b)$ $F(g): F(b) ➞ F(c)$ -If we compose the two morphisms in the target order, we get a morphism **F(g)•F(f) :: F(a) ➞ F(c)**. +If we compose the two morphisms in the target order, we get a morphism $F(g)•F(f) :: F(a) ➞ F(c)$. -If we compose the two morphisms in the source order, we get a morphism **g•f :: a ➞ c**. And from it, we can get the corresponding morphism in the target category - **F(g•f) :: F(a) ➞ F(c)**. +If we compose the two morphisms in the source order, we get a morphism $g•f :: a ➞ c$. And from it, we can get the corresponding morphism in the target category - $F(g•f) :: F(a) ➞ F(c)$. -But both morphisms **F(g•f)** and **F(g)•F(f)** have the signature **F(a) ➞ F(c)** and so they must be equal to one another. - - +But both morphisms $F(g•f)$ and $F(g)•F(f)$ have the signature $F(a) ➞ F(c)$ and so they must be equal to one another. The category of small categories === @@ -396,6 +407,24 @@ There isn't much to say about this category, it is just a good exercise to try t [The category of categories](category_of_categories) + +Categories all the way down +--- + +The recursive nature of category theory might leave some of you confused: we started by saying that categories are *composed of objects and morphisms*, but now we are saying that there are morphisms between categories (functors) and a category where *the objects are categories themselves*. Does that mean that categories are an example of categories? + +Yes. Sounds a bit weird on intuitive level (as for example biscuits don't contain other biscuits and houses don't use houses as building material) but it is perfectly legitimate. + +Category theory does *categorize* (see what I did there) everything, so all of maths is categories all the way down and whether you would threat a given category as a universe, or as a point depends solemly on your viewpoint. + +Like for example, every monoid is a category with one just object. But at the same time, monoids can be seen as belonging to one category - the category of monoids - with monoid homomorphisms acting as objects. + +At the same time we have the category of groups, for example, which contains the category of monoids as a subcategory, as all monoids are groups. + +There may be many more levels of categories from categories. However that does not mean that we have to cover all of them and think about them at all. It is like the concept of a derivative in calculus - the first derivative of a position of the object gives its *speed*, which is useful, the derivative of speed is also useful - it is *velocity*, but the derivative of velocity and those after it leave us indifferent. + +We can use the same tactict with our little journey in category theory - stick on the level that make sense for us and not be obsessed with forming picture of the whole thing Because there is no *whole thing* - category theory is an *abstract* theory. That is, it does not seek to represent an actual state of affairs, but to provide a language that you can use to express many different ideas, actual or purely imaginary. So view the category of categories not as a structure, but as a space, where all these concepts live. + {% if site.distribution == 'print' %} The ghost of Russell's paradox @@ -405,20 +434,61 @@ We say *small* because otherwise the category will include itself and it's going {% endif %} -Categories all the way down +Free and forgetful functors +=== + +In the first few chapters, we reviewed a lot of types of categories that are based on each other i.e. ones where one category is the same as the other plus some additional law - groups are monoids with added inversion, partial orders are antisymmetric preorders. And virtually all categories can be viewed as are sets with added morphisms. + +![Comparison of different types of categories](categories_comparison.svg) + +Between any two such categories there are two functors called the free and forgetful functor. + +Forgetful functors +=== + +Forgetful functors map the objects from the more richer and featureful category to their corresponding objects in the simpler and more unstructured one. + +They strip (forget) all the structure of the more complex category which is not present in the simpler one. i.e. + +Object mapping --- -The recursive nature of category theory might leave some of you confused: we started by saying that categories are composed of objects and morphisms, but now we are saying that there are morphisms between categories as well. Does that mean that categories are an example of categories? +If you do away with the monoid operation of a given monoid, what is left is its underlying set. This observation defines the object mapping of a forgetful functor that goes from the category of monoids to the category of sets (where each monoid is mapped to it's underlying set.) -Yes. Sounds a bit weird on intuitive level (as for example biscuits don't contain other biscuits and houses don't use houses as building material) but it is perfectly legitimate. +![Forgetful functor - object mapping](forgetful_functor_objects.svg) +Morphism mapping +--- -category theory does *categorize* (see what I did there) everything as categories, so it is categories all the way down, like for example, every monoid is a category with one just object. +In order for the forgetful functor to really be a functor it also must map morphisms between the two categories i.e. to map every *monoid homomorphism* between two monoids to a function between their underlying sets. This won't be hard - we said that monoid homomorphisms are function between the monoids' underlying sets which preserves the group operation. Which means that... they are functions. So we need only to forget the extra conditions. -But at the same time, monoids can be seen as belonging to one category - the category of monoids - with monoid homomorphisms acting as objects. +![Forgetful functor](forgetful_functor.svg) -At the same time we have the category of groups, for example, which contains the category of monoids as a subcategory, as all monoids are groups. +Functor laws +--- -There may be many more levels of categories within categories. +In this case the functor laws are obviously followed - we basically copied the structure of the monoid category into the set category. + +Free functors +=== + +Now let's review the functor that has certain relationship with the free functor, but goes the other way around - from sets to monoids. This section would be a little longer, as while going from a more complex category to a simpler one is trivial enough, going the other way around is not that easy. + +As a matter of fact, literary going the other way around is impossible, as the forgetful functor maps all monoids that are based on a given set to that set, so if we try to reverse the mapping we would get something that is not a functor. + +In other words, the connection between more simple to more complex versions of a category is not an isomorphism - we cannot connect each underlying set to *all of the monoids that are based on it*. However, we can connect them to one special monoid that is connected to all of them. + +And that object is the *free monoid* that we saw in chapter 3. And that is the free functor. + +Object mapping +--- + +So the free functor maps every set to the free monoid of that set. When we reviewed free monoids we said that the free monoid of a set $A$ it is the monoid of lists of A's which we will dub $[A]$. The object mapping is just a function that maps each object $a:A$ to the singleton list, so $a \to [a]$. + +Morphism mapping +--- + +The free monoid for set A is the monoid containing lists of elements of type a, so the morphism mapping of the free functor maps each function between sets to a function between lists of sets. + +And the way to construct this mapping that establishes a connection between the free and forgetful functor is to apply the function to every element of that lists. -However that does not mean that we have to cover all of them and think about them at all. It is like the concept of a derivative in calculus - the first derivative of a position of the object gives its *speed*, which is useful, the derivative of speed is also useful - it is **velocity**, but the derivative of velocity and those after it leave us indifferent. We can use the same tactict with our little journey in category theory - stick on the level that make sense for us and not be obsessed with forming picture of the whole thing Because there is no *whole thing* - category theory is an *abstract* theory. That is, it does not seek to represent an actual state of affairs, but to provide a language that you can use to express many different ideas, actual or purely imaginary. So view the category of categories not as a structure, but as a space, where all these concepts live. diff --git a/_chapters/06_functors/constant_functor.svg b/_chapters/06_functors/constant_functor.svg new file mode 100644 index 0000000..58db979 --- /dev/null +++ b/_chapters/06_functors/constant_functor.svg @@ -0,0 +1,323 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_chapters/06_functors/endofunctor_programming.svg b/_chapters/06_functors/endofunctor_programming.svg index 538adc6..ac42ef6 100644 --- a/_chapters/06_functors/endofunctor_programming.svg +++ b/_chapters/06_functors/endofunctor_programming.svg @@ -5,6 +5,7 @@ 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:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" viewBox="0 0 595.3 189.5" @@ -25,7 +26,91 @@ + id="defs15617"> + + + + + + + + + + + + + + + + + + + inkscape:current-layer="svg15613" /> + transform="matrix(0.59711466,-0.03135433,0.03210307,0.57606093,40.023432,263.59217)" /> + transform="matrix(0.59711466,-0.03135433,0.03210307,0.57606093,181.10453,257.98307)" /> + + + + + + transform="matrix(0.54148297,0,0,0.54148297,142.37514,171.45154)"> + + + + diff --git a/_chapters/06_functors/functor_programming_morphisms.svg b/_chapters/06_functors/functor_programming_morphisms.svg new file mode 100644 index 0000000..05f4c22 --- /dev/null +++ b/_chapters/06_functors/functor_programming_morphisms.svg @@ -0,0 +1,312 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + [num] + + + + + + + num + + + + + + + + + + + + + [string] + + + + + + + + + + + + + + + + + + string + + diff --git a/_chapters/06_functors/functor_programming_objects.svg b/_chapters/06_functors/functor_programming_objects.svg new file mode 100644 index 0000000..c6e2a3b --- /dev/null +++ b/_chapters/06_functors/functor_programming_objects.svg @@ -0,0 +1,215 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + [num] + + + + + + [string] + + + + + num + + + + + string + + diff --git a/_chapters/07_natural_transformations.md b/_chapters/07_natural_transformations.md index 321bac8..c3122b3 100644 --- a/_chapters/07_natural_transformations.md +++ b/_chapters/07_natural_transformations.md @@ -1,11 +1,7 @@ ---- -layout: default -title: Natural Transformations ---- Natural transformations and advanced concepts === -In this chapter, we will introduce the central concept of category theory. It is the concept of a morphism between functors or of *natural transformation*. Understanding natural transformations will enable us to define category equality and some other advanced concepts. +In this chapter, we will introduce the central concept of category theory. It is the concept of a morphism between functors or *natural transformation*. Understanding natural transformations will enable us to define category equality and some other advanced concepts. Natural transformations are really is the heart of category theory - As a matter of fact, category theory was invented with the purpose of studying natural transformations. The importance of natural transformations is not obvious at first, and so before introducing them I like to talk about the body of knowledge that this heart maintains (I am good with methaphors... in principle.) @@ -124,29 +120,17 @@ Isomorphism is not hard to construct - given two sets, containing three objects But most of these isomorphisms, are just random. In our studies we are only interested in structures that *make sense*. In category theory the abstract notion of making sense is captured by the naturality condition. + + + Free objects === https://math.stackexchange.com/questions/131389/what-are-free-objects - -Adjunctions -=== - -https://github.com/adamnemecek/adjoint/ - -https://chrispenner.ca/posts/adjunction-battleship - --- Left adjoints preserve joins and right adjoints preserve meets. - --- Free/forgetful adjunctions are ones where the unit is Id. - - - Monads === - Representable functors === @@ -156,7 +140,6 @@ Yoneda Lemma === - https://www.azimuthproject.org/azimuth/show/Applied+Category+Theory+Course#Course diff --git a/_chapters/08_adjunctions.md b/_chapters/08_adjunctions.md new file mode 100644 index 0000000..2fa6f29 --- /dev/null +++ b/_chapters/08_adjunctions.md @@ -0,0 +1,51 @@ + +Adjunctions +=== + +In this chapter we will continue with this *leit motif* that we developed in the previous two chapters - to begin each of them by introducing a new concept of equality between categories (and furthermore, for each new type of equality to be more relaxed than the previous one.) + +We started the chapter about functors by reviewing *categorical isomorphisms*, which are invertable functions between categories. + +Then in the chapter on *natural transformations* we saw categories that are equivalent up to an isomorphism. + +And now we will relax the condition even more and will review a relationship that is not exactly an equality, , but it is not non-equality either. It is not two-way, but at the same time it is not exactly one-way as well. A relationship called *adjunction*. + +As you can see, I am not very good at explaining, so I got some examples alligned. But before we proceed with them, we will go through some of the basic terminology. + +Like equivalence, adjunction is a relationship between two categories. Like equivalence, it is composed of two functors. + +However, unlike equivalence, an adjunction is not symmetric i.e. although the two functors are two way and we + +$F \bullet G \cong id_{D}$ + +$G \bullet F \cong id_{C}$ + +$F \bullet G \to id_{D}$ + +$G \bullet F \to id_{C}$ + +Free-forgetful adjunctions +=== + + +Formal concept analysis +=== + +Tensor-Hom adjunction +=== + +The tensor-hom adjunction is actually a codename for the curry-uncurry function that we saw earlier. + + + +Adjunctions +=== + +https://github.com/adamnemecek/adjoint/ + +https://chrispenner.ca/posts/adjunction-battleship + +-- Left adjoints preserve joins and right adjoints preserve meets. + +-- Free/forgetful adjunctions are ones where the unit is Id. + diff --git a/_layouts/default.html b/_layouts/default.html index b311c58..98ad1d0 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -84,10 +84,12 @@ window.MathJax = {