Re: [R] 0^0 computation in R : Why it is defined 1 in R ?

2014-05-26 Thread Prof Brian Ripley

On 26/05/2014 13:16, ritwi...@isical.ac.in wrote:

Dear R helpers,


today I found something interesting in R. 0^0 gives value 1 in R. But it
is undefined in mathematics. During debugging a R code, I found it and it
effects my program severely. So my question is why it is defined 1 in R?
Is there any particular reason or its a bug in the R software?


Try reading the help:

 Users are sometimes surprised by the value returned, for example
 why ‘(-8)^(1/3)’ is ‘NaN’.  For double inputs, R makes use of IEC
 60559 arithmetic on all platforms, together with the C system
 function ‘pow’ for the ‘^’ operator.  The relevant standards
 define the result in many corner cases.  In particular, the result
 in the example above is mandated by the C99 standard.  On many
 Unix-alike systems the command ‘man pow’ gives details of the
 values in a large number of corner cases.

See §F9.4.4 of the C99 standard.




Here is one demo:

*

ff=function(u){
   return( x^0 * u)
}

x=0
zz=integrate(ff,lower=0,upper=1)$value
zz




source('~/.active-rstudio-document')
zz

[1] 0.5




*

Looking forward to hear any response.

Regards,

Ritwik Bhattacharya
Indian Statistical Institute Kolkata

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


PLEASE do 


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] 0^0 computation in R : Why it is defined 1 in R ?

2014-05-26 Thread Jeff Newmiller
You might find searching the web on this topic educational. Consider [1] and 
[2], for example.

I doubt this will be changing, so you should do your exponentiation in a 
function that handles your special case.

By the way, as nice as RStudio might be, it is not R... it USES R. Examples 
like yours won't run as-is in vanilla R so are not really reproducible for 
(probably most) readers of this list. Please (re-)read the Posting Guide.

[1] http://mathforum.org/dr.math/faq/faq.0.to.0.power.html
[2] 
http://www.askamathematician.com/2010/12/q-what-does-00-zero-raised-to-the-zeroth-power-equal-why-do-mathematicians-and-high-school-teachers-disagree/
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On May 26, 2014 5:16:21 AM PDT, ritwi...@isical.ac.in wrote:
Dear R helpers,


today I found something interesting in R. 0^0 gives value 1 in R. But
it
is undefined in mathematics. During debugging a R code, I found it and
it
effects my program severely. So my question is why it is defined 1 in
R?
Is there any particular reason or its a bug in the R software?

Here is one demo:

*

ff=function(u){
  return( x^0 * u)
}

x=0
zz=integrate(ff,lower=0,upper=1)$value
zz



 source('~/.active-rstudio-document')
 zz
[1] 0.5


*

Looking forward to hear any response.

Regards,

Ritwik Bhattacharya
Indian Statistical Institute Kolkata

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] 0^0 computation in R : Why it is defined 1 in R ?

2014-05-26 Thread David Winsemius

On May 26, 2014, at 9:42 AM, Prof Brian Ripley wrote:

 On 26/05/2014 13:16, ritwi...@isical.ac.in wrote:
 Dear R helpers,
 
 
 today I found something interesting in R. 0^0 gives value 1 in R. But it
 is undefined in mathematics. During debugging a R code, I found it and it
 effects my program severely. So my question is why it is defined 1 in R?
 Is there any particular reason or its a bug in the R software?
 
 Try reading the help:
 
 Users are sometimes surprised by the value returned, for example
 why ‘(-8)^(1/3)’ is ‘NaN’.  For double inputs, R makes use of IEC
 60559 arithmetic on all platforms, together with the C system
 function ‘pow’ for the ‘^’ operator.  The relevant standards
 define the result in many corner cases.  In particular, the result
 in the example above is mandated by the C99 standard.  On many
 Unix-alike systems the command ‘man pow’ gives details of the
 values in a large number of corner cases.
 
 See §F9.4.4 of the C99 standard.
 

A related questi0n is why NaN^0 == 0 returns TRUE:

http://stackoverflow.com/questions/17863619/why-does-nan0-1/17864651

-- 
David.
 
 
 Here is one demo:
 
 *
 
 ff=function(u){
   return( x^0 * u)
 }
 
 x=0
 zz=integrate(ff,lower=0,upper=1)$value
 zz
 
 
 
 source('~/.active-rstudio-document')
 zz
 [1] 0.5
 
 
 *
 
 Looking forward to hear any response.
 
 Regards,
 
 Ritwik Bhattacharya
 Indian Statistical Institute Kolkata
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 PLEASE do 
 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.