## 2019年12月30日月曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 因数分解 - 雑例 - 3つの和、累乗(立方)

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

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

3. $\begin{array}{l}{x}^{3}+8{y}^{3}-64{z}^{3}+24xyz\\ ={x}^{3}+{\left(2y\right)}^{3}+{\left(-4z\right)}^{3}-3x\left(2y\right)\left(-4z\right)\\ =\left(x+2y-4z\right)\left({x}^{2}+4{y}^{2}+16{z}^{2}-2xy+8yz+4zx\right)\end{array}$

コード

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

print('8.')

class MyTest(TestCase):
def test1(self):
x, y, z = symbols('x, y, z', real=True)
spam = [x ** 3 + y ** 3 + 1 - 3 * x * y,
8 * x ** 3 + y ** 3 + z ** 3 - 6 * x * y * z,
x ** 3 + 8 * y ** 3 - 64 * z ** 3 + 24 * x * y * z]

egg = [(x + y + 1) * (x ** 2 + y ** 2 + 1 - x * y - y - x),
(2 * x + y + z) * (4 * x ** 2 + y ** 2 +
z ** 2 - 2 * x * y - y * z - 2 * z * x),
(x + 2 * y - 4 * z) * (x ** 2 + 4 * y ** 2 + 16 * z ** 2 - 2 * x * y + 8 * y * z + 4 * z * x)]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())
self.assertEqual(s.factor(), t)

if __name__ == '__main__':
main()


% ./sample8.py -v
8.
test1 (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.094s

OK
%