Unformatted text preview: • Recursive case!
nn(N) : nn(M), N is M+1.!
– “N is a natural number if M is a
natural number and N is M+1” ? nn(X).!
X = 1 ;!
X = 2 ;!
X = 3 ;!
X = 4 ;!
X = 5 ;!
X = 6 ;!
X = 7 ;!
X = 8 ;!
X=9! Even Numbers
• Suppose
– even numbers are
natural numbers that
are divisible by 2 • Set:
– N = {1,2,3,4,5,..}
– E = {2,4,..} • Task:
– Write a predicate
even/1 that generates
the even numbers Method 1
• Base Case
even(2).! • Recursive Case
even(N) : !
even(M), N is M+2.! • Query:
? e(X).!
X = 2 ;!
X = 4 ;!
X = 6 ;!
X=8 Even Numbers
• Suppose
– even numbers are
natural numbers that
are divisible by 2 Method 2
• Use the natural number definition
and permit only the even ones
• Modify:
nn(1).!
nn(N) : nn(M), N is M+1.! • Set:
– N = {1,2,3,4,5,..}
– E = {2,4,..} • Task:
– Write a predicate
even/1 that
generates the even
numbers • into
even(N) : nn(N), is_even(N).!
where is_even(N)...
View
Full Document
 Fall '08
 STAFF
 Natural number, Evenness of zero, a00, midlist

Click to edit the document details