Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+4 −0
Q&A What do the number entries mean in the sympy poly.diff(...) tuple syntax?

Based on the source code which delegates to this implementation among others, base.diff((x, n)) means to compute the n-th derivative of base with respect to x. Any arguments to diff which aren't tu...

posted 3y ago by Derek Elkins‭  ·  last activity 3y ago by Derek Elkins‭

Answer
#1: Initial revision by user avatar Derek Elkins‭ · 2020-10-04T05:37:59Z (over 3 years ago)
Based on the [source code](https://github.com/sympy/sympy/blob/4c9630723d6d76a356ff6e4cc65e994783c54bd1/sympy/polys/polytools.py#L2337) which delegates to [this implementation](https://github.com/sympy/sympy/blob/4c9630723d6d76a356ff6e4cc65e994783c54bd1/sympy/polys/polyclasses.py#L601) among others, `base.diff((x, n))` means to compute the `n`-th derivative of `base` with respect to `x`. Any arguments to `diff` which aren't tuples get tupled with 1, e.g. `base.diff(x)` is more or less equivalent to `base.diff((x, 1))`. Multiple arguments essentially correspond to repeated differentiation, e.g. `base.diff((x, m), (y, n))` is more or less the same as `base.diff((x, m).diff((y, n))`.

Numeric arguments are indexes into the array of generators provided when the polynomial was created. That is, if `base` is defined by `Poly(..., x, y)`, then `base.diff((0, n))` and `base.diff((x, n))` are more or less the same. Similarly, `base.diff((1, n))` and `base.diff((y, n))`. This is handled by the method [_gen_to_level](https://github.com/sympy/sympy/blob/4c9630723d6d76a356ff6e4cc65e994783c54bd1/sympy/polys/polytools.py#L1810). That method also allows negative numbers to index backwards into the array of generators, i.e. `base.diff((-1, n))` is also equivalent to `base.diff((y, n))`.

The example from the other answer of `base.diff(y, 2)` gets interpreted as `base.diff((y, 1), (2, 1))`, however, since there is only 2 generators (`x` and `y`), this should lead to an exception being thrown in `_gen_to_level` as 2 is not a valid index into the array of generators.

That said, the example in the documentation is rather cryptic, and it is a bit bizarre to have `base.diff((0,0))` which would mean "take the 0-th derivative of the first generator" which is well-defined but corresponds to doing nothing.