{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/7806","labels_url":"https://api.github.com/repos/sympy/sympy/issues/7806/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/7806/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/7806/events","html_url":"https://github.com/sympy/sympy/issues/7806","id":39091787,"number":7806,"title":"Incorrect behavior with subs and second derivatives","user":{"login":"jsoishi","id":4137953,"avatar_url":"https://avatars.githubusercontent.com/u/4137953?v=3","gravatar_id":"","url":"https://api.github.com/users/jsoishi","html_url":"https://github.com/jsoishi","followers_url":"https://api.github.com/users/jsoishi/followers","following_url":"https://api.github.com/users/jsoishi/following{/other_user}","gists_url":"https://api.github.com/users/jsoishi/gists{/gist_id}","starred_url":"https://api.github.com/users/jsoishi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsoishi/subscriptions","organizations_url":"https://api.github.com/users/jsoishi/orgs","repos_url":"https://api.github.com/users/jsoishi/repos","events_url":"https://api.github.com/users/jsoishi/events{/privacy}","received_events_url":"https://api.github.com/users/jsoishi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-07-30T13:32:21Z","updated_at":"2015-03-13T22:11:33Z","closed_at":null,"body":"In Sympy 0.7.4.1 on my machine with Python 3.3.2, and on the sympy live shell on sympy.org (which is currently SymPy 0.7.4.1 (Python 2.7.5)), the following code \r\n\r\n```python\r\nfrom sympy import *\r\nx,z,t = symbols('x, z, t')\r\npsi = Function('psi')(x,z)\r\nj1 = Derivative(psi,x) - Derivative(psi,z)\r\nj1.subs(Derivative(psi,x), t)\r\n```\r\ngives the expected behavior, t - d psi/dx. \r\n\r\nHowever, if I do the same thing with a second derivative with respect to z, \r\n\r\n```\r\nj2 = Derivative(psi,x) - Derivative(psi,z,2)\r\nj2.subs(Derivative(psi,x), t)\r\n```\r\nit returns t - d^2 t/dz^2. I expect it to return t - d^2 psi/dz^2. This happens even if I make `t` a `Function` instead of a `symbol`."},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/79467021","html_url":"https://github.com/sympy/sympy/issues/7806#issuecomment-79467021","issue_url":"https://api.github.com/repos/sympy/sympy/issues/7806","id":79467021,"user":{"login":"nschaeff","id":11467205,"avatar_url":"https://avatars.githubusercontent.com/u/11467205?v=3","gravatar_id":"","url":"https://api.github.com/users/nschaeff","html_url":"https://github.com/nschaeff","followers_url":"https://api.github.com/users/nschaeff/followers","following_url":"https://api.github.com/users/nschaeff/following{/other_user}","gists_url":"https://api.github.com/users/nschaeff/gists{/gist_id}","starred_url":"https://api.github.com/users/nschaeff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nschaeff/subscriptions","organizations_url":"https://api.github.com/users/nschaeff/orgs","repos_url":"https://api.github.com/users/nschaeff/repos","events_url":"https://api.github.com/users/nschaeff/events{/privacy}","received_events_url":"https://api.github.com/users/nschaeff/received_events","type":"User","site_admin":false},"created_at":"2015-03-13T22:11:33Z","updated_at":"2015-03-13T22:11:33Z","body":"I just ran into a reelated problem, with sympy 0.7.6. When running this code:\r\n\r\n    from sympy import *\r\n    init_printing()\r\n\r\n    x=Symbol('x')\r\n    y=Symbol('y')\r\n    z=Symbol('z')\r\n    f=Function('f')\r\n\r\n    expr = diff(f(x,y),x,x,y)\r\n    pprint(expr)\r\n\r\n    e2 = expr.subs(diff(f(x,y),y,2), z)\r\n    pprint(e2)\r\n\r\nThe call to subs() method incorrectly substitutes a df/dy with z, while we asked to substitute d2f/dy2 instead !"}}