Cha2555 week2 knowledge representation logic and prolog
This presentation is the property of its rightful owner.
Sponsored Links
1 / 13

CHA2555 Week2: Knowledge Representation, Logic and Prolog PowerPoint PPT Presentation


  • 48 Views
  • Uploaded on
  • Presentation posted in: General

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 Presentation

CHA2555 Week2: Knowledge Representation, Logic and Prolog

An Image/Link below is provided (as is) to download presentation

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.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cha2555 week2 knowledge representation logic and prolog

CHA2555 Week2:Knowledge Representation,Logic and Prolog

Lee McCluskey

Email [email protected]

First term:

http://scom.hud.ac.uk/scomtlm/cha2555/


Introduction

Introduction

  • What is Knowledge Representation?

    • Does a book represent knowledge?

    • Does a database represent knowledge?

  • What are the requirements for representing knowledge?

    • Separation of behaviour and knowledge – implement ‘generic’ behaviours

    • Maintaining knowledge needs to be easy - add more knowledge and behaviour improves

  • Which ways are used to represent knowledge?

  • Why do we want to represent knowledge? Can we have AI without it?


Implementing ai behaviour

Implementing “AI” behaviour

AI

Implementation Languages

Symbolic Conceptualisation and/or Model

Including knowledge representation

Java

Prolog

“Semantic difference”

LISP

C

Haskell


Logics a popular form of knowledge representation

Logics – a popular form of knowledge representation

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.


Logics

Logics

There are logic families for representing/dealing with all kinds of human knowledge..

  • Time

  • Belief

  • Uncertainty / Fuzziness

  • Possibility and Certainty

  • Change

  • Action

    They all stem from Classical Logic!


Back to prolog

Back to Prolog…

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>.


Prolog structure

Prolog Structure

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)


To execute prolog programs

to execute Prolog programs

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


How prolog works

how Prolog works….

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.


How prolog works1

how Prolog works….

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….


Practicals exs from notes matching

Practicals Exs from Notes.. Matching

  • a. father(X,esau) with father(isaac,Z).

  • b. cost(X,Y,40) with cost(U,V,60).

  • c. sentence(X,predicate(Y,object(Z))) with

  • sentence(subject(bill),Predicate)

  • d. sentence(X,predicate(Z)) with

  • sentence(subject(bill),predicate(verb(hit),object(bill)))


Practicals exs from notes backtracking

Practicals Exs from Notes.. Backtracking

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.


Summary

Summary

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…


  • Login