Math/CSE 1560 Lab 9

Exercise: Recursive procedures in Maple

Objective
The objective of this exercise is to test your familiarity with solving problems using recursion in Maple.

Grading
This lab exercise is meant to be completed in the lab, individually (Collaboration is NOT allowed for this exercise).

NOTE: This is a 2 hour lab. The submission server will close shortly after 4:30 pm. You will not be able to submit your work after that time.

No printouts will be accepted.

Starting off:

  1. Open Maple 12 by clicking on the icon marked as such. If Maple does not start, let the TA know immediately. If asked, choose to start a new worksheet.
  2. On the first 2 lines, enter your name and student number as comments -- start the lines with character #. Then save the file as `lab9.mw` by clicking on `File` and then `save as`.

Problems
Note: Some of these problems can be solved using loops or seq() or map(). To get credit for this assignment you must use recursion instead.

  1. (5 points) Write a procedure using recursion that takes as input a positive integer and returns true if the input is a power of 2 and false otherwise. You are not allowed to use loops, the log function, or any function not covered in class.
  2. (5 points) Recall that the factorial of n is defined as 1*2*3*..*n, The hyperfactorial of n is defined as (1^2)*(2^2)*(3^2)*...*(n^n). Write a procedure rechf using recursion that takes as input a positive integer n and returns the hyperfactorial of n.
    You are not sllowed to use loops, or any function not covered in class.
  3. (5 points) Write a procedure using recursion that takes as input a list L and returns the sum of all the elements of the list with odd indices. In other words it should return the sum L[1]+L[3]+....
    You are not allowed to use loops.
  4. (5 points) Write a procedure using recursion that takes as input a list L of positive integers. It should print an error message if the list is of odd length; otherwise it returns the product L[1]^(L[2])*L[3]^(L[4])*....*L[nops(L)-1]^(L[nops(L)]). You are not allowed to use loops.

Final steps

  1. Save your worksheet.
  2. Submit the assignment as lab 8 in Moodle (the URL is moodle.math.yorku.ca). You can upload several times, but remember to submit using the "send for marking" at the end ONCE - otherwise it may not be sent.
  3. You are done with this assignment. Remember to logout before you leave the lab.