This is the new prototype of vdiff, but it still cannot unleash the
Derivative object unevaluated:
def vdiff(x, vector):
x = np.array(x)
shape = x.shape
ans = []
for vi in vector:
if vi.is_Symbol:
tmp = []
for e in x.ravel():
tmp.append(e.diff(vi))
else:
subs = {}
new_var = sympy.var('new_var')
for s in vi.free_symbols:
subs[s] = solve(new_var - vi, s)[0]
tmp = []
for e in x.ravel():
e = e.subs(subs)
e = e.diff(new_var)
e = e.subs({new_var: vi})
tmp.append(e.diff(new_var))
ans.append(np.array(tmp))
ans = [a.reshape(shape) for a in ans]
return np.array(ans).swapaxes(0, 1)
On Sunday, November 3, 2013 1:07:03 AM UTC+1, Aaron Meurer wrote:
>
> Wait, why is x.diff(f(x)) not 0? We discussed this quite at length
> when we first implemented the ability to do this (you can probably
> find the discussion on the mailing list if you search for it), and we
> came to the conclusion that dF(x, f(x))/df(x) as used in variational
> calculus means nothing more than dF(x, y)/dy|y=f(x). On other words,
> the fact that f(x) depends on x is irrelevant. You are just taking the
> derivative with respect to the second "variable" in the expression,
> which happens to be evaluated at f(x). See also the docstring of
> Derivative.
>
> Aaron Meurer
>
> On Sat, Nov 2, 2013 at 2:16 PM, F. B. <[email protected] <javascript:>>
> wrote:
> >
> >
> > On Saturday, November 2, 2013 5:48:30 PM UTC+1, Aaron Meurer wrote:
> >>
> >> But in general, you can't invert formulas (and even if you
> >> mathematically can, it doesn't mean that solve() can do it).
> >>
> >
> > I was just thinking about this, and about the more general case where
> you
> > are deriving by unknown expression.
> >
> > I suggest that in such cases the differentiation returns an unevaluated
> > derivative.
> >
> > It would be nice to handle derivation by another function, for example:
> >
> >>>> x.diff(f(x))
> > Derivative(x, f(x))
> >>>> x.diff(f(y))
> > Derivative(x, f(y))
> >>>> f(x).diff(g(x))
> > Derivative(f(x), g(x))
> >>>> f(x).diff(g(y))
> > Derivative(f(x), g(y))
> >
> > At least, I would start be leaving the derivative unevaluated, so in the
> > future it will be easier to add tools to handle functional derivatives.
> >
> > Saullo, do you think you can add something like this?
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "sympy" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > To post to this group, send email to [email protected]<javascript:>.
>
> > Visit this group at http://groups.google.com/group/sympy.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.