Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 of learning, but I have to wonder what class of real-world problems is best expressed and solved by such a language. Are there better languages? Does logic programming exist by another name in more trendy programming languages? Is the cynical version of the answer a variant of the Python Paradox?

like image 863
mbac32768 Avatar asked Oct 18 '08 23:10

mbac32768


People also ask

What can logic programming be used for?

Logic Programming is a method that computer scientists are using to try to allow machines to reason because it is useful for knowledge representation. In logic programming, logic is used to represent knowledge and inference is used to manipulate it.

What is the best logic programming language?

Really Prolog is the best way to go when doing logic programming because of all the support built in the language to do this kind of reasoning. In other languages you could do the same but it would take a while to implement a lot of the utilities needed for this kind of programming that Prolog alredy has inside of it.

What kind of logic is used in programming?

Much of computer programming logic is based on formal logic, specifically mathematical logic.


1 Answers

Prototyping.

Prolog is dynamic and has been for 50 years. The compiler is liberal, the syntax minimalist, and "doing stuff" is easy, fun and efficient. SWI-Prolog has a built-in tracer (debugger!), and even a graphical tracer. You can change the code on the fly, using make/0, you can dynamically load modules, add a few lines of code without leaving the interpreter, or edit the file you're currently running on the fly with edit(1). Do you think you've found a problem with the foobar/2 predicate?

?- edit(foobar). 

And as soon as you leave the editor, that thing is going to be re-compiled. Sure, Eclipse does the same thing for Java, but Java isn't exactly a prototyping language.

Apart from the pure prototyping stuff, Prolog is incredibly well suited for translating a piece of logic into code. So, automatic provers and that type of stuff can easily be written in Prolog.

The first Erlang interpreter was written in Prolog - and for a reason, since Prolog is very well suited for parsing, and encoding the logic you find in parse trees. In fact, Prolog comes with a built-in parser! No, not a library, it's in the syntax, namely DCGs.

Prolog is used a lot in NLP, particularly in syntax and computational semantics.

But, Prolog is underused and underappreciated. Unfortunately, it seems to bear an academic or "unusable for any real purpose" stigma. But it can be put to very good use in many real-world applications involving facts and the computation of relations between facts. It is not very well suited for number crunching, but CS is not only about number crunching.

like image 118
Aleksandar Dimitrov Avatar answered Sep 25 '22 12:09

Aleksandar Dimitrov