Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Who's a thief?

by Ovid (Cardinal)
on Jul 01, 2002 at 14:43 UTC ( [id://178571]=note: print w/replies, xml ) Need Help??


in reply to Artificial Intelligence Programming in Perl

cjf asked, in regards to why not much OO seems to be done in Perl:

Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy? Is it because Perl's considered 'just a scripting language' and not meant for serious projects?

Not every problem is approached the same way. If you have a system where the data rapidly changes, object-oriented programming is often a good choice. However, if the data is relatively static but the functionality rapidly changes, then you might find a straight-forward procedural design better than an object-oriented one.

That is to say, not every problem should be approached the same way and just as we acknowledge that Perl is not a great tool for programming device drivers, it's also not the most optimal tool for artificial intelligence. Because AI often involves creating a lot of rules, searching through those rules, backtracking through them (the bane of regexen, remember?), it tends to require a fast programming language to drive it. Consider the little snippet I wrote about thieves. Rather than make you rush off to another link, I'll reproduce it here.


Imagine that I want to know what a given person might steal. I might assume that they will steal stuff given the following conditions:

  • That person is a thief.
  • The stuff is valuable.
  • The stuff is owned by someone (how do you steal something if it's not owned by anyone?).
  • And the person doesn't know the person who owns the stuff they might steal.

If I were programming in Prolog, I might have the following program:

steals(PERP, STUFF) :- thief(PERP), valuable(STUFF), owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). thief(badguy). valuable(gold). valuable(rubies). owns(merlyn,gold). owns(ovid,rubies). knows(badguy,merlyn).

It's fairly easy to read, once you know Prolog. :- is read as "if" and a comma is read as "and" (if outside of parentheses).

I can then ask what a given person might steal:


?- steals(badguy,X).

X = gold

Yes
?- steals(merlyn,X).

No

Now, try to program that in Perl. I've seen Prolog::Alpha, but it needs quite a bit of work, and apparently there is a Language::Prolog::Interpreter, which I know nothing about and couldn't seem to download. Just glancing through their code bases, however, lets you know that this requires a lot of work.

Rather than trying to copy another language, though, how would you write the above program in Perl? Then, just to ensure that you have an extensible solution, try adding a rule the the thief will only steal stuff if he or she knows the stuff exists in a city at least 50 miles from where the thief lives. That's not hard in Prolog.

My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Who's a thief?
by jeorgen (Pilgrim) on Jul 02, 2002 at 11:30 UTC
    Ovid says:

    My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.

    Backtracking is an important feature of languages like Prolog and CLIPS. There is also a text-processing language called Icon that uses something called generators.

    I wonder if perl's pattern matching could be put to use for AI purposes?

    /jeorgen

      My goodness. It's a common enough occurance for someone to point to a Perl regexp and say something like "EEEeeeewww!!!". I don't want to imagine what people will say once they see the regexps used to implement backtracking in AI.

      Paul Fenwick
      Perl Training Australia

        Actually, the only natural backtracking mechanism found in Perl is in regular expressions. Backtracking is what I use to determine primeness of numbers using regular expressions, it's what's used in the Cookbook when regular expressions are used to solve Diophantine equations, and its used in my reduction of 3-CNF-SAT to regular expressions http://perl.plover.com/NPC/NPC-3SAT.html.

        Abigail

Re: Who's a thief?
by jarich (Curate) on Jul 05, 2002 at 11:01 UTC
    Sorry Ovid, but badguy CAN'T steal the gold. It's not possible with your rule set:
    steals(PERP, STUFF) :- .... owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). knows(badguy,merlyn). owns(merlyn,gold).
    or in English:
    * And the person doesn't know the person who owns the stuff they might steal.

    On the other hand the badguy can steal your rubies:

    ?- steals(badguy,X). X = rubies Yes
    and so can merlyn but only if we're allowed to add one more fact:
    thief(merlyn). ?- steals(merlyn,X). Yes
    I think you might want to meet merlyn really fast, and maybe get him to introduce you to badguy. :)

    jarich

    Update: Oops. Forgot that the PERP had to be a thief in order to be able to steal. Which would have meant that merlyn couldn't have stolen the rubies and I would have appeared to not have known what I was talking about. :) I've fixed this now of course.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://178571]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-03-19 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found