Compare commits

...

32 Commits

Author SHA1 Message Date
dependabot[bot]
ca33d3d662
Merge ee82fd3020 into 3ed084c6b8 2024-07-06 11:15:20 +09:00
abuseofnotation
3ed084c6b8
Update FUNDING.yml 2024-06-05 12:30:40 +03:00
Boris Marinov
801c36415f stuff 2024-05-22 21:41:30 +03:00
abuseofnotation
08e2272896
Merge pull request #59 from 414owen/os/few-typo-corrections
fix: Add missing 'is' and 'a' to product/pair explanation
2024-04-25 14:42:22 +03:00
Owen Shepherd
b7e4c46d0c fix: Add missing 'is' and 'a' to product/pair explanation 2024-04-13 17:20:10 +02:00
abuseofnotation
8948e7b97c
Merge pull request #58 from FFFluoride/fffluoride-fix-spag
"Proof read" chapter 0 and 1
2024-03-29 05:51:10 +02:00
FFFluoride
625b10d37a Fixed typo 2024-03-06 19:47:39 +00:00
FFFluoride
a7cdf02b86 Fixed typo and abbreviation 2024-03-06 19:42:52 +00:00
FFFluoride
b505ee14ca Fixed typo and punctuation 2024-03-06 19:29:33 +00:00
FFFluoride
6aec0fb8da Fixed punctuation. More importantly, rewrote a sentence so it makes sense and isn't redundant, I hope you like it. 2024-03-06 19:24:17 +00:00
FFFluoride
b074e79993 Removed redundant comma 2024-03-06 19:15:46 +00:00
FFFluoride
a2812f038d Fixed grammar 2024-03-06 19:10:55 +00:00
FFFluoride
1696d7b188 I had an aneurysm reading that double negative, but maybe that's just a skill issue on my part. Fixed typo aswell. 2024-03-06 19:07:14 +00:00
FFFluoride
2cdb0191a1 merged two sentences to make them more concise and flow a bit better when reading 2024-03-06 18:58:41 +00:00
FFFluoride
618cd79ac2 Removed unnecessary comma 2024-03-06 18:50:58 +00:00
FFFluoride
0a514b0bb8 I feel as if the sentence was essentially repeated twice 2024-03-06 18:42:22 +00:00
FFFluoride
4b472cca84 Consistent plurals and changed things up as I found the (I think) nested hyphens quite jarring. 2024-03-06 18:38:29 +00:00
FFFluoride
74b6e6ba13 This fixes grammar but I changed this sentence, quite a bit and even split it into two. if this isn't what you meant to say I'll change it 2024-03-06 18:28:06 +00:00
FFFluoride
b81fc909d6 Grammar 2024-03-06 18:21:14 +00:00
FFFluoride
242462c074 I read these as pauses, so I added commas. We are already refrencing the word adds nothing here imo 2024-03-05 22:55:06 +00:00
FFFluoride
83d80e4bbf Fixed some more tense and grammar 2024-03-05 22:50:08 +00:00
FFFluoride
0d5d30bdcb The second part is me reordering a semi-broken sentence to make more sense. I'm not too sure about getting rid of the . I'll spare you the lecture but, it's your call if you want to keep that or no. 2024-03-05 22:45:11 +00:00
FFFluoride
4d041790c6 Plural and better word word order (in my opinion) 2024-03-05 22:36:34 +00:00
FFFluoride
87bceefc0d SpAG and saw three clearly related sentences that seperate. This one is honestly detabatable as it isn't strictly wrong and can even be used to make the reader read slower, perhaps to emphasize how important it is they understand that passage. I'll change it if this goes against your intentions 2024-03-05 22:32:33 +00:00
FFFluoride
dd6fe08a6b Concision 2024-03-05 22:22:39 +00:00
FFFluoride
83813d8340 Writing 'Reason' is getting pretty dumb, so I'll just say it instead. The oxford comma here feels clunky, though it's not strictly incorrect. SpAG 2024-03-05 22:17:20 +00:00
FFFluoride
ea93178156 Reason #1: Removing word redunancies. Reason #2: Concision. Reason #3: Less repetetive vocabulary 2024-03-05 22:13:01 +00:00
FFFluoride
eb97d649ac Reason: I think this is what you meant, also that's three 'and's within 8 consecutive words 2024-03-05 22:00:22 +00:00
FFFluoride
74a65722e6 Changed 'It is' to 'It's' I will not be commenting on it the next time I do it. 2024-03-05 21:43:39 +00:00
FFFluoride
64400123c0 Reason #1: We are in the past tense since the word 'would'. Reason #2: Added some question marks to make the reader read this as a question (with an inflection) 2024-03-05 21:42:12 +00:00
FFFluoride
c33189dfa8 Made some grammar and sentence structure changes. To make this easier on myself. Every change (or close together changes) will be a commit. I hope that's not too annoying 2024-03-05 21:27:48 +00:00
dependabot[bot]
ee82fd3020
Bump nokogiri from 1.13.6 to 1.14.3
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.13.6 to 1.14.3.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.13.6...v1.14.3)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-12 06:11:23 +00:00
6 changed files with 47 additions and 49 deletions

2
.github/FUNDING.yml vendored
View File

@ -1,6 +1,6 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: abuseofnotation
patreon: borismarinov
open_collective: # Replace with a single Open Collective username
ko_fi: abuseofnotation

View File

@ -211,7 +211,7 @@ GEM
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.16.0)
nokogiri (1.13.6-x86_64-linux)
nokogiri (1.14.3-x86_64-linux)
racc (~> 1.4)
octokit (4.25.0)
faraday (>= 1, < 3)
@ -219,7 +219,7 @@ GEM
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.7)
racc (1.6.0)
racc (1.6.2)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)

View File

@ -65,16 +65,16 @@ Although many people don't necessarily subscribe to this view of mathematics as
There is nothing wrong with this approach, but mathematics is so much more than solving problems. It was 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 to understand each other. And it is also art and a means of entertainment.
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.
Category theory embodies all these aspects of mathematics, so I think it's very good grounds to writing a book where all of them shine --- a book that isn't based on solving of problems, but exploring concepts and seeking connections between them. A book that is, overall, pretty.
Who is this book for
====
So, who is this book for? Some people would phrase the question as "Who *should* read this book", but if you ask it this way, 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 a solution to many problems (it is, in fact, something much more).
Let's take an example --- many people claim that Einstein's theories of relativity are essential for GPS to work properly, as, due to relativistic effects, the clocks on GPS satellites tick faster than identical clocks on the ground.
Let's take an example --- many people claim that Einstein's theories of relativity are essential for GPSes to work properly. Due to relativistic effects, the clocks on GPS satellites 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 phenomenon in the following way:
They seem to think that if the theory didn't exist, the engineers that developed the GPSes would have faced this phenomenon in the following way:
> Engineer 1: Whoa, the clocks on the satellites are off by X nanoseconds!
>
@ -105,26 +105,26 @@ About category theory
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.
The way we think and talk is based on intuition that develops naturally and is a 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, in what context, etc.)
The way we think and talk is based on intuition that develops naturally and is a 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 meant, although it isn't obvious at all (how are they equal?, in what context?, etc.)
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.
It's in these situations that people often resort to *diagrams* to refine their thoughts. Diagrams (even more than formulas) are ubiquitous in science and mathematics.
Category theory formalizes the concept of diagrams 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 unite various modes of thinking with common terms.
Category theory formalizes the concept of diagrams and their components --- arrows and objects --- to create 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 unite various modes of thinking with 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
===
In this book we will visit various such modes of knowledge and along the way, we would see all other kinds of mathematical objects, viewed through the lens of categories.
In this book we will visit various such modes of knowledge and along the way, see all kinds of mathematical objects, viewed through the lens of categories.
We will start with *set theory* in chapter 1, which is the original way to formalize different mathematical concepts.
We start with *set theory* in chapter 1, which is the original way to formalize different mathematical concepts.
Chapter 2 we will make a (hopefully) gentle transition from sets to *categories* while showing how the two compare and (finally) introducing the definition of category theory.
In the next two chapters, 3 and 4, we jump to two different branches of mathematics and will introduce their main means of abstraction, *groups and orders*, and we will see how they connect to the core category-theoretic concepts that we introduced earlier.
In the next two chapters, 3 and 4, we jump into two different branches of mathematics and introduce their main means of abstraction, *groups and orders*, observing how they connect to the core category-theoretic concepts that we introduced earlier.
Chapter 5 also follows the main formula of the previous two chapters, and gets to the heart of the matter of why category theory is a universal language, by showing its connection with the ancient discipline of *logic*. As in chapters 3 and 4 we start with a crash course in logic itself.
Chapter 5 also follows the main formula of the previous two chapters, getting to the heart of the matter of why category theory is a universal language, by showing its connection with the ancient discipline of *logic*. As in chapters 3 and 4, we start with a crash course in logic itself.
The connection between all these different disciplines is examined in chapter 6, using one of the most interesting category-theoretical concepts --- the concept of a functor.

View File

@ -6,7 +6,7 @@ title: Sets
Sets
===
Let's begin our inquiry by looking at the basic theory of sets. Set theory and category theory share many similarities. We can view category theory as a *generalization* of set theory. That is, it is meant to describe the same thing as set theory (everything?), but to do it in a more abstract manner, one that is more versatile and (hopefully) simpler.
Let's begin our inquiry by looking at the basic theory of sets. Set theory and category theory share many similarities. We can view category theory as a *generalization* of set theory. That is, it's meant to describe the same thing as set theory (everything?), but to do it in a more abstract manner, one that is more versatile and (hopefully) simpler.
In other words, sets are an *example of a category* (the *proto-example*, we might say), and it is useful to have examples.
@ -18,15 +18,15 @@ What is an Abstract Theory
Most scientific and mathematical theories have a specific *domain*, which they are tied to, 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 in order to explain how different *biological species* came to evolve using natural selection, quantum mechanics is a description of how particles behave at a specific scale, etc.
Even most mathematical theories, although not inherently *bound* to a specific domain, like the scientific ones, are often strongly related to one, as differential equations are linked to how events change over time.
Even most mathematical theories, although not inherently *bound* to a specific domain like the scientific ones, are often strongly related to one, as differential equations are linked to how events change over time.
Set theory and category theory are different. They are not created to provide a rigorous explanation of how a particular phenomenon works. Instead they provide a more general framework for explaining all kinds of phenomena. They work less like tools and more like languages for defining tools. Theories that are like that are called *abstract* theories.
Set theory and category theory are different, they are not created to provide a rigorous explanation of how a particular phenomenon works, instead they provide a more general framework for explaining all kinds of phenomena. They work less like tools and more like languages for defining tools. Theories that are like that are called *abstract* theories.
The borders of the two are sometimes blurry, because all theories *use abstraction*, otherwise they would be pretty useless: without abstraction Darwin would have to speak about specific animal species or even individual animals. But theories have core concept that don't refer to anything in particular, but instead are left for people to generalize on. All theories are applicable outside of their domains, but set theory and category theory do not have a domain to begin with.
The borders of the two are sometimes blurry, because all theories *use abstraction*, otherwise they would be pretty useless: without abstraction Darwin would have to speak about specific animal species or even individual animals. But theories have core concepts that don't refer to anything in particular, but are instead left for people to generalize on. All theories are applicable outside of their domains, but set theory and category theory do not have a domain to begin with.
Concrete theories, like the theory of evolution, are composed of concrete concepts. For example, the concept of a *population*, also called a *gene-pool*, refers to a group of individuals that can interbreed. Abstract theories, like set theory, are composed of abstract concepts, like the concept of a set. The concept of a set by itself does not refer to anything. However, we cannot say that it is an empty concept, as there are countless things that can be represented by sets, like, for example, gene pools can be (very aptly) represented by sets of individual animals. And species of animals can too be represented by set &mdash; a set of all populations that can theoretically interbreed.
Concrete theories, like the theory of evolution, are composed of concrete concepts. For example, the concept of a *population*, also called a *gene-pool*, refers to a group of individuals that can interbreed. Abstract theories, like set theory, are composed of abstract concepts, like the concept of a set. The concept of a set by itself does not refer to anything. However, we cannot say that it is an empty concept, as there are countless things that can be represented by sets, for example, gene pools can be (very aptly) represented by sets of individual animals. Animal species can also be represented by sets &mdash; a set of all populations that can theoretically interbreed.
You already see how abstract theories may be useful. Because they are so simple, they can be used as building blocks of many concrete theories. Because they are common, they can be used to unify and compare different concrete theories, by putting these theories in common grounds (this is very characteristic of category theory, as we will see later). Moreover, good (abstract) theories can serve as *mental models* for developing our thoughts.
You've already seen how abstract theories may be useful. Because they are so simple, they can be used as building blocks to many concrete theories. Because they are common, they can be used to unify and compare different concrete theories, by putting these theories in common grounds (this is very characteristic of category theory, as we will see later). Moreover, good (abstract) theories can serve as *mental models* for developing our thoughts.
<!-- comic - brain on category theory -->
@ -48,14 +48,14 @@ Let's construct a set, call it $G$ (as gray) that contains *all* of them as elem
![The set of all balls](../01_set/all.svg)
This example may look overly-simple but in fact it is just as valid as any other one.
This example may look overly-simple, but in fact, it's just as valid as any other.
The key insight that makes the concept useful is the fact that it enables you to reason about several things as if they were one.
Subsets
---
Let's construct one more set. The set of *all balls that are warm color*. Let's call it $Y$ (because in the diagram is colored in **y**ellow).
Let's construct one more set. The set of *all balls that are warm in color*. Let's call it $Y$ (because in the diagram, it's colored in **y**ellow).
![The set of all balls of warm colors](../01_set/subset.svg)
@ -81,7 +81,7 @@ Of course if one is a valid answer, zero can be also. If we want a set of all *b
Because a set is defined only by the items it contains, the empty set is *unique* &mdash; there is no difference between the set that contains zero *balls* and the set that contains zero *numbers*, for instance. Formally, the empty set is marked with the symbol $\varnothing$ (so $B = W = \varnothing$).
The empty set is a special one, for example, it is a subset of every other set or mathematically speaking, $\forall A \to \varnothing \subseteq A$ ($\forall$ means "for all")
The empty set has some special properties, for example, it is a subset of every other set. Mathematically speaking, $\forall A \to \varnothing \subseteq A$ ($\forall$ means "for all")
Functions
===
@ -99,9 +99,9 @@ Here is a function $f$, which converts each ball from the set $R$ to the ball wi
![Opposite colors](../01_set/function_one_one.svg)
This is probably one of the simplest type of functions that exist &mdash; one which encodes a *one-to-one relationship* between the sets &mdash; *one* element from the source is connected to exactly *one* element from the target (and the other way around).
This is probably one of the simplest type of function that exists &mdash; it encodes a *one-to-one relationship* between the sets. That is to say, *one* element from the source is connected to exactly *one* element from the target (and the other way around).
But functions can also express relationships of the type *many-to-one*, where *many* elements from the source might be connected to *one* element from the target (but not the other way around). For example, a function can express a relationship in which several elements from the source set relate to the same element of the target set.
But functions can also express relationships of the type *many-to-one*, where *many* elements from the source might be connected to *one* element from the target (but not the other way around). Below is one such function.
![Function from a bigger set to a smaller one](../01_set/function_big_small.svg)
@ -175,7 +175,7 @@ There is a unique function from any set to any singleton set.
Sets and Functions with numbers
===
All numerical operations can be expressed as functions, acting on the set of (different types of) numbers.
All numerical operations can be expressed as functions acting on the set of (different types of) numbers.
Number sets
---
@ -200,7 +200,7 @@ Overall everything is permitted, as long as you can always provide exactly one r
> Every generalization 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.
> Bertrand Russell, from Introduction to Mathematical Philosophy
Note that most mathematical operations, such as addition, multiplication, etc. require two numbers in order to produce a result. This does not mean that they are not functions. It means that they are just a little more fancy ones. Depending on what we need, we may present those operations as functions from the sets of *tuples* of numbers to the set of numbers, or we may say that they take a number and return a function. More on that later.
Note that most mathematical operations, such as addition, multiplication, etc. require two numbers in order to produce a result. This does not mean that they are not functions, it just means they're a little fancier. Depending on what we need, we may present those operations as functions from the sets of *tuples* of numbers to the set of numbers, or we may say that they take a number and return a function. More on that later.
Sets and Functions in Programming
===
@ -238,11 +238,11 @@ Nowadays, many people feel that mathematical functions are too limiting and hard
Purely-functional programming languages
---
We said that while all mathematical functions are also programming functions, the reverse is not true for *most* programming languages. There are some languages that don't permit non-mathematical functions, and for which this equality holds. They are called *purely-functional* programming languages.
We said that while all mathematical functions are also programming functions, the reverse is not true for *most* programming languages. However, there are some languages that only permit mathematical functions, and for which this equality holds. They are called *purely-functional* programming languages.
A peculiarity in such languages is that they don't support functions that perform operations like rendering stuff on screen, doing I/O, etc. (in this context, such operations are called "side effects".
In purely functional programming languages, such operations are *outsourced* to the language's runtime. Instead of writing functions that directly permform a side effect, for example `console.log('Hello')`, we write functions that return a type that represents that side effect (for example, in Haskell side effects are handled by the `IO` type) and the runtime then executes those functions for us.
In purely functional programming languages, such operations are *outsourced* to the language's runtime. Instead of writing functions that directly perform a side effect, for example `console.log('Hello')`, we write functions that return a type that represents that side effect (for example, in Haskell side effects are handled by the `IO` type) and the runtime then executes those functions for us.
We then link all those functions into a whole program, often by using a thing called *continuation passing style*.
@ -259,7 +259,7 @@ If we apply the first function $g$ to some element from set $Y$, we will get an
![Applying one function after another](../01_set/functions_one_after_another.svg)
We can define a function that is the equivalent to performing the operation described above.
That would be a function such that, if you follow the arrow $h$ for any element of set $Y$ you will get to the same element of the set $G$ as the one you will get if you follow the $g$ and then follow $f$.
That would be a function such that, if you follow the arrow $h$ for any element of set $Y$ you will get to the same element of the set $G$ as the one you will get if you follow both the $g$ and $f$ arrows.
Let us call it $h: Y → G$. We may say that $h$ is the *composition* of $g$ and $f$, or $h = f \circ g$ (notice that the first function is on the right, so it's similar to $b = f(g(a)$).
@ -278,7 +278,7 @@ If we have a function $g: P → Y$ from set $P$ to set $Y$, then for every funct
![Functional composition connect](../01_set/morphism_general.svg)
For example, if we again take the relationship between a person and his mother as a function, with the set of all people in the world as source, and the set of all people that have children as its target, composing this function with other similar functions would give us all relatives on a person's mother side.
For example, if we again take the relationship between a person and his mother as a function with the set of all people in the world as source, and the set of all people that have children as its target, composing this function with other similar functions would give us all relatives on a person's mother side.
Although you might be seeing functional composition for the first time, the intuition behind it is there &mdash; we all know that each person whom our mother is related to is automatically our relative as well &mdash; our mother's father is our grandfather, our mother's partner is our father, etc.
@ -314,11 +314,11 @@ The external diagram is a more appropriate representation of the concept of comp
![Functional composition - general definition](../01_set/functions_compose_general.svg)
If you continue reading this book, you will hear more about diagrams in which all paths are equivalent (they are called *commuting diagrams*, by the way)
If you continue reading this book, you will hear more about diagrams in which all paths are equivalent (they are called *commuting diagrams*, by the way).
At this point you might be worried that I had forgotten that I am supposed to talk about category theory and I am just presenting a bunch of irrelevant concepts. I may indeed do that sometimes, but not right now - the fact that *functional composition* can be presented without even mentioning category theory doesn't stop it from being one of category theory's *most important concepts*.
In fact, we can say (although this is not an official definition) that category theory is the study of things that are *function-like* (we call them *morphisms*) --- ones that have source and target, that can be composed with one another in an associative way, that can be represented by external diagrams etc.
In fact, we can say (although this is not an official definition) that category theory is the study of things that are *function-like* (we call them *morphisms*). They have a source and a target, compose with one another in an associative way, and can be represented by external diagrams.
And there is another way of defining category theory without defining category theory: it is what you get if you replace the concept of equality with the concept of *isomorphism*. We haven't talked about isomorphisms yet, but this is what we will be doing till the end of this chapter.
@ -329,11 +329,11 @@ To explain what isomorphism is, we go back to the examples of the types of relat
![Opposite colors](../01_set/function_one_one.svg)
If we have a one-one-function that connects sets that are of the same size (as is the case here), then this function has the following property: all elements from the target set have exactly one arrow pointing at them. In this case, the function is *invertible*. That is, if you flip the arrows of the function and its source and target, you get another valid function.
If we have a one-to-one-function that connects sets that are of the same size (as is the case here), then this function has the following property: all elements from the target set have exactly one arrow pointing at them. In this case, the function is *invertible*. That is, if you flip the arrows of the function and its source and target, you get another valid function.
![Opposite colors](../01_set/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 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 invertible function that converts the temperature measured in *Celsius* to temperature measured in *Fahrenheit*, and vise versa, we can say that 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).
@ -409,9 +409,9 @@ And in computer science, if we have functions that convert an object of type $A$
Equivalence relations
---
What does it mean for two things to be equivalent? The question sounds quite philosophical, but there is actually is a formal way to answer it, i.e., there is a mathematical concept that captures the concept of equality in a rather elegant way &mdash: the concept of an *equivalence relation*.
What does it mean for two things to be equivalent? The question sounds quite philosophical, but there is actually is a formal way to answer it, i.e., there is a mathematical concept that captures the concept of equality in a rather elegant way &mdash; the concept of an *equivalence relation*.
So what is an equivalence relation? We already know what a relation is --- it is a connection between two sets (an example of which is function). But when is a relation an equivalence relation? Well, according the definition it is when it follows three laws, which correspond to three intuitive ideas about equality. Let's review them.
So what is an equivalence relation? We already know what a relation is --- it is a connection between two sets (an example of which is function). But when is a relation an equivalence relation? Well, according the definition, it's when it follows three laws, which correspond to three intuitive ideas about equality. Let's review them.
Reflexivity
---
@ -491,4 +491,4 @@ To see why, imagine a person (e.g. me), tinkering with some sort of engineering
But things are different if the machine in question is software-based --- due to the ease with which new software components can be rolled out, our design can blur the line that separates some of the components or even do away with the concept of component altogether and make the whole program one giant component (*monolithic design*). Worse, when no ready-made components are available, this approach is actually easier than the component-based approach that we described in the previous paragraph, and so many people use it.
This is bad, as the benefits of monolithic design are mostly short-term --- not being separated to components makes programs harder to reason about, harder to modify (e.g. you cannot replace a faulty component with a new one) and generally more primitive than component-based programs. For this reasons, I think that currently, programmers are losing out by not utilizing the principles of functional composition. In fact, I was so unhappy with the situation that I decided to write a whole book on applied category theory to help people understand the principles of composition better --- it's called Category Theory Illustrated (Oh wait, I am writing that right now, aren't I?)
This is bad, as the benefits of monolithic design are mostly short-term --- not being separated to components makes programs harder to reason about, harder to modify (e.g. you cannot replace a faulty component with a new one) and generally more primitive than component-based programs. For these reasons, I think that currently, programmers are losing out by not utilizing the principles of functional composition. In fact, I was so unhappy with the situation that I decided to write a whole book on applied category theory to help people understand the principles of composition better --- it's called Category Theory Illustrated (Oh wait, I am writing that right now, aren't I?)

View File

@ -75,7 +75,7 @@ In other words, products are extremely important concept, that is vital if you w
Defining products in terms of sets
---
A product, as we said, a set of *ordered* pairs (formally speaking $A \times B ≠ B \times A$). So, to define a product we must define the concept of an ordered pair. So how can we do that? Note that an ordered pair of elements is not just set containing the two elements --- that would just be a *pair*, but not an *ordered pair*).
A product is, as we said, a set of *ordered* pairs (formally speaking $A \times B ≠ B \times A$). So, to define a product we must define the concept of an ordered pair. So how can we do that? Note that an ordered pair of elements is not just a set containing the two elements --- that would just be a *pair*, but not an *ordered pair*).
Rather, an ordered pair is a structure that contains two objects as well as information about which of those objects is the first and which one is second (and in programming, we have the ability to assign names to each member of an object, which accomplishes the same purpose as ordering does for pairs.)

View File

@ -2,16 +2,14 @@
layout: default
title: Types
In the last "category overview" chapter in the book, we will talk about, in my opinion, the most interesting category of all --- the category of *types*.
In the last "category overview" chapter in the book, we will talk about types. This might be disappointing, if you expected to learn about as many *new* categories as possible (for which you don't even suspect that they are categories till the unexpected reveal), as we've been giving examples with the category of types in a given programming language ever since the first chapter, so we already know that they form a category, and *how* they form it. You are also familiar with the Curry-Howard correspondence that connects types and logic.
This might be disappointing, if you expected to learn about as many *new* categories as possible (for which you don't even suspect that they are categories till the unexpected reveal), as we've been giving examples with the category of types in a given programming language ever since the first chapter, so we already know that they form a category, and *how* they form it. You have also heard about the Curry-Howard correspondence, that connects types and logic.
However, types are not just about programming languages --- they are an alternative to sets (and categories) as the foundational language of mathematics. More so, they are as powerful tool as any of those formalisms.
However, you still probably don't know that types are not just about programming languages (and are more than just another category) --- they are an alternative to sets (and categories) as the foundational language of mathematics. More so, they are as powerful tool as any of those formalisms.
Sets, Types and Russell's paradox
===
So, here we are back at sets. Most books about category theory (and mathematics in general) begin with sets. The reason for this is simply because *sets are simple to understand*, at least when we are operating on the conceptual level that is customary for introductory materials --- when we draw a circle around a few things, everyone knows what we are talking about.
So, here we are back at sets. As we discussed at the start of this book, most books about category theory (and mathematics in general) begin with sets. The reason for this (I used to be baffled by it, but now I understand) is simply because *sets are simple to understand*, at least when we are operating on the conceptual level that is customary for introductory materials --- when we draw a circle around a few things, everyone knows what we are talking about.
![Sets](../06_type/sets.svg)
@ -45,7 +43,7 @@ We may deem Russell's paradox unimportant at first, our initial reaction being s
> "Wait, can't we *just* add some rules that say that you cannot draw the set that contains itself?"
This was exactly what the mathematicians Ernst Zermelo and Abraham Fraenkel set out to do (no pun intended), by defining the *ZermeloFraenkel set theory*, or *ZFC* (the *C* at the end is a separate story). ZFC was a success, and it is still in use today, however it compromises one of the best features that sets have, namely their *simplicity*.
This was exactly what the mathematicians Ernst Zermelo and Abraham Fraenkel set out to do (no pun intended), by defining the *ZermeloFraenkel Set Theory*, or *ZFC* (the *C* at the end is a separate story). ZFC was a success, and it is still in use today, however it compromises one of the best features that sets have, namely their *simplicity*.
Why? The original formulation of set theory was based on just one (rather vague) rule/axiom: "Given a property P, there exists a set of all objects that have this property" i.e. any bunch of objects can be put to a set.
@ -66,7 +64,7 @@ Resolving the paradox with type theory
While Zermelo and Fraenkel were working on refining axioms of set theory in order to avert Russell's paradox, Russell himself took a different route and decided to ditch sets altogether, and develop an entirely new mathematical theory that is free of paradoxes by design. He called it *the theory of types* (or *type theory*).
Type theory is not entirely different from set theory, as the concepts of *types* and *terms* are clearly looks reminiscent of the concepts of *sets* and *elements*
Type theory is not at all similar to set theory, but it is at the same time, not entirely different from it, as the concepts of *types* and *terms* are clearly reminiscent of the concepts of *sets* and *elements*
|Theory |Set theory| Type Theory|
|------ | ---------| --------|
@ -84,7 +82,7 @@ In type theory, a term can have only one type. (note that the red ball in the sm
![A type and a subtype](../06_type/type_subtype.svg)
For this reason, types, by definition cannot contain themselves. So this settles Russell's paradox. However, the concept is very weird --- we are basically saying that if you have the type `Human` that contains all humans and the type `Mathematician` that contains all mathematicians, than the mathematician Jencel is a different object than the human Jencel.
Due to this law, types cannot contain themselves. So because of it, Russell's paradox, is entirely avoided. However, the law is very weird --- we are basically saying that if you have the type `Human` that contains all humans and the type `Mathematician` that contains all mathematicians, than the mathematician Jencel is a different object than the human Jencel.
<!--comic(and no, I am not implying that mathematicians aren't human). -->
@ -101,11 +99,11 @@ What are types
So let's set all these things aside (haha, this time it was on purpose) and see how do we define a type theory in its own right.
We say *a* type theory, because (time for a long disclaimer) there are not one, but many different (albeit related) formulations of type theory that are, confusingly, called type *theories* (and less confusingly, *type systems*), such as *Simply-typed lambda calculus* or *Intuitionistic type theory*, so it makes sense to speak about *a* type theory. <!--comic: Dr. Smisloff --- I think they are not confused enough --> At the same time, "type theory" (uncountable) refers to the whole field of study of type theories, just like category theory is the study of categories. Moreover, (take a deep breath) you can sometimes think of the different type systems as "different versions of type theory" and so, when people talk about a given set of features that are common to all type systems, they sometimes use the term "type theory" to refer to any random type system that has these features.
We say *a* type theory, because (time for a long disclaimer) there are not one, but many different (albeit related) formulations of type theory that are, confusingly, called type *theories* (and less confusingly, *type systems*), such as *Simply-typed lambda calculus* or *Intuitionistic type theory*. For this reason, it makes sense to speak about *a* type theory. <!--comic: Dr. Smisloff --- I think they are not confused enough --> At the same time, "type theory" (uncountable) refers to the whole field of study of type theories, just like category theory is the study of categories. And moreover, (take a deep breath) you can sometimes think of the different type systems as "different versions of type theory" and so, when people talk about a given set of features that are common to all type systems, they sometimes use the term "type theory" to refer to any random type system that has these features. But let's get back to our subject (however we want to call it).
But back to our subject (however you call it).
In the last section, we talked about types in the context of set theory and we learned that, unlike set elements, terms can belong to only one type. This is correct, but it is not at all the whole story. In fact, thinking in terms of sets won't get you far as a type theorists --- you have to think in terms of *categories*. So, for this reason, We will start this section with the same piece of advise that I gave you when we went from sets to categories and from classical logic to intuitionistic logic: "forget what you know."
After discovering his paradox, Russell started searching for a new way to define all collections of objects that are *interesting*, without accidentally defining collections that lead us ashtray, (and without having to make up a multitude of additional axioms, a-la ZFC). He devised a system that fits all these criteria, based on a revolutionary new idea... which is basically the same idea that is at the heart of category theory (I don't know why he never got credit for being a category theory pioneer): The *interesting* collections, the ones that we want to talk about in the first place, are the *collections that are the source and target of functions*.
So, after stumbling upon his eponymous paradox (which you don't know about ;)), Russell started searching for a new way to define all collections of objects that are *interesting*, without accidentally defining collections that lead us ashtray, (and without having to make up a multitude of additional axioms, a-la ZFC). He devised a system that fits all these criteria, based on a revolutionary new idea... which is basically the same idea that is at the heart of category theory (I don't know why he never got credit for being a category theory pioneer): The *interesting* collections, the ones that we want to talk about in the first place, are the *collections that are the source and target of functions*.
Building types
===