Live data from Hacker News

The Lost Art of Logarithms

lostartoflogarithms.com

1–10 of 204 posts

Re: The Lost Art of Logarithms

#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 basic log rules in order to the correct exponent. I learned all this in high school, but some of my coworkers thought I was using this amazing, arcane bit of math that had never been seen before. I guess they never use log outside of Big-O notation.

Re: The Lost Art of Logarithms

#3
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.

Re: The Lost Art of Logarithms

#4

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".

Re: The Lost Art of Logarithms

#6

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.

Well, currently exponentiation has a superscript exponent to the right of the base, and logs have a subscript base to the left of the exponent. They're already very similar to your example, but they also include the word "log".

Re: The Lost Art of Logarithms

#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!

Re: The Lost Art of Logarithms

#9
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 usually closer to Integer.numberOfLeadingZeros, but that’s just a bitshift away.)

Re: The Lost Art of Logarithms

#10

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".

The Triangle of power explanation of logarithms is what really got me across logs.

It wasn't until seeing the triangle and having the relationships explained that I had any clue about logarithms, up until then logs had been some archaic number that meant nothing to me.

Because of the triangle of power, I now rock up to B and B+ Trees and calculate the number of disc accesses each will require in the worst case, depending on the number of values in each block (eg, log2(n), log50(n) and log100(n))

Post reply on HN