## 2020年1月1日水曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 整式の最大公約数と最小公倍数 - 数係数の省略

1. 最大公約数、最小公倍数はそれぞれ、

$\begin{array}{l}x{y}^{2}z\\ {x}^{3}{y}^{2}{z}^{3}\end{array}$

（数係数は省略。以下同様。）

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

3. $\begin{array}{l}{a}^{2}bc\\ {a}^{3}{b}^{3}{c}^{2}\end{array}$

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

5. $\begin{array}{l}\left(x+1\right)\left(x+2\right)\\ x\left(x+1\right)\left(x+2\right)\left(x+3\right)\end{array}$

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

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

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

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

10. $\begin{array}{l}{a}^{2}+2ab+{b}^{2}\\ ={\left(a+b\right)}^{2}\\ {a}^{2}-{b}^{2}\\ =\left(a-b\right)\left(a+b\right)\\ {a}^{3}+{b}^{3}\\ =\left(a+b\right)\left({a}^{2}-ab+{b}^{2}\right)\\ a+b\\ \left(a-b\right){\left(a+b\right)}^{2}\left({a}^{2}-ab+{b}^{2}\right)\end{array}$

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

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

コード

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

print('9.')

class MyTest(TestCase):
def test1(self):
x, y, z, a, b, c = symbols('x, y, z, a, b, c', real=True)
spam = [(x * y ** 2 * z ** 3, x ** 3 * y ** 2 * z),
(x ** 2 * y ** 3, x * y ** 2, x ** 4 * y),
(a ** 2 * b ** 3, a ** 3 * b * c ** 2, a ** 2 * b ** 2 * c),
(a ** 3 * (x - 1), a ** 2 * (x - 1) ** 3),
(x * (x + 1) * (x + 2), (x + 1) * (x + 2) * (x + 3)),
(x ** 3 * (x + 2) ** 2 * (x + 1), x ** 2 * (x + 3)
* (x + 2), x ** 2 * (x + 1) * (x + 3) ** 2),
(x ** 2 - 3 * x + 2, x ** 2 - 9 * x + 14),
(x ** 2 - 9, x ** 2 - 2 * x - 3, x ** 2 + 4 * x + 3),
(x ** 2 + x - 6, x ** 2 - 6 * x + 8, x ** 2 - x - 12),
(a ** 2 + 2 * a * b + b ** 2, a ** 2 - b ** 2, a ** 3 + b ** 3),
(x ** 2 + 5 * x + 6, x ** 2 + 6 * x + 9, x ** 3 + 8),
(x ** 2 + 2 * x - 3, x ** 3 + 3 * x ** 2 - x - 3, x ** 3 + 2 * x ** 2 - x - 2)]

gcds = [x * y ** 2 * z,
x * y,
a ** 2 * b,
a ** 2 * (x - 1),
(x + 1) * (x + 2),
x ** 2,
x - 2,
1,
1,
a + b,
1,
x - 1]

lcms = [x ** 3 * y ** 2 * z ** 3,
x ** 4 * y ** 3,
a ** 3 * b ** 3 * c ** 2,
a ** 3 * (x - 1) ** 3,
x * (x + 1) * (x + 2) * (x + 3),
x ** 3 * (x + 1) * (x + 2) ** 2 * (x + 3) ** 2,
(x - 1) * (x - 2) * (x - 7),
(x - 3) * (x + 1) * (x + 3),
(x - 4) * (x - 2) * (x + 3),
(a - b) * (a + b) ** 2 * (a ** 2 - a * b + b ** 2),
(x + 2) * (x + 3) ** 2 * (x ** 2 - 2 * x + 4),
(x - 1) * (x + 1) * (x + 2) * (x + 3)]
for s, g, l in zip(spam, gcds, lcms):
self.assertEqual(gcd(s).factor(), g)
self.assertEqual(lcm(s).factor(), l)

if __name__ == '__main__':
main()


% ./sample10.py -v
9.
test1 (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.204s

OK
%