Login  Register

Re: Roots

Posted by Jon Peck on Nov 16, 2019; 2:32pm
URL: http://spssx-discussion.165.s1.nabble.com/Roots-tp5738554p5738563.html

I thought it would  be interesting to explore negative numbers exponentiated to fractional powers in other systems.  Here is what I found.  (NaN is a value for not a number.  Equivalent to SYSMIS.)


SPSS Statistics
compute z = (-1)**(1/3).  
SYSMIS
Warning # 523
>During the execution of the indicated command, an attempt was made to raise a
>non-positive number to a fractional power, e.g.  (-3)**2.5.

golang
output := math.Pow(-1, 1./3.)
NaN
No warning

Python
(-1)**(1./3.)
no result - calculation is stopped
ValueError: negative number cannot be raised to a fractional power

R
 (-1)^(1/3)
 NaN
No warning

Although I have not seen the SPSS internal transformation code, I expect that it uses logs to calculate exponentiation with a fractional power, hence the error.

The expression could be refactored to get a result in the case where the denominator of the exponent is odd but not as a general solution.  Since Statistics, as with most statistical packages, does not support complex numbers in expressions, that solution is not available.

From Wikpedia...

The powers of negative real numbers are not always defined and are discontinuous even where defined. In fact, they are only defined when the exponent is a rational number with the denominator being an odd integer. 
 

If the definition of exponentiation of real numbers is extended to allow negative results then the result is no longer well-behaved.

Neither the logarithm method nor the rational exponent method can be used to define br as a real number for a negative real number b and an arbitrary real number r. Indeed, er is positive for every real number r, so ln(b) is not defined as a real number for b ≤ 0.

The rational exponent method cannot be used for negative values of b because it relies on continuity. The function f(r) = br has a unique continuous extension[15] from the rational numbers to the real numbers for each b > 0. But when b < 0, the function f is not even continuous on the set of rational numbers r for which it is defined.

For example, consider b = −1. The nth root of −1 is −1 for every odd natural number n. So if n is an odd positive integer, (−1)(m/n) = −1 if m is odd, and (−1)(m/n) = 1 if m is even. Thus the set of rational numbers q for which (−1)q = 1 is dense in the rational numbers, as is the set of q for which (−1)q = −1. This means that the function (−1)q is not continuous at any rational number q where it is defined.

On the other hand, arbitrary complex powers of negative numbers b can be defined by choosing a complex logarithm of b.




On Fri, Nov 15, 2019 at 10:26 AM Stan Gorodenski <[hidden email]> wrote:
I don't know if there is any demand, but I think the square root of -1
is used in electronics. I'm not into this so I really don't know. I did
not pose this question because I have an application for it. I was just
curious since it seems that sophisticated software packages like SPSS
and SAS should be able to do it. I just sent an email to join the SAS
discussion group and will ask them if SAS can do it. I suppose one could
write a routine to return a -1 if the the denominator of the exponent is
an odd number.
Stan

On 11/15/2019 10:05 AM, Rich Ulrich wrote:
> I wonder - Is there any demand for the exception-coding
> that would be necessary?  How many people write code
> where they want to take the fractional root of a negative
> number, where the fraction is the reciprocal of an odd integer?
> ( Note, the fraction cannot be expressed EXACTLY on a binary
> computer. How is that accommodated?)
>
> The natural programming solution to non-integer roots is
> to use logs.  I suppose if there is an area where the problem
> comes up, specialized programs for that area might do it.
> I suspect the efficient solution might use a special subroutine
> call rather than an in-line expression.
>
> --
> Rich Ulrich
>
> ------------------------------------------------------------------------
> *From:* SPSSX(r) Discussion <[hidden email]> on behalf of
> Bruce Weaver <[hidden email]>
> *Sent:* Friday, November 15, 2019 11:35 AM
> *To:* [hidden email] <[hidden email]>
> *Subject:* Re: Roots
> https://www.ibm.com/support/knowledgecenter/en/SSLVMB_26.0.0/statistics_reference_project_ddita/spss/base/syn_transformation_expressions_domain_errors.html
>
>
>
> Kirill Orlov wrote
> > See DOMAIN ERRORS paragraph in Command Syntax Reference.
> >
> >
> > 15.11.2019 4:53, Stan Gorodenski пишет:
> >> compute z = (-1)**(1/3).
> >
> > =====================
> > To manage your subscription to SPSSX-L, send a message to
>
> > LISTSERV@.UGA
>
> >  (not to SPSSX-L), with no body text except the
> > command. To leave the list, send the command
> > SIGNOFF SPSSX-L
> > For a list of commands to manage subscriptions, send the command
> > INFO REFCARD
>
>
>
>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
> ===================== To manage your subscription to SPSSX-L, send a
> message to [hidden email]
> <mailto:[hidden email]> (not to SPSSX-L), with no body text
> except the command. To leave the list, send the command SIGNOFF
> SPSSX-L For a list of commands to manage subscriptions, send the
> command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD