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

70%
+5 −1
Q&A What do the number entries mean in the sympy poly.diff(...) tuple syntax?

I am looking to take a partial derivative of a sympy polynomial with respect to a symbol in the polynomial. In the sympy documentation for poly.diff(...) it gives sample code like this: from sympy ...

2 answers  ·  posted 4y ago by jrh‭  ·  last activity 4y ago by Derek Elkins‭

Question python sympy
#2: Post edited by user avatar jrh‭ · 2020-09-30T21:34:24Z (about 4 years ago)
  • I am looking to take a partial derivative of a sympy polynomial with respect to a symbol in the polynomial.
  • In the [sympy documentation for poly.diff(...)](https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly.diff) it gives sample code like this:
  • ```
  • from sympy import Poly
  • from sympy.abc import x, y
  • Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
  • ```
  • There is no explanation I was able to find as to what these tuple values mean.
  • I'm really just trying to supplement the sympy documentation here, but here is my attempt at providing an MVCE for a question I already know the answer to:
  • ```
  • from __future__ import print_function
  • from sympy import poly, symbols
  • from sympy.abc import x, y
  • base = poly(x*y**2 + x, x, y)
  • print('base function is', base)
  • # appears to be the same as doing diff(y)
  • deriv_mysterious1 = base.diff((0, 0), (1, 1))
  • print('deriv_mysterious1 is', deriv_mysterious1)
  • deriv_mysterious2 = base.diff(y)
  • print('deriv_mysterious2 is', deriv_mysterious2)
  • # same as base
  • deriv_mysterious3 = base.diff((0,0))
  • print('deriv_mysterious3 is', deriv_mysterious3)
  • # same as diff(y)
  • deriv_mysterious4 = base.diff((1,1))
  • print('deriv_mysterious4 is', deriv_mysterious4)
  • # same as diff(x)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • The output of which is
  • ```
  • base function is Poly(x*y**2 + x, x, y, domain='ZZ')
  • deriv_mysterious1 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious2 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious3 is Poly(x*y**2 + x, x, y, domain='ZZ')
  • deriv_mysterious4 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious5 is Poly(y**2 + 1, x, y, domain='ZZ')
  • ```
  • How do I use this tuple syntax? What do these numbers refer to?
  • I am looking to take a partial derivative of a sympy polynomial with respect to a symbol in the polynomial.
  • In the [sympy documentation for poly.diff(...)](https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly.diff) it gives sample code like this:
  • ```
  • from sympy import Poly
  • from sympy.abc import x, y
  • Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
  • ```
  • There is no explanation I was able to find as to what the `(0, 0), (1, 1)` tuples refer to.
  • I'm really just trying to supplement the sympy documentation here, but here is my attempt at providing an MVCE for a question I already know the answer to:
  • ```
  • from __future__ import print_function
  • from sympy import poly, symbols
  • from sympy.abc import x, y
  • base = poly(x*y**2 + x, x, y)
  • print('base function is', base)
  • # appears to be the same as doing diff(y)
  • deriv_mysterious1 = base.diff((0, 0), (1, 1))
  • print('deriv_mysterious1 is', deriv_mysterious1)
  • deriv_mysterious2 = base.diff(y)
  • print('deriv_mysterious2 is', deriv_mysterious2)
  • # same as base
  • deriv_mysterious3 = base.diff((0,0))
  • print('deriv_mysterious3 is', deriv_mysterious3)
  • # same as diff(y)
  • deriv_mysterious4 = base.diff((1,1))
  • print('deriv_mysterious4 is', deriv_mysterious4)
  • # same as diff(x)
  • deriv_mysterious5 = base.diff((0,1))
  • print('deriv_mysterious5 is', deriv_mysterious5)
  • ```
  • The output of which is
  • ```
  • base function is Poly(x*y**2 + x, x, y, domain='ZZ')
  • deriv_mysterious1 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious2 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious3 is Poly(x*y**2 + x, x, y, domain='ZZ')
  • deriv_mysterious4 is Poly(2*x*y, x, y, domain='ZZ')
  • deriv_mysterious5 is Poly(y**2 + 1, x, y, domain='ZZ')
  • ```
  • How do I use this tuple syntax? What do these numbers refer to?
#1: Initial revision by user avatar jrh‭ · 2020-09-30T15:50:34Z (about 4 years ago)
What do the number entries mean in the sympy poly.diff(...) tuple syntax?
I am looking to take a partial derivative of a sympy polynomial with respect to a symbol in the polynomial.

In the [sympy documentation for poly.diff(...)](https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly.diff) it gives sample code like this:

```
from sympy import Poly
from sympy.abc import x, y

Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
```

There is no explanation I was able to find as to what these tuple values mean.

I'm really just trying to supplement the sympy documentation here, but here is my attempt at providing an MVCE for a question I already know the answer to:
```
from __future__ import print_function

from sympy import poly, symbols

from sympy.abc import x, y

base = poly(x*y**2 + x, x, y)
print('base function is', base)

# appears to be the same as doing diff(y)
deriv_mysterious1 = base.diff((0, 0), (1, 1))

print('deriv_mysterious1 is', deriv_mysterious1)

deriv_mysterious2 = base.diff(y)

print('deriv_mysterious2 is', deriv_mysterious2)

# same as base
deriv_mysterious3 = base.diff((0,0))
print('deriv_mysterious3 is', deriv_mysterious3)

# same as diff(y)
deriv_mysterious4 = base.diff((1,1))
print('deriv_mysterious4 is', deriv_mysterious4)

# same as diff(x)
deriv_mysterious5 = base.diff((0,1))
print('deriv_mysterious5 is', deriv_mysterious5)
```

The output of which is 

```
base function is Poly(x*y**2 + x, x, y, domain='ZZ')
deriv_mysterious1 is Poly(2*x*y, x, y, domain='ZZ')
deriv_mysterious2 is Poly(2*x*y, x, y, domain='ZZ')
deriv_mysterious3 is Poly(x*y**2 + x, x, y, domain='ZZ')
deriv_mysterious4 is Poly(2*x*y, x, y, domain='ZZ')
deriv_mysterious5 is Poly(y**2 + 1, x, y, domain='ZZ')
```

How do I use this tuple syntax? What do these numbers refer to?