SQRT delivers only one result

Pages: 123
closed account (48bpfSEw)
it is mathematically incorrect that sqrt(9) is 3. it is -3 too!

How do you handle this problem in your code?
Last edited on
Also, the square root has always been defined as the positive root, which is why you have to put a plus-minus symbol before it, so the sqrt function returning only the positive root is correct.
Last edited on
closed account (48bpfSEw)
@gentleguy, I mean there are two solutions at the same time when using the square root of a value. Considering only the positive one is half of truth...

The function sqrt should deliver all roots!

http://www.wolframalpha.com/input/?source=nav&i=sqrt+(9)


Just google square root function, and it will tell you that it maps the set of all positive numbers on to itself. It's in the very definition of a function that each input only has one output. Also, the sqrt function replicates the standard root operation, which returns a positive value. The plus-minus is not part of the square root function, and is your responsibility to use. Ignoring the mathematical definitions, the only way for the square root function to do this by itself would be to pass in out parameters, which is much more awkward than just running the function twice and negating one.
Last edited on
Because not everyone wants both values. The purpose of a square root function is to return the primary root of a number. This is how it's always been in maths. The bus-shelter like symbol (square root symbol) means return the positive root, and the plus-minus symbol is a separate operation that is used when both values are required. If you want both values, run the function twice and negate one, which is exactly what the plus-minus does.

Also, from a practical standpoint, that would be awkward to use in certain cases, such as if you were chaining functions, or if you expected it to work like the square root function does in maths.
Last edited on
closed account (48bpfSEw)
thank you, you are right. it's a matter of definition a function and it's a matter of responsibility of the programmer to consider all results.
The square root function in maths only gives positive values. That is by definition.

However, if you're talking about 'roots', then things work differently.

For example, x = 4^(1/2) gives positive 2 as the only result, but x^2 = 4 means that x is plus or minus 2.
closed account (48T7M4Gy)
For example, x = 4^(1/2) gives positive 2 as the only result, but x^2 = 4 means that x is plus or minus 2.
That bit's right.

The definition of the square root function goes something like "mathematics : a number that produces a specified number when it is multiplied by itself". So real positive and real negative and complex roots are all there in the definition.

The rest is a limitation of the C++ sqrt() function, not the mathematics function.
No. sqrt() is an implementation of the principal square root, which is written as √x. The principal square root is a non-negative real for all inputs in its domain. That's why, algebraically, √(x^2) = x is false, but √(x^2) = |x| is true. On the other hand, (√x)^2 = x is true.
In texts dealing with complex numbers, you will never see the symbol √ being used for complex roots. When defining the value(s) of a complex y, instead of y = √z you will see z = y^2.
closed account (48T7M4Gy)
Principal Square Root

The unique nonnegative square root of a nonnegative real number. For example, the principal square root of 9 is 3, although both -3 and 3 are square roots of 9.

The concept of principal square root cannot be extended to real negative numbers since the two square roots of a negative number cannot be distinguished until one of the two is defined as the imaginary unit, at which point +i and -i can then be distinguished. Since either choice is possible, there is no ambiguity in defining i as "the" square root of -1.


'Square root' is a mathematical function, the root whether principal or not is a product/result of that function and is a root of the defining equation. The square root symbol is a function-symbol not a root-symbol hence the + or - symbols placed before the roots .
closed account (48T7M4Gy)
In texts dealing with complex numbers, you will never see the symbol √ being used for complex roots.
Oops! : https://en.wikipedia.org/wiki/Square_root
Sorry, I can't tell if you think you're contradicting me, or what exactly you think you're contradicting. You might want to be more explicit in your replies to avoid ambiguities.

The square root symbol is a function-symbol not a root-symbol hence the + or - symbols placed before the roots .
"Function-symbol" and "root-symbol" are not terms I've ever encountered, but in any case √ is a function equivalent to the principal square root.
closed account (48T7M4Gy)
Contradicting people is beneath my dignity. In the case you mention I have given an example where the statement of yours I quoted statement is incorrect.

Moving on.

but in any case √ is a function equivalent to the principal square root.
√ is a mathematical symbol describing/depicting/recording the application of the square root function to it's contents in the same way as an operator if you like. Unfortunately the operation is not equivalent to the principal square root as I quoted above. The principal square root (using the accepted terminology again) is the result of the square root operator, just one of them and not the operation/function itself.

( Interestingly gentleguy has alluded to this in his/her rosy post and offered a suggestion as to how the C++ sqrt() function might one day be improved albeit some people are probably happy with using Boost or somesuch. Of course there are probably higher priorities and there's nothing stopping us from DIY )
√ is a mathematical symbol describing/depicting/recording [...]
Let's not get into semantic games, here. "√" is a mathematical symbol, but √ is a mathematical function. I'm clearly not talking about notation. For all I care, √ and sqrt are the same thing.

in the same way as an operator if you like
Yes, operators are functions.

Unfortunately the operation is not equivalent to the principal square root as I quoted above.
Your quote doesn't contradict the statement "√ is the principal square root".
Look at the article you linked to.
Every non-negative real number a has a unique non-negative square root, called the principal square root, which is denoted by √a, where √ is called the radical sign or radix. [...] Every positive number a has two square roots: √a, which is positive, and −√a, which is negative.


The principal square root (using the accepted terminology again) is the result of the square root operator, just one of them and not the operation/function itself.
You're playing semantic games again. Just like "sine" refers to a function, but "the sine of 1" refers a value, "principal square root" refers to a function and "the principal square root of 2" refers to a value.
The phrase "the principal square root is the result of the square root operator" makes no sense because no such single value exists. You'd have to say "the principal square root of x is the positive square root of x". If we're talking about the principal square root, period, then we're talking about a function: √.
closed account (48T7M4Gy)
So it sounds like we agree with my point that the principal square root is not equivalent to the square root function. Especially since you see no link between the various notations but realise operators are functions are not results of those operators or functions.

It's probably unfortunate that the operator and result are both called square roots and that is where the confusion lays and why the definitions I have submitted have gone to great lengths to clear it up as I did.

The principal square root cannot be anything other than the result of the square root of a number in this context, keeping in mind that the number described by sin(1) can be the result of many operations, even the √ function applied to the appropriate operand (?). Unless I am grossly mistaken there is only one principal square root of a number and there is only one square root function to calculate it. At least that's what the definition and separate quote from Wolfram indicate.
The principal square root cannot be anything other than the result of the square root of a number in this context
No. No one who says "the principal square root" as a complete subject or object in a sentence is talking about a single number.

keeping in mind that the number described by sin(1) can be the result of many operations, even the √ function applied to the appropriate operand (?)
I don't see what that has to do with anything.

So, to recap:
* The square root is a function.
* The principal square root is a function derived from the square root.
* √ is the same function as the principal square root.
* Colloquially, and unless there's a need to emphasize the difference, "the square root" is used interchangeably with "√".
* One might abbreviate "square root" as "sqrt".
* Finally, the C function sqrt() is an approximation of √, not of the true square root.
closed account (48T7M4Gy)
No. No one who says "the principal square root" as a complete subject or object in a sentence is talking about a single number.

Yes. The rest is grammar and semantic misrepresentation of what I wrote which is correct. Given semantics has been unilaterally withdrawn by you from this invaluable discussion, it is now my turn to exclude irrelevant clutching at straws in the form of grammar.

Notwithstanding that, it is still incumbent on helios to prove otherwise or show what the principal square root is if it isn't the product of the square root function. Just one example will do as in my proof that 'never' was the wrong choice of word a while ago.

As far as my comment on sin(1) is concerned my point is sin(1) is about 0.84 and that number, rather than the expression, is definitely the product of the sin function operating on the number 1 (assuming we accept they're radians of course and feel free to argue that into the ground) But 0.84 is also the result of a myriad of unrelated operations such as 1.84 - 1.00, - being the operator. Need I continue? My point is clarified if not completely made.

As far as the numerously and elegantly asterisked items in your recap:
(I like the format so much I'll use it to reply, if I might be so bold.)
* agree - never been any dispute there IIRC
* plainly wrong - the PSR is not a function
* - ditto - saying the same thing twice doesn't make it right 2 * 0 = 0
* very contentious, in fact wrong I would have to say especially so since I doubt whether there is too much colloquial talk around square roots unless you happen to visit Australia, whereupon mathematics is being considered at a very basic level if at all, if you understand the irony of your comment. :)
* one might do that, but that's hardly a lot or even many. One example to prove a universal is hardly convincing. But there again the first would be easier to pronounce unless it is spoken as 'squiggle'.
* as a principal square root factory the sqrt function is eminently accurate at producing them from time to time. sqr(4) = 2 bingo, that myth busted. I think we have discussed 'truth' before and like scientific truth, mathematical truth is a minefield of twists and turns, as interesting as it is, is a completely separate issue but thanks for allowing me this intro on a topic dear to my heart.
Last edited on
closed account (48T7M4Gy)
No one who says "the principal square root" as a complete subject or object in a sentence is talking about a single number

"For example, the principal square root of 9 is 3, although both -3 and 3 are square roots of 9." Myth busted or better ring up Wolfram?
Yes[, some who say "the principal square root" as a complete subject or object in a sentence are talking about a single number].
Okay, then please answer this question: which number is the principal square root? Remember, we're talking about a number, so your answer cannot have any such qualifications as "it depends on what the square root returns" or anything like that, because the moment the value of the principal square root depends on the value of something else, it becomes a function ipso facto.

it is still incumbent on helios to prove otherwise or show what the principal square root is if it isn't the product of the square root function
??? The product by what?
In all seriousness, yes, the principal square root is derived from the square root. Specifically,
principal_square_root: [0, +inf) -> [0, +inf)
such that
principal_square_root(x) = |square_root(x)|
I challenge you to give any other definition of the symbol that makes any sense.

As far as my comment on sin(1) is concerned my point is sin(1) is about 0.84 and that number, rather than the expression, is definitely the product of the sin function operating on the number 1 (assuming we accept they're radians of course and feel free to argue that into the ground) But 0.84 is also the result of a myriad of unrelated operations such as 1.84 - 1.00, - being the operator. Need I continue? My point is clarified if not completely made.
I still fail to see how this is relevant to the conversation. What can we deduce from the statements you're making here?

one might do that, but that's hardly a lot or even many. One example to prove a universal is hardly convincing. But there again the first would be easier to pronounce unless it is spoken as 'squiggle'.
So "sqrt" does not stand for "square root"? It's an amazing coincidence then that the squiggle function just happens to closely approximate √, at least for all valid floating point inputs to sqrt(). Who knows, maybe squiggle does weird things for irrational inputs. We'll just never know.
closed account (48T7M4Gy)
Okay, then please answer this question: which number is the principal square root?
It is the positive root given the definition in that it is one of the two roots of the defining quadratic. Or it is the root that is positive which happens to be a square root. 'Square' being that both roots are of the same magnitude (but of opposite sign) - they form a square, as in a cube root forming a cube.

Remember,
How can I forget

we're talking about a number
Absolute agreement there.

so your answer cannot have any such qualifications as "it depends on what the square root returns" or anything like that,
Well, in all honesty I can't quickly find where I said anything like that. I don't deny I might have at this stage. If you like to post a complete quote of mine I'll be happy to explain where you have misunderstood me and got that wrong too.

because the moment the value of the principal square root depends on the value of something else, it becomes a function ipso facto.
I know you like the phrase 'ipso facto' from elsewhere but it carries no weight even to a seasoned latino. But all ethnicity to a side, I would argue the root does depend on something else but not a function. Mathematically the root is built in to the originating quadratic and is only 'revealed' by the square root function, along with its partner. Ergo, the root is not 'ipso facto' a function !QED, as they say.

it is still incumbent on helios to prove otherwise or show what the principal square root is if it isn't the product of the square root function
??? The product by what?
Exactly my point! I suspect you might be mixing up 'product', perhaps incorrectly thinking I was referring to multiplication, so delete 'product' and substitute it with 'result' and perhaps that makes my challenge to you more clear.

In all seriousness,
Timely
yes,
Very positive
the principal square root is derived from the square root.
Arguably so, but semantics and grammar are out.
Specifically,
thats mathematics for you
principal_square_root: [0, +inf) -> [0, +inf)
As a range, yes, complex numbers are a worry though. Late edit: -inf ?
such that
Yes, I'm still here
principal_square_root(x) = |square_root(x)|
Well a couple of points - with asterisks:
* on face value reasonable but why bother because it has never been in dispute, so we can say it is a recap of the obvious
* arguably, again, given that the square root function produces both, the expression is just a way of selecting one of the two to meet the secondary aspect of a principal root.
* nevertheless we can definitely add the expression to our valued tools of trade

I challenge you to give any other definition of the symbol that makes any sense.
that's an easy one. I did right at the start along with a few other posts IIRC from other ppl.

As far as my comment on sin(1) is concerned my point is sin(1) is about 0.84 and that number, rather than the expression, is definitely the product of the sin function operating on the number 1 (assuming we accept they're radians of course and feel free to argue that into the ground) But 0.84 is also the result of a myriad of unrelated operations such as 1.84 - 1.00, - being the operator. Need I continue? My point is clarified if not completely made.
I still fail to see how this is relevant to the conversation. What can we deduce from the statements you're making here?
I am never wrong. Numbers can come from all sorts of directions, not just the sin functionor dreaded squiggle.

one might do that, but that's hardly a lot or even many. One example to prove a universal is hardly convincing. But there again the first would be easier to pronounce unless it is spoken as 'squiggle'.
So "sqrt" does not stand for "square root"?
No not at all, of course it does to most of us familiar with a small amount of mathematics. I am just saying if a complete outsider who had never seen our alphabet, saw the symbol and no help 'squiggle' might be the response - of course in their own language, where it is unlike to be square anything.

It's an amazing coincidence then that the squiggle function just happens to closely approximate √, at least for all valid floating point inputs to sqrt().
Not for me is there any coincidence, but who am I to say how easily some ppl are amazed?

Who knows,
or cares?
maybe squiggle does weird things for irrational inputs.
Depends on what 'weird' means here because number theory says exactly what an irrational number is and what happens when an irrational number is encountered.
We'll just never know.
Unless you don't understand number theory and have unreasonable expectations of a perfectly defined/accurate answer.
Last edited on
Pages: 123