Ask Your Question

Revision history [back]

Evaluate from string an equation that has integer division

I have the following Python list that contains strings of equations.

L = ['651/349*t + 5382747/9778631000', 't + 57879/196133000', '1000/349*t + 57879/68450417']

You can see that all of the equations have integer division. Because this is obtained by some program, I can not edit the strings.

When I evaluate for t=1.0 with the following code in SageMath (for example), it does not evaluate as an Euclidean division.

F = function('F')(t)
for k in L:
    F(t) = eval(k)
    Fc = fast_callable(F, vars=[t])
    val2eval = 1.0

It gives


And should be give


Of course I can solve this by modifying MANUALLY the strings of the equations by indicating that the denominator is a real number and not an integer (I put a decimal point at the end of the integer in the denominator) as following.

L = ['651/349.*t + 5382747/9778631000.', 't + 57879/196133000.', '1000/349.*t + 57879/68450417.']

But this is not the idea, the strings of the equations are generated automatically and one can not modify by editing manually, because it will be implemented in a process where it should be create at least 2000 equations.

Is there some elegant solution for this? --Many thanks!