|
|||
AI::PrologCurtis "Ovid" PoePresented by
|
|||
|
|
|||
What is Prolog?continued... |
|||
|
|
|||
What is Prolog?
Not a "Professional Logger"continued... |
|||
|
|
|||
What is Prolog?
Not a "Professional Logger"Quoting Ovid:
continued... |
|||
|
|
|||
What is Prolog?
Not a "Professional Logger"Quoting Ovid:
From Wikipedia:
|
|||
|
|
|||
What does Prolog do?Prolog:
|
|||
|
|
|||
Prolog ExampleFamily 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.
|
|||
|
|
|||
FactsRelation Applies To% Facts % predicate(term, ...) % atoms are lowercase or quoted continued... |
|||
|
|
|||
FactsRelation Applies To% Facts % predicate(term, ...) % atoms are lowercase or quoted % tom is male ( male/1 ) male(tom). continued... |
|||
|
|
|||
FactsRelation 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... |
|||
|
|
|||
FactsRelation 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). |
|||
|
|
|||
RulesIf and only If% Rules % predicate(...) :- predicate(...), .... % AND is comma % OR is semi-colon or multiple rules continued... |
|||
|
|
|||
RulesIf 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... |
|||
|
|
|||
RulesIf 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). |
|||
|
|
|||
QueriesWhat can be proved?
% Queries
% interactive prompt ?-
% verify a fact
?- father(tom, erica).
yes.
continued... |
|||
|
|
|||
QueriesWhat can be proved?
% Queries
% interactive prompt ?-
% verify a fact
?- father(tom, erica).
yes.
% fill in the blanks
?- father(X,tom)
mike.
continued... |
|||
|
|
|||
QueriesWhat 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.
|
|||
|
|
|||
Using AI::Prolog
use AI::Prolog;
use Data::Dumper;
continued... |
|||
|
|
|||
Using AI::Prolog
use AI::Prolog;
use Data::Dumper;
my $program_string = <<'END_PROLOG';
continued... |
|||
|
|
|||
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... |
|||
|
|
|||
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... |
|||
|
|
|||
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... |
|||
|
|
|||
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... |
|||
|
|
|||
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... |
|||
|
|
|||
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... |
|||
|
|
|||
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' ];
|
|||
|
|
|||
Info and Resources!!! Alpha Release !!!
AI::Prolog on CPAN:Roman Barták's online programming guide:Adventure in PrologWikipedia: |
|||
|