Questions tagged [prolog]

Prolog is the most commonly used logic programming language. It supports non-deterministic programming through chronological backtracking and pattern matching through unification. Do not use this tag like Prologue and Epilogue.

Prolog is the oldest and most popular logic programming language. Its built-in features include non-deterministic programming through backtracking and a powerful parser formalism called Definite Clause Grammars (DCG) . Modern variants often support some form of constraint programming. It is used for automated reasoning, deductive databases, planning and scheduling tasks, natural language processing, engines for web/business rules and is often used to introduce the declarative paradigm in school.

There is an ISO/IEC standard for Prolog .

Further efforts in harmonizing implementations can be found at Prolog Commons.

Prolog-related tags

Core language:

Modules:

Environment:

Arithmetics:

Puzzles:

Problems:

Implementations:

  1. SWI (free)
  2. SICStus (commercial)
  3. GNU (free)
  4. XSB (free)
  5. B (commercial, discontinued, now Picat)
  6. IF (commercial)
  7. Ciao (free)
  8. Minerva (commercial)
  9. ECLiPSe-CLP (free)
  10. Prolog IV (free)
  11. Tau (free)
  12. Scryer (free)
  13. C-Prolog
  14. trealla

free = allows commercial use without royality

Forums

Free Prolog Programming Books

Languages influenced by Prolog

Microsoft Guan

Historical Archive

Prolog and Logic Programming Historical Sources Archive

Useful links

13358 questions
35
votes
2 answers

Prolog: Clauses are not together in source-file

I have this piece of code: % Family tree female(pen). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim). parent(pam, bob). parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(pat, jim). I get this…
intelis
  • 7,829
  • 14
  • 58
  • 102
34
votes
3 answers

Prolog count the number of times a predicate is true

I want to count the number of times a custom predicate is true. For example, I have the following code: is_man(john). is_man(alex). ?:-is_man(X). X will return john, then if I press semicolon it will also return alex, then false. I want to build…
Victor Blaga
  • 1,822
  • 4
  • 19
  • 28
34
votes
6 answers

Lisp and Prolog for Artificial Intelligence?

Now since i've taken a class 3 years ago in A.I. im clearly proficient enough to ask this question......just kidding just kidding ;) but seriously, what is it about these languages that make them so popular for A.I. research. Even though A.I.…
user475353
34
votes
2 answers

How to create a fact in SWI-Prolog?

I just want to create something like: like(x,y). I've been trying for a long time and am really frustrated, could anyone please tell me how to do it???!!!
Hope7
  • 353
  • 1
  • 3
  • 4
34
votes
2 answers

Datalog vs CLIPS vs Prolog

As many programmers I studied Prolog in university, but only very little. I understand that Prolog and Datalog are closely related, but Datalog is simpler? Also, I believe that I read that Datalog does not depend on ordering of the logic clauses,…
Eli Schneider
  • 4,903
  • 3
  • 28
  • 50
34
votes
8 answers

What are the best uses of Logic Programming?

By Logic Programming I mean the a sub-paradigm of declarative programming languages. Don't confuse this question with "What problems can you solve with if-then-else?" A language like Prolog is very fascinating, and it's worth learning for the sake…
mbac32768
  • 11,453
  • 9
  • 34
  • 40
33
votes
2 answers

"Not equal" sign in Visual Prolog?

I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem: class predicates sister : (string Person, string Sister) nondeterm(o,o). clauses sister(Person, Sister) :- …
Egor
  • 39,695
  • 10
  • 113
  • 130
33
votes
8 answers

different/2 - does a pure, determinate definition exist?

different(Xs, Ys) :- member(X, Xs), non_member(X, Ys). different(Xs, Ys) :- member(Y, Ys), non_member(Y, Xs). While this definition using member/2 and non_member/2 is almost1 perfect from a declarative viewpoint, it produces redundant…
false
  • 10,264
  • 13
  • 101
  • 209
33
votes
8 answers

How to define (and name) the corresponding safe term comparison predicates in ISO Prolog?

Standard term order (ISO/IEC 13211-1 7.2 Term order) is defined over all terms — including variables. While there are good uses for this — think of the implementation of setof/3, this makes many otherwise clean and logical uses of the built-ins in…
false
  • 10,264
  • 13
  • 101
  • 209
32
votes
3 answers

Alternatives to the WAM

I remember once reading that there were at least two other alternatives invented roughly at the same time as the WAM. Any pointers?
adamo
  • 3,584
  • 1
  • 18
  • 23
32
votes
2 answers

How do I include a .pl file in Prolog?

I'd like to include code from another source file. Does anyone know how to do that?
cody
  • 6,389
  • 15
  • 52
  • 77
32
votes
4 answers

Prolog - Arguments are not sufficiently instantiated

I am writing a little program which counts how many elements in a list are not numbers. Here is my code: not_number([],0). not_number([X|T],R):- not(number(X)), R1 is R+1, not_number(T,R1). not_number([_|Tail],Result):- …
Eddwhis
  • 1,124
  • 2
  • 16
  • 33
32
votes
4 answers

Implement the member predicate as a one-liner

Interview question! This is how you normally define the member relation in Prolog: member(X, [X|_]). % member(X, [Head|Tail]) is true if X = Head % that is, if X is the head of the list member(X, [_|Tail]) :- % or…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
31
votes
1 answer

Prolog existence_error following Seven Languages in Seven Weeks

I'm just following the book Seven Languages in Seven Weeks. I've installed gprolog in my Mac machine using command port install gprolog-devel and run first prolog code. likes(wallace, cheese). likes(grommit, cheese). likes(wendolene,…
Hongseok Yoon
  • 3,148
  • 8
  • 36
  • 51
31
votes
2 answers

Why is this prolog query both true and false?

My SWI-Prolog knowledge base contains the following two facts: f(a,b). f(a,c). Now if I pose the query ?- f(a,c). true. But ?- f(a,b). true ; false. Why is f(a,b) both true and false? This also happens when there are three facts in the KB. If…
del
  • 311
  • 1
  • 3
  • 3