<< >> Up Title Contents

2.3.1. Exercises

1. Define predicate square/2 that takes a number as its first argument and returns the square of that number as its second argument. (No recursion in this one.)

2. Define a predicate power/3 that takes numbers as its first two arguments P and N and returns as the value of its third argument a number which is N to the power of P. E.g.

?- power(3,2,P).

P = 8 yes

Note that this requires a recursive rule and the use of arithmetic.


<< >> Up Title Contents