It looks like you're new here. If you want to get involved, click one of these buttons!

- All Categories 2.3K
- Chat 496
- Study Groups 10
- Epidemiology 5
- Network Theory 2
- Leaf Modeling 1
- Review Sections 9
- MIT 2020: Programming with Categories 52
- MIT 2020: Lectures 21
- MIT 2020: Exercises 25
- MIT 2019: Applied Category Theory 339
- MIT 2019: Lectures 79
- MIT 2019: Exercises 149
- MIT 2019: Chat 50
- UCR ACT Seminar 4
- General 64
- Azimuth Code Project 110
- Statistical methods 2
- Drafts 1
- Math Syntax Demos 15
- Wiki - Latest Changes 2
- Strategy 111
- Azimuth Project 1.1K
- - Spam 1
- News and Information 147
- Azimuth Blog 149
- - Conventions and Policies 21
- - Questions 43
- Azimuth Wiki 707

Options

We've seen that a database schema is just a category \(\mathcal{C}\), and a database built on that schema is just a functor \(F: \mathcal{C} \to \textbf{Set}\). What can we do with this realization?

A lot.

First, we can try replacing \(\textbf{Set}\) with some other category, and see what happens! We get some useful variants. Matthew Doty came up with a nice one last time, and I'd like to expand on it and set it in a larger context.

The category \(\textbf{Set}\) has sets as object and *functions* as morphisms. But functions are just a special case of *relations*.

**Definition.** Given sets \(X\) and \(Y\), a **relation** from \(X\) to \(Y\) is a subset of \(X \times Y\).

For example we could have a relation \(\textrm{FriendOf}\) from the set \(X\) of Germans to the set \(Y\) of Italians. Then \( (x,y) \in \textrm{FriendOf}\) means that \(x\) is a German, \(y\) is an Italian, and \(x\) is a friend of \(y\).

When \(R\) is a relation from \(X\) to \(Y\), people often write \(R : X \nrightarrow Y\). This looks like the notation for functions, but also different, so we don't get mixed up.

There's a good reason for this. Any function \(f : X \to Y\) gives a relation from \(X\) to \(Y\), namely the subset

$$ \{ (x, f(x)) : \; x \in X \} \subseteq X \times Y .$$
Indeed lots of people these days *define* a function from \(X\) to \(Y\) to be a special kind of relation \(R: X \nrightarrow Y\), namely one that is:

**Deterministic:**for any \(x \in X\) there is at most one \(y \in Y\) with \( (x,y) \in R\).**Total:**for any \(x \in X\) there is at least one \(y \in Y\) with \( (x,y) \in R\).

We can compose relations in a way that generalizes how we compose functions:

**Definition.** Given relations \(R : X \to Y\) and \(S : Y \to Z\), define the **composite** relation \( S \circ R : X \to Z \) by

$$ S \circ R = \{ (x,z) : \; \textrm{ there exists } y \in Y \textrm{ such that } (x,y) \in R \textrm{ and } (y,z) \in S \}$$ For example, if we compose the relation

$$ \textrm{FriendOf} : \{\textrm{Germans}\} \nrightarrow \{ \textrm{Italians}\} $$ and the relation

$$ \textrm{ChildOf} : \{\textrm{Italians}\} \nrightarrow \{ \textrm{Austrians}\} $$ we get a relation

$$ \textrm{ChildOf} \circ \textrm{FriendOf}: \{\textrm{Germans}\} \nrightarrow \{ \textrm{Austrians}\} $$ where \( (x,z) \) is in this relation if \(x\) is a German, \(y\) is an Austrian, and \(x\) is a friend of a child of \(z\).

The word "relation" is not accidental: in every culture, people have always spent a lot of time keeping track of who is related to whom, and in what way! So, the following category is built deep into our brains:

**Puzzle 114.** Show that there is a category \(\textbf{Rel}\) where:

- objects are sets;
- a morphism \(R : X \nrightarrow Y\) is a relation from \(X\) to \(Y\);
- relations are composed as described above;
- the identity relation \(1_X : X \nrightarrow X \) is

$$ 1_X = \{ (x,x) : x \in X \} .$$ What do you need to do, to show this? You need to check the laws in the definition of a category. If you don't remember those, punish yourself and then go look them up!

**Puzzle 115.** There is an obvious functor \( i: \textbf{Set} \to \textbf{Rel}\). What is it, why is it a functor, and why do people say this functor makes \(\textbf{Set}\) into a subcategory of \(\textbf{Rel}\)?

Using this idea we can imagine a new kind of database! We'll take our database schema to be a category \(\mathcal{C}\) as before, but now we'll define a database built using this schema to be a functor

$$ F : \mathcal{C} \to \mathbf{Rel} .$$
Now \(F\) maps each object of \(\mathcal{C}\) to a set as before, but it maps each morphism to a *relation* between sets!

For example, we could take \(\mathcal{C}\) to be the free category on this graph:

Then a database will be a functor \(F : \mathcal{C} \to \mathbf{Rel} \) that picks out a set of Germans, a set of Italians, a set of Austrians, a *relation* from Germans to Italians, and a *relation* from Italians to Austrians.

This is good! If we used a functor \(F : \mathcal{C} \to \mathbf{Set} \), we'd be forcing each German to be the friend of *exactly one* Italian, and each Italian to be the child of *exactly one* Austrian! That's because functions are relations that are both deterministic and total.

So, we get more flexibility in our theory of databases if we let other categories take the place of \(\textbf{Set}\). I'll conclude with some puzzles that explore another example.

**Definition.** Given sets \(X\) and \(Y\), a **partial function** \(f : X \nrightarrow Y\) is a relation from \(X\) to \(Y\) that is deterministic but not necessarily total.

**Puzzle 116.** Show that if we compose two relations that are partial functions, the result is a partial function.

Using this we get a category \(\textbf{Par}\) with

- sets as objects,
- partial functions as morphisms,
- composition as just described,
- the usual identity relations as identity morphisms.

Every function is a partial function, and every partial function is a relation, but not conversely! In fact \(\mathbf{Set} \) is a subcategory of \(\mathbf{Par}\), and \(\mathbf{Par}\) is a subcategory of \(\mathbf{Rel}\). (I know I haven't said what a subcategory is, but you can look it up.)

**Puzzle 117.** Start with a graph \(G\) having one node \(\textrm{Person}\) and one edge \(\textrm{BestFriend}\) from that node to itself. This gives a free category \(\mathcal{C} = \mathbf{Free}(G)\). How many functors \(F : \mathcal{C} \to \mathbf{Par}\) are possible if

$$ F(\textrm{Person}) = \{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \} ?$$ What sort of situations do these functors describe? How is this different from Puzzle 111?

**Puzzle 118.** How many functors \(F : \mathcal{C} \to \mathbf{Rel} \) are there? What situations do these describe?

## Comments

We need to check the associativity laws,

\[ (A \circ B ) \circ C = A \circ (B \circ C) \]

for relations,

\[ R \circ S = \lbrace (x,z) \mid \exists y \in Y, (x,y)\in S \land (y,z) \in R \rbrace, \\ S \circ T = \lbrace (w,y) \mid \exists x \in X, (w,x) \in T \land (x,y) \in S \rbrace \\ \]

implies,

\[ R \circ (S\circ T) = \lbrace (w,z) \mid \exists y \in Y, (w,y)\in (S \circ T) \land (y,z) \in R \rbrace, \\ = \lbrace (w,z) \mid \exists y \in Y, (w,y)\in \lbrace (w,y) \mid \exists x \in X, (w,x) \in T \land (x,y) \in S \rbrace \land (y,z) \in R \rbrace \] and \[ (R \circ S) \circ T = \lbrace (w,z) \mid \exists x \in X, (w,x) \in T \land (x,z) \in (R \circ S) \rbrace \\ = \lbrace (w,z) \mid \exists x \in X, (w,x) \in T \land (x,z) \in \lbrace (x,z) \mid \exists y \in Y, (x,y)\in S \land (y,z) \in R \rbrace \rbrace \]

which, as sets, are equal.

and the unital laws are given as, \[ R \circ id_X = \lbrace (x,z) \mid \exists x \in X, (x,x) \in id_X \land (x,y) \in R \rbrace \\ id_Y \circ R = \lbrace (x,z) \mid \exists y \in Y, (x,y) \in R \land (y,y) \in id_Y. \rbrace \]

`>**Puzzle 114.** Show that there is a category \\(\textbf{Rel}\\) where: >1. objects are sets; >2. a morphism \\(R : X \nrightarrow Y\\) is a relation from \\(X\\) to \\(Y\\); >3. relations are composed as described above; >4. the identity relation \\(1_X : X \nrightarrow X \\) is >\\[ 1_X = \\{ (x,x) : x \in X \\} .\\] We need to check the associativity laws, \\[ (A \circ B ) \circ C = A \circ (B \circ C) \\] for relations, \\[ R \circ S = \lbrace (x,z) \mid \exists y \in Y, (x,y)\in S \land (y,z) \in R \rbrace, \\\\ S \circ T = \lbrace (w,y) \mid \exists x \in X, (w,x) \in T \land (x,y) \in S \rbrace \\\\ \\] implies, \\[ R \circ (S\circ T) = \lbrace (w,z) \mid \exists y \in Y, (w,y)\in (S \circ T) \land (y,z) \in R \rbrace, \\\\ = \lbrace (w,z) \mid \exists y \in Y, (w,y)\in \lbrace (w,y) \mid \exists x \in X, (w,x) \in T \land (x,y) \in S \rbrace \land (y,z) \in R \rbrace \\] and \\[ (R \circ S) \circ T = \lbrace (w,z) \mid \exists x \in X, (w,x) \in T \land (x,z) \in (R \circ S) \rbrace \\\\ = \lbrace (w,z) \mid \exists x \in X, (w,x) \in T \land (x,z) \in \lbrace (x,z) \mid \exists y \in Y, (x,y)\in S \land (y,z) \in R \rbrace \rbrace \\] which, as sets, are equal. and the unital laws are given as, \\[ R \circ id_X = \lbrace (x,z) \mid \exists x \in X, (x,x) \in id_X \land (x,y) \in R \rbrace \\\\ id_Y \circ R = \lbrace (x,z) \mid \exists y \in Y, (x,y) \in R \land (y,y) \in id_Y. \rbrace \\]`

Looks great, Keith!

I just added another puzzle, Puzzle 118. The point of these counting puzzles is just to make people think about the concepts involved: one can't count something until one understands what it is!

`Looks great, Keith! I just added another puzzle, Puzzle 118. The point of these counting puzzles is just to make people think about the concepts involved: one can't count something until one understands what it is!`

I'll give it a try.

Also, proving associativity of relationship composition is a mess I hope I don't have to do again soon.

`I'll give it a try. Also, proving associativity of relationship composition is a mess I hope I don't have to do again soon.`

Just to make sure my understanding is correct: A relation need not be deterministic nor total? So there can be zero relations to many relations coming out of \(x \in X\) in the relation \(R: X \nrightarrow Y\)?

`Just to make sure my understanding is correct: A relation need not be deterministic nor total? So there can be zero relations to many relations coming out of \\(x \in X\\) in the relation \\(R: X \nrightarrow Y\\)?`

Michael, right. A relation between \(X\) and \(Y\) is nothing more than a subset of \(X \times Y\). Preorders are a particularly nice kind of relation (an endorelation?) which need not be deterministic. (They have to be total, though, since \(x \le x\).)

`Michael, right. A relation between \\(X\\) and \\(Y\\) is nothing more than a subset of \\(X \times Y\\). Preorders are a particularly nice kind of relation (an endorelation?) which need not be deterministic. (They have to be total, though, since \\(x \le x\\).)`

Hey Jonathan,

As you just noted:

This is pretty much the key to the following puzzle

given that

$$ F(\textrm{Person}) = \{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \}$$

`Hey Jonathan, As you just noted: > A relation between \\(X\\) and \\(Y\\) is nothing more than a subset of \\(X \times Y\\). This is pretty much the key to the following puzzle > **Puzzle 118.** How many functors \\(F : \mathcal{C} \to \mathbf{Rel} \\) are there? given that \[ F(\textrm{Person}) = \\{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \\}\]`

Yep! There are \(4^4 = 256\)

functionsover that set, but \(2^{4 \cdot 4} = 65,536\)relations. (Remember that \(2^X\) is the number of subsets of a set of size \(X\); and there are \(Y \cdot Z\) elements in the product of sets of sizes Y and Z.)`Yep! There are \\(4^4 = 256\\) _functions_ over that set, but \\(2^{4 \cdot 4} = 65,536\\) _relations_. (Remember that \\(2^X\\) is the number of subsets of a set of size \\(X\\); and there are \\(Y \cdot Z\\) elements in the product of sets of sizes Y and Z.)`

Since subsets have cardinality \(2^{\mathrm{card}(X)}\), would the number of relationships \(X \nrightarrow Y\) then be \( 2^{\mathrm{card} (X \times Y)} \)?

`Since subsets have cardinality \\(2^{\mathrm{card}(X)}\\), would the number of relationships \\(X \nrightarrow Y\\) then be \\( 2^{\mathrm{card} (X \times Y)} \\)?`

\(i\) is the functor defined as such.

It does nothing to objects. \[ i(x) = x \]

on functions, \(f: x \to y\), \(i\) sends them to the relation, \[ i(f)(x) = \lbrace (x, f(x)) : \; x \in X \land y \in Y\rbrace \subseteq X \times Y . \]

I'd say \(\mathrm{Set}\) is a subcategory because, in \(\mathrm{Rel}\), relationships are less restrictive than functions in \(\mathrm{Set}\). For one thing, the opposite relationship always exists, while the opposite function maybe not (it may not be total or deterministic).

`>**Puzzle 115.** There is an obvious functor \\( i: \textbf{Set} \to \textbf{Rel}\\). What is it, why is it a functor, and why do people say this functor makes \\(\textbf{Set}\\) into a [subcategory](https://en.wikipedia.org/wiki/Subcategory) of \\(\textbf{Rel}\\)? \\(i\\) is the functor defined as such. It does nothing to objects. \\[ i(x) = x \\] on functions, \\(f: x \to y\\), \\(i\\) sends them to the relation, \\[ i(f)(x) = \lbrace (x, f(x)) : \; x \in X \land y \in Y\rbrace \subseteq X \times Y . \\] I'd say \\(\mathrm{Set}\\) is a subcategory because, in \\(\mathrm{Rel}\\), relationships are less restrictive than functions in \\(\mathrm{Set}\\). For one thing, the opposite relationship always exists, while the opposite function maybe not (it may not be total or deterministic).`

To follow up on this, we presumably have a forgetful (?) functor F from Rel to Set which does nothing to morphisms (provided we're defining functions in the usual way, in which case they're already a subset of the Cartesian product, ergo a relation) or objects. This leads to an inevitable question, given the course so far, although I have no reason to think there's an interesting answer. Namely, does F have an adjoint?

`To follow up on this, we presumably have a forgetful (?) functor F from Rel to Set which does nothing to morphisms (provided we're defining functions in the usual way, in which case they're already a subset of the Cartesian product, ergo a relation) or objects. This leads to an inevitable question, given the course so far, although I have no reason to think there's an interesting answer. Namely, does F have an adjoint?`

Keith wrote:

It's less of a mess if you use more words and fewer symbols. Formal logic does not always make a proof easy to follow!

The interesting thing is how associativity of composition of relations relies on associativity of 'and', and also our ability to pull a 'there exists' through an 'and' in certain circumstances. These features, which hold in the logic of sets, hold not just in \(\mathbf{Set}\) but in any so-called 'regular category'. Another example is the category of vector spaces. So, we can develop a category of 'linear relations' inside the category of vector spaces.

Jonathan wrote:

Yes, so there are 65536 functors \(F: \mathcal{C} \to \mathbf{Rel}\), but only 256 functors \(F: \mathcal{C} \to \mathbf{Set}\), and... how many functors \(F: \mathcal{C} \to \mathbf{Par}\)?

Keith wrote:

Yes. By the way, they're called "relations", not "relationships".

\[ i(x) = x \]

Right.

Close, but you mean this:

On functions, \(i\) sends any function \(f: X \to Y\) to the relation \[ i(f) = \lbrace (x, f(x)) : \; x \in X \rbrace \subseteq X \times Y . \]

`Keith wrote: > Also, proving associativity of relationship composition is a mess I hope I don't have to do again soon. It's less of a mess if you use more words and fewer symbols. Formal logic does not always make a proof easy to follow! The interesting thing is how associativity of composition of relations relies on associativity of 'and', and also our ability to pull a 'there exists' through an 'and' in certain circumstances. These features, which hold in the logic of sets, hold not just in \\(\mathbf{Set}\\) but in any so-called 'regular category'. Another example is the category of vector spaces. So, we can develop a category of 'linear relations' inside the category of vector spaces. Jonathan wrote: > Yep! There are \\(4^4 = 256\\) _functions_ over that set, but \\(2^{4 \cdot 4} = 65,536\\) _relations_. Yes, so there are 65536 functors \\(F: \mathcal{C} \to \mathbf{Rel}\\), but only 256 functors \\(F: \mathcal{C} \to \mathbf{Set}\\), and... how many functors \\(F: \mathcal{C} \to \mathbf{Par}\\)? Keith wrote: > Since subsets have cardinality \\(2^{\mathrm{card}(X)}\\), would the number of relationships \\(X \nrightarrow Y\\) then be \\( 2^{\mathrm{card} (X \times Y)} \\)? Yes. By the way, they're called "relations", not "relationships". > >**Puzzle 115.** There is an obvious functor \\( i: \textbf{Set} \to \textbf{Rel}\\). What is it, why is it a functor, and why do people say this functor makes \\(\textbf{Set}\\) into a [subcategory](https://en.wikipedia.org/wiki/Subcategory) of \\(\textbf{Rel}\\)? > \\(i\\) is the functor defined as such. > It does nothing to objects. \\[ i(x) = x \\] Right. > On functions, \\(f: x \to y\\), \\(i\\) sends them to the relation, > \\[ > i(f)(x) = \lbrace (x, f(x)) : \; x \in X \land y \in Y\rbrace \subseteq X \times Y . > \\] Close, but you mean this: On functions, \\(i\\) sends any function \\(f: X \to Y\\) to the relation \\[ i(f) = \lbrace (x, f(x)) : \; x \in X \rbrace \subseteq X \times Y . \\]`

Actually, since \((x,f(x))\) is a pair, shouldn't it be, \[ i(f) = \lbrace (x, f(x)) : \; x \in X \text{ and } f(x) \in Y \rbrace \subseteq X \times Y ? \]

`>Close, but you mean this: >On functions, \\(i\\) sends any function \\(f: X \to Y\\) to the relation \\[ i(f) = \lbrace (x, f(x)) : \; x \in X \rbrace \subseteq X \times Y . \\] Actually, since \\((x,f(x))\\) is a pair, shouldn't it be, \\[ i(f) = \lbrace (x, f(x)) : \; x \in X \text{ and } f(x) \in Y \rbrace \subseteq X \times Y ? \\]`

Some idle speculation that I should probably think harder about before posting:

Might a functor Set -> Rel be considered a forgetful functor, even though it is the morphisms shedding structure, not the objects?

If so, might it be right adjoint to some functor that freely generates functions from relations?

EDIT: My apologies, this is a duplicate of Reuben's question.

`Some idle speculation that I should probably think harder about before posting: - Might a functor Set -> Rel be considered a forgetful functor, even though it is the morphisms shedding structure, not the objects? - If so, might it be right adjoint to some functor that freely generates functions from relations? EDIT: My apologies, this is a duplicate of Reuben's question.`

Here's another go proving the associativity of

Rel, using the "pull athere existsthrough anand" argument @John mentioned:\(x(R\circ (S\circ T))w\)

\(\iff \exists y \textrm{ st } xRy \textrm{ and } y(S\circ T)w\)

\(\iff \exists y \textrm{ st } xRy \textrm{ and } (\exists z \textrm{ st } ySz \textrm{ and } zTw)\)

\(\iff \exists yz \textrm{ st } xRy \textrm{ and } ySz \textrm{ and } zTw\)

\(\iff \exists z \textrm{ st } (\exists y \textrm{ st } xRy \textrm{ and } ySz) \textrm{ and } zTw\)

\(\iff \exists z \textrm{ st } x(R\circ S)z \textrm{ and } zTw\)

\(\iff x((R\circ S)\circ T)w\)

`Here's another go proving the associativity of **Rel**, using the "pull a *there exists* through an *and*" argument @John mentioned: \\(x(R\circ (S\circ T))w\\) \\(\iff \exists y \textrm{ st } xRy \textrm{ and } y(S\circ T)w\\) \\(\iff \exists y \textrm{ st } xRy \textrm{ and } (\exists z \textrm{ st } ySz \textrm{ and } zTw)\\) \\(\iff \exists yz \textrm{ st } xRy \textrm{ and } ySz \textrm{ and } zTw\\) \\(\iff \exists z \textrm{ st } (\exists y \textrm{ st } xRy \textrm{ and } ySz) \textrm{ and } zTw\\) \\(\iff \exists z \textrm{ st } x(R\circ S)z \textrm{ and } zTw\\) \\(\iff x((R\circ S)\circ T)w\\)`

I don't think the inclusion function

Set\(\rightarrow\)Relshould be considered a forgetful functor – because it doesn't forget anything!`I don't think the inclusion function **Set** \\(\rightarrow\\) **Rel** should be considered a forgetful functor – because it doesn't forget anything!`

Keith wrote:

If \(x \in X\), then we get \(f(x) \in Y\) for free because \(f\) is a function from \(X\) to \(Y\). (This is basically modus ponens at the level of types.)

John wrote:

Any partial function \(X \rightharpoonup Y\) can be rendered as a total function \(X \to Y \mathbin{\dot\cup} \{\bot\}\) with a fresh element \(\bot\) added to the codomain, where we send all unmapped values to \(\bot\). Therefore, there are \(5^4 = 625\) functors \(F: \mathcal{C} \to \mathbf{Par}\).

`Keith wrote: > Actually, since \\((x,f(x))\\) is a pair, shouldn't it be, > \\[ > i(f) = \lbrace (x, f(x)) : \; x \in X \text{ and } f(x) \in Y \rbrace \subseteq X \times Y ? > \\] If \\(x \in X\\), then we get \\(f(x) \in Y\\) for free because \\(f\\) is a function from \\(X\\) to \\(Y\\). (This is basically modus ponens at the level of types.) John wrote: > Yes, so there are 65536 functors \\(F: \mathcal{C} \to \mathbf{Rel}\\), but only 256 functors \\(F: \mathcal{C} \to \mathbf{Set}\\), and... how many functors \\(F: \mathcal{C} \to \mathbf{Par}\\)? Any partial function \\(X \rightharpoonup Y\\) can be rendered as a total function \\(X \to Y \mathbin{\dot\cup} \\{\bot\\}\\) with a fresh element \\(\bot\\) added to the codomain, where we send all unmapped values to \\(\bot\\). Therefore, there are \\(5^4 = 625\\) functors \\(F: \mathcal{C} \to \mathbf{Par}\\).`

This is very nice Anindya.

Thank you!

`> Here's another go proving the associativity of **Rel**, using the "pull a *there exists* through an *and*" argument @John mentioned: > > \\(x(R\circ (S\circ T))w\\) > > \\(\iff \exists y \textrm{ st } xRy \textrm{ and } y(S\circ T)w\\) > > \\(\iff \exists y \textrm{ st } xRy \textrm{ and } (\exists z \textrm{ st } ySz \textrm{ and } zTw)\\) > > \\(\iff \exists yz \textrm{ st } xRy \textrm{ and } ySz \textrm{ and } zTw\\) > > \\(\iff \exists z \textrm{ st } (\exists y \textrm{ st } xRy \textrm{ and } ySz) \textrm{ and } zTw\\) > > \\(\iff \exists z \textrm{ st } x(R\circ S)z \textrm{ and } zTw\\) > > \\(\iff x((R\circ S)\circ T)w\\) This is very nice Anindya. Thank you!`

Regarding adjoints for the inclusion functor \(i : \textbf{Set} \rightarrow \textbf{Rel}\)...

Suppose \(i\) has left adjoint \(j\). Then we would have

\[\textbf{Set}(jX, Y) \cong \textbf{Rel}(X, iY)\]

for all sets \(X\) and \(Y\). Now consider the case when \(Y = \varnothing\). Then \(\textbf{Rel}(X, iY) = \textbf{Rel}(X, \varnothing)\) has exactly one element (the empty relation). So we must have exactly one element in \(\textbf{Set}(jX, \varnothing)\). So we must have \(jX = \varnothing\) for all \(X\). But that would mean \(\textbf{Set}(jX, Y)\) always has exactly one element, while \(\textbf{Rel}(X, iY)\) can clearly have many more.

So \(i\) does not have a left adjoint.

Now define \(P : \textbf{Rel} \rightarrow \textbf{Set}\) to be the map sending every set \(X\) in \(\textbf{Rel}\) to its power set \(PX\) in \(\textbf{Set}\), and every relation \(R\) from \(X\) to \(Y\) in \(\textbf{Rel}\) to the "direct image" function sending a subset of \(X\) to the set of all its \(R\)-relations in \(Y\).

It is easy to check that \(P\) is a functor and that there is a natural isomorphism

\[\textbf{Rel}(iX, Y) \cong \textbf{Set}(X, PY)\]

that sends every relation from \(X\) to \(Y\) to the obvious function from \(X\) to \(PY\).

So \(P\) is a right adjoint to \(i\). The unit of the adjunction is the singleton function sending \(x \in X\) to \(\{x\} \in PX\). The counit is the "backwards membership" relation from \(PY\) to \(Y\) that relates a subset of \(Y\) to its members.

`Regarding adjoints for the inclusion functor \\(i : \textbf{Set} \rightarrow \textbf{Rel}\\)... Suppose \\(i\\) has left adjoint \\(j\\). Then we would have \\[\textbf{Set}(jX, Y) \cong \textbf{Rel}(X, iY)\\] for all sets \\(X\\) and \\(Y\\). Now consider the case when \\(Y = \varnothing\\). Then \\(\textbf{Rel}(X, iY) = \textbf{Rel}(X, \varnothing)\\) has exactly one element (the empty relation). So we must have exactly one element in \\(\textbf{Set}(jX, \varnothing)\\). So we must have \\(jX = \varnothing\\) for all \\(X\\). But that would mean \\(\textbf{Set}(jX, Y)\\) always has exactly one element, while \\(\textbf{Rel}(X, iY)\\) can clearly have many more. So \\(i\\) does not have a left adjoint. Now define \\(P : \textbf{Rel} \rightarrow \textbf{Set}\\) to be the map sending every set \\(X\\) in \\(\textbf{Rel}\\) to its power set \\(PX\\) in \\(\textbf{Set}\\), and every relation \\(R\\) from \\(X\\) to \\(Y\\) in \\(\textbf{Rel}\\) to the "direct image" function sending a subset of \\(X\\) to the set of all its \\(R\\)-relations in \\(Y\\). It is easy to check that \\(P\\) is a functor and that there is a natural isomorphism \\[\textbf{Rel}(iX, Y) \cong \textbf{Set}(X, PY)\\] that sends every relation from \\(X\\) to \\(Y\\) to the obvious function from \\(X\\) to \\(PY\\). So \\(P\\) is a right adjoint to \\(i\\). The unit of the adjunction is the singleton function sending \\(x \in X\\) to \\(\\{x\\} \in PX\\). The counit is the "backwards membership" relation from \\(PY\\) to \\(Y\\) that relates a subset of \\(Y\\) to its members.`

Hey I have a favor to ask, could we write such that as s.t. or | writing it as st is probably fine mathematically because two letter variables are so rare but it really throws me down the garden path so to speak.

`Hey I have a favor to ask, could we write such that as s.t. or | writing it as st is probably fine mathematically because two letter variables are so rare but it really throws me down the garden path so to speak.`

Anindya wrote:

Thanks! Very nice! This is really the same as Keith's argument, but by using more words and fewer symbols you can afford to put in more steps, which lets examine the logic in more detail.

Examining the logic in fine-grained detail is worthwhile if we want to

generalizethis proof. We're looking at relations between sets, but one could also look at linear relations between vector spaces, or many other generalizations living in many other categories. People have figured out exactly which categories this works for. They are called 'regular categories'.Inside any regular category, a small fragment of classical logic applies - just enough to work with relations. It's called 'regular logic', and it's mainly about

there existsandand.Wikipedia has a somewhat crappy explanation that's still worth a look:

The main bad thing about this Wikipedia article is that it doesn't list the rules of regular logic. Those can be found in the first volume of Johnstone's

Elephant.One of these rules is associativity of

and, but that step is skipped in your argument because it's so obvious. We could put it in:\(\exists y \textrm{ st } xRy \textrm{ and } \Big[ \exists z \textrm{ st } ySz \textrm{ and } zTw \Big]\)

\(\iff \exists z \textrm{ st } \exists y \textrm{ st } \Big[ xRy \textrm{ and } \big( ySz \textrm{ and } zTw \big)\Big] \)

\(\iff \exists z \textrm{ st } \exists y \textrm{ st } \Big[\big( xRy \textrm{ and } ySz \big) \textrm{ and } zTw \Big] \)

\(\iff \exists z \textrm{ st } \Big[ x(R\circ S)z \textrm{ and } zTw \Big]\)

However,

andis associative because binary meets are associative whenever they exist - in any poset. So this is not very interesting.Much more interesting is how we are pushing the existential quantifier \(\exists\) through an

and. One of the more interesting rules of regular logic lets us do this!There is a way to state this rule in terms of category theory....

`<img width = "150" src = "http://math.ucr.edu/home/baez/mathematical/7_sketches/warning_sign.jpg"> Anindya wrote: > Here's another go proving the associativity of **Rel**, using the "pull a *there exists* through an *and*" argument John mentioned: > > \\(x(R\circ (S\circ T))w\\) > > \\(\iff \exists y \textrm{ st } xRy \textrm{ and } y(S\circ T)w\\) > > \\(\iff \exists y \textrm{ st } xRy \textrm{ and } (\exists z \textrm{ st } ySz \textrm{ and } zTw)\\) > > \\(\iff \exists yz \textrm{ st } xRy \textrm{ and } ySz \textrm{ and } zTw\\) > > \\(\iff \exists z \textrm{ st } (\exists y \textrm{ st } xRy \textrm{ and } ySz) \textrm{ and } zTw\\) > > \\(\iff \exists z \textrm{ st } x(R\circ S)z \textrm{ and } zTw\\) > > \\(\iff x((R\circ S)\circ T)w\\) Thanks! Very nice! This is really the same as Keith's argument, but by using more words and fewer symbols you can afford to put in more steps, which lets examine the logic in more detail. Examining the logic in fine-grained detail is worthwhile if we want to *generalize* this proof. We're looking at relations between sets, but one could also look at linear relations between vector spaces, or many other generalizations living in many other categories. People have figured out exactly which categories this works for. They are called ['regular categories'](https://en.wikipedia.org/wiki/Regular_category). Inside any regular category, a small fragment of classical logic applies - just enough to work with relations. It's called 'regular logic', and it's mainly about _there exists_ and _and_. Wikipedia has a somewhat crappy explanation that's still worth a look: * Wikipedia, [Regular logic and regular categories](https://en.wikipedia.org/wiki/Regular_category#Regular_logic_and_regular_categories). The main bad thing about this Wikipedia article is that it doesn't list the rules of regular logic. Those can be found in the first volume of Johnstone's _Elephant_. One of these rules is associativity of *and*, but that step is skipped in your argument because it's so obvious. We could put it in: \\(\exists y \textrm{ st } xRy \textrm{ and } \Big[ \exists z \textrm{ st } ySz \textrm{ and } zTw \Big]\\) \\(\iff \exists z \textrm{ st } \exists y \textrm{ st } \Big[ xRy \textrm{ and } \big( ySz \textrm{ and } zTw \big)\Big] \\) \\(\iff \exists z \textrm{ st } \exists y \textrm{ st } \Big[\big( xRy \textrm{ and } ySz \big) \textrm{ and } zTw \Big] \\) \\(\iff \exists z \textrm{ st } \Big[ x(R\circ S)z \textrm{ and } zTw \Big]\\) However, *and* is associative because binary meets are associative whenever they exist - in any poset. So this is not very interesting. Much more interesting is how we are pushing the existential quantifier \\(\exists\\) through an *and*. One of the more interesting rules of regular logic lets us do this! There is a way to state this rule in terms of category theory....`

Jonathan - yes, so the answer to Puzzle 117 is 625. Matthew pointed this out already back here, but I thought it would be good to see it here!

The trick you and he are using is to note that the category of sets and partial relations is equivalent to the category of

pointed sets. These are sets with a distinguished element, called 'undefined'. The morphisms in the category of pointed sets, calledbased maps, are functions that preserve this distinguished element. Wikipedia quotes someone as saying:`Jonathan - yes, so the answer to Puzzle 117 is 625. Matthew pointed this out already [back here](https://forum.azimuthproject.org/discussion/comment/19050/#Comment_19050), but I thought it would be good to see it here! The trick you and he are using is to note that the category of sets and partial relations is equivalent to the category of [**pointed sets**](https://en.wikipedia.org/wiki/Pointed_set). These are sets with a distinguished element, called 'undefined'. The morphisms in the category of pointed sets, called **based maps**, are functions that preserve this distinguished element. Wikipedia quotes someone as saying: > This formal completion of sets and partial maps by adding 'improper', 'infinite' elements was reinvented many times, in particular, in topology (one-point compactification) and in theoretical computer science.`

Can we combine \(\mathbf{Rel}\) and \(\mathbf{Par}\) to get something like, \(\mathbf{ParRel}\) where the objects are sets and the morphisms are

partial relations?`Can we combine \\(\mathbf{Rel}\\) and \\(\mathbf{Par}\\) to get something like, \\(\mathbf{ParRel}\\) where the objects are sets and the morphisms are *partial relations*?`

Also, if the cardinality or size of a relation, \[R= X \nrightarrow Y \\ \mathrm{card}(R) = 2^{\mathrm{card}(X\times Y)}.\]

when composing relations, is the cardinality of the composition,

\[ \begin{align} R= X \nrightarrow Y, \\ S= Y \nrightarrow Z, \\ (S\circ R)= X \nrightarrow Z, \\ \mathrm{card}(S\circ R)=2^{\mathrm{card}(X\times Y)}\cdot2^{\mathrm{card}(Y\times Z)} \\ =2^{\mathrm{card}(X\times Y)+\mathrm{card}(Y\times Z)} \\ =2^{\mathrm{card}(Y)\times\mathrm{card}(X \cup Z)}? \end{align} \]

Edit: That would actually make sense since the composition is \[ \Big[ \exists y \textrm{ st } xRy \textrm{ and } ySz \Big] \] where, the \(2^{\mathrm{card}(Y)\times\cdots}\) terms corresponds to the \(\lbrace \exists y \textrm{ st } \cdots \rbrace \) part, and \(2^{\cdots\times \mathrm{card}(X\cup Z)} \) corresponds to the \(\lbrace \cdots\textrm{ st } xRy \textrm{ and } ySz \rbrace \) part.

Edit edit: apparently I thought \((a \times b) + (a \times c) = a + (b \times c)\), instead of the proper distributive property \((a \times b) + (a \times c) = a \times (b + c)\).

`Also, if the cardinality or size of a relation, \\[R= X \nrightarrow Y \\\\ \mathrm{card}(R) = 2^{\mathrm{card}(X\times Y)}.\\] when composing relations, is the cardinality of the composition, \\[ \begin{align} R= X \nrightarrow Y, \\\\ S= Y \nrightarrow Z, \\\\ (S\circ R)= X \nrightarrow Z, \\\\ \mathrm{card}(S\circ R)=2^{\mathrm{card}(X\times Y)}\cdot2^{\mathrm{card}(Y\times Z)} \\\\ =2^{\mathrm{card}(X\times Y)+\mathrm{card}(Y\times Z)} \\\\ =2^{\mathrm{card}(Y)\times\mathrm{card}(X \cup Z)}? \end{align} \\] Edit: That would actually make sense since the composition is \\[ \Big[ \exists y \textrm{ st } xRy \textrm{ and } ySz \Big] \\] where, the \\(2^{\mathrm{card}(Y)\times\cdots}\\) terms corresponds to the \\(\lbrace \exists y \textrm{ st } \cdots \rbrace \\) part, and \\(2^{\cdots\times \mathrm{card}(X\cup Z)} \\) corresponds to the \\(\lbrace \cdots\textrm{ st } xRy \textrm{ and } ySz \rbrace \\) part. Edit edit: apparently I thought \\((a \times b) + (a \times c) = a + (b \times c)\\), instead of the proper distributive property \\((a \times b) + (a \times c) = a \times (b + c)\\).`

Not really: relations are already by default partial. But we can do some other things.

Remember:

A relation \(R : X \nrightarrow Y\) is

deterministicif for any \(x \in X\) there is at most one \(y \in Y\) with \( (x,y) \in R\).A relation \(R : X \nrightarrow Y\) is

totalif for any \(x \in X\) there is at least one \(y \in Y\) with \( (x,y) \in R\).'Partial' just means 'not necessarily total', so 'partial relations' are just relations.

A function is a deterministic total relation. We can try leaving out one of these conditions:

Puzzle.Is there a category \(\mathbf{Det}\) where the objects are sets and the morphisms are deterministic relations, with the usual composition of relations? Prove or disprove this.Puzzle.If the answer to the previous puzzle is yes, and \(\mathcal{C}\) is the category in this lecture's puzzles, how many functors \(F : \mathcal{C} \to \mathbf{Det}\) are there with$$ F(\textrm{Person}) = \{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \} ?$$

Puzzle.Is there a category \(\mathbf{Tot}\) where the objects are sets and the morphisms are total relations, with the usual composition of relations? Prove or disprove this.Puzzle.If the answer to the previous puzzle is yes, and \(\mathcal{C}\) is the category in this lecture's puzzles, how many functors \(F : \mathcal{C} \to \mathbf{Tot}\) are there with$$ F(\textrm{Person}) = \{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \} ?$$ There's a lot more to say, too! I don't want to exhaust everyone, but we can also turn things around as follows:

A relation \(R : X \nrightarrow Y\) is

codeterministicif for any \(y \in Y\) there is at most one \(x \in X\) with \( (x,y) \in R\).A relation \(R : X \nrightarrow Y\) is

cototalif for any \(y \in Y\) there is at least one \(x \in X\) with \( (x,y) \in R\).Remember, a function is a deterministic total relation. We can try stacking on these extra properties:

Puzzle.What do we call a function if it is codeterministic?Puzzle.What do we call a function if it is cototal?Puzzle.What do we call a function if it is codeterministic and cototal?There are famous names for these kinds of functions!

`Not really: relations are already by default partial. But we can do some other things. Remember: 1. A relation \\(R : X \nrightarrow Y\\) is **deterministic** if for any \\(x \in X\\) there is at most one \\(y \in Y\\) with \\( (x,y) \in R\\). 2. A relation \\(R : X \nrightarrow Y\\) is **total** if for any \\(x \in X\\) there is at least one \\(y \in Y\\) with \\( (x,y) \in R\\). 'Partial' just means 'not necessarily total', so 'partial relations' are just relations. A function is a deterministic total relation. We can try leaving out one of these conditions: **Puzzle.** Is there a category \\(\mathbf{Det}\\) where the objects are sets and the morphisms are deterministic relations, with the usual composition of relations? Prove or disprove this. **Puzzle.** If the answer to the previous puzzle is yes, and \\(\mathcal{C}\\) is the category in this lecture's puzzles, how many functors \\(F : \mathcal{C} \to \mathbf{Det}\\) are there with \[ F(\textrm{Person}) = \\{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \\} ?\] **Puzzle.** Is there a category \\(\mathbf{Tot}\\) where the objects are sets and the morphisms are total relations, with the usual composition of relations? Prove or disprove this. **Puzzle.** If the answer to the previous puzzle is yes, and \\(\mathcal{C}\\) is the category in this lecture's puzzles, how many functors \\(F : \mathcal{C} \to \mathbf{Tot}\\) are there with \[ F(\textrm{Person}) = \\{ \textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan} \\} ?\] There's a lot more to say, too! I don't want to exhaust everyone, but we can also turn things around as follows: 1. A relation \\(R : X \nrightarrow Y\\) is **codeterministic** if for any \\(y \in Y\\) there is at most one \\(x \in X\\) with \\( (x,y) \in R\\). 2. A relation \\(R : X \nrightarrow Y\\) is **cototal** if for any \\(y \in Y\\) there is at least one \\(x \in X\\) with \\( (x,y) \in R\\). Remember, a function is a deterministic total relation. We can try stacking on these extra properties: **Puzzle.** What do we call a function if it is codeterministic? **Puzzle.** What do we call a function if it is cototal? **Puzzle.** What do we call a function if it is codeterministic and cototal? There are famous names for these kinds of functions!`

Keith wrote:

Level slip!

If \(R\) is a relation from \(X\) to \(Y\), its cardinality is at most \(\mathrm{card}(X\times Y)\). Its cardinality can hardly ever be as big as \(2^{\mathrm{card}(X\times Y)}\). The number \(2^{\mathrm{card}(X\times Y)}\) is the cardinality of the

set of all relationsfrom \(X\) to \(Y\).So, you're mixing up

a relation from \(X\) to \(Y\)andthe set of all relations from \(X\) to \(Y\).This is called a "level slip" because you're mixing up a specific thing with the collection of all such things. In other words: mixing up an entity and its container!

You made another level slip a while ago, when you hoped that an enriched functor was a special case of base change. Enriched functors go from one \(\mathcal{V}\)-category to another. Base change goes from the category of all \(\mathcal{V}\)-categories to the category of all \(\mathcal{W}\)-categories! Again, it's about entities versus their containers.

Level slips are very common when learning category theory! So, they're nothing to be ashamed of. But learning how to detect and avoid them is really important.

It's great that you're making level slips publicly. Everyone makes them. But making them publicly gives me a chance to explain the

conceptof level slip.`Keith wrote: > \\[R= X \nrightarrow Y \\\\ \mathrm{card}(R) = 2^{\mathrm{card}(X\times Y)}.\\] Level slip! If \\(R\\) is a relation from \\(X\\) to \\(Y\\), its cardinality is at most \\(\mathrm{card}(X\times Y)\\). Its cardinality can hardly ever be as big as \\(2^{\mathrm{card}(X\times Y)}\\). The number \\(2^{\mathrm{card}(X\times Y)}\\) is the cardinality of the _set of all relations_ from \\(X\\) to \\(Y\\). So, you're mixing up _a relation from \\(X\\) to \\(Y\\)_ and _the set of all relations from \\(X\\) to \\(Y\\)_. This is called a "level slip" because you're mixing up a specific thing with the collection of all such things. In other words: mixing up an entity and its container! You made another level slip a while ago, when you hoped that an enriched functor was a special case of base change. Enriched functors go from one \\(\mathcal{V}\\)-category to another. Base change goes from the category of all \\(\mathcal{V}\\)-categories to the category of all \\(\mathcal{W}\\)-categories! Again, it's about entities versus their containers. Level slips are very common when learning category theory! So, they're nothing to be ashamed of. But learning how to detect and avoid them is really important. It's great that you're making level slips publicly. Everyone makes them. But making them publicly gives me a chance to explain the _concept_ of level slip.`

These are

injectiveorone-to-one.These are

surjectiveoronto.These are

bijections!`> **Puzzle.** What do we call a function if it is codeterministic? These are *injective* or *one-to-one*. > **Puzzle.** What do we call a function if it is cototal? These are *surjective* or *onto*. > **Puzzle.** What do we call a function if it is codeterministic and cototal? These are *bijections*!`

John Baez wrote:

Well, at least I defined the cardinality of the composition of

somecategory. Does this category have a proper name?If mathematics was to have a motto, it would be something akin to the game

Dwarf Fortress's "Losing is fun," something like, "Making mistakes is fun!"The idea being, in maths you

willmake mistakes, a lot, so you mind as well find some sort of enjoyment out of it.`John Baez wrote: >\\(\cdots\\) >If \\(R\\) is a relation from \\(X\\) to \\(Y\\), its cardinality is at most \\(\mathrm{card}(X\times Y)\\). Its cardinality can hardly ever be as big as \\(2^{\mathrm{card}(X\times Y)}\\). The number \\(2^{\mathrm{card}(X\times Y)}\\) is the cardinality of the _set of all relations_ from \\(X\\) to \\(Y\\). >So, you're mixing up _a relation from \\(X\\) to \\(Y\\)_ and _the set of all relations from \\(X\\) to \\(Y\\)_. >\\(\cdots\\) Well, at least I defined the cardinality of the composition of *some* category. Does this category have a proper name? >It's great that you're making level slips publicly. Everyone makes them. But making them publicly gives me a chance to explain the concept of level slip. If mathematics was to have a motto, it would be something akin to the game *Dwarf Fortress*'s "Losing is fun," something like, "Making mistakes is fun!" The idea being, in maths you *will* make mistakes, a lot, so you mind as well find some sort of enjoyment out of it.`

Best as I can tell, a deterministic relation is exactly what we mean by a "partial function," so this is just the category \(\mathbf{Par}\) again.

I say yes: we just have to check that the identity relation is total (it is: it's a function) and that total relations are closed under composition: so let us assume that \(R: X\nrightarrow Y\) and \(S : Y\nrightarrow Z\) are total relations, then so is \(S\circ R : X\nrightarrow Z\). Indeed, given \(x\in X\), choose \(y\in Y\) such that \(x R y\); such a \(y\) exists because \(R\) is total. Then using \(y\) we get at least one \(z\in Z\) such that \(y S z\). Then \(x (S\circ R)z\), so in particular such a \(z\) exists, so \(S\circ R\) is total, as desired.

I get 50625, but I don't want to spoil the reasoning if someone else wants to give it a try. (There isn't some kind of markdown spoiler syntax we could use, is there?)

`> **Puzzle.** Is there a category \\(\mathbf{Det}\\) where the objects are sets and the morphisms are deterministic relations, with the usual composition of relations? Prove or disprove this. Best as I can tell, a deterministic relation is exactly what we mean by a "partial function," so this is just the category \\(\mathbf{Par}\\) again. > **Puzzle.** Is there a category \\(\mathbf{Tot}\\) where the objects are sets and the morphisms are total relations, with the usual composition of relations? Prove or disprove this. I say yes: we just have to check that the identity relation is total (it is: it's a function) and that total relations are closed under composition: so let us assume that \\(R: X\nrightarrow Y\\) and \\(S : Y\nrightarrow Z\\) are total relations, then so is \\(S\circ R : X\nrightarrow Z\\). Indeed, given \\(x\in X\\), choose \\(y\in Y\\) such that \\(x R y\\); such a \\(y\\) exists because \\(R\\) is total. Then using \\(y\\) we get at least one \\(z\in Z\\) such that \\(y S z\\). Then \\(x (S\circ R)z\\), so in particular such a \\(z\\) exists, so \\(S\circ R\\) is total, as desired. > **Puzzle.** If the answer to the previous puzzle is yes, and \\(\mathcal{C}\\) is the category in this lecture's puzzles, how many functors \\(F : \mathcal{C} \to \mathbf{Tot}\\) are there with \\( F(\textrm{Person}) = \\) {\\(\textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan}\\)} ? I get 50625, but I don't want to spoil the reasoning if someone else wants to give it a try. (There isn't some kind of markdown spoiler syntax we could use, is there?)`

Hey Owen,

I get the same number.

I don’t think this forum supports spoiler text, sadly. But perhaps I am not doing the right thing...

`Hey Owen, I get the same number. I don’t think this forum supports spoiler text, sadly. But perhaps I am not doing the right thing...`

Keith wrote:

What does "the cardinality of the composition" mean? I can understand "the cardinality of the set of objects" and "the cardinality of the set of morphisms", but composition is a function, and I don't know what the cardinality of a function would be.

`Keith wrote: > Well, at least I defined the cardinality of the composition of _some_ category. What does "the cardinality of the composition" mean? I can understand "the cardinality of the set of objects" and "the cardinality of the set of morphisms", but composition is a function, and I don't know what the cardinality of a function would be.`

Matthew wrote:

Yes! So, everyone knows about relations that are:

deterministic - these are

partial functionsdeterministic and total - these are

functionsdeterministic, total and codeterministic - these are

one-to-one functionsorinjectionsdeterministic, total and cototal - these are

onto functionsorsurjectionsdeterministic, total, cototal and codeterministic - these are

one-to-one and onto functionsorbijections.However, other combinations of these adjectives are less familiar. There's a total of \(2^4\) possibilities, and each one gives an interesting category!

But some of these 16 categories are the opposites of others. For example, a codeterministic and cototal relation is a

cofunction, but a cofunction \(f: X \nrightarrow Y\) is just a function \(g: Y \to X\).I listed 5 categories above, none being the opposite of any other. A 6th the category of total relations, \(\mathbf{Tot}\), discussed in an earlier puzzle.

Puzzle.How many more of these 16 categories are left to discuss, not counting opposites? What are they?`Matthew wrote: > **Puzzle.** What do we call a function if it is codeterministic? > These are *injective* or *one-to-one*. > **Puzzle.** What do we call a function if it is cototal? > These are *surjective* or *onto*. > **Puzzle.** What do we call a function if it is codeterministic and cototal? > These are *bijections*! Yes! So, everyone knows about relations that are: 1. deterministic - these are **partial functions** 2. deterministic and total - these are **functions** 3. deterministic, total and codeterministic - these are **one-to-one functions** or **injections** 4. deterministic, total and cototal - these are **onto functions** or **surjections** 5. deterministic, total, cototal and codeterministic - these are **one-to-one and onto functions** or **bijections**. However, other combinations of these adjectives are less familiar. There's a total of \\(2^4\\) possibilities, and each one gives an interesting category! But some of these 16 categories are the opposites of others. For example, a codeterministic and cototal relation is a **cofunction**, but a cofunction \\(f: X \nrightarrow Y\\) is just a function \\(g: Y \to X\\). I listed 5 categories above, none being the opposite of any other. A 6th the category of total relations, \\(\mathbf{Tot}\\), discussed in an earlier puzzle. **Puzzle.** How many more of these 16 categories are left to discuss, not counting opposites? What are they?`

John Baez wrote:

Fun! First, how many categories on this list are their own opposites? I count four: All relations; total and cototal relations; deterministic and codeterministic relations; and total, cototal, deterministic, and codeterministic relations. That means the remaining 16 - 4 = 12 categories are

nottheir own opposites, so if we aren't counting opposites separately, we should list 6 of those, plus the four that are their own opposites, for 10 categories total. That's four more than the six you listed above.Here are the remaining four:

`John Baez wrote: > **Puzzle.** How many more of these 16 categories are left to discuss, not counting opposites? What are they? Fun! First, how many categories on this list are their own opposites? I count four: All relations; total and cototal relations; deterministic and codeterministic relations; and total, cototal, deterministic, and codeterministic relations. That means the remaining 16 - 4 = 12 categories are *not* their own opposites, so if we aren't counting opposites separately, we should list 6 of those, plus the four that are their own opposites, for 10 categories total. That's four more than the six you listed above. Here are the remaining four: - (7.) All relations - (8.) Total and cototal relations (Is there a clever way of thinking about these? I'm picturing them as bipartite graphs with no isolated vertices, but that's not very compositiony.) - (9.) Deterministic and codeterministic relations ("partial bijections"?) - (10.) Deterministic and cototal relations ("surjective partial functions"?)`

Owen - great!

"Relations" was my trick question; of course we

havetalked about those before.Deterministic and codeterministic relations are indeed sometimes called 'partial bijections', and they're pretty reasonable things to study. A

partial bijectionfrom \(X\) to \(Y\) consists of subsets \(A \subseteq X, B \subseteq Y\) and a bijection from \(A\) to \(B\).For example, in cultures without same-sex marriage or polygamy, marriage might define a partial bijection between the set of men and the set of women. Maybe you can think of loopholes I haven't listed! But you get the idea: every man has at most one wife, every woman has at most one husband.

Surjective partial functions are less popular but certainly easy to understand.

Total and cototal relations are nicely symmetrical but I'm not thinking of many examples off-hand. Well, here's one: I guess every man has at least one female relative and every woman has at least one male relative!

`Owen - great! "Relations" was my trick question; of course we _have_ talked about those before. Deterministic and codeterministic relations are indeed sometimes called 'partial bijections', and they're pretty reasonable things to study. A **partial bijection** from \\(X\\) to \\(Y\\) consists of subsets \\(A \subseteq X, B \subseteq Y\\) and a bijection from \\(A\\) to \\(B\\). For example, in cultures without same-sex marriage or polygamy, marriage might define a partial bijection between the set of men and the set of women. Maybe you can think of loopholes I haven't listed! But you get the idea: every man has at most one wife, every woman has at most one husband. Surjective partial functions are less popular but certainly easy to understand. Total and cototal relations are nicely symmetrical but I'm not thinking of many examples off-hand. Well, here's one: I guess every man has at least one female relative and every woman has at least one male relative!`

Owen wrote:

I don't know of any.

Let's see if I can do this puzzle... I didn't know the answer when I made it up.

A total relation from a 4-element set to itself must relate each of the 4 elements to

at least oneof the 4 elements. So, for each of the 4 elements we must choose a nonempty subset from a 4-element set. The number of such subsets is \(2^4 - 1 = 15\), since there are \(2^4\) subsets of a 4-element set but one is empty. So, we have 15 choices for each of our 4 elements, for a total of \(15^4\). I know that \(15 \times 15 = 225\), and squaring \(225\) gives \(50625\) - I'm killing time, so I did that calculation on paper!`Owen wrote: > > **Puzzle.** If the answer to the previous puzzle is yes, and \\(\mathcal{C}\\) is the category in this lecture's puzzles, how many functors \\(F : \mathcal{C} \to \mathbf{Tot}\\) are there with \\( F(\textrm{Person}) = \\) {\\(\textrm{Anna}, \textrm{Jordan}, \textrm{Lisa}, \textrm{Ryan}\\)} ? > I get 50625, but I don't want to spoil the reasoning if someone else wants to give it a try. (There isn't some kind of markdown spoiler syntax we could use, is there?) I don't know of any. Let's see if I can do this puzzle... I didn't know the answer when I made it up. A total relation from a 4-element set to itself must relate each of the 4 elements to _at least one_ of the 4 elements. So, for each of the 4 elements we must choose a nonempty subset from a 4-element set. The number of such subsets is \\(2^4 - 1 = 15\\), since there are \\(2^4\\) subsets of a 4-element set but one is empty. So, we have 15 choices for each of our 4 elements, for a total of \\(15^4\\). I know that \\(15 \times 15 = 225\\), and squaring \\(225\\) gives \\(50625\\) - I'm killing time, so I did that calculation on paper!`

So a total relation is secretly a function \(t: X \to \left (\mathcal{P}(Y) \setminus \lbrace \varnothing \rbrace \right ) \) in \(\mathbf{Set}\)?

`So a total relation is secretly a function \\(t: X \to \left (\mathcal{P}(Y) \setminus \lbrace \varnothing \rbrace \right ) \\) in \\(\mathbf{Set}\\)?`

By the way, do \(\mathbf{Rel}\), \(\mathbf{Par}\), \(\mathbf{Inj}\), \(\mathbf{Surj}\), \(\mathbf{Bij}\) \(\mathbf{ParSurj}\), \(\mathbf{ParBij}\), etc., form a preorder or even category with a preording/morphisms between them?

`By the way, do \\(\mathbf{Rel}\\), \\(\mathbf{Par}\\), \\(\mathbf{Inj}\\), \\(\mathbf{Surj}\\), \\(\mathbf{Bij}\\) \\(\mathbf{ParSurj}\\), \\(\mathbf{ParBij}\\), etc., form a preorder or even category with a preording/morphisms between them?`

Keith wrote:

Yes! Good observation!

More fundamentally, a relation from \(X\) to \(Y\) is secretly a function \(t: X \to P(Y) \). People summarize this by saying that \(\mathbf{Rel}\) is the 'Kleisli category of the power set monad'. Maybe we'll get to that jargon someday, but Haskell programmers should like it already.

Similarly, a partial function from \(X\) to \(Y\) is secretly a function \(t : X \to Y \sqcup \lbrace \textrm{undefined} \rbrace \). People summarize this by saying that \(\mathbf{Par}\) is the 'Kleisli category' of the monad that sends \(Y\) to \(Y \sqcup \lbrace \textrm{undefined} \rbrace \). I think programmers call this the maybe monad... maybe.

So, there's a general pattern at work here, and Kleisli categories of monads explain this pattern.

There must be some monad that sends \(Y\) to \(P(Y) \setminus \lbrace \varnothing\rbrace \). We could call it the 'nonempty power set' monad.

`Keith wrote: > So a total relation is secretly a function \\(t: X \to P(Y) \setminus \lbrace \varnothing\rbrace \\) in \\(\mathbf{Set}\\)? Yes! Good observation! More fundamentally, a relation from \\(X\\) to \\(Y\\) is secretly a function \\(t: X \to P(Y) \\). People summarize this by saying that \\(\mathbf{Rel}\\) is the 'Kleisli category of the power set monad'. Maybe we'll get to that jargon someday, but Haskell programmers should like it already. Similarly, a partial function from \\(X\\) to \\(Y\\) is secretly a function \\(t : X \to Y \sqcup \lbrace \textrm{undefined} \rbrace \\). People summarize this by saying that \\(\mathbf{Par}\\) is the 'Kleisli category' of the monad that sends \\(Y\\) to \\(Y \sqcup \lbrace \textrm{undefined} \rbrace \\). I think programmers call this the [maybe monad](https://en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad)... maybe. So, there's a general pattern at work here, and [Kleisli categories of monads](https://en.wikipedia.org/wiki/Kleisli_category) explain this pattern. There must be some monad that sends \\(Y\\) to \\(P(Y) \setminus \lbrace \varnothing\rbrace \\). We could call it the 'nonempty power set' monad.`

Keith wrote:

Yes, there's a precise concept of subcategory (click the link), which matches your intuitive one I hope. For any category \(\mathcal{X}\) there's a poset of all its subcategories, where we say \(\mathcal{C} \le \mathcal{D}\) if \(\mathcal{C} \) is a subcategory of \( \mathcal{D}\).

All 16 categories we're talking about are subcategories of \(\mathbf{Rel}\). Some of the them are subcategories of others. So, we get an interesting poset containing just these 16 categories.

Puzzle.What is the Hasse diagram of this poset?`Keith wrote: > By the way, do \\(\mathbf{Rel}\\), \\(\mathbf{Par}\\), \\(\mathbf{Inj}\\), \\(\mathbf{Surj}\\), \\(\mathbf{Bij}\\), \\(\mathbf{ParSurj}\\), \\(\mathbf{ParBij}\\), etc., form a preorder or even category with a preording/morphisms between them? Yes, there's a precise concept of [subcategory](https://en.wikipedia.org/wiki/Subcategory#Formal_definition) (click the link), which matches your intuitive one I hope. For any category \\(\mathcal{X}\\) there's a poset of all its subcategories, where we say \\(\mathcal{C} \le \mathcal{D}\\) if \\(\mathcal{C} \\) is a subcategory of \\( \mathcal{D}\\). All 16 categories we're talking about are subcategories of \\(\mathbf{Rel}\\). Some of the them are subcategories of others. So, we get an interesting poset containing just these 16 categories. **Puzzle.** What is the Hasse diagram of this poset?`

The computer scientists in here would probably love you if you did, and if I recall, doubly so since the double power set monad corresponds to continuation semantics, which are notoriously hard to understand.

`>More fundamentally, a relation from \\(X\\) to \\(Y\\) is secretly a function \\(t: X \to P(Y) \\). People summarize this by saying that \\(\mathbf{Rel}\\) is the 'Kleisli category of the power set monad'. Maybe we'll get to that jargon someday, but Haskell programmers should like it already. The computer scientists in here would probably love you if you did, and if I recall, doubly so since the double power set monad corresponds to continuation semantics, which are notoriously hard to understand.`

An interesting side note:

If you take the notion of group, and enrich it in a \(\mathrm{Par}\) instead of \(\mathbf{Set}\), you get something I'll call a

partial group.For instance, \(\langle \mathbb{Z}, \times, x^{-1}, 0 \rangle \) isn't a group, because \(0^{-1}\) is undefined. Is is however a partial group, because \(0^{-1}\) is undefined (where "undefined" is the partial element}.

In fact, there is a whole field of partial algebra.

`An interesting side note: If you take the notion of group, and enrich it in a \\(\mathrm{Par}\\) instead of \\(\mathbf{Set}\\), you get something I'll call a **partial group**. For instance, \\(\langle \mathbb{Z}, \times, x^{-1}, 0 \rangle \\) isn't a group, because \\(0^{-1}\\) is undefined. Is is however a partial group, because \\(0^{-1}\\) is undefined (where "undefined" is the partial element}. In fact, there is a whole field of [partial algebra](https://en.wikipedia.org/wiki/Partial_algebra).`

Well sets are a bit badly behaved computationlaly but non empty lists are indeed a monad. Losing the empty list hurts though, as it's usable both as an absorbing error and as a backtracking error.

Hmm. A deterministic and co-total function is our old friend a (labled) partition.

`Well sets are a bit badly behaved computationlaly but non empty lists are indeed a monad. Losing the empty list hurts though, as it's usable both as an absorbing error and as a backtracking error. Hmm. A deterministic and co-total function is our old friend a (labled) partition.`

Edit: After careful analysis, I see now that I cannot use Giorgidze's construction to make a power set monad.Well, there is George Giorgidze's trick: https://hackage.haskell.org/package/set-monad

If you look under the hood, he's using a sort of

Free Monadpattern (Oleg Kiselyov has a nice discussion on his website (2015) regard Free Monads):This works of course for

finite setsand gets around the`fromList :: Ord a => [a] -> Data.Set.Set a`

type class dependency.But it would be nice if we could make a monad for

infinite sets...Infinite sets in set theory are primitive.

However, in Higher Order Logic they are not. Here's how John Harrison defines infinite sets in HOL Light:

Sets, for HOL Light, are just predicates. Isabelle/HOL is similar.

Coq.Sets.Ensemblesin Coq are also the same.So a naïve approach, following John Harrison, would be to define the power set monad as follows:

Of course, we fall on our face when try to do

`instance Monad (Pow a) where`

because`return`

is impossible to define correctly.But we can hack around this...

Puzzle MD.Define a power set monad`Pow`

in Haskell using George Giorgidze's trick. Show it also instances`MonadPlus`

.`**Edit: After careful analysis, I see now that I cannot use Giorgidze's construction to make a power set monad.** > Well sets are a bit badly behaved computationally but non empty lists are indeed a monad. Losing the empty list hurts though, as it's usable both as an absorbing error and as a backtracking error. Well, there is George Giorgidze's trick: https://hackage.haskell.org/package/set-monad If you look under the hood, he's using a sort of *Free Monad* pattern (Oleg Kiselyov has a nice discussion on [his website (2015)](http://okmij.org/ftp/Computation/free-monad.html) regard Free Monads): <pre> -- From https://hackage.haskell.org/package/set-monad-0.2.0.0/docs/src/Data-Set-Monad.html#Set data Set a where Prim :: (Ord a) => S.Set a -> Set a Return :: a -> Set a Bind :: Set a -> (a -> Set b) -> Set b Zero :: Set a Plus :: Set a -> Set a -> Set a run :: (Ord a) => Set a -> S.Set a run (Prim s) = s run (Return a) = S.singleton a run (Zero) = S.empty run (Plus ma mb) = run ma `S.union` run mb run (Bind (Prim s) f) = S.foldl' S.union S.empty (S.map (run . f) s) run (Bind (Return a) f) = run (f a) run (Bind Zero _) = S.empty run (Bind (Plus (Prim s) ma) f) = run (Bind (Prim (s `S.union` run ma)) f) run (Bind (Plus ma (Prim s)) f) = run (Bind (Prim (run ma `S.union` s)) f) run (Bind (Plus (Return a) ma) f) = run (Plus (f a) (Bind ma f)) run (Bind (Plus ma (Return a)) f) = run (Plus (Bind ma f) (f a)) run (Bind (Plus Zero ma) f) = run (Bind ma f) run (Bind (Plus ma Zero) f) = run (Bind ma f) run (Bind (Plus (Plus ma mb) mc) f) = run (Bind (Plus ma (Plus mb mc)) f) run (Bind (Plus ma mb) f) = run (Plus (Bind ma f) (Bind mb f)) run (Bind (Bind ma f) g) = run (Bind ma (\a -> Bind (f a) g)) instance F.Functor Set where fmap = liftM instance A.Applicative Set where pure = return (<*>) = ap instance A.Alternative Set where empty = Zero (<|>) = Plus instance Monad Set where return = Return (>>=) = Bind instance MonadPlus Set where mzero = Zero mplus = Plus </pre> This works of course for *finite sets* and gets around the `fromList :: Ord a => [a] -> Data.Set.Set a` type class dependency. But it would be nice if we could make a monad for *infinite sets*... Infinite sets in set theory are primitive. However, in Higher Order Logic they are not. Here's how John Harrison defines infinite sets in HOL Light: <pre> (* From: https://github.com/jrh13/hol-light/blob/master/sets.ml#L33 *) (* ------------------------------------------------------------------------- *) (* Set membership. *) (* ------------------------------------------------------------------------- *) let IN = new_definition `!P:A->bool. !x. x IN P <=> P x`;; </pre> Sets, for HOL Light, are just predicates. Isabelle/HOL is similar. [*Coq.Sets.Ensembles*](https://coq.inria.fr/library/Coq.Sets.Ensembles.html) in Coq are also the same. So a naïve approach, following John Harrison, would be to define the power set monad as follows: <pre> newtype Pow a = Pow { unPow :: a -> Bool } </pre> Of course, we fall on our face when try to do `instance Monad (Pow a) where` because `return` is impossible to define correctly. But we can hack around this... **Puzzle MD.** Define a power set monad `Pow` in Haskell using George Giorgidze's trick. Show it also instances `MonadPlus`.`

I can give a partial answer to this, and let someone else work out the other bits.

First, everything is a subcategory of \(\mathbf{Rel} \), next we know that injections, surjections, and bijections are specialized kinds of functions, so we therefore already have,

\[ (\mathbf{Inj},\mathbf{Surj},\mathbf{Bij}) \subseteq \mathbf{Set}, \]

we also know that bijections are both surjections and injections,

\[ \mathbf{Bij}\subseteq (\mathbf{Inj},\mathbf{Surj}). \]

Using the same reasoning, we can see that the partial versions of relations are preordered, \[ (\mathbf{ParInj},\mathbf{ParSurj},\mathbf{ParBij}) \subseteq \mathbf{Par}, \]

and likewise,

\[ \mathbf{ParBij}\subseteq (\mathbf{ParInj},\mathbf{ParSurj}). \]

Also, we know that all the partial versions of relations contain the standard versions,

\[ \mathbf{Inj}\subseteq\mathbf{ParInj},\mathbf{Surj}\subseteq\mathbf{ParSurj},\\ \mathbf{Bij}\subseteq\mathbf{ParBij}, \mathbf{Set} \subseteq \mathbf{Par}. \]

`>**Puzzle.** What is the Hasse diagram of this poset? I can give a partial answer to this, and let someone else work out the other bits. First, everything is a subcategory of \\(\mathbf{Rel} \\), next we know that injections, surjections, and bijections are specialized kinds of functions, so we therefore already have, \\[ (\mathbf{Inj},\mathbf{Surj},\mathbf{Bij}) \subseteq \mathbf{Set}, \\] we also know that bijections are both surjections and injections, \\[ \mathbf{Bij}\subseteq (\mathbf{Inj},\mathbf{Surj}). \\] Using the same reasoning, we can see that the partial versions of relations are preordered, \\[ (\mathbf{ParInj},\mathbf{ParSurj},\mathbf{ParBij}) \subseteq \mathbf{Par}, \\] and likewise, \\[ \mathbf{ParBij}\subseteq (\mathbf{ParInj},\mathbf{ParSurj}). \\] Also, we know that all the partial versions of relations contain the standard versions, \\[ \mathbf{Inj}\subseteq\mathbf{ParInj},\mathbf{Surj}\subseteq\mathbf{ParSurj},\\\\ \mathbf{Bij}\subseteq\mathbf{ParBij}, \mathbf{Set} \subseteq \mathbf{Par}. \\]`

I decided to read the nlab to see if they might have other relations, and then came across this snippet,

https://ncatlab.org/nlab/show/Inj

My reaction to finding out that \(\mathcal{P}S \cong \mathbf{Inj} / S\) looked something along the lines of:

That implies that functors \(\mathcal{C} \to \mathbf{Inj} / S\) are something like a "being a subobject of, given the context \(\mathcal{C}\)" relation on \(S\).

Also, functors \(S \to \mathbf{Inj} / S \) are something like an "is a subset of" relation, since \(S\) is the only "context".

Edit: Actually, no, under currying, these should be the same as \(\lbrace \texttt{true} \rbrace \to 2^{S \times S}\), which are I believe are subsets of relations on \(S\), not subsets of \(S\).

Edit: OH NEAT! My intuition was correct, the partitions of a set \(S\) that we were studying are given by the co-slice category \(S / \mathbf{Surj}\).

https://ncatlab.org/nlab/show/partition

So then, \(\mathbf{Part}(S) \cong S / \mathbf{Surj}\).

Partitions are kind of like a sort of dual of subsets.

(Also, someone should make an nlab page for the category \(\mathbf{Surj}\).)

`I decided to read the nlab to see if they might have other relations, and then came across this snippet, > For a set \\(S\\), its power set \\((\mathcal{P} S \\) or \\(2^S)\\) is the slice category \\(\mathbf{Inj} / S\\) which has objects that are injections to \\(S\\) and morphisms that are injections of injections that form commuting triangles. \\(2^S\\) is a quasitopos because it is a Heyting algebra. https://ncatlab.org/nlab/show/Inj My reaction to finding out that \\(\mathcal{P}S \cong \mathbf{Inj} / S\\) looked something along the lines of: <img src="http://i0.kym-cdn.com/entries/icons/original/000/000/567/Massimo.jpg"> That implies that functors \\(\mathcal{C} \to \mathbf{Inj} / S\\) are something like a "being a subobject of, given the context \\(\mathcal{C}\\)" relation on \\(S\\). Also, functors \\(S \to \mathbf{Inj} / S \\) are something like an "is a subset of" relation, since \\(S\\) is the only "context". Edit: Actually, no, under currying, these should be the same as \\(\lbrace \texttt{true} \rbrace \to 2^{S \times S}\\), which are I believe are subsets of relations on \\(S\\), not subsets of \\(S\\). Edit: OH NEAT! My intuition was correct, the partitions of a set \\(S\\) that we were studying are given by the co-slice category \\(S / \mathbf{Surj}\\). https://ncatlab.org/nlab/show/partition So then, \\(\mathbf{Part}(S) \cong S / \mathbf{Surj}\\). Partitions are kind of like a sort of dual of subsets. (Also, someone should make an nlab page for the category \\(\mathbf{Surj}\\).)`

In actual data modeling sometimes one sees in fact functors \(\mathcal{C} \to \mathbf{Rel}\). There is an old-fashioned notation from Peter Chen that exhibits this (see here), despite old it seems useful in categorical contexts. It's called an entity-relationship model. Entities (boxes) are objects of \(\mathcal{C}\), and diamonds are the morphisms. There is an inessential difference between entities and their atributes (beans). But the interesting thing is that this notation allows one to express m-to-n relatioships that need the \(\mathbf{Rel}\) image of the functor.

This is in the modeling side. In the practical side, in relational databases, generally speaking, where relations are expressed by foreign keys, functional dependencies n-to-1 substitute arbitrary n-to-m relationships, and they are better described talking about \(\mathcal{C} \to \mathbf{Par}\). Crow's foot or the very similar UML data model are the more directly related modeling pictures.

To model m-to-n relationships for a real DB engine as in the previous paragraph, one adds mediating entities this way: \(Italians \leftarrow ItalianGermanFriendship \to Germans\), with \(ItalianGermanFriendship := Italians \times Germans\), and arrows partial functions in \(\mathbf{Par}\), defined as projections but only when there's an acutal friendship between two of each country (a span in \(\mathbf{Par}\)). Similarly for 3-rol o n-ary relationships, but perhaps we need some next chapter to see what's going on with the instance functor in that case.

If instead of classic relational databases one speaks of Berners-Leenian triplet stores, of semantic web kind, the \(\mathcal{C} \to \mathbf{Rel}\) picture regains realism.

EDIT: While \(\mathcal{C}\) comes from a directed graph, Chen notation is undirected. I think this is because in \(\mathbf{Rel}\) one wants to have different relations for one relation and its converse (the transposed boolean matrix), but in a Chen picture that doesn't care and both relations are seen as expressing the same in different ways.

`In actual data modeling sometimes one sees in fact functors \\(\mathcal{C} \to \mathbf{Rel}\\). There is an old-fashioned notation from Peter Chen that exhibits this (see [here](https://creately.com/blog/diagrams/er-diagrams-tutorial)), despite old it seems useful in categorical contexts. It's called an entity-relationship model. Entities (boxes) are objects of \\(\mathcal{C}\\), and diamonds are the morphisms. There is an inessential difference between entities and their atributes (beans). But the interesting thing is that this notation allows one to express m-to-n relatioships that need the \\(\mathbf{Rel}\\) image of the functor. This is in the modeling side. In the practical side, in relational databases, generally speaking, where relations are expressed by foreign keys, functional dependencies n-to-1 substitute arbitrary n-to-m relationships, and they are better described talking about \\(\mathcal{C} \to \mathbf{Par}\\). Crow's foot or the very similar UML data model are the more directly related modeling [pictures](https://www.microsoft.com/en-us/microsoft-365/blog/2012/10/24/database-notations-tap-the-full-power-of-visio). To model m-to-n relationships for a real DB engine as in the previous paragraph, one adds mediating entities this way: \\(Italians \leftarrow ItalianGermanFriendship \to Germans\\), with \\(ItalianGermanFriendship := Italians \times Germans\\), and arrows partial functions in \\(\mathbf{Par}\\), defined as projections but only when there's an acutal friendship between two of each country (a [span](https://ncatlab.org/nlab/show/span) in \\(\mathbf{Par}\\)). Similarly for 3-rol o n-ary relationships, but perhaps we need some next chapter to see what's going on with the instance functor in that case. If instead of classic relational databases one speaks of Berners-Leenian triplet stores, of semantic web kind, the \\(\mathcal{C} \to \mathbf{Rel}\\) picture regains realism. EDIT: While \\(\mathcal{C}\\) comes from a directed graph, Chen notation is undirected. I think this is because in \\(\mathbf{Rel}\\) one wants to have different relations for one relation and its converse (the transposed boolean matrix), but in a Chen picture that doesn't care and both relations are seen as expressing the same in different ways.`

Christopher wrote:

Yes! But all functions are deterministic, so we can just call this a co-total function... and the usual term is "surjection" or "onto function".

For those not in the know: any surjection \(f: S \to L\) gives a labeled partition of \(S\), where \(L\) is the set of labels and the part of the partition with label \(\ell \in L\) is the set of elements \( \lbrace s \in S : \; f(s) = \ell \rbrace \).

`Christopher wrote: > Hmm. A deterministic and co-total function is our old friend a (labeled) partition. Yes! But all functions are deterministic, so we can just call this a co-total function... and the usual term is "surjection" or "onto function". For those not in the know: any surjection \\(f: S \to L\\) gives a labeled partition of \\(S\\), where \\(L\\) is the set of labels and the part of the partition with label \\(\ell \in L\\) is the set of elements \\( \lbrace s \in S : \; f(s) = \ell \rbrace \\).`

The puzzle above gave interested me to program some functions that give pictures of random relations over the weekend,

Edit: I'd like to be able to compose relations horizontally and vertically sometime in the future.

`The puzzle above gave interested me to program some functions that give pictures of random relations over the weekend, <img src="https://i.imgur.com/QvWiUDn.png"> <img src="https://i.imgur.com/ESwqBOm.png"> <img src="https://i.imgur.com/zFnH4VN.png"> <img src="https://i.imgur.com/WiuyZYR.png"> <img src="https://i.imgur.com/WMwHSls.png"> <img src="https://i.imgur.com/CpPnePX.png"> <img src="https://imgur.com/pN5Sus9.png"> Edit: I'd like to be able to compose relations horizontally and vertically sometime in the future.`

I think one tensors relations, instead of vertically composing.

`I think one tensors relations, instead of vertically composing.`

Maybe i shouldn't ask here, because these are probably way past the scope of this class but i have a couple of questions:

So you can use a labeled partition to talk about what things are made up of. If we want to both talk about how the outer things are connected, and talk about the internal structure of those things, and the inner structure of the connections, does a surjective functor work? Or do you also need more structure?

Also can we replace the "ambient" category of functors? Like a functor is a collection of various functions(satisfying some equations), can we have one that is instead a collection of relations, or even of abstract morphisms in some category.

`Maybe i shouldn't ask here, because these are probably way past the scope of this class but i have a couple of questions: So you can use a labeled partition to talk about what things are made up of. If we want to both talk about how the outer things are connected, and talk about the internal structure of those things, and the inner structure of the connections, does a surjective functor work? Or do you also need more structure? ---- Also can we replace the "ambient" category of functors? Like a functor is a collection of various functions(satisfying some equations), can we have one that is instead a collection of relations, or even of abstract morphisms in some category.`

Keith, I don't think your "random surjections" are surjections. Every element of the target should be hit by an arrow, but 0, 3, and 1 are each missed at various times in your examples.

`Keith, I don't think your "random surjections" are surjections. Every element of the target should be hit by an arrow, but 0, 3, and 1 are each missed at various times in your examples.`