Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to substitute certain function? #188

Open
zhaoli-IHEP opened this issue Dec 26, 2019 · 6 comments
Open

How to substitute certain function? #188

zhaoli-IHEP opened this issue Dec 26, 2019 · 6 comments

Comments

@zhaoli-IHEP
Copy link

zhaoli-IHEP commented Dec 26, 2019

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.

@isuruf
Copy link
Member

isuruf commented Dec 28, 2019

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.

@zhaoli-IHEP
Copy link
Author

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.

Thank you for your reply.
It could be an effective approach. However, how can I know if it is a FunctionSymbol?

@isuruf
Copy link
Member

isuruf commented Dec 29, 2019

You can use get_symengine_class(x) == :FunctionSymbol

@zhaoli-IHEP
Copy link
Author

You can use get_symengine_class(x) == :FunctionSymbol

Thank you!

@Myrddinlefou
Copy link

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.

@zhaoli-IHEP
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants