Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am researching programming languages used for AI programming. I know that LISP is taught as an AI programming language in my university, but Prolog rarely is. I am kind of fond of Prolog, but I'm not an AI programmer so I don't think I'm qualified to judge for myself why Prolog is better than LISP/Scheme. I was wondering if Programmers had any input on this topic.

How could you argue that Prolog would be more useful for AI programming?

I have been researching it a bit, and the basic argument I've seen over and over is that since thoughts are presented in logic, and Prolog is a logical programming language, Prolog can build decision machines easily, or something to that effect.

Is there anything else that can be said for Prolog in AI?

share|improve this question
1  
It's not a lot of work to write a Prolog compiler/interpreter in Lisp. Paul Graham has an example in On Lisp. –  Larry Coleman Jun 16 '11 at 14:55
    
One of my classmates was telling me this too. I found it really interesting that LISP's symbolic manipulation would let me re-create Prolog. Thanks for the nice aside! –  2rs2ts Jun 16 '11 at 18:19
3  
@Larry Coleman: It's not a lot of work to write a naive Prolog compiler/interpreter in Lisp. Making one that is efficient and fully-functional is non-trivial in any language. –  JUST MY correct OPINION Jun 17 '11 at 1:16

4 Answers 4

up vote 14 down vote accepted

From the preface to Prolog Programming for Artificial Intelligence:

Prolog is a programming language centred around a small set of basic mechanisms, including pattern matching, tree-based data structuring and automatic backtracking. This small set constitutes a surprisingly powerful and flexible programming framework. Prolog is especially well suited for problems that involve objects - in particular, structured objects - and relations between them. For example, it is an easy exercise in Prolog to express spatial relationships between objects, such as the blue sphere is behind the green one. It is also easy to state a more general rule: if object X is closer to the observer than object Y, and Y is closer than Z, then X must be closer than Z. Prolog can now reason about the spatial relationships and their consistency with respect to the general rule. Features like this make Prolog a powerful language for artificial intelligence (AI) and non-numerical programming in general. There are well-known examples of symbolic computation whose implementation in other standard languages took tens of pages of indigestible code. When the same algorithms were implemented in Prolog, the result was a crystal-clear program easily fitting on one page.

Basically it's a great language for expressing various relationships and goals in a succinct, (mostly-)readable and (semi-)natural way. Equivalent code in, say, the Lisps tends to be more verbose and more obfuscated in its intent because you spend a lot of time on the guts and the plumbing of managing and reasoning about relationships.

share|improve this answer
    
Thanks for the literature reference. :) –  2rs2ts Jun 16 '11 at 18:21

I took 2 Prolog modules at University and very much enjoyed developing in the language.

Its particularly good for expert systems, I wrote a medical symtom diagnosis one.

The way it was explained to me was that Lisp tends to be used more in certain countries and Prolog in the others.

In terms of which is best, I only covered Lisp briefly when I did lambda calculus in a Theoretical Computer Science module so I'm biased towards Prolog.

If you are developing an application to deal with rules and facts to derive answers Prolog is very good and naturally supports backtracking.

share|improve this answer
    
Thank you for the real world example! –  2rs2ts Jun 17 '11 at 0:02

The difference is a bit like using SQL for database queries rather than writing a program in, say, C. In SQL, you say what you want - but you don't (directly) have to specify the algorithm used to derive it.

A Prolog program is sometimes called a database, but it's really a set of predicate logic statements. The evaluation mechanism takes the query and performs substitutions on it based on the predicate logic statements, doing a search to find correct solutions. All the searching algorithms needed (much more involved than an SQL query) are built into the Prolog compiler.

A SQL query, if you were to implement the same logic naively in C, wouldn't need much more than looping and if/else conditionals.

A Prolog query, implemented in C, would need (at least) a backtracking search using the union-find technique. And that, again, is a naive solution.

A certain kind of AI programming involves a lot of the type of searching that Prolog does. Unsurprisingly, really - originally that AI programming was done in Lisp or some other language, but Prolog was written specifically to do the job.

Predicate logic is the natural approach to defining that style of AI problem and, in Prolog, once you have that definition you can run it directly, without having to implement all those awkward search algorithms.

share|improve this answer

I took an introduction to AI course in my undergrad that used Prolog to have us implement an expert system.

An expert system is a piece of software that is used to solve a very specific problem whose solution is dependent on a high number of rules and variables.

For instance, you could imagine an expert system that tells you whether you should take an umbrella with you when you go out or not; you would give it a set of data (whether it's cloudy, whether it rained the day before, what season it is, etc.) and the expert system would go through rules to give you an answer (if it is cloudy and it rained the day before, then you should take an umbrella).

Prolog's nature makes it very straightforward to implement rules and facts (in Prolog, everything is a rule or a fact), and then "query the database" (get an answer for your question), even when you have thousands of these rules and facts.

If you're interested in the topic, I'd recommend you install a Prolog interpreter and try to implement a very basic expert system to get a feel for it- it might help you understand why it's such a powerful tool for these tasks.

share|improve this answer
    
I read in my research that Prolog makes expert systems easy to implement. Thanks for backing that up with some explanation :) –  2rs2ts Jun 16 '11 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.