## 2019年12月28日土曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 因数分解 - 雑例 - 平方の差

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

2. $\begin{array}{l}4{a}^{4}-36{a}^{2}{b}^{2}+25{b}^{4}\\ ={\left(2{a}^{2}-5{b}^{2}\right)}^{2}-16{a}^{2}{b}^{2}\\ =\left(2{a}^{2}-4ab-5{b}^{2}\right)\left(2{a}^{2}+4ab-5{b}^{2}\right)\end{array}$

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

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

コード

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

print('7.')

class MyTest(TestCase):
def test1(self):
x, y = symbols('x, y', real=True)
spam = [x ** 4 + 2 * x ** 2 + 9,
4 * x ** 4 - 36 * x ** 2 * y ** 2 + 25 * y ** 4,
4 * x ** 4 + 1,
x ** 8 + x ** 4 + 1]
egg = [(x ** 2 + 2 * x + 3) * (x ** 2 - 2 * x + 3),
(2 * x ** 2 - 4 * x * y - 5 * y ** 2) *
(2 * x ** 2 + 4 * x * y - 5 * y**2),
(2 * x ** 2 + 2 * x + 1) * (2 * x ** 2 - 2 * x + 1),
(x ** 2 + x + 1) * (x ** 2 - x + 1) * (x ** 4 - x ** 2 + 1)]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())
self.assertEqual(s.factor(), t)

if __name__ == '__main__':
main()


% ./sample7.py -v
7.
test1 (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.082s

OK
%