-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix 14796 #14798
base: master
Are you sure you want to change the base?
Fix 14796 #14798
Conversation
I'm not sure if |
Oh I guess |
# If old or new is an instance of FunctionClass, then | ||
# it has no free_symbols or args or atoms, so the code | ||
# breaks. I'm assuming in those cases, it is okay to treat | ||
# it as if all three lists are empty lists. |
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.
Remove this comment. The first part will be in the git history, and also the AUTHORS file. The second part should be a comment here on the pull request.
Regarding the question, we apparently allow things like Integral(f(x), f(x))
. Does this do the right thing for it?
Look at the test failure in Travis. You need to remove trailing whitespace. Also, this needs to have a test added. |
l = Lambda(y, g(y)) | ||
int_expr8 = Integral(g(x), (x,0,1)) | ||
int_expr9 = int_expr.subs(f, l) | ||
assert int_expr9 == int_expr8 |
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.
A blank line required at the end.
This is strange. I'm pretty sure that the build failing was not due to anything I did. When I did tests locally, using |
If the ability to subs functions really is intentional, I wonder if it should be done in subs itself, instead of requiring every |
So it looks like this does work because of Application._eval_subs, and looking through the history, it's been there for a while. So we should probably keep the functionality. But I do think it does need to be in subs, not
|
I may be mistaken but only removing the change in |
@DarylMcCullough Thanks for the contribution. Would you still like to complete this PR? The issue is still unresolved. |
Allow substitution of function symbols within an integral
References to other Issues or PRs
Fixes #14796
Brief description of what is fixed or changed
In the code for substitutions within an expression involving limits (such as an
integral), the code breaks if you try to substitute one function symbol for another.
The reason for this is found in the file
sympy/concrete/expr_with_limits.py
inthe implementation of the method
_eval_subs(self, old, new)
of the classExprWithLimits
. Inthat method, the properties and methods
.free_symbols
,.args
,.atoms
are consulted.However, those properties and methods do not return list (or iterables) in the case
where the
old
ornew
arguments are instances ofFunctionClass
.A fix that works in the case that sparked the issue is to check if those properties
and methods return lists, and if not, proceed as if they returned empty lists. This
perhaps should be implemented in the
FunctionClass
.Other comments
The
subs
function allows substitutions of subexpressions within an expression.So for example:
Afterwards,
expr1
will be the expressionf(y)
. You can even substitute functionsymbols for other function symbols:
Afterwards,
expr2
will be the expressioncos(x)
. However, if you try to dothe same substitution within an integral,
Integral(f(x), (x,0,1))
, (the integralfrom x=0 to x=1 of f(x)) then instead of getting
Integral(cos(x), (x,0,1)
, thecode raises an error. This is because in substituting
cos
forf
, it checksthe free variables of
f
and the args off
and the atoms ofcos
, and thosemethods and properties are not defined on FunctionClass objects.