mirror of
https://github.com/abuseofnotation/category-theory-illustrated.git
synced 2024-09-11 17:08:54 +03:00
Gramarly
This commit is contained in:
parent
e74a9dfe67
commit
be3fe9de16
@ -1,35 +1,35 @@
|
||||
Bear With Me for a Set
|
||||
Sets
|
||||
===
|
||||
|
||||
We will begin our inquiry by looking at the basic theory of sets. You will understand why shortly. For now it is suffice to say that sets are an example of a category.
|
||||
We will begin our inquiry by looking at the basic theory of sets. You will understand why shortly. For now, it suffices to say that sets are an example of a category.
|
||||
|
||||
Preface: What is an Abstract Theory
|
||||
===
|
||||
|
||||
> Instead of asking what can be defined and deduced from what is assumed to begin with, we ask instead what more general ideas and principles can be found, in terms of which what was our starting-point can be defined or deduced.
|
||||
|
||||
Most scientific and mathematical theories have a specific domain, to which they are related, and in which they are valid. They are created with this domain in mind and are not intended to be used outside of it. For example Darwin's theory of evolution is created so it explains how different biological species came to be. And quantum mechanics is a description of what particles are at the low scale. Even the work of most mathematicians, although it is not bound to a specific domain, is strongly related to it, as differential equations are liked to the description of events that change over time.
|
||||
Most scientific and mathematical theories have a specific domain, to which they are related, and in which they are valid. They are created with this domain in mind and are not intended to be used outside of it. For example, Darwin's theory of evolution is created so it explains how different biological species came to be. And quantum mechanics is a description of what particles are at the low scale. Even the work of most mathematicians, although it is not bound to a specific domain, is strongly related to it, as differential equations are linked to the description of events that change over time.
|
||||
|
||||
Set theory and category theory are different. They are not created for to provide rigorous explaination of how a particular phenonemum works, but to try to provide a more general framework for explaining all kinds of phenomena. Theories that are like that are called *abstract* theories. All theories *use abstraction*, else they would be pretty useless (without it Darwin would have to speak about specific animal species, or even a individual animals) but few are inherently abstract, so some of their core concepts are left unspecified. Or in other world. That is all theories are applicable outside of their domains, but set theory and category theory do not have a domain to begin with.
|
||||
Set theory and category theory are different. They are not created for to provide a rigorous explanation of how a particular phenonium works, but to try to provide a more general framework for explaining all kinds of phenomena. Theories that are like that are called *abstract* theories. All theories *use abstraction*, else they would be pretty useless (without it Darwin would have to speak about specific animal species or even individual animals) but few are inherently abstract, so some of their core concepts are left unspecified. Or in other words, all theories are applicable outside of their domains, but set theory and category theory do not have a domain, to begin with.
|
||||
|
||||
People have tried to be precise and at the same time down to Earth for centuries, and only recently discovered that "precise and down to earch" is an oxymoron. Let's take Euclidian geometry as an example. Yes, Euclidian geometry is precise, because it is valid for all sets of objects, called ("point" "line" "angle" and "circle" etc.), which have relationships, as defined by the five famous axioms. Yes, geometry does,in many instances, describe the natural world, because there are many sets of objects which have these relations. However its "precise" part and its "down to Earth" parth have nothing to do with each other. We can, for example say that a point is any stain on the floor of your room, and that a line is a piece of duct tape, put on the same floor, and that will be a completely valid application of the Euclidian laws, albeit not very useful one. Or we can try to use geometry to reason about points on the surface of the Earth, which is a very useful application, of geometry, however not of Euclidian geometry, because Euclidian geometry only describes points on a flat plane, and the Earth is not flat. You can argue that these are actually two separate theories there, which just happen to be perceived as one. You have the axioms, or the postulates on one hand, which are not useful for anything on their own, and you have applications in science and engineering which are somewhat based on them, but not quite.
|
||||
People have tried to be precise and at the same time down to Earth for centuries, and only recently discovered that "precise and down to Earth" is an oxymoron. Let's take Euclidian geometry as an example. Yes, Euclidian geometry is precise, because it is valid for all sets of objects, called ("point" "line" "angle" and "circle" etc.), which have relationships, as defined by the five famous axioms. Yes, geometry does, in many instances, describe the natural world, because there are many sets of objects which have these relations. However, its "precise" part and it's "down to Earth" part have nothing to do with each other. We can, for example, define a point as any stain on the floor of your room and that a line as a piece of duct tape, put on the same floor - that will be a completely valid application of the Euclidian laws, albeit not very useful one. Or we can try to use geometry to reason about points on the surface of the Earth, which is a very useful application, of geometry, however not of Euclidian geometry, because Euclidian geometry only describes points on a flat plane, and the Earth is not flat. You can argue that these are actually two separate theories there, which just happen to be perceived as one. You have the axioms, or the postulates on one hand, which are not useful for anything on their own, and you have applications in science and engineering which are somewhat based on them, but not quite.
|
||||
|
||||
What Category Theory aims is to formalize some common concepts that we use in our daily (intellectual) lives in the same way that grammar textbooks formalize the language that we use in our daily lives - a language that does not follow any rules on its own.
|
||||
What Category Theory aims, is to formalise some common concepts that we use in our daily (intellectual) lives in the same way that grammar textbooks formalise the language that we use in our daily lives - a language that does not follow any rules on its own.
|
||||
|
||||
Sets
|
||||
===
|
||||
|
||||
Everything in set theory is defined in therms of sets. A set is a collection of things where, the "things" can be anything you want. Consider, for example these balls:
|
||||
Everything in set theory is defined in terms of sets. A set is a collection of things where the "things" can be anything you want. Consider, for example, these balls:
|
||||
|
||||
![Balls](elements.svg)
|
||||
|
||||
For example let's construct a set, call it **G** (as grey), consisting of *all* of them. This is how we can mark it:
|
||||
For example, let's construct a set, call it **G** (as grey), consisting of *all* of them. This is how we can mark it:
|
||||
|
||||
![The set of all balls](all.svg)
|
||||
|
||||
The example may look childish, but in fact this set is just as valid as any other set.
|
||||
The example may look childish but in fact, this set is just as valid as any other set.
|
||||
|
||||
The things that are contained in the set are called its *elements*. A set is like a summary of its elements. It has no other structure, for example there is not order, no ball goes before or after another, there are no members which are "special" with respect to their membership in the set. Two sets that contain of the same elements are also the same.
|
||||
The things that are contained in the set are called its *elements*. A set is like a summary of its elements. It has no other structure, for example, there is not order, no ball goes before or after another, there are no members which are "special" with respect to their membership in the set. Two sets that contain the same elements are also the same.
|
||||
|
||||
The key insight about what a set it is that it enables you to reason about several things as if they were one.
|
||||
|
||||
@ -37,15 +37,14 @@ The key insight about what a set it is that it enables you to reason about sever
|
||||
Subsets
|
||||
---
|
||||
|
||||
Let's construct one more set. The set of *all balls that are warm color*. I will call it **Y**, because in the diagram its coloured in **y**ellow.
|
||||
Let's construct one more set. The set of *all balls that are warm colour*. I will call it **Y**, because in the diagram is coloured in **y**ellow.
|
||||
|
||||
![Y - the set of all balls of warm colors](subset.svg)
|
||||
![Y - the set of all balls of warm colours](subset.svg)
|
||||
|
||||
Notice that **Y** contains just elements that are also present in **G**. That is, every element of the set of **Y** is also an element in the set **G**. When two sets have this relation, we may say that **Y** is a *subset* of **G** (or **Y ⊆ G**).
|
||||
|
||||
![Y and G together](set_subset.svg)
|
||||
|
||||
|
||||
Singleton Sets
|
||||
---
|
||||
|
||||
@ -53,7 +52,7 @@ The set of all *red balls* contains just one ball.
|
||||
|
||||
![The singleton set of red balls](singleton.svg)
|
||||
|
||||
Like we said above, sets are all about for summarizing *several* elements into one. Still sets that contain just one element are perfectly valid. Simply, there are things which are one of a kind. Furthermore if I have a function which expects a set of given items, here shouldn't be any issue if the "items" are just one item. Or to take a real-life example, the set of queeens of England is a singleton set. The set of books written by the American writer Harper Lee were a singleton - she has written just one novel, until 2015.
|
||||
Like we said above, sets are all about for summarising *several* elements into one. Still, sets that contain just one element are perfectly valid. Simply, there are things which are one of a kind. Furthermore, if I have a function which expects a set of given items, here shouldn't be any issue if the "items" are just one item. Or to take a real-life example, the set of queens of England is a singleton set. The set of books written by the American writer Harper Lee were a singleton - she has written just one novel, until 2015.
|
||||
|
||||
The Empty set
|
||||
---
|
||||
@ -63,7 +62,7 @@ Of course if one is a valid answer, so can be zero. If we want a set of all *bla
|
||||
![The empty set](void.svg)
|
||||
|
||||
|
||||
Note that a set is defined only by the items it contains, which means that there is no difference between the set that contains zero *balls*, and the set that contains zero *numbers*, for instance. In other words, the empty set is *unique* set, which makes it a very special one. Formally, the empty set is marked with the symbol **∅** (so **B = W = ∅**).
|
||||
Note that a set is defined only by the items it contains, which means that there is no difference between the set that contains zero *balls* and the set that contains zero *numbers*, for instance. In other words, the empty set is *unique* set, which makes it a very special one. Formally, the empty set is marked with the symbol **∅** (so **B = W = ∅**).
|
||||
|
||||
The empty set is a special one, for example, it is a subset of every other set (mathematically speaking, **∀ A | A ⊆ ∅**)
|
||||
|
||||
@ -74,7 +73,7 @@ Functions
|
||||
|
||||
A function is a relationship between two sets which matches each element of one set, called the *domain* of the function, with exactly one element from another set, called the converse domain, or the *codomain* of the function.
|
||||
|
||||
Here is a function, **f** which maps each ball from the set **R** to the ball with the opposite color in another set **G** ( in mathematics a function's name is often acompanied by the names of its domain and codomain, like this: **f: R → G**)
|
||||
Here is a function, **f** which maps each ball from the set **R** to the ball with the opposite colour in another set **G** ( in mathematics a function's name is often accompanied by the names of its domain and codomain, like this: **f: R → G**)
|
||||
|
||||
![Opposite colors](function_one_one.svg)
|
||||
|
||||
@ -82,7 +81,7 @@ This is probably one of the simpler types of functions there exists. That is bec
|
||||
|
||||
But functions can also express relationships of the type *many-to-one*, where *many* elements from the domain might be connected to *one* element from the codomain (but not the other way around).
|
||||
|
||||
For example a function can express a relationship in which several elements from the domain relate to the same element of the codomain.
|
||||
For example, a function can express a relationship in which several elements from the domain relate to the same element of the codomain.
|
||||
|
||||
![Function from a bigger set to a smaller one](function_big_small.svg)
|
||||
|
||||
@ -108,11 +107,11 @@ Question: Do all functions that we drew at the beginning *express* something? Do
|
||||
The Identity Function
|
||||
---
|
||||
|
||||
For every set **G**, no matter what it represents, we can define the function that does nothing, or in other words a function which maps every element G to itself. It is called the *the identity function* of **G** or **idG: G → G**.
|
||||
For every set **G**, no matter what it represents, we can define the function that does nothing, or in other words, a function which maps every element G to itself. It is called the *the identity function* of **G** or **idG: G → G**.
|
||||
|
||||
![The identity function](function_identity.svg)
|
||||
|
||||
You can think of **idG** as a function which represents the set **G** in the realm of functions. It's existence allows us to prove many theorems, that we "know" by intuition, formally.
|
||||
You can think of **idG** as a function which represents the set **G** in the realm of functions. Its existence allows us to prove many theorems, that we "know" by intuition, formally.
|
||||
|
||||
Functions and Subsets
|
||||
---
|
||||
@ -162,7 +161,7 @@ I will use the occasion to reiterate some of the more important characteristics
|
||||
- Zero from the domain is connected to itself in the codomain, and that is OK.
|
||||
- Some numbers aren't the square of any other number. That is also OK.
|
||||
|
||||
Overall everything is OK, as long as you can always provide exactly one result (also known as *The result™*) per value, and in mathematics almost always do. Actually math is designed in a way so its operations are valid functions:
|
||||
Overall everything is OK, as long as you can always provide exactly one result (also known as *The result™*) per value, and in mathematics almost always do. Actually, math is designed in a way so its operations are valid functions:
|
||||
|
||||
> Every generalisation of number has first presented itself as needed for some simple problem: negative numbers were needed in order that subtraction might be always possible, since otherwise a − b would be meaningless if a were less than b; fractions were needed in order that division might be always possible; and complex numbers are needed in order that extraction of roots and solution of equations may be always possible.
|
||||
|
||||
@ -173,7 +172,7 @@ Sets and Functions in Programming
|
||||
|
||||
Sets are used extensively in programming, except that there they are called *types* or also *classes*. All sets of numbers that we discussed earlier also exist in most languages as types, and there are also some non-mathematical types that play a huge role in programming.
|
||||
|
||||
The simplest type, `Boolen` is nothing more than a set of two values - `true` and `false`:
|
||||
The simplest type, `Boolean` is nothing more than a set of two values - `true` and `false`:
|
||||
|
||||
![Set of boolean values](boolean.svg)
|
||||
|
||||
@ -187,15 +186,15 @@ Most of the types of programming are composite types - they are a combination of
|
||||
|
||||
Question: What is the type equivalent of subsets in programming?
|
||||
|
||||
Question: Do you recognize some of the basic functions we defined in programming languages you know?
|
||||
Question: Do you recognise some of the basic functions we defined in programming languages you know?
|
||||
|
||||
Some functions in programming (also called methods, subroutines, etc.) kinda resemble mathematical functions - they sometimes take one value of a given type (or in other words, and element that belong to a given set) and always return exactly one element which belongs to another type (or set). For example here is a function which that takes an argument of type `Char` and returns a `Boolean`, depending whether the character is a letter.
|
||||
Some functions in programming (also called methods, subroutines, etc.) kinda resemble mathematical functions - they sometimes take one value of a given type (or in other words, an element that belongs to a given set) and always return exactly one element which belongs to another type (or set). For example here is a function which that takes an argument of type `Char` and returns a `Boolean`, depending on whether the character is a letter.
|
||||
|
||||
![A function from Char to Boolean](char_boolean.svg)
|
||||
|
||||
However functions in programming can also be quite different from mathematical functions - they can perform various operations that have nothing to do with returning a value, called side effects. This is because most common programming languages and paradigms which are in use today were created at a times when the computer resources were much more limited than today, and programming - much more cumberstone, so people had bigger problems than the fact that their functions were not mathematically sound.
|
||||
However functions in programming can also be quite different from mathematical functions - they can perform various operations that have nothing to do with returning a value, called side effects. This is because most common programming languages and paradigms which are in use today were created at times when the computer resources were much more limited than today, and programming - much more cumbersome, so people had bigger problems than the fact that their functions were not mathematically sound.
|
||||
|
||||
One type of functions used in programming which strongly resemble mathematical ones are those which convert a value from one type to another, for example the function which converts a a floating-point number to an Integer. That is probaly the reason why most functional languages are strongly-typed.
|
||||
One type of functions used in programming which strongly resembles mathematical ones are those which convert a value from one type to another, for example, the function which converts a floating-point number to an Integer. That is probably the reason why most functional languages are strongly-typed.
|
||||
|
||||
|
||||
Functional Composition
|
||||
@ -209,7 +208,7 @@ If we apply the first function **g** to some element from set **Y**, we will get
|
||||
|
||||
![Applying one function after another](functions_one_after_another.svg)
|
||||
|
||||
We can define a new function, that is the equivalent to performing the operation described above. Lets call it **h: Y → G**. We may say that **h** is the *composition* of **g** and **f**, or **h = f ∘ g** (notice that the first function is on the right, so its similar to **b = f(g(a)**).
|
||||
We can define a new function, that is the equivalent to performing the operation described above. Let us call it **h: Y → G**. We may say that **h** is the *composition* of **g** and **f**, or **h = f ∘ g** (notice that the first function is on the right, so it's similar to **b = f(g(a)**).
|
||||
|
||||
![Functional composition](functions_compose.svg)
|
||||
|
||||
@ -229,7 +228,7 @@ If we "zoom-out" the last diagram so it does not show the individual set element
|
||||
|
||||
![Functional composition for sets](functions_compose_sets.svg)
|
||||
|
||||
In fact, because the diagram commutes (that is, all arrows, starting from a given set element ultimately lead to the same corresponding element from the resulting set), ennumerating the elements is redundant. Having this insight allows us to redefine functional composition in the following, more visual, way:
|
||||
In fact, because this diagram commutes (that is, all arrows, starting from a given set element ultimately lead to the same corresponding element from the resulting set), enumerating the elements is redundant. Having this insight allows us to redefine functional composition in the following, more visual, way:
|
||||
|
||||
The composition of two functions **f** and **g** is a third function **h** defined in such a way that this diagram commutes.
|
||||
|
||||
@ -242,7 +241,7 @@ The Power of Composition
|
||||
|
||||
To understand how powerful composition is, consider the following: one set being connected to another means that each function from the second set can be transferred to a corresponding function from the first one.
|
||||
|
||||
If we have a function **g: P → Y ** from set **P** to set **Y**, then for every function **f** from the set **Y** to any other set, there is a corresponding function **f ∘ g** from the set **P** to the same set. In other words every time you create a new function.
|
||||
If we have a function **g: P → Y ** from set **P** to set **Y**, then for every function **f** from the set **Y** to any other set, there is a corresponding function **f ∘ g** from the set **P** to the same set. In other words, every time you create a new function.
|
||||
|
||||
![Functional composition connect](morphism_general.svg)
|
||||
|
||||
@ -259,7 +258,7 @@ Notice that the function is invertible, that is if you flip its arrows you get a
|
||||
|
||||
![Opposite colors](isomorphism_one_one.svg)
|
||||
|
||||
Invertible functions are called *isomorphisms*. When there is an invertible function between two sets we can say that the sets are *isomorphic*. For example, the temperature measured in Celcius, is isomorphic to the temperature, measured in Fahrenheit.
|
||||
Invertible functions are called *isomorphisms*. When there is an invertible function between two sets we can say that the sets are *isomorphic*. For example, the temperature measured in Celcius is isomorphic to the temperature, measured in Fahrenheit.
|
||||
|
||||
More formally, two sets **R** and **G** are isomorphic, or **R ≅ G** if there exist functions **f: G → R** and its reverse **g R → G**, such that **f ∘ g = idR** and **g ∘ f = idG** (notice how the identity function comes in handy).
|
||||
|
||||
@ -272,7 +271,7 @@ For example, we all know that everything is equal to itself. Well, if you look c
|
||||
|
||||
![The identity function](isomorphism_identity.svg)
|
||||
|
||||
Note that an isomorphism between two sets does not imply that their *elements* are similar to one another, as some of the examples might suggest. It rather implies that they have similar *structure*, in other words a function that involves one of the sets, can easily be converted to a function involving the other set.
|
||||
Note that an isomorphism between two sets does not imply that their *elements* are similar to one another, as some of the examples might suggest. It rather implies that they have similar *structure*, in other words, a function that involves one of the sets, can easily be converted to a function involving the other set.
|
||||
|
||||
![The architecture of isomorphism](isomorphism_general.svg)
|
||||
|
||||
@ -294,3 +293,4 @@ Following the logic from the last paragraph, each statement about something that
|
||||
Question: Try to come up with a good example that shows how a statement that demonstrates the isomorphism between singleton sets (I obviously couldn't). Consider that all of people and objects are sharing one and the same universe.
|
||||
|
||||
Task: Think of two singleton sets, and try to pinpoint the relation that they have.
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
This book is a product of my own endeavour of understanding category theory from a more non-mathematical viewpoint - it is just that as I am explaining something, I am understanding it better.
|
||||
|
||||
It is aimed at programmers, as well as anyone else who is interested in this stuff. I am writing it as I learn.
|
||||
|
Loading…
Reference in New Issue
Block a user