This preview shows page 1. Sign up to view the full content.
Unformatted text preview: tests N to see if it’s
an even number Even Numbers
• Use the natural number
definition and permit only the
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 is 4/2.!
• produces an integer –
– ?- 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
to test whether a number X is
divide it by 2, call this number Y
divide it by 2 and round it, call this
X is even if Y=Z. – even numbers are natural
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.
- Fall '08