Commit 9545459f authored by Sandra Dylus's avatar Sandra Dylus
Browse files

Merge branch 'master' of git.informatik.uni-kiel.de:sad/advanced-programming-ws19

parents 406b6003 e31cafea
#!/bin/bash
function fillIddfsFile {
(cat | base64 --decode > "$TMP_DIR/$IDDFS_FILE") << EOF
Oi0gbW9kdWxlKCBmb3J0cHJvZwogICAgICAgICAsIFsgaWRkZnNfYXNzZXJ0SWZOb3RFeGlzdHMv
MQogICAgICAgICAgICwgaWRkZnNfbWF4TGlzdC8yCiAgICAgICAgICAgLCBpZGRmc19pc05ld1Jl
c3VsdC8yCiAgICAgICAgICAgLCBpZGRmc19zZWFyY2hEZXB0aC8xCiAgICAgICAgICAgLCBpZGRm
c19zZXRfc3RlcC8xIF0KICAgICAgICAgKS4KOi0gZHluYW1pYyB1c2VyOmNvbnRpbnVlX2lkZGZz
LzAuCjotIGR5bmFtaWMgdXNlcjppZGRmc19pc1VzZXJEZWZpbmVkLzIuCjotIGR5bmFtaWMgdXNl
cjppZGRmc19zdGVwLzEuCjotIGR5bmFtaWMgdXNlcjpleHBhbmRfcXVlcnkvNC4KOi0gbXVsdGlm
aWxlIHVzZXI6ZXhwYW5kX3F1ZXJ5LzQuCjotIG11bHRpZmlsZSB1c2VyOnRlcm1fZXhwYW5zaW9u
LzIuCgoKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSBBVFRFTlRJT04gJSUlJSUl
JSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJSBUaGUgInJvb3QiIHByZWRpY2F0ZXMgYXJl
IHRlcm1fZXhwYW5zaW9uLzIgYW5kIGV4cGFuZF9xdWVyeS80LCBhdCB0aGUgYm90dG9tCiUgb2Yg
dGhpcyBmaWxlIChmb3IgdGVjaG5pY2FsIHJlYXNvbnMpLiBTa2lwIHRvIHRoZW0gdG8gdW5kZXJz
dGFuZCB0aGUgb3RoZXIKJSBwcmVkaWNhdGVzLgolJSUlJSUlJSUlJSUlJSUlJSUlJ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DDFS_FILE"
rm -R "$TMP_DIR"
\ No newline at end of file
:- module( fortprog
, [ iddfs_assertIfNotExists/1
, iddfs_maxList/2
, iddfs_isNewResult/2
, iddfs_searchDepth/1
, iddfs_set_step/1 ]
).
:- dynamic user:continue_iddfs/0.
:- dynamic user:iddfs_isUserDefined/2.
:- dynamic user:iddfs_step/1.
:- dynamic user:expand_query/4.
:- multifile user:expand_query/4.
:- multifile user:term_expansion/2.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ATTENTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The "root" predicates are term_expansion/2 and expand_query/4, at the bottom
% of this file (for technical reasons). Skip to them to understand the other
% predicates.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Special queries %%%%%
% Handle the special query of loading a module (determine user defined
% predicates before).
expandQuery([Module], [Module])
:- absolute_file_name(Module, FileName, [extensions(['.pl'])])
, write(FileName), nl
, preProcess(FileName).
%%%%% The pure term expanding predicates %%%%%
% Expand a query
% `?- <Query>.`
%
% to
%
% `?- iddfs_assertIfNotExists(user:continue_iddfs)
% , iddfs_searchDepth(MaxDepth)
% , retract(user:continue_iddfs)
% , <Query_using_expanded_predicates>
% , iddfs_maxList(Lvls, Lvl)
% , iddfs_isNewResult(Lvl, MaxDepth).`
expandQuery(Query, NewQuery)
:- termAny(isUserDefinedTerm, Query)
-> ( expandBody(MaxDepth, Query, ExpQuery, Lvls)
, makeConjTerm([ iddfs_assertIfNotExists(user:continue_iddfs)
, iddfs_searchDepth(MaxDepth)
, retract(user:continue_iddfs)
, ExpQuery
, iddfs_maxList(Lvls, Lvl)
, iddfs_isNewResult(Lvl, MaxDepth) ]
, NewQuery)
)
; Query = NewQuery.
expandRule(Head, Body, NewHead, NewBody)
:- functor(Head, Functor, Arity)
, user:iddfs_isUserDefined(Functor, Arity)
-> ( expandPredication(MaxDepth, Head, NewHead, Lvl)
, expandBody(MaxD1, Body, TempBody0, Lvls)
, expandBodyByLvlCalc(Lvls, Lvl, TempBody0, TempBody1)
, expandBodyByDepthCalcAndCut(MaxDepth, MaxD1, TempBody1, NewBody) )
; (Head = NewHead, Body = NewBody).
% Expect term (and not its parts generated by `=..`) as input.
expandPredication(Depth, CompoundTerm, Expansion, Lvl)
:- CompoundTerm =.. CTParts
, expandCompoundTermParts(Depth, CTParts, ExpCTParts, Lvl)
, Expansion =.. ExpCTParts.
expandCompoundTermParts(Depth, [Functor | Args], [NewFunctor | NewArgs], Lvl)
:- length(Args, N)
, user:iddfs_isUserDefined(Functor, N)
-> ( appendArgs([Depth, Lvl], Args, NewArgs)
, atom_concat(Functor, '_iddfs_expanded', NewFunctor)
)
% Don't expand if predicate is not user-defined.
; ( Functor = NewFunctor
, Args = NewArgs
, Lvl = 0 ).
% Expect term (and not its parts generated by `=..`) as input.
% If body is just a variable, `=..` does not work.
expandBody(_ , VarBody, VarBody, [0]) :- var(VarBody), !.
expandBody(Depth, Body , NewBody, Lvls)
:- Body =.. BodyParts
, expandBodyParts(Depth, BodyParts, ExpBodyParts, Lvls)
, NewBody =.. ExpBodyParts.
expandBodyParts(Depth, [,, Left, Right], [,, ExpLeft, ExpRight], Lvls)
:- expandBody(Depth, Left, ExpLeft, LvlsLeft)
, expandBody(Depth, Right, ExpRight, LvlsRight)
, append(LvlsLeft, LvlsRight, Lvls).
expandBodyParts(Depth, [;, Left, Right], [;, ExpLeft, ExpRight], Lvls)
:- expandBody(Depth, Left, ExpLeft, LvlsLeft)
, expandBody(Depth, Right, ExpRight, LvlsRight)
, append(LvlsLeft, LvlsRight, Lvls).
expandBodyParts(Depth, [->, Left, Right], [->, ExpLeft, ExpRight], Lvls)
:- expandBody(Depth, Left, ExpLeft, LvlsLeft)
, expandBody(Depth, Right, ExpRight, LvlsRight)
, append(LvlsLeft, LvlsRight, Lvls).
expandBodyParts(Depth, [\+, Arg], [\+, ExpArg], Lvls)
:- expandBody(Depth, Arg, ExpArg, Lvls).
expandBodyParts(Depth, PredicationParts, NewPred, [Lvl])
:- PredicationTerm =.. PredicationParts
, expandPredication(Depth, PredicationTerm, ExpPredTerm, Lvl)
, ExpPredTerm =.. NewPred.
% Transform
%
% <Body>
%
% to
%
% <Body>, iddfs_maxList(Lvls, MaxLvl), Lvl is MaxLvl + 1
expandBodyByLvlCalc(Lvls, Lvl, Body, NewBody)
:- makeConjTerm( [ Body
, iddfs_maxList(Lvls, MaxLvl)
, Lvl is MaxLvl + 1]
, NewBody).
% Transform
% <Body>
%
% to
%
% N > 0 -> ( N1 is N - 1, <Body> )
% ; (iddfs_assertIfNotExists(user:continue_iddfs), fail)
expandBodyByDepthCalcAndCut(MaxDepth, MaxD1, Body, NewBody)
:- makeConjTerm([MaxD1 is MaxDepth - 1, Body], ThenAction)
, makeDisjTerm([ MaxDepth > 0 -> ThenAction
, (iddfs_assertIfNotExists(user:continue_iddfs)
, fail)]
, NewBody).
%%%%% Specific utility predicates %%%%%
iddfs_assertIfNotExists(Term) :- \+ Term -> asserta(Term) ; true.
% This determines the step used to increase the search depth. It is configurable
% by using `iddfs_set_step/1`.
user:iddfs_step(1).
iddfs_set_step(N) :- retractall(user:iddfs_step(_)), asserta(user:iddfs_step(N)).
% Count from 0 to infinity using global step setting.
iddfs_searchDepth(0).
iddfs_searchDepth(D)
:- user:continue_iddfs
, iddfs_searchDepth(D1)
, user:iddfs_step(Step)
, D is D1 + Step.
iddfs_maxList([], 0). % For our purpose this is a good choice.
iddfs_maxList([ X | Xs ], Max)
:- iddfs_maxList(Xs, MaxSoFar)
, (ground(X) -> Max is max(X, MaxSoFar)
; Max is MaxSoFar).
% A result is considered new, if it is found within a new interval.
iddfs_isNewResult(Lvl, MaxDepth)
:- user:iddfs_step(Step)
, Lvl >= MaxDepth - Step + 1.
preProcess(Module)
:- open(Module, read, Stream)
, read_terms(Stream, Terms)
, checkForIllegalOps(Terms)
, getUserDefinedPreds(Terms)
, close(Stream).
read_terms(Stream, [])
:- at_end_of_stream(Stream).
read_terms(Stream, [T | Ts])
:- \+ at_end_of_stream(Stream)
, read(Stream, T)
, read_terms(Stream, Ts).
checkForIllegalOps(Terms) :- listAny(termAny(isForbiddenOp), Terms), !.
checkForIllegalOps(_).
isForbiddenOp(Term)
:- \+ var(Term)
-> functor(Term, '!', 0)
, syntax_error('IDDFS is not compatible with the cut (!) operator!').
isForbiddenOp(Term)
:- \+ var(Term)
-> functor(Term, \+, 1)
, syntax_error('IDDFS is not compatible with the negation (\\+) operator!').
getUserDefinedPreds(Terms)
:- retractall(user:iddfs_isUserDefined(_,_))
, dispatch_terms(Terms).
isUserDefinedTerm(Term)
:- \+ var(Term) -> functor(Term, F, A), user:iddfs_isUserDefined(F, A).
markAsUserDefined(Term)
:- functor(Term, F, A)
, F \= end_of_file
-> iddfs_assertIfNotExists(user:iddfs_isUserDefined(F, A))
; true.
% Transform terms from argument list to an right associative conjunction term.
% For example: `[true, false, true, false]` becomes `true, (false, (true, false))`
makeConjTerm(Args, Result) :- makeOpTerm(,, Args, Result).
% See `makeConjTerm`, but with `;` instead of `,`
makeDisjTerm(Args, Result) :- makeOpTerm(;, Args, Result).
appendArgs(Args, OldArgs, NewArgs) :- append(OldArgs, Args, NewArgs).
%%%%% Generic utility predicates %%%%%
% True if Goal can successfully be applied on root term, or if termAny(Goal, ST)
% can can successfully be applied on any subterm ST of the root term.
% Mind that the root term could also be a variable or an atom.
termAny(Goal, Term) :- call(Goal, Term), !.
termAny(Goal, Term)
:- \+ var(Term)
-> Term =.. [ _ | Args ], listAny(termAny(Goal), Args).
% True if Goal can successfully be applied on any element of List
listAny(Goal, [X | _ ]) :- call(Goal, X), !.
listAny(Goal, [_ | Xs]) :- listAny(Goal, Xs).
% Contruct term using given binary op. For example:
% makeOpTerm( op, [x1, ..., xn], x1 op (x2 op (...( xn-1 op xn)...)) ).
makeOpTerm(_ , [Arg0], Result) :- Result = Arg0.
makeOpTerm(Op, [Arg0, Arg1 | Args], Result)
:- makeOpTerm(Op, [Arg1 | Args], TempRes)
, Result =.. [Op, Arg0, TempRes].
%%%%% The Dispatching of terms %%%%%
%%% Dispatching needed during term expansion
dispatch([:-, Directive], [:-, Directive]) :- !.
dispatch([?-, Query], [?-, NewQuery]) :- expandQuery(Query, NewQuery), !.
dispatch([:-, Head, Body], [:-, NewHead, NewBody])
:- expandRule(Head, Body, NewHead, NewBody), !.
dispatch(PredicationParts, NewPred)
:- PredicationTerm =.. PredicationParts
, expandPredication(_, PredicationTerm, ExpPredTerm, 0)
, ExpPredTerm =.. NewPred.
%%% Dispatching needed during query expansion
dispatch_terms([]).
dispatch_terms([T | Ts]) :- T =.. TParts, dispatch(TParts), dispatch_terms(Ts).
dispatch([:-, _]) :- !.
dispatch([?-, _]) :- !.
dispatch([:-, Head, _]) :- markAsUserDefined(Head), !.
dispatch(PredParts) :- Pred =.. PredParts, markAsUserDefined(Pred).
%%%%% The hooks which initiate term expansion %%%%%
:- asserta((user:expand_query(Q1,Q2,B,B) :- expandQuery(Q1, Q2))).
:- asserta((user:term_expansion(Term, Expansion) :- Term =.. Parts, dispatch(Parts, ProcessedParts), Expansion =.. ProcessedParts)).
%%% Greeting message:
:- write('Welcome to SWI-Prolog (extended WITH COMPLETE SEARCH for FortProg, 20/01/17).'),
nl.
\ No newline at end of file
## 1. Exercise
### Solutions will be checked on Wednesday, January, 19, 4pm to 6pm (Mini-test).
1. *Who is on board?*
A Quidditch club would like to put together a three-person board consisting of a chairperson, a treasurer and a secretary. The candidates are *Potter*, *Weasley*, *Malfoy* and *Granger*. There are however different preferences of the individual members, which limit the possibilities for the formation of a board.
1. *Potter* and *Malfoy* do not want to join the board together.
2. *Malfoy* is only available for the board if *Granger* becomes chairperson.
3. *Weasley* will only join the board if *Potter* also belongs to it.
4. *Potter* does not want to join the board if *Granger* becomes the secretary.
5. *Granger* does not join the board if *Weasley* becomes chairperson.
Write a Prolog program that calculates all possible board member constellations.
**Note:** Make sure to avoid duplicate answers!
1. *Predicates*
1. Add the following predicates to the [family example](asset-89071) from the lecture.
* `son(S, P)` is fulfilled if `S` is a son of `P`.
* `cousin(C, P)` is fulfilled if `C` is a cousin (male or female) of `P`.
* `brother_in_law(B, P)` is fulfilled if `B` is a brother in law of `P`.
* `ancestor(A, P)` is fulfilled if `A` is an ancestor of `P`.
2. Implement the following predicates using the [`append` predicate](asset-89070) from the lecture.
* `lookup(K, KVs, V)` is fulfilled if the tuple `(K, V)` is included in the list `KVs`.
* `member2(E, L)` is fulfilled if `E` is included at least twice in the list `L`.
* `reverse(Xs, Ys)` is fulfilled if the inversion of list `Xs` corresponds to list `Ys`. Implement both the naive and the efficient variant (accumulator technique using an additional argument).
* `sublist(Xs, Ys)` is fulfilled if `Xs` occurs as a sublist in `Ys`.
1. *Binary Numbers*
In the lecture we presented natural numbers as Peano numbers. However, this representation is very inefficient for large numbers. We therefore want to present natural numbers as binary numbers.
* We distinguish the number 0, represented as `o`, and positive numbers >0 represented as `pos(N)`.
* Positive numbers are represented as a bit sequence, where the most significant bit is always 1, so there are no leading zeros. Positive numbers consist of the following functors.
* A term of the form `o(N)` represents the number 2*N,
* a term of the form `i(N)` represents the number 2*N+1 and
* the atom `i` represents the number 1 (most significant bit).
The number 0 is therefore called `o`, 1 as `pos(i)` and 4 as `pos(o(o(i))`. Hence, the outermost functor represents the least significant bit.
1. Define the following predicates based on this number representation.
* Addition of two natural numbers `add(X, Y, Res)`.
* Subtraction of two natural numbers `sub(X, Y, Res)`.
**Note:** Use auxiliary predicates such as `addP`, which are defined on positive numbers. Furthermore, use the following equations and develop equations for further combinations if necessary.
~~~
1+1 = 2
1+(2 * N) = 2 * N+1
1+(2 * N + 1) = 2 * (N+1)
~~~
2. When used in the opposite direction, e.g. with a query like `add(X, Y, pos(o(i)))`, Prolog computes all solutions, but, unfortunately, does not terminate. The reason is, that the Prolog program does not know that the sum of two positive numbers is greater than each summand, and thus increasing summands are tried.
Implement for positive numbers >0 a predicate `lessP(X, Y)` that is satisfied, when `X` is less than `Y`. Then use this predicate to improve the previous implementation of `add`.
1. *Boolean Operations*
Implement Boolean functions `and`, `or`, and `not` as predicates working on the values `true` and `false`. Make sure that negation is also possible. Therefore, you must provide an explicit result as an additional parameter of your predicate.
Also implement the following three Boolean expressions as Prolog predicates `ex1(X, Y, Z, Res)`, `ex2(X, Y, Z, Res)`, and `ex3(X, Y, Z, Res)`.
* (X /\ Y) \/ Z
* (X /\ Y) \/ ((Y /\ Z) /\ Z)
* (X /\ (not Y) /\ Z) \/ ((Z /\ Y) \/ Z)
Specify queries that can be used to answer the following questions. Give the answer of the Prolog system as well as an additional explanation.
* Which results do you get for the values `X = true`, `Y = false` and `Z = true`?
* Which assignments yield `true` as result?
* Is the third equation dependent on `X` or `Z`?
mother(susanne,monika).
mother(norbert,monika).
mother(monika,ulrike).
mother(herbert,christine).
mother(andreas,angelika).
mother(angelika,christine).
mother(hubert,maria).
female(susanne).
female(P) :- mother(_,P).
husband(monika,herbert).
husband(angelika,hubert).
husband(christine,heinz).
husband(maria,fritz).
father(C,F) :- mother(C,M), husband(M,F).
grandmother(C,GM) :- mother(C,M), mother(M,GM).
grandmother(C,GM) :- father(C,F), mother(F,GM).
sibling(P1,P2) :- mother(P1,M), mother(P2,M), P1\=P2.
sister(P,S) :- sibling(P,S), female(S).
date(date(_,_,_)).
year(date(_,_,Y),Y).
month(date(_,M,_),M).
day(date(D,_,_),D).
% data Tree where
% Leaf :: Int -> Tree
% Branch :: Tree -> Tree -> Tree
tree(leaf(_)).
tree(branch(TL,TR)) :- tree(TL),tree(TR).
list([]).
list([_|Xs]) :- list(Xs).
memb(E,[E|_]).
memb(E,[_|Xs]) :- memb(E,Xs).
% (++) :: [a] -> [a] -> [a]
% [] ++ ys = ys
% (x:xs) ++ ys = x : (xs ++ ys)
% app([a],[a],[a])
% the result of a function gets an additional argument
% (usually in the end).
app([] ,Ys,Ys).
app([X|Xs],Ys,[X|Zs]) :- app(Xs,Ys,Zs).
prefix(Xs,Ys) :- app(Xs,_,Ys).
suffix(Xs,Ys) :- app(_,Xs,Ys).
sublist(Xs,Ys) :- prefix(Zs,Ys), suffix(Xs,Zs).
mem(E,Xs) :- sublist([E],Xs).
isPeano(o).
isPeano(s(N)) :- isPeano(N).
add(o ,M,M).
add(s(N),M,s(R)) :- add(N,M,R).
sub(N,M,R) :- add(M,R,N).
leq(o,_).
leq(s(N),s(M)) :- leq(N,M).
len([],o).
<