# Note: For an example showing how to use this sort of technique to pretty print a polynomial object with LaTeX in a IPython console or notebook, see this tutorial: # http://nbviewer.jupyter.org/github/Naereen/notebooks/blob/master/Demonstration%20of%20numpy.polynomial.Polynomial%20and%20nice%20display%20with%20LaTeX%20and%20MathJax%20%28python3%29.ipynb Automatic test of all the docstrings: Trying: P = MyPolynomial Expecting nothing ok Trying: X = P([0, 1]) # We define the monome X, to work with it efficiently Expecting nothing ok Trying: print(X) Expecting: X ok Trying: Q1 = 1 + 2*X + 17*X**3 Expecting nothing ok Trying: print(Q1) Expecting: 1 + 2 * X + 17 * X**3 ok Trying: Q2 = Q1 - 2*X Expecting nothing ok Trying: print(Q2) Expecting: 1 + 17 * X**3 ok Trying: Q3 = -1 - 2*X - 17*X**3 Expecting nothing ok Trying: print(Q3) Expecting: (-1) + (-2) * X + (-17) * X**3 ok Trying: print(-Q3) Expecting: 1 + 2 * X + 17 * X**3 ok Trying: Q4 = (1 + 2*X + 17*X**3) ** 20 Expecting nothing ok Trying: print(Q4) # doctest: +ELLIPSIS Expecting: 1 + 40 * X + 760 * X**2 + 9460 * X**3 + 90440 * X**4 + ... + 4064231406647572451819520 * X**60 ok Trying: Q5 = (1 + 2*X + 17*X**3) ** 100 Expecting nothing ok Trying: print(Q5) # doctest: +ELLIPSIS Expecting: 1 + 200 * X + 19800 * X**2 + 1295300 * X**3 + ... + 1108899372780782949283060780215564719143115314569706274981249422854766735454757111223455545827324114733078454801811428605952 * X**300 ok 3 items had no tests: __main__ __main__.MyPolynomial __main__.MyPolynomial.__str__ 1 items passed all tests: 14 tests in __main__.test 14 tests in 4 items. 14 passed and 0 failed. Test passed. More details on these doctests can be found online in the official Python documentation: https://docs.python.org/3/library/doctest.html