Anda di halaman 1dari 2

Amicably Yours

February 19, 2013


Amicable numbers are pairs of distinct positive integers each of whose proper divisors adds up to the other (1 is included as a divisor but the numbers are not included as their own divisors). The smallest pair of amicable numbers is (220, 284). Down through their quaint history, amicable numbers have been important in magic and astrology, and in casting of horoscopes, making talismans, and concocting love potions. The philosopher Iamblichus of Chalcis (A.D 250 A.D 330) ascribed a knowledge of the pair 220 and 284 to the Pythagoreans. He wrote: They [the Pythagoreans] call certain numbers amicable numbers, adopting virtues and social qualities to numbers, as 220 and 284; for the parts of each have the power to generate the other. Do the following: 1. Write a functional algorithm genAmicables n which generates all pairs of amicable numbers which do not exceed the positive value n. Design your algorithm by step-wise renement and design auxiliary functional algorithms, which are in turn dened by step-wise renement. 2. Give complete proofs of correctness of your functional algorithms. In particular, you need to state and prove relevant theorems which convince the reader that (a) Every pair of numbers generated by your program is indeed amicable. (b) Your program generates every pair of amicable numbers in the given range, i.e. no amicable pair in the range has been missed out. 3. Give proofs of termination of your algorithms. 4. Assume some time complexity measure in terms of the operations on the digital computer. You could assume that addition and subtraction are insignicant compared to operations such as multiplication, div and mod. You could also assume that multiplication, div and mod take the same amount of time and space, to ease your calculations. (a) State your assumptions clearly.

(b) State and prove a theorem giving an upper bound on the running time of your algorithm in terms of the most signication operations used. 5. Assume some reasonable space measure for the numbers you consider. Assume that recursive calls take up the largest amount of space. (a) State your assumptions clearly. (b) State and prove a theorem giving a bound on the space required for your algorithms in terms of the most signication operations used. 6. Are there any functions which may be transformed using tail-recursion so that they consume less time and/or space? If so (a) Perform suitable transformations of your algorithms into tail-recursion (b) Prove the correctness of your transformed functions either with respect to the original function or the previous algorithm(s). (c) Prove that the transformation improves running time and/or space over your previously dened algorithm for the same function. 7. Develop an SML function genAmicables which generates a list of all pairs of amicable numbers (m, n) with m < n < valOf(Int.maxInt). Now do the following. Prepare three les: amicables.pdf containing the development of the algorithm for generating a list of amicable numbers along with the relevant proofs of correctness and complexity as stated above. Ask your TA for guidance on the software required for doing this. amicables.sml containg the SML code of the nal algorithm that you have documented in amicables.pdf. amicables.tgz Use the command tar cvfz to create a single le called amicables.tgz which contains the two les amicables.pdf and amicables.sml Ask your TA for guidance on how to do this. Submit the le amicables.tgz as your assignment submission.

Anda mungkin juga menyukai