Math/CSE 1560 Lab 8

Exercise: Writing while and for-loops in Maple

Objective
The objective of this exercise is to test your familiarity with solving problems using while and for-loops 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 `lab8.mw` by clicking on `File` and then `save as`.

Problems
Note: Some of these problems can be solved using seq() or map(), For this assignment you must use for-loops instead.

  1. (5 points) Goldbach Conjecture: This conjecture states that every even integer greater than 2 be written as the sum of two primes. E.g., 8=3+5, 18=5+13. This conjecture has not been proved or disproved and is a famous, longstanding open problem in Mathematics.
    Write a procedure that takes as input a positive integer. If the input is an odd number it should print an error message and return an empty list; otherwise, it computes one possible way to write the integer as a sum of two primes, and returns a list containing these 2 primes. If there is no such pair of primes, then your procedure should print the message "The Goldbach conjecture is resolved!" and return an empty list.
  2. (5 points) A set of integers a,b,c (a<=b<=c) that satisfy the equation a^2+b^2=c^2 is called a Pythagorean Triple. Write a procedure that determines all Pythagorean triples that have b=16, or a=16 and b <=1000.
    Your procedure should take no inputs, and need not return any value. It should print Pythagorean Triples in order (i.e. as a<=b<=c).
  3. (4 points) Write a procedure that takes as input a list and returns true if all the elements of the list are of type integer and false otherwise.
  4. (6 points) Write a procedure that takes as input a list of integers L of size n and a positive integer k <=n. The procedure should print an error message and return 0 if k>n. Otherwise, it should return the index of the minimum element in L[1..k].
    E.g. if L=[12,43,52,8,1] and k = 3, the procedure should return 1. For the same list and k=4, the answer is 4.

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.