A_name = "_A_" + var
BA_name = "_BA_" + var
// Calculate A and B/A
code += [A_name + " = " + str(A)]
code += [BA_name + " = " + str(B/A)]
// The actual update step
update = "_{var} = ({var} + {BA})*exp(-{A} * dt) - BA"
After Change
code = []
for var, (A, B) in system.iteritems():
s_var = sp.Symbol(var)
s_dt = sp.Symbol("dt")
if B != 0:
BA = B / A
// Avoid calculating B/A twice
BA_name = "_BA_" + var