Thread: My grandpa told me a good way to get the absolute value of a number was to...

  1. #16
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Pfft. It would seem that my vocabulary is computationally slanted :P You are correct, by "unsigned number" I was all along referring to a "semantically absolute value".

  2. #17
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Every definition of a function I've ever seen implies a single output value, and sqrt is just another function. You're saying a function returning 2 values, I'm saying it returns a single value.

  3. #18
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by phantomotap View Post

    That is not coincidence.

    That is fact.

    This fact arises because the very definition of roots and multiplication.
    [/Edit]

    Soma
    If pow(x, 1/2) returns 2 values, then does pow(x, 1/3) also return 2 values? It would seem not, since the negative would not work for both cases. That is why I said it was coincidental.

  4. #19
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by MacNilly View Post
    Every definition of a function I've ever seen implies a single output value, and sqrt is just another function. You're saying a function returning 2 values, I'm saying it returns a single value.
    As I said in post #13, technically sqrt returns a set containing a number and another number of the same value but negated (also, a set with 2 numbers is still a single return value, technically all functions have one input and one output). But in practice and application it is much easier to think of it as a single number with an unknown sign.

  5. #20
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    But in practice and application it is much easier to think of it as a single number with an unknown sign.
    O_o

    I agree, to a point, with that statement.

    Considering a practical application, your entry into the discussion was to offer, in your opinion, a more palatable definition. Your claim of "wrongness" for a different palatable definition was my problem because your definition is also wrong.

    If you intend(ed) to speak in the simple for the sake of easy consumption, I'd agree that the result of "square rooting" is unsigned in that one could coerce the signedness of the result for any particular solution.

    Soma
    Last edited by phantomotap; 09-16-2014 at 09:58 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  6. #21
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Only programmers could debate so hard over something so trivial.

  7. #22
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Yeah, I'm honestly really surprised this topic grew as much as it did. I was expecting like 3 posts at a maximum.

  8. #23
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    My --pedantic switch was on.

  9. #24
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by MacNilly View Post
    If pow(x, 1/2) returns 2 values, then does pow(x, 1/3) also return 2 values?
    pow(x,1/2) and pow(x,1/3) in C will both return 1.0, unless x is zero, since 1/2 and 1/3 are both integers equal to zero. pow() only returns a single value.


    As to the mathematics of the square root.

    1) A square root of a value x is a value that, when multiplied by itself, gives x. If x is a real positive value, it has two square roots - one positive and one negative.
    2) Conventionally, the square root sign, as in
    My grandpa told me a good way to get the absolute value of a number was to...-256px-nuvola_apps_edu_mathematics_blue-p-svg-png
    denotes what is formally called the "principal square root" of x, which is the positive square root of x. A lot of math teachers, however, incorrectly describe this as "the square root". The negative of the principal square root is also a square root.
    3) Negative real values also have two square roots, which are called imaginary (and multiplying one of those by -1 yields the other) and one of them (it doesn't matter which one) is given the mathematical symbol "i" so the other one is denoted by "-i". Imaginary and real values can be added, so 2+3i denotes a "complex value" equal to the "real value 2 plus 3 times i".


    If you start talking about the nth root (where n is a positive integer), then then all complex values (including all real values) except 0 have n of them. So any value has three cube roots, four fourth roots, etc etc. At most one of those is real. The rest are complex (i.e. obtained by combining real and imaginary values).



    In C, things with the sqrt() function are much more prosaic. If x is positive value of type double, then sqrt(x) yields the principal (non-negative) square root of x. If x is negative, sqrt(), a domain error occurs.

    (The 1999 C standard also has functions like csqrt() that work with complex values).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #25
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by grumpy View Post
    A lot of math teachers, however, incorrectly describe this as "the square root". The negative of the principal square root is also a square root
    Which is really important in order to understand the formal definition of the square root within the Real number system. The result of a square root, as it is formally defined in mathematics, is a set of two principal square roots. One being negative and the other positive.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Mario F.
    The result of a square root, as it is formally defined in mathematics, is a set of two principal square roots. One being negative and the other positive.
    I think you meant "set of two square roots", though it does not seem to account for the case of zero, which is in the set of real numbers.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I did mean a set of two principal square roots.
    My grandpa told me a good way to get the absolute value of a number was to...-9-21-2014-18-18-30-png

    Meanwhile the square root of zero could be defined the same. The existence of the negative square root of 0 shouldn't be considered an anomaly in elementary algebra (in which 0 is neither positive or negative). The set will still satisfy all elementary algebraic equations.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #28
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Mario F.
    I did mean a set of two principal square roots.
    But a principal square root is non-negative.

    Quote Originally Posted by Mario F.
    Meanwhile the square root of zero could be defined the same. The existence of the negative square root of 0 shouldn't be considered an anomaly in elementary algebra (in which 0 is neither positive or negative). The set will still satisfy all elementary algebraic equations.
    Not an anomaly, but the negative square root of 0 is 0, which as you noted is neither positive nor negative. Since the members of a set are distinct, it thus seems to me that "set of two square roots" does not account for repetition in the square roots of 0.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #29
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by laserlight View Post
    But a principal square root is non-negative.
    It's important to remember that the square root is an operation waiting to be calculated. While we do refer to square roots in the real number line, we do so for convenience. The actual number is the result of that calculation. In other words, the square root symbol is the symbol of an operation, it is not the actual representation of a Real number. So, while the principal square root of 16 returns 4, the negative of the principal square root of 16 returns -4.

    The square root of a number returns the principal square root and the negative of the principal square root. I should have been more clear about that in post #25, since I was talking about formal definitions.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Mario F.
    It's important to remember that the square root is an operation waiting to be calculated. While we do refer to square roots in the real number line, we do so for convenience. The actual number is the result of that calculation. In other words, the square root symbol is the symbol of an operation, it is not the actual representation of a Real number.
    I am not a mathematician, so I would like to check: are you stating this as something that mathematicians generally hold to be true, or is this the way you understand it but (other) mathematicians do not necessarily agree with you? I ask because the Wolfram website starts explaining the concept of square root with "a square root of a number x is a number r such that r**2 = x", rather than "a square root of a number x is an operation to compute r such that r**2 = x" (I use ** to denote exponentiation). I am also cautious about the notions of "the actual number" and "the actual representation of a Real number" since real numbers have multiple representations.

    Quote Originally Posted by Mario F.
    The square root of a number returns the principal square root and the negative of the principal square root. I should have been more clear about that in post #25, since I was talking about formal definitions.
    Yes, this is what I meant when I assumed that you meant "two square roots" rather than "two principal square roots". For a positive real number, the negative of its principal square root is not its principal square root, so your statement in post #25 is wrong.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Good Ole Random Number
    By jimmyn in forum C Programming
    Replies: 9
    Last Post: 10-02-2012, 02:42 PM
  2. I need a really good technical explantion on the absolute value
    By Overworked_PhD in forum C Programming
    Replies: 6
    Last Post: 01-06-2008, 10:43 PM
  3. Told ya so...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 09-12-2007, 08:12 PM
  4. The computer told me...
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-17-2003, 03:48 AM
  5. i was told something and it screwed me up!
    By DarkViper in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2002, 02:02 PM