Professional Documents
Culture Documents
Artificial Intelligence
Artificial Intelligence
com
Unit-1
Overview and Search Technique
GupShupStudy.com 1
www.gupshupstudy.com
Page 2
GupShupStudy.com 2
www.gupshupstudy.com
Problem Solving:
Strong AI aims to build machines that can truly reason and
solve problems. These machines should be self aware and their
overall intellectual ability needs to be indistinguishable from
that of a human being. Excessive optimism in the 1950s and
1960s concerning strong AI has given way to an appreciation of
the extreme difficulty of the problem. Strong AI maintains that
suitably programmed machines are capable of cognitive mental
states.
Weak AI: deals with the creation of some form of computer-
based artificial intelligence that cannot truly reason and solve
problems, but can act as if it were intelligent. Weak AI holds
that suitably programmed machines can simulate human
cognition.
Applied AI: Aims to produce commercially viable "smart"
systems such as, for example, a security system that is able to
recognize the faces of people who are permitted to enter a
particular building. Applied AI has already enjoyed considerable
success.
Cognitive AI: computers are used to test theories about how the
human mind works--for example, theories about how we
recognize faces and other objects, or about how we solve
abstract problems.
Best First Search: Best First search, which is a way of
combining the advantages of both depth-first and breadth-first-
search into a single method.
One way of combining the two is to follow a single path
at a time, but switch paths whenever some competing path looks
more promising than the current one does.
Page 3
GupShupStudy.com 3
www.gupshupstudy.com
A A A
B C D B C D
Page 4
E F
GupShupStudy.com 4
www.gupshupstudy.com
Step4 Step5
A
A
D
B C D B C D
G H E F
G H E F
I J
GupShupStudy.com 5
www.gupshupstudy.com
Page 6
GupShupStudy.com 6
www.gupshupstudy.com
GupShupStudy.com 7
www.gupshupstudy.com
AO* algorithm:
1. Place the starting node s on open
2. Using the search tree constructed thus far, compute
the most promising solution tree To.
3. Select a node n that is both on open and a part of To.
Remove n from open and place it on closed.
4. If n is a terminal goal node, label n as solved. If the
solution of n results in any of n’s ancestors being solved,
label all the ancestors as solved. If the start node s is
solved, exit with success where To is the solution tree.
Remove from open all nodes with a solved ancestor.
5. If n is not a solvable node (operators cannot be
applied), label n as unsolvable. If the start node is labeled
Page 8
GupShupStudy.com 8
www.gupshupstudy.com
GupShupStudy.com 9
www.gupshupstudy.com
Page 10
GupShupStudy.com 10
www.gupshupstudy.com
Start
Page 11
GupShupStudy.com 11
www.gupshupstudy.com
A A
Page 12
GupShupStudy.com 12
www.gupshupstudy.com
B C D
B(8) C D
Page 13
GupShupStudy.com 13
www.gupshupstudy.com
Heuristic function
A heuristic function, or simply a heuristic, is a function that
ranks alternatives in various search algorithms at each branching
step based on the available information (heuristically) in order to
make a decision about which branch to follow during a search.
Shortest paths
Page 14
GupShupStudy.com 14
www.gupshupstudy.com
Page 15
GupShupStudy.com 15
www.gupshupstudy.com
Finding heuristics
Page 16
GupShupStudy.com 16
www.gupshupstudy.com
GupShupStudy.com 17
www.gupshupstudy.com
Page 18
GupShupStudy.com 18
www.gupshupstudy.com
Page 19
GupShupStudy.com 19
www.gupshupstudy.com
Page 20
GupShupStudy.com 20
www.gupshupstudy.com
Pseudo code
Function alpha beta (node, depth, α, β, Player)
if depth = 0 or node is a terminal node
return the heuristic value of node
If Player = Max Player
for each child of node
α := max(α, alpha beta(child, depth-1, α, β, not(Player) ))
if β≤α
Break (* Beta cut-off *)
return α
else
for each child of node
β := min(β, alpha beta(child, depth-1, α, β, not(Player) ))
if β≤α
break (* Alpha cut-off *)
return β
(* Initial call *)
Alpha beta (origin, depth, -infinity, +infinity, Max Player)
Heuristic improvements
GupShupStudy.com 21
www.gupshupstudy.com
GupShupStudy.com 22
www.gupshupstudy.com
GupShupStudy.com 23
www.gupshupstudy.com
Page 24
GupShupStudy.com 24
www.gupshupstudy.com
Constraint programming
Constraint programming is the use of constraints as a
programming language to encode and solve problems. This is
often done by embedding constraints into a programming
language, which is called the host language. Constraint
programming originated from a formalization of equalities of
terms in Prolog II, leading to a general framework for
embedding constraints into a logic programming language. The
most common host languages are Prolog, C++, and Java, but
other languages have been used as well.
Constraint logic programming
GupShupStudy.com 25
www.gupshupstudy.com
Page 26
GupShupStudy.com 26
www.gupshupstudy.com
Page 27
GupShupStudy.com 27
www.gupshupstudy.com
Page 28
GupShupStudy.com 28
www.gupshupstudy.com
The diagram shows the first two levels, or ply, in the game tree
for tic-tac-toe. We consider all the rotations and reflections of
positions as being equivalent, so the first player has three
choices of move: in the center, at the edge, or in the corner. The
second player has two choices for the reply if the first player
played in the center, otherwise five choices. And so on.
The number of leaf nodes in the complete game tree is the
number of possible different ways the game can be played. For
example, the game tree for tic-tac-toe has 26,830 leaf nodes.
Game trees are important in artificial intelligence because one
way to pick the best move in a game is to search the game tree
using the mini max algorithm or its variants. The game tree for
tic-tac-toe is easily searchable, but the complete game trees for
larger games like chess are much too large to search. Instead, a
chess-playing program searches a partial game tree: typically
Page 29
GupShupStudy.com 29
www.gupshupstudy.com
as many ply from the current position as it can search in the time
available. Except for the case of "pathological" game trees [1]
(which seem to be quite rare in practice), increasing the search
depth (i.e., the number of ply searched) generally improves the
chance of picking the best move.
Two-person games can also be represented as and-or trees. For
the first player to win a game there must exist a winning move
for all moves of the second player. This is represented in the
and-or tree by using disjunction to represent the first player's
alternative moves and using conjunction to represent all of the
second player's moves.
Solving Game Trees
GupShupStudy.com 30
www.gupshupstudy.com
second player can follow that will guarantee either a win or tie.
The algorithm can be described recursively as follows.
1. Color the final ply of the game tree so that all wins for
player 1 are colored one way, all wins for player 2 are
colored another way, and all ties are colored a third
way.
2. Look at the next ply up. If there exists a node colored
opposite as the current player, color this node for that
player as well. If all immediately lower nodes are
colored for the same player, color this node for the
same player as well. Otherwise, color this node a tie.
3. Repeat for each ply, moving upwards, until all nodes
are colored. The color of the root node will determine
the nature of the game.
The diagram shows a game tree for an arbitrary game, colored
using the above algorithm.
It is usually possible to solve a game (in this technical sense of
"solve") using only a subset of the game tree, since in many
games a move need not be analyzed if there is another move that
is better for the same player (for example alpha-beta pruning can
be used in many deterministic games).
Any sub tree that can be used to solve the game is known as a
decision tree, and the sizes of decision trees of various shapes
are used as measures of game complexity.
GupShupStudy.com 31
www.gupshupstudy.com
Page 32
GupShupStudy.com 32
www.gupshupstudy.com
Unit-2
Knowledge Representation
Introduction to Knowledge Representation (KR)
We argue that the notion can best be understood in terms of
five distinct roles it plays, each crucial to the task at hand:
GupShupStudy.com 33
www.gupshupstudy.com
GupShupStudy.com 34
www.gupshupstudy.com
Acquisition Efficiency
- the ability to acquire new knowledge using automatic methods
wherever possible rather than reliance on human intervention.
Page 35
GupShupStudy.com 35
www.gupshupstudy.com
For all X
– if (X is a rose)
– then there exists Y
(X has Y) and (Y is a thorn)
Higher Order Logic
More expressive than first order
Functions and predicates are also objects
Page 36
GupShupStudy.com 36
www.gupshupstudy.com
GupShupStudy.com 37
www.gupshupstudy.com
Page 38
GupShupStudy.com 38
www.gupshupstudy.com
Page 39
GupShupStudy.com 39
www.gupshupstudy.com
Page 40
GupShupStudy.com 40
www.gupshupstudy.com
Page 41
GupShupStudy.com 41
www.gupshupstudy.com
2. PTRANS transfer of
physical location of an object (e.g. go)
3. PROPEL application
of physical force of an object (e.g. throw)
4. MOVE movement
of a body part of an animal by the animal
5. GRASP grasping of
an object by an actor (e.g. hold)
6. INGEST Taking of
an object by an animal to the inside of that a animal
(e.g. Drink.eat)
7. EXPEL Expulsion of
an object from inside the body by an animal to the world
(e.g. spit)
8. MTRANS Transfer of
mental information between animals or within an animal
(e.g. tell)
9. MBUILD Construction
of a new information from an old information (e.g. decide).
10. SPEAK Action of producing sound (e.g. say).
3. LOCs: Locations
Every action takes place at some locations and serves as
source and destination.
4. Ts: Times
Page 42
GupShupStudy.com 42
www.gupshupstudy.com
GupShupStudy.com 43
www.gupshupstudy.com
GupShupStudy.com 44
www.gupshupstudy.com
/-negative
Nil-present
Delta-timeless
C-conditional
CD brought forward the
notion of language independence because all ACT’s are
language-independent primitive.
Semantic Nets: The main idea behind semantic nets is that the
meaning of a concept comes from the ways in which it is
connected to other concepts. In a semantic net, information is
represented as a set of nodes connected to each other by a set of
labeled arcs, which represent relationship among the nodes. A
fragment of a typical semantic net is shown in fig.
Mammal
Isa
Person Has-port Nose
Instance
Uniform-
Color team
Blue Pee-wee-Reese Brooklyn- Dodgers
Page 45
GupShupStudy.com 45
www.gupshupstudy.com
GupShupStudy.com 46
www.gupshupstudy.com
GupShupStudy.com 47
www.gupshupstudy.com
Or, in logic:
X: dog(x) y: Mail-carrier(y) bite(x, y)
To represent this fact, it is necessary to encode the scope of the
universally quantified variable x.
Mail-carrier
Dogs Bite
Assailant victim
Fig: using partitioned semantic nets
Frame: A frame is a collection of attributes (usually called
slots) and associated values (and possibly constraints on values)
that describes some entity in the world. Sometimes a frame
describes an entity in some absolute sense; sometimes it
represents the entity from a particular point of view. A single
frame taken alone is rarely useful. Instead, we build frame
systems out of collection of frames that are connected to each
other.
Set theory provides a good basis for understanding frame
systems. Although not all frame systems are defined this way,
we do so here. In this view, each frame represents either a class
Page 48
GupShupStudy.com 48
www.gupshupstudy.com
GupShupStudy.com 49
www.gupshupstudy.com
Fielder
Isa: ML-baseball-player
Cardinality: 376
*batting-average: .262
Pee-Wee-Reese
Instance: fielder
Height: 5-10
Bats: right
Batting-average: .309
Team: Brooklyn-Dodgers
Uniform-color: Blue
ML-Baseball-Team
Isa: Team
Cardinality: 26
*team-size: 24
*manager:
Brooklyn-dodgers
Instance: ML-Baseball-Team
Team-size: 24
Manager: Leo-Durocher
Page 50
GupShupStudy.com 50
www.gupshupstudy.com
Players: (Pee-Wee-Reese)
fig. A simplified frame system
Page 51
GupShupStudy.com 51
www.gupshupstudy.com
Page 52
GupShupStudy.com 52
www.gupshupstudy.com
Unit-3
Handling Uncertainty and learning
Fuzzy Logic: In the techniques we have not modified the
mathematical underpinnings provided by set theory and logic.
We have instead augmented those ideas with additional
constructs provided by probability theory. We take a different
approach and briefly consider what happens if we make
fundamental changes to our idea of set membership and
corresponding changes to our definitions of logical operations.
The motivation for fuzzy sets is provided by the need
to represent such propositions as:
John is very tall.
Mary is slightly ill.
Sue and Linda are close friends.
Page 53
GupShupStudy.com 53
www.gupshupstudy.com
Page 54
GupShupStudy.com 54
www.gupshupstudy.com
GupShupStudy.com 55
www.gupshupstudy.com
{A, B} {A, C,} {B, C,} {B, D} {A, C,} {C, D} {B, D} {C, D}
Page 56
GupShupStudy.com 56
www.gupshupstudy.com
{O}
Fig Lattice of subsets of the universe U.
GupShupStudy.com 57
www.gupshupstudy.com
Page 58
GupShupStudy.com 58
www.gupshupstudy.com
∑ P (E/Hn).P (Hn)
Specifically, when we say P (A/B), we are describing
the conditional probability of A given that the only evidence we
have is B. If there is also other relevant evidence, then it too
must be considered. Suppose, for example, that we are solving a
medical diagnosis problem. Consider the following assertions:
S: patient has spots
M: patient has measles
F: patient has high fever
Without any additional evidence, the presence of spots serves
as evidence in favor of measles. It also serves as evidence of
fever since measles would cause fever. But, since spots and
fever are not independent events, we cannot just sum their
effects; instead, we need to represent explicitly the conditional
probability that arises from their conjunction. In general, given a
prior body of evidence e and some new observation E, we need
to compute.
P (H/E, e) = P (H/E).P (e/E, H)
P (e/E)
Unfortunately, in an arbitrarily complex world, the sizes of
the set of join probabilities that we are require in order to
compute this function grows as 2n if there are n different
Page 59
GupShupStudy.com 59
www.gupshupstudy.com
Page 60
GupShupStudy.com 60
www.gupshupstudy.com
GupShupStudy.com 61
www.gupshupstudy.com
GupShupStudy.com 62
www.gupshupstudy.com
Examples
Feedback u
Learner
Component
Environment
Or Teacher Knowledge Critic
performance
Base
Evaluator
Response
Performance
Component
Tasks
Fig. Learning Model
Page 63
GupShupStudy.com 63
www.gupshupstudy.com
Page 64
GupShupStudy.com 64
www.gupshupstudy.com
knowledge
Feedback
Learning resultant
Algorithms
Training
Scenario
Representation
scheme
Page 65
GupShupStudy.com 65
www.gupshupstudy.com
GupShupStudy.com 66
www.gupshupstudy.com
Page 67
GupShupStudy.com 67
www.gupshupstudy.com
Factors to consider
GupShupStudy.com 68
www.gupshupstudy.com
GupShupStudy.com 69
www.gupshupstudy.com
.
Generalizations of supervised learning
Page 70
GupShupStudy.com 70
www.gupshupstudy.com
Dog 1 0 0 0 0 0
Cat 1 0 0 0 0 0
Bat 1 0 0 1 0 0
Whale 1 0 0 0 1 0
Canary 0 0 1 1 0 1
Robin 0 0 1 1 0 1
Ostrich 0 0 1 1 0 1
Snake 0 1 0 0 0 1
Lizard 0 1 0 0 0 1
Page 71
GupShupStudy.com 71
www.gupshupstudy.com
Alligator 0 1 0 0 1 1
Fig. Data for unsupervised learning
This form of learning is called unsupervised learning
because no teacher is required. Given a set of input data, the
network is allowed to play with it to try to discover regularities
and relationships between the different parts of the input.
Learning is often made possible through some notion of which
features in the input sets are important. But often we do not
know in advance which features are important, and asking a
learning system to deal with raw input data can be
computationally expensive. Unsupervised learning can be used
as a “feature discovery” module that precedes supervised
learning.
Consider the data in fig. the group of ten animals, each is
described by its own set of features, breaks down naturally into
three groups: mammals, reptiles and birds. We would like to
build a network that can learn which group a particular animal
belongs to, and to generalize so that it can identify animals it has
not yet seen. We can easily accomplish this with a six-input,
three-output back propagation network. We simply present the
network with an input, observe its output, and update its weights
based on the errors it makes. Without a teacher, however, the
error cannot be computed, so we must seek other methods.
Our first problem is to ensure that only one of the three output
units become active for any given input. One solution to this
problem is to let the network settle, find the output unit with the
Page 72
GupShupStudy.com 72
www.gupshupstudy.com
highest level of activation, and set that unit to 1 and all other
output units to 0. In other words, the output unit with the highest
activation is the only one we consider to be active. A more
neural-like solution is to have the output units fight among
themselves for control of an input vector.
Page 73
GupShupStudy.com 73
www.gupshupstudy.com
GupShupStudy.com 74
www.gupshupstudy.com
GupShupStudy.com 75
www.gupshupstudy.com
GupShupStudy.com 76
www.gupshupstudy.com
Page 77
GupShupStudy.com 77
www.gupshupstudy.com
Page 78
GupShupStudy.com 78
www.gupshupstudy.com
Page 79
GupShupStudy.com 79
www.gupshupstudy.com
GupShupStudy.com 80
www.gupshupstudy.com
Page 81
GupShupStudy.com 81
www.gupshupstudy.com
GupShupStudy.com 82
www.gupshupstudy.com
Page 83
GupShupStudy.com 83
www.gupshupstudy.com
Disadvantages:
1. Dependency-directed
backtracking incurs a significant time and space overhead
as it requires the maintenance of dependency records and
an additional no-good database. Thus the effort required to
Page 84
GupShupStudy.com 84
www.gupshupstudy.com
Page 85
GupShupStudy.com 85
www.gupshupstudy.com
Unit-4
Natural Language processing and planning
Backward chaining: Backward chaining (or backward
reasoning) is an inference method used in automated theorem
provers, proof assistants and other artificial intelligence
applications. It is one of the two most commonly used methods
of reasoning with inference rules and logical implications – the
other is forward chaining. Backward chaining is implemented in
logic programming by SLD resolution. Both rules are based on
the modus ponens inference rule.
Page 86
GupShupStudy.com 86
www.gupshupstudy.com
GupShupStudy.com 87
www.gupshupstudy.com
Page 88
GupShupStudy.com 88
www.gupshupstudy.com
Page 89
GupShupStudy.com 89
www.gupshupstudy.com
starting from some multi text and one or more monolingual tree
banks.
The recipe follows:
T1. Induce a word-to-word translation model.
T2. Induce PCFGs from the relative frequencies of productions
in the monolingual tree banks
T3. Synchronize some multi text,
T4. Induce an initial PMTG from the relative frequencies of
productions in the multi tree bank.
T5. Re-estimate the PMTG parameters, using a
Synchronous parser with the expectation smearing.
A1. Use the PMTG to infer the most probable multi tree
Covering new input text.
A2. Linearize the output dimensions of the multi tree.
Steps T2, T4 and A2 are trivial. Steps T1, T3, T5, and A1 are
instances of the generalized parsers
Figure 2 is only architecture. Computational
Complexity and generalization error stand in the
Way of its practical implementation. Nevertheless,
it is satisfying to note that all the non-trivial algorithms
In Figure 2 are special cases of Translator CT.
It is therefore possible to implement an MTSMT
System using just one inference algorithm, parameterized
By a grammar, a smearing, and a search
Strategy. An advantage of building an MT system in
This manner is that improvements invented for ordinary
Parsing algorithms can often be applied to all
The main components of the system. For example,
Page 90
GupShupStudy.com 90
www.gupshupstudy.com
Page 91
GupShupStudy.com 91
www.gupshupstudy.com
GupShupStudy.com 92
www.gupshupstudy.com
Page 93
GupShupStudy.com 93
www.gupshupstudy.com
size, each block can have at most one other block directly on top
of it.
In order to specify both the conditions under which an operation
may be performed and the results of performing it, we need to
use the following predicates:
GupShupStudy.com 94
www.gupshupstudy.com
Page 95
GupShupStudy.com 95
www.gupshupstudy.com
P: CLEAR(Y) ^HOLDING(X)
D: CLEAR(Y) ^HOLDING(X)
Page 96
GupShupStudy.com 96
www.gupshupstudy.com
A: ARMEMPTY^ON(X, Y)
UNSTACK(X, Y)
D: ON(X, Y) ^ARMEMPTY
A: HOLDING(X) ^ON(X, Y)
PICKUP(X)
D: ONTABLE(X) ^ARMEMPTY
A: HOLDING(X)
PUTDOWN(X)
P: HOLDING(X)
D: HOLDING(X)
A: ONTABLE(X) ^ARMEMPTY
GupShupStudy.com 97
www.gupshupstudy.com
C D
A A D
ARMEMPTY
Page 98
GupShupStudy.com 98
www.gupshupstudy.com
ON (C, A) ON (B, D)
ON (B, D) ON (C, A)
[1] [2]
GupShupStudy.com 99
www.gupshupstudy.com
GupShupStudy.com 100
www.gupshupstudy.com
|\ ^
| \++++++++++++++++| |
| v |
++++++> S3 ++++++> S4 ++++++
graphically represents the temporal constraints S1 < S2, S1 <
S3, S1 < S4, S2 < S5, S3 < S4, and S4 < S5. This partial-order
plan implicitly represents the following three total-order plans,
each of which is consistent with all of the given constraints:
[S1,S2,S3,S4,S5], [S1,S3,S2,S4,S5], and [S1,S3,S4,S2,S5].
Partial-Order Planner (POP) Algorithm
function pop(initial-state, conjunctive-goal, operators)
// non-deterministic algorithm
plan = make-initial-plan(initial-state, conjunctive-goal);
loop:
begin
if solution?(plan) then return plan;
(S-need, c) = select-subgoal(plan) ; // choose an unsolved goal
choose-operator(plan, operators, S-need, c);
// select an operator to solve that goal and revise plan
resolve-threats(plan); // fix any threats created
end
end
function solution?(plan)
if causal-links-establishing-all-preconditions-of-all-steps(plan)
and all-threats-resolved(plan)
and all-temporal-ordering-constraints-consistent(plan)
and all-variable-bindings-consistent(plan)
then return true;
else return false;
Page 101
GupShupStudy.com 101
www.gupshupstudy.com
end
function select-subgoal(plan)
pick a plan step S-need from steps(plan) with a precondition c
that has not been achieved;
return (S-need, c);
end
procedure resolve-threats(plan)
foreach S-threat that threatens link "Si --->c Sj" in Links(plan)
begin // "declobber" threat
choose either
Demotion: add "S-threat < Si" to Orderings(plan)
or Promotion: add "Sj < S-threat" to Orderings(plan);
if not(consistent(plan)) then return fail;
end
Page 102
GupShupStudy.com 102
www.gupshupstudy.com
end
Unit-5
Expert System and AI languages
Introduction: An expert system is a set of programs that
manipulate encoded knowledge to solve problems in a
specialized domain that normally requires human expertise. An
expert system’s knowledge is obtained form expert sources and
coded in a form suitable for the system to use in its interference
or reasoning processes. The expert knowledge must be obtained
from specialists or other sources of expertise, such as texts,
Page 103
GupShupStudy.com 103
www.gupshupstudy.com
Page 104
GupShupStudy.com 104
www.gupshupstudy.com
Page 105
GupShupStudy.com 105
www.gupshupstudy.com
User
Page 106
GupShupStudy.com 106
www.gupshupstudy.com
Page 107
GupShupStudy.com 107
www.gupshupstudy.com
EXPERT SYSTEM
USER
Explanation
Module
Output
Learning
Module
Page 108
GupShupStudy.com 108
www.gupshupstudy.com
Page 109
GupShupStudy.com 109
www.gupshupstudy.com
Page 110
GupShupStudy.com 110
www.gupshupstudy.com
Page 111
GupShupStudy.com 111
www.gupshupstudy.com
Page 112
GupShupStudy.com 112
www.gupshupstudy.com
Page 113
GupShupStudy.com 113
www.gupshupstudy.com
Page 114
GupShupStudy.com 114
www.gupshupstudy.com
Page 115
GupShupStudy.com 115
www.gupshupstudy.com
Control information
Fig. Components of blackboard systems.
which is passed on to other nodes or is used to produce some
output response.
Neural networks were originally inspired as being
models of the human nervous system. They are generally
simplified models to be sure.
GupShupStudy.com 116
www.gupshupstudy.com
D
Domain Knowledge System Knowledge
engineer Editor
Expert Base
GupShupStudy.com 117
www.gupshupstudy.com
Page 118
GupShupStudy.com 118
www.gupshupstudy.com
Examples
Here are examples of Common Lisp code.
The basic "Hello world" program:
(Print "Hello world")
As the reader may have noticed from the above discussion, Lisp
syntax lends itself naturally to recursion. Mathematical problems
such as the enumeration of recursively defined sets are simple to
express in this notation.
Evaluate a number's factorial:
(Defun factorial (n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
Page 119
GupShupStudy.com 119
www.gupshupstudy.com
GupShupStudy.com 120
www.gupshupstudy.com
GupShupStudy.com 121
www.gupshupstudy.com
Prolog's single data type is the term. Terms are either atoms,
numbers, variables or compound terms.
• An atom is a general-purpose name with no inherent
meaning. Examples of atoms include x, blue, 'Taco', and
'some atom'.
• Numbers can be floats or integers.
• Variables are denoted by a string consisting of letters,
numbers and underscore characters, and beginning with an
upper-case letter or underscore. Variables closely resemble
variables in logic in that they are placeholders for arbitrary
terms.
• A compound term is composed of an atom called a
"functor" and a number of "arguments", which are again
terms. Compound terms are ordinarily written as a functor
followed by a comma-separated list of argument terms,
which is contained in parentheses. The number of
arguments is called the term's arity. An atom can be
Page 122
GupShupStudy.com 122
www.gupshupstudy.com
An example of a query:
?- write('Hello world!'), nl.
Hello world!
true.
?-
Compiler optimization
Any computation can be expressed declaratively as a sequence
of state transitions. As an example, an optimizing compiler with
Page 123
GupShupStudy.com 123
www.gupshupstudy.com
GupShupStudy.com 124
www.gupshupstudy.com
Dynamic programming
lcs([], _, []) :- !.
lcs(_, [], []) :- !.
lcs([X|Xs], [X|Ys], [X|Ls]) :- !, memo(lcs(Xs, Ys, Ls)).
lcs([X|Xs], [Y|Ys], Ls) :-
memo(lcs([X|Xs], Ys, Ls1)), memo(lcs(Xs, [Y|Ys], Ls2)),
length(Ls1, L1), length(Ls2, L2),
( L1 >= L2 -> Ls = Ls1 ; Ls = Ls2 ).
Example query:
?- lcs([x,m,j,y,a,u,z], [m,z,j,a,w,x,u], Ls).
Ls = [m, j, a, u]
Design patterns
GupShupStudy.com 125
www.gupshupstudy.com
Higher-order programming
Main articles: Higher-order logic and Higher-order
programming
Page 126
GupShupStudy.com 126
www.gupshupstudy.com
GupShupStudy.com 127
www.gupshupstudy.com
Page 128
GupShupStudy.com 128
www.gupshupstudy.com
Practical use
MYCIN was never actually used in practice. This wasn't
because of any weakness in its performance. As mentioned, in
tests it outperformed members of the Stanford medical school
faculty. Some observers raised ethical and legal issues related to
the use of computers in medicine — if a program gives the
wrong diagnosis or recommends the wrong therapy, who should
be held responsible? However, the greatest problem, and the
reason that MYCIN was not used in routine practice, was the
state of technologies for system integration, especially at the
time it was developed. MYCIN was a stand-alone system that
required a user to enter all relevant information about a patient
by typing in response to questions that MYCIN would pose. The
program ran on a large time-shared system, available over the
early Internet (Arpanet), before personal computers were
developed. In the modern era, such a system would be integrated
with medical record systems, would extract answers to questions
from patient databases, and would be much less dependent on
physician entry of information. In the 1970s, a session with
MYCIN could easily consume 30 minutes or more—an
unrealistic time commitment for a busy clinician.
A difficulty that rose to prominence during the development of
MYCIN and subsequent complex expert systems has been the
extraction of the necessary knowledge for the inference engine
Page 129
GupShupStudy.com 129
www.gupshupstudy.com
to use from the human expert in the relevant fields into the rule
base (the so-called knowledge engineering).
Page 130
GupShupStudy.com 130