## 2020年1月3日金曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 分数式とその計算 - 通分、最小公倍数、分母

1. $\begin{array}{l}\frac{{z}^{2}}{xyz}\\ \frac{{x}^{2}}{xyz}\\ \frac{{y}^{2}}{xyz}\end{array}$

2. $\begin{array}{l}\frac{a{x}^{2}{z}^{3}}{{x}^{3}{y}^{2}{z}^{3}}\\ \frac{2{b}^{2}{x}^{3}}{{x}^{3}{y}^{2}{z}^{3}}\\ \frac{3c{y}^{2}{z}^{2}}{{x}^{3}{y}^{2}{z}^{3}}\end{array}$

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

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

コード

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

print('12.')

class MyTest(TestCase):
def test(self):
x, y, z, a, b, c = symbols('x, y, z, a, b, c')
spam = [z / (x * y), x / (y * z), y / (z * x),
a / (x * y ** 2), 2 * b ** 2 /
(y ** 2 * z ** 3), 3 * c / (z * x ** 3),
2 / (a - 1), 4 / (a - 1) ** 2, 8 / (a - 1) ** 3,
(x ** 2 + x + 1) / (x + 1), (x ** 2 - x + 1) / (x - 1)]
egg = [z ** 2 / (x * y * z), x ** 2 / (x * y * z), y ** 2 / (x * y * z),
a * x ** 2 * z ** 3 / (x ** 3 * y ** 2 * z ** 3), 2 * b ** 2 * x ** 3 / (
x ** 3 * y ** 2 * z ** 3), 3 * c * y ** 2 * z ** 2 / (x ** 3 * y ** 2 * z ** 3),
2 * (a - 1) ** 2 / (a - 1) ** 3, 4 *
(a - 1) / (a - 1) ** 3, 8 / (a - 1) ** 3,
(x ** 3 - 1) / (x ** 2 - 1), (x ** 3 + 1) / (x ** 2 - 1)]
for s, t in zip(spam, egg):
self.assertEqual((s - t).simplify(), 0)

if __name__ == '__main__':
main()


% ./sample12.py -v
12.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.438s

OK
%