# joshuaeckroth/cse630-website

Added sister/2 predicate in Prolog notes.

1 parent 6dc3dd2 commit 8e97fc7c96213a0621ad0bf0145b5846d1cf395d committed Apr 23, 2012
Showing with 90 additions and 11 deletions.
1. +1 −1 learning.html
2. +1 −1 planning.html
3. +85 −6 prolog.html
4. +1 −1 reasoning-with-uncertainty.html
5. +1 −1 siteindex.html
6. +1 −1 theindex.html
2 learning.html
 @@ -7,7 +7,7 @@ - +
2 planning.html
 @@ -7,7 +7,7 @@ - +
91 prolog.html
 @@ -7,7 +7,7 @@ - + @@ -456,6 +456,81 @@

Defining complex predicates (rules)

+Let’s try defining the sister relationship: +

+ + + +
sister(X, Y) :- parent(Z, X), parent(Z, Y), female(X), female(Y).
+
+ + +

+And some queries: +

+ + + +
?- sister(ann, pat).
+true.
+
+?- sister(bob, pat).
+false.
+
+?- sister(X, Y).
+X = Y, Y = liz ;
+X = Y, Y = ann ;
+X = ann,
+Y = pat ;
+X = pat,
+Y = ann ;
+X = Y, Y = pat ;
+false.
+
+ + +

+What does X = Y, Y = liz mean? It means liz is, apparently, her +own sister: +

+ + + +
?- sister(liz, liz).
+true.
+
+ + +

+Let’s prevent that by adding another clause to the sister predicate +(\= means “not equal”): +

+ + + +
sister(X, Y) :- parent(Z, X), parent(Z, Y), female(X), female(Y), X \= Y.
+
+ + +

+Now, we get the correct behavior: +

+ + + +
?- sister(liz, liz).
+false.
+
+?- sister(X, Y).
+X = ann,
+Y = pat ;
+X = pat,
+Y = ann ;
+false.
+
+ + +

These rules are essentially the following logical statements:

@@ -469,13 +544,17 @@

Defining complex predicates (rules)

$$(\forall x)(\exists y)(\exists z)((Parent(x, y) \wedge Parent(y, z)) \rightarrow Grandparent(x))$$ +$$(\forall x)(\forall y)(\exists z)((Parent(z, x) \wedge Parent(z, y) +\wedge Female(x) \wedge Female(y) \wedge x \neq y) +\rightarrow Sister(x, y))$$ +

Notice how they all have the same form. Essentially, the variables in -the rule (X in each of these cases) have a $$\forall$$ in front -(because the rule is true for all variables X, should certain -conditions hold), and the variables inside the rule (Y and Z) have -$$\exists$$ in front because you only need to find one value for each -variable to make the rule true for some X. Notice we have +the rule (X or both X and Y in each of these cases) have a +$$\forall$$ in front (because the rule is true for all variables X or +X and Y, should certain conditions hold), and the variables inside +the rule have $$\exists$$ in front because you only need to find one +value for each variable to make the rule true. Notice we have $$\rightarrow$$ not $$\leftrightarrow$$ because there may be more than one way to satisfy a rule. For example,

2 reasoning-with-uncertainty.html
 @@ -7,7 +7,7 @@ - +
2 siteindex.html
 @@ -7,7 +7,7 @@ - +
2 theindex.html
 @@ -7,7 +7,7 @@ - +