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

Parsing input


The last module that we will be discussing is a small but useful module that parses input strings into SymPy expressions. Here is a program that demonstrates the use of this module. There are methods available for making parentheses optional, making multiplication implicit, and allowing functions to be instantiated:

from sympy.parsing.sympy_parser import parse_expr
from sympy.parsing.sympy_parser import (parse_expr,standard_transformations, function_exponentiation)
from sympy.parsing.sympy_parser import (parse_expr,standard_transformations, implicit_multiplication_application)

x = Symbol('x')
parse_expr("2*x**2+3*x+4"))

parse_expr("10*sin(x)**2 + 3xyz")

transformations = standard_transformations + (function_exponentiation,)
parse_expr('10sin**2 x**2 + 3xyz + tan theta', transformations=transformations)

parse_expr("5sin**2 x**2 + 6abc + sec theta",transformations=(standard_transformations +(implicit_multiplication_application,)))