Implements partial substitution of Mul objects#1395
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? |
| } | ||
| } else | ||
| d = x.get_dict(); | ||
| } else if (is_a<Pow>(*sub1)) { |
There was a problem hiding this comment.
This is handled in the first part. Why check again?
There was a problem hiding this comment.
@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.
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.
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.
Hmm, (x**2*y).subs({x: z}) didn't work before?
There was a problem hiding this comment.
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.
@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