[net.lang.c] LPow correction

gwyn@BRL.ARPA (VLD/VMB) (06/24/86)

Jim Cottrell pointed out to me that 0^0 should be 1, not 0
as I had it in my posted LPow() function.  I thought I had
a reason for making it 0, but since I'm unable to reconstruct
that line of reasoning, and *especially* since I can show
(using l'Hospital's rule) that
	limit of x^x as x->0+ is precisely 1,
I am amending our master copy of LPow() to handle exponent 0
as another special case.  Just insert
	if ( exponent == 0 )
		return 1;
in front of the other special cases.  This will make 0^n
zero for n > 0, 1 for n == 0, and 0 (should be infinite)
for n < 0.  The latter is the only known inaccuracy and is
due entirely to not wanting to clutter the algorithm with
error handling; if you want to add error handling this is
the place (recommend setting EDOM and returning MAX_LONG).

rbj@icst-cmr.arpa (Root Boy Jim) (06/24/86)

	Jim Cottrell pointed out to me that 0^0 should be 1, not 0
	as I had it in my posted LPow() function.  I thought I had
	a reason for making it 0, but since I'm unable to reconstruct
	that line of reasoning, and *especially* since I can show
	(using l'Hospital's rule) that
		limit of x^x as x->0+ is precisely 1,

I hadn't thought of it that way. That's what's neat about the truth,
it has so many ways of making itself known! As I also mentioned,
infinite series often generate aught to the naught and call it unity.
As you well know, zero factorial is also one.
BTW, 'tis          ^
		l'Hopital's Rule (the caret is a circumflex accent).
The Eagles even wrote a song about it:
"Take it to the Limit One More Time" (original joke).

	I don't care what APL does.

When it applies to math you do. If you have one handy you might try
expanding the power series for e^x:

infinity ->	<X>
		---	  n
	 x	\	 x		(I definitely didn't use eqn :-)
	e   =	/	---
		---	 n!
		n=0

My favorite one liner is `1 + +/ % ! i 12' (where `%' is DIVIDE (reciprocal)
and `i' is IOTA). Twelve is a good approximation to infinity here. Anyway,
you can see what happens when x is zero. All the other terms flake out
except the first, which has to be one. Isn't this fun?

One last piece of humor: My favorite Star Trek line was when Spock said
(of some physical phenomenon) "It has increased in strength by
one to the fourth power!" He obviously didn't have your function.

	Take care now,

	(Root Boy) Jim Cottrell		<rbj@icst-cmr.arpa>
	Gibble, Gobble, we ACCEPT YOU - - -

P.S. That was Zippy's approcksimation to the Gobble Gobble I owe you.
			   /^\
			    |___I used up all my x's in previous postings

peters@cubsvax.UUCP (Peter S. Shenkin) (06/26/86)

In article <brl-smok.1611> rbj@icst-cmr.arpa (Root Boy Jim) writes:
>My favorite one liner is `1 + +/ % ! i 12' (where `%' is DIVIDE (reciprocal)
>and `i' is IOTA). Twelve is a good approximation to infinity here. Anyway,
>you can see what happens when x is zero. All the other terms flake out
>except the first, which has to be one. Isn't this fun?

Whoops, don't you mean:
		1 + +/ (x ^ i12) % (! i12)
??  (Ya need x^n in the numerator of each term....  I'm using "^" for 
exponentiation.)

Peter S. Shenkin	 Columbia Univ. Biology Dept., NY, NY  10027
{philabs,rna}!cubsvax!peters		cubsvax!peters@columbia.ARPA

timg@mc0.UUCP (06/27/86)

In article <1604@brl-smoke.ARPA> gwyn@BRL.ARPA (VLD/VMB) writes:
>Jim Cottrell pointed out to me that 0^0 should be 1, not 0
>as I had it in my posted LPow() function.


	Sorry to bring it up, but Jim Cottrell is wrong, 0^0 is an indeterminate
form, as you will find by looking in any elementary calculus book (eg. Anton).
This form should be treated just as 0/0.

Tim Graham
Jet Propulsion Laboratory
(818) 577-6689

tainter@ihlpg.UUCP (Tainter) (06/28/86)

> 		limit of x^x as x->0+ is precisely 1,
> 
> I hadn't thought of it that way. That's what's neat about the truth,
> it has so many ways of making itself known! As I also mentioned,
Truth?  What truth?  This isn't a truth, it's a consequence of the
definition of the system as self consistant.  1 + 1 = 2 is not truth
either, it is a definition from a number of integer addition systems.
If your going to talk mathese please avoid terms like truth and reality.
Neither of these concepts have any place in math.
> 	(Root Boy) Jim Cottrell		<rbj@icst-cmr.arpa>
--j.a.tainter

gwyn@BRL.ARPA (VLD/VMB) (06/29/86)

I can think of several solid mathematical reasons to define 0^0 as 1
and no reason not to.  It happens that there's no way to represent
an "indeterminate form" on our machines, so I have to choose something.
It might as well be the most generally useful choice.

I also think atan2(0.,0.) should be defined as 0. for computation.
I've never seen a case where this wasn't what I wanted.

gwyn@BRL.ARPA (VLD/VMB) (06/29/86)

>>>	limit of x^x as x->0+ is precisely 1
> This isn't a truth, it's a consequence of the definition of the system
> as self consistant.

Fortunately I don't subscribe to the school of thought that says all
mathematics is simply rearrangement of symbols according to formal rules.
As a physicist/engineer, the above limit has real meaning for me.
So there.

greg@utcsri.UUCP (Gregory Smith) (06/30/86)

Question: What should 0^0 come out as?
Well, what we have here is a two-dimensional limit.
I.e. what is
			Lim x^y
			(x,y)-> (0,0)

The point (0,0) in the x,y plane can be approached in many ways:
E.g. the following is the approach along the x-axis:

	let x=t, y=0
			Lim t^0		=	1
			t->0+
No problem there.
This is the approach along the y-axis:

	let y=t, x=0
			Lim 0^t		=	0
			t->0+
No problem there.
What about the general solution, along the line y=mx?
( y-axis not included in this one )

	let y=mt, x=t
		L   =	Lim t^mt
			t->0+

	ln(L) = Lim m * t * ln(t)

			m * ln(t)
		= Lim ----------
			1/t

Apply L'Hopital's rule:
			 m*  1/t
		= Lim ----------
		 t->0+	- 1/(t^2)

		= Lim - m * t	=  0
 		  t->0+

Thus the value of L in this class of approaches is exp(0) = 1.

Since the value of the limit depends on the path of approach, the
limit of x^y as (x,y)->(0,0) is deemed to be undefined. As least
that's what they learned me in Advanced Calculus.
So if you don't want to trap 0^0 as an error you could pick 0 or 1,
whichever you feel is better. But the limit is mathematically undefined.

>>>>	limit of x^x as x->0+ is precisely 1

Yes it is. This is the approach along the x=y line, and it is
not a complete characterization of 0^0.

>> This isn't a truth, it's a consequence of the definition of the system
>> as self consistant.
>
The system still isn't consistent. 0^X is 0 in general. X^0 is 1 in general.
( what this all means is that if you built a 3-d model of the plane
z=x^y it would have a vertical cliff or other such weirdness at x=y=0.)

>Fortunately I don't subscribe to the school of thought that says all
>mathematics is simply rearrangement of symbols according to formal rules.
>As a physicist/engineer, the above limit has real meaning for me.
>So there.

I hope it has a little more meaning now.

I have only included straight-line approaches. You can use the general
parametric approach along the curve ( f(t), g(t) ) where f(0)=g(0)=0.
I believe that the case y=mx is the same as this general case, provided

			       g(t)
			Lim    ----
			t->0+  f(t)

is defined and equal to m.

-- 
"Shades of scorpions! Daedalus has vanished ..... Great Zeus, my ring!"
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg

rbj@icst-cmr (Root Boy Jim) (07/01/86)

	>>>	limit of x^x as x->0+ is precisely 1
	> This isn't a truth, it's a consequence of the definition of the system
	> as self consistant.
	
	Fortunately I don't subscribe to the school of thought that says all
	mathematics is simply rearrangement of symbols according to formal rules.
	As a physicist/engineer, the above limit has real meaning for me.
	So there.
	
Which came first the chicken or the egg? (The rooster :-) Would EE's ever
have figured out how complex arithmetic relates to reactance if some
mathematician hadn't wondered `What squared is minus one?'

	(Root Boy) Jim Cottrell		<rbj@icst-cmr.arpa>
	Let me do my TRIBUTE to FISHNET STOCKINGS...

rbj@icst-cmr (Root Boy Jim) (07/01/86)

	In article <1604@brl-smoke.ARPA> gwyn@BRL.ARPA (VLD/VMB) writes:
	>Jim Cottrell pointed out to me that 0^0 should be 1, not 0
	>as I had it in my posted LPow() function.
	
		Sorry to bring it up, but Jim Cottrell is wrong, 0^0 is
	an indeterminate form, as you will find by looking in any elementary
	calculus book (eg. Anton).  This form should be treated just as 0/0.

Sorry to disappoint you, but old Root Boy is correct. It depends on the
context. If we are asking for the value of a function at a given point and
it is an indeterminate form, it may be found to have a value by using
L'Hopital's rule.

On the other hand, if we ask for the value of the constant expression 0^0
we must figure out what that `really' means. As I mentioned, defining
this expression to be unity is useful for infinite series expansions.

Since Doug Gwyn was writing an integer power function he chose the
expression lim x->0 x^x to evaluate 0^0 because that was what he was
interested in. He could have chosen x^(sin x) as well, but why should he?

	Tim Graham Jet Propulsion Laboratory (818) 577-6689

Go ask a mathemetician, and if you don't believe him, try Carl Sagan.

	(Root Boy) Jim Cottrell		<rbj@icst-cmr.arpa>
	LBJ, LBJ, how many JOKES did you tell today??!

Looks like Zippy misspelled my name :-)

gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/01/86)

In article <1843@brl-smoke.ARPA> Root Boy Jim <rbj@icst-cmr> writes:
> He could have chosen x^(sin x) as well, but why should he?

Of course that has the same limit as x->0+.

I bet people are getting tired of this discussion.  Any further
debate about whether 0^0 has a definite value, can harmlessly be
assigned one, etc. should move to net.math instead, so we can
bore the mathematicians too.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/02/86)

In article <3055@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) shows that
	limit as (x,y)->(0,0) of x^y
is path-dependent, which is quite correct and no news at all to anyone
who has studied complex analysis.  The reason I selected 1 as the return
value for 0^0 rather than my initially-coded 0 is that almost all (in a
technical sense) paths yield that value for the limit of x^y.  Of course,
0^0 really is not well-defined; I just wanted to return the most generally
useful value for that case, since I was explicitly not coding in any error
handling.  0^0 "=" 1 turns out to be much more useful in computation than
0^0 "=" 0; neither one is really "right".

My general philosophy about such things as 1/0, 0^0, atan2(0.,0.), etc.
is that the application programmer should never allow such situations to
occur in the first place, since they're obviously illegal, improper, ill-
defined, or whatever.  However, when implementing a general function that
may be used by careless programmers, a decision has to be made about how
to cope with such abuse.  For LPow(), I decided to always do something
sane, quietly, since this was intended as an example of how to obtain
run-time integer exponentiation without embedding it in the language.
Another good solution for math library functions in general is to trigger
matherr() or some similar error handling and recovery scheme.

In summary:  When writing code for general use, watch for abuse and
do SOMEthing deliberate (and relatively sensible) when it occurs.
When writing applications, never try to do anything ill-defined.