0

I need to prove:

reverse(push(as,bs)) = push(reverse(bs), reverse(as))

where:

def push[T](as: List[T], bs: List[T]): 
  List [T] = as match {
      case Nil => bs
      case x::xs => x::push(xs, bs)
  }

def reverse[T](ls: List[T]): List[T] = ls match { case Nil => Nil case x::xs => push(reverse(xs), x::Nil) }

I am already stuck in the base case, since i cant figure out a lemma. The only thing I have this far is:

reverse(push(Nil,bs)) = reverse(bs)

and I'm stuck here since it felt eternity.

Does anyone have an idea for a lemma?

John L.
  • 39,205
  • 4
  • 34
  • 93

1 Answers1

1

I think what would help a lot is proving first that push(push(a, b), c) = push(a, push(b, c)).

Once you have that result, you can make an induction on as only in the equality reverse(push(as,bs)) = push(reverse(bs), reverse(as)).

I will add some details if necessary.

Nathaniel
  • 18,309
  • 2
  • 30
  • 58