
Computational Category Theory in Python III: Monoids, Groups, and Preorders - EvgeniyZh
http://www.philipzucker.com/computational-category-theory-in-python-3-monoids-groups-and-preorders/
======
lr4444lr
Can someone explain to me what Category theory actually contributes to
mathematics beyond the contents of abstract algebra, graph theory, and set
theory? Because every interesting result I've seen just looks like it comes
from those other branches with some different terminology. Does it actually
lead to any unique or synergistic results that the others fail to produce with
their own axioma?

~~~
askthereception
It's more helpful to view category theory as a language.

Most undergraduates learn mathematics in the language of sets. If they're
doing algebra, then the underlying structures of their groups, rings, etc. are
always sets. Same for topology and logic (e.g. classical model theory). An
extreme example of this set-theoretic thinking is defining the real numbers in
terms of Dedekind cuts.

Category theory, very slowly, changes this perspective. If you study this for
years, you will come to realise there is more to mathematics than sets. And
your way of thinking will shift. You will learn to ask different questions.
For example, instead of defining things in terms of their underlying set
(often breaking symmetries), you will ask 'does it have a universal property?'
and so on. Note, there are still tons of reasons to use sets / ZFC, even when
working with categories mostly. But I do not want to get into that and it's
irrelevant for the point I'm trying to make.

Final note: the 'language of sets', i.e. the language of undergraduate
mathematics, is very different from set theory. 'Set theory' is like the
language talking about itself. The same goes for pure category theory.

~~~
jacobolus
Set theory was developed to make analysis “rigorous” by the standards of 19th
century mathematicians, who were probing the edge cases of the more intuitive
(or maybe handwavey) assumptions from the 17th–18th century. Here’s Rudin to
explain:
[https://www.youtube.com/watch?v=hBcWRZMP6xs](https://www.youtube.com/watch?v=hBcWRZMP6xs)

In the 20th century it became trendy to (a) try to base _everything_ on set
theory, (b) write mathematics in a very dry and formal style, taking
inspiration from the Bourbaki project.

My impression is that undergraduates are taught in the language of sets partly
because it is serviceable for describing the subjects they are trying to learn
(esp. analysis) but also more importantly because mid-20th century
mathematicians who set up the curriculum we are still using wanted to
thoroughly teach (indoctrinate?) undergraduates the trendy style of the time.

Personally I think it has been a mixed bag; the style is a big turn-off to
many people, and ends up chasing people out of mathematics who could otherwise
make valuable contributions. The people who remain seem to mostly like it okay
though. YMMV.

~~~
spekcular
I have some problems with this comment.

First, why the scare quotes around "rigorous"? Set theory literally did make
the foundations of analysis more rigorous.

Second of all, we don't use set theory because it's "trendy" or because we
want to "indoctrinate" undergraduates, we use it because it's the best known
foundation for mathematics. If there was something less complicated or
annoying that worked, we'd use that instead. But as far as we know, there
isn't, and there are good reasons to believe we won't find something better.

------
chestervonwinch
I suggest to the author that they rephrase the title to something like
"...Theory in Python Part 3..." to make it clear that this is the third
installment in a series, not specific to Python version 3.

~~~
pansa2
Yes. I was thinking, “I’ve never seen Python 3 written as Python III before”.

------
yowlingcat
Not a bad attempt at all, but it doesn't showcase how expressive things could
be. What would be really cool (and arguably Pythonic) could would be to use
Python's operator overloading to what these abstract entities would look like,
in the same way that the the builtin `set` is used.

------
philzook
Hey, author here! Neato! I'm on HN!

~~~
carapace
I haven't read all the way through yet but this seems pretty great. Some rough
edges, sure, but it's accessible, fairly comprehensive, and concise.

Have you seen "Multi-Level Languages are Generalized Arrows" by Adam Megacz?
[https://arxiv.org/abs/1007.2885](https://arxiv.org/abs/1007.2885)

~~~
philzook
Thanks! I haven't seen this one before. I'll check it out!

------
heavenlyblue
Ok, the basic question: what is dom and cod and why does this article spend
the time explaining the basic concepts but never gives a definition of the
only obviously unknown concept?

~~~
philzook
Sorry, this is the third part of a series. I think I said what those were in
the first part but I'm not sure

dom and cod are the domain and codomain of a morphism. They are functions that
given a morphism will return the object at the head or tail of the morphism.

I don't think that these articles are a very good self contained explanation
of category theory. At the moment, I've been aiming at a supplement written in
concrete python to something more thorough.

~~~
tom_mellior
More generally, I think all the naming could be improved. Why not write out
"domain" and "codomain"? Why abbreviate "identity" as "idd", is that standard
anywhere? Why use "mplus" and "mzero"? The latter is as in Haskell, I believe,
but there they must do it that way because they can't overload the
identifiers. Inside Python classes you don't have that restriction.

~~~
philzook
A good point. If my goal is educational (and it 2/3 is), these stupid short
names are a huge oversight. I honestly didn't think about it much.

I think I started from known Haskell names, some conventions that I may have
absorbed from catlab.jl and other places, and some unthoughtful accidents. I
really really wanted id to be the identity, but I'm pretty sure it's a python
keyword. I added a d and vowed to never speak of it again. Ever written a
program about schools and had to use the variable Klass?

I don't feel too bad about mplus and mzero. It's still pretty clear that they
are something like plus and zero, but the m gives you pause. And it should,
since in one case mplus is in fact multiplication.

If this was rolled out into a library maybe I'd have both long and short
names? I'd never want a library to have only long names for really common
things. cod and dom don't actually give me a seconds pause. I like them having
the same length too. Makes code prettier and easier to read. I also intend to
replace some things with operators which would be even more inscrutable to a
newcomer. @ has to be compose for example (to mimic numpy).

~~~
tom_mellior
> I really really wanted id to be the identity, but I'm pretty sure it's a
> python keyword.

It's a built-in function, but you can overload it within a scope you control
without problems:

    
    
        >>> id
        <built-in function id>
        >>> id = 7
        >>> id
        7
    

> And it should, since in one case mplus is in fact multiplication.

Good point! I take this part back.

As for having identifiers the same length, I know the urge, but usually find
the superficial "elegance" it's not worth it.

------
dr_kiszonka
(I realize that I am probably too late to get an answer.)

Besides Category Theory, what other topics are worth reading about to broaden
one's CS background? I write a lot of code without formal CS training so I was
hoping to expose myself to interesting, preferably "mind-blowing" topics
without having to take a course or go through the whole SICP.

~~~
philzook
Author here. I don't recommend category theory. There are lower hanging more
mind blowing fruit.

I'm having a hard time thinking about a blog posts worth of content that is
mind blowing. Mind blows tend to take more investment than that.

I'd recommend checking out an algorithms course
[https://ocw.mit.edu/courses/electrical-engineering-and-
compu...](https://ocw.mit.edu/courses/electrical-engineering-and-computer-
science/6-006-introduction-to-algorithms-fall-2011/) This one is very good.
Has free videos.

I'd recommend giving functional programming a try. I'm an FP fiend. I found
SICP tough going though.

I'd recommend giving low level programming a try.

Learning prolog is pretty mind blowing
[http://www.learnprolognow.org/](http://www.learnprolognow.org/)

Digital Circuitry is pretty mind blowing
[https://www.nand2tetris.org/](https://www.nand2tetris.org/)

Making interpreters can be pretty mind blowing
[https://craftinginterpreters.com/contents.html](https://craftinginterpreters.com/contents.html)

------
seemslegit
One day I might read something that will undo my conviction that category
theory is the mathematical equivalent of literary critical theory. But alas,
it is not this day.

------
heavenlyblue
This article doesn’t properly use self within python classes. On top of that
the author couldn’t even apply a code formatter to the code so there’s a bunch
of missing/extra spaces.

It also doesn’t even try to make the given code applicable to real problems.
It seems as if someone writing an article of how to use functions.partial
while never mentioning when those partials could be practically used.

All in all, 0 respect for the reader; seems like a badly typed retelling of a
university course.

