I have an expression from a sympy calculation:
sqrt(pi)*(0.333333333333333*a + 0.333333333333333*b - 2.66666666666667*c**2)
where a,b,c are symbols, and would like to parse it so that the floats are replaced with rationals like in
sqrt(pi)*(1/3*a + 1/3*b - 8/3*c**2)
I know how to do one by hand,
In[24] Rational(str(0.333333333333333)).limit_denominator(1000)
Out[24]: 1/3
but do not quite know how to go about parsing the atoms and picking only the ones that are floats, and substituting back the rational number approximation.
What is the smartest way of doing these substitutions in the expression?