Like Tree1Likes

Quick question on mathematical notation (translating to C)

This is a discussion on Quick question on mathematical notation (translating to C) within the General Discussions forums, part of the Community Boards category; I came across a mathematical statement in the form of: (log x)^-1 log y log log z Is that equivalent ...

  1. #1
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151

    Quick question on mathematical notation (translating to C)

    I came across a mathematical statement in the form of:

    (log x)^-1 log y log log z

    Is that equivalent to the C expression:

    pow(log(x), -1)*log(y)*log(log(z))
    Last edited by gardhr; 09-16-2011 at 09:07 PM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Quote Originally Posted by gardhr View Post
    I came across a mathematical statement in the form of:

    (log x)^-1 log y log log z

    Is that equivalent to the C expression:

    pow(log(x), -1)*log(y)*log(log(z))
    Not sure, maybe it is:

    Code:
    pow(log(x), -1)*log(y*log(log(z)))
    I just can't remember the mathematical precedence of logarithms.

    EDIT: By "remember" I mean "recall", that is.
    Last edited by GReaper; 09-16-2011 at 09:32 PM.
    Devoted my life to programming...

  3. #3
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Hmm. Using Google's calculator, it resolves to the code that I posted, with one important difference: it's assuming I mean log10, not the natural logarithm. Is that a fairly standard assumption in mathematical notation?

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    According to the standard([EDIT]: Copy of C99 that I have[/EDIT]) log(x) computes log base e (natural) log of x. log10 functions return the log base 10 of x.
    Last edited by AndrewHunter; 09-16-2011 at 10:23 PM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    I'm pretty sure that's what the equation in question implies, too, but there does seem to be some inconsistencies in convention. For example, you often see "ln" used to distinguish natural logarithm, and now that I think of it, most hand calculators use "log" for log10. Argh!

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by gardhr View Post
    I'm pretty sure that's what the equation in question implies, too, but there does seem to be some inconsistencies in convention. For example, you often see "ln" used to distinguish natural logarithm, and now that I think of it, most hand calculators use "log" for log10. Argh!
    There have been no "inconsistencies" according to the standard, AFAIK.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by gardhr
    it's assuming I mean log10, not the natural logarithm. Is that a fairly standard assumption in mathematical notation?
    If log rather than lg or ln is used, I think that that depends on context. Perhaps the author specified the base elsewhere, or the base does not matter in the big picture (e.g., this is part of some notation for algorithmic complexity), or the author assumed the base due to convention in his/her specialisation.

    Incidentally, I would translate x^-1 as (1/x) to avoid a function call that seems overkill.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by gardhr View Post
    I'm pretty sure that's what the equation in question implies, too, but there does seem to be some inconsistencies in convention. For example, you often see "ln" used to distinguish natural logarithm, and now that I think of it, most hand calculators use "log" for log10. Argh!
    You should specify "C code" and "math code" here then.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,295
    Assuming ^ is "to power of", then p^-1 is equivalent to 1/p (if p is a real or complex value).

    As to "log y log log z" you need to be clear what that means. It is ambiguous, mathematically, as brackets or anything else that might give context (such as font sizes) have been left out. It could be log(y)*log(log(z)) or it could be log(y*log(log(x))

    Mathematically, "log" can mean common logarithm (log10() in C) or natural logarithm (log() in C). Conventionally, common logarithm is the more usual meaning. But, to be sure, you need to read the article (or whatever) that you got the formula from.
    AndrewHunter likes this.
    Right 98% of the time, and don't care about the other 3%.

  10. #10
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by grumpy View Post
    Assuming ^ is "to power of", then p^-1 is equivalent to 1/p (if p is a real or complex value).

    As to "log y log log z" you need to be clear what that means. It is ambiguous, mathematically, as brackets or anything else that might give context (such as font sizes) have been left out. It could be log(y)*log(log(z)) or it could be log(y*log(log(x))

    Mathematically, "log" can mean common logarithm (log10() in C) or natural logarithm (log() in C). Conventionally, common logarithm is the more usual meaning. But, to be sure, you need to read the article (or whatever) that you got the formula from.
    Thanks as always for spelling out what I failed to do.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  11. #11
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Okay, so I guess I'll assume log == natural logarithm since that seems to be the most common usage.

    I'm pretty sure now that the correct interpretation here is log(y)*log(log(z)), too, from the context of the article.

    Thanks for the input everyone!

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by gardhr
    I'll assume log == natural logarithm since that seems to be the most common usage.
    Then when it turns out that your assumption is wrong... if the base really was not specified anywhere, is there an example of the calculation that you can refer to? Is this "pure" mathematics? Is this engineering?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Umm....Laser the base is assumed per the standard....: confused : <on purpose>
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  14. #14
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by laserlight View Post
    Then when it turns out that your assumption is wrong... if the base really was not specified anywhere, is there an example of the calculation that you can refer to? Is this "pure" mathematics? Is this engineering?
    I'm basing it on the heuristic that most papers written about number theory seem to use that convention.

    Specifically, it's a lower bound given for the Miller-Rabin primality test, described here. I'm trying to work out an approximation using only integer math.

  15. #15
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by AndrewHunter View Post
    Umm....Laser the base is assumed per the standard....: confused : <on purpose>
    Yes, but common practical usage varies (depending on the discipline), as laserlight pointed out.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 06:44 AM
  2. big O notation question
    By l2u in forum C++ Programming
    Replies: 7
    Last Post: 11-08-2008, 02:53 PM
  3. [OT] help translating and phrazing
    By jabka in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2007, 11:37 AM
  4. Code translating
    By Liger86 in forum C Programming
    Replies: 3
    Last Post: 12-27-2002, 08:31 AM
  5. Mathematical Question
    By rmullen3 in forum C++ Programming
    Replies: 4
    Last Post: 12-29-2001, 08:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21