Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

substitute() raises exception where python does not

In my usual workflow, I derive symbolic equations and then substitute their arguments by values stored in dictionaries to obtain numerical solutions. Now I found out that the substitute() command raises division by zero exception where standard python does not. This is a bit of a problem, as these exceptions prevent my code from evaluating all data sets once such an exception occurs and I don't want to wrap each line of code in a try-except construct. Does anyone know how the exception could be avoided? Here is an example:

var('a x')
eq_y = y == a/x
vdict = {}
vdict[a] = 1.
vdict[x] = 0.
vdict[a]/vdict[x]

+infinity

However, if I substitute vdict into eq_y, I get an exception:

eq_y.subs(vdict)

Traceback (click to the left of this block for traceback)
...
ValueError: power::eval(): division by zero

substitute() raises exception where python does not

In my usual workflow, I derive symbolic equations and then substitute their arguments by values stored in dictionaries to obtain numerical solutions. Now I found out that the substitute() command raises division by zero exception where standard python does not. This is a bit of a problem, as these exceptions prevent my code from evaluating all data sets once such an exception occurs and I don't want to wrap each line of code in a try-except construct. Does anyone know how the exception could be avoided? Here is an example:

var('a var('y a x')
eq_y = y == a/x
vdict = {}
vdict[a] = 1.
vdict[x] = 0.
vdict[a]/vdict[x]

+infinity

However, if I substitute vdict into eq_y, I get an exception:

eq_y.subs(vdict)

Traceback (click to the left of this block for traceback)
...
ValueError: power::eval(): division by zero