How to substitute certain function?
For example
@vars a b x y
@funs f g
ex1 = f(a,b)
ex2 = subs( ex1, f(x_,y_), g(x_+y_) ) # maybe some wildcard for the arguments?
An alternative approach I can imagine is to iterate over the expression tree. So I found there are functions "get_name" and "get_args". However, it is not very clear for "get_name" to show the operation + and *
If neither above works, it seems I have to turn the expression into String and using regex to implement the substitution, but this lose the point to use SymEngine.
What you can do right now is recursively call get_args on the expression and use get_name if the expression is a FunctionSymbol to create a dictionary for subs.
I agree that this is a useful thing to implement in the C++ library.
What you can do right now is recursively call
get_argson the expression and useget_nameif the expression is a FunctionSymbol to create a dictionary forsubs. I agree that this is a useful thing to implement in the C++ library.
Thank you for your reply. It could be an effective approach. However, how can I know if it is a FunctionSymbol?
You can use get_symengine_class(x) == :FunctionSymbol
You can use
get_symengine_class(x) == :FunctionSymbol
Thank you!
Hi zhaoli-IHEP, did you code your recursive function ? I have the same type of problem and if you have an effective function I am very interesting.
Thank's a lot.
Hi zhaoli-IHEP, did you code your recursive function ? I have the same type of problem and if you have an effective function I am very interesting.
Thank's a lot.
Hi, in fact we did not make generic function to handle this problem. What we do is to use function_symbols to find all functions and then filter them and then make replacement subs for each specific instance.