Skip to content

Commit 975795d

Browse files
committed
init
0 parents  commit 975795d

File tree

17 files changed

+3292
-0
lines changed

17 files changed

+3292
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
notebook/npmath/__pycache__
2+
*.*~
3+
notebook/.ipynb_checkpoints

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Pythonコードを交えて学ぶ関数解析
2+
3+
こちらは、Pythonコードを交えて学ぶ関数解析
4+
5+
* Booth: https://noppoman.booth.pm/items/2698852
6+
7+
のサポートページになります。
8+
9+
## ソースコードについて
10+
11+
[notebook](https://github.com/noppoMan/learning-functional-analysis-with-python/tree/master/notebook)以下に、各章に対応するソースコードがあります。
12+
13+
## 誤植や理論の訂正について
14+
15+
誤植や理論の訂正に関しては、各書籍リビジョンに対応する[正誤表](https://github.com/noppoMan/learning-functional-analysis-with-python/tree/master/typographical-error)をご確認ください。書籍リビジョンは巻末に記載があります。リビジョンが更新された場合は、過去のリビジョンに関する修正は行われず、最新のものに対してのみ修正が加わります。

notebook/L2Space.png

76.4 KB
Loading

notebook/MetricVectorSpace.png

19.7 KB
Loading

notebook/RealVector.png

25.7 KB
Loading

notebook/chapter1.ipynb

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%load_ext autoreload\n",
10+
"%autoreload 2"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"import sys\n",
20+
"import os\n",
21+
"import numpy as np\n",
22+
"import sympy as sym\n",
23+
"from IPython.display import display, Math, Image"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 3,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"A: [0, 1, 2, 3, 4]\n",
36+
"B: [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]\n"
37+
]
38+
}
39+
],
40+
"source": [
41+
"A = [0, 1, 2, 3, 4]\n",
42+
"B = np.arange(0, 1, 0.1)\n",
43+
"\n",
44+
"print(\"A:\", A)\n",
45+
"print(\"B:\", B)"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"# 実数"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 4,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stdout",
62+
"output_type": "stream",
63+
"text": [
64+
"R(1.0) R(2.0)\n",
65+
"<class 'npmath.space.MathSet'>\n",
66+
"R(1.1) R(1.4)\n"
67+
]
68+
}
69+
],
70+
"source": [
71+
"from npmath.space import R, MathSet, IncompatibleElementTypeError, NotInError\n",
72+
"\n",
73+
"RSet = MathSet(lambda x: R(x))\n",
74+
"\n",
75+
"# 𝑎, b ∈ R\n",
76+
"a, b = RSet.take(1., 2.)\n",
77+
"print(a, b)\n",
78+
"\n",
79+
"# 𝐴 ⊂ R\n",
80+
"A = RSet.subset([1.1, 1.2, 1.3, 1.4, 1.5])\n",
81+
"print(type(A))\n",
82+
"a, b = A.take(1.1, 1.4)\n",
83+
"print(a, b)"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 5,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"10 is not in the Set\n"
96+
]
97+
}
98+
],
99+
"source": [
100+
"try:\n",
101+
" A.take(10)\n",
102+
"except NotInError as e:\n",
103+
" print(e)"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 6,
109+
"metadata": {},
110+
"outputs": [
111+
{
112+
"name": "stdout",
113+
"output_type": "stream",
114+
"text": [
115+
"R(3.0)\n",
116+
"R(-1.0)\n",
117+
"R(2.0)\n",
118+
"R(0.5)\n",
119+
"False\n",
120+
"True\n"
121+
]
122+
}
123+
],
124+
"source": [
125+
"a, b = RSet.take(1., 2.)\n",
126+
"print(a + b)\n",
127+
"print(a - b)\n",
128+
"print(a * b)\n",
129+
"print(a / b)\n",
130+
"\n",
131+
"print(a == b)\n",
132+
"print(a < b)"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": 7,
138+
"metadata": {},
139+
"outputs": [
140+
{
141+
"name": "stdout",
142+
"output_type": "stream",
143+
"text": [
144+
"element type should be a float or int. not <str>\n",
145+
"element type should be a float or int. not <function>\n"
146+
]
147+
}
148+
],
149+
"source": [
150+
"try:\n",
151+
" RSet.take(\"hello world\")\n",
152+
"except IncompatibleElementTypeError as e:\n",
153+
" print(e)\n",
154+
" \n",
155+
"try:\n",
156+
" RSet.subset([1, 2, 3, lambda: 1 + 2])\n",
157+
"except IncompatibleElementTypeError as e:\n",
158+
" print(e) "
159+
]
160+
},
161+
{
162+
"cell_type": "markdown",
163+
"metadata": {},
164+
"source": [
165+
"# 自然数"
166+
]
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": 8,
171+
"metadata": {},
172+
"outputs": [
173+
{
174+
"name": "stdout",
175+
"output_type": "stream",
176+
"text": [
177+
"N(1) N(2)\n",
178+
"N(3)\n",
179+
"N(2)\n",
180+
"element type should be a natural number. not <int>\n"
181+
]
182+
}
183+
],
184+
"source": [
185+
"from npmath.space import AnyElement, MathSet, IncompatibleElementTypeError, NotInError\n",
186+
"\n",
187+
"class N(AnyElement):\n",
188+
" def validate(self):\n",
189+
" error = IncompatibleElementTypeError(f\"element type should be a natural number. not <{type(self.value).__name__}>\")\n",
190+
" if type(self.value) is not int:\n",
191+
" raise error\n",
192+
" \n",
193+
" if self.value < 0:\n",
194+
" raise error\n",
195+
" \n",
196+
" def __add__(self, other):\n",
197+
" return self._operate(other, \"__add__\")\n",
198+
" \n",
199+
" def __mul__(self, other):\n",
200+
" return self._operate(other, \"__mul__\")\n",
201+
" \n",
202+
"NSet = MathSet(N)\n",
203+
"a, b = NSet.take(1, 2)\n",
204+
"print(a, b)\n",
205+
" \n",
206+
"print(a + b)\n",
207+
"print(a * b)\n",
208+
"\n",
209+
"try:\n",
210+
" NSet.take(-1)\n",
211+
"except IncompatibleElementTypeError as e:\n",
212+
" print(e)"
213+
]
214+
}
215+
],
216+
"metadata": {
217+
"hide_code_all_hidden": false,
218+
"kernelspec": {
219+
"display_name": "Python 3",
220+
"language": "python",
221+
"name": "python3"
222+
},
223+
"language_info": {
224+
"codemirror_mode": {
225+
"name": "ipython",
226+
"version": 3
227+
},
228+
"file_extension": ".py",
229+
"mimetype": "text/x-python",
230+
"name": "python",
231+
"nbconvert_exporter": "python",
232+
"pygments_lexer": "ipython3",
233+
"version": "3.8.0"
234+
},
235+
"toc": {
236+
"base_numbering": 1,
237+
"nav_menu": {},
238+
"number_sections": false,
239+
"sideBar": true,
240+
"skip_h1_title": false,
241+
"title_cell": "Table of Contents",
242+
"title_sidebar": "Contents",
243+
"toc_cell": false,
244+
"toc_position": {},
245+
"toc_section_display": true,
246+
"toc_window_display": false
247+
}
248+
},
249+
"nbformat": 4,
250+
"nbformat_minor": 4
251+
}

0 commit comments

Comments
 (0)