diff options
Diffstat (limited to 'sem7/pp/prolog/lec4.pl')
-rw-r--r-- | sem7/pp/prolog/lec4.pl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sem7/pp/prolog/lec4.pl b/sem7/pp/prolog/lec4.pl new file mode 100644 index 0000000..36d3880 --- /dev/null +++ b/sem7/pp/prolog/lec4.pl @@ -0,0 +1,50 @@ + +last([X], X). +last([_|XS], X) :- last(XS, X). + +/* +last([1,2,3], X) # Bruger regel 2 +last([2,3], Y) # Bruger regel 2 +last([3], Z) # Bruger regel 1, så Z = 3 +# Så Y = Z = 3 +# Så X = Y = Z = 3 + + +Okay det er også bare fint at skrive +last([1,2,3],X) + | +last([2,3],X) + | +last([3], X) +*/ + +attach([], E, [E]). +attach([X|XS], E, [X|R]) :- attach(XS, E, R). + + +/* +Proof search of attach + +attach([1,2], a, L) + | X = 1, XS = [2], E = a, L = [1|L1] +attach([2], a, L1) + | X1 = 2, XS1 = [], E1 = a, L1 = [2|L2] +attach([], a, L2) + | E2 = a, L2 = [a] +*/ + +nat(zero). +nat(succ(X)) :- nat(X). + +after(succ(X), X). + +leq(zero, Y) :- nat(Y). +leq(succ(X), succ(Y)) :- leq(X, Y), nat(X), nat(Y). + +add(X, zero, X) :- nat(X). +add(X, succ(Y), succ(R)) :- add(X, Y, R), nat(X), nat(Y), nat(R). + +sub(X, Y, R) :- add(R, Y, X). + +min(X, Y, X) :- leq(X, Y). +min(succ(X), Y, Y) :- leq(Y, X). |