FeepingCreature 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: FeepingCreature 02 February 2012 11:33:06AM 4 points [-]

Am I crazy? A right shift by 10 is equivalent to a division by 2^10. 2^10 is 1024..

Comment author: Thomas 02 February 2012 05:28:46PM *  2 points [-]

No. The posted code has a bit shift right for 12 places. The already optimized code by wmorgan has a bit shift for only 10 bits.

The metacommand $RESCOM if while val_operation inc_dec caused this. Having two constants (10 and 12) would be undesirable be cause of this "val_operation" and therefore only the constant 12 was used.

Comment author: wmorgan 02 February 2012 07:18:41PM 1 point [-]

This is the generated code segment:

aphelion=aphelion+aphelion;
aphelion=aphelion+aphelion;
guess=12;
aphelion=aphelion>>guess;

Those four lines together amount to a shift 10 bits to the right, i.e., division by 1024.

I think you understand what's going in the code. The point of my refactoring was to make something that was human-readable: something that I could describe in English. And the English for those four lines of code is "divide by 1024." That's what those four lines do.

Comment author: jimrandomh 02 February 2012 07:13:33PM 1 point [-]

The extra two places of bit shifting cancel with two previous self-additions.

Comment author: Thomas 02 February 2012 07:29:21PM 1 point [-]

I know and I agree with this.

Then you have two different constants (10 and 12). One for the shifting and another for the division. It's nothing wrong with that, but the simulator was prevented to have more constants then absolutely necessary. So everything was done with the "12" and I was discussing that.