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.

Comments on What do the number entries mean in the sympy poly.diff(...) tuple syntax?

Post

What do the number entries mean in the sympy poly.diff(...) tuple syntax?

+5
−1

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 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?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (2 comments)
General comments
jrh‭ wrote over 3 years ago · edited over 3 years ago

I don't really know how to interpret a downvote on this, if you found official documentation somewhere on this please link it. I had to piece this together from 5 or 6 random websites to figure it out. There's this but it has diff(expr, <symbol>, <order>) not poly.diff((<mysterious symbol index>, <order>)), and poly.diff(...) is not taking the partial derivative with respect to the number 0 or a symbol named 0.

Skipping 1 deleted comment.

Moshi‭ wrote over 3 years ago

It's kinda funny how the "Run code block in SymPy Live" on the docs gives an error for that example