1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

N-Prolog cubeライブラリの整備

Posted at

「Prologで数学遊び」の執筆をしています。そのために2*2ルービックキューブを動かすライブラリを用意しました。

cubeライブラリ 

計算実験をしてきたのですがそれらの述語を整理してライブラリにまとめました。詳しくは
CUBE.mdにあります。ざっと使い方をご紹介します。

N-Prolog Ver 4.80 [30M cells]
?- use_module(cube).
yes
?- init_cube(C0),apply(f,C0,C1).
C0 = cube_cube([1,2,3,4,5,6,7,8],[[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]])
C1 = cube_cube([4,1,2,3,5,6,7,8],[[5,1,3,4,6,2],[5,1,3,4,6,2],[5,1,3,4,6,2],[5,1,3,4,6,2],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]]) .
yes
?- init_cube(C0),apply([f,u,r],C0,C1).
C0 = cube_cube([1,2,3,4,5,6,7,8],[[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]])
C1 = cube_cube([5,1,4,3,6,7,2,8],[[1,4,2,5,3,6],[1,4,2,5,3,6],[1,4,2,5,3,6],[5,1,3,4,6,2],[1,4,2,5,3,6],[3,2,6,1,5,4],[3,1,2,5,6,4],[1,2,3,4,5,6]]) .
yes

applyはキューブへの操作を行います。操作は単体でも記述できますし、合成された操作はリストで表記できます。

?- order(f,N).
N = 4 .
yes
?- order([f,u,r],N).
N = 30 .
yes
?- order([f,r,fi,ri],N).
N = 6 .
yes

位相はアトムでも記述できますし、リストでも表記できます。交換子はリストで記述できます。

?- init_cube(C0),apply([f,u,r]^30,C0,C1).
C0 = cube_cube([1,2,3,4,5,6,7,8],[[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]])
C1 = cube_cube([1,2,3,4,5,6,7,8],[[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6],[1,2,3,4,5,6]]) .
yes
?-

操作を繰り返す場合には^をつかってべき乗と同様に記述できます。できるだけキュービストが使っている表記に合わせました。

N-Prologの最新版にcubeライブラリが付属しています。
https://github.com/sasagawa888/nprolog

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?