Suggestion on Derivative and Expr._diff_wrt

54 views
Skip to first unread message

mcpl snu

unread,
Jan 2, 2020, 11:00:00 PM1/2/20
to sympy
In current SymPy, derivative such as dx/d(x+1) is not allowed. Instead, one might use `Derivative(f(x)-1, f(x)).subs(f(x), x+1)`.
Although this is mathematically rigorous, the former expression is sometimes used as well, at least in the field of engineering.


Hence I carefully suggest; how about introducing a `rigorous` parameter to `Derivative`?

When `rigorous=True`, which is a default value, `Derivative` behaves as it does now. It does not allow dx/d(x+1).

When `rigorous=False`, user can have dx/d(x+1) and also evaluate it to 1. Similary, dx/df(x) = 1/(df(x)/dx) is allowed if `rigorous=False`.
User must be aware that this may lead to mathematically incorrect result, and use this feature at own risk.

Francesco Bonazzi

unread,
Jan 4, 2020, 5:08:39 AM1/4/20
to sympy
It's suggest to subclass Derivative if this feature is needed.
Message has been deleted

mcpl snu

unread,
Jan 4, 2020, 5:55:45 AM1/4/20
to sympy
I have tried, and although it was working well, `diff()` method was unaffected since `Expr.diff()` method is connected to `Derivative`.
Since this feature will add no backward incompatibility, I think it would be better to modify `Derivative`.

2020년 1월 4일 토요일 오후 7시 8분 39초 UTC+9, Francesco Bonazzi 님의 말:

David Bailey

unread,
Jan 4, 2020, 6:06:55 AM1/4/20
to sy...@googlegroups.com
On 04/01/2020 10:08, Francesco Bonazzi wrote:
It's suggest to subclass Derivative if this feature is needed. 

I'd like to know what d f(x)/d(x+1) means exactly. It isn't too easy to GOOGLE.

David


mcpl snu

unread,
Jan 4, 2020, 8:08:06 AM1/4/20
to sympy
It's same as df(t)/dt, where t=x+1.


2020년 1월 4일 토요일 오후 8시 6분 55초 UTC+9, David Bailey 님의 말:

Vishesh Mangla

unread,
Jan 4, 2020, 10:27:17 AM1/4/20
to sy...@googlegroups.com

Why don’t you use the chain rule (d f(x) / dx) * (dx/d(x+1)). For first order derivative you can use the reciprocal therefore dx/d(x+1) = 1/(d(x+1)/dx).

 

Sent from Mail for Windows 10

 

From: David Bailey
Sent: 04 January 2020 16:36
To: sy...@googlegroups.com
Subject: Re: [sympy] Suggestion on Derivative and Expr._diff_wrt

 

On 04/01/2020 10:08, Francesco Bonazzi wrote:

It's suggest to subclass Derivative if this feature is needed. 
 

I'd like to know what d f(x)/d(x+1) means exactly. It isn't too easy to GOOGLE.

David

 

--
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 sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/3ee75111-deca-b796-b400-79068e928745%40dbailey.co.uk.

 

Message has been deleted

mcpl snu

unread,
Jan 4, 2020, 10:59:13 AM1/4/20
to sympy


Your suggestion is true. However, using ``Derivative(f(x), x) * 1/Derivative(x+1, x)`` explicitly every time is not very systematic approach.
If we know "Hey, df(x)/d(x+1) equals (df(x)/dx)/(d(x+1)/dx)!", then why don't we let SymPy know to automatically deal with this case with same approach?

Let me put this in another word. We know that ``dsin(x)/dx == cos(x)``. Then, how can we use this to evaluate ``expr = 1+Derivative(sin(x), x)``?
Although we can evaluate this by manually substituting like ``expr.subs(Derivative(sin(x), x), cos(x))``, we let SymPy know that  ``dsin(x)/dx == cos(x)``, so that we can just use ``expr.doit()``.

My idea is same: ``f(x).diff(x+1)`` is better than ``(Derivative(f(x), x) * 1/Derivative(x+1, x)).doit()``. If we can do something explicitly, then it would be better to do it implicitly.


2020년 1월 5일 일요일 오전 12시 27분 17초 UTC+9, Vishesh Mangla 님의 말:

Why don’t you use the chain rule (d f(x) / dx) * (dx/d(x+1)). For first order derivative you can use the reciprocal therefore dx/d(x+1) = 1/(d(x+1)/dx).

 

Sent from Mail for Windows 10

 

From: David Bailey
Sent: 04 January 2020 16:36
To: sy...@googlegroups.com
Subject: Re: [sympy] Suggestion on Derivative and Expr._diff_wrt

 

On 04/01/2020 10:08, Francesco Bonazzi wrote:

It's suggest to subclass Derivative if this feature is needed. 
 

I'd like to know what d f(x)/d(x+1) means exactly. It isn't too easy to GOOGLE.

David

 

--
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 sy...@googlegroups.com.

David Bailey

unread,
Jan 4, 2020, 12:22:08 PM1/4/20
to sy...@googlegroups.com
On 04/01/2020 13:08, mcpl snu wrote:
It's same as df(t)/dt, where t=x+1.

Thanks, and I suppose that also generalises to expressions such as df(x)/d(sin(x))?

df(t)/dt where t=sin(x)

Given how easy it is to mistype input to sympy, I don't think such an extension is such a good idea.

David

Vishesh Mangla

unread,
Jan 4, 2020, 12:47:22 PM1/4/20
to sy...@googlegroups.com

Then use simplistic rules of derivative like d(x+c) = dx, d(ax+c) = a dx.

 

Sent from Mail for Windows 10

 

To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/52688c3f-9ccc-483a-87be-063d65846560%40googlegroups.com.

 

Vishesh Mangla

unread,
Jan 4, 2020, 12:51:08 PM1/4/20
to sy...@googlegroups.com

Wrong if you want to use substitution then it should be df(t-1)/dt.

 

Sent from Mail for Windows 10

 

From: David Bailey
Sent: 04 January 2020 22:52
To: sy...@googlegroups.com
Subject: Re: [sympy] Suggestion on Derivative and Expr._diff_wrt

 

On 04/01/2020 13:08, mcpl snu wrote:

David

--
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 sympy+un...@googlegroups.com.

mcpl snu

unread,
Jan 4, 2020, 12:58:24 PM1/4/20
to sympy
I suppose that you mean df(sin(x))/d(sin(x)), and yes. ``Derivative(f(sin(x)), sin(x))`` will be allowed. However, since ``dx/d(sin(x)) != 1/(d(sin(x))/dx)``, evaluating this will result ``Subs`` instance, I guess.

Mistyping issue will be prevented by introducing 'rigorous' variable, as I mentioned above. And frankly speaking, it's user's fault if one mistypes the input.


2020년 1월 5일 일요일 오전 2시 22분 8초 UTC+9, David Bailey 님의 말:

mcpl snu

unread,
Jan 5, 2020, 7:44:22 PM1/5/20
to sympy
Although using the rules of derivative is good idea, I'm not really sure that SymPy currently has the class for 'd' operator.

And, regarding to your second reply, df(t-1)/dt will be good for AppliedUndef classes. Written in SymPy code, it will be Subs(Derivative(f(t),t), (t,), (x+1)). Then, how about letting f(x).diff(x+1) result this?
Also, let's say if the expression is not AppliedUndef but other class, e.g. Add. For example, dx/d(x+1). In this case, substituting x+1 with t can evaluate this to 1, so I think x.diff(x+1) can return 1 as well.

Let me summarize:

- Differentiating AppliedUndef with x+1 results Subs(Derivative(f(t),t), (t,), (x+1)).
- Differentiating other classes, such as Add or Mul, results the evaluated value, if possible.

How do you think of it?



2020년 1월 5일 일요일 오전 2시 51분 8초 UTC+9, Vishesh Mangla 님의 말:

Wrong if you want to use substitution then it should be df(t-1)/dt.

 

Sent from Mail for Windows 10

 

From: David Bailey
Sent: 04 January 2020 22:52
To: sy...@googlegroups.com
Subject: Re: [sympy] Suggestion on Derivative and Expr._diff_wrt

 

On 04/01/2020 13:08, mcpl snu wrote:

It's same as df(t)/dt, where t=x+1.

 

Thanks, and I suppose that also generalises to expressions such as df(x)/d(sin(x))?

df(t)/dt where t=sin(x)

Given how easy it is to mistype input to sympy, I don't think such an extension is such a good idea.

David

--
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 sy...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages