Y is x2 z is roundx2 y z define isoddx y

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: tests N to see if it’s an even number Even Numbers Method 2 •  Use the natural number definition and permit only the even ones •  Modify: nn(1).! nn(N) :- nn(M), N is M+1.! •  into even(N) :- nn(N), is_even(N).! •  •  Suppose –  even numbers are natural numbers that are divisible by 2 Let’s use Prolog’s built-in arithmetic evaluation predicate is/2! –  ?- Y is 3/2.! •  –  Y=1.5! –  ?- Y is 4/2.! •  produces an integer –  Y=2! –  ?- Y is round(3/2).! •  where is_even(N) tests N to see if it’s an even number produces a floating point number –  rounds up to the nearest integer Y=2 ! Even Numbers •  •  Definition so far Suppose even(N) :- nn(N), is_even(N).! where is_even(N) tests N to see if it’s an even number Simple Idea: –  to test whether a number X is even 1.  divide it by 2, call this number Y 2.  divide it by 2 and round it, call this number Z 3.  X is even if Y=Z. –  even numbers are natural numbers tha...
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