## 2020年1月2日木曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 分数式とその計算 - 約分、既約分数式

1. $\frac{4ab}{16{a}^{2}{b}^{3}}=\frac{1}{4a{b}^{2}}$

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

3. $\begin{array}{l}\frac{4{a}^{3}+8a{b}^{2}}{5{a}^{2}}\\ =\frac{4{a}^{2}+8{b}^{2}}{5a}\end{array}$

4. $\begin{array}{l}\frac{{x}^{3}-xy}{{x}^{2}+xy}\\ =\frac{{x}^{2}-y}{x+y}\end{array}$

5. $\begin{array}{l}\frac{{a}^{2}+7a+10}{{a}^{2}+9a+20}\\ =\frac{\left(a+2\right)\left(a+5\right)}{\left(a+4\right)\left(a+5\right)}\\ =\frac{a+2}{a+4}\end{array}$

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

7. $\begin{array}{l}\frac{{x}^{2}-5xy+6{y}^{2}}{{x}^{2}-7xy+12{y}^{2}}\\ =\frac{\left(x-2y\right)\left(x-3y\right)}{\left(x-3y\right)\left(x-4y\right)}\\ =\frac{x-2y}{x-4y}\end{array}$

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

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

コード

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

print('11.')

class MyTest(TestCase):
def test(self):
x, y, a, b = symbols('x, y, a, b')
spam = [4 * a * b / (16 * a ** 2 * b ** 3),
(x - y) ** 2 / (x ** 2 - y ** 2),
(4 * a ** 3 + 8 * a * b ** 2) / (5 * a ** 2),
(x ** 3 - x * y) / (x ** 2 + x * y),
(a ** 2 + 7 * a + 10) / (a ** 2 + 9 * a + 20),
(x ** 2 - 8 * x + 7) / (x ** 2 - 3 * x - 28),
(x ** 2 - 5 * x * y + 6 * y ** 2) /
(x ** 2 - 7 * x * y + 12 * y ** 2),
(2 * x ** 2 + x - 1) / (x ** 3 + 1),
(a ** 3 - 4 * a) / (a ** 3 + 2 * a ** 2 - 4 * a - 8)]
egg = [1 / (4 * a * b ** 2),
(x - y) / (x + y),
(4 * a ** 2 + 8 * b ** 2) / (5 * a),
(x ** 2 - y) / (x + y),
(a + 2) / (a + 4),
(x - 1) / (x + 4),
(x - 2 * y) / (x - 4 * y),
(2 * x - 1) / (x ** 2 - x + 1),
a / (a + 2)]
for s, t in zip(spam, egg):
self.assertEqual(s.simplify(), t.simplify())

if __name__ == '__main__':
main()


% ./sample11.py -v
11.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.723s

OK
%