Alternatively, the last two clauses could be replaced by:happy(P,D) <- student(P) & holiday(D). happy(P,D) <- teaching(P,C) & midterm(C,D). happy(david,tuesday). happy(david,sunday).
This is probably better as there may be many different Tuesdays that we would want to consider as a Tuesday. We probaly don't want to do the same thing for the constant david, as we mean a particular David, not just anyone called David.happy(david,D) <- tuesday(D). happy(david,D) <- sunday(D).