<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Tutorial Brief
SymPy is symbolic mathematics library written completely in Python and doesn't require any dependencies.
Finding Help
Step1:  symbols() & Symbol()
Step2:  Assumptions for symbols
Step3:  Imaginary Numbers
Step4:  Rational()
Step5:  Numerical evaluation
Step6:  subs()
Step7:  factor() and expand()
Step8:  simplify()
Step9:  apart() and together()
Step10:  Calculus
Step11:  Sum()
Step12:  Product()
Step13:  Solve()
Step14:  Units
Step15:  Converting from Kilometers/hours to Miles/hours
Step16:  Working with NumPy / Pandas and Matplotlib
<ASSISTANT_TASK:>
Python Code:
from sympy import *
3 + math.sqrt(3)
expr = 3 * sqrt(3)
expr
init_printing(use_latex='mathjax')
expr
expr = sqrt(8)
expr
Explanation: Tutorial Brief
SymPy is symbolic mathematics library written completely in Python and doesn't require any dependencies.
Finding Help:
http://docs.sympy.org/latest/index.html
http://sympy.org/en/features.html
http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-5-Sympy.ipynb
<table>
<tr>
    <td><img src="http://www.scipy.org/_static/images/numpylogo_med.png"  style="width:50px;height:50px;" /></td>
    <td><h4>NumPy</h4> Base N-dimensional array package </td>
    <td><img src="http://www.scipy.org/_static/images/scipy_med.png" style="width:50px;height:50px;" /></td>
    <td><h4>SciPy</h4> Fundamental library for scientific computing </td>
    <td><img src="http://www.scipy.org/_static/images/matplotlib_med.png" style="width:50px;height:50px;" /></td>
    <td><h4>Matplotlib</h4> Comprehensive 2D Plotting </td>
</tr>
<tr>
    <td><img src="http://www.scipy.org/_static/images/ipython.png" style="width:50px;height:50px;" /></td>
    <td><h4>IPython</h4> Enhanced Interactive Console </td>
    <td style="background:Lavender;"><img src="http://www.scipy.org/_static/images/sympy_logo.png" style="width:50px;height:50px;" /></td>
    <td style="background:Lavender;"><h4>SymPy</h4> Symbolic mathematics </td>
    <td><img src="http://www.scipy.org/_static/images/pandas_badge2.jpg" style="width:50px;height:50px;" /></td>
    <td><h4>Pandas</h4> Data structures & analysis </td>
</tr>
</table>
SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.
http://sympy.org/
Import SymPy
End of explanation
x, y = symbols("x y")
expr = x**2 + y**2
expr
expr = (x+y)**3
expr
Explanation: symbols() & Symbol()
End of explanation
a = Symbol("a")
a.is_imaginary
b = Symbol("b", integer=True)
b.is_imaginary
c = Symbol("c", positive=True)
c.is_positive
c.is_imaginary
Explanation: Assumptions for symbols
End of explanation
I
I ** 2
Explanation: Imaginary Numbers
End of explanation
Rational(1,3)
Rational(1,3) + Rational(1,2)
Explanation: Rational()
End of explanation
expr = Rational(1,3) + Rational(1,2)
N(expr)
N(pi, 100)
pi.evalf(100)
Explanation: Numerical evaluation
End of explanation
expr = x**2 + 2*x + 1
expr
expr.subs(x, 1)
expr = pi * x**2
expr
expr.subs(x, 3)
N(_)
Explanation: subs()
End of explanation
expr = (x + y) ** 2
expr
expand(expr)
factor(_)
Explanation: factor() and expand()
End of explanation
expr = (2*x + Rational(1,3)*x + 4) / x
expr
simplify(expr)
expr = "(2*x + 1/3*x + 4)/x"
simplify(expr)
expr = sin(x)/cos(x)
expr
simplify(expr)
Explanation: simplify()
End of explanation
expr = 1/(x**2 + 2*x)
expr
apart(expr)
together(_)
Explanation: apart() and together()
End of explanation
diff(sin(x), x)
diff(log(x**2 + 1) + 2*x, x)
integrate(cos(x), x)
Integral(sin(x), (x,0,pi))
N(_)
Explanation: Calculus
End of explanation
expr = Sum(1/(x**2 + 2*x), (x, 1, 10))
expr
expr.doit()
Explanation: Sum()
End of explanation
expr = Product(1/(x**2 + 2*x), (x, 1, 10))
expr
expr.doit()
Explanation: Product()
End of explanation
expr = 2*x + 1
solve(expr)
expr = x**2 - 1
solve(expr)
expr_1 = 2*x + y + 3
expr_2 = 2*y - x
solve([expr_1, expr_2],(x,y))
Explanation: Solve()
End of explanation
from sympy.physics import units as u
5. * u.milligram
1./2 * u.inch
1. * u.nano
u.watt
u.ohm
Explanation: Units
End of explanation
kmph = u.km / u.hour
mph = u.mile / u.hour
N(mph / kmph)
80 * N(mph / kmph)
Explanation: Converting from Kilometers/hours to Miles/hours
End of explanation
def sympy_expr(x_val):
    expr = x**2 + sqrt(3)*x - Rational(1,3)
    return expr.subs(x, x_val)
sympy_expr(3)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
list1 = np.arange(1,1000)
list2 = pd.Series(list1)
%timeit [sympy_expr(item) for item in list1]
%timeit [sympy_expr(item) for item in list2]
%timeit np.vectorize(sympy_expr)(list1)
%timeit list2.apply(sympy_expr)
expr = x**2 + sqrt(3)*x - Rational(1,3)
lf = lambdify(x, expr)
%timeit lf(list1)
%timeit lf(list2)
fig = plt.figure()
axes = fig.add_subplot(111)
x_vals = np.linspace(-5.,5.)
y_vals = lf(x_vals)
axes.grid()
axes.plot(x_vals, y_vals)
plt.show();
Explanation: Working with NumPy / Pandas and Matplotlib
End of explanation
<END_TASK>