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?
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?
1 comment thread