Ask Your Question

Revision history [back]

Following on tmonteil's answer, you shouldn't mix the symbolic function f(x) = ... with a Python function def h(x): .... You can define f as a polynomial in ZZ['x'] as in the other answer, but you can also use the symbolic approach:

sage: f(x) = 122313*x^23 + 445*x^12 + 2013*x + 2345
sage: h(x) = diff(f, x)
sage: h(x)
2813199*x^22 + 5340*x^11 + 2013
sage: h(5)
6707189083360107423888

The two approaches when defining f:

sage: R.<x> = ZZ[]
sage: f = 122313*x^23 + 445*x^12 + 2013*x + 2345 # polynomial
sage: type(f)
<class 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
sage: f(x) = 122313*x^23 + 445*x^12 + 2013*x + 2345 # symbolic
sage: type(f)
<class 'sage.symbolic.expression.Expression'>