Lecture7

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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

This note was uploaded on 04/29/2012 for the course LING 388 taught by Professor Staff during the Fall '08 term at University of Arizona- Tucson.

Ask a homework question - tutors are online