SlideShare a Scribd company logo
1 of 271
Download to read offline
Course Notes
INF-382-99 – ARTIFICIAL INTELLIGENCE
USING PROLOG
By
Martin Lesage
Courses Notes Written for the course INF-382-
99 – ARTIFICIAL INTELLIGENCE USING
PROLOG
Notes made from the book : Bratko, Ivan - Prolog programming for
artificial intelligence, 3rd
edition, Addison-Wesley, 2000
ISBN: 0-201-40375-7
Université du Québec à Rimouski (UQÀR)
January 2002
DEPARTMENT OF MATHEMATICS, COMPUTING AND ENGINEERING
1. LESSON PLAN
SESSION: WINTER 2002
ACRONYMS: INF-382-99
TITLE: Artificial Intelligence
GROUP: 05
CLASS SCHEDULE: Thursday 8:30 am to 11:20 am LOCAL: K-245
START: January 10, 2002
PROFESSOR:
Martin Lesage
Office: K-113
Telephone (UQAR): 724-1986 Ext: 1277
Telephone (CÉGEP de Rivière-du-Loup): (418) 862-6903 Extension: 561
Fax: 724-1879
Email: marles@cegep-rdl.qc.ca
DESCRIPTION OF THE COURSE ACCORDING TO THE DIRECTORY
Know the basic concepts, techniques and applications of artificial intelligence.
Heuristic methods of problem solving; search algorithms in trees and graphs; representation of
knowledge; expert systems; processing of natural languages; pattern recognition; neural
networks. History, results, challenges and limitations. Introduction to LISP or PROLOG language.
Prerequisite (s): INF11299 Programming II
INSERTING THE COURSE INTO THE PROGRAM
This course is an optional course for students of the bachelor's degree in mathematics-computer
science. It has as a formal prerequisite the course INF11299 Programming II but also requires
knowledge acquired in data structures and algorithms.
COURSE OBJECTIVES
- Acquire basic notions in the main fields of artificial intelligence and study the different
concepts and techniques of this discipline; and
- Become familiar with a programming language characteristic of artificial intelligence.
COURSE CONTENT
The course is mainly based on the following compulsory reference book and course notes
provided by the teacher:
Bratko, Ivan
Prolog programming for artificial intelligence, 3rd edition
Addison-Wesley, 2000
ISBN: 0-201-40375-7
PEDAGOGICAL FORMULAS
A three (3) hour meeting each week with the professor to cover the theoretical aspects, do case
studies and supervised exercises. Personal readings in the compulsory reference book and
course notes must be done by the student before each meeting with the professor. Two practical
sessions are also planned.
MANDATORY READING
Bratko, Ivan
Prolog programming for artificial intelligence, 3rd edition
Addison-Wesley, 2000
ISBN: 0-201-40375-7
Lecture notes provided by the teacher
EVALUATION
Assessment methods:
Examinations: The exams are written tests.
Practical work : Assignments are done individually for practical work 1 and in pairs for practical
work 2
French policy: Up to 10% of points can be awarded for the quality of written French in
assignments and exams.
Type of test Weighting
Practical Work 1 15% Delivery on February 21
Practical Work 2 25% Delivery on April 18
Intra exam 30% Date of the test: March 7
Final exam 30% Date of the test: April 25
Proposed notation (correspondence of the numerical note to the literal note, if applicable)
The establishment of the final odds is based on the following fixed odds scale:
Side Note
A+ 93%
A 90%
A- 87%
B+ 83%
B 80%
B- 77%
C+ 73%
C 70%
C- 67%
D+ 63%
D 60%
E <60%
CALENDAR OF MEETINGS
Week Dated
1 January 10 Artificial intelligence (AI): History, results, challenges and limits
Readings: Course Notes
2 January
17th
The representation of knowledge: Logic, deductive reasoning, inductive reasoning,
propositional logic, calculation of predicates, production rules, semantic networks,
structured objects, principles of uncertainty
Readings: Course Notes
3 24 january Knowledge representation: control structures in expert systems, forward chaining,
backward chaining, mixed reasoning, choice of a control strategy
Readings: Course Notes
4 January 31 Prolog language: Presentation of Prolog, syntax and meaning of Prolog programs
Readings: Book of Bratko, chapters 1 and 2
Delivery of Statement of Practice 1
5 February 7 Prolog language: Lists, operators, arithmetic, use of structures
Readings: Book of Bratko, chapters 3 and 4
6 February
14th
Prolog language: Rollback control, additional integrated procedures
Readings: Book of Bratko, chapters 5 and 7
7 the 21st of
February
Prolog language: Operations on data structures
Readings: Book of Bratko, Chapter 9
Submission of practical work 1, submission of statement of practical work 2
8 February 28 Reading week
9 March 7 Intra exam
10 March 14 Prolog language: Elementary problem-solving strategies
Readings: Book of Bratko, Chapter 11
11 March 21st Prolog language: Graph browsing
Readings: Book of Bratko, chapter 12
12 March 28 Expert systems: Functions, main structures and representation of knowledge
Readings: Book of Bratko, Chapter 15
13 April 4 Expert systems: Shell creation, implementation, handling of uncertainty
Readings: Book of Bratko, Chapter 16
14 April 11 Applications of artificial intelligence: Natural language processing, pattern recognition,
digital vision
Readings: Course Notes
15 April 18 Applications of artificial intelligence: Neural networks, robotics
Readings: Course Notes
Handover of practical work 2
16 April 25 Final exam
SCHEDULE FOR SUBMISSION OF WORKS AND EXAMINATIONS
Works
Exams
SPECIAL TERMS
Penalty for late work: Any delay in submitting a work exposes the student to lose 1 point per day
of delay.
Plagiarism: Any student who has copied or tried to copy, in any way whatsoever, will be
immediately dismissed from the examination room, will have his work canceled and his case
submitted to the competent authority who will apply penalties proportionate to the fault.
BIBLIOGRAPHICAL REFERENCES
Mandatory :
Bratko Ivan, Prolog programming for artificial intelligence, 3rd edition, Addison-Wesley, 2000,
ISBN: 0-201-40375-7.
Reference Manuals:
Charniak Eugene, McDermott Drew, Introduction to Artificial Intelligence, Addison-Wesley, 1985.
Luger George F., Stubblefield William A., Artificial Intelligence, Structures and Strategies for Complex Problem Solving,
Benjamin Cummings, 1993.
Laurière JL, Artificial Intelligence, Eyrolles, 1987.
Rich Elaine, Artificial Intelligence, McGraw-Hill, 1983.
Winston Patrick Henry, Artificial Intelligence, InterEditions, 1988.
Clocksin WF, Mellish CS, Programming in Prolog, Springer-Verlag, 1988.
Giannesini F., Kanoui H., Pasero R., Van Caneghem M., Prolog, InterEditions, 1985.
Sterling Leon, Shapiro Ehud, The Art of Prolog: Advanced Programming Techniques, The MIT Press, 1986.
Farreny Henri, Ghallab Malik, Elements of Artificial Intelligence, Hermes, 1987.
Graham Neil, Artificial Intelligence, TAB Books Inc., 1979.
Ginsberg Matthew, Essentials of Artificial Intelligence, Morgan Kaufmann Publishers, Inc., 1993.
Chatain Jean-Noël, Dussauchoy Alain, Expert Systems: Methods and Tools, Eyrolles, 1987.
Frenzel Louis E. Jr., Crash Course in Artificial Intelligence and Expert Systems, Howard W. Sams & Co., ISBN 0-672-
22443-7.
Type of test Weighting 1. Date of delivery
Practical Work 1 15% February 21st
Practical Work 2 25% April 18
Exam Weighting Date of the test
Intra exam 30% March 7
Final exam 30% April 25
COURSE 01
INF-38299 - ARTIFICIAL INTELLIGENCE
In our current society, some salespeople or technologists qualify electronic or computer
systems as intelligent:
 Smart robot (Aïbo)
 Smart tutorial
 Automotive (ABS brakes, electronic injection, suspension, etc.)
 Toys for children
 Surveillance, alarm systems, home automation
 Etc ...
DEFINITIONS
Artificial intelligence is difficult to define in the same way as human intelligence.
The concept of intelligence is complex and relative, and the highly controversial
expression of "artificial intelligence" does not specify it further, it is also difficult to define
the scientific discipline of artificial intelligence (AI).
Artificial intelligence (AI) is a field of computing dedicated to creating hardware and
software capable of mimicking human thought. The main goal of artificial intelligence is
to make computers smarter by producing software that allows a computer to emulate
functions of the human brain in defined applications. The idea is not to replace the
human being but to give him a more powerful tool to help him accomplish his tasks.
This discipline can be considered as a cognitive science and also as a branch of
computer science.
 Cognitive science: understanding and modeling the mechanisms of
understanding, the study of mental faculties.
 Computer science branch: design programs and machines able to deal with
problems for which no direct and assured resolution methods are known.
Artificial intelligence is the study of ideas that can make computers smart
Artificial intelligence is a field of computing dedicated to programming computers to
perform tasks such that if these tasks were performed by a human being, those tasks
would require intelligent action from the human being.
WHY DO WE NEED COMPUTERS OR INTELLIGENT SYSTEMS?
 Smart computers can adapt themselves to their human users instead of the other
way around. Many reviews of computers state that users must adapt to the
language of the computer. It would be important for the user to be able to interact
with the computer using English or another spoken language.
 Robots can work in environments hostile to humans, such as the ocean floor,
underground mines, or in space.
 Robots can do boring and repetitive tasks that are currently performed by
humans because of their ability to perceive and manipulate their environment.
Much work on assembly lines falls into this category.
 Computers can store the vast amounts of information that humans need to do
their jobs and fulfill their personal lives. Depending on needs, the computer can
be used as a teacher, encyclopedia, consultant, journalist or postman.
 In a complex world with complex problems, humans need a multitude of means
to solve problems. Economics, energy and international relations are some areas
where smarter computers could help human beings solve humanity's problems.
ARTIFICIAL INTELLIGENCE TECHNIQUE
An artificial intelligence technique is a method that exploits knowledge that should be
represented in such a way that:
 They catch the generalizations.
 They can be understood by those who have to provide them.
 They can be easily modified to correct mistakes and to reflect changes in the
world and our view of it.
 They can be used in a very large number of cases even if they are not completely
precise or complete.
 They can serve to overcome their own large volume by helping to narrow the field
of possibilities that must usually be considered (sorting / selection of rules).
APPLICATIONS
 Problems solving
Most of the tasks given to computers can be regarded as problems. In each
case, the computer is expected to perform the necessary operations in order to
solve a specific problem.
Unlike traditional applications solving particular problems, artificial intelligence
programs are designed in such a way that they are of the most general use
possible. When a problem and the knowledge base necessary for the solution of
that problem is inputted to this type of program, that program should find a
solution as a human could.
Artificial intelligence techniques tend to dissociate from algorithmic problem-
solving methods. Indeed an artificial intelligence program can generate new
knowledge and have a certain initiative.
 Natural language processing (5th generation software)
Currently, the means of communication between human being and computers is
not very optimal. This is especially true when a person wants to give instructions
or input data to a computer. Some computers can also communicate with
humans through prefabricated sentences.
In the event that computers have to interact with users who are not computer
specialists, the computers must be able to communicate in natural language,
such as English. The computer should also be able to communicate orally or in
writing.
In addition to being able to easily communicate with the user, one of the tasks of
artificial intelligence is to perform processing on natural languages, such as
automatic translation from one language to another or to respond to basic
questions.
 Pattern perception and recognition
In many computer applications, a computer needs to perceive its surroundings
using television cameras, microphones, and other sensors. In addition, the
computer needs to recognize certain characteristics or particular shapes in the
environment it perceives.
 Expert systems
The main use of artificial intelligence today is concentrated in expert systems,
artificial intelligence programs serving as advisers or consultants. An expert
system allows the knowledge and experience of one or more experts in a
particular field to be stored in a computer. This knowledge can then be used by
anyone who needs it.
 Education
Artificial intelligence can also be used in the field of training and education. Using
the techniques of artificial intelligence, new tutorials can be produced that allow
the computer to be an intelligent tutor that can adapt to the experience and level
of knowledge of the student.
 Information Management (Information Storage and Database Query)
In recent years, information relating to fields such as medicine, law, science,
engineering and many others has increased considerably.
No worker in either of these disciplines can have in mind all the information
needed to perform these tasks. The worker may not be aware that a certain
amount of information necessary to perform his job exists.
Computers can store large amounts of information. With current systems, the
user has to describe the desired information to the computer in great detail. The
user must have a precise idea of the information sought in order to make the
computer understand what information to find.
It would indeed be easier for the user to describe the information to find or the
problem to be solved in natural language and let the computer find the relevant
information or elements of solution.
The storage and retrieval of information is also used for other tasks of artificial
intelligence. A program that performs problem solving needs all the data possible
about the problem in question. This program also needs techniques and
troubleshooting rules that have been proven to be valid in solving similar
problems.
Researchers in the field of artificial intelligence define the act of searching for
information stored in a computer for use in problem solving as a representation of
knowledge.
 Robotics
In the case of certain tasks, such as the assembly of parts in factories, the
computer must not only be able to perceive its environment, but must also be
able to perceive changes in it. Like taking a piece and putting it on top of another.
A computer with this ability is called a robot.
One aspect of robotics is the mechanical aspect: no one has yet invented a robot
with limbs as flexible and controllable as a human being. This is a problem that
mechanical and electrical engineers will have to solve even before computer
scientists tackle the subject.
At the computer level, the main aspect of robotics is to make programs that can
allow the robot to perform the appropriate movements in relation to its
environment.
 Games
Since the 18th century, scientists and researchers have focused on making
machines and automatons capable of playing games such as chess and drafts.
In recent years, some computer researchers have focused on game modeling
and how to make efficient programs capable of playing games with acceptable
response times.
As part of this research, some programs that can play games (chess, tic-tac-to,
dominoes, backgamon, etc.) were carried out and analyzed.
Resolving programs that play games is a great application of artificial intelligence
for the following reasons:
- the board or the game environment and the rules of the game are easy to
model
- unlike modeling the environment and the rules of the game, it is difficult for
the computer to calculate the right moves or the right actions to perform. The
computer should analyze the game in a manner similar to a human gamer.
- there are some human masters of these games who are generally happy to
give their opinion on the performance of the game program. The scientists
who created the program will be able to use these reviews to improve the
program.
- tournaments are usually organized in most of these games and the
grandmasters can compete with the computer. The performance of the
computer can thus be compared directly with the human expert.
 Automatic programming (Code generation)
Writing and debugging a complex program is a time consuming task. A large
team of programmers can work several years to produce a compiler or an
operating system, and the result is never without errors. Generally, even if the
program is in its final version, it will still contain errors (bugs) which will affect the
proper functioning of the software until these errors are found and eliminated.
This situation characterizes software production as a victim of the "software
crisis".
One way to avoid this situation is to have the computer generate code from the
statements of the problem to be solved. Such a program generator application
would be an extension of current compilers and report generators. These
applications also produce programs, mail they ask the computer scientist to
describe the application to be produced in greater detail.
 Programmed logic
Sometimes scientists need to prove that a series of facts are a logical
consequence of other facts. A crown lawyer, for example, must prove beyond a
doubt and with supporting evidence that the accused committed the crime with
which he is accused. Programmed logic is the art of programming a computer so
that it can make these deductions.
Obvious applications of programmed logic are found in mathematics. A
mathematician starts with a small set of facts (called axioms) and deduces
interesting consequences (called theorems) from those facts. The mathematician
guarantees that in any situation where the axioms are true, the theorems will also
be true. We can therefore apply these theorems in scientific cases without having
to repeat the deductions of mathematicians.
The computer is thus able to perform mathematical proofs when we provide it
with theorems.
Another application of programmed logic is to prove that a program is correct.
This is an alternative to automatic programming. The human programmer writes
a program. The computer tries to prove that the program is correct; that is, it
solves the problem it was created to solve. If the computer is successful we can
use the program with confidence, otherwise the programmer will have to find out
why the proof failed, possibly due to an error in the program.
Other artificial intelligence programs also need programmed logic, especially
those involved with information retrieval and knowledge representation. Some
facts are stored in the computer. Other facts are looked for by the programmer or
program working on a problem. The computer should try to differentiate the
requested information from the available information.
HISTORICAL
Interest in intelligent machines can be traced back to antiquity.
The scientific roots of the discipline go back, however, to the first work on mathematical
logic and to the first theoretical and practical developments on automata and
computability. The outstanding works on automata and computability are those of
Babbage (the analytical machine, 1842) and especially the contemporaries Church,
Turing (the universal machine of Turing, 1936) and Von Neumann. It is to Alan Turing
that we owe the famous machine intelligence test.
From the beginnings of data processing (ENIAC, the first electronic calculator, born in
1944) some saw in the computer a potential competitor of human intelligence. Indeed,
the calculations made by this new machine would have required a long and painful labor
of intelligent men.
From then on, some researchers proposed algorithms intended to reproduce human
faculties.
Thus, around 1945, John Von Neumann and Oskar Morgenstein proposed a theoretical
solution to a whole class of problems such as strategy games and automatic
demonstration.
In the summer of 1956, a conference of academics was held at Dartmouth College to
study the following issue:
Any aspect of learning or any other characteristic of intelligence can in
principle be well enough defined that a machine could be created in order
to reproduce them.
This issue was raised by John McCarthy (the inventor of LISP) and his study created
artificial intelligence. This conference is considered the official birth of artificial
intelligence.
The first artificial intelligence programs also date from this period: a theorem
demonstrator in proposition logic (1956), a program playing chess (1957) and the LISP
language (1958).
The first years were marked by some contributions and above all a lot of optimism
regarding a vision of future applications of artificial intelligence: understanding a text in
natural language and beating a champion in chess seemed tasks within immediate
reach. The estimate was false, on the contrary it took ten years of meager results to fully
grasp the enormous difficulties of these problems and to develop approach strategies.
The end of the sixties was more productive and brought a real takeoff of the discipline.
Among other results, we find the “Principle of resolution” (1965), the A * algorithm (1968),
programs such as GPS (resolution of puzzles with heuristic of the situation-objective
deviation, 1969), the QA3 system. (based on first order logic, 1969) and early work on
MACSYMA (in 1968, by the Mathlab group at MIT, for assistance in solving mathematical
problems).
The decade of the 1970s was rich in contributions. It brought the essential bases in
representation of the knowledge and the first results on the difficult problems such as the
computer learning, the comprehension of the natural languages, the reasoning on the
time in evolutionary or uncertain situation. At this time also appeared methods and tools
for the development of real applications: expert systems, perception-vision by computer,
robotics, human-machine interfaces, understanding of speech and natural languages in
restricted contexts, programming environments and first symbolic processing machines.
The 1980s materialized these results. At the level of research in artificial intelligence, we
have a greater mastery of the tools and fundamental results acquired, and a more
precise perception of open scientific problems and their difficulty. In terms of
applications, we are witnessing the first commercializations and the corresponding
technological mastery.
RESULTS
Artificial intelligence researchers have failed to standardize the two artificial intelligence
simulation models:
 Same results - different way to get them
 Same results - same way to get them
A certain divergence still exists between these two models due to the fact that scientists
have not yet succeeded in formally modeling the behavior, the learning mechanisms and
the vision process of the human being.
The fact of a certain lack of evidence and absolute formalism does not prevent a whole
category of researchers from doing research in the field of artificial intelligence and
exploring in new directions.
In recent years, some relevant applications and results of this field have been transferred
from universities and private research institutes into commercial products.
The applications of artificial intelligence are finding more and more followers and many
companies and consumers find it very useful or more practical to use systems supported
by software based on artificial intelligence:
 Robotics applications (industrial or residential)
 Digital vision or pattern recognition (robotics, surveillance, remote sensing,
satellites, etc.)
 Tutorials
 Games, simulators
 Speech recognition
 Etc ...
Many of the commercial applications of artificial intelligence lie in the area of expert
systems.
An expert system is a computer program that simulates the knowledge and decision-
making of an expert in a particular area of knowledge.
An expert system program contains a database (knowledge base) and a set of rules
(called heuristics) for making decisions.
Some of these more well-known expert systems are used in medicine, chemistry, and
petroleum research.
The programming of artificial intelligence applications is almost completely dominated by
two languages: LISP and PROLOG. In the United States, almost all artificial intelligence
applications have been written in LISP. In Europe and Japan, many applications have
been developed in PROLOG.
The personal computer is another determining element that has influenced the
development of artificial intelligence. As users demand more and more about the ease of
use of software, software companies are incorporating artificial intelligence techniques
into their software in order to stay competitive.
The potential of artificial intelligence is prompting many investors to finance companies
making software based on artificial intelligence. Some multinational companies such as
IBM, Sperry, DEC and General Motors already have artificial intelligence software.
There is now some pressure on the artificial intelligence community to create practical
applications as quickly as possible. This pressure is created by the fact that developers
of artificial intelligence applications want to enrich themselves and take advantage of
user demand for software that is more flexible and easier to use.
Some computer designers, and in particular the Japanese, want to take the computer
sales market by creating fifth generation computer systems based on artificial
intelligence techniques. The fifth generation is characterized by parallel processing and
the inclusion of artificial intelligence concepts such as speech recognition.
CHALLENGES
The study of artificial intelligence or (AI) is in principle as complex and vast as the study
of human intelligence. This science also includes the development of methods of
producing and understanding natural language, the ability to see or recognize certain
shapes or objects, the ability to make logical inferences or make decisions based on
incomplete information. This science also encompasses making generalizations and
learning by trial and error.
The study of artificial intelligence focuses on two aspects of the reproduction of artificial
intelligence by a machine:
(1) In the first aspect, the aim is to achieve the same results that humans could
achieve, although the processes carried out by machine and humans do not
need to be the same. (This model of the same results and different processes
is exemplified in the way in which humans and computers perform arithmetic
operations).
(2) In the second aspect, the goal is not only for the computer to achieve the
same results as a human, but the computer must also achieve these results
in the same way and following the same rules and procedures.
Science fiction computers and robots, such as HAL in the movie “2001: A Space
Odyssey” and C3P0 in the “Star Wars” movie, have intelligence similar to that of human
beings. Currently, these machines are the domain of science fiction. Too many aspects
of human intelligence are still misunderstood for computers to be endowed with human
intelligence in the near future.
Fortunately, intelligence comparable to that of humans is not necessary for most current
applications of artificial intelligence. A robot working in a warehouse only needs to
recognize and manipulate the items it has to load, unload and store. This robot doesn't
need to be able to discuss philosophy or play chess. Moreover, a program that plays
chess does not need to perceive its external environment and its world is limited to its
chess board.
Although the ultimate goal of artificial intelligence is the pursuit of intelligence
comparable to that of human beings, research in the field of artificial intelligence begins
to bear fruit immediately by creating programs that emulate certain aspects. of artificial
intelligence in a limited form.
The techniques developed by artificial intelligence research are applicable to many
cases and are resources used by programmers when developing applications.
These applications benefit from increased flexibility, more complex problem solving and
easier user interaction thanks to artificial intelligence techniques.
LIMITS
In the early years of artificial intelligence development, only a few researchers took the
two artificial intelligence simulation models seriously:
 Same results - different way to get them
 Same results - same way to get them
However, in the 1960s and 1970s, the success of some complex programs, such as
programs for playing chess, proved that some computer programs could sometimes
surpass human intelligence.
Such results have therefore revived the debates around artificial intelligence and
university researchers have therefore started to seriously research artificial intelligence
around the two models.
In the late 1970s, research in artificial intelligence faced a dead end. Indeed, research in
medicine and psychology cannot yet allow researchers to formally model how human
beings recognize spoken language, recognize images, learn and understand new
concepts.
Computer simulation of intelligent human behavior is based on theoretical rules which
are not necessarily the natural learning process of humans.
We can therefore conclude for the moment that research in artificial intelligence has not
yet succeeded in realizing the problem raised by McCarthy:
Any aspect of learning or any other characteristic of intelligence can in
principle be well enough defined that a machine could be created in order
to reproduce them.
This is how artificial intelligence (AI) appears, a field as ill-defined as intelligence itself.
Unlike traditional computing, where computers mainly handle digital information, artificial
intelligence mainly uses these machines to manipulate symbolic information
(understanding natural language, machine translation, games, demonstration of
theorems, etc.).
Quickly, despite theoretical progress and some spectacular programs, disappointment
replaced the optimism of the beginnings. The algorithms used are based on a more or
less exhaustive analysis of the possibilities and therefore the execution times increase
rapidly and exponentially depending on the complexity of the problem. This is called the
combinatorial explosion.
In 1961 John Mc Carthy proposed an algorithm to try to reduce this constraint (alpha-
beta algorithm making it possible to prune the trees explored by AI programs) but there
was very little fallout from this first period.
This relative failure is partly due to researchers who believed possible the construction of
a General Problem Solver (GPS) and that from a single statement of a method of
resolution and some data of departure. Thus the programs of that time made little or no
use of the knowledge of specialists in the subject dealt with.
Some researchers then decided to completely change the approach to the problem: by
restricting their ambitions to a specific area, they tried to reproduce the way in which the
experts carry out their reasoning (deductions, know-how, etc.). To do this, they relied in
particular on a large body of knowledge on the subject dealt with, the very knowledge
used by specialists in the field. This gave birth to the field of expert systems.
The objective of these programs would no longer be to prove, or to find the optimal
solution to a problem, but rather the best possible answer in the state of knowledge on
the considered field. As this response corresponds to that which the experts would arrive
at, it is therefore necessary to introduce their experience and their reasoning method into
these expert systems, in order to provide less competent users with decision-making
support.
This phenomenon is the reflection of the compromise between generality and efficiency,
and is based on the fact that in humans, the most gifted individual in his intellectual field
has a dismal performance in another. This is due to the considerable mass of knowledge
that man has been able to accumulate over the centuries, in all disciplines.
Expert systems take this fact into account, because it is clear that in order to obtain
programs with very good performance, it is necessary that these programs work in well-
defined areas, knowing how to learn the knowledge in this specialty, manage them and
structure.
In 1950, Alan Turing proposed the following method to determine if a machine can think.
His method has since been known as the Turing Test. To perform this test, we will need
two people and the machine we are evaluating. One person plays the role of the
interrogator. The interrogator will be in a separate room, from the computer and from the
other person, with which he can communicate using a computer terminal. The
interrogator can ask questions of the person or of the machine, but does not know who
they are talking to. The interrogator only knows them as A and B, and seeks to determine
who is the human being and who is the machine. The purpose of the machine is to
mislead the interrogator into believing that she is the person. If the machine succeeds in
doing this,
The most important question, however, is how much knowledge a machine would need
to have to take the Turing test. We can still wait a long time for a machine to pass the
Turing test. This would be the case with a perfect artificial intelligence program. Some
people think no machine will ever do it. We must now be content with an incomplete test.
COURSE 02
INF-38299 - ARTIFICIAL INTELLIGENCE
 THE REPRESENTATION OF KNOWLEDGE
INTRODUCTION
Most artificial intelligence systems are made up of two basic parts:
 a knowledge base: contains facts about objects and their
relationships in a chosen field. The knowledge base can also
contain concepts, theories, practical procedures and their
associations. The knowledge base is the source of
intelligence in the system and will be used by the inference
mechanisms for reasoning and drawing conclusions.
 a mechanism (inference engine): the inference mechanism is
a set of procedures that are used to examine the knowledge
base in a methodical way to answer questions, solve
problems or make decisions within of the domain. The
computer therefore emulates human thought on a subject
determined by the action of the inference mechanism which
searches the knowledge base in order to find answers and
solutions.
Representing knowledge in a computer consists of finding a
correspondence between the external world (external form) and a
symbolic system (internal or physical form) allowing reasoning.
The expert in the field responsible for transmitting his knowledge to
the SE, provides this in its external form. The knowledge acquisition
mechanism encodes this knowledge fragment in internal form, ie a
data structure (table, list, matrix, etc.), before adding it to the
knowledge base.--
The OS uses the logical form, which is generally defined in terms of
index or symbolic keys, to access this data structure and restores the
external form for any dialogue with the user.
Just as there is no universal programming language, the ideal
formalism to represent the knowledge of an SE has not yet been
found.
This is how we can distinguish between three types of representation:
 The procedural representation (finite automata, programs)
which makes the inter-relations between knowledge
fragments explicit but which is difficult to modify.
Benefits :
1. Facilitates the use of Meta-knowledge by allowing the
problem to be broken down explicitly.
2. The pure declarative does not exist, it is essential at the
lowest level.
 Declarative representation (calculation of production rules
predicates, semantic networks) which creates knowledge
fragments independent of each other and therefore easily
modifiable. This knowledge is combined by a general
mechanism of reasoning and deduction.
Advantages: readability, economy, flexibility and ease of
modification.
 Mixed representation (structured objects: frames, script
diagrams, objects ...) mixing the two previous modes of
representation.
It is not our purpose to talk about the first mode of representation that
everyone knows, on the other hand, we will examine the other two
modes in detail.
KNOWLEDGE REPRESENTATION METHODS
Building the knowledge base: knowledge in a given area must be
grouped and codified. This knowledge must be organized and
arranged in a systematic order (knowledge engineering).
Knowledge representation methods have been categorized as:
 declarative (represents facts and assertions): includes logic,
semantic networks, frames and scripts.
 procedural (represents actions and procedures): include
procedures, subroutines and production rules
LOGIC
Logic is the oldest form of representation of knowledge, logic is the
scientific study of the process of reasoning and the systems of rules
and procedures that provide assistance to the process of reasoning.
Logic is considered to be a discipline of philosophy. Its origin dates
back to ancient Greece.
A logical process is structured as follows:
 information is given, statements are made and observations are
noted. This data is the input to the logical process and is called the
premises.
 the premises are used by the logical process which creates
outputs in the form of conclusions called inferences
 with this process, facts that are categorized as true can be used to
derive new facts that are also true.
There are two basic types of reasoning: deductive and inductive.
These two types of reasoning are used in logic to deduce inferences
from premises.
DEDUCTIVE REASON
When general premises are used to derive specific inference, the
process is called deductive reasoning or deduction. The process of
reasoning evolves from a general principle to a specific conclusion.
The process of deduction usually begins with a syllogism (statement
of premises and inferences). To illustrate this process, let's look at an
example:
Major premise: I don't jog when the temperature exceeds 30 degrees
Celcius
Minor premise: Today the temperature is 32 degrees celcius
Conclusion; I will not be jogging today
INDUCTIVE REASONING
Inductive reasoning uses a number of established facts or premises
in order to arrive at a general conclusion. A syllogism is used to
define the problem. To illustrate this process, let's look at an example:
Premise: Defective diodes cause electronic equipment failures
Premise: Faulty transistors cause electronic equipment to fail
Premise: Faulty integrated circuits cause electronic equipment to
malfunction
Conclusion: Defects in semiconductor-based electronic components
are one of the major causes of electronic equipment
failures.
The conclusion of an inductive reasoning is never final or absolute.
COMPUTER LOGIC / COMPUTATIONAL LOGIC
In order for a computer to perform reasoning using logic, methods
must be used to convert syllogisms and the deductive or inductive
reasoning process into a format that the computer can manipulate.
The result is what is known as symbolic logic or mathematical logic. It
is a system of rules and procedures allowing the generation of
inferences from different premises and a set of logical techniques.
These methods are generally known as computer logic.
There are two basic forms of computer logic:
- propositional logic or propositional calculus
- logic of predicates or calculation of predicates (first order logic)
PROPOSAL LOGIC
A proposition is a statement which can take the values true or false.
This is a premise that can be used in order to obtain new propositions
or inferences. The rules are used to determine whether the new
proposition is true or false.
In propositional logic, we use symbols such as letters of the alphabet
to represent different propositions, premises, or conclusions.
Consider, for example, the propositions used below in a simple
deduction process:
A = The postman comes from Monday to Saturday
B = It is Sunday today
C = The postman will not come today
In order for our model to be more faithful to reality, we must have
other means of representing knowledge than in simple propositions
(B = It is Sunday today). Real-world problems involve several
interrelated propositions. To form more complex premises, two or
more propositions can be combined using logical connectors. These
connectors or operators are designated as the logical operators AND,
OR, NEGATION, INVOLVED and EQUIVALENT.
Connector Symbol
AND , , ,.
OR V, ,. +
NEGATION , ~
INVOLVED , 
EQUIVALENT 
NEGATION
AT  AT
V F
F V
A = It's raining today
 A = It's not raining today
AND
D E D E
F F F
F V F
V F F
V V V
D = The car is black
E = The automobile has a six-cylinder engine
D  E = The automobile is black and has a six cylinder engine
OR
P Q P  Q
F F F
F V V
V F V
V V V
P = The moon is a satellite
Q = Earth is a satellite
P  Q = The moon or the earth is a satellite
EQUIVALENT
This connective can be interpreted as being "if and only if"
P Q P  Q
F F V
F V F
V F F
V V V
P = The human being breathes
Q = There is air
P  Q = The human being breathes if and only if there is air
INVOLVEMENT
This connective means that if proposition A is true, then proposition B
is also true
IF A THEN B
AT B AT  B
F F V
F V V
V F F
V V V
A = The automobile engine is defective
B = I cannot drive today
AT  B = If (the automobile's engine is faulty) THEN (I cannot drive
today)
CALCULATION OF PREDICATES (FIRST ORDER LOGIC)
Although propositional logic is a way to represent knowledge, it is not
widely used in artificial intelligence applications. Since propositional
logic is based on complete statements which can only be true or
false, its ability to represent real world knowledge is limited. This is
why the discipline of artificial intelligence uses the calculation of
predicates (first order logic).
In the computation of predicates, a proposition or premise is divided
into two parts:
 arguments (objects): arguments are the individuals or objects
treated by the assertions - names serving as subject or objects
of a sentence
 predicates (assertions): assertions made with objects - verb or
part of the verb
The two parts are combined to create a proposal:
PREDICATE (Individual [object] 1, Individual [object] 2)
Examples
Example 1:
The car is in the garage
IN (automobile, garage)
IN = Products (assertion)
Automobile = Argument (object)
Garage = Argument (object)
Example 2:
Proposal: Jean loves Marie
Expression of the predicate calculation: AIME (Jean, Marie)
Other formats are also used such as:
(in auto garage) or (likes Jean Marie)
In other cases, the proposition may have only one argument. Some
examples are:
The door is open
OPEN (Door)
John is a man
Male (Jean)
VARIABLES
In the calculation of predicates, letters can be substituted for
arguments. The x or y symbols can be used to denote individuals or
objects. The previous example "John loves Mary" can be expressed
in variables of the form x = John and y = Mary. The proposition then
becomes:
Like (x, y)
If variables are used, then the defined proposition is true for all
names substituted for variables. Using this system, a knowledge base
can be defined. Knowledge, expressed in the computation of
predicates can be manipulated to generate inferences.
Example:
Jean loves Marie
Raymond loves Marie
John = x, Mary = y, Raymond = z
Likes (x, y) AND Likes (z, y) INVOLVES  Like (x, z)
The expression means that:
If (Jean loves Marie) AND (Raymond loves Marie) THEN (Jean does
not like Raymond)
INSTANTIATION
Instantiation is the name given to the process of assigning a specific
object or individual to a variable. This object or this individual
becomes an instance of the variable. Associating the variable x with
the individual Raymond is an example of instantiation (x = Raymond).
WELL FORMED FORMULAS (WELL FORMED FORMULAS) - WFF
(WELL FORMED FORMULAS)
Well-formed formulas are logical expressions consisting of:
 variables
 predicates
 quantifiers
1. universal (): quantify all the elements (means "for all")
2. existential(): quantify us only element (means "it exists")
 connective
Examples:
All Texans are citizens of the United States
(x) [Texan (x)  Citizen of the United States (x)]
Cars are red
(x) [automobile (x)  Red (x)]
PRODUCTION RULES
The basic principle of programming in production rules is that each
rule is an independent piece of knowledge (we say: granule), that is,
it contains all the conditions for its application. A rule can translate a
relation, semantic information or a conditional action.
As a result, it is only the comparison between the triggering
conditions of a rule and the existing facts which makes it possible to
"filter" the rules to retain only those which are applicable. (The
premise part is also called the filter of the rule, "pattern" in English.
The SEs are also often designated by the term "Pattern Directed
Inference Systems" that is, inference systems directed by the filters).
A production rule is generally of the form:
If Premise (Antecedent) Then Consequential.
The premise or antecedent represents a situation
The consequent states a particular action or conclusion that applies if
the premise is true.
The most well-known forms of production rules have the following
formats:
Antecedent Consequent
Situation Action
Premise Conclusion
Examples:
IF the share price drops below $ 250.00
THEN buy 100 shares
IF the temperature exceeds 30 degrees Celsius
THEN start the fan
IF the automobile runs out of gas
AND a gas station is in sight
THEN go fill up with gasoline
IF the temperature exceeds 30 degrees Celsius
OR the manual control is activated
THEN start the fan
A set of production rules forms a knowledge base which becomes a
component of a production system.
A production system includes a knowledge base, memory, and an
inference (control) mechanism.
Some initial conditions or goals to be achieved are provided to the
working memory. The inference and control mechanism searches the
knowledge base for rules that can be associated with the initial
conditions. These rules together with the initial conditions or goals
provide the basic knowledge used to solve the problem. The best
known example of a production system is an expert system.
This method of representation used in the majority of ES (MYCIN,
DENDRAL, LITHO, DRILLING ADVISOR, R1, DELTA ...) has certain
advantages due to this structure:
 Ease of modification, due to the modularity of knowledge.
 The more rules the system has, the more powerful it is (in
theory).
 Very easy to read the rules and therefore easy to write.
 Possible introduction of likelihood coefficients to weight
knowledge.
COURSE 03
INF-38299 - ARTIFICIAL INTELLIGENCE
 THE REPRESENTATION OF KNOWLEDGE
SEMANTIC NETWORKS
This formalism, whose authorship is generally attributed to Quillian in
1968, allows the representation of knowledge in the form of graphs:
 Nodes represent concepts (objects or events).
 The arcs reflect the relationships between these concepts
This description can be put in the form of a n-tuple:
 Sub-set of (chair, furniture)
 Has (chair, backrest)
 Has (my grandmother's chair, arms)
The "furniture" node represents a class of objects whose node
"chair" is a special element.
The same goes for the "chair" and "my grandmother's chair" nodes.
This hierarchical structure allows nodes at lower levels to inherit
properties from nodes at higher levels.
Thus, we can deduce from the previous diagram that my
grandmother's chair has a backrest. On the other hand, as far as the
number of legs is concerned, a chair in general (object class) has
four, but my grandmother's chair in particular has three. The lower
level properties (exceptions) correct the upper level properties
(default values).
A semantic network can express any sentence and moreover
important applications in understanding natural language have been
realized.
Let us quote a slightly more complicated example: "The crow held the
cheese proudly until the evening".
Semantic networks can also model quantifiers, implications ...
But all these representations are only operational if there are
procedures that manipulate them. These procedures work like a
unification algorithm, that is to say they try to replace the variables
(unknowns whose value we are looking for) by constants, by
comparing the request and the set of assertions.
For example, the query "Which chair has a number of legs equal to
three?" will be represented by:
The study of the diagrams allows easily to find "X = chair of my
grandmother".
But most often, the answer to a question is not immediate and
requires a journey through the network, so as to use the relationships
or attributes characterizing the entities involved.
One of the drawbacks of this representation is the combinatorial
explosion of the information search when the number of nodes and
arcs becomes too large.
There is therefore a compromise to be found between the complexity
of the data structure and the complexity of its interpreter.
Semantic networks have been used to build ES, PROSPECTOR
which works in the field of mineral geology is the one which makes
the greatest use and with very good results.
However, work on this formalism has focused more on finesse,
consistency of representation of concepts and philosophical
implications than on practical applications.
The structuring of semantic networks has gradually led to hybrid
representations between production rules and structured objects.
STRUCTURED OBJECTS
The different formalisms of knowledge representation that we have
just studied favored the declarative aspect of knowledge as well as its
inferential nature (logic, rules of production).
However, the knowledge that is not inferential (example: variation
around a prototype) was difficult to represent.
Representation in structured objects is an attempt to represent, more
conveniently than by inference, certain forms of knowledge.
The term structured object covers various names such as:
 Frames, a notion launched by Minsky.
 Schemes, in the work on memory.
 Scripts, which describe the sequence of stereotypes of events.
 Prototypes, or units in KRL.
 Objects, in Smalltalk, Flavors, Mering, Loops ...
 Shapes and classes, in Simula.
 Actors, in Plasma.
 Abstract types.
This representation can be considered as an extension of semantic
networks. Extension incorporating procedural knowledge and
introducing a conceptual rigor absent in this representation.
An object contains a certain number of attributes (or slots) which are
the names of the properties characterizing the object. For example,
we will speak of "Color", of "Material", of "Number of legs" for a
"Chair".
These attributes contain facets which are standard (value, default,
validity interval, etc.).
On the other hand, an object is part of a hierarchy and therefore has
more general objects than it, with which it is linked by pointers (Sort
of).
Finally, procedures are associated with objects to calculate precise
values (procedural attachments).
In summary, a structured object contains attributes having several
facets, a special attribute that points to other objects and procedures
associated with it.
This object can be considered as "ideal" and serving as a basis for
comparison to analyze other objects.
It is very similar to semantic networks.
Let us examine the main existing facets through the study of an
example.
Example:
CHAIR (class)
Kind of (movable value)
Number of feet (default 4)
Color ((possibilitdés (white blue brown))
(brown default))
Age (restriction (> 0) (<700))
MY GRANDMOTHER'S CHAIR (object)
Sort of (chair value)
Number of feet (value 3)
Color (white value)
Material (wood value)
Age (value 50)
 Value designates the value of an attribute.
 Default indicates the default value of the attribute if nothing
else is specified.
 A priori, the object "my grandmother's chair" would have
been assigned four feet by inheriting the default value from
its parent "chair", but the value 3 replaces it.
Restriction is a list of predicates which should return TRUE
when applied to the value that we are trying to assign to the
appropriate attribute.
 Possibilities, special case of restriction where the exhaustive
list of possible values is indicated.
 Interval, another way of expressing a restriction.
Example: Age (range [0 -700]).
 Procedure (method), used to call a function calculating the
value of the attribute concerned. It's a kind of procedural
attachment. For example, we can call a function that will
calculate the day of the week according to the given date ...
 Daemon, another form of procedural attachment that
automatically calls a function each time the value of the
attribute concerned changes. For example, in the event of a
change in color (value) of an indicator light attribute, a
message could be printed automatically to warn the user.
At the present time and to our knowledge, there is no SE using only
structured objects. In general, object language is used to represent
static knowledge, descriptive and production rules are used to make
inferences.
However, object-oriented languages are more and more widespread
in computing thanks to their modularity and ease of reading.
In AI, research is underway to integrate this mode of representation
with first-order logic as well as to implement inference engines using
object-oriented languages.
We have just seen the different approaches used to represent
knowledge in ES, it remains to study the control structure
manipulating this knowledge.
CONTROL STRUCTURES IN EXPERT SYSTEMS
The inference engine is the heart of the SE, it is it which, fed by the
knowledge base, dynamically builds the reasoning, deciding which
rules to trigger and in what order.
The reasoning mechanisms using the production rules are those of
formal logic: the "modus ponens" and its counterpart the "modus
tollens".
MODUS PONENS
So far we have studied systems representing facts and knowledge in
symbolic form. The practice of artificial intelligence ensures that
knowledge must be used to make inferences, reason, answer
questions or draw conclusions.
The techniques used by artificial intelligence use the various rules of
inference to manipulate logical expressions and create new facts.
These theories assume that if the original propositions are true, then
the conclusions will also be true.
The simplest rule of inference is the "modus ponens" which makes it
possible to assert from the proposition "if A then B" and from the
assertion A, to deduce B.
[AT  (AT  B)]  B
If A
If A, then B
So B
Example:
A = It's sunny
B = We will go to the beach
AT  B = If (it's sunny) THEN (we'll go to the beach)
SO (we will go to the beach)
MODUS TOLLENS
The "modus tollens" deduced from the same rule and from not B, not
A.
[B  (AT  B)]  AT
If A, then B
B
Therefore AT
Example:
A = It's sunny
B = We will go to the beach
AT  B = If (it's sunny) THEN (we'll go to the beach)
B = We will not go to the beach
SO (it's not sunny)
OPERATION OF INFERENCE ENGINES
However, whatever the reasoning mode used, the basic cycle of an
inference engine (work cycles linked to achieve the result) comprises
four phases:
 Selection phase, of a subset of the fact base (and rule base)
that deserves more attention than the rest of the base.
This restriction phase saves time for the next phase.
This choice is the expression of a strategy which causes the
inference engine to favor a given group of rules and not
another. We will not take this phase into account afterwards
because it does not modify the course of the following
phases.
 Filtering phase.
During this step, the inference engine compares the premise
part of the selected rules with the facts from the fact base to
determine the set of applicable rules.
The progress of this phase is shortened by the previous
phase which made it possible to considerably restrict the set
of rules which will be filtered with the fact base.
 Conflict resolution phase (or choice).
The result of this phase is the choice of the rule that will be
applied effectively.
This crucial phase also expresses a strategy that can be
very simple and unrelated to the context (the first rule in the
list, the least complex, the least used ...) or more complex
and taking into account the context (the most promising , the
most reliable, the least expensive ...)
The quality of this choice depends on the performance of the
inference engine which will more or less quickly deduce the
solution.
 Execution phase.
This phase consists in applying the rule chosen previously,
this action generally consists in adding one or more facts to
the fact base.
It is also possible that the application of this rule calls for
external procedures, modifies the fact base, questions the
user ...
The stopping of this cycle depends on the mode of reasoning
used.
Three modes of reasoning can be used, inducing certain differences
at the level of the basic cycle:
 Forward, data-driven chaining.
 The backward chaining, directed by the goal.
 Mixed chaining.
Let's take a closer look at each of these modes of reasoning.
FRONT CHAIN
The inference engine starts from the facts to arrive at the goal, that is
to say that it selects only the rules whose conditions of the left part
are verified (phase of filtering detection).
The choice phase (conflict resolution) is then applied to this set of
rules, to determine which rule to use first.
Applying this rule generally results in an update of the fact base
(execution phase).
This process is repeated until there are no more applicable rules or
the goal is reached.
This can be schematized as follows:
Entering the initial facts
Start
Filtering phase
Determination of all applicable rules
As long as the set of applicable rules is not empty AND the
problem is not resolved
Make
Choice phase
Conflict resolution
Apply the chosen rule (execution)
Possibly modify all the applicable rules
End do
End While
End
The efficiency of the inference engine lies in the relevance of the
decision taken (elected rule) during the choice phase.
It is this choice which conditions the speed with which the system will
arrive at the solution.
EXAMPLE
Either the knowledge base:
R1: If B and D and EA then F
R2: If D and G then A
R3: If C and F, then A
R4: If B then X
R5: If D A then E
R6: If A and X Then H
R7: If C then D
R8: If X and C then A
R9: If X and B, then D
Let the fact base: B, C and the goal: H
Solution corresponding to the choice of the first applicable rule in the
order of their numbering. Strategy in depth first (exploration of a
branch of the tree to the end and backtracking in case of failure).
Solution corresponding to a strategy selecting among the applicable
rules whichever has the greatest number of conditions, in case of
equality the lowest number rule is used
For example, R8 is preferred over R7 because it has two conditions
against one in R7.
In both cases, the nodes represent the succession of the different
states of the fact base and the arcs the rules that can apply to this
state.
Dashed arcs correspond to applicable rules that have not been used.
Only the rules corresponding to the arcs in solid lines were applied by
the inference engine.
When a rule has already been applied, the system does not apply it
again. Indeed, it would be pointless to deduce a fact which has
already been deduced.
We can therefore clearly see, on these two examples, that the
efficiency of an inference engine, that is to say the speed with which it
reaches the goal (which is measured in number of inferences),
strongly depends of the choice phase
However, this mode of reasoning has several drawbacks:
 The system triggers all applicable rules even if some are of
no interest.
 The fact base must contain enough initial facts for the
system to achieve the goal.
 The user must therefore provide the OS with all the
information it possesses even if some are unnecessary.
 In the event of failure, only one fact could achieve the goal
but the user is not informed since this process is not
interactive.
 This method risks running up against the combinatorial
explosion if the number of rules and facts is important, and
especially if the goal to be reached is not known, because it
is then necessary to apply all the applicable rules to deduce
all that can be deducted.
All the more so since many inference engines reasoning in
forward chaining, work in width first (application of all the
rules applicable at a given moment)
REAR CHAIN
The system starts from the goal (or a goal hypothesis) and tries to go
back to the facts to demonstrate it.
The selected rules are those whose right part (consequent)
corresponds to the desired goal.
The unknown conditions (left part) of these rules become so many
sub-goals to be demonstrated. This process is repeated until all sub-
goals are demonstrated, then the goal is reached, or until it is no
longer possible to select rules.
In this case, the system can ask the user to solve one or more sub-
goals (questions, tests ...) and the process starts over.
The failure occurs when the system can no longer select any rules,
nor ask the user questions (insufficient or inconsistent rules, or the
user cannot answer the questions of the OS).
This process can be schematized as follows:
Start
Filtering phase
If the set of selected rules is empty
So - question the user
If not
As long as the goal is not resolved AND there are still
selected rules
Make
Choice phase
Add the sub-goals corresponding to the left
part of the elected rule
If a sub-goal is not resolved
So solve it (start over)
End if
End do
End while
End if
End
Rules R2, R3 and R8 can be used to verify goal A.
The strategy used is very simple, since it consists of using the first
applicable rule, in their numbering order, to then seek to verify the
produced sub-goals one after the other (in-depth exploration first).
In case of failure, for example the sub-goal G could not be deduced,
there is backtracking in the tree structure and the last rule left aside is
in turn tried (R3 here).
Exploration can stop:
 when the initial goal has been demonstrated (this is the case
here),
 when all possibilities have been explored without success.
The system can then query the user on the unresolved sub-goal.
Note that this mode of reasoning consists in constructing
an AND / OR graph.
Backward chaining has a few advantages:
 The system asks questions only when necessary and after
exploring all possibilities.
 Often the search tree is smaller than in forward chaining.
 The process is interactive.
One of the risks of backward chaining is that of looping: to prove A,
you have to demonstrate B, to prove B, you have to demonstrate A ...
What some inference engines take into account (Mycin for example).
MIXED REASON
The inference engines offering forward chaining and backward
chaining alternately (bidirectional chaining) should not be confused
with those offering mixed chaining, that is to say combining these two
types of reasoning. In this case, the rules appeal simultaneously,
partly premise, to established facts (before) and others to be
established (rear).
As for bidirectional chaining, several possibilities exist. Generally, the
ES proceeds by forward chaining to determine partial conclusions
and then these hypotheses are then verified by backward chaining.
The inference engine can also alternately use forward and backward
chaining and examine at each cycle whether these two reasonings
meet. This allows you to go halfway and stop in the middle, or at the
junction point.
Another possibility is backward chaining on system goals or sub-
goals, with forward chaining propagation of verified sub-goals.
CHOICE OF A CONTROL STRATEGY
Whatever type of reasoning you choose, building an inference engine
involves two delicate steps:
- The definition of methods for selecting candidate rules. To do
this, each rule must be compared with all the basic facts or
with the goal. This comparison search operation is called
"pattern-matching" which may be preceded by a restriction
phase.
- The choice of the rule to be triggered.
This choice influences the performance of the system,
however, a man knows which knowledge to use in a given
situation but not an OS. He often has a rigid choice strategy
(the first, the most recently applicable ...) and in fact this
problem is poorly resolved. A more interesting way is the use
of meta-rules to guide the choice of the system. These are
also given in the form of production rules. Provided by the
expert, they express his strategies for choosing the rules.
The quality of the choices made to build these two elements
decisively affects the efficiency of the inference engine.
When it comes to choosing between forward and backward chaining,
we can say that no strategy is right for every problem.
Data-driven monitoring is very popular because such a program can
make inferences from the information provided by the user without
the user being forced to specify their question.
This approach is easily programmable and seems the most natural
when the system has a certain number of facts and the resolution is
done blindly, not knowing a priori what goal to achieve.
However, this strategy is ineffective for solving complex problems.
On the other hand, if one or more goals are to be reached, or to be
verified, it is more interesting to use the control directed by the goal,
in order to restrict the combinatorial explosion.
It seems that different approaches are necessary for different
problems and that the existence of both types of routing in an
inference engine is desirable.
This is all the more so as our knowledge is mostly empirical but also
sometimes theoretical.
However, forward chaining is indicated for the processing of empirical
knowledge, playing the role of meta-knowledge, and backward
chaining is suited to the confirmation of goals previously mentioned
with certain knowledge.
Backward chaining is also recommended in the case of incomplete
information or a dialogue with the user must be initiated.
In addition to this distinction between modes of reasoning, other
criteria are added to differentiate inference engines.
 Irrevocable and tentative strategies
A strategy is said to be irrevocable if the choices made (rules
applied) are never called into question. Conversely, a
strategy by attempts can call into question the application of
a rule if this choice results in failure. The inference engine
then performs a backtracking to try a previously discarded
rule
In general, backward chaining inference engines tend to use
an attempt-based strategy while forward chaining inference
engines use an irrevocable strategy.
 Strategies in depth or in width first
In an in-depth strategy first, the inference engine explores
the AND / OR tree of solutions, first in its depth (by exploring
a branch to the end).
Conversely in width first, the inference engine explores the
tree in its width (by exploring all possible branches).
A strategy can be in-depth and irrevocable or by attempts. The
same goes for the width.
In fact, the strategies by attempts are generally in depth first
because in width we explore the whole graph so backtracking is
not useful.
COURSE 04
INF-38299 - ARTIFICIAL INTELLIGENCE
1. Bratko Book, Chapters 1 & 2
PROLOG means programming in logic:
LOGIC PROGRAM
The PROLOG programming language is structured around a few
basic mechanisms:
 filtering ("pattern-matching")
 a tree structure of data (rules and facts)
 automatic backtracking
The PROLOG language is particularly well suited to problems
involving objects (and in particular structured objects) as well as
relationships.
These characteristics make PROLOG a powerful language for
artificial intelligence (AI), and more generally for all non-digital
programming.
Prolog is a widely used language mainly in academia and the world of
research. He is linked :
 formal logic and new forms of programming;
 to a modeling of reasoning;
 linguistic processing, writing grammars, analyzers;
 to databases: it is easy to transcribe SQL in Prolog and to
interface a database with a logic module written in Prolog.
HORN CLAUSES
The generalization of modus ponens in logic requires that the
statements be in a standard form called “Horn clauses” according to
the work of the mathematician Alfred Horn.
A Horn clause is a logical statement that can have the following
forms:
q1 AND q2 AND… AND qn  r [If (q 1 AND q2 AND… AND qn)
THEN r]
r  q1  q2  ...  sb
1. where r and qi are predicates and all variables are universally quantized.
PROLOG logical symbols
NATURAL
LANGUAGE
CALCULATION
OF
PREDICATES
PROLOG
and  ,
or  ;
only if  : -
negation  Not
Paradigm of logic programming
program = set of axioms
treatment = constructive proof of a goal statement
We call a logic program a set of Horn clauses.
Example 1:
Let the axioms be:
All men are mortal
(x) [Male (x)  Mortal (x)]
Socrates is a man
(x) [man (x)  (x = Socrates)]
We can reformulate the first axiom:
For all X, if X is a man, then X is mortal
(x) [Male (x)  Mortal (x)]
What we will translate in PROLOG by
mortal (X): - man (X).
man (socrates).
? - mortal (socrates).
Yes
Example 2:
parent (X, Y)
Database predicate which means: X is a direct parent of Y
Rule 1: grandparent (X, Y): - parent (X, Z) & parent (Z, Y)
This rule (1) reads: " X, Y if Z such that: X is a parent of Z and Z is
a parent of Y, then X is a grandparent of Y ”
Rule 2: ancestor (X, Y): - parent (X, Y)
Rule (2) reads: " X, Y if X is a parent of Y, then X is an ancestor of Y
”
Rule 3: ancestor (X, Y): - ancestor (X, Z) & parent (Z, Y)
Rule (3) reads:  X, Y if Z such that: X is ancestor of Z and Z is
parent of Y, then X is an ancestor of Y ".
2. FACTS
A fact is the most basic of statements.
Facts are statements that describe relationships between objects or
properties of objects, for example:
pupil (jean, 1975, info, 2).
pupil (catherine, 1974, info, 2).
pupil (luc, 1976, _, 1).
masculine (jeans).
masculine (luc).
female (catherine).
father (paul, jean).% paul is jean's father
mother (isabelle, jean).
The general form of a fact is as follows:
predicate (argument1, argument2,…).
A predicate is a symbol that translates a relation. Arity is the number
of its arguments. We identify a predicate by its name and its arity:
predicate / arity, for example mother / 2, pupil / 4.
UNIVERSAL FACTS
Variables are useful in the statement of facts.
Example: All people love Pepsi Cola
Like (X, PEPSI_COLA)
The variable X is then universally quantified
( x) [like (x, PEPSI_COLA)]
RULES
Rules make it possible to express conjunctions of goals. Their
general form is:
HEAD: - C1, C2, ..., Cn.
The head of the rule is true if each of the elements of the body of the
rule C1, ..., Cn is true. We call this type of rule Horn clauses.
son (A, B): - father (B, A), male (A).
son (A, B): - mother (B, A), male (A).
parent (X, Y): - father (X, Y).
parent (X, Y): - mother (X, Y).
here the intermediate variable Z is used
grand_parent (X, Y): - parent (X, Z), parent (Z, Y).
A predicate therefore corresponds to a set of rules or facts with the
same name and the same arity: the clauses of the predicate.
Many Prolog programs require that all the rules and all the facts of
the same predicate be contiguous - grouped together - in the program
file. We denote the predicate by its name and its arity, for example
son / 2, parent / 2, grand_parent / 2.
Facts are a special form of rules that are always true. The notation :
made.
is indeed equivalent to:
fact: - true.
Let us define a new predicate "ancestor / 2" determining the ancestor
X of Y by recursion:
Recursion termination condition if it is a direct parent.
ancestor (X, Y): - parent (X, Y).
Otherwise X is ancestor of Y if and only if there is Z, such that X
parent of Z and Z parent of Y.
ancestor (X, Y): - parent (X, Z), ancestor (Z, Y).
When executing a query, Prolog examines the corresponding rules or
facts in the order they are written to the program, from top to bottom.
It uses the first rule (or the first fact) of the predicate to answer. If it
fails, then it goes on to the next rule and so on until it has exhausted
all the rules (or all the facts) defined for that predicate.
When a rule is recursive, the Prolog interpreter recalls the predicate
of the same name by examining the rules (or facts) of this predicate
in the same order.
In the body of a rule, the comma "," is the symbol representing a
logical AND: the conjunction of goals. The symbol ";" represents the
logical OR, the disjunction of goals:
A: - B; vs.
is equivalent to
A: - B.
A: - C.
RECURSIVE RULES
Let us define a new predicate "ancestor / 2" determining the ancestor
X of Y by recursion:
 Recursion termination condition if it is a direct parent:
ancestor (X, Y): - parent (X, Y).
 Otherwise X is ancestor of Y if and only if there is Z, such
that X parent of Z and Z parent of Y:
ancestor (X, Z): - parent (X, Y), ancestor (Y, Z).
QUESTIONS OR REQUESTS
The second form of statements in logic programming is the question
or query.
Questions or queries are a means of obtaining information from a
logic program.
A question or query asks if a certain relationship exists between the
objects.
For example, the query:
father (abraham, isaac).
asks the logic program if the paternity relationship exists between
abraham and isaac
Once the program has loaded, you can ask questions about the facts:
masculine (jeans).
masculine (luc).
? - masculine (jeans).
Yes
? - masculine (françois).
No. (Not in the database)
EXISTENTIAL REQUESTS
Logically, query variables are existentially quantized, which means,
intuitively, that the query:
father (abraham, X)
means:
Is there an X such that Abraham is the father of X
( x) [father (abraham, x)]
Variables can be identified with all other values: with constants, with
compound terms, with the variables themselves. Constants start with
a lower case, variables start with an upper case.
? - masculine (X).
X = jeans;
X = luc;
No
The ";" character allows you to request the following solution. The
"Return" character stops the search for solutions.
? - student (X, Y, Z, 2).
X = jeans, Y = 1975, Z = info;
X = catherine, Y = 1974, Z = info <CR>
? -
TYPES OF PROLOG
In Prolog, everything is a term:
 Constants or atomic terms:
1. Atoms are alphanumeric strings that start with a
lowercase: jean, paul, toto1. You can transform a string
containing special characters (period, spaces, etc.) into
an atom by surrounding it with "'" characters. So 'marc'
and 'cube' are atoms.
2. The numbers: 19, -25, -3.14, 23E-5
 Variables start with a capital letter or the _ sign. _ all by itself
is an anonymous variable: X XYZ Xyz _x _3 _. The system
internally renames its variables and uses the _number
convention, such as _127 or _G127.
 Structures or compound terms consist of a functor with a
series of arguments. The arguments can be atoms,
numbers, variables, or structures such as:
1. pupil (Robert, 1975, info, 2, address (6, 'Frontenac',
'Rivière-du-Loup')). In the example, pupil is the main
functor.
UNIFICATION
In a question, if it succeeds, the variables unify vis-à-vis the other
terms. The terms can be composed as for example:
address (6, 'Frontenac', 'Rivière-du-Loup').
Add the term
student (robert, 1975, info, 2, address (6, 'Frontenac', 'Rivière-du-
Loup'))
in the file and let's consult it. Let's ask the question:
? - pupil (X, Y, Z, T, W).
X = robert
Y = 1975
Z = info
T = 2
W = address (6, 'Frontenac', 'Rivière-du-Loup')
The Prolog unifies the term of the question to the term contained in
the database. For this, it performs the substitution of the variables X,
Y, Z, T, W by terms, here constants and a compound term.
We note this substitution:
{X = robert, Y = 1975, Z = info, T = 2, W = address (6, 'Frontenac',
'Rivière-du-Loup')}
We say that a term A is an instance of B if there is a substitution from
A to B:
masculine (jean) and masculine (luc) are instances of masculine (X)
{X = john} or {X = luc} are the corresponding substitutions.
A term is ground term if it does not include a variable:
f (a, b) is founded
f (a, X) is not
a substitution is founded if the terms which compose it are founded:
{X = a, Y = b} is founded
{X = a, Y = f (b, Z)} is unfounded.
SHARED VARIABLES
We use the same variable to force two arguments to have the same
value. For example, to look for a student who would bear the name of
his field:
? - student (X, Y, X, Z).
The questions can be conjunctions and we can share variables
between the goals. To find all male students, we divide the variable X
between student and male:
? - pupil (X, Y, Z, T), masculine (X).
EXAMPLE: DEFINITION OF RELATIONSHIPS
% enumeration of facts
parent (pam, bob).% Pam is one of Bob's parents
parent (tom, bob).% Clause 2
parent (tom, liz).
parent (bob, ann).
parent (bob, pat).
parent (pat, jim).
male (tom).% Tom is male
male (bob).% Bob is male
man (jim).
female (pam).% Pam is female
woman (liz).
woman (ann).
woman (pat).
Pam Tom
Bob Liz
Ann Pat
Jim
% enumeration of rules
child (Y, X): -% Y is a child of X if
parent (X, Y).% X is one of the parents of Y
mother (X, Y): -% X is the mother of Y
parent (X, Y),% X is one of the parents of Y and
female (X).% X is female
grandparent (X, Z): -% X is one of Z's grandparents
parent (X, Y),% if X is one of the parents of Y and
parent (Y, Z).% Y is one of the parents of Z
sister (X, Y): -% X is sister of Y if
parent (Z, X),
parent (Z, Y),% X and Y have the same parents
female (X),% X is female
different (X, Y).% X and Y are different
ancestor (X, Z): -% X is a direct ancestor of Z
parent (X, Z).% Condition for stopping recursion
ancestor (X, Z): -% X is an indirect ancestor of Z
parent (X, Y),
ancestor (Y, Z).
REQUESTS
? - parent (pam, bob).
Yes
? - parent (pam, tom).
No
? - child (liz, tom).
Yes
? - mother (pam, bob).
Yes
? - grandparent (bob, jim).
Yes
? - sister (liz, bob).
Yes
? - ancestor (pam, jim).
Yes
? - parent (X, liz).
X = tom
? - parent (bob, X).
X = ann; (you must type a ";" to get the other answers
X = pat
? - parent (X, Y).
X = pam
Y = bob;
X = tom
Y = bob;
X = tom
Y = liz;
....
? - parent (Y, jim), parent (X, Y)
X = bob
Y = pat
X
Y
Jim
Parent
Parent
PROCESSING OF RULES (CLAUSES) BY TRAVERSING A
RESOLUTION TREE
Clause - Rule 1: ancestor (X, Z): - parent (X, Z).
Clause - Rule 2: ancestor (X, Z): - parent (X, Y), ancestor (Y, Z)
ancestor (tom, pat)
By rule 1 By rule 2
parent (tom, Y)
ancestor (Y, pat)
parent (tom, pat)
Failure 2. Y = bob
by parent (tom, bob)
ancestor (bob, pat)
By rule 1
parent (bob, pat)
Success
DECLARATIVE AND PROCEDURAL MEANINGS OF
PROGRAMS
PROLOG programs have two levels of meaning:
- declarative meaning: focuses on the relationships defined by
the program through the formulation of facts and rules. It
therefore determines what the program will produce.
- procedural significance: determines how results will be
obtained and how relationships will actually be evaluated by
the PROLOG system. This approach focuses on the generation
of state spaces and traversal of resolution trees.
IDENTIFICATION
It is possible to represent complex data in PROLOG language using
terms. The most important operation concerning terms is identification
(matching).
Given two terms, we say that they identify if:
 they are identical
 the variables present in the two terms can be instantiated so
that the terms of each object become identical
Example:
The two terms:
date (J, M, 1983).
date (D1, May, A1).
are identifiable.
One of the instantiations making the two terms identical is as follows:
 J is instantiated at J1
 M is instantiated to May
 A1 is instantiated at 1983
This is stated in a more compact way using the format used by
PROLOG to produce its results:
J = J1
M = May
A1 = 1983
PROCEDURAL SIGNIFICANCE
The procedural meaning is how the PROLOG inference engine
answers questions. Finding the answer to a question is like erasing a
list of goals.
This is only possible if the variables appearing for these purposes can
be instantiated in such a way that they logically derive from the
program.
The PROLOG language is therefore a procedure responsible for
executing a list of goals according to a given program. Executing a
goal means that we are trying to erase it.
The inputs and outputs of the execution procedure are:
 entry: a program and a list of goals
 output: a success / failure indicator, and an instantiation of
the variables
The meaning of the two output results is as follows:
 The pass / fail indicator is "yes" if the goals are satisfactory
and "no" otherwise. We will say that "yes indicates a success
and" no "a failure.
 The instantiation of the variables takes place only if the
execution is positive
program
3. execution
goal list
failure / success indicator
instantiating variables
THE ORDER OF CLAUSES AND GOALS
Consider the following clause:
p: - p.
This clause means:
p is true if p is true
At the syntax level, this clause is correct, but is redundant.
In fact, such a clause can cause problems for the PROLOG inference
engine.
Consider the question:
? - p.
Using the previous clause, the goal p is replaced by the same goal p,
which in turn is replaced by p, etc. PROLOG thus enters an infinite
loop without noticing that it is not progressing.
This example is a good way to make PROLOG loop, but it can also
happen in other cases as a result of poor arrangement of goals inside
clauses.
By referring to the declarative semantics of PROLOG, we can change
without affecting the declarative meaning (logic):
 the order of clauses in the program
 the order of goals in the body of clauses
Changing the order of goals in the body of clauses influences the
traversal of the resolution tree by the PROLOG inference engine.
This can generate infinite loops (combinatorial explosions).
Combinatorial explosions are generally signaled to the user by the
PROLOG language by a message indicating a stack overflow.
USING THE PROLOG INTERPRETER
We load or replace the (update) file in the Prolog interpreter with the
command:
? - consult (filename).
or with the shortcut:
?- [file name].
Under the LINUX system in console mode:
pl -s filename.pl
Programs are usually in files with the ".pl" suffix. To compile and load
a program:
? - consult (name_of_file).
where filename is an atom, for example:
? - consult ('file.pl').
or the shortcut with the command:
?- [file name].
for example
? - ['file.pl'].
Another shortcut with SWI:
? - [file].
Loading multiple files simultaneously
? - ['file1.pl', 'file2.pl'].
Once the files are loaded, you can run the commands. They end with
a period ".":
? - man (socrates).
Conjunctions of goals are separated by ",":
? - large (X), blue (X), on_the_cube (X).
You can also include directives in a file by the instruction:
: - clause_to_execute.
Directives are clauses that the interpreter will execute when loading
the program.
The content of the loaded file is displayed by:
? - listing.
The display of a particular clause, here father, is done by:
? - listing (father).
If we modify the program in the file, we can update the database by
(Not with SWI where we can only consult):
? - reconsult ('file.pl').
The reload shortcut is:
? - [-'file.pl '].
Finally, we leave Prolog with
? - halt.
COURSE 05
INF-38299 - ARTIFICIAL INTELLIGENCE
2. Bratko Book, Chapters 3 & 4
3. CHAPTER 3
In this chapter we will study a special notation for lists, one of the
simplest and most useful structures, as well as some typical
programs for manipulating them. We will also look at elementary
arithmetic and operator notation, which often improves the readability
of programs. With these three elements, the basic Prolog of the
second chapter becomes a comfortable programming environment.
1. REPRESENTATION OF LISTS
The list is a basic data structure, widely used in non-numeric
programming. A list is a sequence of any number of objects, such as
anne, tennis, tom, ski. This list can be written as follows in Prolog:
[anne, tennis, tom, ski]
However, this is only the outward appearance of the list. As we have
already seen, all structured objects in Prolog are trees. Lists are no
exception.
How can a list be represented by a standard Prolog object? We have
to consider two possibilities: either the list is empty or it is not (!). In
the first case, the list is simply written as an atom: [].
In the second case, we can consider that the list is made up of two
parts:
 the first object, called the head of the list,
 what's left of the list, called the tail.
For our example
[anne, tennis, tom, ski]
the head is anne, and the tail is the list
[tennis, tom, ski]
In general, the head can be anything (any Prolog object, like a tree or
a variable), but the tail must be a list. The head and tail are then
combined by a special functor to give structure. The choice of this
functor depends on the implementation of Prolog, but here we will
assume that it is the point:
. (Head, Tail)
Since Queue is a list, it is either empty or in turn made up of a head
and a tail, which allows lists of any length to be represented. The
following term therefore corresponds to our example list:
. (anne,. (tennis,. (tom,. (ski, []))))
The figure gives the associated tree structure. Notice that the empty
list appears among the terms, because the penultimate queue is the
list consisting of a single object:
[ to ski ]
However, the tail of this list is the empty list:
[to ski] =. (to ski, [])
This example shows how the general principle of data structuring in
Prolog also applies to lists of any length. Likewise, it highlights the
fact that the raw representation of a list using the dot functor can
produce relatively confusing expressions, especially if the tail of the
list is made up of many nested subterms.
This is the reason why it is preferable to use the notation proposed by
Prolog, consisting in putting the rest of the terms of the list in square
brackets, the choice being possible for the programmer.
It should not be forgotten that behind this facade, our lists are
represented internally as binary trees, and automatically converted to
the most readable form when they are printed.
It will therefore be possible to have the following exchange with
Prolog:
? - List1 = [a, b, c],
List2 =. (A,. (B,. (C []))).
List1 = [a, b, c]
List2 = [a, b, c]
? -Leisure1 =. (Tennis,. (Music, [])),
Leisure2 = [skiing, eating],
L = [anne, Loisirs1, tom, Loisirs2].
Hobbies1 = [tennis, music]
Leisure2 = [skiing, eating]
L = [anne, [tennis, music], tom, [skiing, eating]]
This reminds us that the elements of a list can be objects of any type,
and in particular lists.
It is often convenient to treat the tail of a list as a whole.
For example:
L = [a, b, c]
We can write:
Queue = [b, c] and L =. (A, Queue)
To express this in the form of a list in square brackets, Prolog
provides us with a new notation, the vertical bar, which separates the
head and the tail:
L = [a | Tail]
This notation is actually much more general: we can write any
number of elements followed by a "| », Then from the list of remaining
objects. Which gives the following ways of writing our list:
[a, b, c] = [a | [b, c]] = [a, b | [c]] = [a, b, c | []]
To summarize:
 A list is a structure that is either empty or made up of two parts:
a head and a tail, the latter itself being a list.
 Prolog manages lists as a special case of binary trees. To make
it easier to read, Prolog allows special notation:
[Object1, Object2, ...]
or
[Head | Tail]
or
[Object1, Object2, ... | Others]
2. LISTS OPERATIONS
Sets can be represented by lists, with one difference: the order of the
elements in a set does not matter, while this order is essential in a
list.
The same object can also appear there several times. The fact
remains that the most common operations that can be performed on
lists are similar to set operations.
Among those:
 checking for the presence of an object in a list, which
corresponds to the set membership test
 the concatenation of two lists, to obtain a third one, which
corresponds to the set union.
 adding a new object to a list, or deleting an object.
In the rest of this section, we show how to program these operations
on lists, as well as a few others.
1. MEMBERSHIP
Define the membership relation as being:
member (X, L)
where X is an object and L is a list. The goal member (X, L) is verified
if X appears in L. For example:
member (b, (a, b, c])
is right
member (b, [a, [b, c]])
is not true, however
member ([b, c], [a, [b, c]])
ballast.
The program that corresponds to this relationship can be based on
the following observations:
X is a member of L if
(1) X is the head of L, or if
(2) X is a member of the tail of L.
Two clauses are enough to write this, the first being a simple fact, and
the second a rule:
member (X, [XI Queue]).
member (X, [Head I Tail]): -
member (X, Queue).
2. CONCATENATION
To concatenate two lists, we define the relation
conc (L1, L2, L3)
L1 and L2 are two lists, while L3 is the result of their
concatenation.
for example
conc ([a, b], [c, d], [a, b, c, d])
is true, however
conc ([a, b], [c, d], [a, b, a, c, d])
is wrong.
In our definition of conc, we still have to consider two cases,
depending on the first argument L1:
If the first argument is the empty list, then the second and the third
argument must be the same list (let's call it L), which is
expressed in Prolog by the following fact:
conc ([], L, L).
If the first argument to conc is a non-empty list, then it has a head
and a tail like this:
[X | L1]
The figure illustrates the concatenation of [XI L1] and a list L2. The
result is a list [X, L3] where L3 is the concatenation of L1 and L2.
What we translate into Prolog:
conc ([XI L1], L2, [XI L3]): -
conc (L1, L2, L3).
We can now use this program to concatenate lists:
? - conc ([a, b, c], [1, 2, 3], L).
L = [a, b, c, 1, 2, 3]
? - conc ([a, [b, c], d], [a, [], b], L).
L = [a, [b, c], d, a, [], b]
Rather simple in appearance, conc is very flexible and can be used in
many other ways, for example to split a given list into two lists:
? - conc (L1, L2, [a, b, c]).
L1 = []
L2 = [a, b, c];
L1 = [a]
L2 = [b, c];
L1 = [a, b]
L2 = [c];
L1 = [a, b, c]
L2 = [];
no
The program gave the four ways to break down the list
[a, b, c], using backtracking. We can also use backtracking to find a
certain item in a list, such as finding the months before and after a
given month:
? - conc (Before, [May | After],
[jan, feb, mar, apr, mail jun, jui, aut, sep, oct, nov, dec]).
Before = [Jan, Feb, Tue, Apr]
After = [jun, jui, aut, sep, oct, nov, dec].
We get the immediate predecessor and successor of May as follows:
? - conc (_, [Month1, May, Month2 | _],
[jan, feb, mar, apr, mail jun, jui, aut, sep, oct, nov, dec]).
Month1 = Apr
Month2 = jun
Let us now decide to delete in an L1 list everything that follows three
successive occurrences of z, as well as the three z:
? - L1 = [a, b, z, z, c, z, z, z, d, e],
conc (L2, [z, z, z | _], L1).
L1 = [a, b, z, z, c, z, z, z, d, e]
L2 = [a, b, z, z, c]
We have already programmed the membership relationship.
conc allows to redefine it in a more elegant way:
member1 (X, L): -
conc (L1, [XI L2], L).
This clause means that X is a member of list L if L can be
decomposed into two lists, with X being the head of the second.
It goes without saying that member1 defines the same relation as
member, the two names serving only to differentiate the two
implementations. Note that we could have used anonymous
variables:
member1 (X, L): -
conc (_, [X | _], L).
It is interesting to compare these two implementations. The
procedural meaning of member is relatively obvious:
To verify that X is a member of a list L,
 first check that the head of L is equal to X, and if not
 verify that X is a member of the tail of L.
In the case of member1, it is the declarative meaning that is
immediate, not procedural significance. An interesting exercise is to
find out how member1 actually works.
To see more clearly, consider the tracing of the execution of the
following question:
? - member1 (b, [a, b, c]).
The figure gives the execution tracing, from which we can infer that
member1 has the same behavior as member. It goes through the list,
item by item, until the answer is found, or the list exhausted.
3. ADDING AN OBJECT
The easiest way to add an object to a list is to place it there at the
beginning, so that it becomes the head. If X is the new object, and L
the list to which it is added, then the resulting list is quite simply:
[X | L]
So we don't need a procedure for this operation. Nevertheless, this
can still be expressed as a fact if necessary:
adds (X, L, [X | L]).
4. DELETION OF AN OBJECT
Deleting an object X from a list L can be programmed with the relation
eff (X, L, L1)
on L1 is equal to the list L, once X is deleted, eff has a structure
similar to that of member. We are again faced with an alternative:
(1) If X is the head of the list, then the result is the tail of the list,
otherwise
(2) We try to delete X in the tail of the list.
eff (X, [X | Queue], Queue).
eff (X, [Y | Queue], [Y | Queue1]: -
eff (X, Queue, Queue1).
Like a member, eff by nature has non-deterministic behavior. If
several occurrences of X appear in the list, then eff will be able to
delete any one, thanks to the rollback.
Of course, each of the sequences executed will erase only one
occurrence of X, without affecting the others. For example:
? - eff (a, [a, b, a, a], L).
L = [b, a, a];
L = [a, b, a];
L = [a, b, a];
no
delete fails if the list does not contain the object to be deleted.
You can also use eff in the other direction, to insert a new object
anywhere in the list. For example, if we want to see all possible
locations in the list [1, 2, 3], we just have to ask the question:
What is the list L such that after deleting a,
do we get [1, 2, 3]?
? - eff (a, L, [1, 2, 3]).
L = [a, 1, 2, 3];
L = [1, a, 2, 3];
L = [1, 2, a, 3];
L = [1, 2, 3, a];
no
In general, the operation consisting in inserting X in a List List, by
giving LargestList, can be defined by the clause:
insert (X, List, ListPIusLarge): -
eff (X, ListPusLarge, List).
With member1, we elegantly define the membership relation using
conc. We can just as easily use an effect, seeing that an X is a
member of List if it can be deleted from it:
member2 (X, List): -
eff (X, List, _)
5. SUB-SETS OF LISTS
Consider now the sublist relation, which has two lists as arguments, L
and S, S being a sublist of L:
sublist ([c, d, e], [a, b, c, d, e, f])
is true, while
sublist ([c, a], [a, b, c, d, e, f])
is not.
The principles applied for member1 can still be used, although the
relationship is more general. We can formulate it as follows:
S is a sublist of L if:
(3) L can be broken down into two lists L1 and L2, and if
(4) L2 can be broken down into two lists, S and L3.
As we have already seen, the decomposition of the lists can be done
with the relation conc, which leads us to the following Prolog
formulation:
sublist (S, L): -
conc (L1, L2, L),
conc (S, L3, L2).
Of course, the use of a sublist is flexible, which allows it to be used in
several different ways. While its initial objective is to locate a sublist
within a list, it can provide all the sublists of a given list:
? - sublist (S, [a, b, c]).
S = [];
S = [a];
S = [a, b];
S = [a, b, c];
S = [b];
...
6. PERMUTATIONS
It is sometimes useful to generate permutations of a list. For this
purpose, we define the permutation relation, which has two
arguments. These are two lists, such that one is the permutation of
the other. Our intention is to use the possibilities of backtracking, as
in the following example:
? - permutation ([a, b, c], P).
P = [a, b, c];
P = [a, c, b];
P = [b, a, c];
...
The permutation program can also be based on the distinction of two
cases, depending on the first list:
(1) If the first list is empty, then the second list must also be
empty.
(2) If the first list is not empty, then it is of the form
[XIL], and we can construct the permutation of such a list by
permuting L first, which gives L1, then inserting X at all
positions in L1.
The two corresponding Prolog clauses are as follows:
permutation ([], []).
permutation ([X | L], P): -
permutation (L, L1),
insert (X, L1, P).
Another method would consist in removing an element X from the first
list, in permuting the rest of the latter to give the list P, then finally to
add X at the head of P. Which gives the following program:
permutation2 ([], []).
permutation2 (L, [X | P]): -
eff (X, L, L1),
permutation2 (L1, P).
It is interesting to perform some experiments with our permutation
programs. Normal usage would look like this:
? - permutation ([red, blue, green], P).
As expected, the result gives the following six permutations:
P = [red, blue, green];
P = [red, green, blue];
P = [blue, red, green];
P = [blue, green, red];
P = [green, red, blue];
P = [green, blue, red];
no
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)
Artificial Intelligence Using PROLOG Course Notes (INF-382-99)

More Related Content

Similar to Artificial Intelligence Using PROLOG Course Notes (INF-382-99)

Spnd 456 second weekend simmons december 2010
Spnd 456 second weekend simmons december 2010Spnd 456 second weekend simmons december 2010
Spnd 456 second weekend simmons december 2010KarenJan
 
R15 regulations i b.tech - isem.pdf 974772
R15 regulations   i b.tech - isem.pdf 974772R15 regulations   i b.tech - isem.pdf 974772
R15 regulations i b.tech - isem.pdf 974772Dandu Srinivas
 
Coding wp2-comparative study-si(1)
Coding wp2-comparative study-si(1)Coding wp2-comparative study-si(1)
Coding wp2-comparative study-si(1)Georgeta Manafu
 
IRJET- ASL Language Translation using ML
IRJET- ASL Language Translation using MLIRJET- ASL Language Translation using ML
IRJET- ASL Language Translation using MLIRJET Journal
 
9 26-fit-presentation
9 26-fit-presentation9 26-fit-presentation
9 26-fit-presentationmath267
 
Module handout for COM839 - Intelligent Systems [Word format]
Module handout for COM839 - Intelligent Systems [Word format]Module handout for COM839 - Intelligent Systems [Word format]
Module handout for COM839 - Intelligent Systems [Word format]butest
 
GCSE year 9 options evening
GCSE year 9 options eveningGCSE year 9 options evening
GCSE year 9 options eveningbsharland
 
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)mathewhillier
 
Vengatesh's resume for higher education
Vengatesh's resume for higher educationVengatesh's resume for higher education
Vengatesh's resume for higher educationVengatesh Renganathan
 
Resonance Introduction at SacPy
Resonance Introduction at SacPyResonance Introduction at SacPy
Resonance Introduction at SacPymoorepants
 
Teaching Machine Learning to Design Students
Teaching Machine Learning to Design StudentsTeaching Machine Learning to Design Students
Teaching Machine Learning to Design Studentsbutest
 
Syllabus for Bachelors in Engineering Information Science
Syllabus for Bachelors in Engineering Information ScienceSyllabus for Bachelors in Engineering Information Science
Syllabus for Bachelors in Engineering Information Sciencesyed qutubuddin
 

Similar to Artificial Intelligence Using PROLOG Course Notes (INF-382-99) (20)

Spnd 456 second weekend simmons december 2010
Spnd 456 second weekend simmons december 2010Spnd 456 second weekend simmons december 2010
Spnd 456 second weekend simmons december 2010
 
R15 regulations i b.tech - isem.pdf 974772
R15 regulations   i b.tech - isem.pdf 974772R15 regulations   i b.tech - isem.pdf 974772
R15 regulations i b.tech - isem.pdf 974772
 
Coding wp2-comparative study-si(1)
Coding wp2-comparative study-si(1)Coding wp2-comparative study-si(1)
Coding wp2-comparative study-si(1)
 
Python-content-1.pdf
Python-content-1.pdfPython-content-1.pdf
Python-content-1.pdf
 
cv
cvcv
cv
 
IRJET- ASL Language Translation using ML
IRJET- ASL Language Translation using MLIRJET- ASL Language Translation using ML
IRJET- ASL Language Translation using ML
 
9 26-fit-presentation
9 26-fit-presentation9 26-fit-presentation
9 26-fit-presentation
 
Curriculum Viate
Curriculum ViateCurriculum Viate
Curriculum Viate
 
Module handout for COM839 - Intelligent Systems [Word format]
Module handout for COM839 - Intelligent Systems [Word format]Module handout for COM839 - Intelligent Systems [Word format]
Module handout for COM839 - Intelligent Systems [Word format]
 
2021 ME.pdf
2021 ME.pdf2021 ME.pdf
2021 ME.pdf
 
Lp comp8 - july 2014
Lp   comp8 - july 2014Lp   comp8 - july 2014
Lp comp8 - july 2014
 
GCSE year 9 options evening
GCSE year 9 options eveningGCSE year 9 options evening
GCSE year 9 options evening
 
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
 
Stem lab
Stem labStem lab
Stem lab
 
Vengatesh's resume for higher education
Vengatesh's resume for higher educationVengatesh's resume for higher education
Vengatesh's resume for higher education
 
AIML-MODULE1.pdf
AIML-MODULE1.pdfAIML-MODULE1.pdf
AIML-MODULE1.pdf
 
Dsp lab
Dsp labDsp lab
Dsp lab
 
Resonance Introduction at SacPy
Resonance Introduction at SacPyResonance Introduction at SacPy
Resonance Introduction at SacPy
 
Teaching Machine Learning to Design Students
Teaching Machine Learning to Design StudentsTeaching Machine Learning to Design Students
Teaching Machine Learning to Design Students
 
Syllabus for Bachelors in Engineering Information Science
Syllabus for Bachelors in Engineering Information ScienceSyllabus for Bachelors in Engineering Information Science
Syllabus for Bachelors in Engineering Information Science
 

More from Lori Mitchell

Expository Essay Reflection Paper In. Online assignment writing service.
Expository Essay Reflection Paper In. Online assignment writing service.Expository Essay Reflection Paper In. Online assignment writing service.
Expository Essay Reflection Paper In. Online assignment writing service.Lori Mitchell
 
Handwriting Without Tears Paper WITH Picture Han
Handwriting Without Tears Paper WITH Picture HanHandwriting Without Tears Paper WITH Picture Han
Handwriting Without Tears Paper WITH Picture HanLori Mitchell
 
My Mother Childhood Essay. Essay On My Mot
My Mother Childhood Essay. Essay On My MotMy Mother Childhood Essay. Essay On My Mot
My Mother Childhood Essay. Essay On My MotLori Mitchell
 
Stephen King Quote If You Want To Be A Writer, You Must Do Two Things
Stephen King Quote If You Want To Be A Writer, You Must Do Two ThingsStephen King Quote If You Want To Be A Writer, You Must Do Two Things
Stephen King Quote If You Want To Be A Writer, You Must Do Two ThingsLori Mitchell
 
500 Word Essay - Example, Length And Writing Tips At
500 Word Essay - Example, Length And Writing Tips At500 Word Essay - Example, Length And Writing Tips At
500 Word Essay - Example, Length And Writing Tips AtLori Mitchell
 
Pin On Educational Purposes. Online assignment writing service.
Pin On Educational Purposes. Online assignment writing service.Pin On Educational Purposes. Online assignment writing service.
Pin On Educational Purposes. Online assignment writing service.Lori Mitchell
 
English Essay Form 1 - JerryldOneal. Online assignment writing service.
English Essay Form 1 - JerryldOneal. Online assignment writing service.English Essay Form 1 - JerryldOneal. Online assignment writing service.
English Essay Form 1 - JerryldOneal. Online assignment writing service.Lori Mitchell
 
Nurse Practitioner Personal Statement Sample That Can
Nurse Practitioner Personal Statement Sample That CanNurse Practitioner Personal Statement Sample That Can
Nurse Practitioner Personal Statement Sample That CanLori Mitchell
 
As An English Teacher, Writin. Online assignment writing service.
As An English Teacher, Writin. Online assignment writing service.As An English Teacher, Writin. Online assignment writing service.
As An English Teacher, Writin. Online assignment writing service.Lori Mitchell
 
How To Write An Good Literature Essays Online
How To Write An Good Literature Essays OnlineHow To Write An Good Literature Essays Online
How To Write An Good Literature Essays OnlineLori Mitchell
 
EDEXCEL Imaginative Writing Questions Teachin
EDEXCEL Imaginative Writing Questions TeachinEDEXCEL Imaginative Writing Questions Teachin
EDEXCEL Imaginative Writing Questions TeachinLori Mitchell
 
College Essay Essay In High School. Online assignment writing service.
College Essay Essay In High School. Online assignment writing service.College Essay Essay In High School. Online assignment writing service.
College Essay Essay In High School. Online assignment writing service.Lori Mitchell
 
Cheap Essay Writing Services - Avail Best Essay Help AuthorST
Cheap Essay Writing Services - Avail Best Essay Help AuthorSTCheap Essay Writing Services - Avail Best Essay Help AuthorST
Cheap Essay Writing Services - Avail Best Essay Help AuthorSTLori Mitchell
 
Scientific Research Paper Format Template - Writinght
Scientific Research Paper Format Template - WritinghtScientific Research Paper Format Template - Writinght
Scientific Research Paper Format Template - WritinghtLori Mitchell
 
Tips For Writing A Research Paper Research4Life
Tips For Writing A Research Paper Research4LifeTips For Writing A Research Paper Research4Life
Tips For Writing A Research Paper Research4LifeLori Mitchell
 
Printable Birthday Stationary Pics BirthdayStationary
Printable Birthday Stationary Pics BirthdayStationaryPrintable Birthday Stationary Pics BirthdayStationary
Printable Birthday Stationary Pics BirthdayStationaryLori Mitchell
 
Samples Of Persuasive Essays For High School St
Samples Of Persuasive Essays For High School StSamples Of Persuasive Essays For High School St
Samples Of Persuasive Essays For High School StLori Mitchell
 
The Elements Of Writing A Song Songwriting Basics,
The Elements Of Writing A Song Songwriting Basics,The Elements Of Writing A Song Songwriting Basics,
The Elements Of Writing A Song Songwriting Basics,Lori Mitchell
 
If They Give You Lined Paper, Write Sideways. By Daniel Quinn
If They Give You Lined Paper, Write Sideways. By Daniel QuinnIf They Give You Lined Paper, Write Sideways. By Daniel Quinn
If They Give You Lined Paper, Write Sideways. By Daniel QuinnLori Mitchell
 
Robot Writing Paper - 3 Styles By Pink Posy Paperi
Robot Writing Paper - 3 Styles By Pink Posy PaperiRobot Writing Paper - 3 Styles By Pink Posy Paperi
Robot Writing Paper - 3 Styles By Pink Posy PaperiLori Mitchell
 

More from Lori Mitchell (20)

Expository Essay Reflection Paper In. Online assignment writing service.
Expository Essay Reflection Paper In. Online assignment writing service.Expository Essay Reflection Paper In. Online assignment writing service.
Expository Essay Reflection Paper In. Online assignment writing service.
 
Handwriting Without Tears Paper WITH Picture Han
Handwriting Without Tears Paper WITH Picture HanHandwriting Without Tears Paper WITH Picture Han
Handwriting Without Tears Paper WITH Picture Han
 
My Mother Childhood Essay. Essay On My Mot
My Mother Childhood Essay. Essay On My MotMy Mother Childhood Essay. Essay On My Mot
My Mother Childhood Essay. Essay On My Mot
 
Stephen King Quote If You Want To Be A Writer, You Must Do Two Things
Stephen King Quote If You Want To Be A Writer, You Must Do Two ThingsStephen King Quote If You Want To Be A Writer, You Must Do Two Things
Stephen King Quote If You Want To Be A Writer, You Must Do Two Things
 
500 Word Essay - Example, Length And Writing Tips At
500 Word Essay - Example, Length And Writing Tips At500 Word Essay - Example, Length And Writing Tips At
500 Word Essay - Example, Length And Writing Tips At
 
Pin On Educational Purposes. Online assignment writing service.
Pin On Educational Purposes. Online assignment writing service.Pin On Educational Purposes. Online assignment writing service.
Pin On Educational Purposes. Online assignment writing service.
 
English Essay Form 1 - JerryldOneal. Online assignment writing service.
English Essay Form 1 - JerryldOneal. Online assignment writing service.English Essay Form 1 - JerryldOneal. Online assignment writing service.
English Essay Form 1 - JerryldOneal. Online assignment writing service.
 
Nurse Practitioner Personal Statement Sample That Can
Nurse Practitioner Personal Statement Sample That CanNurse Practitioner Personal Statement Sample That Can
Nurse Practitioner Personal Statement Sample That Can
 
As An English Teacher, Writin. Online assignment writing service.
As An English Teacher, Writin. Online assignment writing service.As An English Teacher, Writin. Online assignment writing service.
As An English Teacher, Writin. Online assignment writing service.
 
How To Write An Good Literature Essays Online
How To Write An Good Literature Essays OnlineHow To Write An Good Literature Essays Online
How To Write An Good Literature Essays Online
 
EDEXCEL Imaginative Writing Questions Teachin
EDEXCEL Imaginative Writing Questions TeachinEDEXCEL Imaginative Writing Questions Teachin
EDEXCEL Imaginative Writing Questions Teachin
 
College Essay Essay In High School. Online assignment writing service.
College Essay Essay In High School. Online assignment writing service.College Essay Essay In High School. Online assignment writing service.
College Essay Essay In High School. Online assignment writing service.
 
Cheap Essay Writing Services - Avail Best Essay Help AuthorST
Cheap Essay Writing Services - Avail Best Essay Help AuthorSTCheap Essay Writing Services - Avail Best Essay Help AuthorST
Cheap Essay Writing Services - Avail Best Essay Help AuthorST
 
Scientific Research Paper Format Template - Writinght
Scientific Research Paper Format Template - WritinghtScientific Research Paper Format Template - Writinght
Scientific Research Paper Format Template - Writinght
 
Tips For Writing A Research Paper Research4Life
Tips For Writing A Research Paper Research4LifeTips For Writing A Research Paper Research4Life
Tips For Writing A Research Paper Research4Life
 
Printable Birthday Stationary Pics BirthdayStationary
Printable Birthday Stationary Pics BirthdayStationaryPrintable Birthday Stationary Pics BirthdayStationary
Printable Birthday Stationary Pics BirthdayStationary
 
Samples Of Persuasive Essays For High School St
Samples Of Persuasive Essays For High School StSamples Of Persuasive Essays For High School St
Samples Of Persuasive Essays For High School St
 
The Elements Of Writing A Song Songwriting Basics,
The Elements Of Writing A Song Songwriting Basics,The Elements Of Writing A Song Songwriting Basics,
The Elements Of Writing A Song Songwriting Basics,
 
If They Give You Lined Paper, Write Sideways. By Daniel Quinn
If They Give You Lined Paper, Write Sideways. By Daniel QuinnIf They Give You Lined Paper, Write Sideways. By Daniel Quinn
If They Give You Lined Paper, Write Sideways. By Daniel Quinn
 
Robot Writing Paper - 3 Styles By Pink Posy Paperi
Robot Writing Paper - 3 Styles By Pink Posy PaperiRobot Writing Paper - 3 Styles By Pink Posy Paperi
Robot Writing Paper - 3 Styles By Pink Posy Paperi
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

Artificial Intelligence Using PROLOG Course Notes (INF-382-99)

  • 1. Course Notes INF-382-99 – ARTIFICIAL INTELLIGENCE USING PROLOG By Martin Lesage Courses Notes Written for the course INF-382- 99 – ARTIFICIAL INTELLIGENCE USING PROLOG Notes made from the book : Bratko, Ivan - Prolog programming for artificial intelligence, 3rd edition, Addison-Wesley, 2000 ISBN: 0-201-40375-7 Université du Québec à Rimouski (UQÀR) January 2002
  • 2.
  • 3. DEPARTMENT OF MATHEMATICS, COMPUTING AND ENGINEERING 1. LESSON PLAN SESSION: WINTER 2002 ACRONYMS: INF-382-99 TITLE: Artificial Intelligence GROUP: 05 CLASS SCHEDULE: Thursday 8:30 am to 11:20 am LOCAL: K-245 START: January 10, 2002 PROFESSOR: Martin Lesage Office: K-113 Telephone (UQAR): 724-1986 Ext: 1277 Telephone (CÉGEP de Rivière-du-Loup): (418) 862-6903 Extension: 561 Fax: 724-1879 Email: marles@cegep-rdl.qc.ca DESCRIPTION OF THE COURSE ACCORDING TO THE DIRECTORY Know the basic concepts, techniques and applications of artificial intelligence. Heuristic methods of problem solving; search algorithms in trees and graphs; representation of knowledge; expert systems; processing of natural languages; pattern recognition; neural networks. History, results, challenges and limitations. Introduction to LISP or PROLOG language. Prerequisite (s): INF11299 Programming II INSERTING THE COURSE INTO THE PROGRAM This course is an optional course for students of the bachelor's degree in mathematics-computer science. It has as a formal prerequisite the course INF11299 Programming II but also requires knowledge acquired in data structures and algorithms. COURSE OBJECTIVES - Acquire basic notions in the main fields of artificial intelligence and study the different concepts and techniques of this discipline; and - Become familiar with a programming language characteristic of artificial intelligence.
  • 4. COURSE CONTENT The course is mainly based on the following compulsory reference book and course notes provided by the teacher: Bratko, Ivan Prolog programming for artificial intelligence, 3rd edition Addison-Wesley, 2000 ISBN: 0-201-40375-7 PEDAGOGICAL FORMULAS A three (3) hour meeting each week with the professor to cover the theoretical aspects, do case studies and supervised exercises. Personal readings in the compulsory reference book and course notes must be done by the student before each meeting with the professor. Two practical sessions are also planned. MANDATORY READING Bratko, Ivan Prolog programming for artificial intelligence, 3rd edition Addison-Wesley, 2000 ISBN: 0-201-40375-7 Lecture notes provided by the teacher EVALUATION Assessment methods: Examinations: The exams are written tests. Practical work : Assignments are done individually for practical work 1 and in pairs for practical work 2 French policy: Up to 10% of points can be awarded for the quality of written French in assignments and exams. Type of test Weighting Practical Work 1 15% Delivery on February 21 Practical Work 2 25% Delivery on April 18 Intra exam 30% Date of the test: March 7 Final exam 30% Date of the test: April 25
  • 5. Proposed notation (correspondence of the numerical note to the literal note, if applicable) The establishment of the final odds is based on the following fixed odds scale: Side Note A+ 93% A 90% A- 87% B+ 83% B 80% B- 77% C+ 73% C 70% C- 67% D+ 63% D 60% E <60% CALENDAR OF MEETINGS Week Dated 1 January 10 Artificial intelligence (AI): History, results, challenges and limits Readings: Course Notes 2 January 17th The representation of knowledge: Logic, deductive reasoning, inductive reasoning, propositional logic, calculation of predicates, production rules, semantic networks, structured objects, principles of uncertainty Readings: Course Notes 3 24 january Knowledge representation: control structures in expert systems, forward chaining, backward chaining, mixed reasoning, choice of a control strategy Readings: Course Notes 4 January 31 Prolog language: Presentation of Prolog, syntax and meaning of Prolog programs Readings: Book of Bratko, chapters 1 and 2 Delivery of Statement of Practice 1 5 February 7 Prolog language: Lists, operators, arithmetic, use of structures Readings: Book of Bratko, chapters 3 and 4 6 February 14th Prolog language: Rollback control, additional integrated procedures Readings: Book of Bratko, chapters 5 and 7 7 the 21st of February Prolog language: Operations on data structures Readings: Book of Bratko, Chapter 9 Submission of practical work 1, submission of statement of practical work 2 8 February 28 Reading week 9 March 7 Intra exam 10 March 14 Prolog language: Elementary problem-solving strategies Readings: Book of Bratko, Chapter 11 11 March 21st Prolog language: Graph browsing Readings: Book of Bratko, chapter 12 12 March 28 Expert systems: Functions, main structures and representation of knowledge Readings: Book of Bratko, Chapter 15 13 April 4 Expert systems: Shell creation, implementation, handling of uncertainty Readings: Book of Bratko, Chapter 16 14 April 11 Applications of artificial intelligence: Natural language processing, pattern recognition, digital vision Readings: Course Notes 15 April 18 Applications of artificial intelligence: Neural networks, robotics Readings: Course Notes Handover of practical work 2 16 April 25 Final exam
  • 6. SCHEDULE FOR SUBMISSION OF WORKS AND EXAMINATIONS Works Exams SPECIAL TERMS Penalty for late work: Any delay in submitting a work exposes the student to lose 1 point per day of delay. Plagiarism: Any student who has copied or tried to copy, in any way whatsoever, will be immediately dismissed from the examination room, will have his work canceled and his case submitted to the competent authority who will apply penalties proportionate to the fault. BIBLIOGRAPHICAL REFERENCES Mandatory : Bratko Ivan, Prolog programming for artificial intelligence, 3rd edition, Addison-Wesley, 2000, ISBN: 0-201-40375-7. Reference Manuals: Charniak Eugene, McDermott Drew, Introduction to Artificial Intelligence, Addison-Wesley, 1985. Luger George F., Stubblefield William A., Artificial Intelligence, Structures and Strategies for Complex Problem Solving, Benjamin Cummings, 1993. Laurière JL, Artificial Intelligence, Eyrolles, 1987. Rich Elaine, Artificial Intelligence, McGraw-Hill, 1983. Winston Patrick Henry, Artificial Intelligence, InterEditions, 1988. Clocksin WF, Mellish CS, Programming in Prolog, Springer-Verlag, 1988. Giannesini F., Kanoui H., Pasero R., Van Caneghem M., Prolog, InterEditions, 1985. Sterling Leon, Shapiro Ehud, The Art of Prolog: Advanced Programming Techniques, The MIT Press, 1986. Farreny Henri, Ghallab Malik, Elements of Artificial Intelligence, Hermes, 1987. Graham Neil, Artificial Intelligence, TAB Books Inc., 1979. Ginsberg Matthew, Essentials of Artificial Intelligence, Morgan Kaufmann Publishers, Inc., 1993. Chatain Jean-Noël, Dussauchoy Alain, Expert Systems: Methods and Tools, Eyrolles, 1987. Frenzel Louis E. Jr., Crash Course in Artificial Intelligence and Expert Systems, Howard W. Sams & Co., ISBN 0-672- 22443-7. Type of test Weighting 1. Date of delivery Practical Work 1 15% February 21st Practical Work 2 25% April 18 Exam Weighting Date of the test Intra exam 30% March 7 Final exam 30% April 25
  • 7. COURSE 01 INF-38299 - ARTIFICIAL INTELLIGENCE In our current society, some salespeople or technologists qualify electronic or computer systems as intelligent:  Smart robot (Aïbo)  Smart tutorial  Automotive (ABS brakes, electronic injection, suspension, etc.)  Toys for children  Surveillance, alarm systems, home automation  Etc ... DEFINITIONS Artificial intelligence is difficult to define in the same way as human intelligence. The concept of intelligence is complex and relative, and the highly controversial expression of "artificial intelligence" does not specify it further, it is also difficult to define the scientific discipline of artificial intelligence (AI). Artificial intelligence (AI) is a field of computing dedicated to creating hardware and software capable of mimicking human thought. The main goal of artificial intelligence is to make computers smarter by producing software that allows a computer to emulate functions of the human brain in defined applications. The idea is not to replace the human being but to give him a more powerful tool to help him accomplish his tasks.
  • 8. This discipline can be considered as a cognitive science and also as a branch of computer science.  Cognitive science: understanding and modeling the mechanisms of understanding, the study of mental faculties.  Computer science branch: design programs and machines able to deal with problems for which no direct and assured resolution methods are known. Artificial intelligence is the study of ideas that can make computers smart Artificial intelligence is a field of computing dedicated to programming computers to perform tasks such that if these tasks were performed by a human being, those tasks would require intelligent action from the human being. WHY DO WE NEED COMPUTERS OR INTELLIGENT SYSTEMS?  Smart computers can adapt themselves to their human users instead of the other way around. Many reviews of computers state that users must adapt to the language of the computer. It would be important for the user to be able to interact with the computer using English or another spoken language.  Robots can work in environments hostile to humans, such as the ocean floor, underground mines, or in space.  Robots can do boring and repetitive tasks that are currently performed by humans because of their ability to perceive and manipulate their environment. Much work on assembly lines falls into this category.
  • 9.  Computers can store the vast amounts of information that humans need to do their jobs and fulfill their personal lives. Depending on needs, the computer can be used as a teacher, encyclopedia, consultant, journalist or postman.  In a complex world with complex problems, humans need a multitude of means to solve problems. Economics, energy and international relations are some areas where smarter computers could help human beings solve humanity's problems. ARTIFICIAL INTELLIGENCE TECHNIQUE An artificial intelligence technique is a method that exploits knowledge that should be represented in such a way that:  They catch the generalizations.  They can be understood by those who have to provide them.  They can be easily modified to correct mistakes and to reflect changes in the world and our view of it.  They can be used in a very large number of cases even if they are not completely precise or complete.  They can serve to overcome their own large volume by helping to narrow the field of possibilities that must usually be considered (sorting / selection of rules).
  • 10. APPLICATIONS  Problems solving Most of the tasks given to computers can be regarded as problems. In each case, the computer is expected to perform the necessary operations in order to solve a specific problem. Unlike traditional applications solving particular problems, artificial intelligence programs are designed in such a way that they are of the most general use possible. When a problem and the knowledge base necessary for the solution of that problem is inputted to this type of program, that program should find a solution as a human could. Artificial intelligence techniques tend to dissociate from algorithmic problem- solving methods. Indeed an artificial intelligence program can generate new knowledge and have a certain initiative.  Natural language processing (5th generation software) Currently, the means of communication between human being and computers is not very optimal. This is especially true when a person wants to give instructions or input data to a computer. Some computers can also communicate with humans through prefabricated sentences. In the event that computers have to interact with users who are not computer specialists, the computers must be able to communicate in natural language, such as English. The computer should also be able to communicate orally or in writing.
  • 11. In addition to being able to easily communicate with the user, one of the tasks of artificial intelligence is to perform processing on natural languages, such as automatic translation from one language to another or to respond to basic questions.  Pattern perception and recognition In many computer applications, a computer needs to perceive its surroundings using television cameras, microphones, and other sensors. In addition, the computer needs to recognize certain characteristics or particular shapes in the environment it perceives.  Expert systems The main use of artificial intelligence today is concentrated in expert systems, artificial intelligence programs serving as advisers or consultants. An expert system allows the knowledge and experience of one or more experts in a particular field to be stored in a computer. This knowledge can then be used by anyone who needs it.  Education Artificial intelligence can also be used in the field of training and education. Using the techniques of artificial intelligence, new tutorials can be produced that allow the computer to be an intelligent tutor that can adapt to the experience and level of knowledge of the student.
  • 12.  Information Management (Information Storage and Database Query) In recent years, information relating to fields such as medicine, law, science, engineering and many others has increased considerably. No worker in either of these disciplines can have in mind all the information needed to perform these tasks. The worker may not be aware that a certain amount of information necessary to perform his job exists. Computers can store large amounts of information. With current systems, the user has to describe the desired information to the computer in great detail. The user must have a precise idea of the information sought in order to make the computer understand what information to find. It would indeed be easier for the user to describe the information to find or the problem to be solved in natural language and let the computer find the relevant information or elements of solution. The storage and retrieval of information is also used for other tasks of artificial intelligence. A program that performs problem solving needs all the data possible about the problem in question. This program also needs techniques and troubleshooting rules that have been proven to be valid in solving similar problems. Researchers in the field of artificial intelligence define the act of searching for information stored in a computer for use in problem solving as a representation of knowledge.
  • 13.  Robotics In the case of certain tasks, such as the assembly of parts in factories, the computer must not only be able to perceive its environment, but must also be able to perceive changes in it. Like taking a piece and putting it on top of another. A computer with this ability is called a robot. One aspect of robotics is the mechanical aspect: no one has yet invented a robot with limbs as flexible and controllable as a human being. This is a problem that mechanical and electrical engineers will have to solve even before computer scientists tackle the subject. At the computer level, the main aspect of robotics is to make programs that can allow the robot to perform the appropriate movements in relation to its environment.  Games Since the 18th century, scientists and researchers have focused on making machines and automatons capable of playing games such as chess and drafts. In recent years, some computer researchers have focused on game modeling and how to make efficient programs capable of playing games with acceptable response times. As part of this research, some programs that can play games (chess, tic-tac-to, dominoes, backgamon, etc.) were carried out and analyzed.
  • 14. Resolving programs that play games is a great application of artificial intelligence for the following reasons: - the board or the game environment and the rules of the game are easy to model - unlike modeling the environment and the rules of the game, it is difficult for the computer to calculate the right moves or the right actions to perform. The computer should analyze the game in a manner similar to a human gamer. - there are some human masters of these games who are generally happy to give their opinion on the performance of the game program. The scientists who created the program will be able to use these reviews to improve the program. - tournaments are usually organized in most of these games and the grandmasters can compete with the computer. The performance of the computer can thus be compared directly with the human expert.  Automatic programming (Code generation) Writing and debugging a complex program is a time consuming task. A large team of programmers can work several years to produce a compiler or an operating system, and the result is never without errors. Generally, even if the program is in its final version, it will still contain errors (bugs) which will affect the proper functioning of the software until these errors are found and eliminated. This situation characterizes software production as a victim of the "software crisis".
  • 15. One way to avoid this situation is to have the computer generate code from the statements of the problem to be solved. Such a program generator application would be an extension of current compilers and report generators. These applications also produce programs, mail they ask the computer scientist to describe the application to be produced in greater detail.  Programmed logic Sometimes scientists need to prove that a series of facts are a logical consequence of other facts. A crown lawyer, for example, must prove beyond a doubt and with supporting evidence that the accused committed the crime with which he is accused. Programmed logic is the art of programming a computer so that it can make these deductions. Obvious applications of programmed logic are found in mathematics. A mathematician starts with a small set of facts (called axioms) and deduces interesting consequences (called theorems) from those facts. The mathematician guarantees that in any situation where the axioms are true, the theorems will also be true. We can therefore apply these theorems in scientific cases without having to repeat the deductions of mathematicians. The computer is thus able to perform mathematical proofs when we provide it with theorems.
  • 16. Another application of programmed logic is to prove that a program is correct. This is an alternative to automatic programming. The human programmer writes a program. The computer tries to prove that the program is correct; that is, it solves the problem it was created to solve. If the computer is successful we can use the program with confidence, otherwise the programmer will have to find out why the proof failed, possibly due to an error in the program. Other artificial intelligence programs also need programmed logic, especially those involved with information retrieval and knowledge representation. Some facts are stored in the computer. Other facts are looked for by the programmer or program working on a problem. The computer should try to differentiate the requested information from the available information. HISTORICAL Interest in intelligent machines can be traced back to antiquity. The scientific roots of the discipline go back, however, to the first work on mathematical logic and to the first theoretical and practical developments on automata and computability. The outstanding works on automata and computability are those of Babbage (the analytical machine, 1842) and especially the contemporaries Church, Turing (the universal machine of Turing, 1936) and Von Neumann. It is to Alan Turing that we owe the famous machine intelligence test. From the beginnings of data processing (ENIAC, the first electronic calculator, born in 1944) some saw in the computer a potential competitor of human intelligence. Indeed, the calculations made by this new machine would have required a long and painful labor of intelligent men.
  • 17. From then on, some researchers proposed algorithms intended to reproduce human faculties. Thus, around 1945, John Von Neumann and Oskar Morgenstein proposed a theoretical solution to a whole class of problems such as strategy games and automatic demonstration. In the summer of 1956, a conference of academics was held at Dartmouth College to study the following issue: Any aspect of learning or any other characteristic of intelligence can in principle be well enough defined that a machine could be created in order to reproduce them. This issue was raised by John McCarthy (the inventor of LISP) and his study created artificial intelligence. This conference is considered the official birth of artificial intelligence. The first artificial intelligence programs also date from this period: a theorem demonstrator in proposition logic (1956), a program playing chess (1957) and the LISP language (1958). The first years were marked by some contributions and above all a lot of optimism regarding a vision of future applications of artificial intelligence: understanding a text in natural language and beating a champion in chess seemed tasks within immediate reach. The estimate was false, on the contrary it took ten years of meager results to fully grasp the enormous difficulties of these problems and to develop approach strategies.
  • 18. The end of the sixties was more productive and brought a real takeoff of the discipline. Among other results, we find the “Principle of resolution” (1965), the A * algorithm (1968), programs such as GPS (resolution of puzzles with heuristic of the situation-objective deviation, 1969), the QA3 system. (based on first order logic, 1969) and early work on MACSYMA (in 1968, by the Mathlab group at MIT, for assistance in solving mathematical problems). The decade of the 1970s was rich in contributions. It brought the essential bases in representation of the knowledge and the first results on the difficult problems such as the computer learning, the comprehension of the natural languages, the reasoning on the time in evolutionary or uncertain situation. At this time also appeared methods and tools for the development of real applications: expert systems, perception-vision by computer, robotics, human-machine interfaces, understanding of speech and natural languages in restricted contexts, programming environments and first symbolic processing machines. The 1980s materialized these results. At the level of research in artificial intelligence, we have a greater mastery of the tools and fundamental results acquired, and a more precise perception of open scientific problems and their difficulty. In terms of applications, we are witnessing the first commercializations and the corresponding technological mastery.
  • 19. RESULTS Artificial intelligence researchers have failed to standardize the two artificial intelligence simulation models:  Same results - different way to get them  Same results - same way to get them A certain divergence still exists between these two models due to the fact that scientists have not yet succeeded in formally modeling the behavior, the learning mechanisms and the vision process of the human being. The fact of a certain lack of evidence and absolute formalism does not prevent a whole category of researchers from doing research in the field of artificial intelligence and exploring in new directions. In recent years, some relevant applications and results of this field have been transferred from universities and private research institutes into commercial products. The applications of artificial intelligence are finding more and more followers and many companies and consumers find it very useful or more practical to use systems supported by software based on artificial intelligence:  Robotics applications (industrial or residential)  Digital vision or pattern recognition (robotics, surveillance, remote sensing, satellites, etc.)  Tutorials  Games, simulators  Speech recognition  Etc ...
  • 20. Many of the commercial applications of artificial intelligence lie in the area of expert systems. An expert system is a computer program that simulates the knowledge and decision- making of an expert in a particular area of knowledge. An expert system program contains a database (knowledge base) and a set of rules (called heuristics) for making decisions. Some of these more well-known expert systems are used in medicine, chemistry, and petroleum research. The programming of artificial intelligence applications is almost completely dominated by two languages: LISP and PROLOG. In the United States, almost all artificial intelligence applications have been written in LISP. In Europe and Japan, many applications have been developed in PROLOG. The personal computer is another determining element that has influenced the development of artificial intelligence. As users demand more and more about the ease of use of software, software companies are incorporating artificial intelligence techniques into their software in order to stay competitive. The potential of artificial intelligence is prompting many investors to finance companies making software based on artificial intelligence. Some multinational companies such as IBM, Sperry, DEC and General Motors already have artificial intelligence software.
  • 21. There is now some pressure on the artificial intelligence community to create practical applications as quickly as possible. This pressure is created by the fact that developers of artificial intelligence applications want to enrich themselves and take advantage of user demand for software that is more flexible and easier to use. Some computer designers, and in particular the Japanese, want to take the computer sales market by creating fifth generation computer systems based on artificial intelligence techniques. The fifth generation is characterized by parallel processing and the inclusion of artificial intelligence concepts such as speech recognition. CHALLENGES The study of artificial intelligence or (AI) is in principle as complex and vast as the study of human intelligence. This science also includes the development of methods of producing and understanding natural language, the ability to see or recognize certain shapes or objects, the ability to make logical inferences or make decisions based on incomplete information. This science also encompasses making generalizations and learning by trial and error.
  • 22. The study of artificial intelligence focuses on two aspects of the reproduction of artificial intelligence by a machine: (1) In the first aspect, the aim is to achieve the same results that humans could achieve, although the processes carried out by machine and humans do not need to be the same. (This model of the same results and different processes is exemplified in the way in which humans and computers perform arithmetic operations). (2) In the second aspect, the goal is not only for the computer to achieve the same results as a human, but the computer must also achieve these results in the same way and following the same rules and procedures. Science fiction computers and robots, such as HAL in the movie “2001: A Space Odyssey” and C3P0 in the “Star Wars” movie, have intelligence similar to that of human beings. Currently, these machines are the domain of science fiction. Too many aspects of human intelligence are still misunderstood for computers to be endowed with human intelligence in the near future. Fortunately, intelligence comparable to that of humans is not necessary for most current applications of artificial intelligence. A robot working in a warehouse only needs to recognize and manipulate the items it has to load, unload and store. This robot doesn't need to be able to discuss philosophy or play chess. Moreover, a program that plays chess does not need to perceive its external environment and its world is limited to its chess board.
  • 23. Although the ultimate goal of artificial intelligence is the pursuit of intelligence comparable to that of human beings, research in the field of artificial intelligence begins to bear fruit immediately by creating programs that emulate certain aspects. of artificial intelligence in a limited form. The techniques developed by artificial intelligence research are applicable to many cases and are resources used by programmers when developing applications. These applications benefit from increased flexibility, more complex problem solving and easier user interaction thanks to artificial intelligence techniques. LIMITS In the early years of artificial intelligence development, only a few researchers took the two artificial intelligence simulation models seriously:  Same results - different way to get them  Same results - same way to get them However, in the 1960s and 1970s, the success of some complex programs, such as programs for playing chess, proved that some computer programs could sometimes surpass human intelligence. Such results have therefore revived the debates around artificial intelligence and university researchers have therefore started to seriously research artificial intelligence around the two models.
  • 24. In the late 1970s, research in artificial intelligence faced a dead end. Indeed, research in medicine and psychology cannot yet allow researchers to formally model how human beings recognize spoken language, recognize images, learn and understand new concepts. Computer simulation of intelligent human behavior is based on theoretical rules which are not necessarily the natural learning process of humans. We can therefore conclude for the moment that research in artificial intelligence has not yet succeeded in realizing the problem raised by McCarthy: Any aspect of learning or any other characteristic of intelligence can in principle be well enough defined that a machine could be created in order to reproduce them. This is how artificial intelligence (AI) appears, a field as ill-defined as intelligence itself. Unlike traditional computing, where computers mainly handle digital information, artificial intelligence mainly uses these machines to manipulate symbolic information (understanding natural language, machine translation, games, demonstration of theorems, etc.). Quickly, despite theoretical progress and some spectacular programs, disappointment replaced the optimism of the beginnings. The algorithms used are based on a more or less exhaustive analysis of the possibilities and therefore the execution times increase rapidly and exponentially depending on the complexity of the problem. This is called the combinatorial explosion. In 1961 John Mc Carthy proposed an algorithm to try to reduce this constraint (alpha- beta algorithm making it possible to prune the trees explored by AI programs) but there was very little fallout from this first period. This relative failure is partly due to researchers who believed possible the construction of a General Problem Solver (GPS) and that from a single statement of a method of resolution and some data of departure. Thus the programs of that time made little or no use of the knowledge of specialists in the subject dealt with. Some researchers then decided to completely change the approach to the problem: by restricting their ambitions to a specific area, they tried to reproduce the way in which the experts carry out their reasoning (deductions, know-how, etc.). To do this, they relied in particular on a large body of knowledge on the subject dealt with, the very knowledge used by specialists in the field. This gave birth to the field of expert systems. The objective of these programs would no longer be to prove, or to find the optimal solution to a problem, but rather the best possible answer in the state of knowledge on the considered field. As this response corresponds to that which the experts would arrive at, it is therefore necessary to introduce their experience and their reasoning method into these expert systems, in order to provide less competent users with decision-making support.
  • 25. This phenomenon is the reflection of the compromise between generality and efficiency, and is based on the fact that in humans, the most gifted individual in his intellectual field has a dismal performance in another. This is due to the considerable mass of knowledge that man has been able to accumulate over the centuries, in all disciplines. Expert systems take this fact into account, because it is clear that in order to obtain programs with very good performance, it is necessary that these programs work in well- defined areas, knowing how to learn the knowledge in this specialty, manage them and structure.
  • 26. In 1950, Alan Turing proposed the following method to determine if a machine can think. His method has since been known as the Turing Test. To perform this test, we will need two people and the machine we are evaluating. One person plays the role of the interrogator. The interrogator will be in a separate room, from the computer and from the other person, with which he can communicate using a computer terminal. The interrogator can ask questions of the person or of the machine, but does not know who they are talking to. The interrogator only knows them as A and B, and seeks to determine who is the human being and who is the machine. The purpose of the machine is to mislead the interrogator into believing that she is the person. If the machine succeeds in doing this, The most important question, however, is how much knowledge a machine would need to have to take the Turing test. We can still wait a long time for a machine to pass the Turing test. This would be the case with a perfect artificial intelligence program. Some people think no machine will ever do it. We must now be content with an incomplete test.
  • 27. COURSE 02 INF-38299 - ARTIFICIAL INTELLIGENCE  THE REPRESENTATION OF KNOWLEDGE INTRODUCTION Most artificial intelligence systems are made up of two basic parts:  a knowledge base: contains facts about objects and their relationships in a chosen field. The knowledge base can also contain concepts, theories, practical procedures and their associations. The knowledge base is the source of intelligence in the system and will be used by the inference mechanisms for reasoning and drawing conclusions.  a mechanism (inference engine): the inference mechanism is a set of procedures that are used to examine the knowledge base in a methodical way to answer questions, solve problems or make decisions within of the domain. The computer therefore emulates human thought on a subject determined by the action of the inference mechanism which searches the knowledge base in order to find answers and solutions. Representing knowledge in a computer consists of finding a correspondence between the external world (external form) and a symbolic system (internal or physical form) allowing reasoning. The expert in the field responsible for transmitting his knowledge to the SE, provides this in its external form. The knowledge acquisition mechanism encodes this knowledge fragment in internal form, ie a data structure (table, list, matrix, etc.), before adding it to the knowledge base.--
  • 28. The OS uses the logical form, which is generally defined in terms of index or symbolic keys, to access this data structure and restores the external form for any dialogue with the user. Just as there is no universal programming language, the ideal formalism to represent the knowledge of an SE has not yet been found. This is how we can distinguish between three types of representation:  The procedural representation (finite automata, programs) which makes the inter-relations between knowledge fragments explicit but which is difficult to modify. Benefits : 1. Facilitates the use of Meta-knowledge by allowing the problem to be broken down explicitly. 2. The pure declarative does not exist, it is essential at the lowest level.  Declarative representation (calculation of production rules predicates, semantic networks) which creates knowledge fragments independent of each other and therefore easily modifiable. This knowledge is combined by a general mechanism of reasoning and deduction. Advantages: readability, economy, flexibility and ease of modification.  Mixed representation (structured objects: frames, script diagrams, objects ...) mixing the two previous modes of representation. It is not our purpose to talk about the first mode of representation that everyone knows, on the other hand, we will examine the other two modes in detail.
  • 29. KNOWLEDGE REPRESENTATION METHODS Building the knowledge base: knowledge in a given area must be grouped and codified. This knowledge must be organized and arranged in a systematic order (knowledge engineering). Knowledge representation methods have been categorized as:  declarative (represents facts and assertions): includes logic, semantic networks, frames and scripts.  procedural (represents actions and procedures): include procedures, subroutines and production rules LOGIC Logic is the oldest form of representation of knowledge, logic is the scientific study of the process of reasoning and the systems of rules and procedures that provide assistance to the process of reasoning. Logic is considered to be a discipline of philosophy. Its origin dates back to ancient Greece.
  • 30. A logical process is structured as follows:  information is given, statements are made and observations are noted. This data is the input to the logical process and is called the premises.  the premises are used by the logical process which creates outputs in the form of conclusions called inferences  with this process, facts that are categorized as true can be used to derive new facts that are also true. There are two basic types of reasoning: deductive and inductive. These two types of reasoning are used in logic to deduce inferences from premises. DEDUCTIVE REASON When general premises are used to derive specific inference, the process is called deductive reasoning or deduction. The process of reasoning evolves from a general principle to a specific conclusion. The process of deduction usually begins with a syllogism (statement of premises and inferences). To illustrate this process, let's look at an example: Major premise: I don't jog when the temperature exceeds 30 degrees Celcius Minor premise: Today the temperature is 32 degrees celcius Conclusion; I will not be jogging today
  • 31. INDUCTIVE REASONING Inductive reasoning uses a number of established facts or premises in order to arrive at a general conclusion. A syllogism is used to define the problem. To illustrate this process, let's look at an example: Premise: Defective diodes cause electronic equipment failures Premise: Faulty transistors cause electronic equipment to fail Premise: Faulty integrated circuits cause electronic equipment to malfunction Conclusion: Defects in semiconductor-based electronic components are one of the major causes of electronic equipment failures. The conclusion of an inductive reasoning is never final or absolute.
  • 32. COMPUTER LOGIC / COMPUTATIONAL LOGIC In order for a computer to perform reasoning using logic, methods must be used to convert syllogisms and the deductive or inductive reasoning process into a format that the computer can manipulate. The result is what is known as symbolic logic or mathematical logic. It is a system of rules and procedures allowing the generation of inferences from different premises and a set of logical techniques. These methods are generally known as computer logic. There are two basic forms of computer logic: - propositional logic or propositional calculus - logic of predicates or calculation of predicates (first order logic) PROPOSAL LOGIC A proposition is a statement which can take the values true or false. This is a premise that can be used in order to obtain new propositions or inferences. The rules are used to determine whether the new proposition is true or false. In propositional logic, we use symbols such as letters of the alphabet to represent different propositions, premises, or conclusions. Consider, for example, the propositions used below in a simple deduction process: A = The postman comes from Monday to Saturday B = It is Sunday today C = The postman will not come today
  • 33. In order for our model to be more faithful to reality, we must have other means of representing knowledge than in simple propositions (B = It is Sunday today). Real-world problems involve several interrelated propositions. To form more complex premises, two or more propositions can be combined using logical connectors. These connectors or operators are designated as the logical operators AND, OR, NEGATION, INVOLVED and EQUIVALENT. Connector Symbol AND , , ,. OR V, ,. + NEGATION , ~ INVOLVED ,  EQUIVALENT  NEGATION AT  AT V F F V A = It's raining today  A = It's not raining today
  • 34. AND D E D E F F F F V F V F F V V V D = The car is black E = The automobile has a six-cylinder engine D  E = The automobile is black and has a six cylinder engine OR P Q P  Q F F F F V V V F V V V V P = The moon is a satellite Q = Earth is a satellite P  Q = The moon or the earth is a satellite
  • 35. EQUIVALENT This connective can be interpreted as being "if and only if" P Q P  Q F F V F V F V F F V V V P = The human being breathes Q = There is air P  Q = The human being breathes if and only if there is air INVOLVEMENT This connective means that if proposition A is true, then proposition B is also true IF A THEN B AT B AT  B F F V F V V V F F V V V A = The automobile engine is defective B = I cannot drive today AT  B = If (the automobile's engine is faulty) THEN (I cannot drive today)
  • 36. CALCULATION OF PREDICATES (FIRST ORDER LOGIC) Although propositional logic is a way to represent knowledge, it is not widely used in artificial intelligence applications. Since propositional logic is based on complete statements which can only be true or false, its ability to represent real world knowledge is limited. This is why the discipline of artificial intelligence uses the calculation of predicates (first order logic). In the computation of predicates, a proposition or premise is divided into two parts:  arguments (objects): arguments are the individuals or objects treated by the assertions - names serving as subject or objects of a sentence  predicates (assertions): assertions made with objects - verb or part of the verb The two parts are combined to create a proposal: PREDICATE (Individual [object] 1, Individual [object] 2) Examples Example 1: The car is in the garage IN (automobile, garage) IN = Products (assertion) Automobile = Argument (object) Garage = Argument (object)
  • 37. Example 2: Proposal: Jean loves Marie Expression of the predicate calculation: AIME (Jean, Marie) Other formats are also used such as: (in auto garage) or (likes Jean Marie) In other cases, the proposition may have only one argument. Some examples are: The door is open OPEN (Door) John is a man Male (Jean) VARIABLES In the calculation of predicates, letters can be substituted for arguments. The x or y symbols can be used to denote individuals or objects. The previous example "John loves Mary" can be expressed in variables of the form x = John and y = Mary. The proposition then becomes: Like (x, y) If variables are used, then the defined proposition is true for all names substituted for variables. Using this system, a knowledge base can be defined. Knowledge, expressed in the computation of predicates can be manipulated to generate inferences.
  • 38. Example: Jean loves Marie Raymond loves Marie John = x, Mary = y, Raymond = z Likes (x, y) AND Likes (z, y) INVOLVES  Like (x, z) The expression means that: If (Jean loves Marie) AND (Raymond loves Marie) THEN (Jean does not like Raymond) INSTANTIATION Instantiation is the name given to the process of assigning a specific object or individual to a variable. This object or this individual becomes an instance of the variable. Associating the variable x with the individual Raymond is an example of instantiation (x = Raymond). WELL FORMED FORMULAS (WELL FORMED FORMULAS) - WFF (WELL FORMED FORMULAS) Well-formed formulas are logical expressions consisting of:  variables  predicates  quantifiers 1. universal (): quantify all the elements (means "for all") 2. existential(): quantify us only element (means "it exists")  connective
  • 39. Examples: All Texans are citizens of the United States (x) [Texan (x)  Citizen of the United States (x)] Cars are red (x) [automobile (x)  Red (x)] PRODUCTION RULES The basic principle of programming in production rules is that each rule is an independent piece of knowledge (we say: granule), that is, it contains all the conditions for its application. A rule can translate a relation, semantic information or a conditional action. As a result, it is only the comparison between the triggering conditions of a rule and the existing facts which makes it possible to "filter" the rules to retain only those which are applicable. (The premise part is also called the filter of the rule, "pattern" in English. The SEs are also often designated by the term "Pattern Directed Inference Systems" that is, inference systems directed by the filters). A production rule is generally of the form: If Premise (Antecedent) Then Consequential. The premise or antecedent represents a situation The consequent states a particular action or conclusion that applies if the premise is true.
  • 40. The most well-known forms of production rules have the following formats: Antecedent Consequent Situation Action Premise Conclusion Examples: IF the share price drops below $ 250.00 THEN buy 100 shares IF the temperature exceeds 30 degrees Celsius THEN start the fan IF the automobile runs out of gas AND a gas station is in sight THEN go fill up with gasoline IF the temperature exceeds 30 degrees Celsius OR the manual control is activated THEN start the fan A set of production rules forms a knowledge base which becomes a component of a production system. A production system includes a knowledge base, memory, and an inference (control) mechanism. Some initial conditions or goals to be achieved are provided to the working memory. The inference and control mechanism searches the knowledge base for rules that can be associated with the initial conditions. These rules together with the initial conditions or goals provide the basic knowledge used to solve the problem. The best known example of a production system is an expert system.
  • 41. This method of representation used in the majority of ES (MYCIN, DENDRAL, LITHO, DRILLING ADVISOR, R1, DELTA ...) has certain advantages due to this structure:  Ease of modification, due to the modularity of knowledge.  The more rules the system has, the more powerful it is (in theory).  Very easy to read the rules and therefore easy to write.  Possible introduction of likelihood coefficients to weight knowledge.
  • 42.
  • 43. COURSE 03 INF-38299 - ARTIFICIAL INTELLIGENCE  THE REPRESENTATION OF KNOWLEDGE SEMANTIC NETWORKS This formalism, whose authorship is generally attributed to Quillian in 1968, allows the representation of knowledge in the form of graphs:  Nodes represent concepts (objects or events).  The arcs reflect the relationships between these concepts
  • 44. This description can be put in the form of a n-tuple:  Sub-set of (chair, furniture)  Has (chair, backrest)  Has (my grandmother's chair, arms) The "furniture" node represents a class of objects whose node "chair" is a special element. The same goes for the "chair" and "my grandmother's chair" nodes. This hierarchical structure allows nodes at lower levels to inherit properties from nodes at higher levels. Thus, we can deduce from the previous diagram that my grandmother's chair has a backrest. On the other hand, as far as the number of legs is concerned, a chair in general (object class) has four, but my grandmother's chair in particular has three. The lower level properties (exceptions) correct the upper level properties (default values). A semantic network can express any sentence and moreover important applications in understanding natural language have been realized.
  • 45. Let us quote a slightly more complicated example: "The crow held the cheese proudly until the evening". Semantic networks can also model quantifiers, implications ...
  • 46. But all these representations are only operational if there are procedures that manipulate them. These procedures work like a unification algorithm, that is to say they try to replace the variables (unknowns whose value we are looking for) by constants, by comparing the request and the set of assertions. For example, the query "Which chair has a number of legs equal to three?" will be represented by: The study of the diagrams allows easily to find "X = chair of my grandmother".
  • 47. But most often, the answer to a question is not immediate and requires a journey through the network, so as to use the relationships or attributes characterizing the entities involved. One of the drawbacks of this representation is the combinatorial explosion of the information search when the number of nodes and arcs becomes too large. There is therefore a compromise to be found between the complexity of the data structure and the complexity of its interpreter. Semantic networks have been used to build ES, PROSPECTOR which works in the field of mineral geology is the one which makes the greatest use and with very good results. However, work on this formalism has focused more on finesse, consistency of representation of concepts and philosophical implications than on practical applications. The structuring of semantic networks has gradually led to hybrid representations between production rules and structured objects.
  • 48. STRUCTURED OBJECTS The different formalisms of knowledge representation that we have just studied favored the declarative aspect of knowledge as well as its inferential nature (logic, rules of production). However, the knowledge that is not inferential (example: variation around a prototype) was difficult to represent. Representation in structured objects is an attempt to represent, more conveniently than by inference, certain forms of knowledge. The term structured object covers various names such as:  Frames, a notion launched by Minsky.  Schemes, in the work on memory.  Scripts, which describe the sequence of stereotypes of events.  Prototypes, or units in KRL.  Objects, in Smalltalk, Flavors, Mering, Loops ...  Shapes and classes, in Simula.  Actors, in Plasma.  Abstract types. This representation can be considered as an extension of semantic networks. Extension incorporating procedural knowledge and introducing a conceptual rigor absent in this representation. An object contains a certain number of attributes (or slots) which are the names of the properties characterizing the object. For example, we will speak of "Color", of "Material", of "Number of legs" for a "Chair".
  • 49. These attributes contain facets which are standard (value, default, validity interval, etc.). On the other hand, an object is part of a hierarchy and therefore has more general objects than it, with which it is linked by pointers (Sort of). Finally, procedures are associated with objects to calculate precise values (procedural attachments). In summary, a structured object contains attributes having several facets, a special attribute that points to other objects and procedures associated with it. This object can be considered as "ideal" and serving as a basis for comparison to analyze other objects. It is very similar to semantic networks. Let us examine the main existing facets through the study of an example. Example: CHAIR (class) Kind of (movable value) Number of feet (default 4) Color ((possibilitdés (white blue brown)) (brown default)) Age (restriction (> 0) (<700)) MY GRANDMOTHER'S CHAIR (object) Sort of (chair value) Number of feet (value 3) Color (white value) Material (wood value) Age (value 50)
  • 50.  Value designates the value of an attribute.  Default indicates the default value of the attribute if nothing else is specified.  A priori, the object "my grandmother's chair" would have been assigned four feet by inheriting the default value from its parent "chair", but the value 3 replaces it. Restriction is a list of predicates which should return TRUE when applied to the value that we are trying to assign to the appropriate attribute.  Possibilities, special case of restriction where the exhaustive list of possible values is indicated.  Interval, another way of expressing a restriction. Example: Age (range [0 -700]).  Procedure (method), used to call a function calculating the value of the attribute concerned. It's a kind of procedural attachment. For example, we can call a function that will calculate the day of the week according to the given date ...  Daemon, another form of procedural attachment that automatically calls a function each time the value of the attribute concerned changes. For example, in the event of a change in color (value) of an indicator light attribute, a message could be printed automatically to warn the user.
  • 51. At the present time and to our knowledge, there is no SE using only structured objects. In general, object language is used to represent static knowledge, descriptive and production rules are used to make inferences. However, object-oriented languages are more and more widespread in computing thanks to their modularity and ease of reading. In AI, research is underway to integrate this mode of representation with first-order logic as well as to implement inference engines using object-oriented languages. We have just seen the different approaches used to represent knowledge in ES, it remains to study the control structure manipulating this knowledge.
  • 52. CONTROL STRUCTURES IN EXPERT SYSTEMS The inference engine is the heart of the SE, it is it which, fed by the knowledge base, dynamically builds the reasoning, deciding which rules to trigger and in what order. The reasoning mechanisms using the production rules are those of formal logic: the "modus ponens" and its counterpart the "modus tollens".
  • 53. MODUS PONENS So far we have studied systems representing facts and knowledge in symbolic form. The practice of artificial intelligence ensures that knowledge must be used to make inferences, reason, answer questions or draw conclusions. The techniques used by artificial intelligence use the various rules of inference to manipulate logical expressions and create new facts. These theories assume that if the original propositions are true, then the conclusions will also be true. The simplest rule of inference is the "modus ponens" which makes it possible to assert from the proposition "if A then B" and from the assertion A, to deduce B. [AT  (AT  B)]  B If A If A, then B So B Example: A = It's sunny B = We will go to the beach AT  B = If (it's sunny) THEN (we'll go to the beach) SO (we will go to the beach)
  • 54. MODUS TOLLENS The "modus tollens" deduced from the same rule and from not B, not A. [B  (AT  B)]  AT If A, then B B Therefore AT Example: A = It's sunny B = We will go to the beach AT  B = If (it's sunny) THEN (we'll go to the beach) B = We will not go to the beach SO (it's not sunny)
  • 55. OPERATION OF INFERENCE ENGINES However, whatever the reasoning mode used, the basic cycle of an inference engine (work cycles linked to achieve the result) comprises four phases:  Selection phase, of a subset of the fact base (and rule base) that deserves more attention than the rest of the base. This restriction phase saves time for the next phase. This choice is the expression of a strategy which causes the inference engine to favor a given group of rules and not another. We will not take this phase into account afterwards because it does not modify the course of the following phases.  Filtering phase. During this step, the inference engine compares the premise part of the selected rules with the facts from the fact base to determine the set of applicable rules. The progress of this phase is shortened by the previous phase which made it possible to considerably restrict the set of rules which will be filtered with the fact base.
  • 56.  Conflict resolution phase (or choice). The result of this phase is the choice of the rule that will be applied effectively. This crucial phase also expresses a strategy that can be very simple and unrelated to the context (the first rule in the list, the least complex, the least used ...) or more complex and taking into account the context (the most promising , the most reliable, the least expensive ...) The quality of this choice depends on the performance of the inference engine which will more or less quickly deduce the solution.  Execution phase. This phase consists in applying the rule chosen previously, this action generally consists in adding one or more facts to the fact base. It is also possible that the application of this rule calls for external procedures, modifies the fact base, questions the user ... The stopping of this cycle depends on the mode of reasoning used. Three modes of reasoning can be used, inducing certain differences at the level of the basic cycle:  Forward, data-driven chaining.  The backward chaining, directed by the goal.  Mixed chaining. Let's take a closer look at each of these modes of reasoning.
  • 57. FRONT CHAIN The inference engine starts from the facts to arrive at the goal, that is to say that it selects only the rules whose conditions of the left part are verified (phase of filtering detection). The choice phase (conflict resolution) is then applied to this set of rules, to determine which rule to use first. Applying this rule generally results in an update of the fact base (execution phase). This process is repeated until there are no more applicable rules or the goal is reached. This can be schematized as follows: Entering the initial facts Start Filtering phase Determination of all applicable rules As long as the set of applicable rules is not empty AND the problem is not resolved Make Choice phase Conflict resolution Apply the chosen rule (execution) Possibly modify all the applicable rules End do End While End The efficiency of the inference engine lies in the relevance of the decision taken (elected rule) during the choice phase. It is this choice which conditions the speed with which the system will arrive at the solution.
  • 58. EXAMPLE Either the knowledge base: R1: If B and D and EA then F R2: If D and G then A R3: If C and F, then A R4: If B then X R5: If D A then E R6: If A and X Then H R7: If C then D R8: If X and C then A R9: If X and B, then D Let the fact base: B, C and the goal: H Solution corresponding to the choice of the first applicable rule in the order of their numbering. Strategy in depth first (exploration of a branch of the tree to the end and backtracking in case of failure).
  • 59. Solution corresponding to a strategy selecting among the applicable rules whichever has the greatest number of conditions, in case of equality the lowest number rule is used For example, R8 is preferred over R7 because it has two conditions against one in R7. In both cases, the nodes represent the succession of the different states of the fact base and the arcs the rules that can apply to this state. Dashed arcs correspond to applicable rules that have not been used. Only the rules corresponding to the arcs in solid lines were applied by the inference engine. When a rule has already been applied, the system does not apply it again. Indeed, it would be pointless to deduce a fact which has already been deduced. We can therefore clearly see, on these two examples, that the efficiency of an inference engine, that is to say the speed with which it reaches the goal (which is measured in number of inferences), strongly depends of the choice phase
  • 60. However, this mode of reasoning has several drawbacks:  The system triggers all applicable rules even if some are of no interest.  The fact base must contain enough initial facts for the system to achieve the goal.  The user must therefore provide the OS with all the information it possesses even if some are unnecessary.  In the event of failure, only one fact could achieve the goal but the user is not informed since this process is not interactive.  This method risks running up against the combinatorial explosion if the number of rules and facts is important, and especially if the goal to be reached is not known, because it is then necessary to apply all the applicable rules to deduce all that can be deducted. All the more so since many inference engines reasoning in forward chaining, work in width first (application of all the rules applicable at a given moment)
  • 61. REAR CHAIN The system starts from the goal (or a goal hypothesis) and tries to go back to the facts to demonstrate it. The selected rules are those whose right part (consequent) corresponds to the desired goal. The unknown conditions (left part) of these rules become so many sub-goals to be demonstrated. This process is repeated until all sub- goals are demonstrated, then the goal is reached, or until it is no longer possible to select rules. In this case, the system can ask the user to solve one or more sub- goals (questions, tests ...) and the process starts over. The failure occurs when the system can no longer select any rules, nor ask the user questions (insufficient or inconsistent rules, or the user cannot answer the questions of the OS).
  • 62. This process can be schematized as follows: Start Filtering phase If the set of selected rules is empty So - question the user If not As long as the goal is not resolved AND there are still selected rules Make Choice phase Add the sub-goals corresponding to the left part of the elected rule If a sub-goal is not resolved So solve it (start over) End if End do End while End if End
  • 63. Rules R2, R3 and R8 can be used to verify goal A. The strategy used is very simple, since it consists of using the first applicable rule, in their numbering order, to then seek to verify the produced sub-goals one after the other (in-depth exploration first). In case of failure, for example the sub-goal G could not be deduced, there is backtracking in the tree structure and the last rule left aside is in turn tried (R3 here).
  • 64. Exploration can stop:  when the initial goal has been demonstrated (this is the case here),  when all possibilities have been explored without success. The system can then query the user on the unresolved sub-goal. Note that this mode of reasoning consists in constructing an AND / OR graph. Backward chaining has a few advantages:  The system asks questions only when necessary and after exploring all possibilities.  Often the search tree is smaller than in forward chaining.  The process is interactive. One of the risks of backward chaining is that of looping: to prove A, you have to demonstrate B, to prove B, you have to demonstrate A ... What some inference engines take into account (Mycin for example).
  • 65. MIXED REASON The inference engines offering forward chaining and backward chaining alternately (bidirectional chaining) should not be confused with those offering mixed chaining, that is to say combining these two types of reasoning. In this case, the rules appeal simultaneously, partly premise, to established facts (before) and others to be established (rear). As for bidirectional chaining, several possibilities exist. Generally, the ES proceeds by forward chaining to determine partial conclusions and then these hypotheses are then verified by backward chaining. The inference engine can also alternately use forward and backward chaining and examine at each cycle whether these two reasonings meet. This allows you to go halfway and stop in the middle, or at the junction point. Another possibility is backward chaining on system goals or sub- goals, with forward chaining propagation of verified sub-goals.
  • 66. CHOICE OF A CONTROL STRATEGY Whatever type of reasoning you choose, building an inference engine involves two delicate steps: - The definition of methods for selecting candidate rules. To do this, each rule must be compared with all the basic facts or with the goal. This comparison search operation is called "pattern-matching" which may be preceded by a restriction phase. - The choice of the rule to be triggered. This choice influences the performance of the system, however, a man knows which knowledge to use in a given situation but not an OS. He often has a rigid choice strategy (the first, the most recently applicable ...) and in fact this problem is poorly resolved. A more interesting way is the use of meta-rules to guide the choice of the system. These are also given in the form of production rules. Provided by the expert, they express his strategies for choosing the rules. The quality of the choices made to build these two elements decisively affects the efficiency of the inference engine. When it comes to choosing between forward and backward chaining, we can say that no strategy is right for every problem. Data-driven monitoring is very popular because such a program can make inferences from the information provided by the user without the user being forced to specify their question.
  • 67. This approach is easily programmable and seems the most natural when the system has a certain number of facts and the resolution is done blindly, not knowing a priori what goal to achieve. However, this strategy is ineffective for solving complex problems. On the other hand, if one or more goals are to be reached, or to be verified, it is more interesting to use the control directed by the goal, in order to restrict the combinatorial explosion. It seems that different approaches are necessary for different problems and that the existence of both types of routing in an inference engine is desirable. This is all the more so as our knowledge is mostly empirical but also sometimes theoretical. However, forward chaining is indicated for the processing of empirical knowledge, playing the role of meta-knowledge, and backward chaining is suited to the confirmation of goals previously mentioned with certain knowledge. Backward chaining is also recommended in the case of incomplete information or a dialogue with the user must be initiated.
  • 68. In addition to this distinction between modes of reasoning, other criteria are added to differentiate inference engines.  Irrevocable and tentative strategies A strategy is said to be irrevocable if the choices made (rules applied) are never called into question. Conversely, a strategy by attempts can call into question the application of a rule if this choice results in failure. The inference engine then performs a backtracking to try a previously discarded rule In general, backward chaining inference engines tend to use an attempt-based strategy while forward chaining inference engines use an irrevocable strategy.
  • 69.  Strategies in depth or in width first In an in-depth strategy first, the inference engine explores the AND / OR tree of solutions, first in its depth (by exploring a branch to the end). Conversely in width first, the inference engine explores the tree in its width (by exploring all possible branches). A strategy can be in-depth and irrevocable or by attempts. The same goes for the width. In fact, the strategies by attempts are generally in depth first because in width we explore the whole graph so backtracking is not useful.
  • 70.
  • 71. COURSE 04 INF-38299 - ARTIFICIAL INTELLIGENCE 1. Bratko Book, Chapters 1 & 2 PROLOG means programming in logic: LOGIC PROGRAM The PROLOG programming language is structured around a few basic mechanisms:  filtering ("pattern-matching")  a tree structure of data (rules and facts)  automatic backtracking The PROLOG language is particularly well suited to problems involving objects (and in particular structured objects) as well as relationships. These characteristics make PROLOG a powerful language for artificial intelligence (AI), and more generally for all non-digital programming.
  • 72. Prolog is a widely used language mainly in academia and the world of research. He is linked :  formal logic and new forms of programming;  to a modeling of reasoning;  linguistic processing, writing grammars, analyzers;  to databases: it is easy to transcribe SQL in Prolog and to interface a database with a logic module written in Prolog. HORN CLAUSES The generalization of modus ponens in logic requires that the statements be in a standard form called “Horn clauses” according to the work of the mathematician Alfred Horn. A Horn clause is a logical statement that can have the following forms: q1 AND q2 AND… AND qn  r [If (q 1 AND q2 AND… AND qn) THEN r] r  q1  q2  ...  sb 1. where r and qi are predicates and all variables are universally quantized.
  • 73. PROLOG logical symbols NATURAL LANGUAGE CALCULATION OF PREDICATES PROLOG and  , or  ; only if  : - negation  Not Paradigm of logic programming program = set of axioms treatment = constructive proof of a goal statement We call a logic program a set of Horn clauses.
  • 74. Example 1: Let the axioms be: All men are mortal (x) [Male (x)  Mortal (x)] Socrates is a man (x) [man (x)  (x = Socrates)] We can reformulate the first axiom: For all X, if X is a man, then X is mortal (x) [Male (x)  Mortal (x)] What we will translate in PROLOG by mortal (X): - man (X). man (socrates). ? - mortal (socrates). Yes
  • 75. Example 2: parent (X, Y) Database predicate which means: X is a direct parent of Y Rule 1: grandparent (X, Y): - parent (X, Z) & parent (Z, Y) This rule (1) reads: " X, Y if Z such that: X is a parent of Z and Z is a parent of Y, then X is a grandparent of Y ” Rule 2: ancestor (X, Y): - parent (X, Y) Rule (2) reads: " X, Y if X is a parent of Y, then X is an ancestor of Y ” Rule 3: ancestor (X, Y): - ancestor (X, Z) & parent (Z, Y) Rule (3) reads:  X, Y if Z such that: X is ancestor of Z and Z is parent of Y, then X is an ancestor of Y ".
  • 76. 2. FACTS A fact is the most basic of statements. Facts are statements that describe relationships between objects or properties of objects, for example: pupil (jean, 1975, info, 2). pupil (catherine, 1974, info, 2). pupil (luc, 1976, _, 1). masculine (jeans). masculine (luc). female (catherine). father (paul, jean).% paul is jean's father mother (isabelle, jean). The general form of a fact is as follows: predicate (argument1, argument2,…). A predicate is a symbol that translates a relation. Arity is the number of its arguments. We identify a predicate by its name and its arity: predicate / arity, for example mother / 2, pupil / 4.
  • 77. UNIVERSAL FACTS Variables are useful in the statement of facts. Example: All people love Pepsi Cola Like (X, PEPSI_COLA) The variable X is then universally quantified ( x) [like (x, PEPSI_COLA)] RULES Rules make it possible to express conjunctions of goals. Their general form is: HEAD: - C1, C2, ..., Cn. The head of the rule is true if each of the elements of the body of the rule C1, ..., Cn is true. We call this type of rule Horn clauses. son (A, B): - father (B, A), male (A). son (A, B): - mother (B, A), male (A). parent (X, Y): - father (X, Y). parent (X, Y): - mother (X, Y). here the intermediate variable Z is used grand_parent (X, Y): - parent (X, Z), parent (Z, Y).
  • 78. A predicate therefore corresponds to a set of rules or facts with the same name and the same arity: the clauses of the predicate. Many Prolog programs require that all the rules and all the facts of the same predicate be contiguous - grouped together - in the program file. We denote the predicate by its name and its arity, for example son / 2, parent / 2, grand_parent / 2. Facts are a special form of rules that are always true. The notation : made. is indeed equivalent to: fact: - true. Let us define a new predicate "ancestor / 2" determining the ancestor X of Y by recursion: Recursion termination condition if it is a direct parent. ancestor (X, Y): - parent (X, Y). Otherwise X is ancestor of Y if and only if there is Z, such that X parent of Z and Z parent of Y. ancestor (X, Y): - parent (X, Z), ancestor (Z, Y).
  • 79. When executing a query, Prolog examines the corresponding rules or facts in the order they are written to the program, from top to bottom. It uses the first rule (or the first fact) of the predicate to answer. If it fails, then it goes on to the next rule and so on until it has exhausted all the rules (or all the facts) defined for that predicate. When a rule is recursive, the Prolog interpreter recalls the predicate of the same name by examining the rules (or facts) of this predicate in the same order. In the body of a rule, the comma "," is the symbol representing a logical AND: the conjunction of goals. The symbol ";" represents the logical OR, the disjunction of goals: A: - B; vs. is equivalent to A: - B. A: - C. RECURSIVE RULES Let us define a new predicate "ancestor / 2" determining the ancestor X of Y by recursion:  Recursion termination condition if it is a direct parent: ancestor (X, Y): - parent (X, Y).  Otherwise X is ancestor of Y if and only if there is Z, such that X parent of Z and Z parent of Y: ancestor (X, Z): - parent (X, Y), ancestor (Y, Z).
  • 80. QUESTIONS OR REQUESTS The second form of statements in logic programming is the question or query. Questions or queries are a means of obtaining information from a logic program. A question or query asks if a certain relationship exists between the objects. For example, the query: father (abraham, isaac). asks the logic program if the paternity relationship exists between abraham and isaac Once the program has loaded, you can ask questions about the facts: masculine (jeans). masculine (luc). ? - masculine (jeans). Yes ? - masculine (françois). No. (Not in the database)
  • 81. EXISTENTIAL REQUESTS Logically, query variables are existentially quantized, which means, intuitively, that the query: father (abraham, X) means: Is there an X such that Abraham is the father of X ( x) [father (abraham, x)] Variables can be identified with all other values: with constants, with compound terms, with the variables themselves. Constants start with a lower case, variables start with an upper case. ? - masculine (X). X = jeans; X = luc; No The ";" character allows you to request the following solution. The "Return" character stops the search for solutions. ? - student (X, Y, Z, 2). X = jeans, Y = 1975, Z = info; X = catherine, Y = 1974, Z = info <CR> ? -
  • 82. TYPES OF PROLOG In Prolog, everything is a term:  Constants or atomic terms: 1. Atoms are alphanumeric strings that start with a lowercase: jean, paul, toto1. You can transform a string containing special characters (period, spaces, etc.) into an atom by surrounding it with "'" characters. So 'marc' and 'cube' are atoms. 2. The numbers: 19, -25, -3.14, 23E-5  Variables start with a capital letter or the _ sign. _ all by itself is an anonymous variable: X XYZ Xyz _x _3 _. The system internally renames its variables and uses the _number convention, such as _127 or _G127.  Structures or compound terms consist of a functor with a series of arguments. The arguments can be atoms, numbers, variables, or structures such as: 1. pupil (Robert, 1975, info, 2, address (6, 'Frontenac', 'Rivière-du-Loup')). In the example, pupil is the main functor.
  • 83. UNIFICATION In a question, if it succeeds, the variables unify vis-à-vis the other terms. The terms can be composed as for example: address (6, 'Frontenac', 'Rivière-du-Loup'). Add the term student (robert, 1975, info, 2, address (6, 'Frontenac', 'Rivière-du- Loup')) in the file and let's consult it. Let's ask the question: ? - pupil (X, Y, Z, T, W). X = robert Y = 1975 Z = info T = 2 W = address (6, 'Frontenac', 'Rivière-du-Loup') The Prolog unifies the term of the question to the term contained in the database. For this, it performs the substitution of the variables X, Y, Z, T, W by terms, here constants and a compound term. We note this substitution: {X = robert, Y = 1975, Z = info, T = 2, W = address (6, 'Frontenac', 'Rivière-du-Loup')}
  • 84. We say that a term A is an instance of B if there is a substitution from A to B: masculine (jean) and masculine (luc) are instances of masculine (X) {X = john} or {X = luc} are the corresponding substitutions. A term is ground term if it does not include a variable: f (a, b) is founded f (a, X) is not a substitution is founded if the terms which compose it are founded: {X = a, Y = b} is founded {X = a, Y = f (b, Z)} is unfounded. SHARED VARIABLES We use the same variable to force two arguments to have the same value. For example, to look for a student who would bear the name of his field: ? - student (X, Y, X, Z). The questions can be conjunctions and we can share variables between the goals. To find all male students, we divide the variable X between student and male: ? - pupil (X, Y, Z, T), masculine (X).
  • 85. EXAMPLE: DEFINITION OF RELATIONSHIPS % enumeration of facts parent (pam, bob).% Pam is one of Bob's parents parent (tom, bob).% Clause 2 parent (tom, liz). parent (bob, ann). parent (bob, pat). parent (pat, jim). male (tom).% Tom is male male (bob).% Bob is male man (jim). female (pam).% Pam is female woman (liz). woman (ann). woman (pat). Pam Tom Bob Liz Ann Pat Jim
  • 86. % enumeration of rules child (Y, X): -% Y is a child of X if parent (X, Y).% X is one of the parents of Y mother (X, Y): -% X is the mother of Y parent (X, Y),% X is one of the parents of Y and female (X).% X is female grandparent (X, Z): -% X is one of Z's grandparents parent (X, Y),% if X is one of the parents of Y and parent (Y, Z).% Y is one of the parents of Z sister (X, Y): -% X is sister of Y if parent (Z, X), parent (Z, Y),% X and Y have the same parents female (X),% X is female different (X, Y).% X and Y are different ancestor (X, Z): -% X is a direct ancestor of Z parent (X, Z).% Condition for stopping recursion ancestor (X, Z): -% X is an indirect ancestor of Z parent (X, Y), ancestor (Y, Z).
  • 87. REQUESTS ? - parent (pam, bob). Yes ? - parent (pam, tom). No ? - child (liz, tom). Yes ? - mother (pam, bob). Yes ? - grandparent (bob, jim). Yes ? - sister (liz, bob). Yes ? - ancestor (pam, jim). Yes ? - parent (X, liz). X = tom ? - parent (bob, X). X = ann; (you must type a ";" to get the other answers X = pat
  • 88. ? - parent (X, Y). X = pam Y = bob; X = tom Y = bob; X = tom Y = liz; .... ? - parent (Y, jim), parent (X, Y) X = bob Y = pat X Y Jim Parent Parent
  • 89. PROCESSING OF RULES (CLAUSES) BY TRAVERSING A RESOLUTION TREE Clause - Rule 1: ancestor (X, Z): - parent (X, Z). Clause - Rule 2: ancestor (X, Z): - parent (X, Y), ancestor (Y, Z) ancestor (tom, pat) By rule 1 By rule 2 parent (tom, Y) ancestor (Y, pat) parent (tom, pat) Failure 2. Y = bob by parent (tom, bob) ancestor (bob, pat) By rule 1 parent (bob, pat) Success
  • 90. DECLARATIVE AND PROCEDURAL MEANINGS OF PROGRAMS PROLOG programs have two levels of meaning: - declarative meaning: focuses on the relationships defined by the program through the formulation of facts and rules. It therefore determines what the program will produce. - procedural significance: determines how results will be obtained and how relationships will actually be evaluated by the PROLOG system. This approach focuses on the generation of state spaces and traversal of resolution trees.
  • 91. IDENTIFICATION It is possible to represent complex data in PROLOG language using terms. The most important operation concerning terms is identification (matching). Given two terms, we say that they identify if:  they are identical  the variables present in the two terms can be instantiated so that the terms of each object become identical Example: The two terms: date (J, M, 1983). date (D1, May, A1). are identifiable. One of the instantiations making the two terms identical is as follows:  J is instantiated at J1  M is instantiated to May  A1 is instantiated at 1983 This is stated in a more compact way using the format used by PROLOG to produce its results: J = J1 M = May A1 = 1983
  • 92. PROCEDURAL SIGNIFICANCE The procedural meaning is how the PROLOG inference engine answers questions. Finding the answer to a question is like erasing a list of goals. This is only possible if the variables appearing for these purposes can be instantiated in such a way that they logically derive from the program. The PROLOG language is therefore a procedure responsible for executing a list of goals according to a given program. Executing a goal means that we are trying to erase it. The inputs and outputs of the execution procedure are:  entry: a program and a list of goals  output: a success / failure indicator, and an instantiation of the variables The meaning of the two output results is as follows:  The pass / fail indicator is "yes" if the goals are satisfactory and "no" otherwise. We will say that "yes indicates a success and" no "a failure.  The instantiation of the variables takes place only if the execution is positive program 3. execution goal list failure / success indicator instantiating variables
  • 93. THE ORDER OF CLAUSES AND GOALS Consider the following clause: p: - p. This clause means: p is true if p is true At the syntax level, this clause is correct, but is redundant. In fact, such a clause can cause problems for the PROLOG inference engine. Consider the question: ? - p. Using the previous clause, the goal p is replaced by the same goal p, which in turn is replaced by p, etc. PROLOG thus enters an infinite loop without noticing that it is not progressing. This example is a good way to make PROLOG loop, but it can also happen in other cases as a result of poor arrangement of goals inside clauses. By referring to the declarative semantics of PROLOG, we can change without affecting the declarative meaning (logic):  the order of clauses in the program  the order of goals in the body of clauses
  • 94. Changing the order of goals in the body of clauses influences the traversal of the resolution tree by the PROLOG inference engine. This can generate infinite loops (combinatorial explosions). Combinatorial explosions are generally signaled to the user by the PROLOG language by a message indicating a stack overflow. USING THE PROLOG INTERPRETER We load or replace the (update) file in the Prolog interpreter with the command: ? - consult (filename). or with the shortcut: ?- [file name]. Under the LINUX system in console mode: pl -s filename.pl Programs are usually in files with the ".pl" suffix. To compile and load a program: ? - consult (name_of_file). where filename is an atom, for example: ? - consult ('file.pl').
  • 95. or the shortcut with the command: ?- [file name]. for example ? - ['file.pl']. Another shortcut with SWI: ? - [file]. Loading multiple files simultaneously ? - ['file1.pl', 'file2.pl']. Once the files are loaded, you can run the commands. They end with a period ".": ? - man (socrates). Conjunctions of goals are separated by ",": ? - large (X), blue (X), on_the_cube (X). You can also include directives in a file by the instruction: : - clause_to_execute. Directives are clauses that the interpreter will execute when loading the program. The content of the loaded file is displayed by: ? - listing.
  • 96. The display of a particular clause, here father, is done by: ? - listing (father). If we modify the program in the file, we can update the database by (Not with SWI where we can only consult): ? - reconsult ('file.pl'). The reload shortcut is: ? - [-'file.pl ']. Finally, we leave Prolog with ? - halt.
  • 97. COURSE 05 INF-38299 - ARTIFICIAL INTELLIGENCE 2. Bratko Book, Chapters 3 & 4 3. CHAPTER 3 In this chapter we will study a special notation for lists, one of the simplest and most useful structures, as well as some typical programs for manipulating them. We will also look at elementary arithmetic and operator notation, which often improves the readability of programs. With these three elements, the basic Prolog of the second chapter becomes a comfortable programming environment. 1. REPRESENTATION OF LISTS The list is a basic data structure, widely used in non-numeric programming. A list is a sequence of any number of objects, such as anne, tennis, tom, ski. This list can be written as follows in Prolog: [anne, tennis, tom, ski] However, this is only the outward appearance of the list. As we have already seen, all structured objects in Prolog are trees. Lists are no exception. How can a list be represented by a standard Prolog object? We have to consider two possibilities: either the list is empty or it is not (!). In the first case, the list is simply written as an atom: [].
  • 98. In the second case, we can consider that the list is made up of two parts:  the first object, called the head of the list,  what's left of the list, called the tail. For our example [anne, tennis, tom, ski] the head is anne, and the tail is the list [tennis, tom, ski] In general, the head can be anything (any Prolog object, like a tree or a variable), but the tail must be a list. The head and tail are then combined by a special functor to give structure. The choice of this functor depends on the implementation of Prolog, but here we will assume that it is the point: . (Head, Tail)
  • 99. Since Queue is a list, it is either empty or in turn made up of a head and a tail, which allows lists of any length to be represented. The following term therefore corresponds to our example list: . (anne,. (tennis,. (tom,. (ski, [])))) The figure gives the associated tree structure. Notice that the empty list appears among the terms, because the penultimate queue is the list consisting of a single object: [ to ski ] However, the tail of this list is the empty list: [to ski] =. (to ski, []) This example shows how the general principle of data structuring in Prolog also applies to lists of any length. Likewise, it highlights the fact that the raw representation of a list using the dot functor can produce relatively confusing expressions, especially if the tail of the list is made up of many nested subterms. This is the reason why it is preferable to use the notation proposed by Prolog, consisting in putting the rest of the terms of the list in square brackets, the choice being possible for the programmer. It should not be forgotten that behind this facade, our lists are represented internally as binary trees, and automatically converted to the most readable form when they are printed.
  • 100. It will therefore be possible to have the following exchange with Prolog: ? - List1 = [a, b, c], List2 =. (A,. (B,. (C []))). List1 = [a, b, c] List2 = [a, b, c] ? -Leisure1 =. (Tennis,. (Music, [])), Leisure2 = [skiing, eating], L = [anne, Loisirs1, tom, Loisirs2]. Hobbies1 = [tennis, music] Leisure2 = [skiing, eating] L = [anne, [tennis, music], tom, [skiing, eating]] This reminds us that the elements of a list can be objects of any type, and in particular lists. It is often convenient to treat the tail of a list as a whole. For example: L = [a, b, c] We can write: Queue = [b, c] and L =. (A, Queue)
  • 101. To express this in the form of a list in square brackets, Prolog provides us with a new notation, the vertical bar, which separates the head and the tail: L = [a | Tail] This notation is actually much more general: we can write any number of elements followed by a "| », Then from the list of remaining objects. Which gives the following ways of writing our list: [a, b, c] = [a | [b, c]] = [a, b | [c]] = [a, b, c | []] To summarize:  A list is a structure that is either empty or made up of two parts: a head and a tail, the latter itself being a list.  Prolog manages lists as a special case of binary trees. To make it easier to read, Prolog allows special notation: [Object1, Object2, ...] or [Head | Tail] or [Object1, Object2, ... | Others]
  • 102. 2. LISTS OPERATIONS Sets can be represented by lists, with one difference: the order of the elements in a set does not matter, while this order is essential in a list. The same object can also appear there several times. The fact remains that the most common operations that can be performed on lists are similar to set operations. Among those:  checking for the presence of an object in a list, which corresponds to the set membership test  the concatenation of two lists, to obtain a third one, which corresponds to the set union.  adding a new object to a list, or deleting an object. In the rest of this section, we show how to program these operations on lists, as well as a few others. 1. MEMBERSHIP Define the membership relation as being: member (X, L) where X is an object and L is a list. The goal member (X, L) is verified if X appears in L. For example: member (b, (a, b, c]) is right
  • 103. member (b, [a, [b, c]]) is not true, however member ([b, c], [a, [b, c]]) ballast. The program that corresponds to this relationship can be based on the following observations: X is a member of L if (1) X is the head of L, or if (2) X is a member of the tail of L. Two clauses are enough to write this, the first being a simple fact, and the second a rule: member (X, [XI Queue]). member (X, [Head I Tail]): - member (X, Queue).
  • 104. 2. CONCATENATION To concatenate two lists, we define the relation conc (L1, L2, L3) L1 and L2 are two lists, while L3 is the result of their concatenation. for example conc ([a, b], [c, d], [a, b, c, d]) is true, however conc ([a, b], [c, d], [a, b, a, c, d]) is wrong. In our definition of conc, we still have to consider two cases, depending on the first argument L1: If the first argument is the empty list, then the second and the third argument must be the same list (let's call it L), which is expressed in Prolog by the following fact: conc ([], L, L). If the first argument to conc is a non-empty list, then it has a head and a tail like this: [X | L1]
  • 105. The figure illustrates the concatenation of [XI L1] and a list L2. The result is a list [X, L3] where L3 is the concatenation of L1 and L2. What we translate into Prolog: conc ([XI L1], L2, [XI L3]): - conc (L1, L2, L3). We can now use this program to concatenate lists: ? - conc ([a, b, c], [1, 2, 3], L). L = [a, b, c, 1, 2, 3] ? - conc ([a, [b, c], d], [a, [], b], L). L = [a, [b, c], d, a, [], b]
  • 106. Rather simple in appearance, conc is very flexible and can be used in many other ways, for example to split a given list into two lists: ? - conc (L1, L2, [a, b, c]). L1 = [] L2 = [a, b, c]; L1 = [a] L2 = [b, c]; L1 = [a, b] L2 = [c]; L1 = [a, b, c] L2 = []; no The program gave the four ways to break down the list [a, b, c], using backtracking. We can also use backtracking to find a certain item in a list, such as finding the months before and after a given month: ? - conc (Before, [May | After], [jan, feb, mar, apr, mail jun, jui, aut, sep, oct, nov, dec]). Before = [Jan, Feb, Tue, Apr] After = [jun, jui, aut, sep, oct, nov, dec]. We get the immediate predecessor and successor of May as follows: ? - conc (_, [Month1, May, Month2 | _], [jan, feb, mar, apr, mail jun, jui, aut, sep, oct, nov, dec]). Month1 = Apr Month2 = jun
  • 107. Let us now decide to delete in an L1 list everything that follows three successive occurrences of z, as well as the three z: ? - L1 = [a, b, z, z, c, z, z, z, d, e], conc (L2, [z, z, z | _], L1). L1 = [a, b, z, z, c, z, z, z, d, e] L2 = [a, b, z, z, c] We have already programmed the membership relationship. conc allows to redefine it in a more elegant way: member1 (X, L): - conc (L1, [XI L2], L). This clause means that X is a member of list L if L can be decomposed into two lists, with X being the head of the second. It goes without saying that member1 defines the same relation as member, the two names serving only to differentiate the two implementations. Note that we could have used anonymous variables: member1 (X, L): - conc (_, [X | _], L). It is interesting to compare these two implementations. The procedural meaning of member is relatively obvious: To verify that X is a member of a list L,  first check that the head of L is equal to X, and if not  verify that X is a member of the tail of L.
  • 108. In the case of member1, it is the declarative meaning that is immediate, not procedural significance. An interesting exercise is to find out how member1 actually works. To see more clearly, consider the tracing of the execution of the following question: ? - member1 (b, [a, b, c]).
  • 109. The figure gives the execution tracing, from which we can infer that member1 has the same behavior as member. It goes through the list, item by item, until the answer is found, or the list exhausted.
  • 110. 3. ADDING AN OBJECT The easiest way to add an object to a list is to place it there at the beginning, so that it becomes the head. If X is the new object, and L the list to which it is added, then the resulting list is quite simply: [X | L] So we don't need a procedure for this operation. Nevertheless, this can still be expressed as a fact if necessary: adds (X, L, [X | L]). 4. DELETION OF AN OBJECT Deleting an object X from a list L can be programmed with the relation eff (X, L, L1) on L1 is equal to the list L, once X is deleted, eff has a structure similar to that of member. We are again faced with an alternative: (1) If X is the head of the list, then the result is the tail of the list, otherwise (2) We try to delete X in the tail of the list. eff (X, [X | Queue], Queue). eff (X, [Y | Queue], [Y | Queue1]: - eff (X, Queue, Queue1).
  • 111. Like a member, eff by nature has non-deterministic behavior. If several occurrences of X appear in the list, then eff will be able to delete any one, thanks to the rollback. Of course, each of the sequences executed will erase only one occurrence of X, without affecting the others. For example: ? - eff (a, [a, b, a, a], L). L = [b, a, a]; L = [a, b, a]; L = [a, b, a]; no delete fails if the list does not contain the object to be deleted. You can also use eff in the other direction, to insert a new object anywhere in the list. For example, if we want to see all possible locations in the list [1, 2, 3], we just have to ask the question: What is the list L such that after deleting a, do we get [1, 2, 3]? ? - eff (a, L, [1, 2, 3]). L = [a, 1, 2, 3]; L = [1, a, 2, 3]; L = [1, 2, a, 3]; L = [1, 2, 3, a]; no
  • 112. In general, the operation consisting in inserting X in a List List, by giving LargestList, can be defined by the clause: insert (X, List, ListPIusLarge): - eff (X, ListPusLarge, List). With member1, we elegantly define the membership relation using conc. We can just as easily use an effect, seeing that an X is a member of List if it can be deleted from it: member2 (X, List): - eff (X, List, _) 5. SUB-SETS OF LISTS Consider now the sublist relation, which has two lists as arguments, L and S, S being a sublist of L: sublist ([c, d, e], [a, b, c, d, e, f]) is true, while sublist ([c, a], [a, b, c, d, e, f]) is not.
  • 113. The principles applied for member1 can still be used, although the relationship is more general. We can formulate it as follows: S is a sublist of L if: (3) L can be broken down into two lists L1 and L2, and if (4) L2 can be broken down into two lists, S and L3. As we have already seen, the decomposition of the lists can be done with the relation conc, which leads us to the following Prolog formulation: sublist (S, L): - conc (L1, L2, L), conc (S, L3, L2).
  • 114. Of course, the use of a sublist is flexible, which allows it to be used in several different ways. While its initial objective is to locate a sublist within a list, it can provide all the sublists of a given list: ? - sublist (S, [a, b, c]). S = []; S = [a]; S = [a, b]; S = [a, b, c]; S = [b]; ... 6. PERMUTATIONS It is sometimes useful to generate permutations of a list. For this purpose, we define the permutation relation, which has two arguments. These are two lists, such that one is the permutation of the other. Our intention is to use the possibilities of backtracking, as in the following example: ? - permutation ([a, b, c], P). P = [a, b, c]; P = [a, c, b]; P = [b, a, c]; ...
  • 115. The permutation program can also be based on the distinction of two cases, depending on the first list: (1) If the first list is empty, then the second list must also be empty. (2) If the first list is not empty, then it is of the form [XIL], and we can construct the permutation of such a list by permuting L first, which gives L1, then inserting X at all positions in L1. The two corresponding Prolog clauses are as follows: permutation ([], []). permutation ([X | L], P): - permutation (L, L1), insert (X, L1, P).
  • 116. Another method would consist in removing an element X from the first list, in permuting the rest of the latter to give the list P, then finally to add X at the head of P. Which gives the following program: permutation2 ([], []). permutation2 (L, [X | P]): - eff (X, L, L1), permutation2 (L1, P). It is interesting to perform some experiments with our permutation programs. Normal usage would look like this: ? - permutation ([red, blue, green], P). As expected, the result gives the following six permutations: P = [red, blue, green]; P = [red, green, blue]; P = [blue, red, green]; P = [blue, green, red]; P = [green, red, blue]; P = [green, blue, red]; no