?- type(l-o-g-i-c,X). X = l-o-g-i-c ; X = k-i-g-u-c ; X = ö-p-g-o-c ; X = l-o-f-i-x ; X = k-i-f-u-x ; X = ö-p-f-o-x ; X = l-o-h-i-v ; X = k-i-h-u-v ; X = ö-p-h-o-v ; false.Ideally the program works also backwards.
?- type(X,k-i-g-u-c). X = l-o-g-i-c ;Hint: Decide the direction of substraction (xfy – from left to right – or yfx – from right to left) and write the corresponding op-command at the beginning of your program.
?- flower(1). ( ) ( )@( ) ( ) | \|/ true . ?- flower(2). ( ) ( )@@( ) ( )@@( ) ( ) || || \\||// true .Hint: ASCII flower gallery.
?- similar_registration_numbers('334MMM','333BMW',Cs,N). Cs = ['3', '3', 'M'], N = 3. ?- similar_registration_numbers('333BMW','334MMM',Cs,N). Cs = ['3', '3', 'M'], N = 3. ?- similar_registration_numbers('123ABC','345DEF',Cs,N). Cs = ['3'], N = 1.Hint: Use system predicate atom_chars/2 to transforms a word into the list of its characters.
?- idcode([3,4,5,0,1,2,3,4,2,1,5],). true. ?- idcode([3,4,5,0,1,2,3,4,2,1,5,5],). false. ?- idcode([3,4,5,0,1,2,3,4,2,1,5,5],X). X = .Hint: See Lecture 4 slides 25–26.
In a company there are working Max, Nick, Oscar and Peter. There agencies are: engineer, boss, cashier and storeman (but not necessarily in that order). Find each agency, as it is known the following facts.
?-solve(X).Hint: See Lecture 5 slides 16–23 (three friends).
?- equation(X + 2 = 5). X = 3. ?- equation(2 - 3.5 = Dif). Dif = -1.5.Hint: See Lecture 3 slides 9–10 (operators: type declarations, example).
?-truthtable(connectives, a and b or not c, 'table.html'). a b c | a and b or not c ------------------------- t t t | t t f t t f | t t t ... ?-truthtable(a and b or not c). a b c | a and b or not c ------------------------- t t t | t t t f | t ...Hint: Define logical connectives using command op/3 at the beginning of program.
Note: You can improve the solution during one week (add connectives, calling parameters, css-style, modify the basic structures, html-layout etc).
?- dr_google. Dr. Google: Any problems. Patient: I have sore throat and cough. Dr. Google: Do you have also headache, muscle pains and high fever. Patient: Yes. Dr. Google: You have flu, please go to your GP and she will assign you a sick note. true.Hint: The program should contain lists of symptoms, diseases and doctors and also relations between the entities. The relations can be built as Prolog rules or tables of dependencies.
Note: The interaction between the doctor and patient can be conducted in different ways — yes/no questions, multiple choise questions or answers in natural language. Please keep the dialogue as simple as possible.
?- triple([the,cat,chase,the,mouse],X). X = [cat,chase,mouse].Note: Try to write a definite clause grammar (see Lecture 8 slide 13).
Note: Use WordNet dictionary (wn_s.pl, estwn_s.pl).
:-[wn_s].Note: The sentences can be read from a preprocessed text file 'sentences.pl'. Preprocessing translates the sentences into Prolog readable terms sentence/1 and normalizes the words if needed.
:-[sentences]. ?- sentence(X), triple(X,Y).
[all,trees,are,green]or a Prolog term
?- logic_engine([there,are,trees,in,the,park],[all,trees,are,green],X). X = [trees,in,the,park,are,green]. ?- logic_engine([there,are,birds,in,the,park],[all,trees,are,green],X). false.
Use depth-first and breadth-first search strategies to find all solutions to the problem. For example
?- search(depth-first,Path). Path = [(2,0),...,(4,3),(4,0),(0,0)] ; ... ?- search(breadth-first,Path).Hint: See Lecture 5 slides 8–15 (monkey and banana). Avoid cycles.
?- cs_thesis('html',Thesis). Thesis = ['Tähepõld', 'Tanel', 'Context-Aware Mobile Games Using Android, Arduino and HTML5', '2012'] ; Thesis = ['Tõnisson', 'Kaarel', 'Mechanism for Change Detection in HTML Web Pages as XML Documents', '2015'] ; false. ?- cs_thesis('tõn',Thesis). Thesis = ['Tasa', 'Tõnis', 'Re-using public RNA-Seq data', '2015'] ; Thesis = ['Jaarma', 'Tõnu', 'Review of object oriented parallel programming framework Charm++', '2012'] .Hint: Use SWI-Prolog libraries http_open and xpath.
Hint: See Sterling & Shapiro "The art of Prolog", Bratko "Prolog programming for AI", Jaak Henno "Loogiline programmeerimine".