Live data from Hacker News

The Power of Prolog

metalevel.at

121–130 of 164 posts

Re: The Power of Prolog

#121
For an introduction to Prolog:

Learn Prolog Now - Free Online Version http://www.learnprolognow.org/lpnpage.php?pageid=online

I like this one because it's beginner-friendly (and uses characters from Pulp Fiction as examples).

-- edit: actually, The Power of Prolog to is great, too! If anyone knows more good resources, I'd be happy to hear about them!

Re: The Power of Prolog

#122
post #4

Never understood why natural numbers (or some set of N) is not in the search space: fib(X,X):- X fib(X,Y1+Y2):- fib(X-1,Y1),fib(X-2,Y2). I tried to get answer to this kwestion in reddit, but all I got was personal insults.

> fib(X,Y1+Y2):- fib(X-1,Y1),fib(X-2,Y2).

As others have noted, it's possible to write nicely behaved Prolog versions of this that you can use in various ways: call "fib(3, N)" to find the third Fibonacci number, "fib(3, 6)" to see if the third Fibonacci number is 6, or "fib(I, 6)" to find if 6 is the I-th Fibonacci number for some I.

But these solutions use slightly more verbose syntax that makes the evaluation of arithmetic expressions explicit. As for the question why this is the case and why Prolog doesn't support this natively, it's because the Prolog system would have to know (a) which terms represent arithmetic expressions and (b) at what time all the variables in those terms will be instantiated.

For (a) you need a static type system, which is a well-known concept, and for (b) something called a "mode system", which is something more or less specific to logic and constraint languages. The mode system tells you when certain variables will be bound to values. Consider the example "fib(3, N)", where X is bound, which allows you to compute "X-1" and "X-2", from which you can compute Y1 and Y2, and from these finally "Y1+Y2", i.e., N. For the call "fib(I, 6)" the whole computation is in reverse: From "6 = Y1+Y2" you would need to derive values for Y1 and Y2 (this already involves a search), from which you can derive values that allow you to find values that should be equal, respectively, to "X-1" and "X-2", and from that you might deduce a value for X. This is a completely different computation. It's doable, but you would need to know data types (which in general you don't, in Prolog), predicate modes (which again you don't), and you would need to use separate computations for each mode.

There is a functional/logic language called Mercury, which is a superset of a restricted subset of Prolog, which has static types and modes (using user annotations) and compiles separate versions of each predicate for each mode, and in which something more like what you want is already possible. (If I understand correctly, even in Mercury this example wouldn't work, because it only allows you to unify 6 with "Y1+Y2" if at least one of those variables is known.)

Re: The Power of Prolog

#123
One of my professors in college was an original creator of the Prolog language. He made us learn Prolog so that he could teach us something we could have just as easily done in C or Java. I strongly disliked him. For that reason, I am filled with negative vibes when I think about Prolog.

Re: The Power of Prolog

#124

Earlier quoted context omitted.

This is a frustration of mine. At university they try to install a knowledge of all kinds of crazy languages, before you're ready to appreciate their value and the issues they attempt to address. The most glaring example is probably teaching Haskell in first-year. As a working programmer, you're then corralled into following prescriptive industry-practice - that always errs on the side of dumbing down the choice of t…

You're being asked to be a consultant, you know. They want to pretend that if you rewrite Prolog in C#, it'll be simpler, and that the average C# programmer (the cheapest one they can hire) will simply understand (badly written) logic programming solvers and be able to modify them. Eventually you'll figure out to simply double your hourly rate and ask "do you want a bad Haskell implementation to go with that as well…

I don't know, sounds like it would be pretty confusing giving so many people the same referral code.

Re: The Power of Prolog

#125

Earlier quoted context omitted.

SQL gives you all the solutions to query by default unless you limit them right? A relation (table) in SQL is conceptually a predicate that holds for all tuples (rows) therein. You can AND the predicates with "NATURAL JOIN". You can OR them with "UNION" e.g. this example https://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpa... becomes something like this in SQL. example=# select * from red; item --------- appl…

This is all true, but only for the small subset of Prolog that happens to be introduced on that web page. This analogy breaks down as soon as you have more complex data, not just atoms, or as soon as you introduce recursive rules. Prolog tutorials really do Prolog a disservice by introducing it as a database query language, which is then misunderstood (or misremembered) by many as "it's only a database query language…

SQL can do recursive rules too. SQL tutorials often do SQL a disservice by introducing it as a database query language rather than relational algebra :)

  example=# select * from move;
    place  | method | newplace 
  ---------+--------+----------
   home    | taxi   | halifax
   halifax | train  | gatwick
   gatwick | plane  | rome
  (3 rows)
  
  example=# create view on_route as with recursive on_route(place, newplace, length, path) as (select place, newplace, 1 as length, place as path FROM move UNION select on_route.place, move.newplace, on_route.length + 1, path || '->' || move.place as path FROM move JOIN on_route ON on_route.newplace = move.place) SELECT place, newplace, length, path || '->' || newplace as path FROM on_route;
  CREATE VIEW
  example=# select distinct true from on_route WHERE place = 'home' and newplace = 'rome';
   bool 
  ------
   t
  (1 row)
  
  example=# select path from on_route WHERE place = 'home' and newplace = 'rome';
               path             
  ------------------------------
   home->halifax->gatwick->rome

Re: The Power of Prolog

#127
post #111
post #107

Earlier quoted context omitted.

Those collections have to be implemented by someone. You seem to be assuming that these collections spring fully formed into the world and are black boxes without an implementation.

I think you are willingly missing my point, because I believe it is obvious that I am not making that assumption.

Looking at the other responses to your comment, clearly it is not obvious that you're not making that assumption.

If that's not what you were trying to say, then I still don't understand what you were trying to say.

Re: The Power of Prolog

#129
post #116
post #83

Earlier quoted context omitted.

Prolog was part of course that I'd taken during my Masters. I loved it then. I would love to take a closer look when I have time ... whenever that happens ... Interestingly, IBM Watson uses Prolog. [1] [1] https://www.cs.nmsu.edu/ALP/2011/03/natural-language-process...

IBM uses a special version of Prolog with a different syntax and database access functionality. They hired a department of a university. MS Windows (network code) contains a Prolog with C-style-syntax.

Thanks. Do you know of any other resources describing Watson's inner workings? ...cause just googling for it leads to one of the zillions of marketing bullshit pages or whitepapers devoid of any real infos that IBM's marketing drones have flooded the web with.

Re: The Power of Prolog

#130
I implemented the Wumpus World form Peter Norvig's AIMA using different techniques. I found that Bayesian Logic was much more powerful than Logic programming. Perhaps that explains why Prolog has flourished.

Logic programming is limited to values of true or false. 0 or 1. Bayesian logic can deal with uncertainty values like .2 or .3. It almost seems like a superset. It is also more intuitive IMHO.

I keep the wumpus implementation here if anyone is interested. https://github.com/huherto/aima3/tree/master/src/wumpus

Post reply on HN