Small Prolog interpreter in Elixir

This is very interesting. I used to do Prolog way back in the 1980’s and loved it. But the language was used for things (AI) where better things are now possible.

Where Prolog shines is in the ability to state the intention of the code in just a few lines. I’m looking at this for a sharded UTXO blockchain project. We want to get away from the impenetrable Bitcoin script to have something more expressive than BTC script, but not as complex as Solidity. The declarative paradigm seems perfect for short smart contracts in cryptocurrencies.

The combination of Prolog and Elixir seems ideal for that use case.

I’ll be reading your Github repos closely to learn what I can.

John Small

4 Likes

Thank you so much for your interest.

Kenichi Sasagawa

Your reply cheer up me.
I improved Elxlog a little.
I built Elxlog into Deep Pipe, my deep learning library.
I am planning to corabolate the new AI, DL, and the classical AI, Prolog.

Thank you.

1 Like

I am making a compiler for Elxlog.
It converts Prolog code to Elixir code.
Some simple examples now works.

Elxlog ver0.12
?- compile(‘test.pl’).
true
?- [‘test.o’].
true
?- fact(10,X).
X = 3628800
true
?- my_member(b,[a,b,c]).
true
?- likes(sandy,X).
X = lee;
X = kim;
X = robin;
X = sandy;
X = cats;
X = sandy;
false
?

3 Likes

I am adding parallel processing.

fib(0,0).
fib(1,1).
fib(N,A) :-
N1 is N-1,N2 is N-2,
fib(N1,A1),fib(N2,A2),A is A1+A2.

pfib(0,0).
pfib(1,1).
pfib(N,A) :-
N1 is N-1,N2 is N-2,
parallel(pfib(N1,A1),pfib(N2,A2)),A is A1+A2.

?- time(fib(15,X)).
“time: 2793170 micro second”
X = 610
true
?- time(pfib(15,X)).
“time: 1127453 micro second”
X = 610
true

1 Like

Amazing work!

2 Likes

It feels a bit weird having to write fail() instead of fail, and there is no cut !. How can one survive without !? :wink:

Check out my erlog where I manage both. But it is a much larger system. Of interest for those who have tested it I have fixed some bugs in the ETS interface inerlog_ets.erl so it can now successfully match over an ETS table and get back all the variables in the match pattern.

3 Likes

Thank you for reply.

I decided to explicitly display predicates with no arguments to simplify the parser.

I extended Elxlog to calculate functions written in Elixir on the right side of is/2. I also added an extension to write deterministic predicates directly in Elixir. This is trying to eliminate the cut. For practical use, cut is necessary, but cut is difficult to understand.

Elxlog is not practical. It’s a simple implementation focused on SLD resolution. And I’m making it to test the possibility of parallel processing.

1 Like

Arigato gozaimashita Kenichi-san!
This interpreter inspired me to learn Prolog.
What a wonderful language, what a gift!
Thank you :bowing_man: :slightly_smiling_face:

P.S. for others unknowing and curious like me: The Power of Prolog

5 Likes

I am very honored. Thank you.

2 Likes