I like the first way for the fact that it just has 'x' instead of 'x (t)', but I like the second way because it is simpler and easier to implement.
Is there a way to redefined how x = Symbol('x')(t) would print? I guess subclassing would be one option, take care of it there, and then use the second approach for the auto substitution stuff. ~Luke On May 27, 4:49 pm, Ondrej Certik <ond...@certik.cz> wrote: > We discuss this on IRC with Luke and Fabian. Now I understand -- Luke > wants the result of differentiating not to be instances of > Derivative() class, but rather some other symbols, e.g it should > substitute them for symbols at the end. > > One way to do it is to subclass the Symbol() class that does the right > thing, proof of concept is attached. I had to comment out some lines > in the Function class that were returning 0 immediately if the > expression didn't depend on "t" (the symbol we are differentiating > with respect to). > > After applying the patch, you get: > > $ python t.py > x'*cos(x) > > Another approach may be to create some decorator around Basic.diff() > or even create a new function diff, along these lines: > > ------------ > from sympy import * > > t = Symbol("t") > x = Function("x")(t) > print "current way:", diff(sin(x), t) > > x_diff = Symbol("x'") > derivs_dict = {x.diff(t): x_diff} > def diff(a, b): > return a.diff(b).subs(derivs_dict) > > print "new way:", diff(sin(x), t) > ------------- > > This prints: > > current way: D(x(t), t)*cos(x(t)) > new way: x'*cos(x(t)) > > Luke, isn't the second approach cleaner? No need to create new classes, etc. > > Ondrej > > 0001-Proof-of-concept.patch > 1KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---