Defining Functions in Terms of Other Functions

We could define a function isEven:num -> boolean as follows:

 
isEven:num -> bool;
isEven(n) <=  if n mod 2 = 0
              then true
              else false;
or even more simply as
 
isEven:num -> bool;
isEven(n) <= n mod 2 = 0;
or we could use the previously defined isOdd function:
 
isEven:num -> bool;
isEven(n) <= not (isOdd(n));



Subsections

s.danicic@gold.ac.uk
Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2010-12-29