<jupyter_start><jupyter_text>sympy*sympy* library can be used to handle mathematical formula. **mathemathica** and **matlab** are the famous language in this genre, but they are not open source and expensive software.The advantage of sympy is that- calculate algebra- copy the formula in *latex* format, which can be paste in thesis or technical paper- (and many more)  fraction (Rational)*sympy* supports fraction(Function name is *Rational*) such as 1/3.<jupyter_code>import sympy as smp

x = smp.Rational(1,3)
y = smp.Rational(1,2)

print(x, y, x+y)
print(x*3, (x+y)*6)<jupyter_output>1/3 1/2 5/6
1 5<jupyter_text>Irrational Number*sympy* support irrational number such as $\sqrt{2}, \pi,  e$<jupyter_code>root2 = smp.sqrt(2)
print('Root 2:', root2.evalf(100))
print('Pi:    ', smp.pi.evalf(100))
print('e:     ', smp.E.evalf(100))<jupyter_output>Root 2: 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573
Pi:     3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
e:      2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427<jupyter_text>algebra*sympy* is powerful when solving algebra.<jupyter_code>x = smp.Symbol('x')  # Define 1 symbol
y, z = smp.symbols('y z')  # Define 2 or more symbols

f = x**2 - 2*x + 1
print('Factor', smp.factor(f))
print('Solve', smp.solve(f, x))
f = x + y -7     # x+y = 7
g = x * y -10    # x*y = 10
smp.solve([f,g])
from sympy import symbols, solve, factor

f = x**7 - 1
print(factor(f))
print(solve(f))<jupyter_output>(x - 1)*(x**6 + x**5 + x**4 + x**3 + x**2 + x + 1)
[1, -cos(pi/7) - I*sin(pi/7), -cos(pi/7) + I*sin(pi/7), cos(2*pi/7) - I*sin(2*pi/7), cos(2*pi/7) + I*sin(2*pi/7), -cos(3*pi/7) - I*sin(3*pi/7), -cos(3*pi/7) + I*sin(3*pi/7)]<jupyter_text>Prime factorizationfactorint() function of *sympy* performs prime factorization(decomposition).<jupyter_code>from sympy import factorint

years = [2017,2018,2019]

for y in years:
    print(factorint(y))
# print years that are product of 3 different prims

for year in range(1900, 2019):
    primes = factorint(year)
    if sum(primes.values()) == 3 and len(primes) == 3:
        print('Year:', year, 'Prime', primes)
factorint(1234567890123456789012345678913)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14824335904027422, 'fraction_numerical': 0.18251928020565553, 'mean_word_length': 5.379781420765028, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '651149', 'license': 'MIT', 'n_tokens_mistral': 1191, 'n_tokens_neox': 945, 'n_words': 217, 'path': 'sympy.ipynb', 'repo_name': 'ShinjiKatoA16/UCSY-sw-eng', 'size': '2334'}