Hacker News new | past | comments | ask | show | jobs | submit login
Log(x) vs. ln(x) – The curse of scientific computing (medium.com/ktamiola)
18 points by ktamiola on Feb 25, 2017 | hide | past | favorite | 18 comments



Hah. There's also Log vs log. Capital L Log is the set of solutions to C=exp(z), so is defined up to i2pi*n where n is an integer


There you go! It is a freaking zoo of formalism!


I thought it was common programming knowledge that ln(x) is log(x), and log(x) is log10(x).

As an EE, I use both frequently. Seems a lot of errors could be avoided by just comparing your code to a simple hand calculation. I suppose few do that these days.


And that's exactly why it is such an annoying problem to spot and debug!


>>that ln(x) is log(x), and log(x) is log10(x).

Can you clarify what you mean? Are you missing a log_e_(x)?


Just that all languages and CAD environments I have used define log(x) as natural logarithm, and log10(x) and base 10 logarithm. Again, this is common knowledge in engineering programming, but maybe not so in general programming.


All his examples use log(x) as the natural logarithm of x. I fail to see the confusion.


Examples? Which examples? Do you mean the snippets of documentation I am attaching at the end? Sure, they do!

The problem is the actual math/physics formalism is not!

https://en.wikipedia.org/wiki/Protein_pKa_calculations


The article you link would is about biology, not only that but Wikipedia has to try to be consistent across various fields, unlike mathematics and physics where the natural logarithm is used almost exclusively, so it makes sense to use a more explicit notation.

Sure physics (and sometimes mathematics) do use the notation 'ln' every so often (if only because it's shorter) but you'd be hard pressed to find a reference in anything related to mathematics or physics that uses log as the base 10 logarithm.

Clearly the easiest way to avoid the ambiguity is to only ever use the natural logarithm, which is the choice made by all the programming languages you listed at the end. And since you don't list any references where log should refer to the base-10 logarithm I'll have to conclude that they made the right choice.


Nothing is as easy as both of us wish it was :)

http://www4.ncsu.edu/~jwilson/files/mathsigns.pdf


I think this guy is just wrong, except maybe in saying that `log` is ambiguous and we should be using `log10` and `ln`. Incidentally he uses comma as both a thousand separator and a decimal point in the article.


I am afraid I am not. I wish I was, as it would save me ridiculous amount of time and work.

Start reading here: https://en.wikipedia.org/wiki/Protein_pKa_calculations

This is just the tip of the "log(x) vs ln(x)" iceberg.

I have copy pasted the ln(10) straight from Apple Calc. Thanks for pointing out.


I mean in your assertion that `log` must mean `log10`. I have huge sympathy for contending with inconsistent use of ambiguous notation. My pet hate is `gamma` vs. `tgamma`.


I wouldn't dare to suggest that, yet that's the route that physics and all derivatives have adopted!

We are essentially at the crossroad and obviously, programming, which develops nowadays a bit faster than theoretical physics or mathematics, pushes in one direction.


Well my anecdatum, as a theoretical physicist, is that people very rarely write `log` or use logarithms is bases other than e.


I had a one more look at the article, and you are right! I need to add an log(10) = 2.303 example


Are unit tests insufficient to catch these kinds of mistakes?


They are for sure! Obviously, all depends on the complexity of the problem and the willingness of programmers to install tests :/

In my company, we are ridiculously pedantic about unit testing, but even with proper level of attention to detail we sometimes fail with getting 100% code coverage.

The biggest pain are log(x)/ln(x) issues in numerical optimization.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: