
Log(x) vs. ln(x) – The curse of scientific computing - ktamiola
https://medium.com/@ktamiola/log-x-vs-ln-x-the-curse-of-scientific-computing-170c8e95310c#.pruprqr7z
======
gaze
Hah. There's also Log vs log. Capital L Log is the set of solutions to
C=exp(z), so is defined up to i _2_ pi*n where n is an integer

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

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

~~~
throwaway_374
>>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)?

~~~
madengr
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.

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

~~~
ktamiola
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](https://en.wikipedia.org/wiki/Protein_pKa_calculations)

~~~
contravariant
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.

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

[http://www4.ncsu.edu/~jwilson/files/mathsigns.pdf](http://www4.ncsu.edu/~jwilson/files/mathsigns.pdf)

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

~~~
ktamiola
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](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.

~~~
Y_Y
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`.

~~~
ktamiola
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.

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

------
NiceGuy_Ty
Are unit tests insufficient to catch these kinds of mistakes?

~~~
ktamiola
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.

