<jupyter_start><jupyter_text>SymPySymPy is a python library for [symbolic computing](https://en.wikipedia.org/wiki/Symbolic_computation).  Perhaps the most well known software that embraces symbolic computing is [Maple](https://en.wikipedia.org/wiki/Maple_(software)).  SymPy although significantly less powerul enables numerous symbolic areas of mathematics: algebra, arithmetic, calculus, discrete mathematics and quantum physics. It is capable of formatting the result of the computations as LaTeX code.SymPy is free software and is licensed under New BSD License. The lead developers are <NAME> and <NAME>.  The following code will import everything from the package and enable latex rendering of output.<jupyter_code>from sympy import *
from sympy import init_printing
init_printing()<jupyter_output><empty_output><jupyter_text>Symbolic AlgebraIn the same way we do algebra on paper we can use a computer.  Symbolic computation or [algebraic computation](https://en.wikipedia.org/wiki/Computer_algebra), is a scientific area that refers to the study and development of algorithms and software for manipulating mathematical expressions and other mathematical objects.For example<jupyter_code>sqrt(8)<jupyter_output><empty_output><jupyter_text>We need to define our variables symbolically before we use them<jupyter_code>x,y,z = symbols('x y z')
x<jupyter_output><empty_output><jupyter_text>once the variables are available we can define expressions and perform actions on them<jupyter_code>expr = x + 2*y
print(expr)
expr = expr + 9*x
print(expr)<jupyter_output>x + 2*y
10*x + 2*y<jupyter_text>you may want to **expand** the algebric representation<jupyter_code>expr2 = x*expr
print(expr2)
print(expand(expr2))<jupyter_output>x*(10*x + 2*y)
10*x**2 + 2*x*y<jupyter_text>Recall that factoring is the process of finding the factors--that is finding the terms to multiply together to get an expression. If you need a refresher check out the [Khan academy materials on factoring](https://www.khanacademy.org/math/algebra/polynomial-factorization).  Sympy can factorize<jupyter_code>expr = x + x**2
factor(expr)<jupyter_output><empty_output><jupyter_text>Symbolic calculus - derivatives Definition of a derivativeFrom [wiki](https://en.wikipedia.org/wiki/Derivative) >Derivatives are a fundamental tool of calculus. For example, the derivative of the position of a moving object with respect to time is the object's velocity: this measures how quickly the position of the object changes when time advances.The derivative of f with respect to x is given by  $ f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}$    when this limit exits. Basic derivative propertiesAssuming *c* and *n* to be real constants, then these theorems hold true:and if you want [proofs.](http://www2.bc.cc.ca.us/resperic/Math6A/Lectures/ch2/3/DerivativeRuleProofs.htm)>**1**. *The derivative of a constant is 0*$ \frac{d}{dx}c = 0 $<jupyter_code>c = 1
diff(c)<jupyter_output><empty_output><jupyter_text>>**2**. *The derivative of a variable is 1*$ \frac{d}{dx}x = 1 $<jupyter_code>diff(x)<jupyter_output><empty_output><jupyter_text>>**3**. *The derivative of a constant times a function is the same as the deriviative of that function times the constant*$ \frac{d}{dx}(c \cdot f(x)) = c \cdot \frac{d}{dx}f(x) = c \cdot f'(x) $<jupyter_code>diff(1/x * c)
c * diff(1/x)<jupyter_output>-1/x**2<jupyter_text>>**4**. The derivative of a function plus or minus another function is the same as if we took the derivative separately$ \frac{d}{dx}(f(x) + g(x)) = f'(x) + g'(x) $  (true for minus as well)<jupyter_code>diff(1/x + ln(x))
diff(1/x) + diff(ln(x))<jupyter_output><empty_output><jupyter_text>>**5**. The derivative$ \frac{d}{dx}x^n = n \cdot x^{n-1} $  the power rule<jupyter_code>## can you show that this rule holds?
## here is a way to write partial derivatives
expr = Derivative(1/x+y,x)
expr<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11133914828116984, 'fraction_numerical': 0.01051821446895844, 'mean_word_length': 6.0, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 50, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '154034', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1231, 'n_words': 422, 'path': 'notebooks/sympy-primer.ipynb', 'repo_name': 'cowleyk/math-essentials', 'size': '3911'}