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

ExpandVisitor does not process arguments of FunctionSymbol #1976

Open
salehjg opened this issue Sep 24, 2023 · 0 comments
Open

ExpandVisitor does not process arguments of FunctionSymbol #1976

salehjg opened this issue Sep 24, 2023 · 0 comments

Comments

@salehjg
Copy link

salehjg commented Sep 24, 2023

Hi there,

I was experimenting with expand(foo, true) and noticed that ExpandVisitor is not expanding the arguments of symbolic functions (FunctionSymbol).

For example with Sympy:

import sympy as sp
>>> e1 = sp.parse_expr("f(2*(x+y)*(x-y))")
>>> e1
f((x - y)*(2*x + 2*y))
>>> sp.expand(e1)
f(2*x**2 - 2*y**2)

but this is not possible with SymEngine::expand(), or I am missing something quite obvious.

I modified ExpandVisitor by adding this method to make it work for now:

void bvisit(const FunctionSymbol &x) {
    vec_basic args;
    for (auto &arg: x.get_args()) {
        args.push_back(expand(arg));
    }
    auto e = function_symbol(x.get_name(), args);
    Add::dict_add_term(d_, multiply, e);
}

I am using a patched version of SymEngine 0.10.1 on Arch.

Could you please advise me on how to handle FunctionSymbols properly?

Best,
Saleh

@salehjg salehjg changed the title ExpandVisitor does not process FunctionSymbol's arguments ExpandVisitor does not process arguments of FunctionSymbol Sep 24, 2023
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

1 participant