prolog

Understanding this prolog implementation of head

head([Y],Y):-!. head([X|XS],X). I understand that the head of the list is stored on the variable X. What does the first clause mean? Is it a cut? Why? ...

Prolog instantiation error?

Hello guys, I'm stuck with some sort of error which i don't really understand in prolog. I get this error when calling a rule(which seems to work sometimes?) : error(instantiation_error,Var0) Can anyone explain to me what this means? so i have two rules: special(X) :- user(X, Days), Days >= 20. special(X) :- premiumuser(X). user(gu...

How to use OWL/RDL to represent and query a connected graph?

In PROLOG you can represent and query a connect graph, as in this tutorial: http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_15.html How would you do this using an OWL/RDL tool such as Protégé (http://protege.stanford.edu/)? ...

Are there alternative ways to display a list other than by using loop?

Hi everyone, I know on how to display a list by using loop. For example, choice(a):-write('This is the top 15 countries list:'),nl, loop(X). loop(X):-country(X),write(X),nl,fail. Unfortunately, I don't know on how to display list by using list. Anyone can guide me? ...

Prolog - Finding the current directory, relative directory for 'tell' predicate

I'm having trouble trying to figure out how to get prolog to spit out a text file where I want it to. I'm currently doing a bunch of operations and then using tell('output.txt') to record the output. Now the problem is that when I do this, it creates this file in the SWI \bin\ folder. I was wondering if there's a way to make it create...

prolog interpreter on linux?

I've decided to learn prolog. What's a good interpreter to use? Even better if it has a decent c/c++ ffi. ...

Power function in prolog

Exactly what's the prolog definition for power function. I wrote this code and it give some errors I wanna know exact code for the power function. pow(X,0,1). pow(X,Y,Z):-Y1=Y-1,pow(X,Y1,Z1),Z1=Z*X. Anything wrong with this code? ...

Can you do Logic Programming in Scala?

I read somewhere that Pattern Matching like that supported by the match/case feature in Scala was actually borrowed from Logic languages like Prolog. Can you use Scala to elegantly solve problems like the Connected Graph problem? e.g. https://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_15.html ...

what is logic programming? and what is different from other

today i have talk with other friend ,he said he has logic programming skill , so I am very curious about that. ...

Looking for a good semantic parser for the Russian language.

Does anyone known of a semantic parser for the Russian language? I've attempted to configure the link-parser available from link-grammar site but to no avail. I'm hoping for a system that can run on the Mac and generate either a prolog or lisp-like representation of the parse tree (but XML output is fine as well). Thank you kindly in ad...

prolog program to find equality of two lists in any order

I wanted to write a prolog program to find equality of two lists, the order of elements doesn't matter. So I wrote following: del( _ , [ ] , [ ] ) . del( X , [ X|T ] , T ). del( X , [ H|T ] , [ H|T1 ] ) :- X \= H , del( X , T , T1 ). member( X, [ X | _ ] ) . member( X, [ _ | T ] ) :- member( X, T ). eq...

Find all clauses related to an atom

This is probably a very silly question (I just started learning Prolog a few hours ago), but is it possible to find all the clauses related to an atom? For example, assuming the following knowledge base: cat(tom). animal(X) :- cat(X). , is there a way to obtain every possible information about tom (or at least all the facts that are e...

Understanding prolog [lists]

I am to write a program that does this: ?- pLeap(2,5,X,Y). X = 2, Y = 3 ; X = 3, Y = 4 ; X = 4, Y = 5 ; X = 5, Y = 5 ; false. (gives all pairs X,X+1 between 2 and 5, plus the special case at the end). This is supposedly the solution. I don't really understand how it works, could anyone guide me through it? pLeap(X,X,X,X). pLeap(L,H,...

Prolog - Sum up "positioned" elem in list

Hi guys, any solution to this problem - given a list of numbers [1,2,3,4,5] write a Prolog program to sum up all the odd-positioned in this list ? odd([1,2,3,4,5],Sum) Sum = 9. (1+3+5) ...

Prolog Question

Assume the third parameter is the result. a( 1, [Hd | Tl], Hd ). a( N, [ | Tl], Elem ) :- N > 1, N1 is N - 1, a( N1, Tl, Elem). I'm trying to understand what this does.... ...

Generalizing Fibonacci sequence with SICStus Prolog

I'm trying to find a solution for a query on a generalized Fibonacci sequence (GFS). The query is: are there any GFS that have 885 as their 12th number? The initial 2 numbers may be restricted between 1 and 10. I already found the solution to find the Nth number in a sequence that starts at (1, 1) in which I explicitly define the initia...

prolog list manipulating

I have the following code which basically needs to add a list as an item to a greater list. So NewBoardsList should contain all the boards generated in the moves_generate_board function. The problem is that i get a False in Prolog. Any help ? moves((Colour,_),Board,NewBoardsList):- other_colour(Colour,OtherColour), fin...

Relational Clausal Logic question: what is a Herbrand interpretation

I'm having a hard time coming to grips with relational clausal logic, and I'm not sure if this is the place to ask but it would be help me so much with revision if anyone could provide guidance with the following questions. Let P be the program: academic(X); student(X); other_staff(X):- works_in(X, university). :-student(john). :...

'if' in prolog?

Probably a stupid question, but I can't find any documentation anywhere for it. Is there a way to do an if in prolog, e.g. if a variable is 0, then to do some actions (write text to the terminal). An else isn't even needed, but I can't find any implementation of if. ...

prolog: reduce then write the value of a predicate

This is some of the code I am writing assert(bar(foo)), assert(foo(bar-5)), I'm not sure if it works though. I'm trying to get it to reduce foo by 5. I need a way to write the value of foo, but haven't found a way too. write('foo is' + foo) would be the logical way to me, but doesn't seem to work. ...