This week, we continue our work with Prolog using Learn Prolog Now! and SWI Prolog.
As one would imagine, Prolog supports recursion, lists and arithmetic.
Do the following exercises.
Does Prolog implement a version of generalized modus ponens? If so, demonstrate how it’s done; if not, explain why not. If it doesn’t, can you implement one? Why or why not?
Have you ever seen anything similar to the “successor” rule discussed in LPN!’s Chapter 3.1, Example 3? Where? What was it used for?
Be sure that you can explain how you built your system and how Prolog does recursion.
As time allows, try the following extensions to the first exercises.
Extend the LPN! exercises above as follows.
?- in(katarina, olga, L). L = contains(katarina, olga) ?- in(katarina, irina, L). L = contains(katarina, olga, contains(olga, natasha, contains(natasha, irina)))
These examples produce a “stack trace” of the recursive executation. The first example is a base case, the second a recursive case.
?- listtran3([eins,zwei],2,X). X = [one, two] ?- listtran3([eins,zwei],3,X). X = [yi, er]. ?- listtran3(X,3,[yi, er]). X = [eins, zwei]. ?- listtran3(X,2,[one, two]). X = [eins, zwei].
Simple extensions of your original code will likely only support these language pairs; you don’t need to support Chinese-English translations.
addN/3
predicate that
adds an arbitrary value to each list element as specified by a
numeric parameter.
?- addN([1,2,3],2,X). X = [3, 4, 5].
Submit the files specified above in Moodle under lab 12.