## 2017年12月18日月曜日

### 数学 - Python - 解析学 - 連続写像の空間 - ノルム空間(定義、n次元実数空間、色々なノルム)

1. ${\left|x\right|}_{1}=\sum _{i=1}^{n}\left|{x}_{i}\right|\ge 0$

2. ${\left|x\right|}_{1}=\sum _{i=1}^{n}\left|{x}_{i}\right|=0⇒\left|{x}_{1}\right|=\dots =\left|{x}_{n}\right|=0$

よって、

${x}_{1}=\dots ={x}_{n}=0$

となるので、

$x=0$

3. ${\left|cx\right|}_{1}=\sum _{i=1}^{n}\left|c{x}_{i}\right|=\left|c\right|\sum _{i=1}^{n}\left|{x}_{i}\right|=\left|c\right|{\left|x\right|}_{1}$

4. $\begin{array}{}{\left|x+y\right|}_{1}\\ =\sum _{i=1}^{n}\left|{x}_{i}+{y}_{i}\right|\\ \le \sum _{i=1}^{n}\left(\left|{x}_{i}\right|+\left|{y}_{i}\right|\right)\\ =\sum _{i=1}^{n}\left|{x}_{i}\right|+\sum _{i=1}^{n}\left|{y}_{i}\right|\\ ={\left|x\right|}_{1}+{\left|y\right|}_{1}\end{array}$

1. ${\left|x\right|}_{\infty }=\mathrm{max}\left\{\left|{x}_{1}\right|,\dots ,\left|{x}_{n}\right|\right\}\ge 0$

2. ${\left|x\right|}_{\infty }=\mathrm{max}\left\{\left|{x}_{1}\right|,\dots ,\left|{x}_{n}\right|\right\}=0⇒\left|{x}_{1}\right|=\dots =\left|{x}_{n}\right|=0$

よって、

${x}_{1}=\dots ={x}_{n}=0$

となるので、

$x=0$

3. $\begin{array}{}{\left|cx\right|}_{\infty }=\mathrm{max}\left\{\left|c{x}_{1}\right|,\dots ,\left|c{x}_{n}\right|\right\}\\ =\mathrm{max}\left\{\left|c\right|\left|{x}_{1}\right|,\dots ,\left|c\right|\left|{x}_{n}\right|\right\}\\ =\left|c\right|\mathrm{max}\left\{\left|{x}_{1}\right|,\dots ,\left|{x}_{n}\right|\right\}\\ =\left|c\right|{\left|x\right|}_{\infty }\end{array}$

4. $\begin{array}{}{\left|x+y\right|}_{\infty }\\ =\mathrm{max}\left\{\left|{x}_{1}+{y}_{1}\right|,\dots ,\left|{x}_{n}+{y}_{n}\right|\right\}\\ \le \mathrm{max}\left\{\left|{x}_{1}\right|+\left|{y}_{1}\right|,\dots ,\left|{x}_{n}\right|+\left|{y}_{n}\right|\right\}\\ \le \mathrm{max}\left\{\left|{x}_{1}\right|,\dots ,\left|{x}_{n}\right|\right\}+\mathrm{max}\left\{\left|{y}_{1}\right|,\dots ,|{y}_{n}\right\}\right\}\\ ={\left|x\right|}_{\infty }+{\left|y\right|}_{\infty }\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, solve
import random
x1, y1, x2, y2, x3, y3 = symbols('x1, y1, x2, y2, x3. y3', real=True)
v1 = Matrix([x1, y1])
v2 = Matrix([x2, y2])
vs = [v1, v2]

def norm1(v):
return sum([abs(x) for x in v])

def norm2(v):
return max([abs(x) for x in v])

norms = [norm1, norm2]

print('N1')
for norm in norms:
try:
print(all([norm(v) >= 0 for v in vs]))
except Exception as err:
print(type(err), err)

for norm in norms:
for _ in range(5):
x_sign = -1 if random.randrange(2) == 0 else 1
y_sign = -1 if random.randrange(2) == 0 else 1
v = Matrix([x_sign * random.random() * 10,
y_sign * random.random() * 10])
pprint(v)
pprint(norm(v) >= 0)
print()

print('N2')
for norm in norms:
try:
pprint(solve(norm(v1), (x1, y1)))
except Exception as err:
print(type(err), err)
print()
for v in [(1, 2), (0, 0)]:
pprint(v)
pprint(norm(v))
print()

print('N3')
c = symbols('c', real=True)
for norm in norms:
try:
l = norm(c * v1)
r = abs(c) * norm(v1)
for t in [l, r, l == r, l.expand() == r.expand(), l.factor() == r.factor()]:
pprint(t)
print()
except Exception as err:
print(type(err), err)
print()
for _ in range(5):
try:
x_sign = -1 if random.randrange(2) == 0 else 1
y_sign = -1 if random.randrange(2) == 0 else 1
v = Matrix([x_sign * random.random() * 10,
y_sign * random.random() * 10])
l = norm(c * v)
r = abs(c) * norm(v)
for t in [l == r, l.expand() == r.expand(), l.factor() == r.factor()]:
pprint(t)
print()
except Exception as err:
print(type(err), err)
print()

print('N4')
for nrom in norms:
try:
l = norm(v1 + v2)
r = norm(v1) + norm(v2)
for t in [l, r, l <= r]:
pprint(t)
print()
except Exception as err:
print(type(err), err)
print()
for _ in range(5):
try:
x_sign1 = -1 if random.randrange(2) == 0 else 1
y_sign1 = -1 if random.randrange(2) == 0 else 1
v1 = Matrix([x_sign1 * random.random() * 10,
y_sign1 * random.random() * 10])
x_sign2 = -1 if random.randrange(2) == 0 else 1
y_sign2 = -1 if random.randrange(2) == 0 else 1
v2 = Matrix([x_sign2 * random.random() * 10,
y_sign2 * random.random() * 10])
l = norm(v1 + v2)
r = norm(v1) + norm(v2)
for t in [l, r, l <= r]:
pprint(t)
print()
except Exception as err:
print(type(err), err)
print()


$./sample1.py N1 True <class 'TypeError'> cannot determine truth value of Relational ⎡-3.60926710185543⎤ ⎢ ⎥ ⎣ 6.9103922185622 ⎦ True ⎡9.57041752277116 ⎤ ⎢ ⎥ ⎣-3.93028851221304⎦ True ⎡ -7.3944192349977 ⎤ ⎢ ⎥ ⎣-0.519473049306546⎦ True ⎡2.38880070572094 ⎤ ⎢ ⎥ ⎣-2.03845287170201⎦ True ⎡3.18762488061502⎤ ⎢ ⎥ ⎣-7.1638944314745⎦ True ⎡-6.41195251111337⎤ ⎢ ⎥ ⎣6.05993189592312 ⎦ True ⎡-4.81710291929288⎤ ⎢ ⎥ ⎣-5.7781933238635 ⎦ True ⎡ 5.44499970421381 ⎤ ⎢ ⎥ ⎣-0.417472228032932⎦ True ⎡8.07251073111729⎤ ⎢ ⎥ ⎣1.75368978188321⎦ True ⎡3.44930546015265⎤ ⎢ ⎥ ⎣7.61472240043842⎦ True N2 [] (1, 2) 3 (0, 0) 0 <class 'TypeError'> cannot determine truth value of Relational (1, 2) 2 (0, 0) 0 N3 │c⋅x₁│ + │c⋅y₁│ (│x₁│ + │y₁│)⋅│c│ False False False True True True True True True True True True True True True True True True <class 'TypeError'> cannot determine truth value of Relational <class 'TypeError'> cannot determine truth value of Relational <class 'TypeError'> cannot determine truth value of Relational True True True True True True <class 'TypeError'> cannot determine truth value of Relational N4 <class 'TypeError'> cannot determine truth value of Relational 14.9446119735654 14.9446119735654 True 17.6787683440230 17.6787683440230 True 12.2781313630320 14.4589230209315 True 14.7469415782085 16.8060896219550 True 6.56786992942470 7.58325266844975 True 6.56786992942470 7.58325266844975 True 7.82660756381296 18.2036912534447 True 7.41865867526981 18.1336184290229 True 9.15529273451527 11.6690643681854 True 5.96971885258877 11.1937075726179 True 18.5451943221697 18.5451943221697 True$