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
Implements partial substitution of Mul objects #1395
base: master
Are you sure you want to change the base?
Conversation
Hi, I've run clang-format and found that the code needs formatting. To use the commit you can do
|
@eeshan9815 You can run |
@ShikharJ Okay, thanks! |
@isuruf can you please review the PR? |
symengine/subs.h
Outdated
} | ||
} else | ||
d = x.get_dict(); | ||
} else if (is_a<Pow>(*sub1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is handled in the first part. Why check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isuruf
The first part is the earlier implementation that only looks for exact matches, and not partial matches which should be handled using subs
.
That part is retained only for the fast execution speeds in case of exact matches as it doesn't involve many heavy computations.
Here's some test cases to handle,
|
How should it be decided whether 3*x*y is returned or 5*z*w? |
Doesn't matter, use the first match. |
I have added the above test cases to |
ping @isuruf |
} | ||
} else | ||
d = x.get_dict(); | ||
} else if (is_a<Symbol>(*sub1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this part? Why is sub1
being a Symbol important? I thought the issue was that sub1
being a Mul isn't handled correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial substitution can happen for Symbol
objects as well. For example, if the expression is x**2*y
and sub1
is x
, there is still partial substitution possible.
The first part only looks for exact matches.
Follow up question, should substitution happen repeatedly until not possible? For instance, if the expression is x**2*y**3
and x*y
is to be replaced by z
, should the result be x*y**2*z
or y*z**2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, (x**2*y).subs({x: z})
didn't work before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did, but I've made the non fast_exec
implementation complete. Should I remove these redundant parts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @isuruf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's redundant, remove them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eeshan9815, sorry about the delay. Can you remove redundant code here?
Does this PR affect performance? |
@certik It is slower than the earlier implementation because that only naively looked at the expression for exact matches. |
@isuruf is there more work to be done before merging? |
ping @isuruf |
Fixes #1359
Added 11 test cases which demonstrate the partial substitution of Mul in mixed-variable terms as well.
ping @isuruf