2018年12月7日金曜日

数学 - Python - 線形代数学 - R^n におけるベクトル – 複素数(n組の複素数の加法と乗法、内積、共役複素数)

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^n におけるベクトル)、6(複素数)、練習問題6.を取り組んでみる。

1. $\begin{array}{}\stackrel{-}{⟨B,A⟩}\\ =\stackrel{-}{{\beta }_{1}{\stackrel{-}{\alpha }}_{1}+\dots +{\beta }_{n}{\stackrel{-}{\alpha }}_{n}}\\ =\stackrel{-}{\stackrel{-}{{\alpha }_{1}}{\beta }_{1}+\dots +{\stackrel{-}{\alpha }}_{n}{\beta }_{n}}\\ =\stackrel{-}{\stackrel{-}{{\alpha }_{1}}{\beta }_{1}}+\dots +\stackrel{-}{\stackrel{-}{{\alpha }_{n}}{\beta }_{n}}\\ =\stackrel{-}{\stackrel{-}{{\alpha }_{1}}}\stackrel{-}{{\beta }_{1}}+...+\stackrel{-}{\stackrel{-}{{\alpha }_{n}}}\stackrel{-}{{\beta }_{n}}\\ ={\alpha }_{1}\stackrel{-}{{\beta }_{1}}+\dots +{\alpha }_{n}\stackrel{-}{{\beta }_{n}}\\ =⟨A,B⟩\end{array}$

2. $\begin{array}{}⟨A,B+C⟩\\ ={\alpha }_{1}\stackrel{-}{\left({\beta }_{1}+{\gamma }_{1}\right)}+\dots +{\alpha }_{n}\stackrel{-}{\left({\beta }_{n}+{\gamma }_{n}\right)}\\ ={\alpha }_{1}\left(\stackrel{-}{{\beta }_{1}}+{\stackrel{-}{\gamma }}_{1}\right)+\dots +{\alpha }_{n}\left({\stackrel{-}{\beta }}_{n}+{\stackrel{-}{\gamma }}_{n}\right)\\ ={\alpha }_{1}\stackrel{-}{{\beta }_{1}}+\dots +{\alpha }_{n}\stackrel{-}{{\beta }_{n}}+{\alpha }_{1}\stackrel{-}{{\gamma }_{1}}+\dots +{\alpha }_{n}{\stackrel{-}{\gamma }}_{n}\\ =⟨A,B⟩+⟨A,C⟩\end{array}$

3. $\begin{array}{}⟨\alpha A,B⟩\\ =\left(\alpha {\alpha }_{1}\right){\stackrel{-}{\beta }}_{1}+\dots +\left(\alpha {\alpha }_{n}\right){\stackrel{-}{\beta }}_{n}\\ =\alpha \left({\alpha }_{1}{\stackrel{-}{\beta }}_{1}+\dots +{\alpha }_{n}{\stackrel{-}{\beta }}_{n}\right)\\ =\alpha ⟨A,B⟩\\ ⟨A,\alpha B⟩\\ ={\alpha }_{1}\stackrel{-}{\left(\alpha {\beta }_{1}\right)}+\dots +{\alpha }_{n}\stackrel{-}{\left(\alpha {\beta }_{n}\right)}\\ ={\alpha }_{1}\stackrel{-}{\alpha }\stackrel{-}{{\beta }_{1}}+\dots +{\alpha }_{n}\stackrel{-}{\alpha }{\stackrel{-}{\beta }}_{n}\\ =\stackrel{-}{\alpha }\left({\alpha }_{1}\stackrel{-}{{\beta }_{1}}+\dots +{\alpha }_{n}\stackrel{-}{{\beta }_{n}}\right)\\ =\stackrel{-}{\alpha }⟨A,B⟩\end{array}$

4. $\begin{array}{}⟨A,A⟩\\ ={\alpha }_{1}\stackrel{-}{{\alpha }_{1}}+\dots +{\alpha }_{n}{\stackrel{-}{\alpha }}_{n}\\ ={\left|{\alpha }_{1}\right|}^{2}+\dots +{\left|{\alpha }_{n}\right|}^{2}\end{array}$

ここで A が O のとき、

$\begin{array}{}⟨A,A⟩\\ =0+\dots +0\\ =0\end{array}$

ここで A が O ではない場合、

$⟨A,A⟩>0$

（証明終）

コード(Emacs)

Python 3

#!/usr/bin/env python3
import random
from sympy import pprint, symbols, I, Matrix

print('6.')

def dot(a, b):
return sum([ai * bi.conjugate() for ai, bi in zip(a, b)])

n = 5
a = Matrix(symbols([f'a{i + 1}' for i in range(n)]))
b = Matrix(symbols([f'b{i + 1}' for i in range(n)]))
c = Matrix(symbols([f'c{i + 1}' for i in range(n)]))
o = Matrix([0 for _ in range(n)])
alpha = symbols('a')

lrs = [(dot(a, b), dot(b, a).conjugate()),
(dot(a, b + c), dot(a, b) + dot(a, c)),
(dot(alpha * a, b), alpha * dot(a, b)),
(dot(a, alpha * b), alpha.conjugate() * dot(a, b))]
for l, r in lrs:
for t in [l, r, l.expand() == r.expand()]:
pprint(t)
print()
print()

print(dot(o, o) == 0)

for _ in range(n):
a = Matrix([random.randrange(-5, 6) + random.randrange(-5, 6) * I
for _ in range(n)])
for t in [a, dot(a, a), dot(a, a).expand(), dot(a, a) > 0]:
pprint(t)
print()
print()


$./sample6.py 6. __ __ __ __ __ a₁⋅b₁ + a₂⋅b₂ + a₃⋅b₃ + a₄⋅b₄ + a₅⋅b₅ __ __ __ __ __ a₁⋅b₁ + a₂⋅b₂ + a₃⋅b₃ + a₄⋅b₄ + a₅⋅b₅ True ⎛__ __⎞ ⎛__ __⎞ ⎛__ __⎞ ⎛__ __⎞ ⎛__ __⎞ a₁⋅⎝b₁ + c₁⎠ + a₂⋅⎝b₂ + c₂⎠ + a₃⋅⎝b₃ + c₃⎠ + a₄⋅⎝b₄ + c₄⎠ + a₅⋅⎝b₅ + c₅⎠ __ __ __ __ __ __ __ __ __ __ a₁⋅b₁ + a₁⋅c₁ + a₂⋅b₂ + a₂⋅c₂ + a₃⋅b₃ + a₃⋅c₃ + a₄⋅b₄ + a₄⋅c₄ + a₅⋅b₅ + a₅⋅c₅ True __ __ __ __ __ a⋅a₁⋅b₁ + a⋅a₂⋅b₂ + a⋅a₃⋅b₃ + a⋅a₄⋅b₄ + a⋅a₅⋅b₅ ⎛ __ __ __ __ __⎞ a⋅⎝a₁⋅b₁ + a₂⋅b₂ + a₃⋅b₃ + a₄⋅b₄ + a₅⋅b₅⎠ True _ __ _ __ _ __ _ __ _ __ a₁⋅a⋅b₁ + a₂⋅a⋅b₂ + a₃⋅a⋅b₃ + a₄⋅a⋅b₄ + a₅⋅a⋅b₅ ⎛ __ __ __ __ __⎞ _ ⎝a₁⋅b₁ + a₂⋅b₂ + a₃⋅b₃ + a₄⋅b₄ + a₅⋅b₅⎠⋅a True True ⎡5 - 4⋅ⅈ⎤ ⎢ ⎥ ⎢ 3⋅ⅈ ⎥ ⎢ ⎥ ⎢1 - 5⋅ⅈ⎥ ⎢ ⎥ ⎢ 5 - ⅈ ⎥ ⎢ ⎥ ⎣ 0 ⎦ 9 + (1 - 5⋅ⅈ)⋅(1 + 5⋅ⅈ) + (5 - ⅈ)⋅(5 + ⅈ) + (5 - 4⋅ⅈ)⋅(5 + 4⋅ⅈ) 102 True ⎡-2 - 2⋅ⅈ⎤ ⎢ ⎥ ⎢-3 + 2⋅ⅈ⎥ ⎢ ⎥ ⎢ ⅈ ⎥ ⎢ ⎥ ⎢-5 + 4⋅ⅈ⎥ ⎢ ⎥ ⎣-5 + 4⋅ⅈ⎦ 1 + (-2 - 2⋅ⅈ)⋅(-2 + 2⋅ⅈ) + (-3 - 2⋅ⅈ)⋅(-3 + 2⋅ⅈ) + 2⋅(-5 - 4⋅ⅈ)⋅(-5 + 4⋅ⅈ) 104 True ⎡-5 + 4⋅ⅈ⎤ ⎢ ⎥ ⎢ 5⋅ⅈ ⎥ ⎢ ⎥ ⎢1 + 3⋅ⅈ ⎥ ⎢ ⎥ ⎢4 + 2⋅ⅈ ⎥ ⎢ ⎥ ⎣ 5⋅ⅈ ⎦ (1 - 3⋅ⅈ)⋅(1 + 3⋅ⅈ) + (4 - 2⋅ⅈ)⋅(4 + 2⋅ⅈ) + (-5 - 4⋅ⅈ)⋅(-5 + 4⋅ⅈ) + 50 121 True ⎡-3 - 4⋅ⅈ⎤ ⎢ ⎥ ⎢1 - 2⋅ⅈ ⎥ ⎢ ⎥ ⎢ 1 + ⅈ ⎥ ⎢ ⎥ ⎢-3 + 3⋅ⅈ⎥ ⎢ ⎥ ⎣2 + 3⋅ⅈ ⎦ (1 - ⅈ)⋅(1 + ⅈ) + (1 - 2⋅ⅈ)⋅(1 + 2⋅ⅈ) + (2 - 3⋅ⅈ)⋅(2 + 3⋅ⅈ) + (-3 - 3⋅ⅈ)⋅(-3 + 3⋅ⅈ) + (-3 - 4⋅ⅈ)⋅(-3 + 4⋅ⅈ) 63 True ⎡5 - 2⋅ⅈ ⎤ ⎢ ⎥ ⎢-2 - 3⋅ⅈ⎥ ⎢ ⎥ ⎢-1 + 3⋅ⅈ⎥ ⎢ ⎥ ⎢-4 + 4⋅ⅈ⎥ ⎢ ⎥ ⎣ 5 ⎦ (-1 - 3⋅ⅈ)⋅(-1 + 3⋅ⅈ) + (-2 - 3⋅ⅈ)⋅(-2 + 3⋅ⅈ) + 25 + (5 - 2⋅ⅈ)⋅(5 + 2⋅ⅈ) + (-4 - 4⋅ⅈ)⋅(-4 + 4⋅ⅈ) 109 True$