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?

It appears that the tuple syntax works like this: (variable index, order of derivative) Where something like: base = poly(x*y**2 + x, x, y) deriv_mysterious5 = base.diff((0,1)) print('deriv_mysteri...

posted 4y ago by jrh‭  ·  edited 4y ago by jrh‭

Answer
#3: Post edited by user avatar jrh‭ · 2020-09-30T21:30:55Z (about 4 years ago)
  • It appears that the tuple syntax works like this:
  • `(variable index, order of derivative)`
  • Where something like:
  • ```
  • base = poly(x*y**2 + x, x, y)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
  • - I was not able to find information on how sympy determines which symbol is symbol 0.
  • I think I would recommend the alternative syntax instead:
  • ```
  • base.diff(<symbol>)
  • ```
  • e.g.,
  • ```
  • base.diff(x)
  • ```
  • Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
  • This syntax works:
  • ```
  • base.diff(y, y)
  • ```
  • I was not able to get this syntax working:
  • ```
  • base.diff(y, 2)
  • ```
  • But a slightly modified version of this does work,
  • ```
  • base.diff((y, 3))
  • ```
  • It appears that the tuple syntax works like this:
  • `(variable index, order of derivative)`
  • Where something like:
  • ```
  • base = poly(x*y**2 + x, x, y)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
  • - I was not able to find information on how sympy determines which symbol is symbol 0.
  • I think I would recommend the alternative syntax instead:
  • ```
  • base.diff(<symbol>)
  • ```
  • e.g.,
  • ```
  • base.diff(x)
  • ```
  • Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
  • This syntax works:
  • ```
  • base.diff(y, y)
  • ```
  • I was not able to get this syntax working:
  • ```
  • base.diff(y, 2)
  • ```
  • But a slightly modified version of this does work,
  • ```
  • base.diff((y, 2))
  • ```
#2: Post edited by user avatar jrh‭ · 2020-09-30T21:29:04Z (about 4 years ago)
  • It appears that the tuple syntax works like this:
  • `(variable index, order of derivative)`
  • Where something like:
  • ```
  • base = poly(x*y**2 + x, x, y)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
  • - I was not able to find information on how sympy determines which symbol is symbol 0.
  • I think I would recommend the alternative syntax instead:
  • ```
  • base.diff(<symbol>)
  • ```
  • e.g.,
  • ```
  • base.diff(x)
  • ```
  • Though, interestingly, it seems that for higher order derivatives, only this syntax is supported:
  • ```
  • base.diff(x, x, x)
  • ```
  • I was not able to get this syntax working:
  • ```
  • base.diff(x, 3)
  • ```
  • It appears that the tuple syntax works like this:
  • `(variable index, order of derivative)`
  • Where something like:
  • ```
  • base = poly(x*y**2 + x, x, y)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.
  • - I was not able to find information on how sympy determines which symbol is symbol 0.
  • I think I would recommend the alternative syntax instead:
  • ```
  • base.diff(<symbol>)
  • ```
  • e.g.,
  • ```
  • base.diff(x)
  • ```
  • Though, interestingly, it seems that for higher order derivatives, `poly.diff` has some behavior that seems to differ from `diff(expr,...)` as seen on the [Calculus](https://docs.sympy.org/latest/tutorial/calculus.html#derivatives) page.
  • This syntax works:
  • ```
  • base.diff(y, y)
  • ```
  • I was not able to get this syntax working:
  • ```
  • base.diff(y, 2)
  • ```
  • But a slightly modified version of this does work,
  • ```
  • base.diff((y, 3))
  • ```
#1: Initial revision by user avatar jrh‭ · 2020-09-30T15:50:48Z (about 4 years ago)
It appears that the tuple syntax works like this: 

`(variable index, order of derivative)`

Where something like:

```
base = poly(x*y**2 + x, x, y)
deriv_mysterious5 = base.diff((0,1))
print('deriv_mysterious5 is', deriv_mysterious5)
``` 

Means: "Take first derivative of `base` with respect to symbol[0]", in this case symbol 0 is x.

- I was not able to find information on how sympy determines which symbol is symbol 0.

I think I would recommend the alternative syntax instead:

```
base.diff(<symbol>)
```

e.g.,

```
base.diff(x)
```

Though, interestingly, it seems that for higher order derivatives, only this syntax is supported:

```
base.diff(x, x, x)
```

I was not able to get this syntax working:

```
base.diff(x, 3)
```