I'm running into problems regarding the usage of the Brobdingnag package - after setting
a2 <- as.brob(0.1)^1000,
a2 = exp(-2302.6)
a1 <- as.brob(0.1)^800,
a1 = exp(-1842.1)
I get different results for using sum(a1,a2) and sum(a2,a1) - Each time the result equals the first argument given to the sum function. It seems that maybe sum is not overrided by the Brobdingang package even though its supposed to? Or maybe i'm doing something wrong?
I asked this question also as a reply to another question I wrote, see here
[EDIT: Answer from author of the package]
Hi Dan
This is definitely a bug in the package; thank you for the report! Unfortunately, correcting it will take me some considerable time.
In the meantime, please find below the usual R idiom for calculating the sum of two brobs:
> a1 <- as.brob(0.1)^800
> a2 <- as.brob(0.1)^1000
> a1+a2
> a1 <- as.brob(0.1)^800
> a2 <- as.brob(0.1)^1000
> a1+a2
[1] +exp(-1842.1)
> a2+a1
[1] +exp(-1842.1)
> sum(cbrob(a1,a2))
[1] +exp(-1842.1)
> sum(cbrob(a2,a1))
[1] +exp(-1842.1)
>
I can reproduce your issue with the following code. One answer might be to +
instead of sum
. Added: Another would be to have your data in a vector before doing the sum
> library(Brobdingnag)
> (a1 <- as.brob(0.1)^800)
[1] +exp(-1842.1)
> (a2 <- as.brob(0.1)^1000)
[1] +exp(-2302.6)
>
> a1 + a2
[1] +exp(-1842.1)
> a2 + a1
[1] +exp(-1842.1)
>
> sum(a1, a2)
[1] +exp(-1842.1)
> sum(a2, a1)
[1] +exp(-2302.6)
>
> sum(as.brob(0.1)^c(1000,800))
[1] +exp(-1842.1)
> sum(as.brob(0.1)^c(800,1000))
[1] +exp(-1842.1)
It seems to be that you cannot use sum(,)
like that. Here are some similar strange results with more practical numbers
> as.brob(0.1) + as.brob(1) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> as.brob(1) + as.brob(0.1) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> sum(as.brob(c(0.1, 1))) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> sum(as.brob(c(1, 0.1))) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
>
> sum(as.brob(0.1), as.brob(1)) # not OK, gives first term exp(ln(0.1))
[1] +exp(-2.3026)
> sum(as.brob(1), as.brob(0.1)) # not OK, gives first term exp(ln(1))
[1] +exp(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With