If anyone was curious, here is a quick speed comparison of Prolog in Shen (both SBCL and Scheme version) with SWI-Prolog and Trealla Prolog.
The test was performed on a MacBook Air M3.
The Prolog version of the program:
permute_with_insert([], []).
permute_with_insert([L|Ls0], Ps) :-
permute_with_insert(Ls0, Ls),
insert(L, Ls, Ps).
insert(X, Ys, [X|Ys]).
insert(X, [Y|Ys], [Y|Zs]) :-
insert(X, Ys, Zs).
benchmark(Ls) :-
time((permute_with_insert(Ls, _), fail ; true)).
main :-
benchmark([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
halt.
The Shen version of the program (insert renamed to insert1 because Shen SBCL was complaining):
(defprolog permute_with_insert
[] [] <-- ;
[L|Ls0] Ps <-- (permute_with_insert Ls0 Ls) (insert1 L Ls Ps);
)
(defprolog insert1
X Ys [X|Ys] <-- ;
X [Y|Ys] [Y|Zs] <-- (insert1 X Ys Zs);
)
(defprolog benchmark
Ls <-- (permute_with_insert Ls _) (when false);
Ls <-- ;
)
(time (prolog? (benchmark [1 2 3 4 5 6 7 8 9 10 11 12])))
Trealla Prolog
~/prolog % tpl -g main
benchmark.pro% Time elapsed 92.965s, 1480959528 Inferences, 15.930 MLips
SWI-Prolog
~/prolog % swipl -g main
benchmark.pro% 522,956,326 inferences, 31.920 CPU in 31.965 seconds (100% CPU, 16383472 Lips)
Shen SBCL
~/shen % shen-sbcl
Shen,
www.shenlanguage.org, copyright (C) 2010-2024, Mark Tarver
version: S39, language: Common Lisp, platform: SBCL 2.0.0
port 3.3, ported by Mark Tarver
(0-) (load "benchmark.shen")
(fn permute_with_insert)
(fn insert1)
(fn benchmark)
run time: 449.5423288717866 secs
true
Shen Scheme
~/shen % shen-scheme eval -l benchmark.shen
(fn permute_with_insert)
(fn insert1)
(fn benchmark)
run time: 173.675523 secs
true
Leszek