Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I see. You are using a symbolic equation in the latter case, which will definitely barf at dividing by zero, but the things you are putting in are "real literals".

sage: type(a) <type 'sage.symbolic.expression.expression'=""> sage: type(vdict[a]) <type 'sage.rings.real_mpfr.realliteral'="">

As such, they obey 'usual' division rules for floating-point things like

sage: vdict[x]/vdict[x] NaN

So if you don't want mathematically correct behavior, I suggest not using a symbolic variable!

sage: eq_y = y == z sage: def mysubs(a=.1,x=0.,eq=eq_y): ....: t = a/x ....: return eq.subs(z=t) ....: sage: mysubs() y == +infinity sage: mysubs(.0,.0) y == NaN

Indeed, we get

sage: vdict = {} sage: vdict['a'] = 0. sage: vdict['x'] = 0. sage: mysubs(**vdict) y == NaN

I see. You are using a symbolic equation in the latter case, which will definitely barf at dividing by zero, but the things you are putting in are "real literals".

sage: type(a)
<type 'sage.symbolic.expression.expression'="">
'sage.symbolic.expression.Expression'>
sage: type(vdict[a])
<type 'sage.rings.real_mpfr.realliteral'="">

'sage.rings.real_mpfr.RealLiteral'>

As such, they obey 'usual' division rules for floating-point things like

sage: vdict[x]/vdict[x]
NaN

NaN

So if you don't want mathematically correct behavior, I suggest not using a symbolic variable!

sage: eq_y = y == z
sage: def mysubs(a=.1,x=0.,eq=eq_y):
....:     t = a/x
....:     return eq.subs(z=t)
....: 
sage: mysubs()
y == +infinity
sage: mysubs(.0,.0)
y == NaN

NaN

Indeed, we get

sage: vdict = {}
sage: vdict['a'] = 0.
sage: vdict['x'] = 0.
sage: mysubs(**vdict)
y == NaN

NaN