Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Created June 1, 2022 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terasakisatoshi/eee87b2b13e471d32fb277de412c8df0 to your computer and use it in GitHub Desktop.
Save terasakisatoshi/eee87b2b13e471d32fb277de412c8df0 to your computer and use it in GitHub Desktop.
Lz のお話
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "320d1de7",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:32.141000+09:00",
"start_time": "2022-06-01T00:12:31.155Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"v\"1.7.2\""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"VERSION"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a70aac33",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:34.422000+09:00",
"start_time": "2022-06-01T00:12:31.156Z"
}
},
"outputs": [],
"source": [
"using SymPy"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5ac4eb6c",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:34.923000+09:00",
"start_time": "2022-06-01T00:12:31.157Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(x, y, px, py, θ)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@vars x y px py θ"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2b6466fc",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:35.205000+09:00",
"start_time": "2022-06-01T00:12:31.157Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(x, y, px, py)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = (x,y,px,py)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "58b94906",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:35.454000+09:00",
"start_time": "2022-06-01T00:12:31.158Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Lz (generic function with 2 methods)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Lz(x,y,px,py) = x * py - y * px\n",
"Lz(t::Tuple) = Lz(t...)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "25a05ce1",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:35.533000+09:00",
"start_time": "2022-06-01T00:12:31.159Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"tfm1 (generic function with 2 methods)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tfm1(x,y,px,py) = px,py,-x,-y\n",
"tfm1(t::Tuple) = tfm1(t...)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a980c973",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:36.543000+09:00",
"start_time": "2022-06-01T00:12:31.160Z"
}
},
"outputs": [],
"source": [
"@assert (Lz∘tfm1)(t) == Lz(t)\n",
"@assert iszero((Lz∘tfm1)(t) - Lz(t)) # 差がゼロであることでも確認できる."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "68703cc1",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:36.644000+09:00",
"start_time": "2022-06-01T00:12:31.161Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"tfm2 (generic function with 2 methods)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c = cos(θ)\n",
"s = sin(θ)\n",
"\n",
"tfm2(x,y,px,py) = x*c+px*s,y*c+py*s,px*c-x*s,py*c-y*s\n",
"tfm2(t::NTuple) = tfm2(t...)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "dab7a545",
"metadata": {
"ExecuteTime": {
"end_time": "2022-06-01T09:12:36.985000+09:00",
"start_time": "2022-06-01T00:12:31.162Z"
}
},
"outputs": [],
"source": [
"ex = (Lz∘tfm2)(t) - Lz(t)\n",
"# sin^2 + cos^2 = 1 のルールで簡約化しないとゼロまで持っていけない.\n",
"@assert ex |> expand |> simplify |> iszero"
]
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia-sys 1.7.2",
"language": "julia",
"name": "julia-sys-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.2"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment