Posts

Python closures and stack frames

I use closures quite a lot in python, but the variable lifetime semantics of closures are undocumented as far as I can tell. For example, consider the following code: def f(): a=1 b=1 def g(): return b return g If we call ‘f’ and store the value, ‘b’ will be kept alive. Is ‘a’ kept alive? A naive implementation of closures might store a reference to the entire stack frame of ‘f’ inside the ‘g’ closure, causing ‘a’ to live even though it will never be used.

Foie Gras

The way it should be: “Imagine: a wild pig comes upon a factory farm, and decides to stay?”

This is easily the most wonderful story I’ve heard about farming:

Dan Barber: A surprising parable of foie gras

The most spectacular part starts at 10:10, but the entire thing is amazing.

Matrix plus scalar

If $a$ is a scalar and $M$ is a square matrix, it is very convenient to be able to write $a + M$. Usually people know immediately what this means, but are uneasy about “abusing” notation, so here’s the detailed justification for why this is perfectly legitimate: Matrices should be considered first and foremost as linear transformations. You know what a matrix is if you know what it does to vectors.

Proust

We’ve decided to give up reading In Search Of Lost Time. Here is a fairly accurate description of why:

Crawling Up Everest

He’s not joking: it really is like that. Interesting, yes, but not nearly interesting enough.

The universe is really big

Here are some incredibly beautiful images:

http://www.ted.com/index.php/talks/george_smoot_on_the_design_of_the_universe.html

It feels like I didn’t quite realize how large the universe was. I was imagining that it was very large but mostly empty, trailing off out beyond the galaxies. The universe does not look empty in those pictures; it looks full. Somehow a full universe seems much larger than an empty universe.

Singular values are not the magnitudes of eigenvalues

A week ago someone asked whether the singular values of a general (real) matrix are the magnitudes of its eigenvalues. There are various ways to see that the answer is no, but here’s an amusingly nonconstructive proof: Consider a random matrix $A$ taken from $GL(n)$ with some smooth distribution. With probability 1 all singular values of $A$ will be unique. However, with nonzero probability $A$ will be near a rotation matrix and will have a complex conjugate pair of eigenvalues with the same magnitude.