How to shoot yourself in the foot with Python

Filed under: programming — jlm @ 21:40

Accidentally compare a character and an integer.
$ python -c 'print "\0" > 1024'

Wait, what? Any character is larger than any integer? Why are chars and ints intercomparable then? Shouldn’t I get either a type error or a meaningful comparison? This seems like it’s guaranteed to be wrong!


Got an Eee? Forget Easy Peasy

Filed under: linux — jlm @ 00:56

So, I just upgraded Easy Peasy on my Eee. And surprise, surprise, it broke WiFi again.
Fortunately, there’s a user-contributed fix available, like the other times this has happened!
Unfortunately, the maintainers aren’t adopting it, also just like the other times!

This is a distribution targeting one specific line of netbooks, and in every version of it, WiFi doesn’t work. Scrapheap time for Easy Peasy.


Incentives in action: Airport tarmac delays

Filed under: econ — jlm @ 09:50

When the New York airports re-opened following the recent blizzard, there was a backlog of flights, and short-staffed airline terminal support personnel couldn’t process them as fast as they arrived. Which planes do you think got serviced, and which delayed on the tarmac for hour after hour?

It’s no surprise if you know that the rule put into effect after repeated and persistent multi-hour tarmac delays by the airlines applies only to domestic flights. Miraculously, just enough personnel were found to keep the domestic flights coming to the gates without hitting the delay lengths which would trigger fines — but not enough to service the international flights, for which there are no tarmac delay penalties.

And that’s why the flight from Vancouver, BC to Kennedy Airport sat on the tarmac for over 12 hours. Airlines had no incentive to service it, but did have an incentive to prioritize domestic flights over it. Corporations don’t feel shame or guilt for bad behavior, but they do feel the sting of fines and act to avoid them. We need to choose our incentives carefully.


Dec. 25

Filed under: misc — jlm @ 08:27

Centuries ago, we lived in ignorance, our vision dim, not even knowing what we didn’t know. Now and then some people struck sparks as we stumbled in the darkness, and saw something others had missed.
But, on this day, a man was born who was to kindle a torch and connect heaven and earth.
Though his work and teachings, he changed our worldview forever. He revealed truths and laws that mankind had had no conception of before. He turned our old notions upside-down with a new understanding of the heavenly realm, and of the world on which we live. His teachings have stood the test of time, still being taught, analyzed, and widely used in practice to this very day. The great thinkers of later ages have taken what he revealed, and built magnificently upon it, each generation using the work of the previous to go further.

Happy birthday, Isaac Newton!


Back from Skepticon

Filed under: travel — jlm @ 10:39

I went to Skepticon 3 this weekend and it was a blast.

John Corvino had an excellent talk comparing atheist and homosexuals’ rights movements. This is a tricky topic, needing to avoid trivializing the gay rights struggles while not minimizing the issues faced by atheists in communities of believers either. John struck this balance deftly — I’m not sure someone who was not both an atheist and GLBT activist could have pulled it off.

There were interesting talks on skepticism’s relationship with feminism and sexuality, and another on diversity inside the movement. The Con had a good gender balance, but was very, very white. Part of this has to do with the location in a less-diverse part of the country, but much had to do with the white-skewed demographics of the skeptics movement. Unfortunately, the talk on diversity was lacking when it came to concrete suggestions.

The first day ended with a panel discussion on whether skepticism begat atheism. James Randi brought up that there were two types of atheists, the first who believed there was no god, and the second who didn’t believe that there was a god (ie, actual belief in nonexistence vs. lack of belief in existence). D.J. Grothe segued from this to say he found the arguments in favor and against the existence of god lacking, so he disbelieved, pending new information (so far, so good) and didn’t think there were really type 1 atheists, or maybe a very few. This statement was “WTF?” for me, so at the Q&A I pointed out that there really were people who believed there was no god, because of the problem of natural evil or other arguments. And the next day, during his talk, Grothe made this “no type 1 atheists” claim again! At Q&A Corvino called out again that plenty of atheists have real belief in god’s nonexistence. I’m disappointed in Grothe — he knows better, so claiming that “strong atheism” is a fringe of the atheist movement is simply dishonest.

Before that panel was one on accomidation vs. confrontation. This seemed to quickly settle on a consensus of “we should pick our battles wisely”, and lacking dispute consequently wasn’t that interesting.

The second day had a talk on faith healers by James Randi, which was entertaining, but was mostly video clips. Alas, Randi seems to be suffering from his age. A talk on debunking ghosts and cryptic creatures and spontaneous human combustion was interesting. Dan Barker’s story of going from faithful to faithless was touching. P.Z. Myers talked about teaching genetics by analogy with poker, but I found it unconvincing. Then there was a talk by Rebecca Watson on the so-called War on Christmas, which was hilarious.

The third day was easily the weakest. Victor Stenger’s talk used unsettled cosmology, and was weak. It’d been better if when he’d gone into elementary particles and their wave functions, talk about how the waves interfere and their particles interact. And at least gone into quantum interpretations a little. These are the bits of QM that “quantum spiritualists” misuse, and the talk gave little ammunition to combat them.

Sam Singleton was amusing for his gimmick of impersonating the affect of an evangelical preacher, but that wore thin quickly. His grandfather dying from snake handling was a sad story, another grain in the immense pile of suffering religion has caused. J.T. Eberhard’s was the best of the day, funny, and absolutely true to how talking atheism to the religious runs.

Not actually part of the conference, I spent the non-conferring parts of the weekend wandering Springfield, MO’s city center. I was struck by how utterly inactive the city was. But not like a dead city: The businesses were open, not shuttered, but there was very little traffic, pedestrian or automotive, very strange.

I had a great time talking with complete strangers also there — lots of friendly and intelligent folks. I’m overall very impressed with the conference. I’ve been to industry technical conferences that weren’t run as well. That a college freethinkers group could pull this off without even charging admission is doubly impressive.


Kinked pipes

Filed under: math — jlm @ 12:04

Our friend Keith Devlin poses an interesting question about expanding pipes: A pipe expands by one foot over its one-mile length; how high does it arch?

Keith assumes a single sharp kink in the center and uses Pythagoras to calculate that the pipe arches slightly over 50 feet! Yet if the pipe had its sharp kink near one end, it’d arch slightly under 1 foot. This suggests a calculus of variations problem: Of all the ways a pipe can bend, which way generates the highest arch? The dual problem would be: Of all the ways to arch to a given height (let’s say 50 feet), which way uses the least length of pipe?

Our pipe path will go from one pipe endpoint up to some point with height 50’, thence to the other pipe endpoint. If either of these paths weren’t a line segment, we could shorten the path by using a line segment. The angles the segments make with the horizontal line at 50’ will be equal, otherwise we could shorten the path by equalizing them. So the shortest path is a line up to the center 50’ up, kink, then a straight line to the ground at the other end.

Because this isoceles path is the shortest path to reach a given height, it’s also the highest-reaching path of its length. Keith’s assumption that the pipe sharply kinks in the center gives the highest arch of any possible path!

Minimizing the height isn’t so interesting: By making arbitrarialy fine accordion folds, we can keep the maximum height arbitrarialy small.

What if the pipe makes a parabolic arch? Depth below the arch height at distance x from the center is kx². For our case of a mile-long pipe, we have arch height k(2640)². The curve length is ∫02640 √(1+(2kx)²) dx. If you’re like me, you can’t integrate this without a reference, but it gives (2kx √(4k²x²+1)+sinh-1(2kx))/4k | x=2640. Numerically solving this for length 2640.5 gives k=6.385×10-6, which gives an arch height of 44.5 feet.

That was messier than I expected. I expect a catenary arch, which IIR my physics correctly is what a pipe should assume under gravity, would be much the same.

Why are the arches in the center so much higher than arches at the ends? Going back to the triangle case, if we increase our pipe length by an amount δ over a flat length x, we have height related by x²+h² = (x+δ)² from good old Pythagoras, which gives h = √(2xδ+δ²). δ will vary from near 1 at x=0 to near 0 at x=5280, δ ≈ 1-(x/5280), varies only slowly with x. So with the square root curve being steep at small values, at small x, x has a big impact on h! Toward the other end, δ’s decrease overpowers x’s increase, and as δ gets small h is pulled steeply down.


Permutation puzzle in Futurama

Filed under: math — jlm @ 12:26

I finally got around to watching last week’s Futurama late last night, and there’s an interesting permutations puzzle involved. The puzzle itself is a minor SPOILER, so stop now if 5 days isn’t enough time for you.

Puzzle: There’s a machine that can swap minds between bodies, but can’t swap two people if it’s already swapped that pair of bodies. A group of people use the machine to perform an arbitrary sequence of swaps among themselves. How can this group and two outsiders use the machine to restore everyone’s mind and body?

My solution is here.

I wonder if this is a recasting of a classic swapping puzzle I’m not familiar with.


Finger Multiplication

Filed under: math — jlm @ 12:39

“Finger multiplication” is an old trick for using the bottom-left (easier to memorize) quadrant of the times table to do multiplication in the top-right quadrant. It’s easy to work out why it works, but unsatisfying, but I found rederiving the technique gave more insight.

How might we do this? To go from one quadrant to the other, we subtract from 10, or generally from the base b: (b-x)(b-y) = b²-bx-by+xy
Well, there’s our xy term, to get it alone we want to subtract off b²-bx-by = b(b-x-y), which we can do by adding -b(b-x-y) = b(x+y-b). The factor of b is trivial to deal with, just use place value, so that leaves us with x+y-b. That’s easy enough to calculate on its own, but we can distribute the -b half to each number as (x-b/2)+(y-b/2). We have the numbers b-x and x-b/2 to do arithmetic on, these sum to b/2, the number of fingers on a hand, so if you hold up x-b/2 (x-5 for us pentadactyl folk) fingers on a hand, then the down fingers number b-x. And that’s how you do finger multiplication, hold up x-5 on one hand, y-5 on the other, put the sum of the up fingers in the tens place and the product of the down fingers in the units place et voilà.

Now that we’ve reverse engineered it for the existing use case, can we come up with something like it for others? How about the case where only one term is > 5 ?
We want to move this from the top-left to the bottom-left of the times table, so x∙(b-y) = bx-xy. So, put the smaller number in the tens place, and subtract off the product of it and the “down fingers” from the large number. 3×7? 7 has 3 down fingers, so 30-9 = 21. 4×8? 8 has 2 down fingers, so 40-8 = 32.


Simpson’s paradox

Filed under: math — jlm @ 08:56

I’ve never seen Simpson’s paradox explained by showing the distributions, which I found to be very helpful in understanding what’s going on. So, take a look at these two distributions I made from calls to random():
Simpson's distribution
The cyan distribution has a larger mean than the magenta one, but anyone worth their salt should recognize them as mixtures of unimodal distributions (indeed, that’s how I made them) and look for a binary factor to separate the subpopulations. Upon separating them, in both cases the magentas’ means are higher than the cyans’, Simpson’s paradox.


P vs. NP

Filed under: humor, math — jlm @ 14:37

So, Vinay Deolalikar has a purported proof that P ≠ NP here. But there must be some error, because I just came up with this simple proof that P = NP !
(If you think “joke proof” sounds like an oxymoron, you can stop reading here.)

Let W(m) ➙ s be a member of NP.
Let X(m; n) ➙ s be the first n symbols of W(m). X is obviously in NP.
So, X has a verifier V(m; n; s) in P.
We can find the first symbol t1 of an output of W(m) by trying V(m; 1; c1), V(m; 1; c2), … for all the symbols ci in the alphabet.
We can find the second symbol t2 by trying V(m; 2; t1c1), V(m; 2; t1c2), etc.
And so on for all the symbols t3, t4, … in the output of W(m).
Finding each symbol takes c calls to V, where c is the alphabet size, a constant. Each call of V takes polynomial time, so we can calculate each individual symbol in polynomial time.
The length of the output of W(m) is necessarily polynomial in ∥m∥, so we have a polynomial number of symbols, each calculable in polynomial time, so we can calculate the entirety of W(m) in polynomial time, so W ∈ P.

Powered by WordPress