25A. Equations about Lists

You are familiar with equations about real numbers from algebra. For example, you know that, for all real numbers x, y and z,

x + (y + z) = (x + y) + z

We can also write equations about lists. Here are a few that are true for all lists x and y.

2:[ ]  =  [2]
x:[ ]  =  [x]
[3, 4, 5]  =  3:[4, 5]
tail([3, 4, 5])  =  [4, 5]
tail(x:y)  =  y
head([3, 4, 5])  =  3
head(x:y)  =  x

Suppose that length(x) is the length of list x. Here are some equations about length.

length([2,4,6])  =  3
length([ ])  =  0
length(x:y)  =  length(y) + 1