jimrandomh comments on Automatic programming, an example - Less Wrong

12 Post author: Thomas 01 February 2012 08:55PM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (32)

You are viewing a single comment's thread. Show more comments above.

Comment author: wmorgan 01 February 2012 10:10:13PM *  9 points [-]

The generated code is bizarre. I refactored it as well as I could, and it still doesn't make much sense:

aphelion = (aphelion + perihelion) >> 10;
aphelion = aphelion - (aphelion / 12);
guess = ( ( (aphelion | 12) * (int)sqrt(aphelion) ) ^ 12 ) / 12;

"To get the orbit time in days from the aphelion and perihelion in Kkm, first sum them and divide by 1024. Then from that, subtract one twelfth. Then, to the value, perform a bitwise OR with 0x0C, multiply by the square root, and bit-XOR 0x0C again. Finally, divide by 12, and that will give you the number of days."

Comment author: jimrandomh 02 February 2012 02:03:55AM 28 points [-]

The three problems with the code are that the variable names are all lies, there's a bunch of redundant rescaling which isn't consolidated because it's done in integer math when it should be floating point, and there are a couple bits of overfitting (bitwise operators) that don't belong. If you convert to SSA and wipe out the misleading names, you get:

a1 = perihelion+aphelion Real
a2 = a1+a1 Rescaling
a3 = a2+a2 Rescaling
g1 = 12 Rescaling
a4 = a3>>g1 Rescaling
t1 = a4/g1 Rescaling
a5 = a4-t1 Rescaling
d1 = sqrt(a5) Real
a6 = g1|a5 Overfit
a7 = a6*d1 Real
a8 = g1^a7 Overfit
guess = a8/g1 Rescaling

If you replace the overfitting with pass-throughs (a6=a5, a8=a7), then pretend it's floating point so that you can consolidate all the rescaling into a single multiplicative constant, you get

guess = k * (perihelion+aphelion)*sqrt(perihelion+aphelion)

Which is Kepler's third law.