このワークシートはSageMathにおける微分可能多様体の取り扱いについての簡単な紹介です。以下で紹介するツールはSageManifolds プロジェクト (version 1.2, included in SageMath 8.2).を通じて実装されました。
ipnyb形式のワークシートファイルはここ からダウンロード可能です。このワークシートを実行するには、コマンドsage -n jupyter
などを使ってSageMathのJupyterノートブックインタフェースを起動する必要があります。
[訳注:この日本語版翻訳は山本 昇によって作成されました。翻訳者へのご連絡は、https://souran.kek.jp/kss/top/ を経由して、 職員情報詳細ページ内の「メール送信」リンクをご利用ください。この翻訳版作成にあたり、東海大学理学部北林さんには貴重なコメントをいただきました。この場を借りてお礼申しあげます。 (2023/05/02追記:原文の更新を反映しました。)]
This notebook provides a short introduction to differentiable manifolds in SageMath. The tools described below have been implemented through the SageManifolds project.
Click here to download the worksheet file (ipynb format). To run it, you must start SageMath with the Jupyter notebook, via the command sage -n jupyter
[Note for Japanese version.: this document was translated into Japanese by Noboru Yamamoto. You can reach him through https://souran.kek.jp/kss/top/. "Staff Detail Information" page includes a link "send email". The translator thanks Prof. Kitabayashi of Tokai University for his valuable comments on the draft of the documents.]
このワークシートはSageMathのバージョン 9.2 (あるいはそれ以降)を必要としています、それ以前のバージョンではSageManifoldsの全ての機能が利用可能というわけではないからです。 [訳注:このjupyter notebookはSageMath 9.8 を使って実行しています。]
This notebook is valid for version 9.2 or higher of SageMath:
version()
'SageMath version 9.8, Release Date: 2023-02-11'
最初に、ノートブックが結果をLaTexを使った数式表示で表示するようにします。
First we set up the notebook to display mathematical objects using LaTeX rendering:
%display latex
例として、 $\mathbb{R}$上の3次元の微分可能多様体を定義します。
As an example let us define a differentiable manifold of dimension 3 over $\mathbb{R}$:
M = Manifold(3, 'M', latex_name=r'\mathcal{M}', start_index=1)
3
, は多様体の次元です。SageManifoldsでは任意の正の整数を指定できます。'M'
, は多様体の名前を与える文字列です。この名前は = 記号の左辺にあるシンボルの名前(ここではM
)と異なっていても構いません。左辺のシンボル名はコンピュータメモリのなかの多様体オブジェクトを参照しています。一方、 引数であたえる名前は、多様体に与えられた数学的な名前です。
latex_name=r'\mathcal{M}'
, はこの多様体をLaTeXで表示する際に使う名前を指定します。最初の引用符の前の 'r' に注意してください。:これはこの文字列が raw 文字列であることを示しています。
それによって文字列\mathcal
中のバックスラッシュ '\' は通常の文字として取り扱われます( '\\' としてエスケープする必要がないということです)。
この引数(latex_name
)が省略された場合は、第2引数に与えられた名前(ここではM
です)が使われます。
次の省略可能な引数start_index=1
は多様体のテンソル成分の指標の範囲を指定しています。これを1とすることは指標の範囲が$\{1,2,3\}$であることを示しています。この引数の既定値は start_index=0
です。
The first argument, 3
, is the manifold dimension. In SageManifolds, it can be any
positive integer.
The second argument, 'M'
, is a string defining the manifold's name; it may be
different from the symbol set on the left-hand side of the = sign (here M
): the latter
stands for a mere Python variable, which refers to the manifold object in the computer
memory, while the string 'M'
is the mathematical symbol chosen for the manifold.
The optional argument latex_name=r'\mathcal{M}'
sets the LaTeX
symbol to display the manifold. Note the letter 'r' in front on the first quote:
it indicates that the string is a raw one, so that the backslash character
in \mathcal
is considered as an ordinary character (otherwise, the backslash is
used to escape some special characters). If the argument latex_name
is not
provided by the user, it is set to the string used as the second argument (here 'M'
)
The optional argument start_index=1
defines the range of indices to be used for
tensor components on the manifold: setting it to 1 means that indices will range
in $\{1,2,3\}$. The default value is start_index=0
.
規定のベースフィールド(基底)は$\mathbb{R}$であることに注意してください。もし、
field='complex'
,が与えられていれば、複素数体$\mathbb{C}$を基底として持つ
多様体が定義されます。[list of all options を参照のこと]
Note that the default base field is $\mathbb{R}$. If we would have used the optional
argument field='complex'
, we would have defined a manifold over $\mathbb{C}$. See the
list of all options for more details.
Mを要求すると、そのLaTexのシンボルとして表示されます。
If we ask for M, it is displayed via its LaTeX symbol:
M
代わりに print
関数を使うと、簡潔な記述が表示されます。
If we use the print
function instead, we get a short description of the object:
print(M)
3-dimensional differentiable manifold M
type
コマンドを使うと、M
に対応するPythonオブジェクトのタイプ(DifferentiableManifold_with_category
)が表示できます。
Via the command type, we get the type of the Python object corresponding to M (here the Python class DifferentiableManifold_with_category):
print(type(M))
<class 'sage.manifolds.differentiable.manifold.DifferentiableManifold_with_category'>
category()関数を使って、多様体M
のカテゴリーを調べます。この例では、この多様体の
カテゴリーは$\mathbb{R}$の上の滑らかな多様体であることがわかります。
We can also ask for the category of M and see that it is the category of smooth manifolds over $\mathbb{R}$:
category(M)
多様体の指標(を表すgeneator)は irange()
メソッドで生成されます。この指標はfor-ループなどで使われます。
The indices on the manifold are generated by the method irange(), to be used in loops:
[i for i in M.irange()]
start_index
パラメータが明示的に指定されていない場合、多様体の指標は 0 からはじまります、例えばこの例のように(0,1,2) の範囲となります。
If the parameter start_index had not been specified, the default range of the indices would have been $\{0,1,2\}$ instead:
M0 = Manifold(3, 'M', r'\mathcal{M}')
[i for i in M0.irange()]
まずは、多様体 $\mathcal{M}$ は一つの座標系で覆われると仮定します(そうでない場合は以下で議論されます)。 座標系は次のように宣言されます。
Let us assume that the manifold $\mathcal{M}$ can be covered by a single chart (other cases are discussed below); the chart is declared as follows:
X.<x,y,z> = M.chart()
上式の左辺にある.<x,y,z>
は Pythonの変数 x
, y
and z
が座標系の軸名として使われることを意味します。
これにより、座標軸を名前で指定することが可能になります。
The writing .<x,y,z>
in the left-hand side means that the Python variables x
, y
and z
are set to the three coordinates of the chart. This allows one to refer subsequently to the coordinates by their names.
この例では、関数 chart()
は引数をもっていません。この場合には、座標の名前は、x
, y
と z
(即ち、左辺の <...>
演算子で与えられた名前)になります。また座標の範囲は $(-\infty,+\infty)$ となります。それ以外の座標の名前やその範囲を指定する場合には chart()
にそれらを引数として与えなければなりません。座標名と異なる LaTex で使われる名前を指定する場合も同様です。(以下にそのような例が示されます。)
In this example, the function chart()
has no arguments, which implies that the coordinate symbols will be x
, y
and z
(i.e. exactly the characters set in the <...>
operator) and that each coordinate range is $(-\infty,+\infty)$. For other cases, an argument must be passed to chart()
to specify the coordinate symbols and range, as well as the LaTeX symbol of a coordinate if the latter is different from the coordinate name (an example will be provided below).
座標系は座標系が覆う開集合(ここでは多様体自身)と座標の組で表示されます。
The chart is displayed as a pair formed by the open set covered by it (here the whole manifold) and the coordinates:
print(X)
Chart (M, (x, y, z))
X
それぞれの座標値は指標を使って入手できます。指標の指定方法は多様体の定義時の設定(start_index=1
)に従います。
The coordinates can be accessed individually, by means of their indices, following the convention defined by start_index=1 in the manifold's definition:
X[1]
X[2]
X[3]
座標の全体は[:]
演算子を使って取得します。
The full set of coordinates is obtained by means of the operator [:]:
X[:]
座標系定義で使った <x,y,z>
演算子のおかげで、それぞれの座標をこの名前を使って直接取り扱えます。
Thanks to the operator <x,y,z>
used in the chart declaration, each coordinate can be accessed directly via its name:
z is X[3]
座標は SageMath の記号表現になっています。
Coordinates are SageMath symbolic expressions:
print(type(z))
<class 'sage.symbolic.expression.Expression'>
実数値をもつ座標の関数 (数学的にいえば、座標の終域で定義された関数) は チャートのfunction()
メソッドを使って生成されます。
Real-valued functions of the chart coordinates (mathematically speaking, functions defined on the chart codomain) are generated via the method function() acting on the chart:
f = X.function(x+y^2+z^3)
f
f.display()
f(1,2,3)
これらの関数は、SageManiforldsのクラス ChartFunction
(実際には、そのサブクラス𝙲𝚑𝚊𝚛𝚝𝙵𝚞𝚗𝚌𝚝𝚒𝚘𝚗𝚁𝚒𝚗𝚐_𝚠𝚒𝚝h_𝚌𝚊𝚝𝚎𝚐𝚘𝚛𝚢.𝚎𝚕𝚎𝚖𝚎𝚗t_𝚌𝚕𝚊𝚜𝚜
)に属しています。
They belong to the class ChartFunction
(actually the subclass 𝙲𝚑𝚊𝚛𝚝𝙵𝚞𝚗𝚌𝚝𝚒𝚘𝚗𝚁𝚒𝚗𝚐_𝚠𝚒𝚝h_𝚌𝚊𝚝𝚎𝚐𝚘𝚛𝚢.𝚎𝚕𝚎𝚖𝚎𝚗t_𝚌𝚕𝚊𝚜𝚜
):
print(type(f))
<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'>
そしてこのChartFunction
クラスに属する関数は、標準的な SageMath の記号的関数とは全ての演算で自動的簡約化の振る舞いが異なっています。例えば、二つの記号的関数の和:
and differ from SageMath standard symbolic functions by automatic simplifications in all operations. For instance, adding the two symbolic functions
f0(x,y,z) = cos(x)^2 ; g0(x,y,z) = sin(x)^2
は、次の結果になります。
results in
f0 + g0
一方、ChartFunction
クラスに属する関数は自動的に簡約化されます。
while the sum of the corresponding functions in the class ChartFunction is automatically simplified:
f1 = X.function(cos(x)^2) ; g1 = X.function(sin(x)^2)
f1 + g1
同じ結果を記号的関数でも得るためには、simplify_trig()
メソッドを使います。
To get the same output with symbolic functions, one has to invoke the method simplify_trig():
(f0 + g0).simplify_trig()
違いは表示方法にもあります。記号関数 f0
を表示させると、
Another difference regards the display; if we ask for the symbolic function f0, we get:
f0
となりますが、座標関数 f1
を表示させると、座標表示だけが表示されます。
while if we ask for the chart function f1, we get only the coordinate expression:
f1
f0
の場合と同じような表示を望む場合には、 display()
メソッドを使います。
To get an output similar to that of f0, one should call the method display():
f1.display()
expr()
メソッドは基になる記号表現を返すことを覚えておいてください。
Note that the method expr()
returns the underlying symbolic expression:
f1.expr()
print(type(f1.expr()))
<class 'sage.symbolic.expression.Expression'>
まず、多様体$\mathcal{M}$の部分集合を考えましょう。たとえば、$\{y=0, x\geq 0\}$ で定義される領域の補集合 $U$ です(
(y!=0, x<0)
は $y\not=0$ OR $x<0$を意味していることに注意。$y\not=0$ AND $x<0$ は[y!=0, x<0]
となる。)。
Let us first consider an open subset of $\mathcal{M}$, for instance the complement $U$ of the region defined by $\{y=0, x\geq 0\}$ (note that (y!=0, x<0)
stands for $y\not=0$ OR $x<0$; the condition $y\not=0$ AND $x<0$ would have been written [y!=0, x<0]
instead):
U = M.open_subset('U', coord_def={X: (y!=0, x<0)})
開部分集合$U$に制限された座標系 X
を X_U
と呼ぶことにします。
Let us call X_U
the restriction of the chart X
to the open subset $U$:
X_U = X.restrict(U)
X_U
$U$上の別の座標系、 $(r,\theta,\phi)$、を 導入します。
We introduce another chart on $U$, with spherical-type coordinates $(r,\theta,\phi)$:
Y.<r,th,ph> = U.chart(r'r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
Y
ここでは関数 chart()
は引数を持っています。それはraw文字列でLaTexのシンボルを含んでいます。また、この文字列には座標の(既定値の$(-\infty, +\infty)$とは異なる)範囲指定が含まれています。フィールドは:
で区切られており、座標は空白文字で区切られています。 座標$r$については、LaTexシンボルを指定していないので、下限と上限の二つだけが指定されています。LaTexシンボルは出力の際に使われます。
The function chart() has now some argument; it is a string, which contains specific LaTeX symbols, hence the prefix 'r' to it (for raw string). It also contains the coordinate ranges, since they are different from the default value, which is $(-\infty, +\infty)$. For a given coordinate, the various fields are separated by the character ':' and a space character separates the coordinates. Note that for the coordinate $r$, there are only two fields, since the LaTeX symbol has not to be specified. The LaTeX symbols are used for the outputs:
th, ph
Y[2], Y[3]
Sageが使っている座標の条件は、assumptions()
メソッドを使って確認することができます。
The declared coordinate ranges are now known to Sage, as we may check by means of the command assumptions():
assumptions()
これらの条件は、表現の簡約化の際に使われます。
They are used in simplifications:
simplify(abs(r))
$r >0$ と仮定されているので、$\mathrm{abs}(r)$ は $r$ に簡約されます。
simplify(abs(x)) # no simplification occurs since x can take any value in R
$x$ は$R$の負の値を含むどんな値でも取ることができますから、$\mathrm{abs}(x)$ は簡約できません。
座標 $Y$が宣言されたあとで、さらに 遷移写像を指定することで、$Y$の$X_U$への関係を完全に特定することができます。
After having been declared, the chart Y can be fully specified by its relation to the chart X_U, via a transition map:
transit_Y_to_X = Y.transition_map(X_U,
[r*sin(th)*cos(ph), r*sin(th)*sin(ph), r*cos(th)])
transit_Y_to_X
transit_Y_to_X.display()
set_inverse()
メソッドを用いることで、遷移写像の逆写像を指定することができます。
The inverse of the transition map can be specified by means of the method set_inverse():
transit_Y_to_X.set_inverse(sqrt(x^2+y^2+z^2), atan2(sqrt(x^2+y^2),z), atan2(y, x))
Check of the inverse coordinate transformation: r == r *passed* th == arctan2(r*sin(th), r*cos(th)) **failed** ph == arctan2(r*sin(ph)*sin(th), r*cos(ph)*sin(th)) **failed** x == x *passed* y == y *passed* z == z *passed* NB: a failed report can reflect a mere lack of simplification.
導かれた逆写像は、それと元の写像を組み合わせることで検証できます。 左辺と右辺がそれぞれに対応しています。 上の結果が示しているように、thとphの検証が失敗したと報告されているのは、 arctan2が関係する表式の単純化が不十分であることに起因しています。
A check of the provided inverse is performed by composing it with the original transition map, on the left and on the right respectively. As indicated, the reported failure for th and ph is actually due to a lack of simplification of expressions involving arctan2 . We have then
transit_Y_to_X.inverse().display()
この段階で、多様体のアトラス( user atlas
であって最大アトラスではありません)は三つの座標系を含んでいます。
At this stage, the manifold's atlas (the "user atlas", not the maximal atlas!) contains three charts:
M.atlas()
多様体に最初に定義された座標系は既定の座標系とみなされます。既定座標系はあとで、set_default_chart()
メソッドを使って変更できます。
The first chart defined on the manifold is considered as the manifold's default chart (it can be changed by the method set_default_chart()):
M.default_chart()
各々の開部分空間は各自のアトラスを持っています。開部分空間はそれ自身でも多様体であるからです。
Each open subset has its own atlas (since an open subset of a manifold is a manifold by itself):
U.atlas()
U.default_chart()
Y.plot(X,color={r:'red', th:'green', ph:'blue'})