Archive for the ‘Uncategorized’ Category

Things I Should Not Eat

November 9, 2012

According to various sources, the following will make me get fat, die of cancer, have bad brain functioning, smell bad, or otherwise turn me into a semi-perambulatory excrement pile


  1. Tomatoes
  2. Sugar
  3. Fake sugar
  4. High Fructose Corn Syrup
  5. CAFO-meat
  6. any red meat
  7. any meat
  8. any animal product
  9. refined grains
  10. any wheat
  11. any grain
  12. potatoes
  13. sweet potatoes
  14. corn
  15. french fries
  16. potato chips
  17. anything my ancestors didn’t eat for a million years
  18. anything cooked
  19. anything that tastes good
  20. anything with a health warning
  21. anything with a health claim
  22. anything domesticated
  23. farmed salmon
  24. farmed fish
  25. wild fish with too much mercury
  26. milk
  27. any dairy
  28. spicy food
  29. non-spicy food
  30. things with the wrong glycemic index
  31. things consumed at the wrong time of day
  32. things consumed in the wrong combination
  33. carbohydrates
  34. cholesterol
  35. saturated fats
  36. unsaturated fats
  37. protein
  38. soy
  39. bottled water
  40. unbottled water
  41. anything with caffeine
  42. any non-water drink
  43. fruit
  44. beans
  45. anything remotely like a bean in a taxological sense
  46. pizza
  47. anything fried
  48. anything that comes in a box or wrapper
  49. anything marked as “light”
  50. almonds
  51. peanuts
  52. any dietary supplements
  53. turkey
  54. anything cooked by someone else
  55. anything made in another county
  56. anything in a can
  57. bread
  58. pasta
  59. canola oil
  60. candy
  61. ice cream
  62. peanut butter
  63. anything from America
  64. anything not from Okinawa or a secluded Himalayan valley
  65. anything I didn’t kill myself
  66. anything with sodium
  67. anything without potassium
  68. diet food
  69. workout food
  70. things that are not diet food or workout food
  71. anything domesticated
  72. white rice
  73. brown rice
  74. food that isn’t organic
  75. food that isn’t raw
  76. food that is raw or organic
  77. margarine
  78. anything synthesized
  79. anything with a face
  80. fugu
  81. shellfish
  82. monkey brains
  83. herbs
  84. lasagna
  85. anything too acidic
  86. bananas
  87. eggplant with cucumber
  88. chocolate
  89. anything that didn’t get to run free when alive
  90. anything not from the farmer’s market
  91. anything irradiated
  92. anything genetically-modified
  93. anything that doesn’t rot
  94. anything advertised on television
  95. anything with long-named ingredients
  96. anything with more than five ingredients
  97. things I eat too quickly
  98. things I eat without appreciating
  99. things I eat alone
  100. anything my grandmother wouldn’t recognize as food

Essentially, in order to avoid a self-inflicted existence of crippling non-optimality, I can eat only Brazil nuts and wild truffles that I collect myself.


Transitive Evidence

July 31, 2012

A snippet from a conversation, paraphrased:

A: I’m worried about my posture. People will think I’m not attractive because I slouch.

B: Don’t worry, you can improve your posture because you’re intelligent.

A: What? How does that follow?

B: I notice that rich people tend to be able to improve their posture. Meanwhile, it is usually easy for intelligent people to become rich. Therefore, intelligent people can usually improve their posture.

Regardless of the somewhat-questionable factualness of these assertions, is the statement logically sound? If A is evidence for B and B is evidence for C, is A evidence for C? Mathematically, it is quite easy to see this is not the case. Check out this probability distribution, for example:   A few moments of staring will show you that it’s a counterexample (A is evidence for B, B is evidence for C, but A is not evidence for C). Good thing, too! Imagine if it were true:

  • Being a Native Hawaiian is evidence for being in Hawaii. Being in Hawaii is evidence for being a tourist. Therefore, being a Native Hawaiian is evidence for being a tourist.
  • If an object is an insect, that’s evidence that it can fly. If an object can fly, that’s evidence that it’s an airplane. Therefore, being an insect is evidence that an object is an airplane.
  • Having sex is evidence that you are breathing hard. Breathing hard is evidence that you’re jogging. Therefore, having sex is evidence that you’re jogging.
  • If it’s raining, that’s evidence that there are umbrellas around. If there are umbrellas around, that’s evidence that you’re in an umbrella factory. Therefore, rain is evidence that you’re in an umbrella factory.

Dropping a Slinky (calculation)

July 30, 2012

Let’s do a quick bit of math related to Dropping a Slinky. Last time, I estimated that it takes about 0.3 seconds for the slinky to collapse. To get a more precise answer, note that however the slinky falls, its center of mass must accelerate downwards at gravitational acceleration.

Where is the slinky’s center of mass? When it’s just hanging, the slinky is in equilibrium, so the derivative of the tension is proportional to the density. Also, if we assume an ideal spring with zero rest length, the tension is inversely proportional to the density (why?). Therefore, we write

\frac{\mathrm{d}T}{\mathrm{d}x} = g \rho


T = \frac{\alpha}{\rho}


This can be solved to show that the density follows


\rho \propto \frac{1}{\sqrt{x}}


Integrating, we find that the center of mass is one third the way up the slinky. The time for the slinky to collapse is the same as the time for the center of mass to fall to the bottom, or


t = \sqrt{\frac{2 (1/3 l)}{g}}


This is the same answer, but modified by a factor of 0.81. Notice that this only depends on the “slinkiness” – the zero rest length ideal spring. We expect thick and thin slinkies of different stiffnesses to act in essentially the same way.

Dropping a Slinky

July 30, 2012

A short video of what it looks like to drop a slinky. It’s surprising and elegant.

So what’s the speed that waves propagate in a slinky? A slinky is a bit tricky, because as you pull on it, it stretches out so that the density goes down. Meanwhile, the tension goes up. Both these effects increase the speed of wave propagation, so waves travel much more quickly at the top of a hanging slinky than at the bottom.

Since the only material properties around are the linear density \lambda and the tension T, we must put these together to get a velocity, which we do by

v = \sqrt{\frac{T}{\lambda}}

As the slinky hangs, it should be in equilibrium, so the gradient of the tension at any point is equal to gravity times the density there. This yields the result that the tension is a square root of how far up you go from the bottom of the spring. As a rough estimate, though, the tension should on average be about half the spring’s weight, while the density on average is the spring’s weight divided by its length. Thus

v = \sqrt{\frac{weight}{mass/length}} = \sqrt{g l}

where g is gravitational acceleration and l is the slinky’s length. The characteristic time of such a slinky is

t = \frac{l}{v} = \sqrt{\frac{l}{g}}

For a one meter slinky we get a time of .3 seconds (and a speed of only a few meters per second), meaning it’s an effect we can see quite well even without high-speed photography!


The same basic mechanism is there in dropping anything else, but typical sound speeds are on the order of thousands of meters per second, so usually it’s much too fast.

Three Things Every Man Should Have and Know

April 26, 2012

I turn around and all the sudden my Facebook friends are getting excited about becoming 30-year old women. So in response to 30 Things Every Woman Should blah blah blah, here are some things a man should have and know before he turns 30.


Something he’s good at (preferably marketable).
Some self-confidence.
Training in at least five ways to exterminate a zombie.


How to eat well, exercise, and manage money.
Who his friends are.
Where the clit is.

I think that should pretty much cover it.

Why Least Squares?

February 7, 2012

Rod and Pegboard

Suppose you have a bunch of pegs scattered around on a wall, like this:

You see a general trend, and you want to take a rod and use it to go through the points in the best possible way, like this:

How do you decide which way is best? Here is a physical solution.

To each peg you attach a spring of zero rest length. You then attach the other side of the spring to the rod. Make sure the springs are all constrained to be vertical.

Now let the rod go. If most of the points are below it, the springs on the bottom will be longer, exert more force, and pull the rod down. Similarly, if the rod’s slope is shallower than that of trend in the points, the rod will be torqued up to a steeper slope. The final resting place of the rod is one sort of estimate of the best straight-line approximation of the pegs.

To see mathematically what this system does, remember that the energy stored in a spring of zero rest length is the square of its length. The system finds a stable static equilibrium, so it is at a minimum of potential energy. Thus, this best-fit line is the line that minimizes the squares of the lengths of the springs, or minimizes the squares of the residuals, as they’re called.

This picture lets us find a formula for the least-squares line. To be in equilibrium, the rod must have no force on it. The force exerted by a spring is proportional to its length, so the lengths of all the springs must add to zero. (We count length as negative if the spring is above the rod and positive otherwise.)

Mathematically, we’ll write the points as (x_i, y_i) and the line as y = mx+b. Then the no-net-force condition is written

\sum_i y_i - (mx_i+b) = 0

There must also be no net torque on the rod. The torque exerted by a spring (relative to the origin) is its length multiplied by its x_i. That means

\sum_i x_i \left(y_i - (mx_i + b)\right) = 0

These two equation determine the unknowns m and b. The reader will undoubtedly be unable to stop themselves from completing the algebra, finding that if there are N data points

m = \frac{\frac{1}{N}\sum_i x_iy_i - \frac{1}{N}\sum_i y_i \frac{1}{N}\sum_i x_i}{\frac{1}{N} \sum_i x_i^2 - (\frac{1}{N}\sum_i x_i)^2}

b = \frac{1}{N}\sum_i y_i - m \frac{1}{N} \sum_i x_i

These formulas clearly contain some averages. Let’s denote \frac{1}{N}\sum_i x_i = \langle x \rangle and similarly for y and combination of the two. Then we can rewrite the formulae as

m = \frac{\langle xy\rangle - \langle x \rangle \langle y\rangle }{\langle x^2\rangle - \langle x\rangle ^2}

\langle y \rangle = m \langle x \rangle + b

This is called a least-squares linear regression.


The story about the rod and minimizing potential energy is not the really the reason we use least-squares regression; it was only convenient illustration. Students are often curious why we do not, for example, minimize the sum of the absolute values of the residuals.

Take a look at the value \langle x^2\rangle - \langle x\rangle ^2 from the expression for the least-squares regression. This is called the variance of x. It’s a very natural measure of the spread of x – more so than the one you’d get by adding up the absolute values of the errors.

Suppose you have two variables, x and u. Then

\mathrm{var}(x+u) = \mathrm{var}(x) + \mathrm{var}(u) + \langle 2xu\rangle - 2\langle x \rangle \langle u \rangle

The reader is no doubt currently wearing a pencil down to the nub showing this.

If x and u are independent, the last two terms cancel (down to the nub!), and we have

\mathrm{var}(x+u) = \mathrm{var}(x) + \mathrm{var}(u)

In practical terms: flip a coin once and the number of heads has a variance of .25. Flip it a hundred times and the variance is 25, etc. This linearity property does not hold for absolute values.

So variance is a very natural measure of variation. Simple linear regression is nice, then, because it

  1. makes the mean residual zero
  2. minimizes the variance of the residuals
Defining the covariance as a generalization of the variance \mathrm{cov}(x,y) \equiv \langle xy\rangle - \langle x\rangle \langle y\rangle (so that \mathrm{var}(x) = \mathrm{cov}(x,x)), we can rewrite the slope m in the least-squares formula as
m = \frac{\mathrm{cov}(x,y)}{\mathrm{var}(x)}

The Distance Formula

The distance d of a point (x,y) from the origin is

d^2 = x^2 + y^2

In three dimensions, this becomes

d^2 = x^2 + y^2 + z^2

The generalization to n dimensions is clear.

If we imagine the residual as coordinates of a point in n-dimensional space, the simple linear regression is the line that brings that point in as close to the origin as possible, another cute visualization.

Further Reading

The physical analogy to springs and minimum energy comes from Mark Levi’s book The Mathematical Mechanic. Amazon Google Books

The Wikipedia articles on linear regression and simple linear regression are good.

There’s much mathematical insight to be had at Math.Stackexchange, Stats.StackExchange and MathOverflow

A Cute Hat Problem

December 31, 2011

I’ve seen a number of “hat problem” logic puzzles, but this one I found the other day was new to me nonetheless.  I’m stealing from, where you can find a beautiful description of the answer.


Three people enter the room, each with a hat on their head. There are two colors of hats: red and blue; they are assigned randomly. Each person can see the hats of the two other people, but they can’t see their own hats. Each person can either try to guess the color of their own hat or pass. All three do it simultaneously, so there is no way to base their guesses on the guesses of others. If nobody guesses incorrectly and at least one person guesses correctly, they all share a big prize. Otherwise they all lose.

One more thing: before the contest, the three people have a meeting during which they decide their strategy. What is the best strategy?