## 2019年11月6日水曜日

### 数学 - Python - 代数学 - 整式の計算 - 整数の加法・減法・乗法 - 整数の乗法 - 2変数、同次数、差、展開

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

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

コード

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

print('9.')

class MyTest(TestCase):

def test(self):
a, b = symbols('a, b')
expr = (a - b) * sum([a ** k * b ** (5 - k) for k in range(6)])
self.assertEqual(expr.expand(), a ** 6 - b ** 6)

if __name__ == '__main__':
main()


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

----------------------------------------------------------------------
Ran 1 test in 0.007s

OK
%