# Lists

You saw a couple of lists in the Intro workbook. Now we examine
lists in more detail. We do so because of the extent to which
Maxima relies on lists. Create the list ["This is", "a list that",
"contains", 5.0, "items."]. In this list four of the five items are
alphabetic strings, and one is a number. Most of the lists that
we use for analysis consist of numbers.

The text strings must be bracketed by " marks. If the 5.0 were so
bracketed, it would be treated as text and would not be 
available for mathematical manipulation.

Bind the list to the name aList.

First, set fpprintprec:4$

/*Input. Execute (ctrl-enter) for results */
fpprintprec:5$ kill(all)$
aList: ["This is", "a list that", "contains", 5.0, "items."];

Type these two commands 3*aList[2]; and 3*aList[4];. As far as
Maxima knows, contains is the name that has been assigned to an
expression, so it returns a computation of sorts, but one that 
has no meaning here.

/*Input. Execute (ctrl-enter) for results */
log(aList[3]); log(aList[4]);

Enter the command setify(aList);. Is the listed set equivalent to
the list? Why or why not?

/*Input. Execute (ctrl-enter) for results */
setify(aList);

Enter this command: ["This", "list", "is a", "list", "with",6,"items"];.
Convert this list to a set. In what two ways does the set differ from
the list?

/*Input. Execute (ctrl-enter) for results */
["This", "list", "is a", "list", "with",6,"items"];
setify(%);

Enter and execute this command: makelist(i,i,0,10);, which 
generates the counting numbers 0 through 10.

/*Input. Execute (ctrl-enter) for results */
makelist(i,i,0,10);

Replace the first i in the command above with each of the 
following: 5*i, 5*(i-5), 5*(i-5)^2, factorial(i) or i!, 
exp(1.0*i), log(1.0*i). For the last entry, log, change 
the range from 0,10 to 1,10 because log(0) is not defined.

/*Input. Execute (ctrl-enter) for results */
makelist(5*i,i,0,10);   makelist(5*(i-5),i,0,10);
makelist(5*(i-5),i,0,10);     makelist(5*(i-5)^2,i,0,10);
makelist(i!,i,0,10);    makelist(exp(1.0*i),i,0,10);
makelist(log(1.0*i),i,1,10);

Suppose that a simple production function, with a single input L, 
has this characteristic: f(L) = 100*sqrt(L). Create the command that
enters this relationship into Maxima's memory. Then create a list 
named Llist (note case) that L ranging from 5 to 50. Do this by 
replacing i with L in the first command in the preceding cell.

Now enter float(f(Llist)); and float(map(f,Llist));. Both commands 
should yield the same list of values. Assign the name yList to one
of the two. What is the interpretation of these numbers? 

/*Input. Execute (ctrl-enter) for results */
f(L):=100*sqrt(L);
Llist:makelist(5*L,L, 1,10);
yList: float(f(Llist));   float(map(f,Llist));

To confirm that the output per unit of L decreases as L increases
enter avgList: float(f(Llist)/Llist);, which instructs Maxima to compute
f(L) for each item in Llist and then divide that value by L. Confirm
the 

/*Input. Execute (ctrl-enter) for results */
avgList: float(f(Llist)/Llist);

Confirm the assertion regarding what Maxima is doing. Select two
or three items in yList and divide the values by the corresponding
values in Llist.

/*Input. Execute (ctrl-enter) for results */
yList[5]/Llist[5];

Of course, every list has a length, the number of items in the 
list. Maxima records this value and assigns it the name length.
This fact can be used to divide the interval {0, 1} into a 
a set of equally long subintervals.

Use the commands n:12$, makelist(k,k,0,n);, and %/(length(%)-1);
to create a list of 13 values (0 is included) that show the 
endpoints of 12 intervals. Assign this list the name intervalsList to the
last of the lists that you generate.

Change n to confirm that this treatment is general.

/*Input. Execute (ctrl-enter) for results */
n:5$       makelist(k,k,0,n);    intervalsList:%/(length(%)-1);

Sometimes knowing the sum of the items in a list is useful. Use the command
sum(intervalsList[i],i,1,length(intervalsList)); to confirm that the sum is (n+1)/2,
where n is the number of intervals and n+1 is the number of values (including
0) in the list.

/*Input. Execute (ctrl-enter) for results */
/*
Either of the two commands below works
*/
sum(intervalsList[i],i,1,length(intervalsList));
sum(intervalsList[i],i,1,n+1);