The n00b

posted in Journal #259850
Published November 27, 2005
Advertisement
Learning an entirely new programming paradigm is surely an extremely refreshing experience. I've been having lots of Prolog fun today.

We've already established that I'm an established slacker. Out of the 17 or so AI lectures we've taken so far, I've only attended the first [lol]. I'm much better when it comes to classes, though, where we actually learn something, so I've attended like 4 out of 6.

Also, I usually only "study" for university 4 times a year: before the midterms and before the finals. Given that the AI mid-term is next Sunday, I had to see what all the fuss is about, so I started reading our course notes and exploring Prolog. And man, what an enjoyable paradigm and language. It's really enlightening to explore problem solving from an entirely different perspective - I encourage you to try it out if you hadn't already.

Given the following very simple rule, "You talk about someone either if you know him or you know someone who talks about him", the exercise asks you to create a prolog representation of it for the following And/Or tree:



So I quickly came up with this:
knows(bill, jane).knows(jane, pat).knows(jane, fred).knows(fred, bill).talks_about_r(X,Y):- knows(X,Y).talks_about_r(X,Y):- knows(X,Z), talks_about_r(Z,Y).


It recursed infinitely whenever I queried it with:
?- talks_about_r(X,Y).

Given how inexperienced I am, I couldn't figure out why except by running and tracing it. Can you?
Think about it...

...

Gave up?

Here's a sample run:
X = billY = jane ;X = janeY = pat ;X = janeY = fred ;X = fredY = bill ;X = billY = pat ;X = billY = fred ;X = billY = bill ;X = billY = jane ;X = billY = pat ;X = billY = fred ;X = billY = bill ;X = billY = jane ;X = billY = pat ;X = billY = fred ;X = billY = bill ;X = billY = jane ;X = billY = pat ;X = billY = fred ;X = billY = bill ;X = billY = jane ;X = billY = pat ;X = billY = fred ;X = billY = bill ;X = billY = jane ;


Even after taking a look at the above run, I couldn't find out what's going exactly. The derivation tree revealed what's going on:



You can see that the last derived node takes us to "talks_about(bill, Y)", which is going to be broken into 2 branches: "knows(bill, Y)" and "knows(bill, Y), talks_about_r(bill, Y)". Given that bill knows jane, the right branch takes us back to the point: "knows(bill, jane), talks_about_r(jane, Y)" and so on and on and on...[lol]

You can imagine that for a nublet like myself this thingy took quite some time to discover [grin]. I haven't really thought of a simple and elegant solution to prevent this yet, because I'm done for today - perhaps tomorrow. Until then, feel free to tell me your solution if you happen to know one.

So now I've added the 2nd thing to the list of things that bring me back to n00ber zone: Prolog (The first being leetox, of course).

Muhammad out.
Previous Entry OS Development #1
0 likes 3 comments

Comments

jollyjeffers
Still undecided on journal title then? Journal Prisoner #259850

Quote:Learning an entirely new programming paradigm is surely an extremely refreshing experience.
Definitely agreed. I really liked learning Haskell a few years ago. Teaches you to look at similar problems in a different way. Definitely must be one of the more compact quicksort implementations ever!

I've also just finished a course covering Lambda Calculus - not really any good for applied programming, but it's one of best ways to explore what programming really means. It's beautiful to see how you can put all the constructs together to show properties of pretty much every language currently used. By showing those properties you can also explore why certain languages behave the way that they do.

Anyway, regarding Prolog, doesn't it's definitions of functions implicitly define an inverse? I've never studied it, but a friend of mine did a couple of years ago - and explained that it can be a real pain to work with because you can feed answers into a function in order to get the parameters back out. Something thats a bit unintuitive in C++/Java [lol]

Jack
November 27, 2005 05:25 PM
ukdeveloper
We had a "Guest Lecture" on AI from a new member of our Computer Science department. The guy's apparently a world AI expert, a guy called Rens Bod if you've heard of him.

Basically everything he said went straight over my head. Probably because I was also hung over, but it was complicated stuff anyway.
November 28, 2005 05:45 PM
Muhammad Haggag
Quote:Still undecided on journal title then? Journal Prisoner #259850

Actually, I think I'll settle down for the current one. It's the perfect title I've been looking for.

Quote:Definitely agreed. I really liked learning Haskell a few years ago. Teaches you to look at similar problems in a different way. Definitely must be one of the more compact quicksort implementations ever!

Yeah, I plan to take a stab at a functional language sometime next year. Probably will be O'Caml.

Quote:I've also just finished a course covering Lambda Calculus - not really any good for applied programming, but it's one of best ways to explore what programming really means. It's beautiful to see how you can put all the constructs together to show properties of pretty much every language currently used. By showing those properties you can also explore why certain languages behave the way that they do.

I've never studied or read about Lambda Calculus in detail - I'll check the wiki link for now, thanks.

Quote:Anyway, regarding Prolog, doesn't it's definitions of functions implicitly define an inverse? I've never studied it, but a friend of mine did a couple of years ago - and explained that it can be a real pain to work with because you can feed answers into a function in order to get the parameters back out. Something thats a bit unintuitive in C++/Java

Well, yes, but that's very elegant IMO, once you get the hang of it. You don't have return values or anything, everything's a predicate that is either true or false. So you do all your input/output with parameters. For example:

dog(rocky).
cat(whatever).

person(jack).
person(jenny).

has_dog(jack, rocky).
has_cat(jenny, whatever).

has_pet(X, Y):- person(X), has_dog(X, Y).
has_pet(X, Y):- person(X), has_cat(X, Y).


A query like:
?- has_pet(X, Y).
Gives you back X = jack, Y = rocky and X = jenny, Y = whatever.

A query like:
?- has_pet(jack, Y).
Where we provided part of the answer, gets us back Y = rocky.

Quote:We had a "Guest Lecture" on AI from a new member of our Computer Science department. The guy's apparently a world AI expert, a guy called Rens Bod if you've heard of him.

Haven't heard of them, but a google turned this up Rens Bod. Looks to have lots of research in natural language processing, which is indeed a complex subject.

Quote:Basically everything he said went straight over my head. Probably because I was also hung over, but it was complicated stuff anyway.

Must've been an enjoyable lecture, then [lol].
November 28, 2005 10:46 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Opera 9 w000000t

1288 views

Damn

1176 views

VBE fun, #2

1284 views

VBE fun

1326 views

French, #1

1411 views

Mult-tasking

1172 views

DirectInput hooking

1057 views

MDX overlay sample

1326 views
Advertisement