Fast sincos routine

R

Robert Futrell

Allan Bruce said:
but sqrt of a positive number can be positive or negative

e.g. sqrt(4) = +/- 2

This is false. The square root of a positive number is always
positive.

You are thinking of the example they teach you in school:

sqrt((x^2)) = +/- x

This doesn't mean that there are two answers, one positive and one
negative; it's poor notation meaning that the answer is always
positive, even if x is negative.

For example, if x = -2,

sqrt((-2)^2) = 2 (not +/-2)

Thus, the "solution" in this case is "-x".

If you don't believe me, pick up any algebra schoolbook or graphing
calculator and find the graph for f(x) = sqrt(x). The graph clearly
passes the "vertical line test" and is therefore a function (although
I hope you already knew that); and we all SHOULD know that functions
have a UNIQUE y-value for every x.
 
C

CBFalconer

Robert said:
This is false. The square root of a positive number is always
positive.

You are just the man I want to see. I have all these marvellous
proofs, about 1 == 0, and things like that. You will be able to
immediately see that they are accurate and incontrovertible.
 
M

Mark McIntyre

This is false. The square root of a positive number is always
positive.

eh? A square has two roots, one positive and one negative.
This doesn't mean that there are two answers, one positive and one
negative;

Well, yes it does.
and we all SHOULD know that functions have a UNIQUE y-value for every x.

garbage.
 
D

Dik T. Winter

> On 5 Mar 2004 10:43:49 -0800, in comp.lang.c , (e-mail address removed) (Robert

>
> eh? A square has two roots, one positive and one negative.

Let us put this in perspective. In mathematics, the function "sqrt",
when presented with a positive number gives a positive result.
Otherwise it would not be a function. (In mathematics a function
is something that gives a single result when it is given an argument.
You have to go to Riemann surfaces to have a complete function sqrt.)

The *equation* x^2 = 2 has two roots, one of them is sqrt(2) and the
other is -sqrt(2).

I know about the proofs CBFalconer alludes to. When using the sqrt
function they assume that with complex argument and complex result
sqrt(a * b) = sqrt(a) * sqrt(b),
this equation is false.
 
N

Nick Landsberg

Dik said:
I know about the proofs CBFalconer alludes to. When using the sqrt
function they assume that with complex argument and complex result
sqrt(a * b) = sqrt(a) * sqrt(b),
this equation is false.

Huh?

using pure mathematics ...

If we sqaure both sides of the equation we get

sqrt(a*b) ^ 2 = sqrt(a) ^ 2 * sqrt(b) ^ 2

since sqrt(x)^2 = x for all x
(by definition)

we get a * b = a * b

What am I missing?

As far as I know, the above is true
even for complex numbers, i.e. sqrt(-1).

Please explain.
 
R

Robert Futrell

CBFalconer said:
You are just the man I want to see. I have all these marvellous
proofs, about 1 == 0, and things like that. You will be able to
immediately see that they are accurate and incontrovertible.

Thanks for the witty reply, but I was taking the notation "sqrt(x)" to
mean you wanted to compute the answer equivalent to math's

--
\/x

function. Here's a source from a professor to back me up on this,
since I know you won't believe me:

http://math.vanderbilt.edu/~schectex/commerrs/#Radicals

In short, positive numbers DO have two roots, but when you write

--
\/x

in math, that literally means "the nonnegative root". That is why the
graph of y=sqrt(x) does NOT have any negative y-values, and why the
square root function IS A FUNCTION. I hope you are not conjecturing
that square root is not a function...

I apologize, my previous post should have been more clear.

And here is a proof for you; see if you can spot an error in it:

Suppose
-----
\/(x^2) = +/- x (both) for x>0. Then

-----
\/(x^2) = -x. Since

-----
\/(x^2) <=> x^(2/2), we have

x^(2/2) = -x

=> x^1 = -x

=> x = -x

which is a contradiction. Thus, it is not true that

-----
\/(x^2) = +/- x (both) for x>0.
 
R

Robert Futrell

Clark Cox said:
You are simply wrong, read any math textbook.

I think we're talking about two different things here; I was taking
the notation "sqrt(x)" to mean you wanted to compute the answer
equivalent to math's

--
\/x

function. Here's a source from a professor to back me up on this,
since I know you won't believe me:

http://math.vanderbilt.edu/~schectex/commerrs/#Radicals

In short, positive numbers DO have two roots, but when you write

--
\/x

in math, that literally means "the nonnegative root". That is why the
graph of y=sqrt(x) does NOT have any negative y-values, and why the
square root function IS A FUNCTION. Do you know what a square root
graph looks like? I hope you are not conjecturing that square root is
not a function...

I apologize, my previous post should have been more clear.

And here is a proof for you; see if you can spot an error in it:

Suppose
-----
\/(x^2) = +/- x (both) for x>0. Then

-----
\/(x^2) = -x. Since

-----
\/(x^2) <=> x^(2/2), we have

x^(2/2) = -x

=> x^1 = -x

=> x = -x

which is a contradiction. Thus, it is not true that

-----
\/(x^2) = +/- x (both) for x>0.
 
R

Robert Futrell

Mark McIntyre said:
eh? A square has two roots, one positive and one negative.


Well, yes it does.


garbage.

Not garbage; I was using very strict math here and you (and indeed,
most everybody else) wasn't. I was taking the notation "sqrt(x)" to
mean you wanted to compute the answer equivalent to math's

--
\/x

function. Here's a source from a professor to back me up on this,
since I know you won't believe me:

http://math.vanderbilt.edu/~schectex/commerrs/#Radicals

In short, positive numbers DO have two roots, but when you write

--
\/x

in math, that literally means "the nonnegative root". That is why the
graph of y=sqrt(x) does NOT have any negative y-values, and why the
square root function IS A FUNCTION. I assume you know what a square
root graph looks like. I hope you are not conjecturing that square
root is not a function...

I apologize, my previous post should have been more clear.

And here is a proof for you; see if you can spot an error in it:

Suppose
-----
\/(x^2) = +/- x (both) for x>0. Then

-----
\/(x^2) = -x. Since

-----
\/(x^2) <=> x^(2/2), we have

x^(2/2) = -x

=> x^1 = -x

=> x = -x

which is a contradiction. Thus, it is not true that

-----
\/(x^2) = +/- x (both) for x>0.
 
R

Robert Futrell

CBFalconer said:
You are just the man I want to see. I have all these marvellous
proofs, about 1 == 0, and things like that. You will be able to
immediately see that they are accurate and incontrovertible.

I am curious to see the fallacious proof of 1==0 you have, as long as
the logical fallacy involves the sqrt discussion at hand.

Another thing: If "sqrt" in mathematics doesn't imply a positive-only
root, then why does the quadratic forumula contain "+/-" before the
square-root term? If sqrt really had two solutions in pure math like
you say, wouldn't the "+/-" in front be redundant?

Doesn't prove anything I know, but something for you to ponder.
 
M

Martin Dickopp

Nick Landsberg said:
Huh?

using pure mathematics ...

If we sqaure both sides of the equation we get

sqrt(a*b) ^ 2 = sqrt(a) ^ 2 * sqrt(b) ^ 2

since sqrt(x)^2 = x for all x
(by definition)

we get a * b = a * b

What am I missing?

It's always possible to derive a true statement from a false statement.
For example, take the false statement 1 = -1, square both side, and you
arrive at the true statement 1 = 1.

Martin
 
P

pete

Martin said:
It's always possible to derive a true statement
from a false statement.
For example, take the false statement 1 = -1, square both side,
and you arrive at the true statement 1 = 1.

Squaring equations, typically adds roots to the solution set:
x == 1 /* 1 */
x * x == 1 /* 1, -1 */

The last time I saw somebody try something like that,
they were trying to win drinks in a bar.
It's sophistry, not algebra.
 
P

pete

Robert said:
Not garbage; I was using very strict math here and you (and indeed,
most everybody else) wasn't. I was taking the notation "sqrt(x)" to
mean you wanted to compute the answer equivalent to math's

--
\/x

function. Here's a source from a professor to back me up on this,
since I know you won't believe me:

http://math.vanderbilt.edu/~schectex/commerrs/#Radicals

In short, positive numbers DO have two roots, but when you write

When I learned math in school
it was called the "principle square root".

http://www.google.com/search?hl=en&ie=ISO-8859-1&q="principle+square+root"
 
M

Martin Dickopp

pete said:
Squaring equations, typically adds roots to the solution set:
x == 1 /* 1 */
x * x == 1 /* 1, -1 */

Unlike 1 == -1 or 1 == 1, x == 1 or x*x == 1 are not statements that
are true or false. So, while you're right, this doesn't invalidate my
explanation.

Martin
 
R

Robert Futrell

Nick Landsberg said:
Huh?

using pure mathematics ...

If we sqaure both sides of the equation we get

sqrt(a*b) ^ 2 = sqrt(a) ^ 2 * sqrt(b) ^ 2

since sqrt(x)^2 = x for all x
(by definition)

we get a * b = a * b

What am I missing?

As far as I know, the above is true
even for complex numbers, i.e. sqrt(-1).

Please explain.

The product rule sqrt(ab) = sqrt(a) * sqrt(b) holds in the reals but
not in the complex plane.
 
D

Dik T. Winter


Want to see an example? Set a = b = -1:
1 = sqrt(1) = sqrt(a * b) != sqrt(a) * sqrt(b) = sqrt(-1) * sqrt(-1) =
= i * i = -1.
In mathematics the sqrt function is *not* multiplicative. It is so only
when you restrict yourself to positive real arguments. Similar:
ln(a * b) = ln(a) + ln(b)
only if you restrict yourself to postive real arguments.
 
N

Nick Landsberg

Dik said:
Want to see an example? Set a = b = -1:
1 = sqrt(1) = sqrt(a * b) != sqrt(a) * sqrt(b) = sqrt(-1) * sqrt(-1) =
= i * i = -1.
In mathematics the sqrt function is *not* multiplicative. It is so only
when you restrict yourself to positive real arguments. Similar:
ln(a * b) = ln(a) + ln(b)
only if you restrict yourself to postive real arguments.

Thank you!

I guess I'll have to get out the 40 year old math books
and bone up on the idiosyncracies.

Nick L.

- At this age, memory is the second thing to go,
and I forgot what the first is.
 
P

Paul Hsieh

Actually Robert Futrell is technically correct in his original explanation, but
his statements do not clarify the real issue.

(e-mail address removed) says...
eh? A square has two roots, one positive and one negative.

There can be up to two roots of a square depending on your number system basis.
But the number 0 only has one root which is neither positive or negative. This
is different from the classically described "square root function".
Well, yes it does.


garbage.

Actually that technically *is* definition of a function. A function can only
have a single range value for any given domain value. And that's the point.
As soon as you call it "the square root *FUNCTION*" then you are talking about
the classic square root function which takes non-negative real numbers and maps
them to other non-negative real numbers.

Robert Futrell original post made true statements, but lacked sufficient
explanation:

- Saying that the square root function takes postiive numbers to other positive
numbers is true, however he *IS* leaving out 0 for some reason.
- The square root function is also always incident with at least one of the
square roots of the numbers its defined in its domain. (He left this out.)
- The square root function is continuous.

The +/- notation is used when, for whatever reason, you need to describe both
roots when a number has two square roots. (Though it works redundantly for 0.)

Why this is all in comp.lang.c is beyond me, however I would like to point out
the following:

if (a < 0) a = -a;

does *NOT* necessarily force the integer variable a to be non-negative (see if
you can figure out how/why). So following it up with:

b = sqrt(a);

will lead to undefined behavior. See:

http://www.azillionmonkeys.com/qed/2scomp.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top