## 2020年4月7日火曜日

### 数学 - Python - 新しい数とその表示ー複素数と複素平面 - 複素平面 - ド・モアブルの公式と複素数のn乗根 - 1の虚数の立方根、累乗、自然数

1. n が3の倍数のとき。

$n=3k$

とおく。

$\begin{array}{l}{\omega }^{2n}+{\omega }^{n}+1\\ ={\left({\omega }^{3}\right)}^{2k}+{\left({\omega }^{3}\right)}^{k}+1\\ =1+1+1\\ =3\end{array}$

n が3の 倍数ではないとき。

$\begin{array}{l}{\omega }^{n}\ne 1\\ {\omega }^{2n}+{\omega }^{n}+1\\ ={\left({\omega }^{n}\right)}^{2}+{\omega }^{n}+1\\ =\frac{\left({\omega }^{n}-1\right)\left({\left({\omega }^{n}\right)}^{2}+{\omega }^{n}+1\right)}{{\omega }^{n}-1}\\ =\frac{{\left({\omega }^{n}\right)}^{3}-1}{{\omega }^{n}-1}\\ =\frac{{\left({\omega }^{3}\right)}^{n}-1}{{\omega }^{n}-1}\\ =\frac{1-1}{{\omega }^{n}-1}\\ =0\end{array}$

コード

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

print('13.')

w = symbols('w', imag=False)
ws = [z for z in solve(w ** 3 - 1) if z != 1]
n, k = symbols('n, k', integer=True)
fs = [(w ** (2 * n) + w ** n + 1).subs({w: w0}) for w0 in ws]

class MyTestCubic(TestCase):
def test_0(self):
for f in fs:
self.assertEqual(f.subs({n: 3 * k}).simplify(), 3)

def test_1(self):
for f in fs:
a, b = f.subs({n: 3 * k + 1}).as_real_imag()
self.assertEqual(a.simplify(), 0)
self.assertEqual(b.simplify(), 0)

def test_2(self):
for f in fs:
a, b = f.subs({n: 3 * k + 2}).as_real_imag()
self.assertEqual(a.simplify(), 0)
self.assertEqual(b.simplify(), 0)

if __name__ == "__main__":
main()


% ./sample13.py -v
13.
test_0 (__main__.MyTestCubic) ... ok
test_1 (__main__.MyTestCubic) ... ok
test_2 (__main__.MyTestCubic) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.720s

OK
%