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

Derivative of vector-valued function #375

Closed
abrock opened this issue May 11, 2016 · 3 comments
Closed

Derivative of vector-valued function #375

abrock opened this issue May 11, 2016 · 3 comments

Comments

@abrock
Copy link

abrock commented May 11, 2016

Derivative calculation works for scalar-valued functions:

In[56]:= p[x_] := x^2
In[57]:= p'[x]
Out[57]= 2 x

But not for vector-valued functions:

In[58]:= p[x_] := {x^2}
In[59]:= p'[x]
Out[59]= {0}

I was expecting {2x}.

@abrock
Copy link
Author

abrock commented May 11, 2016

Integration in contrast works just fine:

In[68]:= Integrate[{t, t^2}, {t,0,1}]
Out[68]= {1 / 2, 1 / 3}

@bnjones
Copy link
Member

bnjones commented May 12, 2016

Another example:

In[7]:= D[{#^2}, #]
Out[7]= {0}

In[8]:= D[{x^2}, x]
Out[8]= {2 x}

I think this is related to this rule in mathics/builtin/calculus.py:

 'D[{items___}, x_?NotListQ]': 'D[#, x]& /@ {items}',

When this is applied to D[{#^2}, #], x gets bound to # and interpolated directly into a Function expression, which I think is where this goes wrong. We end up with D[#^2, #^2] which evaluates to zero (which isn't right either but that's not related to this issue).

There might be some other issues here but a short-term fix is to avoid slots in these rules, so we can properly handle taking derivatives of slot expressions.

bnjones added a commit to bnjones/Mathics that referenced this issue May 12, 2016
Using Function and Slot in this rule causes problems if the pattern
variables are bound to expressions containing slots. Avoid this by
using the named-argument form of Function.
bnjones added a commit that referenced this issue May 12, 2016
Fix for issue #375: avoid slots in rule handling D[{...}, ...]
@bnjones
Copy link
Member

bnjones commented May 12, 2016

This should now be fixed. Thanks for reporting this!

@bnjones bnjones closed this as completed May 12, 2016
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

2 participants