• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Dumb Square Root Ques.

matabiri said:
Also, the sqrt() function is defined as returning only the positive root, and this is what is being implemented.
This is because the original Fortran developers didn't feel like dealing with a multiple-value return mechanism.

rppa said:
Two responses. First of all, how do you suggest it return two solutions?
Implementation detail. Common Lisp does it just fine.

Actually, no. In mathematics, the term "square root" of a positive real number A is reserved for the positive solution of x^2 = A. It's the "principal" solution to this equation, the principal root of x^2 - A.
Cop out.

Dr. Kitten said:
Because in order to talk about the square root function, by definition, it needs to have a unique value (for each input).
A tuple is a perfectly good thing for a function to return.

Face the music, folks. It's lazy software developers.

:D

~~ Paul
 
Paul C. Anagnostopoulos said:
[A tuple is a perfectly good thing for a function to return.

Face the music, folks. It's lazy software developers.

:D

~~ Paul
On the contrary - lazy documenters. The Solaris man page says:
<pre>
DESCRIPTION
The sqrt() function computes the square root of x.
</pre>
But the HP-UX man page says:
<pre>
DESCRIPTION
sqrt() returns the non-negative square root of x.
</pre>
Other than that it is a matter of knowing how to use your tools. If you know what your function is returning and you know your maths then it should not matter as long as it is documented properly.

You may as well ask why it returns a rational number for the square root of 2. Why doesn't a function called pi() actually return pi?

You should get Mathematica if you want your programming language to do your maths for you.
 
Paul C. Anagnostopoulos said:

Face the music, folks. It's lazy software developers.Paul

To be an actual function, and not just a mapping, it has to pass the straight line test.

If you can draw a straight line on the graph, anywhere, and cross the graph twice, then it is not a function.

If the sqrt() function returned, in addition, negative values, , it would fail this test.
 
jzs said:
To be an actual function, and not just a mapping, it has to pass the straight line test.

If you can draw a straight line on the graph, anywhere, and cross the graph twice, then it is not a function.

If the sqrt() function returned, in addition, negative values, , it would fail this test.
Not that a programming language function needs to conform to the mathematical definition, but according to Mathworld:

A function is a relation that uniquely associates members of one set with members of another set.

In other words the set of returned values can be tuples.
 
Robin said:

In other words the set of returned values can be tuples.

"uniquely" is the keyword there.

Functions are many-to-one or one-to-one.

Later on down the page,

"Unfortunately, the term "function" is also used to refer to relations that map single points in the domain to possibly multiple points in the range. These "functions" are called multivalued functions (or multiple-valued functions), and arise prominently in the theory of complex functions, where the presence of multiple values engenders the use of so-called branch cuts."

so they're not functions in the standard use of the word.


http://mathworld.wolfram.com/Function.html
 
jzs said:
To be an actual function, and not just a mapping, it has to pass the straight line test.

If you can draw a straight line on the graph, anywhere, and cross the graph twice, then it is not a function.

If the sqrt() function returned, in addition, negative values, , it would fail this test.

So f(x) = x*x is not a function? Doesn't sound right to me. Do you perhaps mean a straight line parallel to the y axis?

--Terry.
 
jzs said:
"uniquely" is the keyword there.

Functions are many-to-one or one-to-one.

Later on down the page,

"Unfortunately, the term "function" is also used to refer to relations that map single points in the domain to possibly multiple points in the range. These "functions" are called multivalued functions (or multiple-valued functions), and arise prominently in the theory of complex functions, where the presence of multiple values engenders the use of so-called branch cuts."

so they're not functions in the standard use of the word.


http://mathworld.wolfram.com/Function.html
That is right, but it says "Uniquely" to a member of a set. A member of a set does not need to be a number, it can be a tuple, a vector, a string, an imaginary number, another set. The definition of function that relates to the set of real numbers is a subset of the generic definition.

In any case we are talking about computer programming which does not need to follow the rules. In any good programming language a function can return any datatype that can be defined, including arrays and aggregates.

From Terry
So f(x) = x*x is not a function? Doesn't sound right to me. Do you perhaps mean a straight line parallel to the y axis?
I assumed that was what was meant.
 
Terry said:
So f(x) = x*x is not a function? Doesn't sound right to me. Do you perhaps mean a straight line parallel to the y axis?

--Terry.

I should have said 'vertical' line instead of straight.
 
new drkitten said:
Um, it's the principal square root of negative one.

If you know enough to make nit-picky corrections to my earlier post, you already know the answer to your question.
Yeah, just engaging in some Socratic questioning, to point out the circularity: The principal square root of -1 is i. What is i? It's the principal square root of -1. The inability to truly give a solid definition of i is, of course, related to the self-isometry of the complex numbers.

Robin
That is right, but it says "Uniquely" to a member of a set. A member of a set does not need to be a number, it can be a tuple, a vector, a string, an imaginary number, another set.
Are you saying that a vector etc. is not a number?

In any case we are talking about computer programming which does not need to follow the rules. In any good programming language a function can return any datatype that can be defined, including arrays and aggregates.
Every function, mathematical or computational, must return a single value. That value may be a composite, but it is still a single value. According to my understanding of CS, functions are handled through stacks in most programming languages, so that after the function runs there is a stack left over that represents the return value(s). A programmer writing code through a compiler might see several different return values, but as far as the actual program is concerned, there is only the one stack. Mostly a semantic issue, but the point is that it's not that computer programming doesn't "follow the rules"; it's just that the rules apply slightly differently.
 
Originally posted by Art Vandelay
Are you saying that a vector etc. is not a number?
Wow, you really are picky aren't you? Yes a vector is a number but it can consist of more than one number. But a tuple might not be a number, it might consist of any type of value. A string is not a number although it can be represented by numbers. A set is not a number. The vertical line on an x-y axis test will only hold for a function R->R and so is not the be all and end all test for a function that jzs claims it is.
Every function, mathematical or computational, must return a single value. That value may be a composite, but it is still a single value. According to my understanding of CS, functions are handled through stacks in most programming languages, so that after the function runs there is a stack left over that represents the return value(s). A programmer writing code through a compiler might see several different return values, but as far as the actual program is concerned, there is only the one stack. Mostly a semantic issue, but the point is that it's not that computer programming doesn't "follow the rules"; it's just that the rules apply slightly differently.
A mathematical function must map onto a single member of a set, but a single member of a set can be anything you want it to be including another set.

A computational function may do whatever the software developers damn well want it to do, so an Informix 4GL function may return more than one value. The internals of how this is handled is irrelevant, but it is the nature of a stack that you can push many values on it. In general, however, programming languages adhere to the definition of a function from discrete mathematics.
 
While I suppose a calculator, etc, that remembers each case where you've asked for a multivalued result (1/N power for for integer N for a simple example) and continues on with the calculations, recalling all possible branches for all possible such values isn't impossible...

It's going to be hard to understand the output. It won't take many such functions to create a huge mass of results, some of which may be the same as others numerically, some not, etc, etc.

There are some interesting "results" that have come out of multiple-root issues in history, too :) There are a great number of ways people have gone wrong...
 
Art Vandelay said:
Yeah, just engaging in some Socratic questioning, to point out the circularity: The principal square root of -1 is i. What is i? It's the principal square root of -1. The inability to truly give a solid definition of i is, of course, related to the self-isometry of the complex numbers.

Eh? i is defined as "the number which, when multiplied by itself, gives -1" isn't it? No square root in there at all...

Mind you, -i also fits that definition, I suppose...
 
new drkitten said:
And my algebra textbook does phrase the Fundamental Theorem of Algebra as implying n complex roots for an n-th degree polynomial. Of course, complex numbers were well-established by the time Gauss proved the FTA, and the specific question of how many roots a given polynomial possessed had been asked -- and mis-answered-- many times before. (The claim of n solutions dates back to the 1600s, I think.)

My Complex Analysis book gives the "n roots for an n order polynomial" as a corrollary to the Fundamental Theorem. I think I understand why. Given that for any polynomial, f(x), of degree n, there exists one root, call it x0, then that means that the polynomial can be written as

f(x) = (x - x0)g(x)

where g(x) is a polynomial of degree n-1. However, g also has a root, x1, etc, etc.

The corrollary in Mathews complex analysis book is that any polynomial can be written as

f(x) = A(x - x0)(x - x1)(x - x2)...

where A is a constant and x0, x1, etc are the zeros for the equation. For an n order polynomial, there are n such terms, meaning there are n roots.

I have always treated the Fundamental Theorem as the basis for n roots, although I agree that depending on how it is stated, it is not obvious (until you think about it a little).

BTW, ISTR that algebraically, the square root was always supposed to be the _absolute value_ of x, where x^2 = 1. That would address the question of positive/negative and whether there was a single value or not. However, I'm pulling that out of high school algebra, so I can't say that it holds at more formal levels.
 
Robin said:

In other words the set of returned values can be tuples.

Unfortunately, this "solution" (n.b. scare quotes) introduces more problems than it solves; if the set of returned values includes tuples, then you can't use square root notation in traditional mathematical expressions, because the domain over which normal operators (+,-,*,/, etc.) are defined is typically the real number line or the complex plane, depending upon the context.

So the funny looking almost a division sign notation refers to a function defined over the (positive) real numbers that returns a unique positive real -- and this notation, with specifically a functional interpretation, has been in place since the 17th century.

It's not a question of lazy software engineers. The mathematicians who developed the notation needed a method of expressing the idea of a principal square root as a function from the reals to the reals so that it merged smoothly with the rest of the algebraic notation that was being developed in the 17th century. As has been repeatedly pointed out, this does not imply that they did not have other notations at their disposal if they needed to deal with the entire solution set as a whole. For example, in set notation, I can define all tenth roots of 1 as

{ x | x^10 = 1 }, possibly with the addition of the fact that x is an elements of C, of R, depending on whether I want the complex ones or not.

But the result of that notation is a set -- and as such I can't do other elementary math (for example, dividing a set by 2) using the elementary infix notation we all know and love from elementary school.

This is not a computer language issue. This is a mathematical expressiveness issue. The (unenhanced) radical notation is defined, and has been since the 17th century, to produce the principal square root of a non-negative real number (or more generally the principal nth root of a non-negative real). The mathematicians who developed the notation were well aware that there were other roots (and had other expressions available), but the one that was the simplest and most useful was the one referring to the principal root.

So in answer to SS's question from way back:
But who gets to decide what is useful? And since when does usefullness trump complete solutions?

The people who use the notation get to decide what is useful, and three hundred years of voting suggest that there is no need for a simplified functional notation for the complete set of roots of a real number or the complete set of zeros of an equation.

If you have an application that you cannot express in set-theoretic (as opposed to functional) notation, I would be interested to see it.
 
I think that what I am now going to write about the basic definitions has been said before on this thread, by various different posters but I just want to put it together. (I do this for living, there are witnesses who can testify that I can apply the Pumping Lemmas of regular and context-free languages while drunk. And I have arranged the regular PL as a polka).

The basic mathematical definitions start from sets. A set is a collection of elements. Now, what the previous sentence means philosophically is something that I leave to set theorists as I do with the sets not containing itself and all that stuff.

What suffices now is that a set can be written in using various different notations, the most important being:

1. Enumerating all elements in it, for example:

S_1 = { 0, 1, 2, green, red, apple, the moon }
S_2 = { 0, 1, 2, ... }

The first example is finite, the second infinite.

2. Expressing them via some condition (predicate)

S_3 = { x | x is a prime number }

A relation is a mathematical way of associating the elements of sets with each other. This is done via the cartesian product of the sets. The cartesian product of two sets is the set of all ordered pairs that can be formed from their elements.

For example, if

A = { a, b }
B = { 1, 2 },

then their cartesian product is:

A x B = { (a, 1), (a, 2), (b, 1), (b, 2) } .

A relation is formally a subset of a cartesian product. For example, we could define a relation R in A x B as:

R = { (a, 1), (a, 2), (b, 1) }.

Of course, this relation is rather pointless, so we could try another, more practical one.

Consider the set of early Roman emperors:

E = { caesar, augustus, tiberius, gaius, claudius, nero }

and define the relation A on E x E with the idea that the pair (x, y) belongs to A if x is the adopted son of y. Then we have:

A = { (caesar, augustus), (augustus, tiberius), (gaius, tiberius), (nero, claudius) }.

Or we could use a more mathematical definition of examining the set N of natural numbers and the "less than" relation. Then,

< = { (0,1), (0,2), (1,2), (0,3), (1,3), (2,3), ... }

So, basically we write x < y if and only if (x, y) belongs in <.

Now, a function is a relation that fulfills one additional condition: for each element of the first set there is exactly one pair in the relation. (Some category theorists may want to define it in another way but hopefully none of us are category theorists. (I took one course on it and I'm actively trying to forget anything that I learned on it)).

None of the earlier example relations are functions: R has two pairs for a, A has no pair for Claudius, and < has an infinite number of pairs for all elements.

An example function could be the successor function s(x) = x+1:

s = { (0,1), (1,2), (2, 3), ... }

(The A relation is a partial function as all emperors have at most one adoptive father).

Mathematically it doesn't matter a bit what the sets are and what the relations are. If the relation has exactly one pair for each element of the first set, then it is a function. If it hasn't it isn't.

Now, how does this relate with the square root. Well, you have several possible ways to define the square root such that it is a function. Basically you choose what the domain and the range of the function are. (In the following R is the set of real numbers, R+ the set of positive numbers, and C the set of complex nunbers).

Sqrt_1 : R+ -> R+
Sqrt_2: R+ -> R+ x R-
Sqrt_3: C -> C x C

Or you might not even want to force the square root to be a function at all but you are comfortable in it being a relation on R+ x R or C x C, that is certainly one consistent way of thinking it.

What definition you want to use depends on what you want to do. Sqrt_1 is in practical life usually the most convenient one. And if someone doesn't believe that there is a place for convenience in mathematics, then I suggest that someone to start reading articles written by elderly German mathematicians of the 19th century.( Or of the 20th century, even, there was one 1990-something paper where I couldn't understand a bit because that particular professor used heavily outdated notation combined with total lack of examples or explanations.)

One good point in Sqrt_1 is that it mixes well with arithmetic operators: if you want to compose operators (meaning that you want to write stuff like 5 * ( 2 + 4)), then everything that you have should operate on the same domains and ranges. (Well, same except that it is not a problem if the operators take different numbers of arguments). Of course, you could define the operations so that, for example, addition would work for sets of numbers but that would be mightily confusing to everybody, including you.

However, Sqrt_1 is not good enough for all uses. If you want to find the roots of a second order polynomial, then you have to consider also the negative roots. Or complex roots when you get into more complex problems.

So, my point is that you should use the definition that is the best for the problem that you are trying to solve.

Long-time experience of mathematicians indicate that it makes sense to restrict the square root symbol to denote only the positive root when the argument is a positive real (and when we are not using complex numbers). Convenience is very important in mathematics, otherwise we would still be using Roman numerals for everything.
 
SkepticalScience said:
Why doesn't my calculator, computer, even google say that the square root of 4 is 2 AND -2?

Aren't both of them the square root of 4?

(Now, on to moving the hair from my forehead, so it doesn't get in the way of my hand!)

I actually wrote a literal calculator (type the expression, get the answer) that did this.

It turned out to be a pain in the butt, mostly due to finding a way to do it intuitively using mathematical notation, as follows:

OK, set notation seems to be right for this. So sqrt 4 = {-2, 2} Eachwise operators on sets let you do a lot with this, like encode the binomial formula. Now, how do you pick one? Mathematical convention is +sqrt 4 = 2 and -sqrt 4 = -2. So you define the unary operators + and - differently over sets from over scalars, as selection operators. So +{2, -2} = 2. But what, then, is the justification for not saying +{2, -2} = {2}? +{1, 2, -17} should certainly be {1, 2}. In a simple expression, you can force the result to be a scalar, but in a complicated one, how do you tell? Do you just force all results to be scalars when there is only one element in the set? That screws everything up in different ways.
 
bunch of hubub over nothing, the point of the sqrt function is to return the non-negative square root. Check the man page.
It's up to the programmer to read the documention, understand it, and use the function appropriately.
 
Matabiri said:
Mind you, -i also fits that definition, I suppose...

There is no way to define 'i' in such a way that '-i' doesn't also fit the definition. We might all be using different 'i's.
 
Originally posted by new drkitten
Unfortunately, this "solution" (n.b. scare quotes) introduces more problems than it solves
Wha....? It is not a solution. It is simply a statement of the mathematical definition of a function. That is all. I was replying to jzs who said that a function could only be called a function if it passed the 'vertical line' test on a cartesian axis. I was pointing out that functions do not necessarily map onto R but onto any set.

Why are you trying to read in things that I didn't say?
 
RussDill said:
bunch of hubub over nothing, the point of the sqrt function is to return the non-negative square root. Check the man page.
It's up to the programmer to read the documention, understand it, and use the function appropriately.
Which is what I said way back, only pointing out that some man pages do not make this explicit. In any case I would have thought it bleeding obvious.

I think that there are a number of subthreads though that have nothing to do with the original question.

New drkitten said it - the surd symbol specifically means the principal square root, so if the calculator has this on the key then it is technically correct for it to return 2 when you enter 4 and press the square root key.
 

Back
Top Bottom