Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 6 years ago

res0001 gravatar image

Conflicting Sage vs Wolfram evaluation of a limit?

Why are the following results different, and which (if either) is correct?

Sage: (you can cut/paste/execute this code here)

#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a) 
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); limit(V(a,w), a=oo)

#out()=
1

Wolfram: (you can execute this code here)

#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2 
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]  
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2 
Assuming[w>0, Limit[V[a,w], a -> Infinity]]

#out()=
0

(This is supposed to compute the limit, as a -> oo, of the variance of a standard normal distribution when truncated to the interval (a,a+w); so, intuitively, I think the answer should be strictly positive.)

Conflicting Sage vs Wolfram evaluation of a limit?

Why are the following results different, and which (if either) is correct?

Sage: (you can cut/paste/execute this code here)

#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a) 
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); limit(V(a,w), a=oo)
print(limit(V(a,w), a=oo))
plot(V(a,1),a,0,8)

#out()=
1

enter image description here

Wolfram: (you can execute this code here)

#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2 
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]  
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2 
Assuming[w>0, Limit[V[a,w], a -> Infinity]]
Plot[V[a,1], {a,0,8} ]

#out()=
0

enter image description here

(This is supposed to compute the limit, as a -> oo, of the variance of a standard normal distribution when truncated to the interval (a,a+w); so, intuitively, I think the answer should be strictly positive.)positive. EDIT: After adding the plots, I'm wondering if the limit may actually fail to exist?)

Conflicting Sage vs Wolfram evaluation of a limit?

Why are the following results different, computed limits different (1 by Sage, 0 by Wolfram), and which (if either) is correct?

Sage: (you can cut/paste/execute this code here)

#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a) 
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); print(limit(V(a,w), a=oo))
plot(V(a,1),a,0,8)

#out()=
1

enter image description here

Wolfram: (you can execute this code here)

#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2 
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]  
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2 
Assuming[w>0, Limit[V[a,w], a -> Infinity]]
Plot[V[a,1], {a,0,8} ]

#out()=
0

enter image description here

(This is supposed to compute the limit, as a -> oo, of the variance of a standard normal distribution when truncated to the interval (a,a+w); so, intuitively, I think the answer should be strictly positive. EDIT: After adding the plots, I'm wondering if the limit may actually fail to exist?)

Conflicting Sage vs Wolfram evaluation of a limit?

Why are the following computed limits different (1 by Sage, 0 by Wolfram), and which (if either) is correct?

EDIT: Revised to increase the numerical precision in Wolfram. (I don't know how to do the same in Sage.) The Wolfram plot strongly suggests that the limit is indeed 0, and that the issue is entirely about numerical precision.

Sage: (you can cut/paste/execute this code here)

#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a) 
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); print(limit(V(a,w), a=oo))
plot(V(a,1),a,0,8)

#out()=
1        #<--------- computed limit = 1

enter image description here

Wolfram: (you can execute this code here)

#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2 
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]  
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2 
Assuming[w>0, Limit[V[a,w], a -> Infinity]]
Plot[V[a,1], {a,0,8} ]
Plot[V[a, 10], {a, 0, 100}, WorkingPrecision -> 128] 

#out()=
0
0        (* <--------- computed limit = 0 *)

enter image description hereenter image description here

(This is supposed to compute the limit, as a -> oo, of the variance of a standard normal distribution when truncated to the interval (a,a+w); so, intuitively, I think the answer should be strictly positive. EDIT: After adding the plots, I'm wondering if the limit may actually fail to exist?).)

Conflicting Sage vs Wolfram evaluation of a limit?

Why

>Why are the following computed limits different (1 by Sage, 0 by Wolfram), and which (if either) is correct?

EDIT: Revised to increase correct?

EDIT: Increasing the numerical precision in Wolfram. (I don't know how to do the same in Sage.) The Wolfram produces a plot that strongly suggests that the limit is indeed 0, which it had already computed. Presumably, Sage is computing the wrong limit simply because of inadequate numerical precision, so the question is now ...

How can I increase the numerical precision in Sage, so that limit() and that the issue is entirely about numerical precision.

plot() will produce the correct results (i.e., the limit should be 0 and the plot should show a stable approach to 0)?

Sage: (you can cut/paste/execute this code here)

#in()=
f(x) = exp(-x^2/2)/sqrt(2*pi)
F(x) = (1 + erf(x/sqrt(2)))/2
num1(a,w) = (a+w)*f(a+w) - a*f(a)
num2(a,w) = f(a+w) - f(a) 
den(a,w) = F(a+w) - F(a)
V(a,w) = 1 - num1(a,w)/den(a,w) - (num2(a,w)/den(a,w))^2
assume(w>0); print(limit(V(a,w), a=oo))
plot(V(a,1),a,0,8)

#out()=
1        #<--------- computed limit = 1

enter image description here

Wolfram: (you can execute this code here)

#in()=
f[x_]:=Exp[-x^2/2]/Sqrt[2*Pi]
F[x_]:=(1 + Erf[x/Sqrt[2]])/2 
num1[a_,w_] := (a+w)*f[a+w] - a*f[a]
num2[a_,w_] := f[a+w] - f[a]  
den[a_,w_] := F[a+w] - F[a]
V[a_,w_] := 1 - num1[a,w]/den[a,w] - (num2[a,w]/den[a,w])^2 
Assuming[w>0, Limit[V[a,w], a -> Infinity]]
Plot[V[a, 10], {a, 0, 100}, WorkingPrecision -> 128] 

#out()=
0        (* <--------- computed limit = 0 *)

enter image description here

(This is supposed to compute the limit, as a -> oo, of the variance of a standard normal distribution when truncated to the interval (a,a+w).)