"群論の味わい"/SAGE と GAP の GRAPE を使ってグラフを構成する

目次へ

Graph Theory using the GRAPE package

"群論の味わい"  第7章  7.2 ケーリーグラフ

例 7.2.1   SAGE と GAP の GRAPE パッケージを使って、対称群 S3 のグラフを構成する方法を例示します。

 この例題は私にとって挑戦的に思えた。なぜなら、次は初めての経験です。

  1. Sage から GAP を使用する。
  2. GAP のパッケージ GRAPE を使用する。

1. については、調べてみると標準で組み込まれていることがわかった。
 IPython から GAP を使用することはブログに書いたが、Sage から実行することに気が付かなかった。

パッケージ GRAPE をインストールする

パッケージのインストール方法は次に書いてあった。
  Installing Gap Packages
これを参考にインストールできた。 $SAGE_ROOT/local/gap/latest/pkg に grape をコピーする。

$ sage -sh
~$ cd $SAGE_ROOT/local/gap/latest/pkg
(sage-sh) satouy@Ubuntu-1:pkg$ ls
GAPDoc-1.5.1  grape
(sage-sh) satouy@Ubuntu-1:pkg$ cd grape
(sage-sh) satouy@Ubuntu-1:grape$ ./configure ../..
(sage-sh) satouy@Ubuntu-1:grape$ make
      MESSAGES
(sage-sh) satouy@Ubuntu-1:grape$ exit
exit
Exited Sage subshell.
$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.7, Release Date: 2015-05-17                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: gap_reset_workspace()
sage: quit
$

例 7.2.1

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.7, Release Date: 2015-05-17                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘

sage: gap.LoadPackage('"grape"')
true
sage: gens = [(1,2),(2,3)]
sage: gap.eval("gens := "+str(gens))
'[ (1,2), (2,3) ]'
sage: gap.eval("C := CayleyGraph(Group(gens), gens)")
'rec( adjacencies := [ [ 2, 3 ] ], group := Group([ (1,3)(2,4)(5,6), (1,2)(3,5)\n  (4,6) ]), isGraph := true, isSimple := true, \n  names := [ (), (2,3), (1,2), (1,2,3), (1,3,2), (1,3) ], order := 6, \n  representatives := [ 1 ], schreierVector := [ -1, 2, 1, 1, 2, 1 ] )'
sage: E = eval(gap.eval("UndirectedEdges(C)"))
sage: V = eval(gap.eval("Elements(Vertices(C))"))
sage: L = [sum([[y[i] for y in [x for x in E if v in x]\
....: if y[i] != v] for i in range(len(gens))], [])\
....: for v in V]
sage: d = dict(zip(V,L))
sage: G = Graph(d)
sage: show(G.plot())
/home/satouy/local/sage-6.7-x86_64-Linux/local/lib/python2.7/site-packages/setuptools-12.4-py2.7.egg/pkg_resources/__init__.py:1224: UserWarning: /home/satouy/.sage//.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Launched png viewer for Graphics object consisting of 13 graphics primitives
sage: quit
Exiting Sage (CPU time 0m1.00s, Wall time 14m38.35s).
Exiting spawned Gap process.
$ 

Sage -ipython notebook

目次へ