Loading in 3 Seconds
CHA2555 Week2: Knowledge Representation, Logic and Prolog. Lee McCluskey Email [email protected] First term: http://scom.hud.ac.uk/scomtlm/cha2555/. Introduction. What is Knowledge Representation? Does a book represent knowledge? Does a database represent knowledge?
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
CHA2555 Week2:Knowledge Representation,Logic and Prolog
Lee McCluskey
Email [email protected]
First term:
http://scom.hud.ac.uk/scomtlm/cha2555/
AI
Implementation Languages
Symbolic Conceptualisation and/or Model
Including knowledge representation
Java
Prolog
“Semantic difference”
LISP
C
Haskell
All men are mortalEnglish
Socrates is a man
Therefore Socrates is mortal
Ax Man(x) => Mortal(x)First-Order Logic
Man(Socrates)
Therefore Mortal(Socrates)
mortal(X) :- man(X).Prolog
man(socrates).
?- mortal(socrates).
- Yes.
There are logic families for representing/dealing with all kinds of human knowledge..
They all stem from Classical Logic!
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
grandad(X,Y) :- father(X,Z),parent(Z,Y).
father(jacob,freda).
mother(freda,frank).
-- a Prolog program is a sequence of CLAUSES, each ending in ‘.’
-- each clause may be either a FACT or a RULE.
<fact> ::= <predicate>.
<predicate> ::= <predicate symbol>(<sequence of terms>)
<term> ::= <constant> | <variable> | <symbol>( < sequence of terms>)
<rule> ::= <predicate> :- <sequence of predicates>.
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
grandad(X,Y) :- father(X,Z),parent(Z,Y).
father(jacob,freda).
mother(freda,frank).
A rule contains a HEAD and RULE BODY separated by the ':-' symbol. Each head must be a predicate and each rule body is a sequence of predicates separated by commas
Rules can be read two ways: DECLARATIVELY or PROCEDURALLY.
** X is the grandad of Y is true if there exists a Z such that
X is the father of Z and Z is the parent of Y. (declarative)
** To prove X is the grandad of Y, first prove X is the father
of some Z, then prove this Z is the parent of Y. (procedural)
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
grandad(X,Y) :- father(X,Z),parent(Z,Y).
father(jacob,freda).
mother(freda,frank).
To execute/activate/run a program a GOAL is typed to the Prolog interpreter. It responds with no (failure) or yes (success) together with the successful instantiations of variables that appeared in the goal.
?- grandad(jacob,frank).
-yes
?- grandad(X,frank).
X = jacob
-yes
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
grandad(X,Y) :- father(X,Z),parent(Z,Y).
father(jacob,freda).
mother(freda,frank).
To solve a goal such as:
?-grandad(jacob,frank).
Prolog tries to MATCH this goal with facts and rule heads in the program, starting from the top and working down - search.
-- constants/predicate symbols must match with constants/predicate symbols
-- variables can match with any term
When a variable MATCHES with a term we say it is instantiated.
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
grandad(X,Y) :- father(X,Z),parent(Z,Y).
father(jacob,freda).
mother(freda,frank).
To solve a goal such as:
?-grandad(jacob,frank).
When a rule head is matched, matching variables become instantiated throughout the rule, and the TAIL of the rule is executed as if it were a GOAL.
So Prolog executes ‘father(jacob,Z),parent(Z,frank)’ next….
furry(tabby). furry(leo). small(tabby).
has_whiskers(leo). has_big_teeth(leo). has_whiskers(tabby).
cat(X) :- has_whiskers(X), furry(X).
timid(X) :- cat(X), small(X).
If the query '?-timid(X)' was typed, the second rule's first
predicate 'cat(X)' would succeed with X = leo; this, however,
would cause the second predicate to fail and control would
backtrack to 'cat(X)'.
The last successful match is then failed: this is the
match of furry(leo) of the 'cat' rule with the identical fact in
the database. furry(leo) fails completely since it can find no
alternative match; consequently backtracking takes place in the
'cat' rule which eventually results in a success with X = tabby.
The predicate 'small(X)' with this binding then succeeds.
Knowledge Representation – encoding knowledge so that it can be updated and used by reasoning processes
Prolog – Matching and Backtracking
Practical: Continue with the online exercises. Make sure you understand Prolog’s procedural method (up to the end of section 2)
Advance to section 3 and beyond…