## 2020年1月4日土曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 分数式とその計算 - 分数式の演算、加法と減法、通分

1. $\begin{array}{l}\frac{\left(a-b\right)c+a\left(b-c\right)+b\left(c-a\right)}{abc}\\ =0\end{array}$

2. $\begin{array}{l}\frac{1-x+2x}{1-{x}^{2}}\\ =\frac{1+x}{1-{x}^{2}}\\ =\frac{1}{1-x}\end{array}$

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

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

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

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

7. $\begin{array}{l}\frac{\left(x+2\right)\left(x+1\right)-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}-2{x}^{2}+2x-4}{x\left(x+1\right)}\end{array}$

8. $\begin{array}{l}\frac{{x}^{2}-x-2-{x}^{2}+x-1}{{x}^{3}+1}+\frac{{x}^{2}+x+3}{{x}^{3}+1}\\ =\frac{{x}^{2}+x}{{x}^{3}+1}\end{array}$

9. $\begin{array}{l}\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}\end{array}$

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

11. $\begin{array}{l}\frac{x-2}{\left(2x-3\right)\left(x-1\right)}+\frac{3x-1}{\left(2x-3\right)\left(x+2\right)}+\frac{2{x}^{2}-5}{\left(x+2\right)\left(x-1\right)}\\ =\frac{{x}^{2}-4+3{x}^{2}-4x+1}{\left(2x-3\right)\left(x-1\right)\left(x+2\right)}+\frac{2{x}^{2}-5}{\left(x+2\right)\left(x-1\right)}\\ =\frac{4{x}^{2}-4x-3}{\left(2x-3\right)\left(x-1\right)\left(x+2\right)}+\frac{4{x}^{3}-6{x}^{2}-10x+15}{\left(2x-3\right)\left(x-1\right)\left(x+2\right)}\\ =\frac{4{x}^{3}-2{x}^{2}-14x+12}{\left(2x-3\right)\left(x-1\right)\left(x+2\right)}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols

print('13.')

class MyTest(TestCase):
def test(self):
x, a, b, c = symbols('x, a, b, c')
spam = [(a - b) / (a * b) + (b - c) / (b * c) + (c - a) / (c * a),
1 / (1 + x) + 2 * x / (1 - x ** 2),
1 / (x + 4) - (x + 3) / (x ** 2 - 16),
(x + 1) / (2 * x - 2) - (x ** 2 + 3) / (2 * x ** 2 - 2),
(x + 8) / (x ** 2 + x - 2) - (x + 4) / (x ** 2 + 3 * x + 2),
(x + 1) / (x + 2) - (x - 2) / (x + 1) +
(x ** 2 - 4) / (x ** 2 + 3 * x + 2),
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 / (a - 1) + 1 / (a + 1) + 2 * a /
(a ** 2 + 1) + 4 * a ** 3 / (a ** 4 + 1),
x / (x ** 2 + 1) + x / (x ** 2 + 1) ** 2 +
1 / (x * (x ** 2 + 1) ** 2),
(x - 2) / (2 * x ** 2 - 5 * x + 3) + (3 * x - 1) /
(2 * x ** 2 + x - 6) + (2 *
x ** 2 - 5) / (x ** 2 + x - 2),
a / ((a - b) * (a - c)) + b / (b - c) / (b - a) + c / (c - a) / (c - b)]
egg = [0,
1 / (1 - x),
-7 / (x ** 2 - 16),
1 / (x + 1),
6 / (x ** 2 - 1),
(x + 1) / (x + 2),
(x ** 3 - 2 * x ** 2 + 2 * x - 4) / x / (x + 1),
(x ** 2 + x) / (x ** 3 + 1),
8 * a ** 7 / (a ** 8 - 1),
1 / x,
(4 * x ** 3 - 2 * x ** 2 - 14 * x + 12) / (2 * x - 3) / (x - 1) / (x + 2)]
for s, t in zip(spam, egg):
self.assertEqual((s - t).simplify(), 0)

if __name__ == '__main__':
main()


% ./sample13.py -v
13.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 1.029s

OK
%