The palindrome relation indicates that a list is the same backward and
forward. Write palindrome using only append.
;; YOUR CODE HERE
(query (palindrome a b c a)) ; Failed.
(query (palindrome a b c b a)) ; Success!
(query (palindrome a b b a)) ; Success!
(query (palindrome a ?x c b ?y)) ; Success! ; ?x: b ; ?y: a
A New Subset
Remember the subsets relation that we wrote in the homework which finds
a list of all the subsets of a given set? Let's now write a
relation subset that checks if a set is a subset of another set. We
will represent a set as a sorted list.
;; YOUR CODE HERE
(query (subset () (hi))) ; Success!
(query (subset (b d e) (a b c d e))) ; Success!
(query (subset (b c f) (a b c d e))) ; Faliure.
(query (subset ?set (1 2 3))) ; Success!
; ?set: () ; ?set: (3) ; ?set: (2) ; ?set: (2 3)
; ?set: (1) ; ?set: (1 3) ; ?set: (1 2) ; ?set: (1 2 3)
Notice that by just stating what a subset is, we can get logic to enumerate all
subsets of a set for us. How cool is that!
Tree Manipulation
We shall now represent trees in logic! Suppose we represent a tree by a list
(entry left right) and represent a null tree by the empty list
(). We also have a few relations that extracts the left, right and entry of a
tree.
Write relations for in-tree, which checks if a tree has a specific
entry.
Can you tell what order the leaves of the tree appear in? Hint: do you know what
kind of search the logic interpreter does when it tries to match patterns?