Professional Documents
Culture Documents
UNIVERSITY OF SUMER
COLLEGE OF COMPUTER SCIENCE AND INFORMATION
TECHNOLOGY
COMPUTER INFORMATION SYSTEM DEPARTMENT
Students are sincerely advised to read various books and consult internet sites
for a detailed clarification of topics presented here.
Readings
Syllabus
1
Prof. Dr. Ali Hussein Hasan
Tautologies in propositional logic
Translating between English and Logic Notation
Control structures in reasoning
Backward chaining – Goal directed reasoning
Forward chaining – data directed computation or Modus
Ponens Reasoning
Hybrid control structure ( Rule – cycle hybrid)
Theorem proving by propositional logic
Semantic method
Syntactic methods
Theorem proving by Wang’s Algorithm
Resolution in propositional logic
4 Predicate logic – First order logic FOL
Writing a Sentence into Clause Forms
5 Problem solving by intelligent search
Problem Representation
Graphs versus Trees
Search methods
Systematic methods:
Depth first search
Breadth first search:-
Optimal search method
Hill Climbing method
Best first method
6 Knowledge Representation structures
Types of knowledge representation
Production Rules PR
Semantic Networks (SN).
Conceptual Graphs (CG).
Frames.
Scripts.
7 Expert systems
8 Practical programming: PROLOG
2
Prof. Dr. Ali Hussein Hasan
Introduction : Overview of Artificial Intelligence
Artificial intelligence (AI) is the study of solutions for problems that are
difficult or impractical to solve with traditional methods. It is used pervasively
in support of everyday applications such as email, word-processing and search,
as well as in the design and analysis of autonomous agents that perceive their
environment and interact rationally with the environment. The solutions rely
on a broad set of general and specialized knowledge representation schemes,
problem solving mechanisms and learning techniques. They deal with sensing
(e.g., speech recognition, natural language understanding, computer vision),
problem – solving (e.g., search, planning), and acting (e.g., robotics) and the
architectures needed to support them (e.g., agents, multi-agents). The study of
Artificial Intelligence prepares the student to determine when an AI approach
is appropriate for a given problem, identify the appropriate representation and
reasoning mechanism, and implement and evaluate it.
By different Scientists/researchers)
3
Prof. Dr. Ali Hussein Hasan
• The study of mental faculties through the use of computational
models (Charniak and McDermott, 1985).
• The study of the computations that make it possible to perceive,
reason, and act (Winston, 1992).
• A field of study that seeks to explain and emulate intelligent behavior
in terms of computational processes (Schalkoff, 1990).
• AI seeks to understand the working of the mind in mechanistic terms. The
branch of computer science that is concerned with the automation of
intelligent behavior (Luger and Stubblefield, 1993).
AI problems
For solving an AI problem, one may employ both AI and non AI algorithms.
4
Prof. Dr. Ali Hussein Hasan
1- If a solution to the problem needs symbolic representation in computers,
then we can consider it as an AI problem. Ex. Understanding of English
sentences by a computer when they are represented in the symbolic form.
2- If there is a combinatorial explosion in outputting the result of a
traditional problem. Ex. 8-queens and travelling salesman problems.
Topics of AI
5
Prof. Dr. Ali Hussein Hasan
6- Logic programming:- Logic programming is a type of programming
paradigm which is largely based on formal logic. Any program written
in a logic programming language is a set of sentences in logical form,
expressing facts and rules about some problem domain. Major logic
programming language families include Prolog, Answer set
programming (ASP) and Datalog. In all of these languages, rules are
written in the form of clauses:
H :- B1, …, Bn.
and are read declaratively as logical implications:
H if B1 and … and Bn.
7- Soft computing:- Soft computing differs from conventional (hard)
computing in that, unlike hard computing, it is tolerant of imprecision,
uncertainty, partial truth, and approximation. In effect, the role model
for soft computing is the human mind.
The principal constituents of Soft Computing (SC) are Fuzzy Logic
(FL), Evolutionary Computation (EC), Machine Learning (ML) and
Probabilistic Reasoning (PR), Artificial Neural Networks.
8- Management of imprecision and uncertainty:- imprecision generally
occurs in database due to the lack of appropriate data and poor
authenticity level of sources. It is uncertainty when the incompleteness
of knowledge is referred that originates in the knowledge base due to the
lack of certainty in the piece of knowledge.
6
Prof. Dr. Ali Hussein Hasan
Application of AI
1- Game playing:- most games are played using a well – defined set of
rules; this makes it easy to generate the search space and frees the
researchers from many of the ambiguities and complexities inherent in
less structure problem.
2- Automated reasoning and theorem proving:- most of the appeal of
automated theorem proving lies in the rigor and generally of logic.
Because it is a formal system, logic lends itself to automation. A wide
variety of problems can be attacked by representing the problem
instances as theorems to be proved.
3- Expert systems:- E.S. is a combination of a theoretical understanding of
the problem and a collection of heuristic problem solving results that
experience has shown to be effective in domain. E.S. are constructed by
obtaining this knowledge from a human expert and coding it into a form
that a computer may apply to similar problems.
4- Natural language processing NLP or understanding:- understanding
natural language involves much more than parsing sentences into their
individual parts of speech and looking these words up in a dictionary.
Real understanding depends on extensive background knowledge about
the domain of discourse and idioms used in that domains as well as an
ability to apply general contextual knowledge to resolve the omission
and ambiguities that are a normal part of human speech.
5- Image understanding:- image understanding is advanced image
processing in which artificial – intelligence techniques are used to
interpret images by locating, characterizing, and recognizing objects and
other features in the scene.
6- Robotics:- AI applied in robotics, in order to see, hear and react to other
sensory stimuli.
7- Machine learning:- Machine learning is a method of data analysis that
automates analytical model building. It is a branch of artificial
intelligence based on the idea that machines should be able to learn and
adapt through experience. It was born from pattern recognition and the
theory that computers can learn without being programmed to perform
specific tasks; researchers interested in artificial intelligence wanted to
see if computers could learn from data. The iterative aspect of machine
learning is important because as models are exposed to new data, they
are able to independently adapt. They learn from previous computations
7
Prof. Dr. Ali Hussein Hasan
to produce reliable, repeatable decisions and results. It’s a science that’s
not new – but one that has gained fresh momentum.
While many machine learning algorithms have been around for a long
time, the ability to automatically apply complex mathematical
calculations to big data – over and over, faster and faster – is a recent
development. Here are a few widely publicized examples of machine
learning applications you may be familiar with:
a- The heavily hyped, self-driving Google car (WAYMO). The essence
of machine learning.
b- Online recommendation offers such as those from Amazon and
Netflix? Machine learning applications for everyday life.
c- Knowing what customers are saying about you on Twitter? Machine
learning combined with linguistic rule creation.
d- Fraud detection. One of the more obvious, important uses in our
world today.
8- Pattern recognition:- is the process of classifying input data into objects
or classes based on key features. There are two classification methods in
pattern recognition: supervised and unsupervised classification.
8
Prof. Dr. Ali Hussein Hasan
Virtual reality also refers to remote communication environments which
provide a virtual presence of users with through telepresence and
telexistence or the use of a virtual artifact (VA). The immersive
environment can be similar to the real world in order to create a lifelike
experience grounded in reality. Augmented reality systems may also be
considered a form of VR that layers virtual information over a live
camera feed into a headset, or through a smartphone or tablet device.
10- Intelligent control:- Intelligent control is a class of control techniques
that use various artificial intelligence computing approaches like neural
networks, Bayesian probability, fuzzy logic, machine learning,
evolutionary computation and genetic algorithms.
9
Prof. Dr. Ali Hussein Hasan
AI Agents and their Environments
Particular artificial intelligence programs, can be thought of as intelligent
agents that interact with particular environments. In general, intelligent agents
of all types (including rats, people, as well as AI programs) interact with their
environments in two main ways: perception and action.
For purposes of AI, perception is the process of transforming something from
the environment into internal representations (memories, beliefs, etc.). Action
done when the agent, by doing something, changes the environment.
An AI system is composed of an agent and its environment. The agents act in
their environment. The environment may contain other agents.
An agent is anything that can perceive its environment through sensors and acts
upon that environment through effectors.
• A human agent has sensory organs such as eyes, ears, nose, tongue and
skin parallel to the sensors, and other organs such as hands, legs, mouth,
for effectors.
• A robotic agent replaces cameras and infrared range finders for the
sensors, and various motors and actuators for effectors.
• A software agent has encoded bit strings as its programs and actions.
For example, if a robot uses its camera to determine that there is a wall in front
of it, then it is using perception. In this example, the camera is a "sensor." If
that robot uses its body to push the wall over, then it is doing action. The body,
in this case, is an "actuator". If the robot uses wheels to back up, this is also an
example of doing action. The environment has changed because the robot is
10
Prof. Dr. Ali Hussein Hasan
now in a different place. Typical robot actuators include arms, wheels, lights,
or speakers.
What about an AI that has no body? Let's take, for example, a music
recommendation system. In this case, the environment for the agent might be
the web page that the user clicks and types into, or perhaps a database of user
preferences. The sensors, in this case, are abstract functions in the agent's
programming, rather than pieces of hardware, as they are on a robot. The
function that detects when a user clicks, or the function that fetches information
from the database might be considered sensors for this agent. What would the
actuators be? When the agent displays recommended music to the user, they
are using actuators to display things on the screen--or to serve the web page.
Another example is the database that the music recommendation system uses-
-should it be considered a part of the environment that the agent interacts with,
or a part of the agent's memory? As you can see from this example, what is
considered an actuator and what is considered part of the environment depends
on what you consider to be the boundaries of the agent. There is not always a
right or wrong boundary. It depends on the context of the discussion.
Agent Terminology
Behavior of Agent − It is the action that agent performs after any given
sequence of percepts.
Percept Sequence − It is the history of all that an agent has perceived till date.
11
Prof. Dr. Ali Hussein Hasan
Rationality
Rationality is nothing but status of being reasonable, sensible, and having good
sense of judgment.
An ideal rational agent is the one, which is capable of doing expected actions
to maximize its performance measure, on the basis of − Its percept sequence.
Its built–in knowledge base.
A rational agent always performs right action, where the right action means the
action that causes the agent to be most successful in the given percept sequence.
12
Prof. Dr. Ali Hussein Hasan
Sensors: Keyboard (entry of symptoms, findings, patient's answers)
13
Prof. Dr. Ali Hussein Hasan
Agent’s structure can be viewed as −
14
Prof. Dr. Ali Hussein Hasan
They use a model of the world to choose their actions. They maintain an
internal state.
Model − The knowledge about “how the things happen in the world”.
15
Prof. Dr. Ali Hussein Hasan
They choose their actions in order to achieve goals. Goal-based approach is
more flexible than reflex agent since the knowledge supporting a decision is
explicitly modeled, thereby allowing for modifications.
16
Prof. Dr. Ali Hussein Hasan
They choose actions based on a preference (utility) for each state. Goals are
inadequate when –
There are conflicting goals, out of which only few can be achieved.
Goals have some uncertainty of being achieved and you need to weigh
likelihood of success against the importance of a goal.
Nature of Environments
17
Prof. Dr. Ali Hussein Hasan
very challenging environment as it is highly difficult for a software agent to
perform as well as a human.
Turing Test
Two persons and a machine to be evaluated participate in the test. Out of the
two persons, one plays the role of the tester. Each of them sits in different
rooms. The tester is unaware of who is machine and who is a human. He
interrogates the questions by typing and sending them to both intelligences, to
which he receives typed responses.
This test aims at fooling the tester. If the tester fails to determine machine’s
response from the human response, then the machine is said to be intelligent.
Properties of Environment
18
Prof. Dr. Ali Hussein Hasan
4- Single agent / Multiple agents − The environment may contain other
agents which may be of the same or different kind as that of the agent.
5- Accessible / Inaccessible − If the agent’s sensory apparatus can have
access to the complete state of the environment, then the environment is
accessible to that agent.
6- Deterministic / Non-deterministic − If the next state of the environment
is completely determined by the current state and the actions of the
agent, then the environment is deterministic; otherwise it is non-
deterministic.
7- Episodic / Non-episodic − In an episodic environment, each agent’s
performance is the result of a series of independent tasks performed.
There is no link between the agent’s performance and other different
scenarios. In other words, the agent decides which action is best to take,
it will only consider the task at hand and doesn’t have to consider the
effect it may have on future tasks.
Examples:
Episodic environment: mail sorting system
Non-episodic environment: chess game.
there are three different colours of paths leading down the mountain. These
different colours represent three different difficulty levels, blue is for
beginners, red for intermediates and black for experts.
19
Prof. Dr. Ali Hussein Hasan
The idea is that there are multiple agents that represent skiers. The task of each
agent is to make their way from the top of the mountain, down to the lodge in
the fastest time possible. The agents will have different skill levels and a
confidence level that will affect their decision making abilities on which route
to take.
Agents
The agents in this system are represented by skiers.
Environment
The environment is the slope that contains different pistes for different
difficulty settings.
Tasks
The task of all the agents is to make to the lodge as soon as possible.
Effectoric capabilities
The agents will be able to perform particular tasks in order to navigate down
the slope. These include:
• Speeding up.
• Slowing down.
• Stopping.
• Turning.
• Bailing out.
Reasoning
The agents would mainly use practical reasoning. The factors affecting which
route they decide to take will be a combination of the agent's skill level and
their confidence. As the agents progress down the slope, naturally their skill
will improve as will their confidence. This means that they can take different
routes down the slope. But the environment can affect an agents confidence.
For example, if the agent falls then its skill will not decrease but its confidence
will. Similarly if the weather takes a turn for the worse.
20
Prof. Dr. Ali Hussein Hasan
Propositional and Predicate Logic
-Propositional Logic
In general, in logic, we are not concerned with the truth of statements, but rather
with their validity. That is to say, although the following argument is clearly
logical, it is not something that we would consider to be true:
Mary is a lemon
Notice:- The propositional logic is not powerful enough to represent all types
of assertions that are used in computer science and mathematics, or to express
certain types of relationship between propositions such as equivalence.
For example, the assertion "x is greater than 1", where x is a variable, is not a
proposition because you can not tell whether it is true or false unless you know
the value of x. Thus the propositional logic can not deal with such sentences.
However, such assertions appear quite often in mathematics and we want to do
inferencing on those assertions.
Also the pattern involved in the following logical equivalences can not be
captured by the propositional logic:
21
Prof. Dr. Ali Hussein Hasan
"Not all birds fly" is equivalent to "Some birds don't fly". "Not all integers are
even" is equivalent to "Some integers are not even". "Not all cars are
expensive" is equivalent to "Some cars are not expensive",..
The first step in describing a language is to introduce the pieces that make it
up, its set of symbols:-
Sentences in the propositional calculus are formed from these atomic symbols
according to the following rules:-
22
Prof. Dr. Ali Hussein Hasan
* an expression is a sentence or WFF if and only if it can be formed of legal
symbols through some sequence of these rules.
Definitions 2:-
Symbol Meaning
˄ And
˅ Or
~ Negation
p→q if p then q, if p means “you live in France” and q means “You
speak
French,” then p→q corresponds to the statement “if you live in
France, then
you speak French.”
𝑝↔𝑞 if p then q and if q then p, If I have 1000 Dinars then only I will
go to buy sandwich. The converse condition that I will go to buy
sandwich if and only if I have 1000 Dinars. The first statement
covers necessity and the second one covers sufficiency.
Implication
Bidirectional implication
≡ Identity
⊢ Derivability, 𝑥 ⊢ 𝑦 means that y has been derived from x by a
procedure.
⊨ Logical entailment, 𝑥 ⊨ 𝑦 mean that y logically follows from x
23
Prof. Dr. Ali Hussein Hasan
5- Let r be a propositional formula constructed by connecting atomic
proposition p,q,s, etc. An interpretation for r is a function that maps v(p),
v(q) and v(s) into true or false values that together keep r true.
Ex:
𝑝∧𝑞
The possible interpretation is
v(p) = true and v(q)=true
ex:
∼𝑝∨𝑞
Interpretation :- {v(p)=true, v(q)=true}, {v(p)=false, v(q)= false},
{v(p)=false, v(q)=true}.
6- A propositional formula is called satisfiable if its value is true for some
interpretation.
** generally use ⊨ 𝑝 to denote that p is satisfiable.
7- A propositional formula is called valid or tautology, when it is true for
all possible interpretations.
p3=p1→p2.
p1 & p2 represent premise and conclusion respectively for the if-then clause.
Definitions:
1− ∼∼ 𝑝 ≡ 𝑝. 2- 𝑝 ∧ 𝑞 ≡ 𝑞 ∧ 𝑝. 3-𝑝 ∨ 𝑞 ≡ 𝑞 ∨ 𝑝. 4-(𝑝 ∧ 𝑞) ∧ 𝑟 ≡ 𝑝 ∧
(𝑞 ∧ 𝑟).
12- 𝑝 → 𝑞 ≡ ~𝑝⋁𝑞
24
Prof. Dr. Ali Hussein Hasan
Translating between English and Logic Notation
• To use logic, it is first necessary to convert facts and rules about the real
world into logical expressions using the logical operators.
• Let us examine some examples. First, we will consider the simple operators,
∧, ∨, and ~.
• Sentences that use the word and in English to express more than one concept,
all of which is true at once, can be easily translated into logic using the AND
operator, ∧.
-- For example: “It is raining and it is Tuesday.” might be expressed as: R ∧T,
Where R means “it is raining” and T means “it is Tuesday.”
Hence, for example, we might translate “it is raining in New York” as: N(R)
We might equally well choose to write it as: R(N).
• Let us return now to the logical operators. The expression “it is raining in
New York, and I’m either getting sick or just very tired” can be expressed as
follows: R(N) ∧(S(I) ∨T(I)).
25
Prof. Dr. Ali Hussein Hasan
• Here we have used both the ∧ operator, and the ∨ operator to express a
collection of statements. The statement can be broken down into two sections,
which is indicated by the use of parentheses.
• The section in the parentheses is S(I) ∨ T(I), which means “I’m either getting
sick OR I’m very tired”. This expression is “AND’ed” with the part outside the
parentheses, which is R(N).
• It is important to get the ~ in the right place. For example: “I’m either not
well or just very tired” would be translated as ~W(I) ∨ T(I).
• The position of the ~ here indicates that it is bound to W(I) and does not play
any role in affecting T(I).
• Now let us see how the → operator is used. Often when dealing with logic
we are discussing rules, which express concepts such as “if it is raining then I
will get wet.”
• Implication can be used to express much more complex concepts than this.
26
Prof. Dr. Ali Hussein Hasan
A(x) means that x ends up asleep at his desk.
• The important thing to realize is that the choice of variables and predicates is
important, but that you can choose any variables and predicates that map well
to your problem and that help you to solve the problem.
• For example, in the example we have just looked at, we could perfectly well
have used instead S→A ∨ L where S means “he eats a sandwich which has
pickles in it,” A means “he ends up a sleep at his desk,” and L means “he sings
loud songs.”
• Note that we have thus far tended to use single letters to represent logical
variables. It is also perfectly acceptable to use longer variable names, and thus
to write expressions such as the following:
Examples:
27
Prof. Dr. Ali Hussein Hasan
A: It is hot
B: It is sunny
AΛB
AVB
~AΛ~B
Ex:
If it is Sunday we go fishing.
It is Sunday
Therefore we go fishing
P→Q
If it is Sunday we go fishing
We do not go fishing
28
Prof. Dr. Ali Hussein Hasan
P→Q
~Q
~P
P→Q
Q→R
P→R
Hw:-
Ex:
If you work hard then you get lucky. Either you get lucky or you work hard, or
both. If you get lucky then, either you are not a rogue or you work hard (but
not both). You are a rogue.
If Mary loves Pat then Mary loves Quincy. If it is Monday then Mary loves Pat
or Quincy (or both). Mary does not love both Pat and Quincy.
If the car has no fuel or it has no spark, then it will not start. The car has a spark.
The car will not start.
29
Prof. Dr. Ali Hussein Hasan
Control structures in reasoning
We will deal with three methods for control the reasoning in Prolog:
Algorithm:
Backward Chaining:
30
Prof. Dr. Ali Hussein Hasan
Ex: prove Z is true from the following knowledge base:
R1: 𝑍: −𝐹 ∧ 𝐵.
R2: F: −𝐶 ∧ 𝐷. RULES
R3: D:-A.
A.
B.
C.
E. FACTS
G.
H.
Solution:
Step1:- the system checks the facts for Z. And when that fails, search the rules
that conclude Z, i.e. have Z on the left side. It find Z in the R1 and decides that
it must establish F & B in order to conclude Z.
Step2:- the system try to establish F, first checking the data base and then
finding a rule R2 that conclude F. From this rule the system must establish C
& D to conclude F.
Step3:- the system try to establish C, first checking the data base and then
finding it.
Step4:- the system try to establish D, first checking the data base and then
finding a rule R3 that conclude D. From this rule the system must establish A
to conclude D.
Step5:- the system tries to establish A, first checking the data base and then
finding it.
31
Prof. Dr. Ali Hussein Hasan
Step7:- executes R2 to establish F.
Goal Z
F B
TRUE
E
C D
TRUE
A
TRUE
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
R5: b:-d.
R6: b:- e.
R7: c(2):- not(e).
R8: d:-f2,f3.
R9: e:-f2,f4.
f2.
f3.
not(f1).
not(f4).
32
Prof. Dr. Ali Hussein Hasan
ii- Forward chaining – data directed computation or Modus Ponens
Reasoning
Modus Ponens Reasoning = the way that affirms by affirming.
الطريقة التي تؤكد بتأكيدها
There is no query, no goal, we just use the facts we know to infer some
new facts.
- In some cases, not very efficient as we might generate many thousands
of conclusions before the one we want is generated
- Useful where we want to know everything which can be derived from
the known facts
- Useful where there are many valid solutions, all potentially valid.
- Can be used where all input data (facts) are assumed to be available
from the beginning of each problem.
Algorithm:
1- Ignore all the false facts or rules.
2- Mark all facts as unused and get a fresh copy of the rule.
3- Until no more unused facts remains, pick the first-listed one, call it F
‘pursue’.
Take the 1st unused fact, let it is F:-
a- Let R is the rule that contains the fact F in the right side. Do the
following steps with all rules that contain F in its right side:
i- Create new fact/facts identical to the rule R except F is
deleted.
ii- If the right side of the R became empty, then put R in the
facts and mark it as unused. Delete all remaining rules that have
the same left side name.
iii- If the right side of R is not empty after deleting F, then a
new rule will be created, and delete R.
b- Mark F as used:- after all steps in (a) was completed, repeat the work
with new unused fact.
4- After finishing all unused facts and mark them as used, search the rules
that contain the ‘not’. If the negation for not given fact in the facts list,
then add the ‘not’ of the fact to the facts list and consider it as true and
mark it as unused then repeat the steps in 3.
33
Prof. Dr. Ali Hussein Hasan
Ex:- R1: 𝑍: −𝐹 ∧ 𝐵 .
R2 : 𝐹: −𝐶 ∧ 𝐷.
R3 : D:-A.
A.
B.
C.
E.
G.
H.
Solution:
34
Prof. Dr. Ali Hussein Hasan
8- Take the fact C. it is found in R2, delete it. New rule is created R5
and delete R2. Mark C as used fact.
R4 : Z:-F.
R5: F:- D.
A*.
B*.
C*.
E.
G.
H.
D.
9- Take E, then G, then H, we notice they are not found in the right side
of any rule. Mark them as used facts
10- Take D, it is found in R5. Delete D from R5. A new fact created
is F, add it to the facts, and delete R5. Mark D as used.
R4 : Z:-F.
A*.
B*.
C*.
E*.
G*.
H*.
D*.
F.
11- Take F, it is found in R4. Delete it from R4. A new fact created
Z add it to the facts, delete R4, mark F as used.
12- There is no rule to infer so the work is stop.
Ex:-
prove 𝑔1 ∨ 𝑔2(𝑍)
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
R5: b:-d.
R6: b:- e.
35
Prof. Dr. Ali Hussein Hasan
R7: c(2):- not(e).
R8: d:-f2,f3.
R9: e:-f2,f4.
f2.
f3.
Solution:-
1- Take f2, it is found in R8 & R9. Delete it from the rules. New rules
is created.
R10: d:-f3.
R11: e:- f4.
f2*.
f3.
2- Take f3, it is found in R10, delete it from R10, then new fact is created.
Delete R10.
f2*, f3*, d.
3- Take d, it is found in R5 and R4 but in negation, so suspended to the end.
Delete d from R5 to produce the fact b.
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
R6: b:- e.
R7: c(2):- not(e).
R11: e:- f4.
f2*, f3*, d*, b.
4- Take b, delete it from R2, to get R12, delete R2. Also delete R6 not
needed.
R1: g1:-f1.
R3: g2(X):-c(X).
R4: a:-not(d).
R7: c(2):- not(e).
R11: e:- f4.
f2*, f3*, d*, b*.
5- There is no facts to take, but we have two suspended ‘not’.
6- Take R4, since d is true so R4 is false.
7- Take R7, since e is not found in facts so add not(e ) is added to the facts.
So delete not(e ) from R7 to yield fact c(2).
36
Prof. Dr. Ali Hussein Hasan
8- Take the fact c(2), it is found in R3, and it is true only if X=2, so R3
become true only in g2(2). But can not delete it.
iii- Hybrid control structure ( Rule – cycle hybrid)
The rules are tried in order as with backward chaining, but each rule is used
in forward chaining to assert new facts.
1- Ignoring any rules with ‘not’.
2- If the conditions on the right side of some rule all match the facts, then
the rule succeeds its left side and add to the database as new fact. And
eliminate from further consideration all rules whose left sides are
equivalent to the new fact. If the rule left side has variables, do this for
every possible way of binding these variables.
3- When no new rules succeed on a cycle through all of them, rules with
‘not’ now considered; cycling resumes at the top of rules, with the ‘not’
expressions now succeeding if their arguments are not now facts. Again
we continue until no new rules succeed on a cycle.
Ex:-
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
R5: b:-d.
R6: b:- e.
R7: c(2):- not(e).
R8: d:-f2,f3.
R9: e:-f2,f4.
f2.
f3.
Sol.:- cycle 1:
1- R1, R2, R3, R5, & R6 are tried respectively. R4 and R7 skipped because
of ‘not’. No one succeed because nothing on any right side matches a
fact that is stated to be true.
2- R8 is tried and it succeeds. Fact d is asserted and eliminate R8.
3- R9 fails.
37
Prof. Dr. Ali Hussein Hasan
Cycle2:-
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
R7: c(2):- not(e).
R9: e:-f2,f4.
f2.
f3.
d.
b.
Cycle5:
1- R2 & R2 fail as before, R3 succeeds with X=2 only and g2(2) must be a
fact. We can not eliminate R3 because g2(2) is more specific than the
left side of R3.
Now the remaining rules and facts are:-
R1: g1:-f1.
R2: g1:-a,b.
R3: g2(X):-c(X).
R4: a:-not(d).
38
Prof. Dr. Ali Hussein Hasan
R9: e:-f2,f4.
f2.
f3.
d.
b.
not(e).
c(2).
g2(2).
39
Prof. Dr. Ali Hussein Hasan
Theorem proving by propositional logic
i- Semantic method
Ex: let P1= the sky is cloudy. P2= it will rain. And 𝑃3 ≡ 𝑃1 → 𝑃2 to be three
propositions.
Attempt to check whether forward and backward chaining holds good for the
following theorem: 𝑃1, 𝑃3 ⟹ 𝑃2.
Sol.:Truth table:-
P1 P2 𝑃3 ≡ 𝑃1 → 𝑃2 ≡ ~𝑃1 ∨ 𝑃2
0 0 1
0 1 1
1 0 0
1 1 1
Forward chaining:- when all premises are true, check whether the conclusion
is true. Under this circumstance we say that forward hold good.
Now, when P1 & P3 are true, check if P2 is true. Note that in the last row,
P1=1, P3=1 yield P2=1. So forward chaining holds good.
Backward chaining:- when all the consequences are false, check whether at
least one of the premises is false.
In the 3rd row P2=0 & P3=0, so backward chaining hold good.
So as forward and backward chaining both satisfied together, then the theorem
𝑃1, 𝑃3 ⟹ 𝑃2 holds good.
40
Prof. Dr. Ali Hussein Hasan
P1=0 then P2=0 (1st row) backward chaining.
Fails.
Standard theorems:-
1- ~𝑝 ∧ (𝑝 ∨ 𝑞) ⇒ 𝑞. 2- ~𝑞 ∧ (𝑝 ⟶ 𝑞) ⇒ ~𝑝.
3- 𝑝 ⟶ 𝑞 ⇒ ~𝑝 ∨ 𝑞. 4- ~(𝑝 ⟶ 𝑞) ⇒ 𝑝 ∧ ~𝑞
5- 𝑝 ⟷ 𝑞 ⇒ (𝑝 ⟶ 𝑞) ∧ (𝑞 ⟶ 𝑝).
7-(𝑝 ∨ 𝑞) ∧ (𝑝 ⟶ 𝑟) ∧ (𝑞 ⟶ 𝑟) ⇒ 𝑟. Prove?
8- 𝑝 ⟶ (𝑞 ⟶ 𝑟) ⇒ (𝑝 ∧ 𝑞) ⟶ 𝑟. Prove?
9- ( 𝑝 ⟶ 𝑞) ∧ (𝑞 ⟶ 𝑟) ⇒ 𝑝 ⟶ 𝑟. Prove?
10- 𝑝 ∧ (𝑝 ⟶ 𝑞) ∧ (𝑞 ⟶ 𝑟) ⇒ 𝑟. Prove?
Now the syntactic approach for theorem proving can be done in two ways:
1- Method of substitution
Here, left hand side or right hand side of the statement to be proved is chosen
and the standard formulas (above) are applied selectively to prove the other
side of the statement.
Ex: prove (𝑝 ⟶ 𝑞) ⇔ ~𝑞 ⟶ ~𝑝
LHS 𝑝 ⟶ 𝑞
⟹ ~𝑝 ∨ 𝑞
⟹ 𝑞 ∨ ~𝑝
⟹ ~(~𝑞) ∨ ~𝑝
~𝑞 ⟶ ~𝑝
41
Prof. Dr. Ali Hussein Hasan
Ex: prove 𝑝 ⟶ (𝑞 ⟶ 𝑟) ⟺ (𝑝 ∧ 𝑞) ⟶ 𝑟
Lhs: 𝑝 ⟶ (𝑞 ⟶ 𝑟)
⟹ 𝑝 ⟶ (~𝑞 ∨ 𝑟)
⟹ ~𝑝 ∨ (~𝑞 ∨ 𝑟)
⟹ (~𝑝 ∨ ~𝑞) ∨ 𝑟
⟹ ~(𝑝 ∧ 𝑞) ∨ 𝑟
⟹ (𝑝 ∧ 𝑞) ⟶ 𝑟
i.e.
𝑝1 ∧ 𝑝2 ∧ 𝑝3 ∨ … .∧ 𝑝𝑛 ⟹ 𝑞1 ∨ 𝑞2 ∨ 𝑞3 ∨ … . 𝑞𝑚
Algorithm:-
42
Prof. Dr. Ali Hussein Hasan
c- Theorem splitting:- if the LHS contains OR, then split the theorem
into two sub-theorems by replacing OR. If the RHS contains
AND, then split the theorem into two sub-theorems.
𝑝 ∨ 𝑞 ⟹ 𝑠, 𝑡
⊨ 𝑝 ⟹ 𝑠, 𝑡 & 𝑞 ⟹ 𝑠, 𝑡
𝑝, 𝑞 ⟹ 𝑠 ∧ 𝑡
⊨ 𝑝, 𝑞 ⟹ 𝑠 & 𝑝, 𝑞 ⟹ 𝑡 .
Sol:-
𝑝, 𝑝 ⟶ 𝑞, 𝑞 ⟶ 𝑟 ⟹ 𝑟
By S1: 𝑝, ~𝑝 ∨ 𝑞, ~𝑞 ∨ 𝑟 ⟹ 𝑟
By S2c: 𝑝, ~𝑝 ∨ 𝑞, ~𝑞 ⟹ 𝑟 𝑝, ~𝑝 ∨ 𝑞, 𝒓 ⟹ 𝒓
Terminated by S3-a
By S2a: 𝒑, ~𝑞 ⟹ 𝒑, 𝑟 By S2a: 𝑝, 𝒒 ⟹ 𝒒, 𝑟
Since all the terminals of the three have been stopped by using S3-a, then the
theorem holds good.
43
Prof. Dr. Ali Hussein Hasan
Resolution in propositional logic
Resolution theorem:-
The idea of Propositional Resolution is simple. Suppose we have the clause {p,
q}. In other words, we know that p is true or q is true. Suppose we also have
the clause {~q, r}. In other words, we know that q is false or r is true. One
clause contains q, and the other contains ~q. If q is false, then by the first clause
p must be true. If q is true, then, by the second clause, r must be true. Since q
must be either true or false, then it must be the case that either p is true or r is
true. So we should be able to derive the clause {p, r}.
Resolution algorithm:-
⋮
⋮
44
Prof. Dr. Ali Hussein Hasan
Until a null clause is obtained or no further progress can be
made.
Sol:-
𝑝∨𝑞 ~𝑞 ∨ 𝑟
p∨ 𝑟 ~𝑝 ∨ 𝑠
𝑟∨𝑠 ~𝑠
𝑟 ~𝑟
∅
So the goal is proved and it will rain.
45
Prof. Dr. Ali Hussein Hasan
Strengths and weaknesses of propositional logic
It is cold COLD
Search a candle in all locality shops has a clear meaning to search all shops in
the locality for candle. But propositional logic will require separate statement
for each shop.
46
Prof. Dr. Ali Hussein Hasan
Predicate logic – First order logic FOL
Predicate logic (also called first order predicate logic) has a similar formalism
like propositional logic. However, the capability of reasoning and knowledge
representation using predicate logic is higher than propositional logic. The
language of first-order logic is built around objects and relations.
The primary difference between propositional and first-order logic is that, the
propositional logic assumes that there are facts that either hold or do not hold
in the world. Each fact can be in one of two states: true or false, and each model
assigns true or false to each proposition symbol. First-order logic assumes that
the world consists of objects with certain relations among them that do or do
not hold. So that When we look at the syntax of natural language, the most
obvious elements are nouns and noun phrases that refer to objects (squares,
pits, wumpuses) and verbs and verb phrases that refer to relations among
objects (is breezy, is adjacent to, shoots). Some of these relations are
functions—relations in which there is only one “value” for a given “input.” It
is easy to start listing examples of objects, relations, and functions:
• Relations: these can be unary relations or properties such as red, round, bogus,
prime, multistoried . . ., or more general n-ary relations such as brother of,
bigger than, inside, part of, has color, occurred after, owns, comes between, . .
.
• Functions: father of, best friend, third inning of, one more than, beginning of
..
Ex:
Relation: equals;
Function: plus.
(“One plus two” is a name for the object that is obtained by applying the
function “plus” to the objects “one” and “two.” “Three” is another name for
this object.)
47
Prof. Dr. Ali Hussein Hasan
“Squares neighboring the wumpus are smelly.”
Property: smelly;
Relation: neighboring.
Relation: ruled;
FOL includes two more quantifiers: ∀ essential quantifier ( for all ). and ∃
existence quantifier ( there exist ).
To illustrate the use of the quantifiers, let us consider the following pieces of
knowledge.
Alphabets of FOL
1. Constants: a, b, c
2. Variables: X, Y, Z
3. Functions: f, g, h
4. Operators: ∧,∨, ~ 𝑎𝑛𝑑 ⟶
5. Quantifiers: ∀ 𝑎𝑛𝑑 ∃
6. Predicate: P, Q, R
48
Prof. Dr. Ali Hussein Hasan
e.g., a, x, t(x), t(g(x)) are all terms.
1. Biscuit (coconut-crunchy)
2. Child (mary) ∧ Takes (mary, coconut-crunchy)
3. ∀X ((Child (X ) ∧ ∃Y (Biscuit (Y) ∧ Takes (X, Y) )) →Loves
(john, X)
4. Loves (john, mary)
49
Prof. Dr. Ali Hussein Hasan
Writing a Sentence into Clause Forms
Step II: Reduction of the scope of negation: Replace ~ sign by choosing any
of the following:
a) ~(P ∨ Q) = ~P ∧ ~Q
b) ~(P ∧ Q) = ~P ∨~Q
c) ~( ~P ) = P
d) ~( ∃X P) = ∀X ~ P
e) ~(∀X P) = ∃ X ~P
Step IV: Moving of quantifiers in the front of the expression: Bring all
quantifiers at the front of the expression.
⇒∀X ∀Y ~Child (X) ∨~Takes (X,Y) ∨~Biscuit (Y) ∨ (Loves (john, X))
50
Prof. Dr. Ali Hussein Hasan
Step VI: Putting the resulting expression in conjunctive normal form
(CNF):
Step VII: Writing one clause per line: If the original expression is of the
following CNF, then rewrite each clause/ line, as illustrated below.
original expression:
After writing one clause per line, the resulting expressions become as follows.
With reference to the above, we get the following line as the final expression.
Child (X), Takes (X, Y), Biscuit (Y) → Loves (john, X).
Ex:
51
Prof. Dr. Ali Hussein Hasan
Ex:- Prove Loves (john, mary)
Sol:-
Let
A1 = Biscuit (coconut-crunchy)
Child (mary)
and
52
Prof. Dr. Ali Hussein Hasan
Ex:-
Sol:-
Wff:-
1- man(marcus).
2- pompeian(mrcus).
53
Prof. Dr. Ali Hussein Hasan
3- ∀X pompeian(X) → roman(X).
4- ruler(caesar).
5- ∀X romain(X) →loyalto(X,caesar) ∨ hate(X,caesar).
6- ∀X ∃Y loyalto(X,Y).
7- ∀X ∃Y prson(X) ∧ ruler (Y) ∧ tryassasinate(X,Y) →~loyalto(X,Y).
8- tryassasinate(marcus,caesar).
54
Prof. Dr. Ali Hussein Hasan
Problem solving by intelligent search
The search problem is associated with two important issues; first “what to
search” and secondly “where to search”. The first one is generally referred to
as the “the key”, while the second one is termed “search space”.
Problem Representation
In a monastery in the deepest Tibet there are three crystal columns and 64
golden rings. The rings are different sizes and rest over the columns. At the
beginning of time all the rings rested on the leftmost column, and since than
the monks have toiled ceaselessly moving the rings one by one between the
columns. In moving the rings a larger ring must not be placed on a smaller ring.
Furthermore, only one ring at a time can be moved from one column to the
55
Prof. Dr. Ali Hussein Hasan
next. A simplified version of this problem which will consider involves only 2
or 3 rings instead of 64.
The legal moves in this state space involve moving one ring from one pole to
another, moving one ring at a time, and ensuring that a larger ring is not placed
on a smaller ring.
Ex:- 8-Puzzles
The 8-Puzzle involves moving the tiles on the board above into a particular
configuration. The black square on the board represents a space. The player
can move a tile into the space, freeing that position for another tile to be moved
into and so on.
1 4 3
7 6
5 8 2
For example, given the initial state above we may want the tiles to be moved
so that the following goal state may be attained.
1 8 3
2 4
7 6 5
56
Prof. Dr. Ali Hussein Hasan
Although a player moves the tiles around the board to change the configuration
of tiles. However, we will define the legal moves in terms of moving the space.
The space can be moved up, down, left and right.
57
Prof. Dr. Ali Hussein Hasan
58
Prof. Dr. Ali Hussein Hasan
Graphs versus Trees
If states in the solution space can be revisited more than once a directed graph
is used to represent the solution space. In a graph more than one move sequence
can be used to get from one state to another. Moves in a graph can be undone.
In a graph there is more than one path to a goal whereas in a tree a path to a
goal is more clearly distinguishable. A goal state may need to appear more than
once in a tree. Search algorithms for graphs have to cater for possible loops and
cycles in the graph. Trees may be more “efficient” for representing such
problems as loops and cycles do not have to be catered for. The entire tree or
graph will not be generated.
Notice that there is more than one path connecting two particular nodes in a
graph whereas this is not so in a tree.
Given that
L+(M+N)=(L+M)+N ……. A
M+N=N+M…………..C
59
Prof. Dr. Ali Hussein Hasan
2- tree representation
Search methods:-
60
Prof. Dr. Ali Hussein Hasan
Each node is not visited more than once. A depth first search of the this tree
produces: A, B, E, K, S, L ,T, F, M, C, G, N, H, O, P, U, D, I, Q, J, R.
Although in this example the tree was generated first and then a search of the
tree was conducted. However, often there is not enough space to generate the
entire tree representing state space and then search it. The algorithm presented
below conducts a depth first search and generates parts of the tree as it goes
along.
open = [Start];
closed = [];
61
Prof. Dr. Ali Hussein Hasan
State = failure;
begin
remove the leftmost state from open, call it X;
State = success
else begin
generate children of X;
put X on closed
end else
end while
return State;
end def
Example 1: Suppose that the letters A,B, etc represent states in a problem. The
following moves are legal:
A to B and C
B to D and E
C to F and G
D to I and J
I to K and L
Start state: A Goal state: E , J
Let us now conduct a depth first search of the space. Remember that tree will
not be generated beforehand but is generated as part of the search. The search
and hence generation of the tree will stop as soon as success is encountered or
the open list is empty.
62
Prof. Dr. Ali Hussein Hasan
Time Complexity
If we find the goal at the leftmost position at depth d, then the number of
nodes examined = (d +1). On the other hand, if we find the goal at the
extreme right at depth d, then the number of nodes examined include all the
nodes in the tree, which is
≅ b( bd + d) / 2 (b -1)
This is the average case time complexity of the depth first search algorithm.
Since for large depth d, the depth first search requires quite a large
runtime, an alternative way to solve the problem is by controlling the depth
of the search tree. Such an algorithm, where the user mentions the initial.
63
Prof. Dr. Ali Hussein Hasan
2- Breadth first search:-
The breadth first search algorithm visits the nodes of the tree along its
breadth, starting from the level with depth 0 to the maximum depth. It can be
easily realized with a queue. For instance, consider the tree, given below
Here, the nodes in the tree are traversed following their ascending ordered
labels.
Procedure Breadth-first-search
Begin
64
Prof. Dr. Ali Hussein Hasan
The breadth first search algorithm, presented above, rests on a simple
principle. If the current node is not the goal add the offspring of the
current in any order to the rear end of the queue and redefine the front
element of the queue as the current. The algorithm terminates, when the goal
is found.
n1
n2 n3 n4
n3 n4
n4 n5 n6
n5 n6 n7 n8
Time Complexity
For the sake of analysis, we consider a tree of equal branching factor from
each node = b and largest depth = d. Since the goal is not located within
depth (d-1), the number of false search [1], [2] is given by
Further, the first state within the fringe nodes could be the goal. On the
other hand, the goal could be the last visited node in the tree. Thus, on an
average, the number of fringe nodes visited is given by
( 1+bd ) / 2.
65
Prof. Dr. Ali Hussein Hasan
Differences Between Depth First and Breadth First
Breadth first is guaranteed to find the shortest path from the start to the goal.
DFS may get “lost” in search and hence a depth-bound may have to be imposed
on a depth first search. BFS has a bad branching factor which can lead to
combinatorial explosion. The solution path found by the DFS may be long and
not optimal. DFS more efficient for search spaces with many branches, i.e. the
branching factor is high.
The following factors need to be taken into consideration when deciding which
search to use:
66
Prof. Dr. Ali Hussein Hasan
The hill climbing algorithm is formally presented below.
Procedure Hill-Climbing
Begin
1. Identify possible starting states and measure the distance (f) of their
closeness with the goal node; Push them in a stack according to the
ascending order of their f ;
2. Repeat
Pop stack to get the stack-top element;
If the stack-top element is the goal, announce it and exit
Else push its children into the stack in the ascending order of their
f
values;
Until the stack is empty;
End.
. يتم حساب الكلفة بتجميع كلف المسار وصوال" ألى الهدف-:البحث التجميعي أو تسلق التلة
SB=1. SA=4. BF=3. BE=2. FG2=1. FI=2. EG1=3. EH=4. AD=2. AC=1.
Sol:-
4 1
A B
1 2 2 3
C D E F
4 3 2 1
3
H G1 I G2
S(0)
B(1) A(4)
67
Prof. Dr. Ali Hussein Hasan
E(3) F(4) A(4)
The hill climbing algorithm too is not free from shortcomings. One
common problem is trapping at local maxima at a foothill. When trapped at
local maxima, the measure of f at all possible next legal states yield less
promising values than the current state. A second drawback of the hill
climbing is reaching a plateau. Once a state on a plateau is reached, all legal
next states will also lie on this surface, making the search ineffective.
Procedure Best-First-Search
. كلفة كل عقدة هو كلفة الوصول اليها من العقدة السابقة لها فقط-:"البحث اللحظي أو أالقل أوال
Begin
1. Identify possible starting states and measure the distance (f) of their
closeness with the goal; Put them in a list L;
Begin
a) Identify the node n from L that has the minimum f; If there
exist more than one node with minimum f, select any one of them
(say, n) arbitrarily;
b) If n is the goal
Then return n along with the path from the starting node,
and exit;
Else remove n from L and add all the children of n to the list L,
with their labeled paths from the starting node;
End While;
End
68
Prof. Dr. Ali Hussein Hasan
Ex: repeat last example
S(0)
B(1) A(4)
69
Prof. Dr. Ali Hussein Hasan
Knowledge Representation structures
1- Objects: these are facts about real time entities in our world domain.
Example, ‘Guitar has string, trumpets are brass instrument’.
2- Events: these are actions that occur in our world. Example, ‘Lionel
Andrés "Leo" Messi is an Argentine professional footballer who plays
as a forward for Spanish club FC Barcelona and the Argentina national
team’. Or ‘Messi played as a forward in FC Barcelona club’.
3- Performance: it represents a behavior. Example, ‘playing the guitar’ ; it
involves knowledge about how to do it.
4- Meta-knowledge: it is the knowledge about knowledge. This knowledge
can read straight signs along the way to find out where it is. For example,
‘Jain’s robot who plan’s a trip’.
5- Facts: these are what truth we need to represent about the real world.
This can be regarded as the knowledge level for a domain.
70
Prof. Dr. Ali Hussein Hasan
• Fourthly, the fragments of a piece of knowledge can be accessed
concurrently by many modules, thereby providing the reasoning systems
a
scope for sharing of resources. Such sharing of resources call for
minimal
structure and consequently less hardware / software devices for
realization of the knowledge bases.
• Finally, many modules of the structural models can be
made active concurrently, thus providing a scope for massive parallelism
in the reasoning process. The time efficiency of the inference engines
thus can be improved with structured models.
Types:-
1- Production Rules PR
Knowledge is represented with rules, these rules are expressed in the standard
IF-THEN :-
x,y,… variables.
The LHS of PR is called antecedent/conditional part and the RHS is called the
consequent/conclusion part.
71
Prof. Dr. Ali Hussein Hasan
1- Rule-Number :- IF condition THEN conclusion.
2- Rule-Number:- conclusion IF condition.
3- In PROLOG format:- rule(rule-no.,rule-head,rule-body).
Examples:
1-
2-
AND
3-
4-
5-
72
Prof. Dr. Ali Hussein Hasan
You are given two jugs, a 4-gallon one and a 3-gallon one. Neither has any
measuring mark on it. How can you get exactly 2 gallons of water into the
4-gallon jug.
Solution:
The state space for this problem can be described as the set of ordered pairs
of integers (x,y);
Where,
Production Rules:
Rule State Process
1 (X,Y | X<4) (4,Y)
{Fill 4-gallon jug}
2 (X,Y |Y<3) (X,3)
{Fill 3-gallon jug}
3 (X,Y |X>0) (0,Y)
{Empty 4-gallon jug}
4 (X,Y | Y>0) (X,0)
{Empty 3-gallon jug}
5 (X,Y | X+Y>=4 ^ Y>0) (4,Y-(4-X))
{Pour water from 3-gallon jug into 4-gallon
jug until 4-gallon jug is full}
6 (X,Y | X+Y>=3 ^ X>0) (X-(3-Y),3)
{Pour water from 4-gallon jug into 3-gallon
jug until 3-gallon jug is full}
7 (X,Y | X+Y<=4 ^ Y>0) (X+Y,0)
{Pour all water from 3-gallon jug into 4-
gallon jug}
8 (X,Y | X+Y <=3^ X>0) (0,X+Y)
73
Prof. Dr. Ali Hussein Hasan
{Pour all water from 4-gallon jug into 3-
gallon jug}
9 (0,2) (2,0)
{Pour 2 gallon water from 3 gallon jug into
4 gallon jug}
Initialization:
Start State: (0,0)
Apply Rule 2:
(X,Y | Y<3) -> (X,3)
{Fill 3-gallon jug}
Now the state is (X,3)
Iteration 1:
Current State: (X,3)
Apply Rule 7:
(X,Y | X+Y<=4^Y>0) (X+Y,0)
{Pour all water from 3-gallon jug into 4-gallon
jug}
Now the state is (3,0)
Iteration 2:
Current State : (3,0)
Apply Rule 2:
(X,Y | Y<3) -> (3,3)
{Fill 3-gallon jug}
Now the state is (3,3)
Iteration 3:
Current State:(3,3)
Apply Rule 5:
(X,Y | X+Y>=4 ^Y>0) (4,Y-(4-X))
{Pour water from 3-gallon jug into 4-gallon
jug until 4-gallon jug is full}
Now the state is (4,2)
Iteration 4:
74
Prof. Dr. Ali Hussein Hasan
Current State : (4,2)
Apply Rule 3:
(X,Y | X>0) (0,Y)
{Empty 4-gallon jug}
Now state is (0,2)
Iteration 5:
Current State : (0,2)
Apply Rule 9:
(0,2) (2,0)
{Pour 2 gallon water from 3 gallon jug into 4
gallon jug}
Now the state is (2,0)
Goal Achieved.
6-
A farmer wants to transfer his three belongings a wolf, a goat, and a cabbage
by a boat from left bank of a river to its right bank. The boat can carry at
75
Prof. Dr. Ali Hussein Hasan
most two items including the farmer. If unwanted, the wolf may eat up the
goat and the goat may eat up the cabbage.
1- (w,g||f,c)
2- (g,c||f,w)
3- (f,w||g,c)
4- (f,c||w,g)
R1: (f,g,w,c||nil)→(w,c||f,g).
R2: (w,c||f,g)→(f,w,c||g).
R3: (f,w,c||g)→(c||f,w,g).
R4: (c||f,w,g)→(f,g,c||w).
R5: (f,g,c||w)→(g||f,w.c).
R6: (g||f,w,c)→(f,g||w,c).
R7: (f,g||w,c)→(ni||f,g,w,c).
R8: (f,w,c||g)→(w||f,g,c).
R9: (w||f,g,c)→(f,g,w||c).
R10: (f,g,w||c)→(g||f,w,c).
R11: (g||f,w,c)→(f,g||w,c).
R12: (f,g||w,c)→(nil||f,g,w,c).
76
Prof. Dr. Ali Hussein Hasan
77
Prof. Dr. Ali Hussein Hasan
Most relationships are deduced from the given sentences. Some standard
relationships used in semantic nets :-
isa
a kind – of
78
Prof. Dr. Ali Hussein Hasan
instance – of
member – of
has – parts
has
can
examples:-
like
X Y
2- Jim is a boy.
Instance - of
Jim boy
gave
Instance - of
Agent
john event 10$
object
Beneficiary
bagger
79
Prof. Dr. Ali Hussein Hasan
4- Tweety is a yellow bird that has wings and can fly
can
fly
A kind of
bird Tweety yellow
color
has
wings
Consequent:- like y
x
Instance – of Instance – of
child sweet
Antecedent
80
Prof. Dr. Ali Hussein Hasan
6-
i- Green – bird (parrot).
ii- Singer – bird(cuckoo).
iii- Bird(green – bird).
iv- Bird(singer – bird).
v- Aves(bird).
vi- ~singer – bird(parrot).
vii- ~green – bird(cuckoo).
Aves
Is a
Is a bird
Green-bird
Is a Is a
~Is a
parrot Is a
Singer-bird
cuckoo
~Is a
81
Prof. Dr. Ali Hussein Hasan
sing
fly Can can
bird
Has isa parrot is green
wings
has isa
Can isa
feathers is large
82
Prof. Dr. Ali Hussein Hasan
aircraft
isa
airplane
3- Conceptual graphs CG
As an alternative to the above ‘display’ form, the graphs may be written in the
following ‘linear’ text-based form:
The full stop '.' signals the end of a particular graph. Consider the following
83
Prof. Dr. Ali Hussein Hasan
example:
This example will form a part of an illustrative case study about requests for
funding new business projects in the fictitious enterprise ‘P-H Co.’. The
example graph reads as “The initiator of a funding request is an employee”.
cat, book, etc مفاهيم مدركة بالحواس اي تكون لها صورة في الخيال مثل
Ex:- suppose that you have the relations fly, color, parent.
bird
fly
father
child
parent
mother
84
Prof. Dr. Ali Hussein Hasan
Ex:
dog brown
color
john book
Recipient
*each concept box is labeled with the names of the type and the individual.
The type and individual labels are separated by a colon “ : “.
dog:emma brown
color
*in CG; every concept is a unique individual of a particular types. CG also let
us indicate a specific but unnamed individuals. A unique taken called a marker
is written as a no. preceded by a #. Markers are different from names in that
they are unique: individuals may have one name, many names or no name at
all, but they have exactly one marker.
Ex:
Dog #1 brown
color
85
Prof. Dr. Ali Hussein Hasan
2- A dog named Emma is brown.
Dog #1 brown
color
emma
name
name
hoby nancy
lil
instrument Part of
86
Prof. Dr. Ali Hussein Hasan
name emma
state hungry
Dog #1 pink
color
neg
Proposition:
pizza
87
Prof. Dr. Ali Hussein Hasan
8- Tom believes that Jaime do not like pizza.
Same as 7 except add negative to the proposition.
9- John gave Tom an ice cream can.
88
Prof. Dr. Ali Hussein Hasan
Examples :1-
dog Brown
color
2-
dog:emma brown
color
3-
Dog pink
color
neg
Using ~ yields
4-
89
Prof. Dr. Ali Hussein Hasan
father
child
parent
mother
90
Prof. Dr. Ali Hussein Hasan
4- Knowledge representation by Frames
Containment: It means that a slot in the frame contains another frame. For
example, the ‘seat arrangement’ slot of frame B contains the default frame C
and the ‘preferential arrangement’ slot of frame C contains the default frame
D. It is to be noted that default containment is denoted by ---> . A
solid arrow (→) , on the other hand, corresponds to specialization of frame,
presented below.
A B C D
Exam. Hall of
Examination-Hall Sumer Univ .
Seat arrangement Preferential seat
Seat arrang.: of Computer coll
Seat-Arrangement arrangement of
Invigi : at least 2/ at Sumer univers. Computer dept. of
room. No. of candidate Sumer university
Invigilators
Examinee : / bench : 2 Euclidean
Examinees- 2 group of Candidate in the Distance between
Question
examinees/room . same bench candidate of same
Question paper : 1
Paper : 1Qu/ should be :of group : to be
Question /
Candidate Candidate. different class/ maximized .
Answer script: year.
Answer 1 answer Preferential
Scripts: Script/ Candi. / hall Arrangement.
1script/candidate
91
Prof. Dr. Ali Hussein Hasan
The ‘--- >’ represent the containment.
Airplane
Color
Length
Engine type
Wing spam
Speed
Weight
92
Prof. Dr. Ali Hussein Hasan
Expert Systems
93