Saturday, October 10, 2009

How to teach Category Theory?

So I'm teaching an intro to category theory course this fall at Portland State, my new place of employment.

Now, I think it's going alright. I have only 6 people in on this class, including one professor, but I imagine that if I teach it again in the future and advertise it a bit harder that there will be more.

It's been an interesting experience, though, because I've realized one of the big problems with trying to explain category theory: it's too young a field. We have all the definitions, but none of the metaphors. There's no coherent narrative to give you intuition. "Categories for the Working Mathematician", one of my all time favorite books, cheats pretty seriously on this front. It never gives a basic vocabulary to use to describe any of these structures, it just gives so many examples from other areas of math that you start to build an intuition; however, you have almost no words with which to explain this intuition.

I was inspired to write more about this because of a thread on reddit. I strongly disagree with the sentiment that one should be able to explain the concepts of category theory in terms of functional programming. Some ideas in category theory- such as representable functors, adjoints, hom-sets, topoi - are general enough that any attempts to squash them into Haskell code is simplifying to the point of confusion. An example of this is Dan Piponi's old post on the Yoneda lemma. While it's good and gives intuition, it's also a bit of a lie- the Haskell arrow (->) is not actually a hom-set and Yoneda is all about the relation between hom-sets and natural transformations that allows you to embed any category C into the category of functors from C to Set, a category with much richer logical structure. As much as the analogy to Haskell helps, I think it hurts by making the big, general, picture harder to see.

So is the solution to suck it up and just bang your head against Mac Lane, never thinking about how it relates to code? Of course not! Let's take a slight detour, first, before talking about what to do.

So Paul Graham has this famous essay - famous enough I don't even see a point to linking it - about "Blub programmers" and how they're blind to the powers of better tools because they only know Blub. It probably wasn't Graham's intent, but this essay is usually referenced by language evangelists to explain why some programmer they talk to isn't instantly willing to adopt their favorite language despite how awesome it is. It's a seductive explanation. The people who disagree with them don't "get it" or just aren't trying.

The more likely reason? They're terrible at explaining why their language is good.

When I was a grad student in physics, most of the grad students (myself included, much to my shame) joked about how dumb all the pre-med students were and how they never wanted to do any work, because that was the most convenient explanation for why there were so many complaints about how hard & confusing the labs, lectures, etc. were.

The more likely reason? We were terrible at explaining physics.

That brings me back to the course I'm teaching. I'm spending the majority of my time trying to figure out real metaphors for explaining category theory, especially with respect to its uses in Computer Science.

So far, the basic story I'm going with is that category theory is about "modeling structures". Functors are about instances of models in a target category. Natural transformations are ways to move between two models in a "coherent" fashion. I'm still fleshing out this language, and I don't know how terribly helpful it will be at the end of the day, but I'll be cleaning up and releasing my notes at the end of the term as one long pdf. The point is that there's still a lot of programmers, computer scientists, and even mathematicians that don't see category theory for the beautiful foundational math I see. Now, it's possible that they're all stupid or don't want to work.

The more likely reason?

18 comments:

Antoine said...

Because this is the internet: Beating the Averages by Paul Graham

michiexile said...

Very true, and I wish I read this before I got started.

I do try to give intuition in my lectures - though I end up finding it more difficult than I expected (naive as I was going into it).

Feel free to pick up my notes as inspiration source. I try to give narrative flows, but I don't feel I do a very good job of it.

http://haskell.org/haskellwiki/User:Michiexile/MATH198

Tom Ritchford said...

I took a course in Homological Algebra and Category theory some 25 years ago - I certainly passed but unlike many other courses at the time it never stuck with me, I think because it was pretty but never let me do anything new I couldn't do with some other technique.

A friend described it later as "a solution in search of a problem" which more or less summed it up for me!

(But that was 25 years ago - what has happened since?)

Chris said...

I don't know, isn't the idea "We just suck at explaining" just another form of seductive thinking? If we could just explain it the right way, it'd make sense to anyone!

There is a significant amount of internalization that goes on in learning anything, which usually requires continually thinking about things outside of the material presented (regardless of whatever the material presented is). Many people have a tendency on encountering an idea the third time say "Why didn't they just explain it that way the _first_ time?!". A lot of the time, it's just the third time the concept has been encountered that's the difference.

Back to your pre-meds, I think it has much less to do with them being lazy or stupid (which, for crying out loud, their pre-meds, of course they aren't), but much more to the apparent irrelevance to them of learning how to add vectors together when in their other classes their actually learning stuff about how the body works. They aren't going to invest their time thinking outside of class about physics (which, honestly, isn't that relevant to them), when their other classes are telling them how not to accidentally kill people.

@Tom, they said the same thing about the laser.

Neel Krishnaswami said...

So far, the basic story I'm going with is that category theory is about "modeling structures".

This is actually why category theory is hard to teach. Your audience needs to understand enough structures that a) they can understand why they might want to move between them, and b) the examples need to be different enough that the translation isn't totally obvious.

E.g., in group theory, you've got "groups as addition over the integers" and "groups as symmetries", which gives you two examples that look different enough that it's surprising and interesting that there's common structure under the skin. That motivates students to believe that there is a deeper structure that is worth the effort of developing a mathematical intuition for.

If you know at least two of abstract algebra, lattice theory, type theory, and point-set topology, then category theory is pleasing in the same way. But unfortunately those are not elementary subjects,

Creighton Hogg said...

Chris,
So I don't think there's some silver bullet that will make the whole thing instantly make sense to everyone; however, when people are complaining - as in that reddit thread, or among other grad students I've talked to - that they've put in significant time and aren't getting any real payout, then I do think the explanations must not be very good.

In the case of the pre-med students, what opened my eyes in my second year of teaching was really talking to them as peers, even friends, and seeing just how much effort they were putting in with so little gain in understanding.

So, I disagree with your assessment in a slight way but for the most you are right. My goal is to see if we can take reduce, not eliminate, the amount of time it takes to internalize since it seems disproportionately high for the subject.

My inspiration in the matter is the long-running "This Week's Finds in Mathematical Physics", because Baez has developed such a knack for explaining ideas in a way that builds intuition almost immediately.

Sure, after a single reading you won't be able to go out and apply these ideas professionally - but you will have the big picture and it'll be clear why people care about it. That's the "narrative" that I'm trying to build for category theory.

Anonymous said...

Geroch's book, Mathematical Physics uses category theory to tie his exposition together. You might find some motivational examples there.

sigfpe said...

Forget about Haskell being a programming language. Syntactically it contains the internal language for a suitable class of category. In this sense, Haskell code is talking about a precise class of category, it gives precise examples of category theoretical concepts with no "lies", and standard proofs of Haskell program correctness are in fact valid category theoretical proofs. This internal language doesn't let you say everything that can be said about all categories, but that's not a problem. People have always taught mathematics by giving examples that aren't necessarily as general as the theory being discussed - eg. we teach groups by considering examples with modular arithmetic.

As a side effect, this internal language also gives runnable programs.

Creighton Hogg said...

sigfpe,

The general problem I have is that you need to appeal to internal category theory in order to justify why those examples are kosher. I want to start with the general framework of categories internal to Set, the normal "category theory" that is generally presented in introductions.

Maybe you're right, though. I hadn't been open to the idea that starting out internal to a different category was a good starting point. I don't feel comfortable with the idea in the context of building a course - but I don't have a reason beyond gut feeling that it would make things more confusing later.

What I want to avoid is any "cheat" analogous to teaching intro physics with algebra instead of calculus: it makes the bar of entry lower, but causes the subject to be almost impossibly hard beyond a certain point. I don't want to teach in a way that will require unlearning later.

sigfpe said...

I don't make any claim to know what's good for teaching. That's a hard subject.

I'm only really responding to your claim that I was slightly lying :-) The message of a large chunk of Lambek and Scott is that typed lambda calculus is the internal language of Cartesian closed categories, and, by implication, that many proofs about Haskell programs, including pointful ones that at first seem applicable only to Set, are rigorous for any CCC. (Or even *any* category, depending on what language features you use.)

I certainly wouldn't make such an internal language a significant component of a CT course for mathematicians. But it does give useful examples and the intuitions to be gained from it are sound and not at as hand-wavey as some might think. And it is probably a good way to go when dealing with people who already know functional programming.

I feel a blog post coming on :-)

Chris said...

@Creighton Hogg

If the pre-med students have not taken calculus, than that largely accounts for the issue. Like you say, it's 'cheating' (on the administrations part), because the students have been deprived of the idea of breaking things into very small approximations, and then adding up the approximations (seriously, this is not intuitive). If you try to circumvent that entire mode of thinking altogether, than a physics class largely becomes a matter of faith, with equations given to the students to be used in certain circumstances for certain, unrealistic, problems. No internalization can take place, since the concepts aren't connected, and the glue logic isn't present. So if you are teaching physics without calculus, than yes, I'll grant you, you could say it's because "Your explanations suck", but how good can your explanations be without calculus?

In this case, isn't algebra essentially the 'calculus' of Category Theory? It provides the wealth of examples, and the basic mode of thinking. As far as I can tell, a lot of people from the reddit forums seem to be trying to tackle category theory without algebra. And, unsurprisingly, it comes off as useless abstraction. The amount of category theory needed to understand a language (to the point of writing code in it) like Haskell, is arguably, none.

But I'll definitely agree, there is definitely a thing such as a 'bad' explanation, and some explanations are easier to wrap your head around than others (but sometimes trying to figure out what the hell the prof was talking about can be useful too ;))

I look forward to your notes, and see how you attempt to solve this problem. :)

Anonymous said...

Category theory is almost entirely about developing a unifying vocabulary for various topics.

I like this paper by Baez a lot: http://math.ucr.edu/home/baez/rosetta.pdf (but it's kind-of out there)

I think you must use a range of examples from broad contexts to actually make CT compelling -- that's why it's usually only taught fairly late in a math education -- any earlier and you don't have enough examples to look at.

I also think that the usual CT+CS paper by Moggi et al is actually pretty good in terms of examples etc. But it assumes a lot of CT to start with.

I also think that a CT course should really at least recommend _Categories for the Working Mathematician_, which is a brutally dense book. Ideally, the exercises would come from it-- they are good, but tougher than they seem when skimming the book.

Hans Stricker said...

@Creighton, I really liked this post! Very well written, I would have liked to be at Portland State to be your 7th student, but alas.

What I am looking for is a way to explain basic mathematical approaches - set theory, type theory, model theory, category theory, Bourbaki's "structure theory", "functional theory" (the theory behind functional programming) - in a unified (!) manner even to laymen (especially philosophers). The only premise: to be interested in.

Does this sound absurd?

Anonymous said...

nice post. thanks.

Anonymous said...

http://markonzo.edu coupon hamburgersи http://www.mydogspace.com/me/keno http://weber-grills.indieword.com/ http://www.rottentomatoes.com/vine/showthread.php?p=17358206 http://gerber-knives.indieword.com/ http://www.mypage.com/tempurpedic/weblog http://www.minco.com/community/user/Profile.aspx?UserID=19029 http://treadmill.indieword.com/ http://aviary.com/artists/deltafaucets

ricardo said...

Consider having a look at INFOSENSE by Keith Devlin. Devlin, an accomplished numberist ... gives us a clear picture of his subject ... The key, says Devlin, is not information, but knowledge, which he defines as information put into practice.

In other words, try to get to sharing knowledge in your class.

Anonymous said...

Hi-ya i am new here. I came accross this board I have found It extremely helpful & it has helped me alot. I should be able to give something back and assist other users like its helped me.

Thanks a load, Catch You Around.

Anonymous said...

Greetings im fresh on here, I came accross this board I have found It extremely useful and it's helped me a lot. I should be able to contribute and aid others like its helped me.

Thank You, See Ya Around