jlm-blog
~jlm

27-Jan-2008

Musings on Newcomb’s Paradox

Filed under: philosophy — jlm @ 11:45

So, I’ve been thinking about Newcomb’s Paradox lately.
I think part of the issue is it conflates a couple issues, and it might be useful to consider them separately. So, think on these paradoxes:

Determinism vs. Nondeterminism
Consider a superhuman predictor and a fair coin. The predictor predicts what the coin will show, then you flip it. The predictor is [nearly] always right.

Removal of free will
A computer has been programmed to maximize its expected score as a player in the Newcomb scenario, given that the predictor has a copy of the program to analyze, run in simulation or on another computer, etc. How will it play?

My take on Newcomb’s paradox? It reduces to the question of whether free will makes our choices inherently unpredictable, and the paradox is thorny because free will isn’t well defined enough to provide a clear answer.
If we have no free will, it’s just the computer scenario. If we assume free willed actions are inherently unpredictable, then the existence of a predictor contradicts that assumption, just like it contradicts the assumption that the outcome of a fair coin flip cannot be predicted.

10-May-2007

Tip: compression

Filed under: general — jlm @ 16:28

It doesn’t help to zip already compressed file formats, like jpeg or mpeg, it only wastes CPU. Uncompressed video, audio, or still images will compress better with algorithms which are dedicated for video, audio, or images than they will with general compressors. JPEG is for photos — for images which are line drawings use PNG.

3-May-2007

Periodic table of *

Filed under: science — jlm @ 13:36

Okay, so the Periodic Table of the Elements is one of the iconic symbols of Chemistry. Even if you flunked your high school Chem, you’ll recognize it instantly. Unfortunately, if you flunked high school Chem, you won’t actually know what it means.

Not recognizing that it’s a systematic arrangement of all the chemical elements, elucidating their properties in terms of their electron structure, you’re tempted to fill it in instead with items from whatever interest you do have. Make a Periodic Table of Fruit, or a Periodic Table of Government, or a Periodic Table of Rhetoric, then feel like you’ve somehow contributed something useful to Fruit classification. But what does this non-Elemental table mean? Do the properties of fruit recur periodically as something corresponding to atomic number increases? What even corresponds to atomic number? Why should fruit group as if it had electron shells? Does your table actually explain anything? Or are you just capitalizing on the fact that atoms do have electron shells and so elemental properties do arrange into a periodic table which is tremendously useful for chemistry, and applying it to something completely inappropriate?

30-Mar-2007

Distance between points on a sphere

Filed under: math — jlm @ 15:22

If you try and find out how you compute the distance between points on a sphere, you’ll get a bunch of sites which offer to calculate it for you if you enter the coordinates. If you search harder, you can even get the formula. But no one seems to be offering a derivation. So here you go.

First, some preliminaries. The half angle formulas give us 2 sin² ½ψ = 1−cos ψ. (Easily derivable from cos 2α = cos² α − sin² α.) The straight-line distance (cutting through the inside of the sphere) between two points on a unit sphere with an angle ψ between them is 2 sin ½ψ. (Bisect the triangle formed by the two points and the center of the sphere.) Together, these mean that the square of the straight-line distance is 2 − 2 cos ψ.

[Geometric diagram of a sphere]

Consider A and B to be our two points we want to get the distance between, with latitudes φA and φB, and longitudes which differ by Θ. We’ll operate mostly on the disk formed by the parallel through B. The point where it intersects the pole is D, and the projection of A onto it is C. Let EB be perpendicular to DC.

The radius of the parallel through A is rA = cos φA = DC; the one through B is rB = cos φB = DB. Angle CDB is Θ, so EB = rB sin Θ and ED = rB cos Θ.
EC = CD − ED = rArB cos Θ.
BC² = EC² − EB² = rA² − 2 rA rB cos Θ + rB² cos² Θ + rB² sin² Θ = rA² + rB² − 2 rA rB cos Θ.

AC = |sin φA − sin φB|.
AB² = BC² + AC² = rA² + rB² − 2 rA rB cos Θ + sin² φB − 2 sin φA sin φB
   = cos² φA + sin² φA + cos² φB + sin² φA + sin² φB − 2 rA rB cos Θ − 2 sin φA sin φB
   = 2 − 2 rA rB cos Θ − 2 sin φA sin φB.

If ψ is the angle AOB (which is also the along-surface distance between A and B), then
AB² = 2 − 2 cos ψ, from the “preliminaries”.
So, 1 − rA rB cos Θ − sin φA sin φB = 1 − cos ψ.
ψ = arccos(cos φA cos φB cos Θ + sin φA sin φB).

30-Jan-2007

Washington’s farewell address

Filed under: politics — jlm @ 17:36

Randall Munroe, of xkcd fame, has gone and translated George Washington’s farewell address into everyday speech. It’s an utterly fascinating read, and much more tractable than trying to read the whole thing (it’s quite long) in his original text. Washington’s ideas on what makes good government are well argued by him, and Munroe has made it accessable. Give it a read, you won’t regret it!

29-Jan-2007

Cell biology animation

Filed under: science — jlm @ 07:33

The folks at Harvard have put together an amazing CGI video showing some of the biochemical dynamics involved in our cells: The Inner Life of the Cell

There’s other good informative bio videos there, but nothing else with as tasty eye-candy.

17-Dec-2006

Hectic holidays

Filed under: time — jlm @ 16:37

A friend of mine called this time of year the “hectic holidays”, and it’s absolutely correct.

I love the getting together with my family, the Christmas feast, the time off… But the gifting is very stressful. It’s hard to pick out gifts for people, it’s hard to ask for gifts, and shopping is a huge pain: Even when you know what you want to buy, going to retail stores right now is an exercise in frustration. And then the effort is wasted because they’re out of stock!

How many people can we get together under the idea that Christmas is better off without the gifts, so we can focus on nobler ideals. Can we make Christmas a holiday that’s not about commerce, but a celebration of our brotherhood with our fellow man?

16-Dec-2006

The C aliasing rules

Filed under: programming — jlm @ 11:49

A lot of people are confused by the pointer aliasing rules introduced by C99. (Sometimes called “strict aliasing”.) First, what is aliasing? When two pointers refer to the same location, they’re called “aliases”.
void fcn(int *p) { int *q = p; ... }
Here p and q are aliases. The general rule is that pointers to the same type are allowed to alias, and pointers to different types are not. (Differences like signed/unsigned and const/non-const aren’t considered significant here– they’re all in the same “aliasing class”.)
void fcn(float *p) { int *q = (int *) p; ... }
This is illegal, because p and q are aliases, but one points to float while the other points to int. In practical terms, the optimizer will reorder accesses to *p and *q across each other, or optimize out writing/reading the value back into/from memory, because they’re in different alias classes, and you’ll get mysterious bugs.
There are two exceptions to this rule: void * and char *. Pointers of these two types are allowed to alias any kind of pointer. void * can be assigned from and to any pointer without a cast, but you’re only allowed to assign it to a type which reflects the original pointer (or char *).
void intfcn(void *p) { int *q = p; ... }
void floatfcn(void *p) { float *q = p; ... }
void fcn(void) {
  int i;
  intfcn(&i);  /*  OK: int * -> void * -> int *  */
  floatfnc(&i);  /*  Bad: int * -> void * -> float *  */
}

This style is used a lot in callbacks, where it’ll look something like:
void callsoon(void (*fcn)(void *), void *arg);  /* Call fcn(arg) in one second */
void fcn(void) {
  static int i = 1;
  static float f = 0.1;
  callsoon(intfcn, &i);
  callsoon(floatfcn, &f);
}

The compiler is still assuming your int * and float * pointers won’t alias here: It’s up to you to ensure that the void * which got a float * doesn’t get turned into an int * and vice-versa. The void * is telling the compiler “I can ensure non-aliasing on my own, without you checking”. You should not use it to silence aliasing warnings, because you get those warnings in situations where the compiler is going to re-order accesses, and the void * gives it free license to do so silently!
What do you do when you really need to alias across types? First, don’t do a straight pointer typecast or go through a void * typecast for the reasons above:
void fcn(float *p) { int *q = (void *)p; ... }
void fcn(float f) { int i = *(int *)&f; ... }
void fcn(float f) { int i = *(int *)(void *)&f; ... }  /* All illegal aliasing */

Another common but illegal technique is to go through a union:
union { int i; float f; } x; x.f = f; i = x.i;  /* Illegal: unions can only be read from the last type assigned to them */
So, what do you do? One of the most common use cases is for transferring byte representations, and memcpy() works fine for this (any modern compiler will optimize it into stores).
void fcn(float *p) { int i; memcpy(&i, p, sizeof(i)); ... }  /* Safe if sizeof(int) == sizeof(float) */
void fcn(float f) { int i; memcpy(&i, &f, sizeof(i)); ... }  /* Ditto */

void fcn(float *p) { int *q; memcpy(&q, &p, sizeof(q)); ... }  /* Illegal: just a fancy way of writing q = (int *)p */
If you need fine-grained access, this is where char * comes in. It’s allowed to alias any other pointer, so the compiler can’t re-order pointer accesses across char * accesses unless it can ensure non-aliasing by other means.
void fcn(float *p) { char *q = (char *)p; ... }  /* Safe */
Note that just going though a char * on your way to an illegal alias doesn’t make it legal:
void fcn(float *p) {
  char *q = (char *)p;  /* q now validly aliases p */
  int *r = (int *)q;  /* r now validly aliases q, but p and r are still in different alias classes and *p and *r can be re-ordered across each other */
  ...
}

void fcn(float *p) { int *q = (int *)(char *)p; ... }  /* Illegal aliasing of p and q, same as q = (int *)p */
char * is safe, as long as you do your references through it, as chars (bytes), but just having a char * there doesn’t make non-char * references legal.

7-Nov-2006

What’s wrong with my sound?

Filed under: linux — jlm @ 13:03

The sound on my Ubuntu box stopped working this morning.
I was getting a ton of messages “ALSA lib pcm_dmix.c:819:(snd_pcm_dmix_open) unable to open slave”. I bounced artsd, and it said that very message on startup. After the usual futzing around, such as looking in syslog and finding nothing, I straced it, and searching for dev files noticed:
open("/dev/snd/pcmC0D0p", O_RDWR|O_NONBLOCK) = -1 EBUSY (Device or resource busy)
Well, that certainly looks like a culprit, would have been nice if artsd could have actually reported that as an error.
Now, let’s fuser /dev/snd/pcmC0D0p — huh, the two xpdf ’s I’m running have it open. (WTF is xpdf permanently grabbing my pcm device?) Kill the xpdf ’s, now artsd can start cleanly, and I have working sound again.
I have no idea how normal users (Ubuntu’s alleged target market) are supposed to handle this. Reboot, most likely. Works for Microsoft.

10-Oct-2006

North Korea

Filed under: humor — jlm @ 17:09

I’ve gotten some inquiries re the song from last night, so here are the lyrics.

Your technicians drilled the bore
You lit the fuse, it shook the floor
You wanted into the nuclear club if it killed ya
I’ve seen your statue below the marble arch
But listen Kim, before you start a victory march
Your country’s a poor and very hungry North Kore-a

My seismometers let me know
What really went on below
You want to pretend it was not a dud, do ya?
But remember yeah we did testing too
Vaporized part of Eniwetok Atoll like the morning dew
And the Marshalls weren’t that far from North Kore-a

Maybe push will come to shove
But remember when we took off the glove
And pushed you back from Pusan to Seoul, ha
Even the Chinese want your ear tonight
They’re not laughing now that you’ve made the Sun’s light
No it’s a close and a very pissed off Chin-a

Our talks didn’t work; they weren’t much
But you couldn’t talk so you decided to punch
I fooled my people I bet I can also fool ya
Yeah and even if it all goes wrong
I believe Armageddon won’t be long
With my hands lifted for a Hallelujah

Apologies to Leonard Cohen.

Powered by WordPress