Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

O-Prolog update

81 views
Skip to first unread message

ken...@gmail.com

unread,
Oct 3, 2017, 7:03:01 PM10/3/17
to
Hello

I updated O-Prolog. It is ver0.591.
I have implemented tail recursive optimization on O-Prolog.
As a result, the interpreter runs 9Queens faster than the SWI-Prolog.
Also, I am making efforts to make compatible with ISO-Prolog. However, it is incomplete now.
On the Linux version, I improved the editing of REPL. The history function can also be called with UP and DOWN keys.
Please try it.

http://eisl.kan-be.com/library/oprolog1.html

Kenichi Sasagawa

burs...@gmail.com

unread,
Oct 3, 2017, 7:14:25 PM10/3/17
to
O-Prolog Ver0.591:

?- time(test).
Elapsed Time=0.136000 (second)

SWI-Prolog (threaded, 64 bits, version 7.7.0):

?- time(test).
% 287,256 inferences, 0.016 CPU in 0.022 seconds (71% CPU, 18384384 Lips)

Why do you think you are faster than SWI-Prolog?

P.S.: I am using this test case:

-------------- begin test case --------------------

nodiag([], _, _).
nodiag([N|L], B, D) :-
D =\= N - B,
D =\= B - N,
D1 is D + 1,
nodiag(L, B, D1).

qdelete(L, A, A, L).
qdelete([H|T], X, A, [A|R]) :-
qdelete(T, X, H, R).

search([], _, []).
search([H|T], History, [Q|M]) :-
qdelete(T, Q, H, L1),
nodiag(History, Q, 1),
search(L1, [Q|History], M).

% queens(-List)
queens(X) :-
search([1,2,3,4,5,6,7,8,9], [], X).

test :- queens(_), fail; true.

-------------- end test case --------------------

j4n bur53

unread,
Oct 3, 2017, 7:21:44 PM10/3/17
to
Something is wrong with time/1 and with fail/0.

I tried to get out of micro test (measurements
possibly below clock granulatrity):

test :- queens(_), fail.
test.
test2 :- between(1, 10, _), test, fail
test2.

But then I get the following error:

?- time(test2).
Shelter over flow

burs...@gmail.com schrieb:

ken...@gmail.com

unread,
Oct 3, 2017, 7:27:06 PM10/3/17
to
Hello Mr.Burs

I compared it with SWI-Prolog(version 7.2.3) of Windows version.
The result is as follows.
% 287,959 inferences. 0.078 CPU in 0.337 seconds (23% CPU. 3685875 Lips)
I wonder why?

Kenichi Sasagawa

burs...@gmail.com

unread,
Oct 3, 2017, 7:37:13 PM10/3/17
to
I get:
Elapsed Time=0.136000 (second)
And:
Elapsed Time=0.250000 (second)

randomly. So I want to get out of this
low granularity timing, and let the program
run longer, with between/3, but it crashes then.

ken...@gmail.com

unread,
Oct 3, 2017, 7:42:58 PM10/3/17
to
I am planning to improve.
The reason of random execution time is that GC is running.

ken...@gmail.com

unread,
Oct 4, 2017, 3:54:40 AM10/4/17
to
Hello Mr. Burs

I understood the reason. The benchmark program I used is below.
SWI-Prolog would have spent time displaying the answer.
I am making a compiler now. I 've get a goal. I would like to make it faster than the current 10 times.

Kenichi Sasagawa

-----------code--------
% 9-queens program


test :- queen([1,2,3,4,5,6,7,8,9],X),write(X),nl,fail.

queen(Data, Out) :-
queen_2(Data, [], Out).

queen_2([], _, []).
queen_2([H|T], History, [Q|M]) :-
qdelete(Q, H, T, L1),
nodiag(History, Q, 1),
queen_2(L1, [Q|History], M).

qperm([], []).
qperm([X|Y], [U|V]) :-
qdelete(U, X, Y, Z),
qperm(Z, V).

qdelete(A, A, L, L).
qdelete(X, A, [H|T], [A|R]) :-
qdelete(X, H, T, R).


nodiag([], _, _).
nodiag([N|L], B, D) :-
D =\= N - B,
D =\= B - N,
D1 is D + 1,
nodiag(L, B, D1).

safe([]).
safe([N|L]) :-
nodiag(L, N, 1),
safe(L).




j4n bur53

unread,
Oct 4, 2017, 1:49:59 PM10/4/17
to
I like O-Prolog, it has a little unconventional
top-level, but it seems to understand a lot
of the ISO core standard syntax.

I am right that in the below, qperm/2 and
safe/1 are not needed during the test run?

During time/1 what timer do you use. During
testing I didn't have the impression that
the different timings are due to GC,

because then they would show slight variations,
but on my machine time/1 only show two different
values, even when I did the test like 10 or 20

times, this means for me that the granularity
of the timer you use, is somewhere around
1/8 of second (judged from the two value) or so.

ken...@gmail.com schrieb:

ken...@gmail.com

unread,
Oct 4, 2017, 4:07:43 PM10/4/17
to
Thank you for your reply.

I referred to AZ-Prolog when I made O-Prolog.
AZ-Prolog is a commercial implementation.
It was developed by a Japanese company called SOFNEC.
I like AZ-Prolog and I imitated it.
AZ-Prolog is used in the robot pepper.
https://www.youtube.com/watch?v=XI4FXys3yJ8

The benchmark is based on the page of SICStus Prolog.

O-Prolog time/1 is not accurate. It uses the clock function of C.

I referred to Norvig's PAIP when making O-Prolog.
Therefore, inside of O-Prolog is S expression like Lisp.
However, this is not effective data structure for Prolog.
I'm redesigning a new data structure for Prolog.

I am making a translator from Prolog to C.
But that is difficult for me.
There are many things to think about.

Kenichi Sasagawa

burs...@gmail.com

unread,
Oct 4, 2017, 5:06:55 PM10/4/17
to
clock() will only show CPU time,
but I guess SWI-Prolog shows walltime.

https://github.com/SWI-Prolog/swipl-devel/blob/80b01be6d538a13eea5ca9fea4a540e6c486e542/library/statistics.pl#L577

Also using POSIX gettimeofday you might
get a higher resolution.

suseconds_t
Used for time in microseconds.

Thats a potential resolution of 10^(-6).

(Since JDK 1.5 in Java, you can also
use System.nanoTime() which has potential
resolution of 10^(-9))

ken...@gmail.com

unread,
Oct 8, 2017, 12:02:34 AM10/8/17
to
Hello Mr.Burs

The benchmark program of 9Queens you indicated has become a big stimulus to me.
I thought about the compiler of O-Prolog with a lot of time and concentration.
I finally got the idea of a simple C conversion code.
I made ISLisp compiler. However, the Prolog compiler seemed much more difficult than that.
I think that it is possible to complete Prolog compiler.
Thank you.

Kenichi Sasagawa

ken...@gmail.com

unread,
Oct 22, 2017, 6:42:38 AM10/22/17
to
Hello

I updated O-Prolog. It is ver0.60.
http://eisl.kan-be.com/library/oprolog1.html

I improved the data structure and suppressed the invocation of GC.
I have improved the accuracy of time/1. I secured accuracy of microseconds.
I implemented the timer time/1 for distance measurement with ultrasound.
It is a function to control the toy robot with Prolog.

The following is the Prolog code to use HC-SR04.
setup :-
wiringpi_setup_gpio(X),
pin_mode(23,output),
pin_mode(24,input),
digital_write(23,0),
delay(1000).

measure(X) :-
digital_write(23,1),
delay_microseconds(11),
digital_write(23,0),
read_wait(1),
timer(on),
read_wait(0),
timer(off),
timer(T),
X is T * 34000 /2.

read_wait(X) :-
repeat,
digital_read(24,Y),
X == Y,!.


And here is the posted article. Unfortunately it is only Japanese. I'm sorry.
https://qiita.com/sym_num/items/6796aa929f71dcf76078

Kenichi Sasagawa

0 new messages