Live data from Hacker News

The Lost Art of Logarithms

lostartoflogarithms.com

11–20 of 204 posts

Re: The Lost Art of Logarithms

#11
post #2

I started using LMAX Disruptor for some projects. One quirk with Disruptor is that the queue size always has to be an exponent of two. I wanted to make sure that I always have at least enough room for any size and I didn't want to manually compute, so I wrote this: var actualSize = Double.valueOf(Math.pow(2, Math.ceil(Math.log(approxSize) / Math.log(2)))).intValue(); A bit much for a single line, but just using some…

This is perfectly usable, of course, but I’d write var actualSize = Integer.highestOneBit(approxSize - 1) purely to avoid involving the horrors that live beneath the humble pow() and log(). (Integer.highestOneBit, also known as “isolate leftmost bit”, “most significant one”, or the like, essentially has to be a primitive to be efficient, unlike its counterpart for the lowest bit, x&-x. The actual CPU instruction is u…

That's pretty cool; I didn't even consider doing any cool bitwise arithmetic.

I didn't particularly care about performance or anything for this particular case, since it runs exactly once at the start of the app just to initiate the Disruptor.

Re: The Lost Art of Logarithms

#12
post #2

I started using LMAX Disruptor for some projects. One quirk with Disruptor is that the queue size always has to be an exponent of two. I wanted to make sure that I always have at least enough room for any size and I didn't want to manually compute, so I wrote this: var actualSize = Double.valueOf(Math.pow(2, Math.ceil(Math.log(approxSize) / Math.log(2)))).intValue(); A bit much for a single line, but just using some…

Just shift the size to the right 1 bit and count the shifts until the value turns to zero, and you'll get your number 2 exponent for the size :)

Re: The Lost Art of Logarithms

#13
post #5

Is this the same author who wrote Win32 API books?

Yes the office door stop as it was known as at our place. Top book though just faded in utility and no one had the heart to dispose of it because of the good memories.

Re: The Lost Art of Logarithms

#14

Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.

https://mathcenter.oxford.emory.edu/site/math108/logs/ Some people have suggested the "triangle of power".

Yea; this owns. I used it for my own stuff.

Re: The Lost Art of Logarithms

#15
post #8

Charles Petzold wrote one of my favorite books - "Code: The Hidden Language of Computer Hardware and Software". Very excited to see how this turns out and thanks for giving some of this knowledge away for free!

I would also recommend the "NAND to Tetris" book. Covers much the same ground (as I remember things anyway) but is a hands on approach. I enjoyed Code also though and is worth a look for those interested.

Re: The Lost Art of Logarithms

#16

Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.

https://mathcenter.oxford.emory.edu/site/math108/logs/ Some people have suggested the "triangle of power".

I never understand why anyone thinks its good notation. The layout means nothing and lets you infer nothing because exponentiation isn't a 2d planar geometric operation. All the information and rules are contained in the idea "exponentials map the additive reals to the multiplicative reals".

The notation conveys no information at all, and provides no means of proving anything, and even the notation for function composition is worse.

Given the operator pow : R^2->R there are 2 possible inverses. root and log

root isn't even interesting. its just pow with the 2nd argument precomposed with reciprocal. root x b = pow x 1/b

Re: The Lost Art of Logarithms

#17
post #8

Charles Petzold wrote one of my favorite books - "Code: The Hidden Language of Computer Hardware and Software". Very excited to see how this turns out and thanks for giving some of this knowledge away for free!

[deleted]

Re: The Lost Art of Logarithms

#18
post #13
post #5

Is this the same author who wrote Win32 API books?

Yes the office door stop as it was known as at our place. Top book though just faded in utility and no one had the heart to dispose of it because of the good memories.

Good book indeed, just that I wouldn't use a book to look up Win32 API functions.

Re: The Lost Art of Logarithms

#19

Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.

https://mathcenter.oxford.emory.edu/site/math108/logs/ Some people have suggested the "triangle of power".

https://www.youtube.com/watch?v=sULa9Lc4pck

Re: The Lost Art of Logarithms

#20
Here's an logarithmic fact that I've made use of frequently:

If X is a random variable having a uniform distribution between zero and one, then –ln(X)/λ has an exponential distribution with rate λ.

This relationship comes in handy when, for example, you want to draw weighted random samples. Or generating event times for simulations.

Post reply on HN