Compartilhar via


Logs, Lns and Log10: OneNote gets it right

 

As I mentioned before, one of the areas of OneNote I took when I came to the team was what we call "Napkin Math."  This the ability to type equations like

8-4=        And getting a "4" when you press Enter or the spacebar.

 

It also works for basic trigonometric functions like

Sin(45)=0.707106781186547 (note this is based on 90 degrees)

 

So far, so good.  But I hit a snag with logarithms.

 

Try this:

Case 1: Type

Ln(2.718)=

And hit enter.  You get 0.999896315728952, right?

 

Great.  This is the natural log of 2.718.

 

Case 2:

Now try:

Log10(100)=

And hit enter (or space).  You get 2, right?  This is the base 10 log of 100, and again, OneNote gets it right.

 

Case 3:

Now try this:

Log(10)=  

And you get 2.302585092994046.  Hmm.  What number raised to 2.302585092994046 results in 10?  The answer is e, the natural log.  OK, mathematically, this makes sense, but every textbook I've used in school would say log(10)=1. 

 

All of my textbooks, and the Windows & Macintosh calculators, Excel and probably every physical calculator would evaluate log(10) as being base 10.  So here OneNote is in seeming disagreement with the rest of the (English speaking) world.  Based on this unexpected behavior, I entered a bug in our database.  My next task was to help figure out where things went wrong and help develop a plan to fix the problem.

 

As it turns out, nothing is wrong.  Here's why.

 

As I typically do when OneNote does something I do not understand, I went to talk with Irina, another tester on our team.  She has a Master's degree in Math, and since I only have a BA in Math, she automatically knows more than me.  She said it's only in America that log(x) has any meaning, as most math books in the rest of the world use lg(x) to denote base 10 logs.  Hmm, and an interesting clue.  What to do?

 

I turned next to the fountain of all human knowledge: the internet.  And buried in the National Institute of Standards and Technology documentation about how to represent just about any mathematical expression in typography , I found exactly how logarithms are expected to be typeset [in section 10.1.2].  Here's the link, and what follows is the gist of it as it relates to logs:

 

ln x

(ln x = loge x)

lg x

(lg x = log10 x)

 

And to specify base 10?

loga x

(logarithm to the base a of x)

 

And here is where OneNote is right, and most other math apps get it wrong.  To get a base 10 log, we expect you to tell us the base 'a' by typing log10(1000) to compute "3".  Instead of assuming you mean "10" if you do not specify a base, we use "e" - the gels with behavior seen in the real world.  Now that I understand it's going to use "e" as the base, I'm happy with the behavior.

 

By the NIST guidelines, an equation like log(8) has no meaning since the base is not specified.  The behavior we show, which returns a natural log in this case, sort of makes sense now.  Since we do not know the base, we default to using natural logs.  This is the same behavior as MATLAB, by the way.

 

Since OneNote obeys the NIST standards, my bug report came back as "Won't Fix," and Dan Escapa suggested I blog about why.  This is why.

 

Questions, comments, concerns and criticisms always welcome,

John

Comments

  • Anonymous
    October 11, 2007
    PingBack from http://www.artofbam.com/wordpress/?p=7414

  • Anonymous
    October 30, 2007
    I would make the use of Log and Ln consistent with Excel. Seems inconsistent that OneNote outputs: -1^2 = 1 but 0-1^2 = -1 I would think that -1^2 = -1 and (-1)^2 = 1. Excel does the same thing, though.

  • Anonymous
    November 01, 2007
    Yep, that order of precedence bug you mention is logged already.  As part of our automation push this week, I added a new formula to test for exactly that.  Try this: 1/2*2=0.25 but that is wrong by the order of precedence of arithmetic.  ON should evaluate the operations from left to right, since divide and multiply are at the same level. It should have been parsed as (1/2)*2=1 As far ON doing what Excel does... I'm not 100% sold.  The specification is vague as to what the expected result is - literally, it gives no guidance whatsoever.  Excel defaults to doing what the US default is, and ON defaults to what Europeans and Russia textbooks use.  Different behavior for different markets, I suppose.  And FWIW, the spec should really define what to do for undefined cases (such as always return an error or the like). John

  • Anonymous
    December 05, 2007
    The comment has been removed

  • Anonymous
    December 05, 2007
    The comment has been removed

  • Anonymous
    December 05, 2007
    Oh, and check out this addin Stephen Lawrence created for Matlab to OneNote (it's only a few lines, if I remember correctly): http://www.onenotepowertoys.com/2007/06/21/matlab-to-onenote/

  • Anonymous
    February 17, 2008
    I just ran across this blog after debugging an Excel spreadsheet.  Although Excel's log function wants to take two arguments, if you only give it one it happily defaults to base 10.  This threw me for a bit since I didn't check one particular calculation for a while.  Many other programming languages like C, Perl, Python, and so on use log to mean natural log.  So I think OneNote's interpretation is most in sync with common usage.  The other option (perhaps less dangerous?) is to make it undefined or complain if only one argument is given.  IMO, Excel is a poor model to go by.

  • Anonymous
    September 01, 2008
    thanks i dont get why it puts an E in the answer