Skip to content

Commit

Permalink
Lab13
Browse files Browse the repository at this point in the history
More prolog
  • Loading branch information
mrsillydog committed May 8, 2020
1 parent e5d4b1e commit ff61b8e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lab13/lab_1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Exercise 13.1
* a.
* i. Exercise 3.2
*/

directlyIn(katarina,olga).
directlyIn(olga,natasha).
directlyIn(natasha,irina).
in(X,Y) :- directlyIn(X,Y).
in(X,Y) :- directlyIn(Z,Y), in(X,Z).

/**
* in(katarina,natasha). => true.
* in(olga, katarina). => false.
*
* ii. Exercise 4.5
*/

tran(eins,one).
tran(zwei,two).
tran(drei,three).
tran(vier,four).
tran(fuenf,five).
tran(sechs,six).
tran(sieben,seven).
tran(acht,eight).
tran(neun,nine).

listtran([],[]).
listtran([G|TG],[E|TE]) :- tran(G,E), listtran(TG,TE).

/**
* listtran([eins,neun,zwei],X).
* X = [one, nine, two].
*
* listtran(X,[one,seven,six,two]).
* X = [eins, sieben, sechs, zwei].
*/

/**
* b.
* Prolog does implement at least a partial version of generalized modus ponens.
* While universal instantiation is not explicitly stated, it is implied; with a
* statement like the one below (fun(X).), universal instantiation will make it so
* the query fun(<any parameter>). will return true.
* Prolog does not have existential instantiation and cannot be given existential
* instantiation. This is because while Prolog deals with positive, clear statements
* well, such as a universal instantiation which makes an affirmative statement about
* all, it doesn't deal well with uncertainty. And with an existential instantiation,
* uncertainty is assigned to every variable; at least one has to have the assigned
* quality, but it's not clear which one.
*/

fun(X).



32 changes: 32 additions & 0 deletions lab13/lab_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Exercise 13.2
on(a,b)
on(b,c)
supports(table,c)
AxAy supports(x,y) => on(y,x)
AxAy on(x,y) => above(x,y)
AxAyAz above(x,y) ^ above(y,z) => above(x,z)

Suppose:
1. !above(a,table) ^ on(a,b) ^ on(b,c) ^ supports(table,c)

Through (AxAy supports(x,y) => on(y,x))
^ supports(table,c)

2. !above(a,table) ^ on(a,b) ^ on(b,c) ^ on(c,table)

Through (AxAy on(x,y) => above(x,y))
^ on(a,b) ^ on(b,c) ^ on(c,table)

3. !above(a,table) ^ above(a,b) ^ above(b,c) ^ above(c,table)

Through (AxAyAz above(x,y) ^ above(y,z) => above(x,z))
^ above(b,c) ^ above(c,table)

4. !above(a,table) ^ above(a,b) ^ above(b,table)

Through AxAyAz (above(x,y) ^ above(y,z) => above(x,z))
^ above(a,b) ^ above(b,table)

5. !above(a,table) ^ above(a,table)

Contradiction. Therefore, above(a,table) must be true.

0 comments on commit ff61b8e

Please sign in to comment.