% Solution to EE 4785 1996 Final Exam % This file can be read by C-Prolog. % % Problem 1 % % First, get a special case out of the way. order([],'Undefined'). % % The main clause: doesRepeat finds the smallest repeating list and % lengthOf determines its length. % order(List,Length):- doesRepeat(SubList,List), % Get smallest repeating sublist. lengthOf(SubList,Length). % Determine its length. % % doesRepeat(SubList,List) % % succeeds if List consists of repeated occurrences of SubList. % SubList may or may not be bound. If it's not bound then split % will bind it to the first one or more elements of List, otherwise % split verifies that List starts with SubList. Either way, split % extracts the remainder of List, RestList, for a recursive call. % doesRepeat(SubList,List):- split(SubList,RestList,List), % Split List into SubList and RestList. doesRepeat(SubList,RestList). % Check if RestList consists of Sublists. doesRepeat(_,[]). % End recursion when list empty. % % split(Left,Right,Whole) % % Splits list Whole into two parts, Left, a non-empty list, and Right. % (This is similar to append, except that in append Left could be an empty % list.) % split([Left],Right,[Left|Right]). split([H|Left],Right,[H|Whole]):- split(Left,Right,Whole). % % lengthOf(List,Length) % % Determines the length of List. % lengthOf([],0). lengthOf([_|T],C):- lengthOf(T,CTail), C is CTail+1. % % Problem 2 % % The file shellOAVbc.pro should be in the class directory. :-['shellOAVbc.pro']. % Solution to Problem 2: r1:if thereExist(S:.isa=stock, ( S:.cost=C and C<5 and S:.numInStock=N and N>0) ) then cheapBook:=S. r2:if thereExist(S:.isa=stock, ( S:.cost=C and C<5 and S:.title=T and S:.numInStock=N and N>0 and thereExist(B:.isa=book, ( B:.title=T and B:.binding='Hardcover' ) ))) then cheapHardCover:=S. r3:if forAll(B:.isa=book, B:.series='Dilbert', ( B:.title=T and thereExist(S:.isa=stock, S:.title=T and S:.numInStock=N and N>0) ) ) then haveAllDilbertBooks. % Sample run: % | ?- deduce(haveAllDilbertBooks,X). % % X = true % % yes % | ?- deduce(B=cheapBook and T=B:.title,_). % % B = stock3 % T = Instant Expert Systems % % yes % | ?- deduce(B=cheapHardCover and T=B:.title,_). % % B = stock2 % T = More Poetry % % Sample data for above rules. data(book1,isa,book,init). data(book1,title,'Nontrivial Expert Systems',init). data(book1,series,'Computer Science',init). data(book1,binding,'Hardcover',init). data(book2,isa,book,init). data(book2,title,'Instant Expert Systems',init). data(book2,series,'Computer Solutions',init). data(book2,binding,'Paperback',init). data(book5,isa,book,init). data(book5,title,'More Poetry',init). data(book5,series,'Un-Ending Verse',init). data(book5,binding,'Hardcover',init). data(book3,isa,book,init). data(book3,title,'You wont survive by your wits alone',init). data(book3,series,'Dilbert',init). data(book3,binding,'Paperback',init). data(book4,isa,book,init). data(book4,title,'The Dilbert Principle',init). data(book4,series,'Dilbert',init). data(book4,binding,'Paperback',init). data(stock1,isa,stock,init). data(stock1,title,'Nontrivial Expert Systems',init). data(stock1,cost,95.97,init). data(stock1,numInStock,1,init). data(stock3,isa,stock,init). data(stock3,title,'Instant Expert Systems',init). data(stock3,cost,4.95,init). % Wow! Includes floppy disk! data(stock3,numInStock,10,init). data(stock2,isa,stock,init). data(stock2,title,'More Poetry',init). data(stock2,cost,2.99,init). data(stock2,numInStock,20,init). data(stock4,isa,stock,init). data(stock4,title,'You wont survive by your wits alone',init). data(stock4,cost,6.95,init). data(stock4,numInStock,10,init). data(stock5,isa,stock,init). data(stock5,title,'The Dilbert Principle',init). data(stock5,cost,6.95,init). data(stock5,numInStock,10,init). % There are more books in the Dilbert series. % % Problem 3 % % Given: % H1 Car problems. % H2 Away for a reason. % H3 Weather. % % E1: Car acting strangely. % E2: Tow truck. % E3: Owns an unreliable car. % % E4: Vacation. % E5: Lunch. % % E6: Storm. % E7: Left at time of possible storm. % E8: Lives across river. % % Rules % % Since H1 could occur with any E1-E3 and two would make H1 more % likely the evidence should be combined with the co-combining % rule. The co-combining rule combines antecedents of rules, so: % % if E1 then H1. % if E2 then H1. % if E3 then H1. % % Since evidence E4 and E4 known with certainty and only one can be true: % % if E4 or E5 then H2. % % Since all three pieces of evidence are necessary for H3: % % if E6 and E7 and E8 then H3. % % Problem 4a % % thematic_role_frame1 isa thematic_role_frame % agent: John % thematic object: ball % destination: Jack % verb: throw % % pa_throw1 isa pa_action % primitive: throw % agent: John % object: ball % destination: Jack % % Problem 4b % % Since "mail" is a primitive action, the ES would "know" about the % mailing process. For example, the ES might understand that mailing % requires a container for the ball, stamps, a trip to a mailbox or % post office, and at least a one-day wait before Jack receives the % ball. % % With primitive action frames an ES might estimate when Jack would % receive the ball. % % Problem 4c % % Linguistic modifiers alter a membership function, this function maps % elements, which have to be numbers, to the unit interval, the % element's membership. Elements of the set of speeds are numbers, so % linguistic modifiers are possible. However, elements of the set of % movies aren't numbers, so the membership function would map some other % type of element (e.g., the movie titles) to the unit interval. It % would be no problem, on the other hand, to provide linguistic % modifiers for S, the set of good movie ratings, where an element of % the set is the number of starts given by a reviewer. % % % Problem 4d % :-op(500,xfx,slots). :-op(400,xfy,ako). :-op(400,xfx,isa). car ako roadVehicle ako personalProperty slots [ [airbag, true], [numCupHolders, 5]]. car1 isa car slots [ [brand, gm], [color, arrestMeRed]]. % Syntax error since isa appears twice. % % car1 isa car isa property % slots [ % [brand, gm], % [color, arrestMeRed]].