python - Why does sympy.diff not differentiate sympy polynomials as expected? -


i trying figure out why sympy.diff not differentiate sympy polynomials expected. normally, sympy.diff works fine if symbolic variable defined , polynomial not defined using sympy.poly. however, if function defined using sympy.poly, sympy.diff not seem compute derivative. below code sample shows mean:

import sympy sy  # define symbolic variables x = sy.symbol('x') y = sy.symbol('y')  # define function without using sy.poly f1 = x + 1 # define function using sy.poly f2 = sy.poly(x + 1, x, domain='qq')  # compute derivatives , return results df1 = sy.diff(f1,x) df2 = sy.diff(f2,x) print('f1:  ',f1) print('f2:  ',f2) print('df1:  ',df1) print('df2:  ',df2) 

this prints following results:

f1:   x + 1 f2:   poly(x + 1, x, domain='qq') df1:   1 df2:   derivative(poly(x + 1, x, domain='qq'), x) 

why sympy.diff not know how differentiate sympy.poly version of polynomial? there way differentiate sympy polynomial, or way convert sympy polynomial form allows differentiated?

note: tried different domains (i.e., domain='rr' instead of domain='qq'), , output not change.

this appears bug. can around calling diff directly on poly instance. ideally calling function diff top level sympy module should yield same result calling method diff.

in [1]: sympy import *  in [2]: sympy.abc import x  in [3]: p = poly(x+1, x, domain='qq')  in [4]: p.diff(x) out[4]: poly(1, x, domain='qq')  in [5]: diff(p, x) out[5]: derivative(poly(x + 1, x, domain='qq'), x)  in [6]: diff(p, x).doit() out[6]: derivative(poly(x + 1, x, domain='zz'), x) 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -