2017年12月6日水曜日

数学 - Python - もう１つの数学の基盤 - 行列と行列式 – 行列式 - 2次の行列式の諸性質(列の入れ替えと符号、列の定数倍を加える、成分を用いた証明)

1. $\begin{array}{}\mathrm{det}\left(\stackrel{\to }{b},\stackrel{\to }{a}\right)\\ =|\begin{array}{cc}{b}_{1}& {a}_{1}\\ {b}_{2}& {a}_{2}\end{array}|\end{array}={b}_{1}{a}_{2}-{a}_{1}{b}_{2}\\ =-\left({a}_{1}{b}_{2}-{b}_{1}{a}_{2}\right)\\ =-|\begin{array}{cc}{a}_{1}& {b}_{1}\\ {a}_{2}& {b}_{2}\end{array}|\\ =-\mathrm{det}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)$

2. $\begin{array}{}\mathrm{det}\left(\stackrel{\to }{a}+k\stackrel{\to }{b},\stackrel{\to }{b}\right)\\ =|\begin{array}{cc}{a}_{1}+k{b}_{1}& {b}_{1}\\ {a}_{2}+k{b}_{2}& {b}_{2}\end{array}|\end{array}=\left({a}_{1}+k{b}_{1}\right){b}_{2}-{b}_{1}\left({a}_{2}+k{b}_{2}\right)\\ ={a}_{1}{b}_{2}+k{b}_{1}{b}_{2}-{b}_{1}{a}_{2}-k{b}_{1}{b}_{2}\\ ={a}_{1}{b}_{2}-{b}_{1}{a}_{2}\\ =|\begin{array}{cc}{a}_{1}& {b}_{1}\\ {a}_{2}& {b}_{2}\end{array}|\\ =\mathrm{det}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)$
$\begin{array}{}\mathrm{det}\left(\stackrel{\to }{a},\stackrel{\to }{b}+k\stackrel{\to }{a}\right)\\ =|\begin{array}{cc}{a}_{1}& {b}_{1}+ka,\\ {a}_{2}& {b}_{2}+k{a}_{2}\end{array}|\end{array}={a}_{1}\left({b}_{2}+k{a}_{2}\right)-\left({b}_{1}+k{a}_{1}\right){a}_{2}\\ ={a}_{1}{b}_{2}+k{a}_{1}{a}_{2}-{b}_{1}{a}_{2}-k{a}_{1}{a}_{2}\\ ={a}_{1}{b}_{2}-{b}_{1}{a}_{2}\\ =|\begin{array}{cc}{a}_{1}& {b}_{1}\\ {a}_{2}& {b}_{2}\end{array}|\\ =\mathrm{det}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)$

コード(Emacs)

Python 3

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

print('D4')
a1, a2, b1, b2, k = symbols('a1, a2, b1, b2, k')

X = Matrix([[a1, b1],
[a2, b2]])
Y = Matrix([[b1, a1],
[b2, a2]])

for t in [X, Y, Y.det(), Y.det() == -X.det()]:
pprint(t)
print()

print('D5')
X = Matrix([[a1 + k * b1, b1],
[a2 + k * b2, b2]])
Y = Matrix([[a1, b1],
[a2, b2]])

for t in [X, Y, X.det(), X.det().factor() == Y.det().factor()]:
pprint(t)
print()

X = Matrix([[a1, b1 + k * a1],
[a2, b2 + k * a2]])
Y = Matrix([[a1, b1],
[a2, b2]])

for t in [X, Y, X.det(), X.det().factor() == Y.det().factor()]:
pprint(t)
print()


$./sample0.py D4 ⎡a₁ b₁⎤ ⎢ ⎥ ⎣a₂ b₂⎦ ⎡b₁ a₁⎤ ⎢ ⎥ ⎣b₂ a₂⎦ -a₁⋅b₂ + a₂⋅b₁ True D5 ⎡a₁ + b₁⋅k b₁⎤ ⎢ ⎥ ⎣a₂ + b₂⋅k b₂⎦ ⎡a₁ b₁⎤ ⎢ ⎥ ⎣a₂ b₂⎦ -b₁⋅(a₂ + b₂⋅k) + b₂⋅(a₁ + b₁⋅k) True ⎡a₁ a₁⋅k + b₁⎤ ⎢ ⎥ ⎣a₂ a₂⋅k + b₂⎦ ⎡a₁ b₁⎤ ⎢ ⎥ ⎣a₂ b₂⎦ a₁⋅(a₂⋅k + b₂) - a₂⋅(a₁⋅k + b₁) True$