## 2018年10月13日土曜日

### 数学 – Python - 数学はここから始まる - 数 – 分数式の演算と分数式 – 分数式の演算(加法・減法(和と差)、既約、通分、因数分解)

1. $\frac{ac-bc+ab-ac+bc-ab}{abc}=0$

2. $\frac{x-1}{{x}^{2}-1}=\frac{1}{x+1}$

3. $\frac{x+2-4}{x-2}=1$

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

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

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

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

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

9. $\begin{array}{}\frac{2a}{{a}^{2}-1}+\frac{2a}{{a}^{2}+1}+\frac{4{a}^{3}}{{a}^{4}+1}\\ =\frac{4{a}^{3}}{{a}^{4}-1}+\frac{4{a}^{3}}{{a}^{4}+1}\\ =\frac{8{a}^{7}}{{a}^{8}-1}\\ =\frac{8{a}^{7}}{\left(a+1\right)\left(a-1\right)\left({a}^{2}+1\right)\left({a}^{4}+1\right)}\end{array}$

10. $\begin{array}{}\frac{x+2+x}{x\left(x+1\right)\left(x+2\right)}+\frac{1}{\left(x+2\right)\left(x+3\right)}\\ =\frac{2}{x\left(x+2\right)}+\frac{1}{\left(x+2\right)\left(x+3\right)}\\ =\frac{2x+6+x}{x\left(x+2\right)\left(x+3\right)}\\ =\frac{3}{x\left(x+3\right)}\end{array}$

11. $\frac{-a\left(b-c\right)-b\left(c-a\right)-c\left(a-b\right)}{\left(a-b\right)\left(b-c\right)\left(c-a\right)}=0$

12. $\begin{array}{}\frac{-\left(b-c\right)\left(b+1\right)-\left(c-a\right)\left(a+1\right)}{\left(a-b\right)\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)}\\ =\frac{-{b}^{2}-b+bc+c-ca-c+{a}^{2}+a}{\left(a-b\right)\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)}\\ =\frac{-{b}^{2}-b+bc+{a}^{2}-ca+a}{\left(a-b\right)\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)}\\ =\frac{\left(a+b\right)\left(a-b\right)+\left(1-c\right)\left(a-b\right)}{\left(a-b\right)\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)}\\ =\frac{a+b-c+1}{\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)}\end{array}$

残りの計算。

$\frac{\left(a+b-c+1\right)\left(c+1\right)-\left(a+1\right)\left(b+1\right)}{\left(b-c\right)\left(c-a\right)\left(a+1\right)\left(b+1\right)\left(c+1\right)}$

分子の計算。

$\begin{array}{}-{c}^{2}+\left(a+b\right)c+a+b+1-ab-a-b-1\\ =-{c}^{2}+\left(a+b\right)c-ab\\ =-\left({c}^{2}-\left(a+b\right)c+ab\right)\\ =-\left(c-a\right)\left(c-b\right)\\ =\left(b-c\right)\left(c-a\right)\end{array}$

よって求める計算結果は

$\frac{1}{\left(a+1\right)\left(b+1\right)\left(c+1\right)}$

コード(Emacs)

Python 3

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

print('19.')

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

ts = [(a - b) / (a * b) + (b - c) / (b * c) + (c - a) / (c * a),
x / (x ** 2 - 1) - 1 / (x ** 2 - 1),
(x + 2) / (x - 2) + 4 / (2 - x),
1 / (x + 1) - 2 * x / (x ** 2 - 1),
x + 2 - 2 * x / (x + 1) - (3 * x ** 2 + 4) / (x * (x + 1)),
(x - 2) / (x ** 2 - x + 1) - 1 /
(x + 1) + (x ** 2 + x + 3) / (x ** 3 + 1),
1 / (x ** 2 - 3 * x + 2) + 2 / (2 * x ** 2 - x - 1) -
3 / (2 * x ** 2 - 3 * x - 2),
1 / x - 1 / (x + 1) - 1 / (x + 2) + 1 / (x + 3),
1 / (a - 1) + 1 / (a + 1) + 2 * a /
(a ** 2 + 1) + 4 * a ** 3 / (a ** 4 + 1),
1 / (x * (x + 1)) + 1 / ((x + 1) * (x + 2)) + 1 / ((x + 2) * (x + 3)),
a / ((a - b) * (a - c)) + b /
((b - c) * (b - a)) + c / ((c - a) * (c - b)),
1 / ((a - b) * (a - c) * (a + 1)) + 1 / ((b - c) * (b - a) * (b + 1)) + 1 / ((c - a) * (c - b) * (c + 1))]

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


$./sample19.py 19. (1) 0 (2) 1 ───── x + 1 (3) 1 (4) -1 ───── x - 1 (5) ⎛ 2 ⎞ (x - 2)⋅⎝x + 2⎠ ──────────────── x⋅(x + 1) (6) x ────────── 2 x - x + 1 (7) x ───────────────────────── (x - 2)⋅(x - 1)⋅(2⋅x + 1) (8) 2⋅(2⋅x + 3) ───────────────────────── x⋅(x + 1)⋅(x + 2)⋅(x + 3) (9) 7 8⋅a ───────────────────────────────── ⎛ 2 ⎞ ⎛ 4 ⎞ (a - 1)⋅(a + 1)⋅⎝a + 1⎠⋅⎝a + 1⎠ (10) 3 ───────── x⋅(x + 3) (11) 0 (12) 1 ─────────────────────── (a + 1)⋅(b + 1)⋅(c + 1)$