COS 333: Chapter 16, Part 2

Willem van Heerden
10 Sept 202050:50

Summary

TLDRThis lecture delves into the foundations of Prolog, a logic programming language developed in the 1970s for applications in natural language processing and automated theorem proving. It covers the basic elements of Prolog, including terms, fact, rule, and goal statements, and discusses the inferencing process, highlighting its distinction from first-order predicate calculus. The lecture also touches on Prolog's development, its two main dialects, and provides insights into its programming constructs, illustrating how facts and rules are used to prove goals, and introducing the concepts of resolution, backtracking, and the tracing model for debugging.

Takeaways

  • πŸ“œ The lecture covers Prolog, its origins, basic elements, and inferencing process.
  • πŸ›οΈ Prolog was developed in the 1970s-1980s by the University of Aix-Marseille in France and the University of Edinburgh in Scotland.
  • πŸ” Prolog is used for natural language processing and automated theorem proving.
  • πŸ”§ Prolog programs are built from terms, which can be constants, variables, or structures.
  • πŸ“š Fact statements in Prolog represent basic ground truths, using structures to express hypotheses.
  • πŸ“ Rule statements express theorems and consist of an antecedent and a consequent.
  • ❓ Goal statements, or queries, are used for theorem proving, asking Prolog to prove the truth of propositions.
  • πŸ”„ Prolog uses top-down resolution (backward chaining) to match goals to facts.
  • 🌐 Multiple sub-goals are proved using depth-first search, and Prolog handles backtracking if a sub-goal fails.
  • πŸ” Prolog's tracing model helps debug programs, showing events like call, exit, redo, and fail.

Q & A

  • What are the main topics covered in the second lecture on logic programming languages?

    -The second lecture primarily focuses on Prolog, starting with its origins, moving on to basic elements like terms, facts, rules, and goals, and finally discussing how Prolog handles the inferencing process differently from theorem proving in first-order predicate calculus.

  • Which two universities were initially involved in the development of Prolog?

    -The development of Prolog began as a collaboration between the University of Marseille in France and the University of Edinburgh in Scotland.

  • What were the main interests of the University of Marseille and Robert Kowalski in the development of Prolog?

    -The University of Marseille aimed to use Prolog for natural language processing, while Robert Kowalski from the University of Edinburgh was interested in using it for automated theorem proving.

  • What are the three main kinds of terms in Prolog programming language?

    -The three main kinds of terms in Prolog are constants (which can be atoms or integers), variables, and structures.

  • How are atoms named in Prolog and what are the conventions for naming them?

    -Atoms in Prolog can be named using a string of letters, digits, and underscores beginning with a lowercase letter, or using any sequence of printable ASCII characters including spaces, as long as they are enclosed in single quotes. However, the first approach is standardized for better readability.

  • What is a variable in Prolog and how is it named?

    -A variable in Prolog is a term that can be instantiated with a value during the resolution process. It is named as a string of letters, digits, and underscores but must always start with an uppercase letter.

  • What is a fact statement in Prolog and how is it represented?

    -A fact statement in Prolog is an atomic proposition used to express a hypothesis or a basic ground truth. It is represented using Prolog structures as headless Horn clauses, starting with a functor followed by a pair of parentheses containing parameters.

  • What is the syntactic form of rule statements in Prolog and how do they differ from fact statements?

    -Rule statements in Prolog are represented by headed Horn clauses, consisting of an antecedent (the 'if' part) and a consequent (the 'then' part), separated by a colon and dash, indicating an implication. They differ from fact statements in that they include a rule for deriving new facts from existing ones.

  • How does Prolog handle the inferencing process when attempting to prove the truth of a proposition?

    -Prolog uses top-down resolution or backward chaining for its inferencing process. It starts with the goal and attempts to find a sequence of matches using rules that lead to facts, which are then used to prove the goal.

  • What are the two general approaches for proving multiple sub-goals in Prolog and which one does Prolog use?

    -The two general approaches for proving multiple sub-goals are breadth-first search and depth-first search. Prolog uses the depth-first search approach due to its lower computational load.

  • What is backtracking in Prolog and when does it occur?

    -Backtracking in Prolog occurs when the inferencing process fails to prove one of the sub-goals after proving a previous sub-goal. It involves moving back to the last successfully proved sub-goal and finding a different solution that could potentially satisfy the failed sub-goal.

  • What is the purpose of the trace structure in Prolog and what are the four events it provides?

    -The trace structure in Prolog is used for debugging Prolog programs by providing insight into the steps performed during the inferencing process. The four events it provides are call (beginning of an attempt to satisfy a goal), exit (goal has been satisfied), redo (backtracking occurs), and fail (goal fails).

Outlines

00:00

πŸ“š Introduction to Prolog Programming Language

This segment introduces the second lecture on logic programming languages, specifically focusing on Prolog. It outlines the lecture's agenda, including the origins of Prolog, its development in the 1970s by the University of Marseille and the University of Edinburgh, and its applications in natural language processing and automated theorem proving. The lecture will cover basic elements of Prolog, such as terms, facts, rules, goals, and the inferencing process, contrasting it with theorem proving in first-order predicate calculus.

05:01

πŸ” Understanding Prolog's Basic Elements: Terms and Statements

This paragraph delves into the fundamental components of Prolog programs, starting with terms which can be constants, variables, or structures. Constants include atoms and integers, with atoms being symbolic values. Variables are distinguishable by starting with an uppercase letter, and structures represent atomic propositions. The paragraph also explains Prolog's three types of statements: fact statements representing basic truths, rule statements expressing theorems, and goal statements used in theorem proving.

10:02

πŸ“œ The Syntax and Semantics of Prolog Statements

The third paragraph discusses the syntax of Prolog statements, emphasizing how fact statements are represented using functors and parameters. It also explains rule statements, which are akin to implications with an antecedent and a consequent, and how they are read. The paragraph highlights the importance of the structure of these statements in expressing relationships and properties within Prolog programs.

15:06

πŸ”„ Prolog's Rule Statements and Generalization

This section further explores rule statements in Prolog, differentiating between specific and general rules. It illustrates how general rules use variables to relate to universal objects, whereas specific rules relate to particular objects. The paragraph also explains how Prolog handles logical 'or' statements by creating separate rules for each condition, showcasing examples of rules that define parent and grandparent relationships.

20:07

🎯 Prolog's Goal Statements and Query Mechanism

The focus shifts to goal statements, or queries, in Prolog, which are used to prove the truth of propositions. The paragraph explains how Prolog's inferencing engine works behind the scenes to prove goals and how users can interact with the Prolog interpreter in query mode. It also demonstrates how to structure queries with examples and discusses the use of variables and conjunctive propositions within goals.

25:08

πŸ”„ Prolog's Inferencing Process and Resolution

This segment explains the inferencing process in Prolog, detailing how Prolog attempts to prove the truth of goals using facts and rules. It contrasts two general approaches to the matching process: bottom-up resolution (forward chaining) and top-down resolution (backward chaining). The paragraph highlights Prolog's use of top-down resolution to focus the search for relevant facts and rules to prove a goal.

30:10

🌐 Prolog's Inferencing with Multiple Sub-Goals

The sixth paragraph addresses how Prolog handles queries with multiple sub-goals, discussing breadth-first and depth-first search strategies. It emphasizes Prolog's use of depth-first search due to its lower computational load. The paragraph also introduces the concept of backtracking, which occurs when Prolog fails to prove a sub-goal and must revert to a previous sub-goal to find an alternative solution.

35:12

πŸ” Prolog's Backtracking and Tracing Model

This section delves into the backtracking process in Prolog with an example, illustrating how Prolog attempts to prove sub-goals and reverts to previous steps when a sub-goal cannot be proven. It also explains the tracing model in Prolog, which is used for debugging and provides insight into the inferencing process through events like call, exit, redo, and fail.

40:14

πŸ“ Example of Prolog's Tracing Model in Action

The eighth paragraph provides a practical example of the tracing model, showing how Prolog attempts to satisfy sub-goals using facts about likes and dislikes. It demonstrates the steps Prolog takes to match facts with sub-goals, the instantiation of variables, and the use of the trace structure to visualize the inferencing process, including the points at which Prolog exits, fails, and backtracks.

45:16

πŸš€ Conclusion and Preview of Upcoming Lectures

The final paragraph concludes the current lecture and previews the next one, where the remaining elements of Prolog programs will be discussed, including basic arithmetic and lists. It also mentions the exploration of Prolog's deficiencies and practical applications, setting the stage for a deeper understanding of the language's capabilities and limitations.

Mindmap

Keywords

πŸ’‘Prolog

Prolog is a logic programming language primarily associated with artificial intelligence. It is known for its ability to handle complex queries and symbolic processing. In the video, Prolog is the central theme, with its origins, syntax, and inferencing process being discussed extensively. For example, the script mentions the development of Prolog at the University of Ex Marseille and the University of Edinburgh, highlighting its applications in natural language processing and automated theorem proving.

πŸ’‘Inferencing Process

The inferencing process in Prolog is the mechanism by which the language deduces new facts from existing ones. It is central to how Prolog operates, using a top-down resolution or backward chaining approach. The script explains this process in detail, contrasting it with the theorem proving in first-order predicate calculus and illustrating it with examples such as determining if 'bob' is a 'man' based on the given facts and rules.

πŸ’‘Fact Statement

A fact statement in Prolog represents a basic truth or axiom within the program. It is a type of statement that uses Prolog structures to express hypotheses. The script provides several examples of fact statements, such as 'female(shelly).' or 'father(bill, jake).', which serve as the foundational knowledge for the inferencing process.

πŸ’‘Rule Statement

Rule statements in Prolog are used to express theorems and derive new facts from existing ones. They are represented by headed horn clauses and consist of an antecedent (the 'if' part) and a consequent (the 'then' part). The script discusses how these rules are used to express relationships, such as 'parent(x, y)' being defined by 'mother(x, y)' or 'father(x, y)'.

πŸ’‘Goal Statement

A goal statement, often referred to as a query in Prolog, is used in theorem proving. It is a proposition presented to Prolog, which the interpreter then attempts to prove true. The script explains how goal statements are used in query mode, such as asking Prolog to prove that 'fred' is 'male', and how the interpreter responds based on the facts and rules provided.

πŸ’‘Term

In Prolog, a term is a basic building block of a program and can be a constant, a variable, or a structure. The script defines terms and provides examples, such as constants being atoms or integers, variables starting with an uppercase letter, and structures representing atomic propositions like 'father(X, Y)'.

πŸ’‘Variable

Variables in Prolog are used to represent unknown values and are a key component in the language's ability to perform general reasoning. They always start with an uppercase letter, distinguishing them from atoms and constants. The script illustrates variables with examples like 'X' and 'my_var', and discusses their role in instantiation during the resolution process.

πŸ’‘Backtracking

Backtracking is a fundamental concept in Prolog related to the search for solutions when proving goals. If a sub-goal fails to be proven, Prolog backtracks to find alternative solutions. The script provides an example of backtracking in the context of finding an instantiation for 'x' that satisfies multiple sub-goals, such as finding a male who is also the parent of 'shelly'.

πŸ’‘Resolution

Resolution is the process of proving goals in Prolog by finding a chain of facts and rules that link a goal to a known fact. The script describes how Prolog uses top-down resolution or backward chaining to perform this process, starting with the goal and working backward to find matching facts and rules.

πŸ’‘Tracing Model

The tracing model in Prolog is a debugging tool that provides insight into the steps performed during the inferencing process. The script mentions the trace structure and its use in understanding the various events like 'call', 'exit', 'redo', and 'fail' that occur as Prolog attempts to satisfy goals.

πŸ’‘Bottom-Up Resolution

Bottom-up resolution, also known as forward chaining, is one of the two general approaches to the matching process in Prolog. It starts with the facts and uses rules to find matches leading to the goal. The script contrasts this approach with top-down resolution, explaining that bottom-up resolution works well with a large set of facts that could potentially lead to the goal.

πŸ’‘Top-Down Resolution

Top-down resolution, or backward chaining, is the approach Prolog uses for its inferencing process. It starts with the goal and works backward to find a sequence of matches using rules that lead to facts. The script explains that this approach is more focused and efficient when there are fewer facts that could lead to the goal.

Highlights

Lecture focuses on Prolog, a logic programming language, discussing its origins and basic elements.

Prolog was initially developed for natural language processing and automated theorem proving.

The development of Prolog began in the 1970s with collaboration between universities in France and Scotland.

Prolog programs are constructed from terms, which can be constants, variables, or structures.

Constants in Prolog can be atoms or integers, with atoms being symbolic values used in reasoning.

Variables in Prolog are identified by starting with an uppercase letter, differing from atoms.

Structures in Prolog represent atomic propositions and are used to build statements within the language.

Three types of statements in Prolog are fact, rule, and goal statements, each serving a unique purpose.

Fact statements represent basic truths or axioms within a Prolog program.

Rule statements in Prolog are used to derive new facts from existing ones, expressed as headed horn clauses.

Goal statements, or queries, are used in theorem proving to determine the truth of a proposition.

Prolog uses top-down resolution or backward chaining for its inferencing process.

The inferencing process involves matching and resolution to prove the truth of goals.

Prolog's inferencing engine handles instantiations during the resolution process when queries are issued.

Backtracking is a key part of Prolog's search process when a sub-goal fails to be proven.

Prolog interpreters provide a tracing model for debugging, offering insight into the inferencing process.

The tracing model includes events like call, exit, redo, and fail to trace the inferencing steps.

The lecture concludes with an example illustrating the tracing model in Prolog.

Transcripts

play00:00

this is the second of our three lectures

play00:04

on logic programming languages and in

play00:06

this lecture we'll be moving on

play00:09

to prologue which will then finish

play00:12

off in the third lecture

play00:17

these are the topics that we'll be

play00:19

discussing in today's lecture

play00:21

we'll begin with a quick look at the

play00:23

origins of prologue

play00:25

and where the programming language was

play00:27

developed then we'll move

play00:29

on to some of the basic elements that

play00:32

prolog

play00:32

programs are built up out of so we'll

play00:35

begin by looking at

play00:37

terms then we'll look at fact rule and

play00:40

goal statements and then finally we'll

play00:43

look at how

play00:44

prologue deals with the inferencing

play00:47

process

play00:48

we'll see that this is a little bit

play00:50

different to the

play00:51

theorem proving in first order predicate

play00:54

calculus that we spoke about

play00:55

in the previous lecture in the lecture

play00:58

following this one

play01:00

we will continue looking at prologue

play01:03

and we'll then move on to some practical

play01:06

examples

play01:07

of programs that manipulate lists which

play01:10

in

play01:10

many ways are similar to the example

play01:13

programs that we covered in the previous

play01:15

chapter

play01:16

when we were dealing with the scheme

play01:18

programming language

play01:22

the development of the prologue

play01:23

programming language began

play01:25

in the early 1970s and continued

play01:28

into the 1980s all the way until the end

play01:32

of that decade

play01:34

so the initial development was a

play01:35

collaboration between two universities

play01:38

firstly the university of ex marseille

play01:40

in france

play01:41

and secondly the university of edinburgh

play01:44

in scotland

play01:46

so at the university of ex marseille the

play01:48

intention

play01:49

was to use this new programming language

play01:52

for natural language processing

play01:55

natural language processing is the

play01:57

automated processing

play01:58

of natural language as it would be

play02:01

written

play02:02

or spoken by a human being

play02:05

so in other words this is a subfield

play02:08

within the domain

play02:09

of artificial intelligence at the

play02:12

university of edinburgh the main

play02:13

collaborator was robert kowalski

play02:15

and he was interested in using prologue

play02:18

for automated theorem proving

play02:21

so both of these application areas are

play02:23

still very active

play02:25

areas of research and prologue can still

play02:28

be used for these purposes however the

play02:31

set of programming languages that are

play02:33

applicable in these two domains has

play02:36

widened somewhat since the 1970s

play02:39

and 1980s eventually

play02:42

the two teams working on the development

play02:46

of the programming language went their

play02:48

separate ways

play02:49

and so development then continued

play02:52

and two main dialects of prologue were

play02:55

developed

play02:57

so the most commonly used and most

play03:01

widely available

play03:02

dialect of prologue is the dialect that

play03:05

was developed at the university of

play03:07

edinburgh

play03:08

and the syntax used in this dialect is

play03:11

referred to as edinburgh

play03:12

syntax we will be assuming for

play03:15

the remainder of this lecture and the

play03:18

next lecture

play03:19

that we are using edinburgh syntax

play03:24

we are now ready to move on to the

play03:26

prologue programming language

play03:28

itself however as was the case for our

play03:32

discussion

play03:32

on scheme in the previous chapter we

play03:35

first need to define a number of

play03:38

fundamental concepts

play03:40

the first of these concepts is the

play03:42

notion of a

play03:44

term and a term is a basic building

play03:47

block

play03:48

of a prologue program so a term can be

play03:51

either a constant

play03:53

a variable or a structure and we'll look

play03:56

at each of these three

play03:57

term forms one by one so first of all we

play04:02

have

play04:02

constants and constants can be either

play04:05

atoms or

play04:06

integers now integers are fairly

play04:08

straightforward they are represented as

play04:11

you would expect

play04:12

like a normal integer literal in a

play04:15

programming

play04:16

language such as c plus or java

play04:19

so an example of an integer is the value

play04:22

42 as you can see over there

play04:25

atoms are the symbolic values

play04:28

that prolog uses so here

play04:32

we are talking about symbolic values

play04:34

once again

play04:35

as abstract concepts that the prologue

play04:38

programming

play04:39

language reasons about

play04:42

to the prologue programming language an

play04:44

atom doesn't have an intrinsic meaning

play04:46

but

play04:47

we as humans attach a meaning to each

play04:50

atom so an atom then

play04:54

can be named in two ways it can first of

play04:57

all

play04:57

be a string of letters digits and

play05:01

underscores as long as this sequence

play05:04

begins with a lower case later

play05:07

we use this same convention when we were

play05:09

discussing first order predicate

play05:11

calculus

play05:12

so an example of this kind of naming is

play05:15

joe

play05:15

as you can see over there and note that

play05:18

the

play05:18

j is a lowercase letter

play05:22

alternatively we can use any sequence

play05:26

of printable ascii characters including

play05:28

spaces

play05:29

as long as they are delimited by

play05:32

apostrophes

play05:33

so in other words single quotes over

play05:35

here we have an example of this kind of

play05:38

naming convention so here some atom

play05:42

is then the name of an atom

play05:45

as a whole now we won't be using the

play05:49

second kind of notation

play05:51

due to the fact that it makes prologue

play05:54

programs

play05:55

slightly less readable so we will be

play05:57

standardizing on the

play05:59

first approach to naming atoms in other

play06:02

words

play06:03

a single string of letters digits and

play06:06

underscores

play06:06

no spaces and beginning with a lowercase

play06:09

letter the

play06:13

second kind of term that exists in

play06:15

prolog

play06:16

is the variable so a variable

play06:19

like an atom is a string of letters

play06:21

digits and

play06:22

underscores however very importantly a

play06:25

variable name must always start with an

play06:28

upper case later

play06:29

an underscore incidentally is considered

play06:32

to be an uppercase letter however in

play06:34

general we won't start variable names

play06:36

with

play06:37

underscores now variables are the

play06:40

only components of a prologue program

play06:43

that can start with an uppercase later

play06:46

so therefore it is very easy to

play06:49

identify variables in prolog programs

play06:53

over here we have two examples of

play06:56

variables so here we have an x note that

play07:00

it's an uppercase x and

play07:02

we'll see that fairly often in the

play07:05

coming examples

play07:06

we will use a single letter to

play07:10

name a variable if it is also possible

play07:13

to give more descriptive names to

play07:15

variables

play07:16

so for example here we have my var and

play07:18

as you can see it starts with an

play07:20

uppercase

play07:21

m indicating that it is a variable

play07:25

now variables are associated with

play07:27

instantiations

play07:28

and we've discussed instantiations in

play07:30

the previous lecture

play07:32

in the context of first order predicate

play07:34

calculus

play07:35

so to refresh your memory and

play07:37

instantiation is

play07:39

a binding of a value to a variable

play07:43

an instantiation only happens during the

play07:46

resolution process

play07:47

that prologue performs when you issue a

play07:51

query to it

play07:52

but we'll get to more detail on this

play07:54

process a little bit

play07:56

later then the third and final kind of

play08:00

term that exists in prologue is

play08:01

a structure and a structure represents

play08:04

an

play08:05

atomic proposition in other words the

play08:07

simplest kind of proposition

play08:09

that we can represent so over here

play08:12

we have the syntax for a

play08:16

structure representing an atomic

play08:17

proposition

play08:19

and we can see that it uses exactly the

play08:22

same kind of notation

play08:24

as we used when we were representing

play08:26

atomic propositions

play08:28

in first order predicate calculus

play08:31

so we start off then with the functor

play08:34

which is essentially the name

play08:36

of the relation represented by the

play08:38

atomic proposition

play08:40

and the functa name starts with

play08:43

a lowercase letter exactly

play08:47

in the same way as we saw for symbolic

play08:50

atoms

play08:51

then following the functo we have a pair

play08:54

of parentheses

play08:56

and within the parentheses we have a

play08:58

list of parameters

play09:00

where the parameters are separated by

play09:03

commas

play09:06

the three kinds of terms namely

play09:09

constants

play09:10

variables and structures are used to

play09:13

build up statements within

play09:15

prolog there are three kinds of

play09:18

statements

play09:19

that exist in the prologue programming

play09:21

language

play09:22

fact statements rule statements and

play09:25

finally

play09:26

goals we'll be looking at each of these

play09:29

three types of statements in more detail

play09:32

in the next few slides

play09:35

the first and simplest kind of statement

play09:38

that can appear in a prologue program

play09:41

is a fact statement fact statements

play09:44

are atomic propositions and they are

play09:47

used to express

play09:48

hypotheses so in other words fact

play09:51

statements

play09:52

are basic ground truths or axioms

play09:55

that are assumed to be true within a

play09:58

prologue

play09:59

program prolog structures are used to

play10:02

represent

play10:02

fact statements so this means that these

play10:06

statements are headless horn clauses

play10:09

so over here we have four examples of

play10:11

fact statements within

play10:13

prologue and note that they all end with

play10:16

a full stop they also start with a

play10:20

functor so in the first example the

play10:22

functi

play10:23

is female in the second example the

play10:25

functi is again

play10:26

female in the third example the function

play10:28

is male

play10:29

and in the final example the functor is

play10:32

father

play10:33

note that the functors all start with

play10:35

lowercase letters

play10:37

so once again i'll reiterate that the

play10:39

only things that can start with

play10:40

uppercase letters in prolog

play10:43

are variables then following each

play10:46

functor we have a pair of parentheses

play10:48

and within the parentheses we have

play10:51

parameters

play10:52

so in the first example there's only one

play10:54

parameter namely shelly

play10:56

in the second example again only one

play10:58

parameter which is

play11:00

ana and in the third example one

play11:02

parameter

play11:03

called bill and then in the final

play11:06

example we have two parameters

play11:08

bill and jake and note that they are

play11:11

separated

play11:12

using a comma now all of these

play11:15

parameters start with lower case letters

play11:17

so this means that they

play11:19

are atoms once again i'll

play11:22

reiterate that these atoms are simply

play11:25

abstract objects as far as prologue is

play11:28

concerned

play11:29

however we as humans can attach some

play11:32

kind of

play11:33

meaning to them so in other words we can

play11:36

specify

play11:36

that shelly refers to a specific

play11:40

person also

play11:43

note that the functors do not have any

play11:47

intrinsic meaning associated with them

play11:50

they are simply abstract representations

play11:53

of properties

play11:55

or relationships between objects

play11:58

we as humans once again can attach a

play12:01

specific meaning to them

play12:03

so for example in the first case we

play12:06

could interpret this fact statement as

play12:08

specifying that shelly is female

play12:10

the second fact statement might be

play12:12

interpreted as

play12:13

anna is female in the third case we may

play12:17

interpret this fact

play12:18

as bill is male and in the final case

play12:21

we could interpret the fact as stating

play12:23

either that bull is the father of jake

play12:26

or that jake is the father of bill

play12:30

notice also that the fanta doesn't have

play12:32

to appear only once

play12:34

so over here we have two facts where the

play12:37

functi

play12:37

is female these represent then two

play12:41

separate facts where the property

play12:44

or properties described for the

play12:47

parameter

play12:49

hold for two separate objects

play12:52

so in other words in this particular

play12:54

example

play12:55

we have two females namely shelly

play12:58

and anna

play13:02

the second kind of statement that can

play13:05

exist

play13:05

in a prologue program is the rule

play13:08

statement

play13:09

rule statements are used to express

play13:12

theorems

play13:13

so this means that these rules can be

play13:15

used to derive

play13:16

new facts given existing facts that

play13:20

prologue already knows about within

play13:22

a program they are represented by means

play13:26

of headed horn clauses

play13:28

and their syntactic form within prologue

play13:31

is therefore quite similar to the horn

play13:34

clauses that we discussed in the

play13:36

previous lecture

play13:38

these rules therefore consist of two

play13:41

parts

play13:41

a right side and a left side the right

play13:45

side

play13:45

is the antecedent in other words the if

play13:48

part

play13:49

of the rule and this may be either a

play13:52

single term or a conjunction of terms

play13:55

where a conjunction of terms is a set of

play13:57

terms linked by

play13:58

logical and operators

play14:02

now the form that a conjunction takes in

play14:04

prologue

play14:05

is a list of several terms

play14:08

which are separated from one another by

play14:11

means of commas

play14:12

there are no explicit logical and

play14:15

operators

play14:16

so in other words the commas serve

play14:19

as implied and operators between the

play14:22

terms

play14:24

then the left side of a rule statement

play14:26

is the consequence

play14:28

in other words the then part of the rule

play14:31

and this must be a single term so in

play14:34

other words conjunctions

play14:36

or disjunctions are not allowed on the

play14:39

left side

play14:40

of a rule

play14:43

here we have some examples of rule

play14:45

statements

play14:46

as they might appear in a prologue

play14:49

program

play14:50

our first example over here is a

play14:53

specific rule and this is because it

play14:55

uses only atoms

play14:56

and no variables what this means is that

play15:00

the rule relates to specific

play15:02

objects rather than objects in general

play15:06

notice also that rule statements always

play15:08

end with a full stop

play15:10

in exactly the same way as fact

play15:12

statements

play15:13

do so we have two parts to this rule

play15:16

on the right hand side we have the

play15:18

antecedent and in this case the

play15:20

antecedent is

play15:21

a single term in other words not a

play15:24

conjunction of terms

play15:26

on the left hand side we have the

play15:28

consequent and of course the consequent

play15:30

must be a single term then between the

play15:33

antecedent and the consequent we've got

play15:35

this colon dash

play15:37

and this represents an implication

play15:41

the colon and the dash are together

play15:43

meant to resemble an

play15:44

arrow that points from the right hand

play15:46

side to the left

play15:48

so in other words pointing from the

play15:50

antecedent

play15:51

to the consequent so how would we read

play15:55

this rule

play15:56

well the usual way to read such a rule

play15:58

is to start on the right hand side with

play16:00

the antecedent

play16:02

and move to the left hand side in other

play16:04

words

play16:05

the consequent so we would read this

play16:08

rule

play16:08

as if mary is the mother of shelly

play16:12

then it implies that mary must also be

play16:16

the ancestor of shelly

play16:19

now often times i will read rules in the

play16:22

opposite direction starting on the left

play16:24

hand side and moving to the right hand

play16:27

side

play16:27

this is not a different expression of

play16:30

the meaning of the rule it's simply a

play16:32

restatement

play16:34

of the previous way that i described

play16:37

this rule

play16:38

so instead of reading this rule as if

play16:41

mary is the mother of shelly

play16:43

then it implies that mary must also be

play16:45

the ancestor of shelly

play16:47

i can read it as mary

play16:50

is the ancestor of shelley if

play16:54

mary is the mother of shelly

play16:58

so notice that with this

play17:01

rephrasing of the rules meaning i am not

play17:04

implying that the implication is

play17:06

bidirectional

play17:07

so i am saying that mary is the ancestor

play17:10

of shelly

play17:11

if mary is the mother of shelley rather

play17:14

than

play17:15

saying if mary is the ancestor of shelly

play17:19

then mary must be the mother of shelly

play17:24

so in general specific rules are

play17:27

not as useful as general rules and this

play17:30

is because as i mentioned before

play17:32

specific rules relate to specific

play17:36

objects usually we are trying to express

play17:39

a rule that relates to all objects

play17:42

and therefore we would use general rules

play17:45

as these last four examples

play17:48

illustrate so these general rules then

play17:52

use variables and this means that they

play17:54

relate to universal objects rather than

play17:57

specific objects so our first

play18:00

two rules over here describe the parent

play18:04

relation now what we are trying to

play18:06

express here

play18:07

is that x is the parent of y

play18:11

if either x is the mother of y

play18:14

or x is the father of y

play18:18

but of course as we've previously seen

play18:20

prologue rules

play18:21

cannot include disjunctions in other

play18:24

words they can't

play18:25

include logical or statements

play18:28

so we address this then by creating

play18:31

two rules that describe the parent

play18:34

relation

play18:35

so the first rule then states that x

play18:38

is the parent of y if x

play18:41

is the mother of y and the second rule

play18:44

states that

play18:45

x is the parent of y if x

play18:48

is the father of y so

play18:52

whenever you are attempting to express a

play18:54

rule that contains

play18:56

a logical or you must then

play18:59

write this as separate rules

play19:02

that relate to the same relation in this

play19:05

example

play19:06

it was the parent relation

play19:10

the next example describes a grandparent

play19:13

relation over here

play19:14

and here you can see that the antecedent

play19:17

contains

play19:18

two terms that are connected by a

play19:22

single comma so the comma then

play19:25

represents a logical and

play19:29

now what this example also illustrates

play19:31

is

play19:32

that we can use a variable in the

play19:34

antecedent that doesn't appear in the

play19:36

consequent

play19:37

so you can see that the consequent uses

play19:39

the variables x

play19:41

and z and x and z

play19:44

are also used in the antecedent however

play19:47

the antecedent

play19:48

also uses the variable y so

play19:52

what are we trying to express here then

play19:54

well we are

play19:55

saying that x is the grandparent of z

play20:00

if x is the parent of a y

play20:04

and this y is also the parent

play20:07

of z so in other words we are stating

play20:10

that there

play20:11

is an object that lies between x and y

play20:14

where x is the parent of that object and

play20:17

that object

play20:18

is the parent of zed

play20:22

our final example over here is a

play20:24

slightly more

play20:25

complex rule and this rule describes

play20:28

the sibling relation so here we are

play20:31

stating

play20:32

that x is the sibling of y

play20:36

if there exists an m such that

play20:39

m is the mother of x and m is also the

play20:42

mother of y

play20:44

and then also an if exists

play20:48

where if is the father of x

play20:51

and f is also the father of

play20:54

y so in other words what we are

play20:57

specifying here is that x and y

play20:59

are siblings if they share a mother in

play21:02

common

play21:03

and they also share a father in common

play21:09

the third and final kind of statement

play21:11

supported in

play21:12

prologue is the goal statement

play21:16

goal statements are often simply

play21:17

referred to as goals or sometimes

play21:19

queries

play21:20

and they are used in theorem proving

play21:23

so a theorem then is a proposition that

play21:26

we present

play21:27

to prologue and the prologue interpreter

play21:30

is then responsible for attempting to

play21:32

prove

play21:32

the truth of this proposition

play21:35

now the proof is handled behind the

play21:38

scenes by the

play21:39

interpreters inferencing engine and

play21:42

therefore

play21:43

the programmer themselves will not

play21:45

actually

play21:46

implement the proof now in general

play21:50

a prologue interpreter will allow a

play21:53

programmer to

play21:54

provide facts and rules either in the

play21:57

form

play21:57

of a source code file or in an

play22:00

interactive mode

play22:01

similar to the interactive modes that

play22:04

are usually provided by scheme

play22:06

interpreters either way the prolog

play22:09

interpreter will allow the programmer to

play22:11

enter a second mode

play22:12

which is referred to as the query mode

play22:15

and in this mode they can then type in

play22:19

goals or queries which the prolog

play22:22

interpreter

play22:23

then needs to answer

play22:26

so a simple goal uses exactly the same

play22:28

syntax

play22:29

as a fact statement in other words these

play22:32

are headless horn clauses

play22:35

over here we have an example of such a

play22:38

headless horn clause note that it ends

play22:42

with a full stop and you will also

play22:45

notice

play22:46

that a question mark and a dash

play22:49

symbol precede the query

play22:52

so the question mark and dash symbols

play22:55

are not

play22:56

part of the query i simply use them

play22:59

to clearly indicate when a query is

play23:02

being presented

play23:03

rather than a fact statement

play23:07

so the reason that i use a question mark

play23:11

and a dash symbol to indicate

play23:15

that a query is being issued is that

play23:17

this is

play23:18

a fairly common prompt that is used by a

play23:20

lot of prologue

play23:22

interpreters when the interpreter is in

play23:25

query mode so what

play23:28

are we then asking the prolog

play23:31

interpreter to do

play23:33

when we issue a query such

play23:36

as this well we're essentially asking

play23:40

the prologue interpreter whether it can

play23:43

prove

play23:43

that fred is a man

play23:46

the interpreter will then attempt to

play23:49

answer

play23:50

this question by considering the

play23:53

facts and the rules that have been

play23:55

provided by the programmer

play23:58

if the prologue interpreter can answer

play24:00

this

play24:01

query and determine that it is true

play24:05

then it will respond with a yes or

play24:08

a true result if the prolog interpreter

play24:11

can't prove the truth of this query then

play24:14

it will respond with

play24:15

a no or a false

play24:19

now we can also use conjunctive

play24:21

propositions

play24:23

and variables within our propositions

play24:26

within our goals so over here i have two

play24:29

examples of these cases

play24:31

here we have a simple goal so again it's

play24:34

a single headless horn clause

play24:38

but we can see that it includes a

play24:40

variable

play24:41

x over here so what we are

play24:44

asking the prologue interpreter in this

play24:46

case

play24:47

is can you find a value for x

play24:51

such that x is the father

play24:54

of mike what will then happen

play24:58

is prologue will attempt to find an

play25:00

instantiation

play25:01

for the variable x that will make this

play25:05

query true so if prolog

play25:08

can find an instantiation for x that

play25:10

makes the query true it will then

play25:12

respond with

play25:13

yes or true and then it will also

play25:16

indicate

play25:17

what the value for x should be

play25:21

if prolog cannot find an instantiation

play25:24

for x

play25:25

that makes this query true then it will

play25:27

respond with

play25:29

a no now it is also possible

play25:33

to re-query within prolog

play25:36

so what will happen then in that case is

play25:39

we will enter our

play25:40

initial query and then we will get a

play25:43

response from prolog

play25:45

we can then issue a re-query and there

play25:48

are a variety of different syntactic

play25:50

mechanisms that we can use

play25:52

to do this but what we are then asking

play25:55

prolog to do

play25:56

is to find another instantiation of x

play26:00

which is different to the first

play26:01

instantiation

play26:02

and also makes the query true

play26:05

we can continue re-quering until

play26:08

eventually prolog cannot find

play26:10

a new instantiation for x that makes the

play26:13

query true

play26:14

and then in that case prolog will

play26:15

respond with no

play26:17

or false now in the final example over

play26:20

here

play26:21

we have a query that consists

play26:24

of two simple goals and these

play26:28

are referred to as sub goals

play26:31

so here we have one sub goal and here we

play26:33

have the second sub goal

play26:35

and note that there is x a comma between

play26:38

the two

play26:38

which indicates implicitly a logical

play26:42

and operation so what we are asking the

play26:45

prolog interpreter to do

play26:46

here is to find an instantiation for x

play26:50

such that x is the father of mike

play26:54

and x is also male once again if

play26:58

prologue can

play26:58

find such an instantiation that makes

play27:01

both of these

play27:02

sub-goals true then it will respond with

play27:04

yes or true

play27:06

and then provide the value for the

play27:09

instantiation of

play27:10

x if it cannot find such an

play27:13

instantiation then it will respond with

play27:15

no

play27:16

or false and once again we can then

play27:19

re-query prologue repeatedly to find

play27:21

different instantiations for the

play27:23

variable x

play27:24

that make the sub-goals both true

play27:28

and we can continue doing this until

play27:30

eventually prologue can't find

play27:32

a suitable instantiation at which point

play27:35

it will then respond with

play27:36

a no or a false

play27:41

we've now discussed most of the basic

play27:44

components

play27:44

of a prologue program there are only

play27:48

two topics that we still need to discuss

play27:51

firstly prologues support for basic

play27:54

arithmetic

play27:55

and secondly lists in prologue we'll get

play27:58

to these two topics

play28:00

in the next lecture but for now we will

play28:03

focus

play28:03

our attention on the inferencing process

play28:06

that is performed

play28:07

by prologue so we've just seen that the

play28:11

inferencing process

play28:12

requires a prologue interpreter to

play28:15

attempt to prove the truth

play28:17

of either a goal or a set

play28:20

of sub-goals now in order to do this

play28:24

the prologue interpreter by means of its

play28:27

inferencing engine

play28:29

needs to find a chain that involves

play28:32

facts and rules now this

play28:35

chain then needs to link our goal which

play28:39

will represent

play28:40

as q to a fact

play28:43

a and this fact a needs to be found

play28:47

such that we have a series of links

play28:50

from the fact to the goal q

play28:54

so our fact a then needs to imply

play28:58

another fact b fact b then

play29:01

needs to imply fact c and so on

play29:05

until eventually we arrive at fact p

play29:08

which implies fact q which

play29:12

is then the goal that we are trying to

play29:14

prove

play29:16

now this process then is referred to

play29:19

as matching satisfying or

play29:22

resolution now there are two

play29:26

general approaches that we can use to

play29:28

perform this

play29:29

matching process that we've just

play29:31

described

play29:32

the first is called bottom up resolution

play29:35

sometimes also referred to as forward

play29:38

chaining

play29:39

here we begin with facts that have been

play29:41

specified by the programmer

play29:43

and then we use rules in order to

play29:46

attempt to find a sequence of matches

play29:49

that will eventually lead to the goal we

play29:52

are trying to prove

play29:55

now this approach works well with a

play29:57

large set of possibly

play29:59

appropriate facts all of which will lead

play30:02

to the goal this is because there's a

play30:06

high

play30:06

likelihood that we will select a fact

play30:10

that will lead to the goal

play30:11

and therefore our search will be fairly

play30:15

focused the second approach

play30:18

is called top down resolution or

play30:21

backward chaining

play30:22

and this approach is the opposite of

play30:25

forward chaining so here we begin with

play30:28

the goal that we

play30:29

are trying to prove and then we attempt

play30:32

to find

play30:33

a sequence of matches using rules

play30:36

that eventually lead to facts

play30:41

now this approach works well if we have

play30:43

a small set

play30:44

of possibly appropriate facts that will

play30:48

lead to the goal we are trying to prove

play30:51

the reason for this is that forward

play30:54

training

play30:55

will be much more likely to select

play30:58

a fact that will not lead to

play31:01

the goal so therefore if we use backward

play31:04

training and start with the goal

play31:06

then our search will be more focused

play31:09

towards finding one of the few

play31:13

appropriate facts prologue uses

play31:17

top-down resolution or backward chaining

play31:20

in order to perform its matching process

play31:24

so let's look at these two approaches

play31:28

by means of a simple example over here

play31:31

here we have

play31:32

a single facts which we've specified and

play31:35

this fact states that

play31:36

bob is a father then we have

play31:40

a rule and this rule states that if x

play31:43

is a father then it implies that x must

play31:47

also be

play31:48

a man now we issue a

play31:51

query to our system and this query

play31:54

is asking whether bob is a man

play31:59

now with bottom up resolution or forward

play32:01

chaining

play32:02

we begin with the facts

play32:06

that have been specified by the

play32:07

programmers so we start off then

play32:10

with the fact that bob is a

play32:13

father we then find that we have

play32:16

a rule that involves the

play32:20

relation father and we can then

play32:24

substitute bob in for the variable

play32:27

x in this case so this is then

play32:30

an instantiation that we have performed

play32:33

note that it is the inferencing process

play32:35

that performs this

play32:37

instantiation so now because we've

play32:39

instantiated

play32:41

x to bob we then know by means of the

play32:44

implication

play32:45

that bob must also be a

play32:48

man this is the consequent of

play32:52

this rule so this then is

play32:55

the goal that we are trying to prove we

play32:58

have found

play32:59

now a path that leads from a fact

play33:02

to our goal and therefore

play33:05

the logic system would conclude

play33:08

that this goal has been proven to be

play33:11

true

play33:13

now with top down resolution or backward

play33:16

training which is what prologue uses

play33:18

we begin with the goals in other words

play33:21

we begin with the goal

play33:23

that we are attempting to prove that bob

play33:26

is

play33:26

a man so then we look through

play33:30

our facts and rules and we find

play33:33

this rule which includes then the

play33:36

relation man

play33:38

which was used in our query

play33:42

so we can then substitute bob for

play33:45

the variable x in this case again that

play33:48

is an instantiation and then

play33:52

we arrive at the antecedent that

play33:55

bob is a father we then

play33:59

again search through our facts and rules

play34:02

and we find this fact over here which

play34:05

states that

play34:06

bob is a father and this matches with

play34:09

the

play34:10

antecedent that we've just instantiated

play34:13

so now we've found a path that leads

play34:16

from our goal

play34:17

to a fact that has been specified

play34:23

next we need to consider how multiple

play34:26

sub goals are dealt with

play34:27

by the inferencing process so if we have

play34:31

multiple sub goals

play34:32

there are two general approaches that we

play34:35

can use

play34:36

to prove each of these sub goals

play34:39

the first is a breadth first search and

play34:42

here we work

play34:43

on all of the sub goals in parallel

play34:47

the second approach is a depth first

play34:49

search

play34:50

and here we start with the first

play34:52

sub-goal and find

play34:54

a complete proof for it we then move on

play34:57

to the second sub-goal

play34:59

and find a complete proof for that

play35:01

sub-goal

play35:02

and then the third sub-goal and so on

play35:04

until

play35:05

eventually we've proved all of the

play35:07

sub-goals

play35:09

so a depth-first search can generally be

play35:12

performed with fewer computational

play35:14

resources because we are focusing

play35:16

on each proof individually where each

play35:20

proof

play35:21

involves finding a chain of matches

play35:25

because of this lower computational load

play35:29

involved with depth first search

play35:31

prologue

play35:32

uses this approach

play35:36

now if we have multiple sub-goals to

play35:39

prove

play35:40

backtracking potentially comes into play

play35:43

so backtracking occurs

play35:46

when we have several sub-goals and we

play35:49

are proving these sub-goals one by one

play35:52

but we then fail to prove one of the

play35:54

sub-goals

play35:56

in this case we then need to backtrack

play35:58

and this means

play35:59

we have to then move back to the

play36:02

previous

play36:03

sub-goal that was proved just prior

play36:07

to the sub-goal that failed we then need

play36:10

to find

play36:11

a different solution for this previous

play36:14

sub-goal that potentially then could

play36:17

lead

play36:17

to us being able to prove the sub-goal

play36:21

that failed when we

play36:24

backtracked to a previous sub goal we

play36:26

begin the search

play36:28

for a different solution where the

play36:30

previous

play36:31

search left off now this backtracking

play36:34

process can potentially lead to a lot of

play36:37

wasted time

play36:38

as well as wasted memory space and the

play36:41

reason

play36:42

for this is that we may have to keep

play36:44

backtracking

play36:45

until eventually we have found all of

play36:48

the possible proofs

play36:50

for every sub-goal so let's illustrate

play36:53

this backtracking process

play36:55

by means of this example query

play36:58

and here we are assuming that we have a

play37:01

prologue program

play37:02

that specifies a number of facts

play37:05

and some of these facts then are

play37:08

specified by means

play37:09

of the male relation and they specify

play37:12

that particular atoms are male

play37:16

we also have a number of facts

play37:19

that are specified by means of the

play37:21

parent relation

play37:22

and the parent relation specifies that

play37:25

one atom

play37:26

is the parent of another atom

play37:29

so what are we asking the prologue

play37:32

interpreter to do

play37:33

with this query well we're asking

play37:36

the prologue interpreter to find an atom

play37:40

which instantiates the variable x such

play37:43

that that atom

play37:44

is male and that atom is also

play37:48

the parent of shelly

play37:51

so how does prologue then go about

play37:54

attempting to prove these two sub-goals

play37:58

now what's important to understand here

play38:01

is that prologue

play38:02

always proves sub-goals from left

play38:05

to right prologue also matches

play38:08

from the top of the program to the

play38:11

bottom

play38:12

when it is considering facts

play38:15

so what will happen then is prologue

play38:17

will begin

play38:18

with the first sub-goal and it will then

play38:21

attempt to find the first

play38:25

rule that specifies a

play38:28

male relation for a particular atom

play38:32

that atom will then be used to

play38:34

instantiate

play38:35

the variable x and then prologue will

play38:37

move on to the next

play38:39

sub-goal with this sub-goal it will then

play38:42

use the instantiation of

play38:44

x and it will then attempt to

play38:48

find a fact that specifies that

play38:51

the atom that x has been instantiated to

play38:54

is the parent of shelly

play38:57

now if this atom is not the parent of

play39:00

shelly

play39:01

then we've failed to prove the second

play39:04

sub-goal

play39:05

so we now need to backtrack to the first

play39:08

sub-goal this then means that we

play39:11

continue the search where we left off

play39:14

so we don't reconsider the first rule

play39:18

that is specified by means of the

play39:22

male relation we therefore find the

play39:25

second that specifies

play39:28

that a particular atom is male

play39:31

this then leads to another instantiation

play39:35

of x with a different atom to the first

play39:39

instantiation

play39:40

and then we again move on to the second

play39:42

sub goal

play39:44

and now we need to prove that this

play39:47

atom that has been instantiated

play39:51

for x is again the parent

play39:54

of shelly so we then continue this

play39:57

backtracking process

play39:58

until eventually we found an

play40:01

instantiation for x

play40:03

that satisfies both of the sub-goals

play40:07

now let's consider a situation where

play40:10

there is no male that is

play40:13

a parent of shelly in this case what

play40:17

will happen is we will continuously

play40:19

backtrack until we have eventually

play40:22

considered

play40:24

every fact that specifies that a

play40:27

particular atom

play40:28

is male in that case we've then

play40:31

exhausted all of the possible

play40:33

instantiations for

play40:35

x and we haven't managed to prove

play40:38

both of the sub-goals in this case then

play40:41

both sub-goals fail

play40:43

and prologue will then respond with a no

play40:46

or a false indicating that it could not

play40:49

prove the goal

play40:53

now prologue interpreters typically also

play40:56

provide a tracing model and this

play41:00

is provided by means of a built-in trace

play41:03

structure the trace structure

play41:06

is used when we are attempting to

play41:09

debug our prologue programs and this

play41:12

gives

play41:13

us insight into the various steps that

play41:16

are performed

play41:17

during the inferencing process so the

play41:20

tracing model

play41:21

then has four events that

play41:24

can occur the first is a call

play41:27

and this indicates the beginning of an

play41:30

attempt to satisfy

play41:32

a goal the next event is an

play41:35

exit and this occurs when a goal has

play41:38

been satisfied

play41:40

then we have a redo event and this

play41:43

happens

play41:44

when backtracking occurs and finally

play41:47

we have a fail event which occurs

play41:50

when a goal fails

play41:55

let's finish this lecture by looking at

play41:57

a simple example that illustrates how

play42:00

the tracing model in prolog

play42:02

works over here we have a simple

play42:05

prologue program that consists

play42:07

only of four fact statements

play42:11

and the fact statements all use the

play42:14

likes relation which specifies that one

play42:17

atom likes another so the first

play42:20

fact statement specifies that jake likes

play42:24

chocolate the second fact statement

play42:28

indicates that jake also likes apricots

play42:31

the third fact statement tells us that

play42:34

darcy

play42:35

likes licorice and the final fact

play42:38

statement specifies that darcy also

play42:41

likes

play42:42

apricots so now we enter query mode

play42:46

and we begin then by using

play42:50

the trace structure as you can see over

play42:53

here

play42:54

note that the trace ends with a full

play42:56

stop and this

play42:57

instructs the prologue interpreter

play43:00

to print out each step that is performed

play43:03

during the inferencing process

play43:05

now we need to provide a query

play43:08

to the interpreter and that's exactly

play43:11

what we do

play43:12

over here and note that this query

play43:14

consists of two sub

play43:15

goals here and here

play43:19

and the two sub goals are separated by a

play43:21

comma

play43:22

also notice that the sub goals

play43:26

use a variable named x

play43:29

so what are we asking the prolog

play43:31

interpreter

play43:32

to do at this point well we want the

play43:36

interpreter to find an

play43:38

instantiation for x and

play43:41

that instantiation should then result

play43:44

in both of the sub-goals

play43:47

being true now we are less interested

play43:51

in the final result of this query and

play43:54

more interested

play43:55

in the steps that are performed to get

play43:57

there

play43:59

so once again recall that prologue

play44:03

attempts to satisfy sub goals

play44:06

from left to right so we begin with this

play44:09

leftmost sub goal

play44:11

and then move to the right one

play44:14

so first what we need to do is find

play44:18

an instantiation for x so that

play44:21

the first sub goal is true

play44:25

so that's exactly what we do with this

play44:28

call over here

play44:29

and at this point the variable x has not

play44:33

been instantiated so that's what's

play44:36

represented here by this underscore 0

play44:39

which indicates that we do not have

play44:42

a value instantiated for this variable

play44:46

yet now recall again

play44:49

that when prologue is

play44:52

matching it moves from the top of

play44:55

the program to the bottom so what will

play44:59

happen

play44:59

is we will look for a fact that

play45:03

matches this first sub goal and we will

play45:06

start

play45:07

at the top and find the first matching

play45:10

fact statement

play45:12

so that first matching fact statement is

play45:15

in fact

play45:16

the first fact over here specified in

play45:19

our program

play45:21

that states that jake likes chocolate

play45:25

so that then results in the variable

play45:28

x being instantiated to

play45:31

the atom chocolate and that's then

play45:35

exactly what happens

play45:36

in this exit that occurs at this point

play45:40

so here we now indicate that we have

play45:43

matched against the

play45:46

fact that states that jake likes

play45:49

chocolate

play45:49

and therefore chocolate has been used to

play45:52

instantiate

play45:53

the variable x so

play45:56

now we've satisfied the first sub goal

play46:00

so we can then move on to the second

play46:03

sub goal so we now have another call but

play46:07

at this point

play46:08

this variable x has been instantiated

play46:11

with the atom chocolate so

play46:15

we are then performing a call

play46:19

for the statement that darcy likes

play46:23

chocolate now again we need to then

play46:26

perform our matching process from top to

play46:29

bottom so we are looking

play46:31

for a fact statement that specifies that

play46:34

darcy

play46:35

likes chocolate and of course you can

play46:37

see that

play46:38

none of the facts specify this so this

play46:41

means

play46:42

we then have a fail and this fail

play46:46

then is for the

play46:49

fact that darcy likes chocolate

play46:52

so this means we have now failed to

play46:55

prove our

play46:56

second sub goal at this point so we now

play46:59

need to backtrack

play47:00

to the first sub goal and find another

play47:04

instantiation

play47:05

for the variable x so this is then

play47:08

indicated by

play47:10

the redo over here and now

play47:13

we have an uninstantiated variable x

play47:17

which is indicated by this underscore 0

play47:20

at this point so now we continue the

play47:23

search

play47:24

where we left off so we left the search

play47:27

at this point where we matched the

play47:31

first fact for the first

play47:34

sub-goal so now we continue our search

play47:37

down

play47:37

and we then find the second

play47:40

fact over here that states that jake

play47:44

likes apricots so

play47:47

we then have an exit and this exit then

play47:50

indicates

play47:51

that the variable has been instantiated

play47:54

with the atom apricots

play47:57

so now we have once again satisfied the

play48:01

first sub-goal and we need to move on to

play48:04

the second sub goal over here

play48:07

so we have now instantiated the

play48:11

variable x with the value apricots

play48:15

which then means that we have a call

play48:18

for the statement that

play48:21

darcy likes apricots

play48:25

we then begin the search once again at

play48:28

the top of our program matching the

play48:32

facts one by one and we see that we then

play48:36

can match the statement that dorsey

play48:39

likes apricots by means of the

play48:43

lost fact over here so now we've found a

play48:46

match

play48:47

this then results in an exit which means

play48:51

that we have now satisfied

play48:53

the second sub-goal so now we've

play48:56

satisfied both

play48:57

sub-goals which means that the

play49:00

inferencing process can now

play49:02

terminate and it will respond then with

play49:05

a

play49:05

yes or a true and then indicate

play49:08

that the instantiation for x is

play49:12

apricots which then satisfies both

play49:15

of the two sub-goals

play49:18

now we could then at this point issue

play49:21

a re-query again and this then tells

play49:25

prologue

play49:26

to attempt to find another value for

play49:29

x that will make both sub goals

play49:32

true so then again we will begin

play49:36

with our first sub goal over here

play49:39

and we will try to then find another

play49:42

instantiation

play49:44

for x that will make this first sub-goal

play49:46

true

play49:47

but at this point we have now considered

play49:50

all of the

play49:51

facts that involve jake liking

play49:54

something else so we then cannot find

play49:57

another matching fact meaning we can't

play50:00

then

play50:01

locate another valid instantiation for

play50:04

the variable x at this point

play50:06

so at this stage prologue will then fail

play50:09

and respond with a no

play50:10

or a false indicating that it can't find

play50:14

another instantiation for the x

play50:17

variable all right so that concludes

play50:21

this

play50:21

lecture in the next lecture we will

play50:24

continue

play50:24

looking at the last two remaining

play50:28

elements

play50:28

of prologue programs and we will then

play50:31

look at some example prologue programs

play50:35

that reason about lists we will also

play50:38

look

play50:38

at some deficiencies associated with the

play50:41

prologue

play50:42

programming language and then finally we

play50:45

will look at some practical applications

play50:47

of prologue

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Prolog ProgrammingLogic LanguagesAI ApplicationsNatural LanguageAutomated TheoremInference ProcessBacktrackingFact StatementsRule StatementsGoal Statements