I have the following two functions in scala:
def sum(ls: List[Int]): Int = ls match
{
case Nil => 0
case l::ls => l + sum(ls)
}
def turn(ls: List[Int]) : List[Int] = ls match
{
case Nil => List()
case l::ls => append(turn(ls), List(l))
}
Function sum(ls)
is calculating the sum of its elements and turn(ls)
returns me a list with the elements in reversed order. sum(List(2, 13, 4))
is 19 and turn(List(2, 13, 4))
is List(4, 13, 2)
How can I show with (structural) induction that
sum(cs) == sum(turn(cs))
holds?