Modifying a part of the expression tree

43 views
Skip to first unread message

Bla Binorbit

unread,
Mar 11, 2022, 12:32:41 PM3/11/22
to sympy

Hello,
I would like to modify a part of an expression so as to obtain:
`EXPR.args[2].args[1] = MODIFIED_SUB_EXPRESSION`

How can I do this? The elements returned by "args" are immutable tuples, I cannot edit them in place and I don't know how to create a modified copy.

Thank you for your help,
Olivier


Chris Smith

unread,
Mar 11, 2022, 5:07:27 PM3/11/22
to sympy
This is what `epath` is made for, I believe. I have not spent enough time with it to provide much help, however -- only a pointer.

/c

Bla Binorbit

unread,
Mar 11, 2022, 7:39:01 PM3/11/22
to sympy
Thank you. I didn't know `epath()`. Indeed, the following command performs the desired modification:
`epath("/[2]/[1]", EXPR, lambda expr: MODIFIED_SUB_EXPRESSION)`
Best regards,
Olivier
Reply all
Reply to author
Forward
0 new messages