## 2019年12月10日火曜日

### 数学 - Python - 代数学 - 整式の計算 - 式の展開、和と積、置き換え

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

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

コード

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

print('5.')

x, y = symbols('x, y')
a = x + y
b = x * y

class MyTest(TestCase):
def test1(self):
self.assertEqual(((x - y) ** 2).expand(), (a ** 2 - 4 * b).expand())

def test2(self):
self.assertEqual(x ** 4 + y ** 4, (a ** 4 - 4 *
a ** 2 * b + 2 * b ** 2).expand())

if __name__ == '__main__':
main()


% ./sample5.py -v
5.
test1 (__main__.MyTest) ... ok
test2 (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.014s

OK
%