#!/usr/bin/env python # coding: utf-8 # # Factoring Polynomials with SymPy # Here is an example that uses [SymPy](http://sympy.org/en/index.html) to factor polynomials. # In[ ]: from ipywidgets import interact from IPython.display import display # In[ ]: from sympy import Symbol, Eq, factor, init_printing init_printing(use_latex='mathjax') # In[ ]: x = Symbol('x') # In[ ]: def factorit(n): display(Eq(x**n-1, factor(x**n-1))) # Notice how the output of the `factorit` function is properly formatted LaTeX. # In[ ]: factorit(12) # In[ ]: interact(factorit, n=(2,40));