On Sun, Jun 8, 2008 at 1:09 AM, Rickard Armiento <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Wow, thanks for the extremely rapid and helpful response + patch!
>
>> In [2]: print f(5*x).diff(x)
>> 5*D(f(5*x), 5*x)
>
> But I am not sure how this notation can work in the general case. How
> should sympy handle this input:
>
> In [3]: f(x,5*x).diff(x)
>
> or even just:
>
> In [4]: f(x,x).diff(x)
>
> I tried this in your development version, and get results that I "kind
> of understand", but which are not formally correct. For example:
>
> In [5]: f(x,x).diff(x)
> Out [5]: 2*D(f(x,x),x)
>
> I would expect something like this:
>
> In [6]: f(x,x).diff(x)
> Out [6]: D(f(x_1,x),x1).subs(x_1,x) + D(f(x,x_2),x_2).subs(x_2,x)
>
>> What remains to be done is to improve the Derivative class to
>> represent the substitution, [...] When we teach
>> Derivative(x**2, x).subs(x, 0) to behave like a number, then
>> all should work as expected.
>
> Right, a proper handling of substitutions appear to be related also to
> the solution to the above issue. Currently one cannot even input the
> expression in Out[6] above without the substitutions just falling
> away.
>
>> Any ideas? I think we just need another argument to be added to
>> Derivative --- the point of differentiation and that should be it.
>
> That sounds very reasonable. So, its either that -- allowing
> Derivative to represent both a derivative and subsequent substitution
> -- or to make sure subs can stay unevaluated in expressions.
Exactly. I think the first option will be easier to implement, because
for the second one, we would have to introduce a new class
representing
unevaluated substitution.
That should fix the above as well.
>
> To keep the ability of Derivative to represent more than one
> derivative, while adding the ability to represent a point of
> differentiation, it seems something as fancy as this is needed:
>
> In [7]: f(x,x).diff(x)
> Out [7]: Derivative(f(x_1,x),(x_1,x)) + Derivative(f(x,x_2),(x_2,x))
>
> Or perhaps this is nicer:
>
> In [8]: f(x,x).diff(x)
> Out [8]: Derivative(f(x_1,x),x_1==x) + Derivative(f(x,x_2),x_2==x)
>
> (But would that work, or will there be an issue with x_1==x evaluating
> to False?)
It's just a way how it is printed, so we can print it using any
notation we like.
I was thinking about this a little and I think the Derivative should
introduce a new dummy symbol for representing what exactly it is
differentiating + a substitution for that symbol at the end (how
things are implemented internally is a different thing, but it should
behave like this). That should be general enough construction to
represent anything.
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})
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})
Please check it that I didn't make a mistake in these examples and
also that it could indeed represent everything. (Again, how things are
actually printed is a different thing, of course the easy things like
f(x).diff(x) should imho be printed using the light syntax, like
D(f(x), x), but the complicated things could be printed using the full
general syntax).
If we agree on the above, than let's implement it.
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---