Book Image

Mastering Python Scientific Computing

Book Image

Mastering Python Scientific Computing

Overview of this book

Table of Contents (17 chapters)
Mastering Python Scientific Computing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Pretty printing


SymPy can pretty print the output using ASCII and Unicode characters. There are a number of printers available in SymPy. The following are the most common printers of SymPy:

  • LaTeX

  • MathML

  • Unicode pretty printer

  • ASCII pretty printer

  • Str

  • dot

  • repr

This program demonstrates the pretty print function to print various expressions using the ASCII and Unicode printers:

from sympy.interactive import init_printing
from sympy import Symbol, sqrt
from sympy.abc import x, y
sqrt(21)
init_printing(pretty_print=True) 
sqrt(21) 
theta = Symbol('theta') 
init_printing(use_unicode=True) 
theta 
init_printing(use_unicode=False) 
theta 
init_printing(order='lex') 
str(2*y + 3*x + 2*y**2 + x**2+1) 
init_printing(order='grlex') 
str(2*y + 3*x + 2*y**2 + x**2+1) 
init_printing(order='grevlex') 
str(2*y * x**2 + 3*x * y**2) 
init_printing(order='old') 
str(2*y + 3*x + 2*y**2 + x**2+1) 
init_printing(num_columns=10) 
str(2*y + 3*x + 2*y**2 + x**2+1)

The following program uses the LaTeX printer for pretty printing...