I want to remove all occurrences of “a” in expression “exp” except for the first one, which I want to keep.
To do that, I have tried X = symbols(‘X’) <<replace first occurrence of a by X>> replace all remaining occurrences by 0 replace X by a For the second statement, an Internet search suggested replace, like this: X = symbols(‘X’) exp = exp.replace(a, X, 1) # maximum of one replacement exp = exp.subs(a, 0) exp = exp.subs(X, a) Unfortunately, this version of replace doesn’t work, and I have not found any way to do it with subs of xreplace. This post tells me that subs and replace have kwargs, but I haven’t found any documentation on that. https://stackoverflow.com/questions/56584025/sympy-subs-vs-replace-vs-xreplace -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/febcad9b-c406-4636-965f-ab9afec8f501n%40googlegroups.com.