Skip to content

Commit

Permalink
Lab12
Browse files Browse the repository at this point in the history
prolog
  • Loading branch information
mrsillydog committed May 1, 2020
1 parent 12d112e commit b5e3236
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lab12/lab_1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
killer(butch).
married(mia, marsellus).
dead(zed).
kills(marsellus,X):-footmassage(X,mia).
loves(mia,X):-gooddancer(X).
eats(jules,X):-nutritious(X); tasty(X).

/**
* a. i. I built up the representations so that the nouns were consistently the
* arguments (butch,mia,marsellus), and if a variable was required then
* I would use X as a simple variable. The relational adjectives and verbs
* were used as functors (married, kills, killer, eats). From there it was a
* simple matter of determining which functors in regard to which arguments
* implied which other functors in regard to which other arguments.
*/

wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X):- hasBroom(X), hasWand(X).
hasBroom(X):- quidditchPlayer(X).

/**
* a. ii.
* 1. wizard(ron). This returns true, since ron is defined as a wizard; but if a semicolon
* is pressed, it returns false, since hasBroom(ron). and hasWand(ron). are not stated.
* 2. witch(ron). This returns ERROR: Undefined procedure: witch/1 (DWIM could not correct
* goal), since the functor witch is not defined.
* 3. wizard(hermione). This returns false, because wizard(hermione). is not stated, and
* neither are hasBroom(hermione). and hasWand(hermione).
* 4. witch(hermione). This returns ERROR: Undefined procedure: witch/1 (DWIM could not
* correct goal), since the functor witch is not defined.
* 5. wizard(harry). This returns true; while wizard(harry). is not expressly stated,
* hasBroom(harry). and hasWand(harry). are, which through modus ponens Prolog can use
* to conclude wizard(harry).
* 6. wizard(Y). This returns Y = ron, and if a semicolon is typed it returns Y = harry.
* Y = ron is returned because wizard(ron). is expressly stated, and Y = harry is returned
* for the same reason wizard(harry). returned true in the previous query.
* 7. witch(Y). This returns ERROR: Undefined procedure: witch/1 (DWIM could not
* correct goal), since the functor witch is not defined.
*/
39 changes: 39 additions & 0 deletions lab12/lab_2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* a. i.
* 1. bread = bread -> true. No instantiation occurs because there are no
* variables involved.
* 2. ’Bread’ = bread -> false. No instantiation occurs because there are
* no variables involved.
* 8. food(X) = food(bread) -> X = bread. X is instantiated to bread.
* 9. food(bread,X) = food(Y,sausage) -> X = sausage, Y = bread. X is
* instantiated to sausage, Y is instantiated to bread.
* 14. meal(food(bread),X) = meal(X,drink(beer)) -> false. If X is
* instantiated to drink(beer) then
* meal(food(bread),drink(beer)) != meal(drink(beer),drink(beer)). If X is
* instantiated to food(bread), then
* meal(food(bread),food(bread)) != meal(food(bread),drink(beer)).
*/

wizard(tom).
house_elf(dobby).
witch(hermione).
witch('McGonagall').
witch(rita_skeeter).
magic(X):-house_elf(X).
magic(X):-wizard(X).
magic(X):-witch(X).

/* Swi-prolog doesn't allow us to query using functors that haven't been previously defined. In short,
it doesn't allow us to unify variables with functors that haven't been used before.
For instance:
magic(house_elf).
wizard(harry).
magic(wizard).
all return me variations on this error: Undefined procedure: wizard/1.....
wizard/1 has not been used, so it cannot be queried (wizard(harry). and magic(wizard).) and it additionally
prevents magic/1 being used on other functors, since magic/1 depends on wizard/1
However, if I add to the knowledge base the line
wizard(tom).
(or any other random atomic that has no relevance to the rest of the knowledge base, not necessarily tom)
then all three return actual values (false, in each case), because the functor has now been defined and used.
*/
7 changes: 7 additions & 0 deletions lab12/lab_3.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
weighsduck(lady).
floats(X):-weighsduck(X).
wood(X):-floats(X).
burn(X):-wood(X).
witch(X):-burn(X).

/* witch(lady). returns true */

0 comments on commit b5e3236

Please sign in to comment.