LPN: reorg, split notes from exocortex page.

The exocortex page was getting unwieldy, this makes more sense.
This commit is contained in:
2018-01-16 16:43:12 -08:00
parent 36ed6df77f
commit 6d4fb673ef
19 changed files with 363 additions and 0 deletions

5
lpn/ch01/kb1.pl Normal file
View File

@@ -0,0 +1,5 @@
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.

6
lpn/ch01/kb2.pl Normal file
View File

@@ -0,0 +1,6 @@
happy(yolanda).
listens2Music(mia).
listens2Music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2Music(mia).
playsAirGuitar(yolanda):- listens2Music(yolanda).
listens2Music(bruce).

9
lpn/ch01/kb3.pl Normal file
View File

@@ -0,0 +1,9 @@
happy(vincent).
listens2Music(butch).
playsAirGuitar(vincent):-
listens2Music(vincent),
happy(vincent).
playsAirGuitar(butch):-
happy(butch).
playsAirGuitar(butch):-
listens2Music(butch).

8
lpn/ch01/kb4.pl Normal file
View File

@@ -0,0 +1,8 @@
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin,honey_bunny).
loves(honey_bunny,pumpkin).

11
lpn/ch01/kb5.pl Normal file
View File

@@ -0,0 +1,11 @@
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin,honey_bunny).
loves(honey_bunny,pumpkin).
/**
* original definition:
* jealous(X,Y):- loves(X,Z), loves(Y,Z).
*/
jealous(X,Y):- loves(X,Z), loves(Y,Z), X \= Y.

13
lpn/ch01/lexicon.pl Normal file
View File

@@ -0,0 +1,13 @@
word(determiner,a).
word(determiner,every).
word(noun,criminal).
word(noun,'big kahuna burger').
word(verb,eats).
word(verb,likes).
sentence(Word1,Word2,Word3,Word4,Word5):-
word(determiner,Word1),
word(noun,Word2),
word(verb,Word3),
word(determiner,Word4),
word(noun,Word5).

2
lpn/ch01/lines.pl Normal file
View File

@@ -0,0 +1,2 @@
vertical(line(point(X,Y),point(X,Z))).
horizontal(line(point(X,Y),point(Z,Y))).

97
lpn/ch01/notes.md Normal file
View File

@@ -0,0 +1,97 @@
## Some basic syntax
```
property(name).
proposition.
/* rules */
head :- tail.
```
Example:
```
happy(yolanda).
listens2Music(mia).
listens2Music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2Music(mia).
playsAirGuitar(yolanda):- listens2Music(yolanda).
```
### Rules
Conditional fact:
```
/* source */
listensToMusic(X) :- happy(X).
playsAirGuitar(X) :- listensToMusic(X).
happy(a).
/* interactive */
playsAirGuitar(a). /* true */
playsAirGuitar(b). /* false */
```
## KB5
```
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin,honey_bunny).
loves(honey_bunny,pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
```
Note that when you enter queries, sometimes it waits for you to enter something
(so far seems like a semi-colon finishes a query). For example:
```
2 ?- jealous(vincent, W).
W = vincent
```
Output freezes there, waiting on input. Enter the semicolon:
```
2 ?- jealous(vincent, W).
W = vincent ;
W = marsellus.
```
Replacing both atoms with variable:
```
3 ?- jealous(A, B).
A = B, B = vincent ;
A = vincent,
B = marsellus ;
A = marsellus,
B = vincent ;
A = B, B = marsellus ;
A = B, B = pumpkin ;
A = B, B = honey_bunny.
```
This brings up something interesting: *jealous(A, A)* is always true:
```
4 ?- jealous(A, A).
A = vincent ;
A = marsellus ;
A = pumpkin ;
A = honey_bunny.
```
Can we fix that in the definitions?
```
jealous(X,Y):- loves(X,Z), loves(Y,Z), X \= Y.
```
Now:
```
9 ?- jealous(A, A).
false.
```
Re-reading a previous section, seems that ';' means "or".

3
lpn/ch01/test.pl Normal file
View File

@@ -0,0 +1,3 @@
listensToMusic(X) :- happy(X).
playsAirGuitar(X) :- listensToMusic(X).
happy(a).