VIEWS: 34 PAGES: 14 CATEGORY: Education POSTED ON: 5/25/2010
MACQUARIE UNIVERSITY Division of Information and Communication Sciences A POTPOURI OF PAST EXAM QUESTIONS FOR COMP329/825 LOGIC AND REASONING QUESTION A1. (Propositional Logic) (8 marks) (a) (2 marks) Translate each of the following sentences into sentences of propositional logic. (i) Only one of the three teams – Australia, England and South Africa – will win the gold medal. (ii) If any of the three teams – Australia, England and South Africa – wins the gold medal, Australia will. Use the following scheme of abbreviation: A: The Australian team will win the gold medal E: The English team will win the gold medal S: The South African team will win the gold medal QUESTION 1 (a) (3 marks) Translate the following ﬁrst-order sentences into English: (i) ∀x (banknote(x) → has watermark(x)) (ii) ∀x ∃y (person(x) → f ather(y, x)) (iii) ∃x ∀y (person(x) ∧ f ather(x, y)) where person(x) means “x is a person” f ather(x, y) means “x is the father of y” banknote(x) means “x is a banknote” has watermark(x) means “x has a watermark” (b) (2 marks) Convert the following English sentences into sentences of ﬁrst-order logic. (i) All dog owners are animal lovers. (ii) No animal lover kills an animal. Use meaningful predicate names or state the translation scheme you are using. (c) (2 marks) Brieﬂy describe what is meant by the syntax and by the semantics of a logic. QUESTION A2. (First-Order Logic) (12 marks) (a) (2 marks) Translate the following ﬁrst-order sentences into idiomatic English: (i) ∀x (F rog(x) → (P oisonous(x) → Colourf ul(x))) (ii) ∀x ¬∀y¬ (F rog(x) → (F rog(y) ∧ M ore poisonous(y, x))) where F rog(x) means “x is a frog” M ore poisonous(x, y) means “x is more poisonous than y” P oisonous(x) means “x is poisonous” Colourf ul(x) means “x is colourful” QUESTION 2 (9 marks) Consider the following argument: There are no compassionate professors. All competent profesors are compassionate. Therefore no competent professors exist. The ﬁrst two formulas are premises of the argument, and the last formula is the conclusion. • Translate the argument into predicate logic. (3 marks) Use the following vocabulary: S(x): x is compassionate. P(x): x is competent. • Show, using the resolution method, that the conclusion follows from the premises. (6 marks) QUESTION 1 (10 marks) Consider the following argument in predicate logic: 1. (∀X)(∀S)(¬on(S) →at(box,X,pushbox(X,S))) 2. (∀S) on(climbbox(S)) 3. (∀S)((on(S)∧at(box,c,S)) →hb(grasp(S))) 4. (∀X)(∀S)(at(box,X,S) →at(box,X,climbbox(S))) 5. ¬on(s0) 6. (∃S) hb(S) The ﬁrst ﬁve formulas are premises of the argument, and the last formula is the conclusion. Show, using the resolution method, that the conclusion follows from the premises. QUESTION 1 (6 marks) Consider the following argument: A parent of a parent of someone is his/her grandparent. Everyone has a parent. Therefore someone has a grandparent. 2 The ﬁrst two formulas are premises of the argument, and the last formula is the conclusion. (a) (2 marks) Translate the argument into ﬁrst-order (predicate) logic. Suppose that the domain of discourse is people (quantiﬁers range over people). In your translation, use the following vocabulary: p(X,Y): X is Y’s parent. g(X,Y): X is Y’s grandparent. (b) (4 marks) Show, using the resolution method, that the conclusion follows from the premises. QUESTION A1. (general) Each question is of equal value. Give short answers (1 - 2 sentences). (a) What is the main diﬀerence between logic programming and imperative programming? (b) Translate the following statement into ﬁrst-order (predicate) logic: There is a rational number between any two given rational numbers. (c) Translate the following statement into ﬁrst-order (predicate) logic with equality:There are at least two red things. (d) Why doesn’t an analogue of the truth table method work to show the validity of statements in ﬁrst-order logic? (e) Why is the resolution method a refutation procedure? (f ) What is the occur’s check? (g) Give an example Prolog program that has exactly two answers to a given goal. (Show both the program and the goal.) (h) Consider the cut operator (!) in Prolog. What is the main diﬀerence between red cuts and green cuts? QUESTION A2. (logic) (5 marks) Prove whether the following are fallacies or rules of inference (valid reasoning). Note that → is the implication connective, ¬ is the negation connective. (a) (3 marks) Law of the syllogism p→q ¬q ∨ r ¬p ∨ r (b) (2 marks) Law of disjunctive inference 3 p∨q ¬p q QUESTION A3. (resolution method) (9 marks) Consider the following argument: No employer who is either inconsiderate or tyrannical can be successful. Some employers are inconsiderate. There are only tyrannical employers. Therefore no employer can be successful. The ﬁrst three formulas are premises of the argument, and the last formula is the conclusion. (a) (3 marks) Translate the argument into ﬁrst-order (predicate) logic. Suppose that the domain of discourse is the employers (quantiﬁers range over the employers). In your translation, use the following vocabulary: I(x): x is inconsiderate. S(x): x is successful. T(x): x is tyrannical. (b) (6 marks) Show, using the resolution method, that the conclusion follows from the premises. 4 PROLOG PROGRAMMING QUESTION B1. (4 marks) Lucas sequence is similar to Fibonacci sequence of numbers, except the ﬁrst two terms are 1 and 3, and each subsequent term is the sum of the previous two terms; so the sequence goes 1, 3, 4, 7, 11, ... Write the predicate lucas(N, Value) which calculates the Nth term in the Lucas sequence. QUESTION B2. (6 marks) We can represent a family tree using the parent predicate, where parent(tom, bob) indicates that Tom is the parent of Bob. Deﬁne a new predicate called cousin(X, Y) which would ﬁnd the cousins of X. Hint: Your cousins are the people in your family who have the same grandparent as you. Your grandparents are the people who are the parents of your parents. You cannot be your own cousin, and your brother or sister cannot be your cousin either. QUESTION 2 (7 marks) a) (3 marks) Determine whether or not the following pairs of literals can be uniﬁed using uniﬁca- tion (with occur’s check). For each pair of literals, if the literals are uniﬁable, ﬁnd a most-general uniﬁer (substitution) for them; if they are not uniﬁable, give the reason. • p([a,[b],[c]]) p([X|[Y|[Z]]]) • r(X,f(X),f(g(Y))) r(g(Y),Z,f(g(Z))) • p([a,[[b,X]]]) p([Y,[Z]|T]) • r(X,f(X)) r(g(Y),Y) b) (4 marks) Assume the following speciﬁcation of the append predicate: append([],L,L). % app.1 append([H|T],L,[H|R]) :- append(T,L,R). % app.2 Given the goal ?- append(A,B,[1,2]), draw the corresponding search (proof) tree. Annotate each successful branch with the corresponding answer substitutions for A and B. QUESTION A4. (Prolog programming) (12 marks) You may use the following predicates in your answers to questions A4-5. append([],L,L). append([H|T],L,[H|R]) :- append(T,L,R). member(X,[X|_]). member(X,[_|T]) :- member(X,T). delete(X, [X|T], T). delete(X, [H|T], [H|L]) :- delete(X, T, L). Provide the speciﬁcations of the following predicates in Prolog: 5 (a) (3 marks) delete_all(X,L1,L2) is true if the list L2 is just like the list L1 with all occurrences of the element X removed from it. Examples: ?- delete_all(1,[1,2,3,1,1],L). L = [2,3] (b) (3 marks) remove_duplicates(L1,L2) is true if the list L2 is just like the list L1 with all the duplicate elements in L1 removed Examples: ?- remove_duplicates([1,2,1,1,2,3,4,4], L). L = [1,2,3,4] QUESTION 3 (8 marks) a) Assume the speciﬁcation of the append predicate given in question 2-b) above. Provide the speciﬁcations of the following predicates: • (2 marks) adjacent(X, Y, L) is true if X and Y appear side by side in list L (they are adjacent in the list). Provide the speciﬁcation of adjacent in terms of append. Examples: ?- adjacent(2,3,[1,2,3,4]). yes ?- adjacent(3,2,[1,2,3,4]). yes • (3 marks) flatten(L1,L2) is true if L2 is a list containing all the constants appearing in list L1 and no other. Example: ?- flatten([[1],2,[3,[4]]],L). L = [1,2,3,4] b) We can represent a tree structure using a ternary functor, say tree, as follows: • an empty tree: []. • a tree node: tree(L,V,R) where L and R are the left and right subtrees of the tree rooted at the node, and V is the value for the node. The term tree(tree([],1,[]),2,tree(tree([],3,[]),4,tree([],5,[]))) represents the fol- lowing tree structure: T1 2 1 4 3 5 Provide the speciﬁcation of the following predicate: 6 • (3 marks) flip(T1,T2) is true if T1 and T2 are trees such that T2 is just like T1 with the left and right subtrees of each node in T1 ﬂipped (swapped). For example, let T1 represent the tree given above and T2 represent the tree tree(tree(tree([],5,[]),4,tree([],3,[])),2,tree([],1,[])): T2 2 4 1 5 3 Then flip(T1,T2) is true. QUESTION B3. (4 marks) The following Prolog program gives unexpected answers for Query-1 and Query-2. Decide if the program is logically sound, show how the queries would be represented in Prolog and explain the answers for the queries. You might want to use a proof tree, or describe what would happen if trace was being used to make your explanation clear. % X is atwork is X is not at home % Tom is at home % Pam is Tom’s wife. % % Query-1: Is pam at work, we get Yes % Query-2: Is anybody at work, we get No atwork(X) :- not(athome(X)). athome(tom). wife(pam, tom). QUESTION A5. (solving puzzles) (9 marks) Write a Prolog program to solve the following puzzle. You may use any predicate speciﬁed/given in the previous questions. You must specify any extra predicate(s) you use. Note: • Use the clues in the given order in your program; • Clearly document which part of your program corresponds to which clue. • Try to use the best data structure for the solution to the puzzle. • Avoid the use of numerical constraints in the clues (except clue 3 in which you can use numerical constraints to identify odd-numbered drawers). • Full marks will NOT be gained by just having a correct solution. Clarity, conciseness and eﬃciency will also be taken into account. • Do not use cut (!), or (;) and not (\+). % S O M E W H E R E S A F E % ___________________________ % % Logic Problems Issue 16 page 21 7 % % The diagram represents a typical all-purpose chest of drawers filled with % a variety of small household objects. From the clues given below, can you % work out in which drawer each of the items is? % % +----------------------------------------------------+ % | | % | +-------------------+ +-------------------+ | % | | [1] | | [4] | | % | +-------------------+ +-------------------+ | % | | % | +-------------------+ +-------------------+ | % | | [2] | | [5] | | % | +-------------------+ +-------------------+ | % | | % | +-------------------+ +-------------------+ | % | | [3] | | [6] | | % | +-------------------+ +-------------------+ | % | | % +----------------------------------------------------+ % % Clues: % 1. The stationery is in a left-hand drawer. % 2. The playing-cards are immediately above the table-mats. % 3. The fish knives are in an odd-numbered drawer and the pins and needles % are immediately below them. % 4. The photos are not in a top drawer. QUESTION A3. (solving puzzles) (10 marks) Write a Prolog program to solve the following puzzle. You may use any predicate given above in the previous questions. You must specify any extra predicate(s) you use. % T H A T ’ L L T E A C H Y O U ! % _____________________________________ % % St Boniface’s primary school has six classes, the youngest pupils % being in class 1 and the oldest in class 6. From the clues given below, % can you determine the name and age of the teacher in charge of each class? % % Class Teacher Age % ---------------------------- % | 1 | | | % ---------------------------- % | 2 | | | % ---------------------------- % | 3 | | | % ---------------------------- % | 4 | | | % ---------------------------- % | 5 | | | % ---------------------------- % | 6 | | | % ---------------------------- % % % Clues: % 8 % 1. Miss Chance is five years younger than the teacher of class 4. % 2. Miss Teake became very attached to her last year’s class and % was reluctant to hand them over at the beginning of this school year % to the 22-year old; on the other hand, the 33-year old was only % too glad to hand her lot over to Miss Fitt, who is not % the oldest teacher. % 3. The teacher of class 2 is younger than Miss Chance by as much as % the teacher of class 3 is younger that Miss Mashe; this is not % a difference of 13 years. % 4. The combined age of Miss Laye and the teacher of class 1 % is equal to that of the teacher of class 6 and Miss Deedes. % % Names: Chance, Deedes, Fitt, Laye, Mashe, Teake % Ages: 22, 27, 33, 38, 46, 51 % Note: • Use the clues in the given order in your program; • Clearly document which part of your program corresponds to which clue. • Try to use the best data structure for the solution to the puzzle. • Full marks will NOT be gained by just having a correct solution. Clarity, conciseness and eﬃciency will also be taken into account. • Do not use cut (!), or (;) and not (\+). 9 AI TECHNIQUES Section C. Short Answer Questions • In evaluating a problem solving method, what are some of the important criteria to consider? • State the relative advantages and disadvantages of breadth-ﬁrst search and depth-ﬁrst search as problem solving methods. • Brieﬂy state the diﬀerence between blind search methods and heuristic search methods. • What is meant by the term heuristic in problem solving? Give an example. • What is meant by the term admissibility of the A∗ algorithm? • What is the meaning of the minimax value calculated for a game tree? • What is the purpose of the alpha-beta pruning algorithm? QUESTION A4. (Search) (10 marks) (a) (5 marks) For the following search strategies, list the order in which nodes are expanded in the state graph below, starting with node 1. Where there is a choice of which node to expand, choose that on the leftmost branch ﬁrst. (i) Depth-limited search (with a limit of 3). (ii) Lowest-cost ﬁrst (that is, uniform-cost) search (use the edge costs given in the state graph to determine path costs) 1 3 1 2 3 2 1 0 -2 4 5 6 7 10 4 5 8 9 10 Evaluate the lowest-cost ﬁrst strategy using the four criteria: (i) completeness, (ii) optimal- ity, (iii) time complexity, and (iv) space complexity. State your assumptions (if any) in your evaluation and explain your answers. (b) (5 marks) Consider the following arrangement of tiles in the 8-puzzle: 1 2 3 6 7 8 5 4 10 keeping in mind that the goal state is 1 2 3 8 4 7 6 5 (i) Consider the following heuristic: The weight of each tile is its number (1, 2, 3, · · ·, 8). For any given arrangement of tiles, the heuristic value then is the sum of the weights of the tiles out of place. Apply this heuristic function to the initial arrangement of tiles given above. Is this heuristic admissible (explain your asnwer)? (ii) Using this heuristic, apply the A∗ heuristic search algorithm to ﬁnd a solution to this puzzle (show your working to a depth of ﬁve only). QUESTION C3. (5 marks) Consider the following initial state and the goal state in the 8-puzzle: 1 2 3 1 2 3 6 7 =⇒ 8 4 8 5 4 7 6 5 (i) Suppose that we are given an admissible heuristic function h1 which is based on the sum of Manhattan distances. Apply h1 to both states given above. (ii) Suppose that we are given another admissible heuristic h2 which we cannot show performs better or worse than h1 . That is, we cannot show that either heuristic is always closer to the actual cost of a path to a goal node than the other. Devise a new heuristic, using both of h1 and h2 , that performs better than either of them. QUESTION C1. (8 marks) Suppose that we combine iterative deepening search with the uniform cost (lowest-cost) ﬁrst search. We try all possible depth limits: ﬁrst depth 0, then depth 1, then depth 2 and so on. At each depth limit, we apply the lowest-cost ﬁrst search up to that depth. Assume that, at any stage of search, nodes that have already been explored (visited) are not explored again. This assumption does not include nodes that are still in the frontier. Assume that, for any generated node, the information about the lowest-cost path from start node to that node is also kept. Apply this search to the state graph given below. Show the order in which nodes are explored starting with node a as the initial node. Use the edge costs given in the graph to determine path costs. When there is a choice of which frontier node to explore (that is when two or more nodes have the same cost), choose that on the leftmost branch ﬁrst. a 5 16 c 10 5 b 1 5 0 d 7 e f 2 3 g 7 11 Evaluate this new search strategy using the four criteria: (i) completeness, (ii) optimality, (iii) time complexity, and (iv) space complexity. State your assumptions (if any) in your evaluation and explain your answers. QUESTION C2. (5 marks) Suppose that we run a greedy (best-ﬁrst) search strategy with h(n) = −g(n) where h(n) is the heuristic value of node n and g(n) is the actual cost of the path from an initial node to node n. What can you say about this heuristic function? What sort of search does the greedy search emulate with this heuristic function?Show the order in which the greedy search will expand the nodes in the state graph given in question C1, with initial node a and goal node g. QUESTION C1. (8 marks) Consider a ﬁnite tree of depth d and branching factor b. (A tree consisting of only a root node has depth 0; a tree consisting of a root node and its b successors has depth 1; etc) Suppose the shallowest goal node is at depth g < d. (a) What is the minimum and maximum number of nodes that might be generated by a depth-ﬁrst search with depth bound equal to d? (b) What is the minimum and maximum number of nodes that might be generated by a breadth- ﬁrst search? 12 QUESTION B4. (Reasoning Under Uncertainty) (a) (1 mark) Describe one commonly held view as to what probability numbers mean. (b) (2 marks) Suppose you have the following information: Inﬂuenza causes headache 70% of the time. 1 The chance of a patient having inﬂuenza is 20000 . 1 The chance of a patient having a headache is 1000 . Determine the conditional probability of a patient suﬀering from inﬂuenza given they have a headache (i.e., P (Inf luenza|Headache)). QUESTION C3. (4 marks) After your yearly checkup, the doctor has bad news and good news. The bad news is that you tested positive for a serious disease, and that the test is 99% accurate (i.e., the probability of testing positive given that you have the disease is 0.99, as is the probability of testing negative given that you don’t have the disease). The good news is that this is a rare disease, striking only one in 10,000 people. Why is it good news that the disease is rare? What are the chances that you actually have the disease? That is, compute the conditional probability P (Have disease|Tested positive). QUESTION C4. (5 marks) The belief network shown below formalizes the following situation: you have a new burglar alarm installed at home. It is fairly reliable detecting a burglary, but also responds on occasion to minor earthquakes. You also have two neighbours, John and Mary, who promised to call you at work when they hear the alarm. John quite reliably calls when he hears the alarm, but sometimes confuses the telephone ringing with the alarm and calls then too. Mary, on the other hand, likes rather loud music and sometimes misses the alarm altogether. Burglary P(Burglary) Earthquake P(Earthquake) 0.001 0.002 Burglary Eartquake P(Alarm) Alarm True True 0.95 True False 0.94 False True 0.29 False False 0.001 JohnCalls MaryCalls Alarm P(JohnCalls) Alarm P(MaryCalls) True 0.90 True 0.70 False 0.05 False 0.01 Calculate the joint probability that both John and Mary call, there is no alarm and that there is neither an earthquake nor a burglary: P (JohnCalls ∧ MaryCalls ∧ ¬Alarm ∧ ¬Burglary ∧ ¬Earthquake). 13 QUESTION B4. (Reasoning Under Uncertainty) (5 marks) (a) (1 mark) Show how to derive Bayes’ Rule from the product rule P (A ∧ B) = P (A|B).P (B). (b) (1 mark) Describe one commonly held view as to what probability numbers mean. (c) (1 mark) Suppose you have the following information: Measles causes fever 80% of the time. 1 The chance of a patient having measles is 20000 . 1 The chance of a patient having a fever is 1000 . Determine the conditional probability of a patient suﬀering from measles given they have a fever (i.e., P (M easles|F ever)). (d) (2 marks) Consider the following belief network. Determine the joint probability P (A, B, C, D) (show your working). P(B) P(D) B 0.95 D 0.7 A C B P(A) B D P(C) T 0.95 T T 0.9 F 0.1 T F 0.05 F T 0.0 F F 0.0 14