Hi,

> Examples:
>
> In [1]: f(x, y).diff(x)
> Out [1]: D(f(_x, y), {_x: x})
>
> In [2]: f(x, x).diff(x)
> Out [2]: D(f(_x, x), {_x: x})+D(f(x, _x), {_x: x})
>
> In [3]: f(3*x, 5*x).diff(x)
> Out [3]: 3*D(f(_x, 5*x), {_x: x})+5*D(f(3*x, _x), {_x: x})

I think this should be:

In [3]: f(3*x, 5*x).diff(x)
Out [3]: 3*D(f(_x, 5*x), {_x: 3*x})+5*D(f(3*x, _x), {_x: 5*x})

> In [4]: f(x, x).diff(x).subs(x, 5)
> Out [4]: D(f(_x, 5), {_x: 5})+D(f(5, _x), {_x: 5})
>
> In [5]: f(x, y).diff(x).diff(y)
> Out [5]: D(f(_x, _y), {_x: x, _y:y})
>
> In [6]: f(g(x)).diff(x)
> Out[6]: D(f(_x), {_x:g(x)}) * D(g(_x), {_x: x})
>
> In [7]: f(g(x)).diff(x).subs(x, 5)
> Out[7]: D(f(_x), {_x:g(5)}) * D(g(_x), {_x: 5})

I started looking a little bit at the sympy core for how to do this,
but ran into some problems with the idea of using a dictionary like
this. To handle multiple derivatives in analogy with your [5], one
would need a new dummy variable for each new derivative of the same
variable, like so:

In [8]: f(x, y).diff(x).diff(x)
In [8]: D(f(__x, _y), {__x: _x, _x:x})

Maybe the implementation becomes simpler if one only allow for one
(optional) substitution-dictionary at the end of the Derivative? (I
guess this could also be generalized to other functionality that may
have similar issues, e.g. limits.)

Repeating your examples with this notation would give:

In [9]: f(x, y).diff(x)
Out [9]: D(f(_x, y), _x, {_x: x})

In [10]: f(x, x).diff(x)
Out [10]: D(f(_x, x), _x, {_x: x})+D(f(x, _x), _x, {_x: x})

In [11]: f(3*x, 5*x).diff(x)
Out [11]: 3*D(f(_x, 5*x), _x, {_x: 3*x})+5*D(f(3*x, _y), _y, {_y:
5*x})

In [12]: f(x, x).diff(x).subs(x, 5)
Out [12]: D(f(_x, 5), _x, {_x: 5})+D(f(5, _y), _y, {_: 5})

In [13]: f(x, y).diff(x).diff(y)
Out [13]: D(f(_x, _y), _x, _y, {_x: x, _y:y})

In [14]: f(g(x)).diff(x)
Out[14]: D(f(_x), _x, {_x:g(x)}) * D(g(_x), _x, {_x: x})

In [15]: f(g(x)).diff(x).subs(x, 5)
Out[15]: D(f(_x), _x, {_x:g(5)}) * D(g(_x), _x, {_x: 5})

And then,

In [16]: f(x, y).diff(x).diff(x)
Out[16]: D(f(_x, y), _x, _x, {_x:x})

However, as you say, in a case like this it should be realized that
the expression does not contain 'x' and thus the substitution can be
simplified away. So, lets also list an example where this cannot be
done:

In [17]: f(x, x).diff(x).diff(x)
Out[17]: D(f(_x, x), _x, _x, {_x:x}) + D(f(_x, _y), _x, _y,
{_x:x,_y:x}) + D(f(_x, _y), _y, _x, {_x:x,_y:x}) + D(f(x, _y), _y, _y,
{_y:x})

If the automatic removal of the substitutions is aggressive, I guess
it should even simplify to:

In [18]: f(x, x).diff(x).diff(x)
Out[18]: D(f(_x, x), _x, _x, {_x:x}) + D(f(x, _y), x, _y, {_y:x}) +
D(f(x, _y), _y, x, {_y:x}) + D(f(x, _y), _y, _y, {_y:x})

Does this seem better, or do you prefer the dictionary-derivative
syntax?

Best regards,
Rickard

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to