In[1]:= e = x*y + z
Out[1]= x y + z
In[2]:= e[[1]]
Out[2]= x y
In[3]:= e[[1, 1]]
Out[3]= x
In[4]:= e[[1, 1]] = q
Out[4]= q
In[5]:= e
Out[5]= q y + z
I don't think you need traversal. You just need to rebuild the
expression from the bottom up with the remaining args (remember that
expr == expr.func(*expr.args)).
It would probably be useful to have some utilities functions for
dealing with tuples like (1, 0) meaning expr.args[1].args[0].
What about if I add such options on this line:
Is it reasonable?
What about if I add such options on this line:
Is it reasonable?
What is PartReplace supposed to do? For me it just returns the replacement.
In [14]: PartReplace(x*y+z, w, 1,1)
Out[14]: w⋅x + z
In [15]: (x*y+z).args[1].args[1]
Out[15]: y
In [18]: Part((x*y+z), 1, 1)
Out[18]: y
In [20]: Part(x*y+w*z, slice(None, None, None), 1)
Out[20]: y + z
In [21]: PartReplace(x*y + w*z, o, slice(None, None, None), 1)
Out[21]: o⋅w + o⋅x