Hi If I have a <- Inf + 1i then Re(a) is Inf, and Im(a) is 1, as expected. But if b <- 1 + Inf * 1i, then Im(b) = Inf , as expected, but Re(b) = NaN, which I didn't expect. Why this asymmetry? How to define an object with Re(b)=1, Im(b)=Inf? -- Robin Hankin Uncertainty Analyst Southampton Oceanography Centre European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
Inf +1i vs 1+Inf*1i
5 messages · robin hankin, Oscar Rueda Palacio, Martin Maechler
Robin, You could try b <- complex(real=1, im=Inf) ------------------------------------------ ?scar Manuel Rueda Palacio Viceintervenci?n Consejer?a de Hacienda Junta de Castilla y Le?n Tfno: 983414092 e-mail: ruepalos at jcyl.es ------------------------------------------ -----Mensaje original----- De: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]En nombre de Robin Hankin Enviado el: mi?rcoles, 13 de abril de 2005 9:51 Para: R-help at stat.math.ethz.ch Asunto: [R] Inf +1i vs 1+Inf*1i Hi If I have a <- Inf + 1i then Re(a) is Inf, and Im(a) is 1, as expected. But if b <- 1 + Inf * 1i, then Im(b) = Inf , as expected, but Re(b) = NaN, which I didn't expect. Why this asymmetry? How to define an object with Re(b)=1, Im(b)=Inf? -- Robin Hankin Uncertainty Analyst Southampton Oceanography Centre European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
"Robin" == Robin Hankin <r.hankin at soc.soton.ac.uk>
on Wed, 13 Apr 2005 08:51:19 +0100 writes:
Robin> Hi
Robin> If I have
Robin> a <- Inf + 1i
Robin> then
Robin> Re(a) is Inf, and Im(a) is 1, as expected.
Robin> But if
Robin> b <- 1 + Inf * 1i,
Robin> then
Robin> Im(b) = Inf , as expected, but Re(b) = NaN, which I didn't expect.
Robin> Why this asymmetry?
I think this is a (very long standing) buglet in our complex
arithmetic, since you can directly see
> 1+ 1i*Inf
[1] NaN+Infi
Robin> How to define an object with Re(b)=1, Im(b)=Inf?
{Oscar already mentioned b <- complex(real=1, im=Inf) }
Martin Maechler, ETH Zurich
Actually, the problem comes from "Inf * 1i" (or 1i * Inf)
and the
0 * Inf |-> NaN
which of course is `correct' in general, but a bit undesirable
in the rule
(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
{and similarly in complex division}.
Note that the same problem also leads to
> 1 * complex(re=0, im=Inf)
[1] NaN+Infi
which is even more ugly,
since '1 * z' really should return 'z' for all z.
Martin
BTW: S-plus (6.2.1) also returns NaN
(printing "NA". S+ has no complex versions of 'NaN')
"MM" == Martin Maechler <maechler at stat.math.ethz.ch>
on Wed, 13 Apr 2005 10:17:00 +0200 writes:
"Robin" == Robin Hankin <r.hankin at soc.soton.ac.uk>
on Wed, 13 Apr 2005 08:51:19 +0100 writes:
Robin> Hi
Robin> If I have
Robin> a <- Inf + 1i
Robin> then
Robin> Re(a) is Inf, and Im(a) is 1, as expected.
Robin> But if
Robin> b <- 1 + Inf * 1i,
Robin> then
Robin> Im(b) = Inf , as expected, but Re(b) = NaN, which I didn't expect.
Robin> Why this asymmetry?
MM> I think this is a (very long standing) buglet in our complex
MM> arithmetic, since you can directly see
>> 1+ 1i*Inf
MM> [1] NaN+Infi
Robin> How to define an object with Re(b)=1, Im(b)=Inf?
MM> {Oscar already mentioned b <- complex(real=1, im=Inf) }
MM> Martin Maechler, ETH Zurich
MM> ______________________________________________
MM> R-help at stat.math.ethz.ch mailing list
MM> https://stat.ethz.ch/mailman/listinfo/r-help
MM> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Apr 13, 2005, at 09:40 am, Martin Maechler wrote:
Actually, the problem comes from "Inf * 1i" (or 1i * Inf) and the 0 * Inf |-> NaN which of course is `correct' in general, but a bit undesirable in the rule (a + bi) * (c + di) = (ac - bd) + (ad + bc)i
thanks for this Martin.
Now I see what is going on, I wouldn't describe this as "undesirable"
because
"(1+0i) * (0 + Inf i)" depends on the behaviour of the infinite limit
in the second bracket compared with the zero limit in the first.
To wit, f() and g() both calculate 1*(Inf i):
> f <- function(n){(1+1i/sqrt(n))*(0+n*1i)}
> g <- function(n){(1+1i/n)*(0+sqrt(n)*1i)}
> f(1e8)
[1] -10000+1e+08i
> g(1e8)
[1] -1e-04+10000i
>
So perhaps it's unreasonable to expect complex arithmetic to guess what
I want.
very best wishes
rksh
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743