In [1]:
import sympy as sym
from IPython.display import display,Math
In [2]:
display(Math('f(x) = 3+2x-5x^2+7x^4'))
display(Math('g(x) = 4x^2+x^5'))

print('Summation rule')
display(Math('\\quad (f+g)\' = f\'+g\''))
print('Product rule')
display(Math('\\quad (f+g)\' \\ne f\'\\times g\''))
display(Math('\\quad (f+g)\' = f\'\\times g + f \\times g\''))
$\displaystyle f(x) = 3+2x-5x^2+7x^4$
$\displaystyle g(x) = 4x^2+x^5$
Summation rule
$\displaystyle \quad (f+g)' = f'+g'$
Product rule
$\displaystyle \quad (f+g)' \ne f'\times g'$
$\displaystyle \quad (f+g)' = f'\times g + f \times g'$
In [3]:
x = sym.symbols('x')

f = 3 + 2*x - 5*x**2 + 7*x**4
g = 4*x**2 + x**5

df = sym.diff(f)
dg = sym.diff(g)
print(df)
print(dg)
28*x**3 - 10*x + 2
5*x**4 + 8*x
In [4]:
display(Math('\\text{Summation rule}'))
display(Math('\\quad (f + g)\' = %s' %sym.latex(sym.expand(sym.diff(f+g)))))
display(Math('\\quad f\' + g\' = %s' %sym.latex(sym.expand(df+dg))))
$\displaystyle \text{Summation rule}$
$\displaystyle \quad (f + g)' = 5 x^{4} + 28 x^{3} - 2 x + 2$
$\displaystyle \quad f' + g' = 5 x^{4} + 28 x^{3} - 2 x + 2$
In [5]:
display(Math('\\text{Product rule}'))
display(Math('\\quad(f\\times g)\' = %s' %sym.latex(sym.expand(sym.diff(f*g)))))
display(Math('\\text{Without applying the product rule.}'))
display(Math('\\quad f\' \\times g\' = %s' %sym.latex(sym.expand(sym.diff(f) * sym.diff(g)))))
display(Math('\\text{With applying the product rule.}'))
display(Math('\\quad f\' \\times g + f \\times g\' = %s' %sym.latex(sym.expand(df*g + f*dg))))
$\displaystyle \text{Product rule}$
$\displaystyle \quad(f\times g)' = 63 x^{8} - 35 x^{6} + 180 x^{5} + 15 x^{4} - 80 x^{3} + 24 x^{2} + 24 x$
$\displaystyle \text{Without applying the product rule.}$
$\displaystyle \quad f' \times g' = 140 x^{7} - 50 x^{5} + 234 x^{4} - 80 x^{2} + 16 x$
$\displaystyle \text{With applying the product rule.}$
$\displaystyle \quad f' \times g + f \times g' = 63 x^{8} - 35 x^{6} + 180 x^{5} + 15 x^{4} - 80 x^{3} + 24 x^{2} + 24 x$