rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Simplifying %derivative does not pull out constant factors #99

Open rtoy opened 2 weeks ago

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:08:57 Created by zakhmak on 2017-09-19 19:45:40 Original: https://sourceforge.net/p/maxima/bugs/3333


Hello, I discover a strange behavior regarding expand() command inside wxMaxima. I wrote a ticket on the wxMaxima bug tracking system firstly https://github.com/andrejv/wxmaxima/issues/926 but unfortunately the staff couldn't help me to resolve this singularity. So it was instead recommended to me to contact directly the Maxima staff because wxMaxima a front end for Maxima is.

Concerning the problem, you can find below protocol describing how to reproduce it. I don't know if it Is this really a bug. I tried it not only in wxMaxima but also directly in the Maxima console that informs: Maxima 5.38.1 using Lisp SBCL 1.3.4.

I don't understand what really differs expression e4 from expression e5 except that one expression to expand is saved in a variable. Thanks in advance for any reply

dummy dependency (scale factor) e1: q(t) = C * u(t);

derivation of the quantity e2: i(t) = diff(q(t),t);

replace quantity with its dependencies in the derivation e3: subst(rhs(e1), q(t), e2);

request to move the (constant) scale factor outside the derivation operator as I expected (but that doesn't work) e4: expand(rhs(e3));

only way I succeed to move the (constant) scale factor outside the derivation operator (working but only for this transmitted expression) e5: expand(diff((C*u(t)),t));

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:08:58 Created by tomasriker on 2017-09-20 06:52:09 Original: https://sourceforge.net/p/maxima/bugs/3333/#534f


If I understand you correctly, you want to move a constant factor out of a differentiation operation. This is not what expand does. expand only expands things like (x+1)*(x-1) to x^2-1 or (x+1)^2 to x^2+2*x+1. I think the problem is that the constant factor is only moved outside at the time of doing diff(...). In your case, you pass an unknown function q(t) to diff. If Maxima knew at that time that q(t) = C * u(t), it would work. Replacing it afterwards is too late. So you'll probably want to define a real function like this:

q(t) := C * u(t);
i(t) := diff(q(t), t);

i(t) is then correctly C*('diff(u(t),t,1)).

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:00 Created by tomasriker on 2017-09-20 07:34:51 Original: https://sourceforge.net/p/maxima/bugs/3333/#25f3


rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:03 Created by tomasriker on 2017-09-20 07:35:36 Original: https://sourceforge.net/p/maxima/bugs/3333/#389c


The question is: Should (re)simplifying %derivative pull out constant factors (, too)?

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:05 Created by tomasriker on 2017-09-21 17:27:02 Original: https://sourceforge.net/p/maxima/bugs/3333/#552d


Maxima is inconsistent here, regarding diff vs. integrate:

(%i1)   subst(f(x) = a * f(x), integrate(f(x), x));
(%o1)   a*integrate(f(x),x)
(%i2)   subst(f(x) = a * f(x), diff(f(x), x));
(%o2)   'diff((a*f(x)),x,1)

Note how the constant factor a is pulled outside the integral, but not outside the derivative.

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:07 Created by zakhmak on 2017-09-21 20:13:08 Original: https://sourceforge.net/p/maxima/bugs/3333/#c3ad


Hello David, yes my goal is effectively to pull the constant out of the derivative. Concerning this inconsistency, maybe do you know if there is any (indirect) way to skirt the problem ?

Thanks for your advice to use function definition instead. I begin to have a closer on it but I am not done with it.

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:09 Created by zakhmak on 2017-09-21 20:37:13 Original: https://sourceforge.net/p/maxima/bugs/3333/#98e0


Eurêka ! I finally found the solution that I was actually looking for :

request to move the (constant) scale factor outside the derivation operator as I expected e4: ev(e3,diff);

So I don't know if this was a bug or not but anyway this bug ticket can be closed from my point of view.

rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:11 Created by robert_dodier on 2017-09-29 23:55:43 Original: https://sourceforge.net/p/maxima/bugs/3333/#bca5


rtoy commented 2 weeks ago

Imported from SourceForge on 2024-07-01 18:09:13 Created by robert_dodier on 2017-09-29 23:55:43 Original: https://sourceforge.net/p/maxima/bugs/3333/#537f


Looks like a bug to me -- diff should be consistent with integrate. Seems it would be relatively easy to fix.