## 2018年10月14日日曜日

### 数学 – Python - 数学はここから始まる - 数 – 分数式の演算と分数式 – 分数式の演算(乗法・除法(積と商)、既約、通分、因数分解)

1. $\frac{\left(x+7\right)\left(x-7\right)\left(x+2\right)}{x\left(x+2\right)\left(x-7\right)}=\frac{x+7}{x}$

2. $\frac{\left(x+y\right){\left(x-y\right)}^{2}}{{\left(x-y\right)}^{2}x\left(x+y\right)}=\frac{1}{x}$

3. $\frac{\left(x+1\right)\left(x+2\right)\left(x+4\right)\left(x-3\right)}{\left(x-3\right)\left(x-2\right)\left(x+1\right)\left(x+3\right)}=\frac{\left(x+2\right)\left(x+4\right)}{\left(x-2\right)\left(x+3\right)}$

4. $\frac{5\left(x-1\right)\left(x+2\right)\left({x}^{2}-2x+4\right)}{\left(x-6\right)\left(x+2\right)4\left(x+1\right)\left(x-1\right)}=\frac{5\left({x}^{2}-2x+4\right)}{4\left(x-6\right)\left(x+1\right)}$

5. $\frac{\left(a-2\right)\left(a-3\right)2\left(3a+2\right)\left(a+1\right)}{\left(3a+2\right)\left(a-1\right)\left(a-3\right)\left(a+2\right)}=\frac{2\left(a-2\right)\left(a+1\right)}{\left(a-1\right)\left(a+2\right)}$

6. $\frac{\left(1+a\right)\left(1-a\right)\left(1+b\right)\left(1-b\right)}{\left(1+b\right)a\left(1+a\right)\left(1-a\right)}=\frac{1-b}{a}$

7. $\frac{\left(2x-5\right)\left(3x+4\right)\left(x-2\right)\left(x+1\right)x\left(x+2\right)}{\left(x+2\right)\left(x-2\right)3x\left(2x-5\right)\left(x+1\right)\left(3x+4\right)}=\frac{1}{3}$

8. $\begin{array}{}\frac{{x}^{2}-4x+3-4x+12+12x-12}{\left(x-1\right)\left(x-3\right)}·\frac{{x}^{2}+4x+3+4x+12-12x-12}{\left(x+1\right)\left(x+3\right)}\\ =\frac{{x}^{2}+4x+3}{\left(x-1\right)\left(x-3\right)}·\frac{{x}^{2}-4x+3}{\left(x+1\right)\left(x+3\right)}\\ =\frac{\left(x+1\right)\left(x+3\right)}{\left(x-1\right)\left(x-3\right)}·\frac{\left(x-1\right)\left(x-3\right)}{\left(x+1\right)\left(x+3\right)}\\ =1\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols

print('20.')

a, b, x, y = symbols('a, b, x, y')

ts = [(x ** 2 - 49) / (x ** 2 + 2 * x) * (x + 2) / (x - 7),
(x ** 2 - y ** 2) / (x ** 2 - 2 * x *
y + y ** 2) * (x - y) / (x ** 2 + x * y),
(x ** 2 + 3 * x + 2) / (x ** 2 - 5 * x + 6) /
((x ** 2 + 4 * x + 3) / (x ** 2 + x - 12)),
(5 * x - 5) / (x ** 2 - 4 * x - 12) / ((4 * x ** 2 - 4) / (x ** 3 + 8)),
(a ** 2 - 5 * a + 6) / (3 * a ** 2 - a - 2) *
(6 * a ** 2 + 10 * a + 4) / (a ** 2 - a - 6),
(1 - a ** 2) / (1 + b) * (1 - b ** 2) / (a + a ** 2) * 1 / (1 - a),
(6 * x ** 2 - 7 * x - 20) / (x ** 2 - 4) * (x ** 2 - x - 2) /
(6 * x ** 2 - 15 * x) / ((3 * x ** 2 + 7 * x + 4) / (x ** 2 + 2 * x)),
(1 - 4 / (x - 1) + 12 / (x - 3)) * (1 + 4 / (x + 1) - 12 / (x + 3))]

for i, t in enumerate(ts, 1):
print(f'({i})')
pprint(t.factor())
print()


$./sample20.py 20. (1) x + 7 ───── x (2) 1 ─ x (3) (x + 2)⋅(x + 4) ─────────────── (x - 2)⋅(x + 3) (4) ⎛ 2 ⎞ 5⋅⎝x - 2⋅x + 4⎠ ───────────────── 4⋅(x - 6)⋅(x + 1) (5) 2⋅(a - 2)⋅(a + 1) ───────────────── (a - 1)⋅(a + 2) (6) -(b - 1) ───────── a (7) 1/3 (8) 1$