How can I make all low values in a SymPy expression zero? For example, my result is:
1.0*a1*cos(q1) - 6.12e-17*(a2*sin(q2) + a3*sin(q2 + q3) + a4*sin(q2 + q3 + q
What about more details? I guess you want replace part of a symbolic calculation string, Regular expression in Python could be helpful, you can code like this:
In [1]: import re
In [2]: s = '1.0*a1*cos(q1) - 6.12e-17*(a2*sin(q2) + a3*sin(q2 + q3) + ' \
...: 'a4*sin(q2 + q3 + q4))sin(q1) + 1.0(a2*cos(q2) + ' \
...: 'a3*cos(q2 + q3) + a4*cos(q2 + q3 + q4))*cos(q1)'
In [3]: s = re.sub(r'[+-/*/]\s\S*e-[1-9]\d+\S*\s', '', s)
In [4]: s
Out[4]: '1.0*a1*cos(q1) + a3*sin(q2 + q3) + a4*sin(q2 + q3 + q4))sin(q1) + 1.0(a2*cos(q2) + a3*cos(q2 + q3) + a4*cos(q2 + q3 + q4))*cos(q1)'
First argument of re.sub() function decide what you want to reduce, e-[1-9]\d+
represent a number lower than e-10 which you can modify, I hope it helps.