f`(0)

14 views
Skip to first unread message

David Bailey

unread,
Jun 4, 2019, 1:44:50 PM6/4/19
to sympy
The ability to expand an expression containing unknown functions, about some point, is obviously very valuable, and it is nice that this is possible using SymPy, however if I expand f(x) about 0 I get this:

f(0) + x*Subs(Derivative(f(_x), _x), _x, 0) + x**2*Subs(Derivative(f(_x), (_x, 2)), _x, 0)/2 + O(x**3)

Is there any way to reduce that to something neater and more like textbook maths such as

f(0)+x*f`(0)+x**2*f```(0)/2 + O(x**3)

I chose f` rather than f' because as far as I know, the '`' character is not used in Python.

Outputting the expression as Latex cleans it up a bit, but it is still not as neat as the usual notation for the derivative of a function notation.

David

Oscar Benjamin

unread,
Jun 4, 2019, 3:08:44 PM6/4/19
to sympy
Yeah, it would be nice to be able to do that. Unfortunately SymPy has
no notion of the derivative of an unapplied function. I'd like to have
a differential operator so you could do something like `D(sin) == cos`
etc. I believe there are some long-standing issues on Github about
this.

--
Oscar
> --
> 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 post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/5bca2aa1-8b2b-4a3f-af18-6f9a42dc87cd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
Jun 4, 2019, 3:44:01 PM6/4/19
to sympy
This is primarily an issue of printing. The str() printer prints
things in a way that can be copy-pasted back into SymPy, and since
f'(0) isn't valid syntax, you end up with the more verbose
representation that is used for the expression.

It would be useful to have printers, at least pretty printers, that
printed f'(0) instead of the subs version. If a D object like Oscar
described existed, then the str printer could print that, since it
would be valid SymPy syntax.

It shouldn't be hard to make a printer that defines _print_Subs to
print things nicer for your use-case. I think some printers may
already exist that do this (perhaps in the mechanics module), though I
could be misremembering that.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQ-7iEgovJtmqaNm_5rudpwc2vdMObYkRqV71u5PhjFSg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages