Planet Prolog

February 09, 2012

StackOverflow

Prolog, counter

I want to calculate , in two lists (same lenght), the number of elements that are equal and in the same position. For example: Lets say we have the lists A = [3,6,7,9] and B = [2,6,4,9], i want to be printed in the screen the message, "2 bulls found".

So far i have made this:

bulls([],[]).
bulls([Ha|Ta],[Hb|Tb]) :-
    Ha = Hb,
    writeln('bull found'),
    bulls(Ta,Tb);
    bulls(Ta,Tb).

Every time an element that exists in the same place in both lists, the message 'bull found' is printed. And in my mind i want to make something like this:

bulls([],[],_).
bulls([Ha|Ta],[Hb|Tb],Counter) :-
    Ha = Hb,
    NewCounter is Counter + 1,
    bulls(Ta,Tb,NewCounter);
    bulls(Ta,Tb,NewCounter).

bulls(List1,List2):- bulls(List1,List2,0).

bulls is called from another rule that passes the lists two it. How do i make it so it prints the value of 'bulls' to the screen. Any help?


Edit So after Suki's post, i made this test program testing 2 lists:

bulls([],[],X), write(X), write('bulls found'),fail.
bulls([Ha|Ta],[Hb|Tb],Counter) :-
    Ha = Hb,
    NewCounter is Counter + 1,
    bulls(Ta,Tb,NewCounter);
    bulls(Ta,Tb,NewCounter).

check(List1,List2):- 
    bulls(List1,List2,0).


start:-
    A=[1,1,1,1],
    B=[2,1,2,1],
    writeln(A),writeln(B),
    check(A,B).

and i get this result

1 ?- start.
[1,1,1,1]
[2,1,2,1]
ERROR: bulls/3: Arguments are not sufficiently instantiated

what am i doing wrong?

by sijoune at February 09, 2012 12:21 AM

February 08, 2012

StackOverflow

Has anybody seen a good open source Prolog implementation of the SATCHMO theorem prover?

I've seen quite a few papers on the SATCHMO theorem prover that talk about Prolog implementations. But the only source code implementation I've found so far was in a book and it was really limited and meant only for giving an example of how rules were evaluated and fired. Has anybody seen a good open source implementation of SATCHMO in Prolog?

Note, I am not referring to the Python language tool for Django called Satchmo, which is why I did not include Satchmo in the tags since that is what Stack Overflow shows as the dominant definition for that tag.

by Robert Oschler at February 08, 2012 11:25 PM

Beginner - add multiples of 3 and 5

Whenever I'm learning a new paradigm, I'm trying to solve the project euler problems with it. With Prolog I already got stuck at the first problem (the sum of all positive multiples of 3 and 5 below 1000) though. Aside from my code probably being extraordinarily horrible (it's actually longer than my C solution, which is quite a feat on it's own), I just can't get it to work. After adding the portion that's supposed to remove the multiples of 3 from the sum of the multiples of 5, gprolog will keep spitting out "No" for the query ?- sigma(1000,N).

Here's the code, the problem apparently lies in sigma5, but I can't quite spot it:

sigma(Num, Result) :- sigma3(Num, 3, Result3),
                      sigma5(Num, 5, Result5),
                      Result is Result3 + Result5.

sigma3(Num, A, Result) :- A < Num,
                          Ax is A+3,
                          sigma3(Num, Ax, ResultX),
                          Result is ResultX + A.

sigma3(Num, A, Result) :- A >= Num,
                          Result is 0.

sigma5(Num, A, Result) :- A < Num,
                          mod3 is A mod 3,
                          0 \= mod3,
                          Ax is A+5,
                          sigma5(Num, Ax, ResultX),
                          Result is ResultX + A.

sigma5(Num, A, Result) :- A < Num,
                          mod3 is A mod 3,
                          0 == mod3,
                          Ax is A+5,
                          sigma5(Num, Ax, ResultX),
                          Result is ResultX.

sigma5(Num, A, Result) :- A >= Num,
                          Result is 0.

Thanks in advance for any help.

by Cubic at February 08, 2012 06:40 PM

Prolog - weird issue

So i have an assignment in which i have to make a guessing game (bulls and cows). Firstly i made i little program where you enter two numbers and it checks if they have the same length and then if they are equal. *The numbers have have to be in lists, in order to be able to give in every guess the number of bulls and cows (see the rules of the game).

    equal([],[]).
    equal([Ha|Ta],[Hb|Tb]) :-
        Ha = Hb, equal(Ta,Tb).

    check_length(List1,List2):-
            same_length(List1,List2),writeln('The Lists have the same length!').

    check_equality(List1,List2):-
            equal(List1,List2),writeln('The Lists are equal!').
start:-
    write('give 1st list:'), read(X),atom_chars(X, List1),
    write('give 2nd list:'), read(Y),atom_chars(Y, List2),
    check_length(List1,List2),
    check_equality(List1,List2).

So far so good. It works fine. Then i went on to the next step and altered it, so it generates a list with 4 random integers and then it waits for the user to make a guess and compares the two lists like before. *Obviously i print the generated number to the screen in order to know if the program works ok.

start:-
    A is random(9),
    B is random(9),
    C is random(9),
    D is random(9),
    List2=[A,B,C,D],
    write('Generated number:'),writeln(List2),
    write('Make a guess:'), read(Guess),atom_chars(Guess, List1),
    nl,
    check_length(List1,List2),
    check_equality(List1,List2).

The problem is that this time even if you type the right number, the program does figure out if the lists (numbers) have the same length but fails in equality check. What am i doing wrong?

Thanks in advance.

by sijoune at February 08, 2012 04:33 PM

Random items in Prolog

I know I can do X is random(10). to get a random number from 0 to 10, but is there a similar command to get a random matching item?

by Pieter at February 08, 2012 12:48 PM

Using A* to solve Travelling Salesman Problem

I've been tasked to write an implementation of the A* algorithm (heuristics provided) that will solve the travelling salesman problem. I understand the algorithm, it's simple enough, but I just can't see the code that implements it. I mean, I get it. Priority queue for the nodes, sorted by distance + heuristic(node), add the closest node on to the path. The question is, like, what happens if the closest node can't be reached from the previous closest node? How does one actually take a "graph" as a function argument? I just can't see how the algorithm actually functions, as code.

I'm starting in C++ cause I'm far more familiar with it, verifying that the code works and produces expected results, then moving on to PROLOG, so preferably only solutions that don't involve a mass of library or language specific code like Boost.

Edit: Yes, I read the Wikipedia page before posting the question. Repeatedly. It doesn't really answer the question- searching the graph is way, way different to solving the TSP. For example, you could construct a graph where the shortest node at any given time always results in a backtrack, since two paths of the same length aren't equal, whereas if you're just trying to go from A to B then two paths of the same length are equal.

Hell, you could derive a graph by which some nodes are never reached by always going closest first.

I don't really see how A* applies to the TSP. I mean, finding a route from A to B, sure, I get that. But the TSP? I don't see the connection.

by DeadMG at February 08, 2012 09:33 AM

February 07, 2012

StackOverflow

Why does changing the order of facts change the behavior of the predicate?

This is my first idea:

perm([X|Y],Z) :- takeout(X,Z,W), perm(Y, W).   
perm([],[]).

When I tried to run -? perm([1, 2, 3], P)., it showed a stack overflow problem.

But if we change the order of the two statements, it will work.

perm([X|Y],Z) :- perm(Y, W), takeout(X,Z,W).  
perm([],[]). 

Why? I am a Prolog beginner, please help.

by Feifei Ji at February 07, 2012 11:02 PM

What's the difference between Prolog rules and queries?

I'm new to logical programming and find it difficult to understand the difference between rules and queries, I feel they are basically the same. Any help to clarify this would be greatly appreciated.

by n00b at February 07, 2012 09:39 PM

In Order Tree Traversal in Prolog

I'm new to Prolog and I'm trying write an in-order tree traversal where given a list of facts such as:

leftSubtree(9, 7).
leftSubtree(7, 1).
leftSubtree(1, -2).
leftSubtree(11, 9).
leftSubtree(16, 13).
leftSubtree(3, 2).
rightSubtree(9, 11).
rightSubtree(7, 6).
rightSubtree(1, 3).
rightSubtree(11, 16).
rightSubtree(16, 19).

I can use inOrder(9,X). to print out a the tree in order. I tried using the following code which works but was hoping for something simpler. Any tips or assistance would be appreciated.

inOrder(Root, X):-
   \+ leftSubtree(Root,Left),
   \+ rightSubtree(Root,Left) ->
   X = [Root];
   leftSubtree(Root,Left), 
   rightSubtree(Root,Right)->
   inOrder(Left, LeftNode),
   inOrder(Right, RightNode),
   append(LeftNode,[Root|RightNode],X);
   leftSubtree(Root,Left), 
   inOrder(Left, LeftNode),
   append(LeftNode,[Root],X);
   rightSubtree(Root,Right)->
   inOrder(Right, RightNode),
   append([Root],RightNode,X).

by gestalt at February 07, 2012 03:49 PM

Prolog function output

I am trying to do a function in prolog to add item in a list of list. What I want to do is to add 1 item at the end of the first list, 2 item at the end of the second list, etc.

I wrote this to start:

changerTableau(N,[Ligne|Reste],TableauVide,NouveauTableau):-
    repeter(N,'.',Point),
    append(Ligne,Point,NouvelleLigne),
    append(TableauVide,NouvelleLigne,NouveauTableau),
    writeln(N),
    N2 is N+1,
    writeln(NouveauTableau),
    changerTableau(N2,Reste,NouveauTableau,Output).

repeter(0,_,[]):-!.
repeter(N,Item,[Item|Reste]):-
    N2 is N - 1,
    repeter(N2,Item, Reste).

So what I want the program to do is, if I start with that:

changerTableau(1,[['x','w'],['a','b'],['l','o','l']],[ ],Resultat). 

I want to have in output:

Resultat = [['x','w','.'],['a','b','.','.'],['l','o','l','.','.','.']]

by Ichiban at February 07, 2012 03:10 PM

Using prolog with emacs

GNU Emacs 23.2.1
Fedora xfce 14

I starting to get into Prolog, and I want to use my emacs as the IDE for programming in Prolog.

Currently I use emacs for c/c++. But not sure how to get started with Prolog. I know that emacs has a built in library for programming in emacs. However, I have researched and found it is feature less, i.e. no syntax highlighting, indention, etc.

So I have download the emacs prackage Prolog.el. I have loaded this library using M-X Load-library.

However, I am not sure what to do after that. How do I compile my prolog files? In the menu of the emacs IDE it has nothing for Prolog.

Do I also need to download some interpretor or compiler for Prolog? Is there an emacs command for compiling? I normally use make in emacs when compiling c code.

I did a yum search prolog and got these results, so with all these choices which one do I need?:

gprolog.x86_64 : GNU Prolog is a free Prolog compiler
pl.x86_64 : SWI-Prolog - Edinburgh compatible Prolog compiler
pl-static.x86_64 : Static library for SWI Prolog
ppl-gprolog.x86_64 : The GNU Prolog interface of the Parma Polyhedra Library
ppl-gprolog-static.x86_64 : The static archive for the GNU Prolog interface of the Parma Polyhedra Library
ppl-swiprolog.x86_64 : The SWI-Prolog interface of the Parma Polyhedra Library
ppl-swiprolog-static.x86_64 : The static archive for the SWI-Prolog interface of the Parma Polyhedra Library
ppl-yap.x86_64 : The YAP Prolog interface of the Parma Polyhedra Library
yap.i686 : High-performance Prolog Compiler
yap.x86_64 : High-performance Prolog Compiler

Many thanks for any suggestions,

================== EDIT =====================

I have installed the following pl.x86_64

I have download the prolog.el and put it the following directory:

~/.emacs.d/site-lisp/prolog/prolog.el

And I have configured my emacs with the following:

;;; Prolog mode
(setq load-path (cons "~/.emacs.d/site-lisp/prolog/prolog.el" load-path))
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing prolog programs." t)
(setq prolog-system 'swi) ; prolog-system below for possible values
(setq auto-mode-alist (append '(("\\.pl$" . prolog-mode))
                              auto-mode-alist))

So when I save a file as *.pl I get the prolog menu options.

So I write some prolog code and from the prolog menu, I select Run interactive prolog session

I get a second blank buffer open which says (Inferior Prolog:run Shell-Compile)

However, I am not sure what I need to do at this stage. How do I compile and run the prolog files?

Many thanks for any further support.

by ant2009 at February 07, 2012 11:54 AM

February 06, 2012

StackOverflow

Circular Prolog

I have the following prolog code:

equiAngularTriangle(T) :-
    equiLateralTriangle(T).

equiLateralTriangle(T) :-
    equiAngularTriangle(T).

Is there a way to keep the interpreter from asking the same question twice? For instance, if I ask equiAngularTriangle(t), then it's going to ask equiLateralTriangle(t), then ask equiLateralTriangle(t), but it should know not to pursue that last one again, because the same question is on the "query stack".

Is there an option or some special syntax that lets Prolog behave the way I want it to?

by math4tots at February 06, 2012 09:11 PM

reddit Prolog

StackOverflow

All subset of list with k elements in Prolog

Please help me to solve this problem:

subset(N, [1,2,3], L).

if N=2, I want the result is that:

[1,2];

[2,1];

[1,3];

[3,1];

[2,3];

[3,2];

(in any order)

Thanks in advance.

by Welcome789 at February 06, 2012 02:57 PM

Scheme/Prolog finding all positions of an element in a list

I need help finding the first position of an element in a list and then finding all positions of the same element in both Scheme and Prolog for a really late exam for a course I did half a year ago and can't remember ANYTHING :(

Any ideas?

by user1189409 at February 06, 2012 02:23 PM

February 05, 2012

StackOverflow

How do I work with equations that are passed on in the goal/query of prolog?

I have this scenario wherein I get a linear equation in the Prolog query like below:

?- myquery( 3X + 5Y = 10, Result).

So my query has an equation 3X + 5Y = 10, which in general assumes the form AX + BY = C, where A=3, B=5 and C=10.

Now, in my prolog program, I am trying to define a predicate that can take in the expression mentioned in the query above. That is, I somehow want to get A, B and C values and also the operator involved (in the above case the plus operator) stored and then used on the logic that I define withing the program. I am wondering how this can be done.

To be more generic, the question is how do I identify the constants and the operator involved in an equation that is passed on through the goal/query?

I am new to Prolog, any help is really appreciated.

by kallakafar at February 05, 2012 07:42 PM

reddit Prolog

February 04, 2012

StackOverflow

3-jugs of water in prolog doesn't work

I have 3 jugs of water problem to solve but with a little trick.I dont have to use an algorithm but to have a 'function' that allows to user to move litres from on jug to another with an initial and final state that its written also by him.

For example he writes initial(10,0,0,0,r) and the first state is 10 litres in first and zero in the other two, also he writes final(0,3,3,3,l) and the final state has 3 litres in the two smaller jugs and zero in the first one.

The 'moves' between the jugs happen when he writes go(7,3,r) where he moves 3 litres to the right (from right to left we have the jugs form bigger to smaller) from bigger to the second jug, -7 is the litres that are left and 3 are the litres to be moved and r is the direction-.

And i have written this prolog code but every go-state is false..Has anyone any idea why??

:- dynamic go/3.
:- dynamic cur_state/1,init/5.
:- dynamic end_state/1, final/5.

cur_state(State):-State = state(10,0,0,7,l).
end_state(State):-State = state(0,3,3,0,r).

pour(state(D1,D2,D3,N,l),move(D,C,r),state(D,C,D3,N,r)) :-
        D is D1-N,
        C is D2+N.
pour(state(D1,D2,D3,N,r),move(D,C,l),state(D,C,D3,N,l)) :-
        D is D1-N,
        C is D2.
pour(state(D1,D2,D3,N,l),move(D,C,r),state(D,D2,C,N,r)) :-
        D is D1-N,
        C is D3+N.
pour(state(D1,D2,D3,N,l),move(D,C,r),state(D1,D,C,N,r)) :-
        D is D2-N,
        C is D3+N.
pour(state(D1,D2,D3,N,r),move(D,C,l),state(D1,D,C,N,l)) :-
        D is D2-N,
        C is D1+N.
pour(state(D1,D2,D3,N,r),move(D,C,l),state(D1,D,c,N,l)) :-
        D is D2-N,
        C is D3.
pour(state(D1,D2,D3,N,l),move(D,C,r),state(C,D2,D,N,r)) :-
        D is D3-N,
        C is D1.
pour(state(D1,D2,D3,N,r),move(D,C,l),state(D1,C,D,N,l)) :-
        D is D3-N,
        C is D2+N.
pour(state(D1,D2,D3,N,r),move(D,C,l),state(C,D2,D,N,l)) :-
        D is D3-N,
        C is D1+N.

carry(7,0).
carry(3,0).
carry(10,0).
carry(4,0).
carry(7,3).

legal(10,X,Y):-X+Y=<10.
legal(X,Y,Z):-X+Y+Z=<10.
legal(X,7,Y):-X+Y=<3.
legal(X,Y,3):-X+Y=<7.

newstate(state(D1,D2,D3,N,l),state(D11,D22,D33,N1,r)):-
        carry(M,C),
        M=<7,C=<3,
        D22 is D2+N,
        D11 is D1-N,
    D3 is D33,
    N1 is N,
        D2=<7,D1=<10,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,r),state(D11,D22,D33,N1,l)):-
        carry(M,C),
        M=<10,C=<100,
        D11 is D1-N,
    D22 is D2,
    D33 is D3,
        D1=<10,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,l),state(D11,D22,D33,N1,r)):-
        carry(M,C),
        M=<10,C<3,
        D11 is D1-N,
        D33 is D3+N,
    D22 is D2,
        D1=<10,D3=<3,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,r),state(D11,D22,D33,N1,l)):-
        carry(M,C),
        M=<7,C=<3,
        D22 is D2-N,
        D33 is D1+N,
        D11 is D1,
        D2=<7,D1=<10,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,l),state(D11,D22,D33,N1,r)):-
        carry(M,C),
        M=<7,C=0,
        D22 is D2-N,
        D33 is D3+N,
        D11 is D1,
    D2=<7,D3=<3,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,r),state(D11,D22,D33,N1,l)):-
        carry(M,C),
        M=<7,C=<100,
        D22 is D2-N,
    D33 is D3,
    D11 is D1,    
    D2=<7,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,r),state(D11,D22,D33,N1,l)):-
        carry(M,C),
        M=<3,C=<7,
        D22 is D2+N,
        D33 is D3-N,
        D11 is D1,
    D3=<3,D2=<7,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,r),state(D11,D22,D33,N1,l)):-
        carry(M,C),
        M=<3,C=<100,
        D11 is D1+N,
        D33 is D3-N,
        D22 is D2,
    D3=<3,D1=<10,
    legal(D1,D2,D3).

newstate(state(D1,D2,D3,N,l),state(D11,D22,D33,N1,r)):-
        carry(M,C),
        M=<3,C=<100,
        D33 is D3-N,
        D22 is D2,
    D11 is D1,  
    D3=<3,
    legal(D1,D2,D3).


eisodos(_):- cur_state(State),write(State),nl.

init(S1,S2,S3,S4,S5):-assert(cur_state(State):-State =                 state(S1,S2,S3,S4,S5)),write('Arxikh:'),
write(state(S1,S2,S3,S4,S5)),retractall(init(S1,S2,S3,S4,S5)),nl.

final(S1,S2,S3,S4,S5):-assert(end_state(State):-State =  state(S1,S2,S3,S4,S5)),write('Telikh:'),
write(state(S1,S2,S3,S4,S5)),retractall(final(S1,S2,S3,S4,S5)),nl.

go(Move1,Move2,Move3):-cur_state(State),newstate(State,NextState),
    pour(State,move(Move1,Move2,Move3), NextState),
    retractall(cur_state(State):-State = state(_,_,_,_,_)),asserta(cur_state(NextState)),
    ((end_state(NextState),write('Bravo!!!!')) ;(write(' ---*Eiste sthn katastash --- :'),write(NextState))),nl.

by tetartos at February 04, 2012 08:16 PM

Towers of Hanoi puzzle (prolog)

every one know the famous hanoi prolog

and you can find it HERE

and its great but when i write this query move(3,left,right,center).

its not showing these results

Move top disk from left to right
Move top disk from left to center
Move top disk from right to center 
Move top disk from left to right 
Move top disk from center to left 
Move top disk from center to right 
Move top disk from left to right

what i got is

Trace: >> RETURN: nl()
Trace: >> RETURN: hanoi(1,left,right,center)
Trace: >> RETURN: hanoi(2,center,right,left)
Trace: >> RETURN: hanoi(3,left,right,center)
True
1 Solution

so how i can let it print the results in a better way , and is it possible to name the disks so the program will name them to me as to show results as the following "move disk A from the left to the right"

sorry if I ask a lot but god I love PROLOG.

by Nadia at February 04, 2012 05:23 PM

February 03, 2012

reddit Prolog

StackOverflow

How to access list permutations in prolog?

i want to access list permutation and pass it as argument to Other functions, this is permutation code:

takeout(X,[X|R],R).  
takeout(X,[F |R],[F|S]) :- takeout(X,R,S),write(S).  
perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W).  
perm([],[]).

by zahraTZ at February 03, 2012 10:04 PM

ALP Newsletter

CFP: CILC 2012

CALL FOR PAPERS
9th Italian Convention on Computational Logic (CILC 2012)
Rome, Italy, June 6th to June 7th, 2012
www.dis.uniroma1.it/~cilc2012

The Italian Convention on Computational Logic is an annual event organized by GULP (Gruppo ricercatori e Utenti Logic Programming), the Italian association for Logic Programming affiliated to ALP (Association for Logic Programming). Since 1986, the annual meeting organized by GULP is the most important occasion for meeting and exchanging ideas and experiences between users, researchers and developers, who work in the field of computational logic. During its 26 years of recurrence, the annual GULP meeting has continually widened its horizons from the field of traditional logic programming to the more general areas of declarative programming and its applications in various neighboring fields, such as Artificial Intelligence or Deductive Databases. Also in this year’s convention, GULP wants to continue and possibly widen this policy, using the general term Computational Logic for integrating the various research fields, which use in direct or indirect, practical or theoretical ways or just addresses the ideas or techniques of logic as a tool for representation and calculation.
CILC 2012 will be held at the Dipartimento di Sistemi ed Informatica (DIS) of Università di Roma “La Sapienza” from June 6th to June 7th, 2012, in co-location with DL 2012, NMR 2012, KR 2012, and AI*IA 2012.

IMPORTANT DATES
Abstract submission deadline: March 10, 2012
Paper submission deadline: March 17, 2012
Notification of acceptance: April 15, 2012
Final version due: May 6, 2012
Convention: June 6-7, 2012

SCOPE
The convention will feature presentations of refereed contributions, including the demonstration of software prototypes, concerning all aspects of computational logic.

The topics of interest for the convention include, but are not limited to, the following areas:

  • Logic Programming, Constraint Programming and other forms of declarative programming
  • Extensions and integrations of declarative programming languages
  • Analysis, transformation, validation, and verification of programs
  • Instruments and environments for program development
  • Implementations and benchmarking
  • Model Checking
  • Automated Theorem Proving
  • Non-Monotonic Reasoning
  • Answer Set Programming
  • Knowledge Representation
  • Treatment of uncertain and incomplete knowledge
  • Approximate Reasoning
  • Abductive Logic Programming
  • Model-based Reasoning
  • Inductive Logic Programming
  • Deductive Databases
  • Data Mining and Data Integration
  • Multi-agent systems
  • Semantic Web
  • Natural Language Processing
  • Computational logic for concurrency, coordination, mobility and objects
  • Planning and scheduling
Contributions can be of two types: (a) Full papers, possibly already submitted at other conferences or journals, and (b) short papers, which are particularly suitable for presenting work in progress, software prototypes, extended abstracts of doctoral theses, or general overviews of research projects.
INVITED SPEAKERS * Umberto Straccia, ISTI-CNR Pisa, Italy
ORGANIZATION * Francesca Alessandra Lisi, Università degli Studi di Bari “Aldo Moro”, Italy (PC Chair) * Fabio Patrizi, “Sapienza” Università di Roma, Italy (Local Organization Chair)
SUBMISSION INSTRUCTIONS Authors are invited to submit their manuscripts in PDF via the EasyChair system. Articles must be written in English and must not exceed 15 pages for full papers and 5 pages for short papers, respectively. Manuscripts should be formatted using the Springer LNCS style. Accepted articles have to be presented at the convention.
PROCEEDINGS The original papers accepted for presentation at the convention (both full and short) will be published via CEUR-WS.org.
RESOURCES * Information about submission, registration, travel information, accommodation, etc., is available on the CILC 2012 homepage: www.dis.uniroma1.it/~cilc2012 * The official GULP home page is at http://lia.deis.unibo.it/gulp/

by Editors at February 03, 2012 10:49 AM

StackOverflow

Can you get a job thanks to your Prolog skills?

This Prolog question is introduced as an interview question. Can you get a job thanks to your Prolog skills? Is it used in the industry? (ok, ok, a job can be out of the industry too).

by Juanjo Conti at February 03, 2012 05:43 AM

Good IDE to get started with prolog

I need to start learning Prolog for my job.

I haven't used Prolog before and my company needs to build a program that will use Prolog.

So the program will be used commercially.

So some questions:

1) Does Prolog use a compiler to compile the programs. Like gcc does for c?

2) Is there commercial standard of Prolog? I have only heard of SWI Prolog.

3) I have been using GNU Emacs with Linux for many years. I am thinking of using the Prolog.el package? Any comments on that?

Many thanks for any answers,

by ant2009 at February 03, 2012 04:00 AM

February 01, 2012

StackOverflow

Flatten a list in Prolog

I've only been working with Prolog for a couple days. I understand some things but this is really confusing me.

I'm suppose to write a function that takes a list and flattens it.

i.e. - flatten([a, [b,c], [[d],[],[e]]]) -> [a,b,c,d,e]

The function takes out the inner structures of the list.

This is what I have so far:

flatten2([],[]).
flatten2([Atom|ListTail],[Atom|RetList]) :-
      atom(Atom), flatten2(ListTail,RetList).
flatten2([List|ListTail],RetList) :-
      flatten2(List,RetList).

Now, this works when I call flatten2([a, [b,c], [[d],[],[e]]], R).

I tells me that R = [a,b,c,d,e].

But when I call this function to see if a list that I input is already flattened, flatten2([a, [b,c], [[d],[],[e]]], [a,b,c,d,e])., it returns false.

Why does it work on one hand, but not the other? I feel like I'm missing something very simple.

Thanks.

by ToastyMallows at February 01, 2012 07:20 PM

how to split a sentence in swi-prolog

I am trying my hands on swi-prolog in win xp. I am trying to understsnad how to split a sentence in prolog into spearate atoms.

Ex : Say I have a sentence like this :

"this is a string"
Is there any way to get individual words to get stored in a variable?

like :

X = this
Y = is
....
and so forth.

Can anyone please explain how this works?

Thanks.

by JPro at February 01, 2012 03:08 PM

Count the number of occurrences of a number in a list

I'm writing a program in prolog that count the number of occurrences of a number in a list

count([],X,0).
count([X|T],X,Y):- count(T,X,Z), Y is 1+Z.
count([_|T],X,Z):- count(T,X,Z).

and this is the output

?- count([2,23,3,45,23,44,-20],X,Y).
X = 2,
Y = 1 ;
X = 23,
Y = 2 ;
X = 23,
Y = 1 ;
X = 3,
Y = 1 ;
X = 45,
Y = 1 ;
X = 23,
Y = 1 ;
X = 44,
Y = 1 ;
X = -20,
Y = 1 ;
false.

it's count the same number several times

Any help is appreciated

by Ratzo at February 01, 2012 12:54 PM

AllegroGraph check existing triple

I am using AllegroGraph 4. I have a triple store, and I am trying to add new triples only if they don't already exist.

Here is my Prolog query:

(select (?news) (alfas ?news) (a-- ?news !tst:has-annotation !tst:Test)))

where alfas checks for a condition(it works fine) and a-- is defined like this:

(<-- (a-- ?s ?p ?o)
;; Fails unless all parts ground.
(lisp (not (triple-exists-p ?s ?p ?o)))
(lisp (add-triple ?s ?p ?o)))

I have also tried defining it like this:

(<-- (a-- ?s ?p ?o)
;; Fails unless all parts ground.
(lisp (not (get-triple :s ?s :p ?p :o ?o)))
(lisp (add-triple ?s ?p ?o)))

But the triple is added anyway, no matter if it already exists or not. Why?

by Dragos at February 01, 2012 12:41 PM

How can make array in prolog?

I want to make an array in Prolog. How can do it? How can access the elements?

by zahraTZ at February 01, 2012 01:36 AM

January 31, 2012

StackOverflow

ask for input in prolog

I've written a code for solving sudoku.Now I don't know how to enter values of my variables. Here is a part of my code:

number(1).
number(2).
number(3).
number(4).
number(5).
number(6).
number(7).
number(8).
number(9).

sudoku(A1,A2,A3,A4,A5,A6,A7,A8,A9,
       B1,B2,B3,B4,B5,B6,B7,B8,B9,
       C1,C2,C3,C4,C5,C6,C7,C8,C9,
       D1,D2,D3,D4,D5,D6,D7,D8,D9,
       E1,E2,E3,E4,E5,E6,E7,E8,E9,
       F1,F2,F3,F4,F5,F6,F7,F8,F9,
       G1,G2,G3,G4,G5,G6,G7,G8,G9,
       H1,H2,H3,H4,H5,H6,H7,H8,H9,
       I1,I2,I3,I4,I5,I6,I7,I8,I9) :-
  number(A1),
  number(A2),
  number(A3),
  number(A4),
  number(A5),
  number(A6),
  number(A7),
  number(A8),
  number(A9),
  .
  .
  .
  H7 \= G7, H7 \= G8, H7 \= G9,
  H7 \= H8, H7 \= H9,
  H7 \= I7, H7 \= I8, H7 \= I9,
  H8 \= G7, H8 \= G8,H8 \= G9,
  H8 \= H7, H8 \= H9,
  H8 \= I7, H8 \= I8, H8 \= I9,
  H9 \= G7, H9 \= G8,H9 \= G9,H9 \= H7,H9 \= H8,
  H9 \= I7,H9 \= I8,H9 \= I9,
  I7 \= G7, I7 \= G8, I7 \= G9, I7 \= H7,
  I7 \= H8, I7 \= H9,
  I7 \= I8, I7 \= I9,
  I8 \= G7, I8 \= G8,I8 \= G9,
  I8 \= H7, I8 \= H8,I8 \= H9,
  I8 \= I7, I8 \= I9,
  I9 \= G7, I9 \= G8,I9 \= G9,I9 \= H7,I9 \= H8,
  I9 \= I7,I9 \= I8,

Now I don't know how to give some values and get answer... I'm just a beginner. For example, solve this sample:

47--6--59
---2-7---
6-------8
--5-8-9--
-1-7-6-8-
-—8-4-2--
8-------2
---6-3---
92--5--16

by user1181065 at January 31, 2012 11:52 PM

Remove duplicates in list (Prolog)

I am completely new to Prolog and trying some exercises. One of them is:

Write a predicate set(InList,OutList) which takes as input an arbitrary list, and returns a list in which each element of the input list appears only once.

Here is my solution:

member(X,[X|_]).
member(X,[_|T]) :- member(X,T).

set([],[]).
set([H|T],[H|Out]) :-
    not(member(H,T)),
    set(T,Out).
set([H|T],Out) :-
    member(H,T),
    set(T,Out).

I'm not allowed to use any of built-in predicates (It would be better even do not use not/1). The problem is, that set/2 gives multiple same solutions. The more repetitions in the input list, the more solutions will result. What am I doing wrong? Thanks in advance.

by Shark at January 31, 2012 11:46 PM

Testing Prolog Difference lists

I've been reading about how great difference lists are and I was hoping to test some examples from the books. But it seems that you can't pass lists as input in just the same way as, for instance append([1,2,3], [4,5], X), where X=[1,2,3,4,5]. Strangely, no book I've consulted ever mentions this.

I'm running the code on swipl and I'm interested in testing out a difference append predicate:

dapp(A-B,B-C,A-C).

and a "rotate first element of list" predicate:

drotate([H|T]-T1,R-S) :- dapp(T-T1,[H|L]-L,R-S).

Any ideas, how I can test these predicates in swipl?

Thanks! Daniel

by Daniel Loureiro at January 31, 2012 08:52 PM

Prolog predicate calling

In the following tutorial: http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/7_3.html

There is the part:

test_parser :- repeat,
               write('?? '), 
               read_line(X),
               ( c(F,X,[])   | q(F,X,[])  ),
               nl, write(X), nl, write(F), nl, fail.

Now I'm extremely confused about the c(F,X,[]) and q(F,X,[]) part because it doesn't seem to match any thing that I have seen, c only takes one parameter from what I can tell and these parameters don't seem to make sense for q. Please help me understand what is going on here.

by legion at January 31, 2012 08:10 PM

search all paths and the shortest path for a graph - Prolog

I have a problem in my code with turbo prolog wich search all paths and the shortest path for a graph between 2 nodes the problem that i have is to test if the node is on the list or not exactly in the clause of member and this is my code :

/*



           1    ---- b ----   3
           ---       |        ---
        ---          |             -----
      a              |5                  d
        ---          |             -----
            ---      |         ---
             2  ---  |     ---   4
                  -- c  --

for example we have for b--->c 
([b,c],5) , ([b,a,c],3) and ([b,d,c],7) : possible paths.
([b,a,c],3) : the shortest path.                                                        

*/

DOMAINS
list=Symbol *
PREDICATES


distance(Symbol,Symbol)
    path1(Symbol,Symbol,list,integer)
    path(Symbol,Symbol,list,list,integer)
    distance(Symbol,list,integer)
    member(Symbol,list)
    shortest(Symbol,Symbol,list,integer)

CLAUSES 
    distance(a,b,1).
    distance(a,c,2).
    distance(b,d,3).
    distance(c,d,4).
    distance(b,c,5).
    distance(b,a,1).
    distance(c,a,2).
    distance(d,b,3).
    distance(d,c,4).
    distance(c,b,5).

    member(X,[X|T]).
member(X, [Y|T]) :- member(X, T).

absent(X,L) :-member(X, L),!,fail.
    absent(_,_).

/*find all paths*/
path1(X, Y, L, C):- path(X, Y, L, I, C).
path(X, X, [X], I, C) :- absent(X, I).
path(X, Y, [X|R], I, C) :- distance(X, Z, A) , absent(Z, I), 
   path(Z, Y, R, [X|I] ,C1) , C=C1+A .

/*to find the shortest path*/
shortest(X, Y, L, C):-path(X, Y, L, C),path(X, Y, L1, C1),C<C1.

by user307320 at January 31, 2012 07:26 PM

Function argument used as list head variable in Prolog

I am a bit confused about this function definition in Prolog:

sample(X,[X|Tail]) :- member(X,Tail).

this function checks if X is at the first position of the given list and if X is also found in the tail of the list.

sample(1,[1,2,3]).
false.
% because 1 is not found in the tail

sample(1,[1,2,1]).
true.

But how does it work? X is the parameter given by the user but it seems to be overwriten by the head|tail extraction from the list. So it seems X new value is the first element in the list.

by apparat at January 31, 2012 06:49 PM

January 30, 2012

StackOverflow

How can access a List created in prolog?

i need to write a code that should access to list that created. but i don't know how, i read this question: How do I store and access a list within a variable in Prolog?

but it wasn't my problem I create the list with this code:

p([Head|Tail]):-
read(Head),
p([Tail|Taile]).
my_write([Head|Tail]):- write(Head),nl,my_write(Tail).

and i need created list. what should i do ? it's make me confuse.

by zahraTZ at January 30, 2012 06:53 PM

Limits to expressibility in Cyc, or similar knowledge-base projects?

What are the limits to expressibility, in Cyc or similar knowledge-base projects.

Are there certain concepts that can't be expressed? Is there any project that can express any concept?

I don't understand Cyc's syntax yet, but here is one example:

 (forAll ?CAT 
  (implies 
    (isa ?CAT DomesticCat) 
    (eatsWillingly ?CAT Meat)))

(I think what it means, is: domestic cats are cats, and cats willingly eat meat!)

So, assuming the person answering this question knew Cyc's language fully, my question to him, would be "What concepts can't be expressed in cyc".

For example this concept:

"How can someone fall so far, without realising it".

Is there any knowledge-representation language that can fully represent this statement?

But my real question is... is there any knowledge-representation language, that can express any concept. As far as I'm aware, there is no project yet (whether cyc, wordnet, prolog, or anything else) that can represent every kind of concept. But I don't know Cyc well enough to say that for sure.

by boytheo at January 30, 2012 02:03 PM

What is SML used for?

What are the uses of SML in the real word?

Are its practical uses similar to that of Prolog?

by CreamBun at January 30, 2012 08:44 AM

prolog SWI shell issues

I am trying to get my feet wet with some Prolog, as I have a project due in it relatively soon. How would I do something simple such as displaying some output text to the console? I am using the SWI shell, and attempting to consult a .pro file that looks like this

write_to_screen():-
    write("Hello World").

However, when I try and consult this file, I come across compile errors. Anyone know how you would call this function from the SWI shell?

*the error I am getting is 'Syntax error: Illegal start of term'

by Zack at January 30, 2012 07:57 AM

January 29, 2012

StackOverflow

Defining a module in Prolog

I have some problems defining a module. Here's a short reduction of the code:

:- module(my_module, [word/1]).
:- module(my_module, [alias_of/2]).

alias_of(A, B) :-
        alias_of(A, C),
        alias_of(C, B).
alias_of('Word_1', 'Word_2').

word(A) :-
        alias_of(B, A),
        word(B).
word('Word_1').
word('Word_3').

And this is the SWI-Prolog output when I consult the file:

1 ?- ERROR: (i:/dev/prolog-workspace/trial.0.pro:2):
        Undefined procedure: my_module:module/2
            However, there are definitions for:
                module/1
Warning: (i:/dev/prolog-workspace/trial.0.pro:2):
        Goal (directive) failed: my_module:module(my_module, [alias_of/2])

I thought, from the tutorials I read, that exposing predicates could be done using :- module(module_name,[predicate_name/arity]). What's wrong ?

EDIT: as I have played with this code now and tested it as a module, I figured out it's completely bugged...

by Stephane Rolland at January 29, 2012 08:21 PM

January 28, 2012

StackOverflow

What is the meaning of predicate "simple/1" in Prolog (SWI-Prolog)

I run into problem while reading a book. I see a program use predicate "simple" ( I guess simple/1 ). I don't know what is the meaning of this predicate, I can't find it with ?-help(simple) in the console. But when I tried with some queries in console, it worked something like:

5 ?- simple(p(x)). false.

6 ?- simple(mia). true.

7 ?- simple(Mia). true.

8 ?- simple(f(Mia)). false.

I tried to google, but it seems no use. I guess it is some sort of predicate to determine if the argument was Terms(or Variables) or Complex Terms. I'm not sure ! Anyone has used or met this predicate before, can you give a clue ?

Thanks.

by autobot_101 at January 28, 2012 08:42 AM

January 27, 2012

ALP Newsletter

CFP: PPDP 2012

Call for papers: 14th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming

Leuven, Belgium, September 18-20, 2012 (co-located with LOPSTR 2012)

PPDP 2012 is a forum that brings together researchers from the declarative
programming communities, including those working in the logic, constraint and
functional programming paradigms, but also embracing a variety of other
paradigms such as visual programming, executable specification languages,
database languages, and knowledge representation languages. The goal is to
stimulate research in the use of logical formalisms and methods for specifying,
performing, and analysing computations, including mechanisms for mobility,
modularity, concurrency, object-orientation, security, verification and static
analysis. Papers related to the use of declarative paradigms and tools in
industry and education are especially solicited. Topics of interest include,
but are not limited to:

  • Functional programming
  • Logic programming
  • Answer-set programming
  • Functional-logic programming
  • Declarative visual languages
  • Constraint Handling Rules
  • Parallel implementation and concurrency
  • Monads, type classes and dependent type systems
  • Declarative domain-specific languages
  • Termination, resource analysis and the verification of declarative programs
  • Transformation and partial evaluation of declarative languages
  • Language extensions for security and tabulation
  • Probabilistic modelling in a declarative language and modelling reactivity
  • Memory management and the implementation of declarative systems
  • Practical experiences and industrial application

This year the conference will be co-located with the 22nd International
Symposium on Logic-Based Program Synthesis and Transformation (LOPSTR 2012) and
held in cooperation with ACM SIGPLAN.  The conference will be held in Leuven,
Belgium. Previous symposia were held at Odense (Denmark), Hagenberg (Austria),
Coimbra (Portugal), Valencia (Spain), Wroclaw (Poland), Venice (Italy), Lisboa
(Portugal), Verona (Italy), Uppsala (Sweden), Pittsburgh (USA), Florence
(Italy), Montreal (Canada), and Paris (France).

Papers must describe original work, be written and presented in English, and
must not substantially overlap with papers that have been published or that are
simultaneously submitted to a journal, conference, or workshop with refereed
proceedings. Work that already appeared in unpublished or informally published
workshop proceedings may be submitted (please contact the PC chair in case of
questions). Proceedings will be published by ACM Press*

After the symposium, a selection of the best papers will be invited to extend
their submissions in the light of the feedback solicited at the symposium.  The
papers are expected to include at least 25% extra material over and above the
PPDP version. Then, after another round of reviewing, these revised papers will
be published in a special issue of SCP with a target publication date by
Elsevier of 2013.

Important Dates

Abstract Submission:         May 28, 2012
Paper submission:         May 31, 2012
Notification:             July 6, 2012
Camera-ready:             July 18, 2012

Symposium:             September 19-21, 2012

Invites for SCP:         September 26, 2012
Submission of SCP:         December 12, 2012
Notification from SCP:         February 7, 2013
Camera-ready for SCP:         March 7, 2013

Authors should submit an electronic copy of the paper (written in English) in
PDF. Each submission must include on its first page the paper title; authors
and their affiliations; abstract; and three to four keywords. The keywords will
be used to assist us in selecting appropriate reviewers for the paper. Papers
should consist of no more than 12 pages, formatted following the ACM SIG
proceedings template (option 1). The 12 page limit must include references but
excludes well-marked appendices not intended for publication. Referees are not
required to read the appendices, and thus papers should be intelligible without
them.

Program Committee:

Slim Abdennadher     German University in Cairo, Egypt
Puri Arenas        Complutense University of Madrid, Spain
Marcello Balduccini    Kodak Research Labs, USA
Amir Ben-Amram        Tel-Aviv Academic College, Israel
Philip Cox        Dalhousie University, Canada
Marina De Vos        University of Bath, UK
Martin Erwig        Oregon State University, USA
Martin Gebser        University of Potsdam, Germany
Jacob Howe        City University London, UK
Joxan Jaffar         National University of Singapore, Singapore
Gabriele Keller     University of New South Wales, Australia
Andy King        University of Kent, UK
Julia Lawall         INRIA Paris, France
Rita Loogen         Philipps-Universitat Marburg, Germany
Greg Michaelson        Heriot-Watt University, UK
Matthew Might        University of Utah, USA
Henrik Nilsson        University of Nottingham, UK
Catuscia Palamidessi    INRIA Saclay and Ecole Polytechnique, France
Kostis Sagonas         Uppsala University, Sweden and NTUA, Greece
Taisuke Sato        Tokyo Institute of Technology, Japan
Peter Schneider-Kamp    University of Southern Denmark, Denmark
Tom Schrijvers        University of Ghent, Belgium
Terrance Swift        Universidade Nova de Lisboa, USA
Mirek Truszczynski    University of Kentucky, USA
Stephanie Weirich     University of Pennsylvania, USA

Program Chair:

Andy King
School of Computing, University of Kent
Canterbury, CT2 7NF, UK

General Co-Chairs

Daniel De Schreye and Gerda Janssens
Department of Computer Science
K.U.Leuven, Celestijnenlaan 200 A, B-3001 Heverlee, Belgium

by Editors at January 27, 2012 03:03 PM

CFP: LOPSTR 2012

Call for papers: 22nd International Symposium on Logic-Based Program Synthesis and Transformation LOPSTR 2012

Leuven, Belgium, September 18-20, 2012 (co-located with PPDP 2012)

http://costa.ls.fi.upm.es/lopstr12

The aim of the LOPSTR series is to stimulate and promote international
research and collaboration on logic-based program development. LOPSTR
is open to contributions in logic-based program development in any
language paradigm. LOPSTR has a reputation for being a lively,
friendly forum for presenting and discussing work in progress. Formal
proceedings are produced only after the symposium so that authors can
incorporate this feedback in the published papers.

The 22nd International Symposium on Logic-based Program Synthesis and
Transformation (LOPSTR 2012) will be held in Leuven, Belgium; previous
symposia were held in Hagenberg, Coimbra, Valencia, Lyngby, Venice,
London, Verona, Uppsala, Madrid, Paphos, London, Venice, Manchester,
Leuven, Stockholm, Arnhem, Pisa, Louvain-la-Neuve, Manchester and
Odense (you might have a look at the contents of past LOPSTR
symposia). LOPSTR 2012 will be co-located with PPDP 2012
(International ACM SIGPLAN Symposium on Principles and Practice of
Declarative Programming).

Topics of interest cover all aspects of logic-based program
development, all stages of the software life cycle, and issues of both
programming-in-the-small and programming-in-the-large. Both full
papers and extended abstracts describing applications in these areas
are especially welcome. Contributions are welcome on all aspects of
logic-based program development, including, but not limited to:

  • specification
  • verification
  • analysis
  • specialization
  • composition
  • certification
  • transformational techniques in SE
  • synthesis
  • transformation
  • optimisation
  • inversion
  • program/model manipulation
  • security
  • applications and tools

Survey papers, that present some aspect of the above topics from a new
perspective, and application papers, that describe experience with
industrial applications, are also welcome.

Papers must describe original work, be written and presented in
English, and must not substantially overlap with papers that have been
published or that are simultaneously submitted to a journal,
conference, or workshop with refereed proceedings. Work that already
appeared in unpublished or informally published workshop proceedings
may be submitted (please contact the PC chair in case of questions).

Proceedings

The formal post-conference proceedings will be published by Springer
in the Lecture Notes in Computer Science series.

Important Dates

Abstract submission:                  May 21,2012
Paper submission:                     May 25, 2012
Notification (for pre-proceedings):   June 29, 2012
Camera-ready (for pre-proceedings):   July 8, 2012
Symposium:                            September 18-20, 2012

Submissions must be formatted in the Lecture Notes in Computer Science
style. They cannot exceed 15 pages including references but excluding
well-marked appendices not intended for publication. Referees are not
required to read the appendices, and thus papers should be
intelligible without them.

Full papers can be directly accepted for publication in the formal
proceedings to be published by Springer in the LNCS series or accepted
only for presentation at the symposium. After the symposium, all
authors of extended abstracts and full papers accepted only for
presentation will be invited to revise and/or extend their submissions
in the light of the feedback solicited at the symposium. Then, after
another round of reviewing, these revised papers may also be published
in the formal proceedings.

Authors should submit an electronic copy of the paper (written in
English) in PDF or Postscript (Level 2). Each submission must include
on its first page the paper title; authors and their affiliations;
contact author’s email; abstract; and three to four keywords. The
keywords will be used to assist us in selecting appropriate reviewers
for the paper. If electronic submission is impossible, please contact
the program chair for information on how to submit hard copies.

Papers should be submitted to the submission website for LOPSTR 2012.

Program Committee

Elvira Albert           Complutense University of Madrid, Spain
Sergio Antoy            Portland State University, US
Demis Ballis            University of Udine, Italy
Henning Christiansen    Roskilde University, Denmark
Michael Codish          Ben-Gurion University of the Negev, Israel
Danny De Schreye        K.U.Leuven, Belgium
Esra Erdem              Sabanci University, Istanbul
Maribel Fernandez       King’s College London, UK
John Gallagher          Roskilde University, Denmark
Miguel Gomez-Zamalloa   Complutense University of Madrid, Spain
Robert Glück           University of Copenhagen, Denmark
Rémy Haemmerlé           Technical University of Madrid, Spain
Reiner Hähnle          TU Darmstadt, Germany
Geoff Hamilton          Dublin City University, Ireland
Carsten Fuhs            RWTH Aachen, Germany
Gerda Janssens          K.U.Leuven, Belgium
Isabella Mastroeni      University of Verona, Italy
Paulo Moura             Universidade da Beira Interior, Portugal
Kazutaka Matsuda        Tohoku University, Japan
Johan Nordlander        Luleå University of Technology, Sweden
Andrey Rybalchenko      Technische Universität München, Germany
Kostis Sagonas  Uppsala University, Sweden
Francesca Scozzari      Università “G. D’Annunzio” di Chieti, Italy
Valerio Senni           Universtà di Roma “Tor Vergata”, Italy
German Vidal            Technical University of Valencia, Spain

Program Chair

Elvira Albert
Department of Computer Science (DSIC)
Complutense University of Madrid
Madrid, Spain

General Co-Chairs

Daniel De Schreye and Gerda Janssens
Department of Computer Science
K.U.Leuven, Celestijnenlaan 200 A, B-3001 Heverlee, Belgium

by Editors at January 27, 2012 02:58 PM

StackOverflow

Prolog Arithmetic plus

I've stumbled on a rather weird problem (to me).

Very easy, I want to an addition between 2 integers. I use the plus clause from swi

Now when I do this (I'm calculation something in a graph)

plus(LatestTime,LengthPath,TimeArrive),

The TimeArrive variable is a physical address instead of the answer. Now I've tried to make an other clause

myPlus(Var1,Var2,Result):-
    Result is Var1 + Var2.

And here is the same, so I'm starting to believe their is something wrong with my 2 input variables

LatestTime,LengthPath

However when I 'write' them I receive the integer instead of physical address.

Any clues? Because I'm out of idea's :)

by Christophe at January 27, 2012 02:35 PM

January 26, 2012

StackOverflow

Variables and how they are set and used in prolog

http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_1.html

So on that tutorial where it has:

conflict(Coloring) :- 
   adjacent(X,Y), 
   color(X,Color,Coloring), 
   color(Y,Color,Coloring). 

Am I understanding this correctly, that Color is a variable and is set to a value after the first call to color and then that value is used in the second call to color?

by legion at January 26, 2012 10:18 PM

ALP Newsletter

Book review: Computational Logic and Human Thinking: How to be Artificially Intelligent

by Luís Moniz Pereira
http://centria.di.fct.unl.pt/~lmp/
Centro de Inteligência Artificial (CENTRIA)
Faculdade de Ciências e Tecnologia
Universidade Nova de Lisboa, Portugal

Computational Logic and Human Thinking: How to be Artificially Intelligent

by Robert Kowalski

Cambridge University Press, 2011
ISBN: 978-0521123365, paperback, $46.00
xxii+310 pages

This is a review of the recent book by Robert Kowalski, Emeritus Professor in the Department of Computing Imperial College, London, http://www.doc.ic.ac.uk/~rak/

In 2011 he received the IJCAI Award for Research Excellence for his contributions to logic for knowledge representation and problem solving, including his pioneering work on automated theorem proving and logic programming.

Product Description (from C.U.P)

The practical benefits of computational logic need not be limited to mathematics and computing. As this book shows, ordinary people in their everyday lives can profit from the recent advances that have been developed for artificial intelligence. The book draws upon related developments in various fields from philosophy to psychology and law. It pays special attention to the integration of logic with decision theory, and the use of logic to improve the clarity and coherence of communication in natural languages such as English. This book is essential reading for teachers and researchers who may be out of touch with the latest developments in computational logic. It will also be useful in any undergraduate course that teaches practical thinking, problem solving or communication skills. Its informal presentation makes the book accessible to readers from any background, but optional, more formal, chapters are also included for those who are more technically oriented.

Detailed Summary of the Book by Chapters (abridged from the book)

Introduction. In Artificial Intelligence (AI), an agent is any entity, embedded in a real or artificial world, that can observe the changing world and perform actions on the world to maintain itself in a harmonious relationship with the world. Computational Logic (CL), as used in AI, is the agent’s language of thought. Sentences expressed in this language represent the agent’s beliefs about the world as it is and its goals for the way it would like it to be. The agent uses its goals and beliefs to control its behaviour. It can also use CL to guide its public communications with other agents.

Logic on the Underground. The London Underground Emergency Notice illustrates the way in which the meanings of English communications can be understood as thoughts in logical form. In CL these thoughts have both a logical and computational character. Because of this dual character, sentences expressed in this form are also called logic programs.

The Psychology of Logic. The most influential and widely cited argument against logic comes from psychological experiments about reasoning with natural language sentences in conditional form. The most popular interpretation of these experiments is that people do not have a natural general-purpose ability to reason logically, but have developed instead, through the mechanisms of Darwinian evolution, specialised algorithms for solving typical problems that arise in their environment. This chapter argues that one of the problems with the experiments is that they fail to appreciate that the natural language form of a conditional is only an approximation to the logical form of its intended meaning. Another problem is that the interpretation of these experiments is based upon an inadequate understanding of the relationship between knowledge and reasoning In contrast, the CL understanding of human thinking can be expressed loosely as: thinking = specialised knowledge + general-purpose reasoning.

The Fox and the Crow. Aesop’s fable of the fox and crow illustrates the backward reasoning of a clever fox, to generate a plan to achieve the goal of having the cheese of a not so clever crow. The chapter contrasts the fox’s proactive, backward reasoning with the crow’s reactive, forward reasoning, to respond to the fox’s praise by breaking out in song, thereby dropping the cheese to the ground, where the fox can pick it up. Both fox and crow reason according to the general-purpose inference rules of CL, but the fox has a better knowledge of the world, and more powerful ways of using it for her benefit. If the crow knew as much as the fox and were able to reason preactively, thinking before acting, then he could reason forward from the hypothetical performance of his candidate actions, predict their likely consequences, and choose an alternative action to achieve a better expected resulting state of affairs.

Search. In CL, a proof procedure consists of a collection of inference rules and a search strategy. The inference rules determine both the structure of proofs and the search space of all possible proofs relevant to the solution of a goal. The search strategy determines the manner in which the search space is explored in the search for a solution. Many different search strategies are possible.

Negation as Failure. In the semantics of CL the world is a positive place, which can be characterised by the positive atomic sentences that are true at the time. Because the ultimate purpose of an agent’s goals and beliefs is to manage its interactions with the world, the syntactic form of the agent’s thoughts also has a corresponding positive bias. Syntactically negative thoughts commonly arise from the failure to observe or derive positive information. Negation as failure is a natural way to reason by default with incomplete information, deriving conclusions under the assumption that the agent knows it all, but then withdrawing the conclusions if new information shows they do not hold. It also facilitates organising goals and beliefs into hierarchies of rules and exceptions.

How to Become a British Citizen. The British Nationality Act is a body of English sentences, which states precisely the conditions under which a person may acquire, renounce or be deprived of British citizenship. The Act is designed to be both unambiguous, so there is little doubt about its intended meaning, and flexible, so that it can be applied to changing circumstances. Its English style resembles the conditional form of sentences in CL. In addition to its use of conditional form, the Act illustrates many other important features of CL, such as the representation of rules and exceptions, and meta-level reasoning about what it takes for a person to satisfy the requirements for naturalisation as a British citizen. In contrast, the University of Michigan Lease Termination Clause shows how an ambiguous, virtually unintelligible English text can be made understandable by reformulating it in CL.

The Louse and the Mars Explorer. The most influential computational model of human thinking in Cognitive Psychology is the Production Systems, model illustrated in this chapter by the wood louse and the Mars explorer robot. Production systems combine a working memory of atomic facts with condition-action rules of the form if conditions then actions. The working memory is like a model of the current state of the world, and the rules like an agent’s goals and beliefs. Condition-action rules are embedded in an observation-thought-decision-action cycle and executed by matching the conditions of rules with facts in the working memory, thereby generating the actions of rules as candidate actions by forward chaining, which is similar to forward reasoning. If more than one candidate action is generated, conflict resolution decides amongst them. The chosen action is then executed, changing the state of the working memory, simulating the way an agent’s actions change the state of the world. From a logical point of view, there are three kinds of condition-action rules: reactive rules, which are like instinctive stimulus-response associations; goal-reduction rules, which reduce goals to subgoals by forward chaining; and forward reasoning rules, which perform genuine logical forward reasoning.

Maintenance Goals as the Driving Force of Life. The agent model in the book combines the functionalities of logic and production systems in a logical framework. It takes from production systems the observation-thought-decision-action cycle, but replaces condition-action rules by goals and beliefs in the logical form of conditionals. It replaces reactive rules by maintenance goals used to reason forwards, goal-reduction rules by beliefs used to reason backwards, and forward reasoning rules by beliefs used to reason forwards. In the logical agent model, the agent cycle responds to observations of the environment by reasoning forwards with beliefs, until it derives a conclusion that matches one of the conditions of a maintenance goal. It reasons backwards, to check the other conditions of the maintenance goal. If all the conditions of the maintenance goal are shown to hold, it reasons forwards one step, deriving the conclusion of the maintenance goal as an achievement goal. It then reasons backwards using its beliefs to reduce the achievement goal to a plan of candidate actions.

The Meaning of Life. The logical framework of the book views an agent’s life as controlled by the changes taking place in the world, by its own goals and beliefs, and by the choices the agent makes between different ways of achieving its goals. The combination of its beliefs and its highest-level goals generates a hierarchy of goals and subgoals. For the sake of efficiency, this hierarchy may be collapsed into a collection of more direct stimulus-response associations, whose original goals are no longer apparent, but implicit and emergent. In AI, and Computing more generally, it is common for an intelligent designer to implement an artificial agent that does not contain an explicit representation of its higher-level goals. The designer is aware of the agent’s goals, but the agent itself is not. As far as the agent is concerned, its life seems entirely meaningless. In this chapter the seemingly meaningless life of an imaginary, artificial wood louse, is compared with the more meaningful life of an intelligent agent, in which stimulus-response associations and awareness of higher-level goals are combined.

Abduction. One of the main functions of an agent’s beliefs is to represent causal relationships between its experiences. The agent uses these causal representations both proactively to generate plans to achieve its goals, and preactively to derive consequences of candidate actions to help it choose between alternative candidate actions. The agent can use the same causal beliefs abductively, to generate hypotheses to explain its observations, and deductively to derive consequences of hypotheses to help it choose between alternatives. The process of generating and choosing hypotheses to explain observations is called abduction. Like default reasoning with negation as failure, abduction is defeasible.

The Prisoner’s Dilemma. Deciding between alternative abductive explanations of an observation is similar to deciding between alternative actions, exemplified by the Prisoner’s Dilemma. In this chapter, it is seen how an agent can use a combination of CL and decision theory to choose between alternatives. In decision theory the agent should choose an alternative having the best expected outcome, determined by combining judgements of the utility of the actions’ consequences with judgements of the likelihood that their consequences will actually happen. Decision theory is normative, requiring detailed knowledge of utilities and probabilities, but neglecting the motivations of an agent’s actions. In practice, agents typically employ heuristic goals and beliefs, to approximate the decision-theoretic norms. To make smarter choices than those obtained by decision theory or heuristics alone, it is better to use the broader framework of the agent cycle, to analyse the motivations of actions, and to ensure that a full range of alternatives is explored.

Motivations Matter. Decision Theory leads to consequentialist theories of morality, which judge the moral status of actions simply in terms of their consequences. But in psychological studies and the law, people judge actions both in terms of their consequences and their motivations. CL can model such moral judgements by using constraints to prevent actions deemed morally or legally unacceptable.

The Changing World. An agent’s life is a continuous struggle to maintain a harmonious relationship with the ever-changing world. The agent assimilates its observations of the changing state of the world, and performs actions to change the world in return. To help it survive and prosper in such a changing environment, an agent must use beliefs about cause and effect, represented in its language of thought. This chapter investigates the logical representation and semantics of such causal beliefs.

Logic and Objects. Whereas in Cognitive Psychology production systems are the main competitor of Logic, in Computing the main competitor is Object-Orientation (OO). In the OO point of view, the world consists of objects that interact by sending and receiving messages. Objects respond to messages by using encapsulated methods, invisible to other objects, and inherited from methods associated with general classes of objects. CL is compatible with OO, if objects are viewed as agents, methods are viewed as goals and beliefs, and messages as one agent supplying information or requesting help from another. Viewed this way, the main contribution of OO is two-fold: It highlights the value of structuring knowledge in relatively self-contained modules, and of organising it in abstract hierarchies.

Biconditionals. This chapter explores the view that conditional beliefs are two-way biconditionals in disguise. Both negation as failure and abduction can be understood as reasoning with such biconditionals as equivalences.

Computational Logic and the Selection Task. This chapter interprets some results of psychological experiments on reasoning with conditionals. It investigates the different ways CL explains these results, depending on whether a conditional is interpreted as a goal or as a belief. If it is interpreted as a belief, then it is often natural to interpret the conditional as specifying the only conditions under which the conclusion holds. This explains one of the two main mistakes that people make when reasoning with conditionals, when judged by the standards of classical logic. The other mistake is that people often fail to reason correctly with negation. This is partly explainable by the fact that an agent’s observations are normally represented by positive atomic sentences, and that negative conclusions must be derived from positive observations. Often this is easier with conditional goals than with conditional beliefs.

Meta-logic. Meta-logic can be used to simulate the reasoning of other agents, and to solve problems that cannot be solved in the object language alone. This is illustrated with a variant of the wise man puzzle and, moreover, with Gödel’s theorem that there are true but unprovable sentences in arithmetic.

Conclusions. This concluding chapter takes a step back from the details, and takes a broader look at the main aim of the book, which is to show how CL can reconcile conflicting paradigms for explaining and guiding human behaviour. It also suggests how CL may help to reconcile conflicts in other areas.

Appendices: The Syntax of Logical Form. Truth. Forward and Backward Reasoning. Minimal Models and Negation. The Resolution Rule of Inference. The Logic of Abductive Logic Programming.

Commentary

Robert Kowalski is a foundational figure of Computational Logic and, over the years, has regularly laid down in print a succession of its cornerstones. His latest is a book several years in the making, that has filled the community with justified expectation and reward.

It is a deep epistemological book, as can be amply gleaned from the detailed summary above, and one which unrelentingly makes the case for Computational Logic as a premium scaffolding framework that bridges computational and human thinking.

The book is within clear grasp of a general higher-educated audience, because of the adept and informal naturalness with which it addresses, explains and exemplifies nevertheless non-trivial issues in knowledge representation and reasoning.

It is also a treasure trove for teachers and researchers alike, as it admirably integrates the author’s longstanding groundbreaking and fertile research efforts, and expounds with clarity and simplicity the unifying epistemological virtues of the Computational Logic paradigm ‒ one that is supported by a vast community of researchers.

Additionally, the formal support material, concentrated in the 64-pages of the six appendices at the end, provides a self-contained introduction to Computational Logic, which furthermore pinpoints and raises problems with a high potential for subsequent research, of interest to the community as a whole.

The Conclusions, when all is said and done, stand convincingly vindicated, and the book’s set of beliefs, achievement goals and maintenance goals are perfunctorily discharged, notwithstanding the author’s own penitence on topics left out, which we countenance: namely Inductive Learning, Uncertainty, Probability Theory, Connectionism, Conflict Resolution, and their relationships to Computational Logic.

This is understandable given the general audience targeted, and the technicalities of such advanced subjects, it being justly compensated for by due reference to appropriate surveys and the scientific literature.

One could readily think of other similarly refractory advanced subjects, such as Ontologies, Preferences, Belief Revision, to name a few. Indeed, given the very richness and varied scope of the Computational Logic paradigm, it will remain a never ending source and destination for the modelling of human thinking and its enabling mechanisms.

The book’s subtitle, “How to be Artificially Intelligence“, appears at first puzzling and I believe deliberately so. Is natural intelligence not enough? Is that not for computers and the like? How can I, a human, be artificially intelligent?

Answers are several in coming, but all under the banner that to understand ‒ and thence to perfect ‒ human intelligence, one must express how it works, and the computer is the experimental apparatus to test our own self-understanding, modelling it in detail to the extent we can. Logic, in the wide sense of logical, is the natural shared vehicle for so doing in a precise scientific way. And the computer, our privileged computational machine par excellence, is no doubt our artificial shared vehicle for objectively proving the worthiness of that understanding. Computational Logic spans both, and symbiotically benefits both.

Robert Kowalski is indeed intelligent, whether artificial or not, so it is a great thing that he wrote this illustrious book, as only he could have done.

by Editors at January 26, 2012 09:39 PM

StackOverflow

Checking repetition in list - Prolog

I'm trying to write hasRepetition that 'recives' a list and returns true if and only if it has repetitions in it.

I wrote : hasRepetition([Head|Tail]) :- member(Head,Tail);hasRepetition(Tail).

7 ?- hasRepetition([1,1]). ERROR: toplevel: Undefined procedure: hasRepetition/1 (DWIM could not correct goal)

by Belgi at January 26, 2012 05:36 PM

prolog running not work properly

sometimes when I run my program it works properly and sometimes when I try to run it it can't start to run ERROR: Undefined procedure: I restarted I consulted then I tried and I got answers what is the problem here? what should i do? I have SWI-Prolog Editor

by nik parsa at January 26, 2012 03:00 PM

Working with list of lists in Prolog

Please help me to solve this problem: I have a list of lists

[[1,2],[3,4]]

How do I get:

[1,3]

[1,4]

[2,3]

[2,4]

Or if I have a list of lists

[[1,2],[3,4],[6,7]]

How do I get:

[1,3,6]

[1,3,7]

[1,4,6]

[1,4,7]

[2,3,6]

[2,3,7]

[2,4,6]

[2,4,7]

Thanks

by Welcome789 at January 26, 2012 02:33 PM

Counting similar facts in prolog

I want to return true, if a fact (A) is declared only once in the prolog database, return false otherwise. For instance, if we have:

class('Person'). class('Person'). isUniqueClass(A) :- %%% This part I don't know how to do

And I query isUniqueClass('Person'). I want to return false. However, if we have:

class('Person'). isUniqueClass('Person') :- %%% Again same thing goes here

And I query isUniqueClass('Person'). I want it to return true.

Any tips?

by user1090837 at January 26, 2012 12:57 PM

How to count the number of children of parents in prolog (without using lists) in prolog?

I have the following problem. I have a certain number of facts such as: parent(jane,dick). parent(michael,dick). And I want to have a predicate such as: numberofchildren(michael,X) so that if I call it like that it shows X=1.

I've searched the web and everyone puts the children into lists, is there a way not to use lists? Thanx Daniel

by dasen at January 26, 2012 10:51 AM

January 25, 2012

StackOverflow

Procedure to test whether list represents a set with no duplicates

In Prolog how do you write a procedure that can be used to test whether or not a list represents a set with no duplicates?

by General_9 at January 25, 2012 05:45 PM

Testing whether a list represents a set with no duplicates

Because the built in predicate setof can be used to create an ordered list without duplicates, can I use it to test whether a list represents a set with no duplicates in this way:

no_duplicates(L):- setof(_,_,L).

by General_9 at January 25, 2012 05:37 PM

Satisfying a Unary Prolog predicate

In order to write a procedure satisfy(P,L) which returns the list L of all terms X such that the unary predicate P(X) succeeds. I have attempted the following: satisfy(P,L):- findall(X,call(P(X)),L).

Am I on the right track or I have gone completely off?

by General_9 at January 25, 2012 03:25 PM

Prolog Cuts and query results

In a prolog program as stated below:

town(a).
town(b).
town(c).
town(d).
dam(e).
dam(f).
link(a,b).
link(a,c).
link(c,d).
link(b,d).
link(b,c).
link(c,e).
link(a,e).
link(d,f).
neighbour(X,Y):- link(X,Y) ; link(Y,X).

Are these the correct results from the following queries:

Query 1 - ?-dam(X), once(neighbour(X,Y)),town(Y).

Results: X=e Y=c; X=f Y=d

Query 2 - ?-dam(X), neighbour(X,Y),!,town(Y).

Results: X=e Y=c

Query 3 - ?-dam(X),!,neighbour(X,Y),town(Y).

Results: X=e Y=c; X=e Y=a

by General_9 at January 25, 2012 02:52 PM

Inserting X in its correct position in a sorted list

In prolog how do I insert X in its correct position in a sorted list?

My Attempt:

insert(X,[Y|Rest],[X,Y|Rest]):-
X @< Y;
insert(X,Rest,BiggerRest).

by General_9 at January 25, 2012 02:29 PM

Neighbour, town, dam, link relationships

In a prolog program as stated below:

town(a).
town(b).
town(c).
town(d).
dam(e).
dam(f).
link(a,b).
link(a,c).
link(c,d).
link(b,d).
link(b,c).
link(c,e).
link(a,e).
link(d,f).
neighbour(X,Y):- link(X,Y) ; link(Y,X).

Would this be the correct procedure all_neighbours(L,X) which returns a list L of all neighbouring towns to X: all_neighbours(L,X):- town(Y), findall(Y, neighbour(X,Y), L).

Would this be the correct procedure has_dam(L) which returns a list L of all towns that have at least one neighbouring dam: has_dam(L):- dam(Y), town(X), findall(X, neighbour(X,Y), L).

Would this be the correct procedure no_dam(L) which returns a list L of all towns that have no neighbouring dam: no_dam(L):- town(X), not dam(Y), findall(X, neighbour(X,Y), L).

by General_9 at January 25, 2012 01:43 PM

How to check if there's two facts that represent the same in prolog

I'm having trouble understanding this. Suppose I have:

person(peter).
person(bob).
person(amanda).

Is there a way in which I can prove that no two persons have the same name? I tried doing:

person(X) = person(Y).

but this gives:

X = Y

or is this enough??

Thanks!

by bb2 at January 25, 2012 01:34 PM

Prolog and ancestor relationship

I have to write a small prolog program which checks if a given person is a ancestor of a second one. These are the facts and rules:

mother(tim, anna).
mother(anna, fanny).
mother(daniel, fanny).
mother(celine, gertrude).
father(tim, bernd).
father(anna, ephraim).
father(daniel, ephraim).
father(celine, daniel).

parent(X,Y) :- mother(X,Y).
parent(X,Y) :- father(X,Y).

The test if a person is an ancestor of another person is easy:

ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

But now I have to write a method ancestor(X,Y,Z) which also prints out the relationship between two persons. It should look like this

?- ancestor(ephraim, tim, X).
false.
?- ancestor(tim, ephraim, X).
X = father(mother(tim)).

And that is the problem: I have no clue how do to this.

by user1164180 at January 25, 2012 12:19 PM

Which is the best among Visual Prolog, SWI-Prolog, and others?

I have searched the Internet and stackoverflow.com, but got nothing.

Who can give me a comparison between various Prolog compilers/IDEs such as Visual Prolog and SWI-Prolog?

Thanks in advance!

by xmllmx at January 25, 2012 07:19 AM