AI::Prolog

# 1

AI::Prolog

Curtis "Ovid" Poe

Presented by

  • Shaun Griffith

  • Toronto Perl Mongers

  • September 29, 2005

TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 2

What is Prolog?


continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 2

What is Prolog?

Not a "Professional Logger"


continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 2

What is Prolog?

Not a "Professional Logger"

Quoting Ovid:

  • In Perl, we traditionally tell the language how to find a solution.

  • In Prolog, we describe what a solution would look like and let the language find it for us.


continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 2

What is Prolog?

Not a "Professional Logger"

Quoting Ovid:

  • In Perl, we traditionally tell the language how to find a solution.

  • In Prolog, we describe what a solution would look like and let the language find it for us.

From Wikipedia:

  • From the French programmation en logique

  • A Logic Programming language created in 1972

  • Predicate calculus (first order)

  • Declarative programming style

TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 3

What does Prolog do?

Prolog:

  • Looks good in Flannel

  • Understands facts, rules, and queries.

  • Solves logic puzzles

    • Three men, Mr. Smith, Jones, and Wilson, each had one of three...

    • Su Doku

  • Proves theorems

  • Plays Adventure

TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 4

Prolog Example

Family Tree (Stumps)

   % Facts
   male(tom).
   father(tom, sally).
   father(tom, erica).
   father(mike, tom).

   % Rules
   father(X,Y)  :- parent(X,Y), male(X).
   parent(X,Y)  :- father(X,Y).

   % Interactive Queries
   ?- parent(tom, sally)
        yes.
   ?- father(X,tom)
        mike.
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 5

Facts

Relation Applies To

   % Facts
   %     predicate(term, ...)
   %     atoms are lowercase or quoted

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 5

Facts

Relation Applies To

   % Facts
   %     predicate(term, ...)
   %     atoms are lowercase or quoted
   % tom is male  ( male/1 )
   male(tom).

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 5

Facts

Relation Applies To

   % Facts
   %     predicate(term, ...)
   %     atoms are lowercase or quoted
   % tom is male  ( male/1 )
   male(tom).
   % tom is the father of sally ( father/2 )
   father(tom, sally).

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 5

Facts

Relation Applies To

   % Facts
   %     predicate(term, ...)
   %     atoms are lowercase or quoted
   % tom is male  ( male/1 )
   male(tom).
   % tom is the father of sally ( father/2 )
   father(tom, sally).
   father(tom, erica).
   father(mike, tom).
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 6

Rules

If and only If

   % Rules
   %    predicate(...) :- predicate(...), ....
   %    AND is comma
   %    OR is semi-colon or multiple rules

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 6

Rules

If and only If

   % Rules
   %    predicate(...) :- predicate(...), ....
   %    AND is comma
   %    OR is semi-colon or multiple rules
   % a father is a male AND a parent
   father(X,Y) :- parent(X,Y), male(X).

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 6

Rules

If and only If

   % Rules
   %    predicate(...) :- predicate(...), ....
   %    AND is comma
   %    OR is semi-colon or multiple rules
   % a father is a male AND a parent
   father(X,Y) :- parent(X,Y), male(X).
   % a parent is a father OR mother
   parent(X,Y)  :- father(X,Y).
   parent(X,Y)  :- mother(X,Y).
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 7

Queries

What can be proved?

    % Queries
    %    interactive prompt ?-
    %    verify a fact
    ?- father(tom, erica).

         yes.

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 7

Queries

What can be proved?

    % Queries
    %    interactive prompt ?-
    %    verify a fact
    ?- father(tom, erica).

         yes.
    %    fill in the blanks
    ?- father(X,tom)

         mike.

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 7

Queries

What can be proved?

    % Queries
    %    interactive prompt ?-
    %    verify a fact
    ?- father(tom, erica).

         yes.
    %    fill in the blanks
    ?- father(X,tom)

         mike.
    ?- mother(tom,X)

         no.
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).
    END_PROLOG

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).
    END_PROLOG
    my $prolog = AI::Prolog->new($program_string);

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).
    END_PROLOG
    my $prolog = AI::Prolog->new($program_string);
    $prolog->query("father(X,tom).");

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).
    END_PROLOG
    my $prolog = AI::Prolog->new($program_string);
    $prolog->query("father(X,tom).");
    while (my $result = $prolog->results())
    {  print Dumper $result; }

continued...
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 8

Using AI::Prolog

    use AI::Prolog;
    use Data::Dumper; 
    my $program_string = <<'END_PROLOG';
       % Facts
       male(tom).
       father(tom, sally).
       father(tom, erica).
       father(mike, tom).
       % Rules
       father(X,Y)  :- parent(X,Y), male(X).
       parent(X,Y)  :- father(X,Y).
    END_PROLOG
    my $prolog = AI::Prolog->new($program_string);
    $prolog->query("father(X,tom).");
    while (my $result = $prolog->results())
    {  print Dumper $result; }
    $VAR1 = [ 'father', 'mike', 'tom' ];
TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AI::Prolog

# 9

Info and Resources

!!! Alpha Release !!!

  • Implementation based on W-Prolog, by Dr. Michael Winikoff.

  • Some features stolen from X-Prolog.

AI::Prolog on CPAN:

Roman Barták's online programming guide:

Adventure in Prolog

Wikipedia:

TPM Lightning Talks 2005

Previous | Index | Next

Copyright Shaun Griffith © 2005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table of Contents

1. AI::Prolog - Curtis "Ovid" Poe
2. What is Prolog?
3. What does Prolog do?
4. Prolog Example
5. Facts
6. Rules
7. Queries
8. Using AI::Prolog
9. Info and Resources - !!! Alpha Release !!!