In this assignment we are going to start using functions more precisely.
Maple has two ways of representing functions. There is a one line notation that
uses an arrow (some of you have started using this in your assignments) and there
is a second way that is good for representing functions that take more than one line
called a procedure. In this assignment we will consider lists of elements
and functions on those lists.
Example: > f := x -> x^2;
Then this is how you would use this function: > f(y);
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Notice that x doesn't appear anywhere where the function is used, it appears
only in the definition. The letter x
is a dummy variable that gets replaced every time you use f( something )
then wherever x appears it is replaced with "something". This should be familiar
because this is the notation that we use in mathematics all the time.
This method for creating a function is good only if your function can be expressed
as a single command. If you want to make a function that takes several steps or
several Maple commands, then you will need to make a 'procedure' or make a bunch of
smaller functions which you combine. We will look more closely at procedures
in our next assignments. In this assignment, we will will work with one line functions
and the arrow -> notation. More generally we will work with functions
of the form
We will also work a command which can be used to create a sequence in Maple called seq.
The command seq creates an expression for a bunch of values and puts it in a
For instance, > [seq(i^2, i=0..10)];
makes a list of values of i^2 where i ranges from 0 to 10.
In general we will see
this command used as > seq( expression involving variable, variable=startval..endval );
This will create a sequence of values which isn't quite the same as a list. If we want to turn
it into a list or a set we would put square brackets or curly braces around this expression (see
the examples below. If I want to make a list of 100 zeros, I would use [seq(0,i=1..100)].
Understand what the following commands do by seeing what Maple returns, using the help functions,
and by experimenting by changing the commands around so that you understand what they do.
The command convert(list, `and`) (also see convert(list, `or`)) returns
true if all elements in a list are true (respectively if one element is true and the others
Write a function called to_points which takes a list L
of non-negative integers and
returns a list of pairs [x, y] where 1 $\leq$ x $\leq$ the length of L
and 1 $\leq$ y $\leq$ L[x]. Then write a function called
transpose_points which takes a list of pairs of the form [x,y] and
interchanges the x and y coordinates.
Write a third function called from_points which does the inverse of the function
to_points in that it takes a list of points points and returns a list L where
L[i] is the number of points whose first coordinate is i where i
ranges between 1 and max(map(p->p,points)). Then define
If all your functions are working properly it should be that > transpose_list([6,4,2,1,1,1,1]);
returns [7, 3, 2, 2, 1, 1] (but, of course, it should work on any input).
Finally write a function of $n$ (where $n$ is a positive integer) called number_self_conjugates
that counts the number of partitions of $n$ such that transpose_list(partitition) = partition.
* Write a function is_odd that accepts an integer $n$ and returns true if
$n$ is odd.
* Write a function are_all_odd that returns true if all elements in a list are odd.
* Write a function which number_odd_partitions which returns the number of
partitions of $n$ which are odd.
Calculate the number of odd partitions of $n$
for $n$ between 1 and 15.
Now write a function odd_partitions(n)
that list the odd partitions of n.
You should open up a new worksheet and start from scratch. You will have to save
your work in a file and upload that file on to the course
solution should be a sequence of commands where it is easy to change the input
string and after you execute the sequence of commands you should have the
correct output string. Please add documentation to your worksheet to explain how it
works. Just a few sentences is sufficient, but imagine that you were opening up the
worksheet for the first time and wanted to know what it did. You will be marked down
if what you write is not clear and coherent.
You should finish your assignment before class Wednesday October 17 by 11:59pm. Assignments
submitted after this date will be assessed a penalty of 10% per day.