1 exercises

chapter: 1 function and lists

Problem 1.

a plus f x + x times y * x 
=
(a(plus(f(x)))) + (x(times(y)) * x) -- That's not confusing... at all.

3 4 + 5 + 6 -- Doesn't evaluate because 3(4) is not well defined.
=
(3(4) + (5)) + (6)

2^2^2^2
=
2^(2^(2^2))

Problem 2.

Let f,g,h be functions such that h:AB,g:BC,f:CD for some sets A,B,C,D. Define F1=f(gh),F2=(fg)h.

The domain of f(gh) is the domain of gh, which in turn is the domain of h, which is equal to A. Similarly, the domain of (fg)h is equal to the domain of h, which is A. So F1 and F2 share domains.

The codomain of F1 is equal to the codomain of f, which is D. Similarly, the codomain of F2 is equal to the codomain of fg, which is equal to the codomain of f, which is equal to D. So F1 and F2 share codomains.

Then, let us consider an element xA and where F1 and F2 send it.

F1(x)=((fg)h)(x)=(fg)(h(x))=f(g(h(x)))=f(gh(x))=(f(gh))(x)=F2(x).

As such, F1=F2 and composition is associative.

Problem 3.

Define ++ as the concat operator. This is associative, which follows from an inductive proof. Consider as,bs to be lists, and induct on the length of cs. It is not commutative since [1,2][2,1], and its identity element is equal to the empty list [] . This does not have a zero element. In this way concatenation over a consistent type forms a free monoid.

Problem 4.

map double [3, 7, 4, 2] = [6, 14, 8, 4]
map (double.double) [3, 7, 4, 2] = [12, 28, 16, 8]
map double [] = [].

sum . map double = double . sum -- True, as the integers are a commutative ring
sum . map sum = sum . concat -- True, assuming type [[Integer]]
sum . sort = sum -- True as addition is commutative in the integers