## 2019年12月31日火曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 因数分解 - 雑例 - 様々な工夫

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

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

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

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

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

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

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

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

コード

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

print('9.')

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

egg = [(a + b) * (a - b) * (a ** 2 + b ** 2 + c ** 2),
(x - y) * (x ** 2 + x * y + y ** 2 - x + y),
(a + b) ** 3 * (a - b),
(x + y) * (3 * x ** 2 - 2 * x * y + 2 * y ** 2),
(a + b) * (a ** 2 - a * b + 4 * b ** 2),
3 * (a + b) * (b + c) * (c + a),
(x + 3) * (x - 2) * (x ** 2 + x + 5),
(2 * x ** 2 - 3 * x - 1) * (2 * x - 5) * (x + 1)]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())
self.assertEqual(s.factor(), t.factor())

if __name__ == '__main__':
main()


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

----------------------------------------------------------------------
Ran 1 test in 0.194s

OK
%