Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. This Prolog exercise is concerned with book, libraries and selection of books

ID: 3657602 • Letter: 1

Question

1. This Prolog exercise is concerned with book, libraries and selection of books. A book is represented as a structure of the form book (author, title, no-of-pages, category) The following are examples of structures that represent books: book(negnevitski, artificialIntelligence, 415, study) book(dumas, musqueteers, 777, justFun) A library is represented as a list of such book representations; example: book(sayers, artificialIntelligence, 288, detective) book(negnevitski, artificialIntelligence, 415, study) book(nerdson, smartAlgorithms, 465, study) book(sayers, someOtherTitle, 194, detective) book(nerson, musqueteers, 777, justFun) Write a Prolog file that has list of books as given in the above example. Then write queries to find - all books written by sayers, - all books on artificialIntelligence, - all books on detective category and written by sayers.

Explanation / Answer

% 3.03 (**) Truth tables for logical expressions (3). % Generalize problem P47 in such a way that the logical % expression may contain any number of logical variables. % % Example: % ?- table([A,B,C], A and (B or C) equ A and B or A and C). % true true true true % true true fail true % true fail true true % true fail fail true % fail true true true % fail true fail true % fail fail true true % fail fail fail true :- ensure_loaded(p3_02). % table(List,Expr) :- print the truth table for the expression Expr, % which contains the logical variables enumerated in List. table(VarList,Expr) :- bindList(VarList), do(VarList,Expr), fail. bindList([]). bindList([V|Vs]) :- bind(V), bindList(Vs). do(VarList,Expr) :- writeVarList(VarList), writeExpr(Expr), nl. writeVarList([]). writeVarList([V|Vs]) :- write(V), write(' '), writeVarList(Vs). writeExpr(Expr) :- Expr, !, write(true). writeExpr(_) :- write(fail).