You are on page 1of 19

Course Code Course Title Assignment Number Maximum Marks Weight age Last Date of Submission

: : : : : :

MCSE-003 Artificial Intelligence and Knowledge Management MCA(5)/E003/Assign/2011 100 25% 30th April, 2011 (For January Session) 31st October, 2011 (For July Session)

This assignment has ten questions and carries 80 marks. The rest of the 20 marks are for viva-voce. Answer all the questions. You may use illustrations and diagrams to enhance the explanations. Please go through the guidelines regarding assignments given in the Programme Guide for the format of presentation.
Question 1: How does the use of heuristics reduce the search space ? Suggest a god heuristic function for travelling salesman problem.

(10 Marks)

According to George Polya heuristics is the study of the methods and rules of discovery and invention. In state space search, heuristics define the rules for choosing branches in a state space that are most likely to lead to an acceptable solution. There are two cases in AI searches when heuristics are needed:

The problem has no exact solution. For example, in medical diagnosis doctors use heuristics to choose the most likely diagnoses given a set of symptoms. The problem has an exact solution but is too complex to allow for a brute force solution. Key Point: Heuristics are fallible. Because they rely on limited information, they may lead to a suboptimal solution or to a dead end. Example: The traveling salesman problem is too complex to be solved via exhaustive search for large values of N. The nearest neighbor heuristic work well most of the time, but with some arrangements of cities it does not find the shortest path. Consider the following two graphs. In the first, nearest neighbor will find the shortest path. In the second it does not:

According to George Polya heuristics is the study of the methods and rules of discovery and invention. In state space search, heuristics define the rules for choosing branches in a state space that are most likely to lead to an acceptable solution. There are two cases in AI searches when heuristics are needed:

The problem has no exact solution. For example, in medical diagnosis doctors use heuristics to choose the most likely diagnoses given a set of symptoms. The problem has an exact solution but is too complex to allow for a brute force solution. Key Point: Heuristics are fallible. Because they rely on limited information, they may lead to a suboptimal solution or to a dead end. Example: The traveling salesman problem is too complex to be solved via exhaustive search for large values of N. The nearest neighbor heuristic work well most of the time, but with some arrangements of cities it does not find the shortest path. Consider the following two graphs. In the first, nearest neighbor will find the shortest path. In the second it does not:

Question 2: Write short notes on the following : (i) Knowledge manipulation Knowledge manipulation and inference. If we have a certain domain and its representation in a representational space, we can execute operations on these structures. In the case of symbolic representation, we are manipulating symbols according to certain rules and algorithms (e.g., we can draw inferences on the given facts and rules or in a semantic network). In the case of connectionist networks, activations spread through the network and generate patterns of activations that lead to the externalization of behavior. (ii) Associative networks
Neural networks can be classified as either pattern-classifiers or pattern-associators. Pattern-classifiers take an input vector and output a value that can be used to classify it. For example, taking a sonar signal and classifying it as either a rock or a mine. Perceptrons and Adaline networks are examples of such classifiers. A pattern-associator network is a net that takes a given input vector and outputs another vector. There are two types of associative networks, hetero-associative (HA) and auto-associative (AA). Hetero-associative takes an input vector and outputs a completely different vector. For example, an HA-net could be used to take a sound file and output the text that it

represents (or the closest learned text). Auto-associative networks take input and output the same vector. How is this useful? An AA-net could learn various vectors, then when a corrupted vector came in, it would be corrected by the net. This can be used in imagerecognition of partial or corrupted ("noisy") images. It is auto-associative networks that this essay will focus on, or more specifically the Hopfield network. The Hopfield Network The Hopfield is an auto-associative network often used (or derivates of it) in monochrome image recognition. When introduced in 1982, it had a rather new concept - outputs would feedback to the inputs. The network consists of one layer, whose unit outputs feedback to all the other inputs but its own. The architecture looks like this:

One of the huge advantages of this network is that weights are calculated with one calculation (mathematically-speaking). In order to see how the Hopfield network works, and how the mathematics behind it came about, we must temporarily digress and talk about the learning matrix.

(iii) Fuzzy matching algorithms In the symbolic Logic systems like, PL and FOPL, that we have studied so far, any (closed) formula has a truth-value which must be binary, viz., True or False. However, in our everyday experience, we encounter problems, the descriptions of which involve some words, because of which, to statements of situations, it is not possible to assign a truth value: True or False. For example, consider the statement: If the water is too hot, add normal water to make it comfortable for taking a bath. In the above statement, for a number of words/phrases including too hot add, comfortable etc., it is not possible to tell when exactly water is too hot, when water is (at) normal (temperature), when exactly water is comfortable for taking a bath. For example, we cannot tell the temperature T such that for water at temperature T or less, truth value False can be associated with the statement Water is too hot and at the same time truth-value True can also be associated to the same statement Water is too hot when the temperature of the water is, say, at degree T + 1, T + 2.etc.

Fuzzy logic is an ideal way to take analog concepts from the real world and make them manageable in the discrete world of computer systems. Instead of dealing with crisp values and their semantics, we deal instead with membership in sets that represent the semantics of the value system. In this way, we can operate in the domain of conditional expressions using degrees of membership in fuzzy membership functions. Fuzzy logic was created by Lotfi Zadeh at the University of California at

Berkeley in 1965. The method was controversial, but adopted with success in Japan in a variety of successful applications. Adoption in the U.S. was much slower, but applications have grown with this method. This is because fuzzy logic can be easily implemented in low cost and low-end microprocessors. From a control perspective, fuzzy logic solves a real problem when considering the semantics of values. In human language, we talk about discrete states, but this creates problems for continuous ranges of values. For example, we can refer to temperature as hot or cold, but what do they really mean? Further, if we try to build logic based on a discrete factor such as cold, we quickly run into problems. The continuous nature of things like temperature are not well suited for the binary nature of logic. For example,

if we have just two temperatures, then theres a temperature by which we transition from cold to hot, and the real world doesnt work that way. The answer is to use a mechanism that takes real-world ranges and translates them into discrete states, but in a fuzzy way. For example, instead of our temperature being hot or cold, our temperature is instead a member of the states. Lets look at an example to illustrate this further. Figure 12.17 provides graph indicating the membership functions for our temperature states. A membership function is one that defines the degree of membership for a value to a given state (instead of simple true or false, as would be the case for traditional logic). For example, if our temperature is T1 or below, then we can say that the temperature is 1.0 cold and 0.0 hot. But since the membership for hot is 0, we can omit it. On the other side, temperature T3 is 1.0 hot and 0.0 cold (or simply, Hot). Between T1 and T2 is where fuzzy logic begins to make sense. For example, at temperature T2, the fuzzy temperature is 0.5 cold and 0.5 hot.

So its neither hot, nor cold. This allows us to refer to temperatures in human terms, while allowing a computer to deal with them in a numeric sense (in terms of membership in a temperature category). (iv) Conceptual Dependency Graph
Conceptual dependency theory offers a number of important benefits. By providing a iconal theory ofnatural language semantics, it reduces problems of ambiguity. Second, the Representation itself directly captures much of natural language semantics, by attempting to provide a canonical form for the meaning of sentences. That is, all sentences that have the same meaning will be represented internally by syntactically identical, not just semantically equivalent, graphs. This cauonical representation is an effort to simplify the mferences required for understanding. For example, we can demonstrate that two inferences mean the same thing with a simple match of conceptual dependency graphs; a representation that did not provide a canonical form might require extensive operations on differently structured graphs. Unfortunately, it is questionable whether a program may be written to reliably reduce sentences to canonical form. As Woods (1985) and others have pointed out, reduction to a canonical form is provably uncomputable for monoids, a type ofalgebraic group that is far simpler than natural language. There is also no evidence that humans store their knowledge in any such sort of canonical form.

Inheritance in conceptual graphs.

7.24Conceptual graph of the statement Tom believes that Jane likes pizza, showing the use of a propositional concept.

(20 Marks)

Question 3: Discuss state space representatio n for the following well-known problems: (15 Marks) (i) Travelling Salesman Problem Starting at A, find the shortest path through all the cities, visiting each city exactly once and returning to A.

Redu cing Sear ch Com plexi ty: For N cities ,a brute force soluti on to the traveling salesman problem takes N! time. There are ways to reduce this complexity: Branch and Bound Algorithm: Generate one path at a time, keeping track of the best circuit so far. Use the best circuit so far as a bound on future branches of the search. This reduces the complexity to 1.26N. Nearest Neighbor Heuristic: At each stage of the circuit, go to the nearest unvisited city. This strategy reduces the complexity to N, so it is highly efficient, but it is not guaranteed to find the shortest path, as the following example shows:

(ii) Wat er-Jug Problem Imagine that you have two jugs called X and Y. Initially, both are empty. You are allowed to fill either jug X or jug Y from a tap but if you do, you have to fill it completely. You are also allowed to fill jug X from jug Y, or jug Y from jug X, and to empty either jug on the ground. Jug X can hold 4 pints and jug Y can hold 3 pints. The problem is simply this: given the allowed actions, can you manage to reach a state where you have exactly 2 pints in jug X. This problem is known as the water jugs problem and it has no easy solution. If we just fill X from the tap we end up with 4 pints in X, not 2. If we fill Y from the tap and empty it into X, we end up with 3 pints in X. The only way to find a solution to this problem is to consider systematically the effects achieved by performing sequences of actions. But how can we go about this?

Systematically considering all possible sequences of actions is just like systematically considering all possible sequences of locations (i.e. all possible routes). So the water jugs problem can be construed as a sort of search problem. Of course, if we are going to construe the water jugs problem as a search problem, nodes in the search space will have to represent states of the two jugs rather than locations in a physical environment. The start node, will have to be a representation of the initial state (e.g. 0 pints in both jugs); the goal node will have to be a representation of the goal state (e.g. 2 pints in X, any amount in Y), and the successor function will have to return that set of new states which can be reached from any given state by performing exactly one allowed action. So the main difference between this example and the one used in the previous chapter is that each state now contains some components (e.g. the contents of the two jugs) rather than just being an atomic value (e.g. clock_tower).

Constructing Successor Nodes We can represent states in the water jugs problem as two-element lists in which the first element is an integer representing the number of pints in the jug called X, and the second element is an integer representing the number of pints in Y. Thus, the state in which X has 3 pints in it and Y has 2 would be represented by the list expression:

[3 2]

We could implement the successor function using the approach that we took with the pathfinding problem, i.e. we could construct a database showing the connections between states and then use a foreach loop to dig out the states we can achieve in one move. The beginning of the database might look something like this:

[ [[0 0] [4 0]] [[0 0] [0 3]] ... ... ] -> database;

These first two elements represent the fact that from the state [0 0] you can either fill X to achieve [4 0] or fill Y to achieve [0 3]. Note that the complete database will be large. There are 5 4 possible states and there are normally 6 possible actions. So the database will have roughly 5 4 6 = 120

entries. It will not be exactly 120 because, for some states, two different actions can lead to an identical new state. Nevertheless this multiplicity leads us to wonder whether there might be an easier way to implement the successor function.

Note that our state representations are structures with two separate components. The successors of any given state can be derived (i.e. computed) by looking at the components of any state representation and making some substitutions. For example, imagine that we wish to work out what the successors of the state [4 2] are. We know that one possible action is to empty X into Y; thus one successor is just the state which is reached by carrying out this action. But what is this state?

We can construct it quite easily. Y can hold 3 pints. So if we empty X into Y (which already has 2 pints in it), exactly 1 pint will flow from X to Y. X will have 3 pints left in it and Y will have 3 pints in it. It is quite easy to turn this bit of computation into POP-11 code. In fact we can write POP-11 rules to take care of every allowable action. If we put them all together, we get a function which produces the successors of any given state. This program obviously implements the desired successor function. But it does not do so in the same way that our previous program didby scanning a database. It produces the successors by operating on the components of structured state descriptions.

A simple version of the successor function might be defined as in Figure 3-1. This version of the function only takes account of the single action whereby one jug is emptied on the ground. Either X can be emptied or Y can be emptied; so the successors of any state include one state in which X has 0 pints (regardless of what it had before) and one state in which Y has 0 pints. The number of pints in the other jug remains the same in either case.

/* successors2 takes a state and returns a list of successor states. */ define successors2(state) -> result; vars X Y; state --> [?X ?Y]; [[^X 0] [0 Y]] -> result; enddefine;

The function digs out the components of the input state description using the matcher arrow. This, effectively, puts the number of pints in the jug X in to the variable called "X", and the number of pints in the jug Y in to the variable called "Y". It then constructs a list of lists (i.e. a list of states), one of which substitutes the original X with 0 and the other of which substitutes the original Y with 0. These are just the successor states of the original state resulting from the action of emptying either X or Y on the ground.

To implement the complete successor function for this problem we need to take account of the other possible actions. Note that in the case of actions involving the emptying of one jug into another, the generation of a successor state entails doing a little bit of arithmetic. For example, to work out how much water flows from X to Y when we empty X into Y, we have to work out how much space Y has in it (by subtracting 3 from Y) and how much water is transferred by subtracting this from the current value of "X". The complete function might be defined as in Figure 3-2. Note the use of comments.

/* successors3 takes a state and returns a list of successor states. */ define successors3(state) -> result; vars X Y result; state --> [?X ?Y]; [^( /* FILL X COMPLETELY FROM Y WITH SOME LEFT OVER */ if Y /= 0 and X /= 4 and X+Y > 4 then [4 ^(X+Y-4)] endif; /* EMPTY Y COMPLETELY INTO X */ if Y /= 0 and X /= 4 and X+Y =< 4 then [^(X+Y) 0] endif; /* FILL Y COMPLETELY FROM X WITH SOME LEFT OVER */ if Y /= 3 and X /= 0 and X+Y > 3 then [^(X+Y-3) 3] endif; /* EMPTY X COMPLETELY INTO Y */ if Y /= 3 and X /= 0 and X+Y =< 3 then [0 ^(X+Y)] endif; /* EMPTY OUT X */ if X /= 0 then [0 ^Y] endif; /* EMPTY OUT Y */ if Y /= 0 then [^X 0] endif; /* FILL X UP FROM THE TAP */ if X /= 4 then [4 ^Y] endif; /* FILL Y UP FROM THE TAP */

if Y /= 3 then [^X 3] endif; )] -> result; enddefine;

(iii) Human Cannibal River-Crossing Problem. N (where N>=1) missionaries and N cannibals arrive on the left bank of a river. They have a rowing boat with them. The boat will be used for transporting them across the river to the right bank. Each of them know how to row but there are two constraints: The boat, which requires one person to row, cannot carry more than two persons at a time; and If the number of missionaries on a bank is one or more, the number of cannibals on that bank cannot be more than the number of missionaries on that bank. How are the missionaries and the cannibals to be transported across the river?

To set up the state space of this problem we must find a suitable formal representation of:

N (where N>=1) missionaries and N cannibals arrive on the left bank of a river. They have a rowing boat with them. The boat will be used for transporting them across the river to the right bank. Each of them know how to row but there are two constraints: The boat, which requires one person to row, cannot carry more than two persons at a time; and If the number of missionaries on a bank is one or more, the number of cannibals on that bank cannot be more than the number of missionaries on that bank. How are the missionaries and the cannibals to be transported across the river?

To set up the state space of this problem we must find a suitable formal representation of: State triple <1,2,3>, where 1 persons on the left bank; 2 persons on the right bank; 3 boat position (L boat is on the left bank; R boat is on the right bank); If m denote missionaries, c cannibals, the initial state is and the final state is <0,NmNc,R>. To set up the state space of this problem we must find a suitable formal representation of: Moves There are five alternative moves: 1m send one missionary in the boat to sail 2m two missionaries 1m1c one missionary and one cannibal 1c one cannibal 2c two cannibals

Question 4: Represent the following situation with Associative networks. "IGNOU is an open university established by an act of parliament. It has various schools of studies and Divisions to support academic activities at the Head Quarters. IGNOU's regional centers are spread all over the country to manage the academic and administrative activities. Each School and Division is headed by a Director and each Regional Centre is headed by Regional Directors." (10 Marks) Note: Figure 7.3 Page 129 pf Introduction to Artificial Intelligence and Expert systems by D.W.Patterson, Prentice-Hall of India, 1992). Network representations provide a means of structuring and exhibiting the structure in knowledge. In a network, pieces of knowledge are clustered together into coherent semantic groups. Networks also provide a more natural way to map to and from natural language than do other representation schemes. Network representations give a pictorial presentations of objects, their attributes and the relationships that exist between them and other entities. In this section, we describe general associative networks (also known as semantic networks) and conceptual graphs and give some of their properties. Associative networks are directed graphs with labeled nodes and arcs or arrows. The language used in constructing a network is based on selected domain primitives for objects and relationsa as well as some general primitives. A fragment of a simple network is illustrated below figured. In the figure, a class of objects known as bird is depicted. The class some properties and a specific memebers. Associative networks were introduced by Quallian(1968) to model the semantics of English sentences and words. He called his structures semantic networks to signify words by the paths connecting them. The connections were determined through a kind of spreading activatioon between the two words.

Quillian's model of semantic networks has a certain intuitive appeal in that related information is clustered and bound together through relational links. The knowledge required for the performance of some tasks is typically contained within a narrow domain or a semantic vicinity of the taks. This type of organization in some way, resembles the way knowledge is stored and retrived in humans. The graphical portrayal of knowledge can also be some what more expensive than other representation schemes. This probably accounts for the popularity and the diversity of representation models for which they have been employed. They have, for example, been used in a variety of systems such as natural language understanding, information retrieval, deductive data bases, learning systems, computer vision, and in speech generation systems.

Question 5: (a) Compare and contrast the following (Any two): i) A* and AO*

A* and AO* are the two classical heuristic best-first al-gorithms for searching OR and AND/OR graphs (Hart,Nilsson, & Raphael 1968; Martelli & Montanari 1973;Pearl 1983). The A* algorithm is taught in every AI class,and has been studied thoroughly both theoretically and empirically. The AO* algorithm, on the other hand, has found less uses in AI, and while prominent in early AI texts (Nils-son 1980) it has disappeared from current ones (Russell & Norvig 1994). In the last few years, however, there has been a renewed interest in the AO* algorithm in planning re- search where problems involving uncertainty and feedback can be formulated as search problems over AND/OR graphs (Bonet & Geffner 2000). In this work, we carry out what is probably the first in-depth empirical evaluation of AO* in relation with other AND/OR graph search algorithms. We compare AO* with an old but general algorithm, Value Iteration (Bellman 1957; Bertsekas 1995), and a new algorithm, Learning in Depth- First Search, and its variant Bounded LDFS (Bonet & Geffner 2005). While VI performs a sequence of Bellman updates over all states in parallel until convergence, LDFS performs selective Bellman updates on top of successive

depth-first searches, very much as Learning RTA* (Korf 1990) and RTDP (Barto,Bradtke, & Singh 1995) perform

Bellman updates on top of successive greedy (real-time) searches. In the absence of accepted benchmarks for evaluating AND/OR graph search algorithms, we introduce four parametric domains, and consider a large number of instances, some involving millions of states. In all cases we focus on the computation of solutions with minimum cost in the worst case using three different and general admissible heuristic functions. We find roughly that while AO* does better than VI in the presence of informed heuristics, LDFS, with or without heuristics, tends to do better than both. AO* is limited to handling AND/OR graphs without cycles. The difficulties arising from cycles can be illustrated by means of a simple graph with two states and two ac-tions: an action a with cost 5 maps the initial state s0 nondeterministically into either a goal state sG or s0 itself, and a second action b with cost 10 maps s0 deterministically into sG . Clearly, the problem has cost 10 and b is the only (optimal) solution, yet the simple cost revision step in AO* does not yield this result. Thus, for domains where such cycles appear, we evaluate a recent variant of AO*, CFCrev , introduced in Jimen z Torras 2000 that is not affected by this eproblem. We could have used LAO* as well (Hansen & Zil-berstein 2001), but this would be an overkill as LAO* is designed to minimize expected cost in probabilistic AND/OR graphs (MDPs) where solutions themselves can be cyclic, something that cannot occur in Additive or Max AND/OR graphs. Further algorithms for cyclic graphs are discussed in (Mahanti, Ghose, & Sadhukhan 2003). LDFS has no lim-itations of this type; unlike AO*, it is not affected by the presence of cycles in the graph, and unlike Value Iteration, it is not affected either by the presence of dead-ends in the state space if the problem is solvable. The paper is organized as follows: we consider first the models, then the algorithms, the experimental set up and the results, and close with a brief discussion.

AO* 1. Place the start node s on open.


2. Using the search tree constructed thus far, compute the most promising solution tree T 3. Select a node n that is both on open and a part of T. 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 ns ancestors being solved, label all the ancestors as solved. If the start node s is solved, exit with success where T 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 as unsolvable, exit with failure. If any of ns ancestors become unsolvable because n is, label them unsolvable as well. Remove from open all nodes with unsolvable ancestors. 6. Otherwise, expand node n generating all of its successors. For each such successor node that contains more than one sub problem, generate their successors to give individual sub problems. Attach to each newly generated node a back pointer to its predecessor. Compute the cost estimate h* for each newly generated node and place all such nodes that do not yet have descendents on open. Next, recomputed the values of h* at n and each ancestor of n. 7. Return to step 2.

ii)

Conceptual graph and conceptual representation

A conceptual graph is a finite, connected, bipartite graph. The nodes of the graph are either concepts or conceptual relations. Conceptual graphs do not use labeled arcs; instead the conceptual relation nodes represent relations between concepts. Because conceptual graphs are bipartite, concepts only have arcs to relations, and vice versa. In Figure 7.14 dog and brown are concept nodes and color a conceptual relation. To distinguish these types of nodes, we represent concepts as boxes and conceptual relations as ellipses. In conceptual graphs, concept nodes represent either concrete or abstract objects in the world of discourse. Concrete concepts, such as a cat, telephone, or restaurant, are characterized by OUf ability to form an image of them in our minds. Note that concrete concepts include generic concepts such as cat or restaurant along with concepts of specific cats and restaurants. We can still form an image of a generic cat. Abstract concepts include things such as love, beauty, and loyalty that do not correspond to images in our minds.
Conceptual Representation Conceptual representation is arguably the most important cognitive functions in humans. It stands at the centre of the information processing flow, with input from perceptual modules of differing kinds, and is centrally involved in memory, speech, planning, decision-making, actins, inductive inferences and much more besides. It is therefore unsurprising that it is also a domain of interest to the full range of cognitive sciences linguistics via lexical semantics, psychology through the use of concepts in thought and categorisation and children's acquisition of concepts and word meanings. AI through the development of systems for knowledge representation neuroscience through the recent development of interest in dissociations between knowledge domains and the role of perceptual and motor areas in concept representation, and finally philosophy which originally began the whole process of trying to find the basic building blocks of thought and kn

iii)

Scripts and frames

A natural language understanding program must use a large amount of background knowledge to understand even the simplest conversation (Section 14.0). There is evidence that hwnans organize this knowledge into structures corresponding to typical situations (Bartlett 1932). Ifwe are reading a story about restaurants. baseball, or politics, we resolve any ambiguities in the text in a way consistent with restaurants, baseball, or politics. If the subject of a story changes abruptly, there is evidence that people pause briefly in their reading, presumably to change knowledge structures. It is hard to understand a poorly organized or structured story, possibly because we cannot easily fit it into any of our existing knowledge structures. There can also be errors in understanding when the subject of a conversation changes abruptly, presumably because we are confused over which context to use in resolving pronoun references and other ambiguities in the conversation. A script is a structured representation describing a stereotyped sequence of events in a particular context. The script was originally designed by Schank and his research group 1Schank and Abelson 1977) as a means of organizing conceptual dependency structures

into descriptions of typical situations. Scripts are used in natural language understanding systems to organize a knowledge base in terms of the situations that the system is to understand. Most adults are quite comfortable (i.e., they, as customers, know what to expect and how to act) in a restaurant They are either met at the restaurant entrance or see some sign indicating that they should continue in and find a table. If a menu is not available at the mole or if it is not presented by the waiter, then the customer will ask for one. Similarly, customers understand the routines for ordering food, eating, paying, and leaving. In fact, the restaurant script is quite different from other eating scripts such as the "fastfood" model or the "formal family meal". In the fast-food model the customer enters, gets in line to order, pays for the meal (before eating), waits about for a tray with the food, takes me tray and tries to find a clean table, and so on. These are two different stereotyped sequences of events, and each has a potential script.

Entry conditions or descriptors of the world that must be true for the script to be called. In this script, these include an open restaurant and a hungry customer that has some money. Results or facts that are true once the script has terminated; for example, the customer is full and poorer, the restaurant owner has more money. Props or the "things" that support the content of the script. These might include tables, waiters, and menus. The set ofprops supports reasonable default assumptions about the situation: a restaurant is assumed to have tables and chairs unless stated otherwise. Roles are the actions that the individual participants perform, The waiter takes orders, delivers food, and presents the bill. The customer orders, eats, and pays. Scenes. Schank breaks the script into a sequence of scenes each of which presents a temporal aspect of the script In the restaurant there is entering, ordering, eating, etc. Another representational scheme, in many ways similar to scripts, that was intended to capture in explicitly organized data structures the implicit connections of information in a problem domain, was called frames. This representation supports the organization of knowledge into more complex units that reflect the organization of objects in the domain. In a 1975 paper, Minsky describes a frame: Here is the essence of the frame theory: When one encounters a new situation (or makes a substantial change in one's view of a problem) one selects from memory a structure called a "frame". This is a remembered framework to be adapted to fit reality by changing details as necessary (Minsky 1975). According to Minsky, a frame may be viewed as a static data structure used to represent well-understood stereotyped situations. Framelike structures seem to organize our own knowledge of the world. We adjust to every new situation by calling up information structured by past experiences. We then specially fashion or revise the details of these past experiences to represent the individual differences for the new situation.
Question 6: Write a LISP program to solve a quadratic equation ax2 + bx + c = 0 having real coefficients a, b, c. (10 Marks)

? (defun quadratic-roots (a b c)
"Returns the roots of a quadratic equation aX^2 + bX + c = 0"

(let ((discriminant (- (* b b) (* 4 a c)))) (values (/ (+ (- b) (sqrt discriminant)) (* 2 a)) (/ (- (- b) (sqrt discriminant)) (* 2 a))))) QUADRATIC-ROOTS ? (quadratic-roots 1 2 4) #c(-1.0 1.7320508075688772) #c(-1.0 -1.7320508075688772) ? (quadratic-roots 2 -16 36) #c(4.0 1.4142135623730951) #c(4.0 -1.4142135623730951) ? (quadratic-roots 1 4 4) -2 -2 ? (quadratic-roots 1 -14 49) 7 7 ? (quadratic-roots 1 8 4) -0.5358983848622456 -7.464101615137754 ? (quadratic-roots 1 4 -5) 1 -5

The QUADRATIC-ROOTS function shows how to use a documentation string. The first form in the function body is a string. This does not affect the function result, but it is recorded by the Lisp system for later reference:
? (documentation 'quadratic-roots 'function) "Returns the roots of a quadratic equation aX^2 + bX + c = 0"

This function also shows how we can return two values from a function. You recognize the formula for the roots of a quadratic equation:

? (defun quadratic-roots-2 (a b c)
"Returns the roots of a quadratic equation aX^2 + bX + c = 0. Returns only one value if the roots are coincident." (let ((discriminant (- (* b b) (* 4 a c)))) ; zero if one root (cond ((zerop discriminant) ;; coincident roots -- return one value (/ (+ (- b) (sqrt discriminant)) (* 2 a))) (t ;; two distinct roots

(values (/ (+ (- b) (sqrt discriminant)) (* 2 a)) (/ (- (- b) (sqrt discriminant)) (* 2 a))))))) QUADRATIC-ROOTS-2 ? (quadratic-roots-2 1 -14 49) 7 ? (quadratic-roots-2 1 4 -5) 1 -5 NOTE: ZEROP is a predicate (hence the P suffix) that is true when its numeric argument is zero. Writing (ZEROP n) is the same as writing (= n 0).

Note how QUADRATIC-ROOTS-2 has a two-line documentation string. The newline is part of the string:
? (documentation 'quadratic-roots-2 'function) "Returns the roots of a quadratic equation aX^2 + bX + c = 0. Returns only one value if the roots are coincident."

You might also like