Suggested answers

advertisement
Suggested answers
This document contains suggested answers to selected questions from the exam in TDDC65
Artificial Intelligence and Lisp from 2008-08-23.
Question 1: Lisp programming (10p)
1a (3p) We have created a variable things with information about some objects. What will
the Lisp interpreter return if we enter the following three expressions (exactly as stated) with
labels 2-4 in the example?
CL-USER(1): (setq things '(table chair (box pencil eraser)))
(TABLE CHAIR (BOX PENCIL ERASER))
CL-USER(2): (length things)
3
CL-USER(3): (append '(things) (third things))
(THINGS BOX PENCIL ERASER)
CL-USER(4): (cons 3 (* 2 7))
(3 . 14)
1b (3p) Write a Lisp function locate that checks if an atom (symbol or number) is present in
a list. Assume that the list does not contain sublists. The function should return T or NIL. The
following examples show how the function should work:
(defun locate (e seq)
(cond ((endp seq) nil)
((eq e (first seq)) t)
(t (locate e (rest seq)))))
1c (3p) Write a Lisp function locate-all that is a more generic version of the previous
function. The second argument should be a predicate function to be applied to all elements.
You should also assume that the list might contain sublists, and process them as well. The
function locate-all should return T if the predicate returns T for at least one element,
otherwise NIL. Here are some examples:
(defun locate-all (pred seq)
(cond ((endp seq) nil)
((atom (first seq))
(if (funcall pred (first seq))
t
(locate-all pred (rest seq))))
(t (or (locate-all pred (first seq))
(locate-all pred (rest seq))))))
1d (1p) What should we give as first argument to locate-all in order to find out if the list
contains an integer (not a float) greater than or equal to 100?
CL-USER(10): (locate-all #'(lambda (x) (and (integerp x) (>= x 100)))
'(a b 150.5 c 99 (d 102 e)))
T
Question 2: Logic (12p)
2a (2p) Construct a truth table for the following formula:
(P ∨ Q) ∧ R
P
0
0
0
0
1
1
1
1
Q
0
0
1
1
0
0
1
1
R
0
1
0
1
0
1
0
1
P∨Q
0
0
1
1
1
1
1
1
(P ∨ Q) ∧ R
0
0
0
1
0
1
0
1
2b (2p) Is the formula in 2a satisfiable? Is it valid? Motivate your answer using the truth table.
Yes, it is satisfiable, since there are at least one row in the truth table that is true for the
whole formula. No, it is not valid, since there are rows in the truth table are false for the
whole formula.
2c (2p) Prove the following equivalence in a suitable way:
¬(R ∧ ¬S) ≡ R ⇒ S
This can be proven either by truth tables or by rewriting.
2d (2p) We have a small and very simple ground moving robot. In every situation there are
only three possible actions for the robot: move 1 dm forward, turn right 90° or turn left 90°.
The robot has two sensors. A proximity sensor tells us if there is an object immediately in
front of the robot and a radio sensor tells us if a desired target is somewhere in a 75° sector in
front of the robot. The software controlling the robot has a knowledge base with the following
rules:
A reading from the proximity sensor can only mean that there is an obstacle in front of
the robot.
The robot should go forward if the target is in front and there are no obstacles.
If there is an obstacle in front, the robot should turn right.
If no other action is possible, the robot should turn left.
At a given situation the proximity sensor does not give a reading, but the target seems to be
close by. Translate the knowledge base and the sensor data in this situation into suitable
formulas in propositional logic.
P = There is a reading from the proximity sensor.
O = There is an obstacle in front of the robot.
T = There is a target in front of the robot.
F = The robot should go forward.
R = The robot should turn right.
L = The robot should turn left.
1.
2.
3.
4.
5.
P⇔O
T ∧ ¬O ⇒ F
O⇒R
¬R ∧ ¬F ⇒ L
¬P ∧ T
2e (1p) Which action should the robot take in this situation? Use informal reasoning to find a
conclusion.
Since we don’t get a reading from the proximity sensor, there cannot be an obstacle in
front of the robot, and since there is also a target in front, we should go forward.
2f (3p) Prove your claim from the previous question using resolution.
The hypothesis is that the robot should go forward (F). In order to prove this using
resolution, we first have to negate the hypothesis and convert this formula and all other
formulas to CNF. Then we can do resolution on the clauses.
6. ¬P ∨ O
7. ¬O ∨ P
8. ¬T ∨ O ∨ F
9. ¬O ∨ R
10. R ∨ F ∨ L
11. ¬P
12. T
13. ¬F
14. ¬T ∨ O
15. O
16. P
17. ⊥
formula 1 as CNF (one direction)
formula 1 as CNF (the other direction)
formula 2 as CNF
formula 3 as CNF
formula 4 as CNF
formula 5 as CNF (first clause)
formula 5 as CNF (second clause)
negated hypothesis
8 + 13
12 + 14
7 + 15
11 + 16
Question 3: Search (8p)
3a (2p) Search strategies differ in the order in which nodes are selected for expansion. We can
easily write a generic search algorithm (which is done in pseudo code in the book) and simply
switch between different ways of inserting new nodes into the queue. What is the difference
between depth first and breadth first search and how does the insertion of new nodes differ
between these algorithms?
Breadth first is implemented with a (FIFO) queue and depth first is implemented with a
stack (sometimes called a LIFO queue). For more discussion see chapter 3.4.
3b (2p) In what ways can we measure problem-solving performance for a search strategy?
Explain in a few words each category.
Completeness, optimality, time complexity and space complexity. See chapter 3.3.
3c (4p) The search tree can look like this:
4
4
4
3
3
2
2
3
2
1
3
1
0
Download