6 ms·
Log(x) vs. ln(x) – The curse of scientific computing
- contravariant 10y agoAll his examples use log(x) as the natural logarithm of x. I fail to see the confusion.
- ktamiola 10y agoExamples? 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 10y agoThe 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 10y agoNothing 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
- gaze 10y agoHah. 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
- ktamiola 10y agoThere you go! It is a freaking zoo of formalism!
- madengr 10y agoI 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.
- ktamiola 10y agoAnd that's exactly why it is such an annoying problem to spot and debug!
- throwaway_374 10y ago>>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 10y agoJust 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.
- Y_Y 10y agoI 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 10y agoI 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 10y agoI 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 10y agoI 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 10y agoWell my anecdatum, as a theoretical physicist, is that people very rarely write `log` or use logarithms is bases other than e.
- ktamiola 10y agoI had a one more look at the article, and you are right! I need to add an log(10) = 2.303 example
- NiceGuy_Ty 10y agoAre unit tests insufficient to catch these kinds of mistakes?
- ktamiola 10y agoThey 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.