Modified Exercise 1.17, Added double and halve procedures