1. Cumulative Sums

Write a predicate sums(+List, ?SumList) that maps a list of integers to a list of cumulative sums. For example,

sums([1, 3, 5, 7], L)
L = [1, 4, 9, 16]

2. Vectors and Matrices

As we saw in the lecture, we can represent a vector in Prolog as a simple list, e.g. [2, 4, 6]. We can represent a matrix using a nested list; for example, the identity 2 x 2 matrix is

[ [ 1, 0 ],
  [ 0, 1 ] ]

Write predicates that can perform the following operations:

  1. add : matrix + matrix → matrix

  2. generate the N x N identity matrix, for a given integer N

  3. dot product: vector · vector → scalar, using foldl

3. Multiplication

In the lecture we saw that we can define the integers in Prolog using an atom z (zero) and a functor s (successor).

With this representation, define a predicate mul(a, b, c) that is true if a · b = c. Can you write it so that it works in all directions?