<jupyter_start><jupyter_text>SymPyThe SymPy package is useful for symbolic algebra, much like the commercial software Mathematica.We won't make much use of SymPy during the boot camp, but it is definitely useful to know aboutfor mathematics courses.<jupyter_code>import sympy as sp
sp.init_printing()<jupyter_output><empty_output><jupyter_text>Symbols and ExpressionsWe'll define `x` and `y` to be `sympy` symbols, then do some symbolic algebra.<jupyter_code>x, y = sp.symbols("x y")
expression = (x+y)**4
expression
sp.expand(expression)
expression = 8*x**2 + 26*x*y + 15*y**2
expression
sp.factor(expression)
expression - 20 *x*y - 14*y**2
sp.factor(expression - 20*x*y - 14*y**2)<jupyter_output><empty_output><jupyter_text>Lambdify: Making python functions from sympy expressions<jupyter_code>expression
f = sp.lambdify((x,y), expression, 'numpy')
f(3,4)
8 * 3**2 + 26 * 3 * 4 + 15 * 4**2<jupyter_output><empty_output><jupyter_text>CalculusYou can use `sympy` to perform symbolic integration or differentiation.<jupyter_code>expression = 5*x**2 * sp.sin(3*x**3)
expression
expression.diff(x)
expression = sp.cos(x)
expression.integrate(x)
expression.integrate((x, 0, sp.pi / 2))<jupyter_output><empty_output><jupyter_text>You can also create unevalated integrals or derivatives. These can later be evaluated with their `doit` methods.<jupyter_code>deriv = sp.Derivative(expression)
deriv
deriv.doit()
inte = sp.Integral(expression, (x, 0, sp.pi / 2))
inte
inte.doit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.126, 'fraction_numerical': 0.026, 'mean_word_length': 6.9, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '292896', 'license': 'MIT', 'n_tokens_mistral': 564, 'n_tokens_neox': 524, 'n_words': 138, 'path': 'SymPyExample.ipynb', 'repo_name': 'shumway/srt_bootcamp', 'size': '1500'}