Lemma about list and rev list
Question
Trying to prove the following lemma I got stuck. Usully theorems about lists are proven using induction, but I don't know where to move next.
forall (T : Type) (h : T) (t : list T), h :: t = rev t ++ [h] -> t = rev tforall (T : Type) (h : T) (t : list T), h :: t = rev t ++ [h] -> t = rev tT: Type
h: T
t: list T
H: h :: t = rev t ++ [h]t = rev tT: Type
h: T
H: [h] = rev [] ++ [h][] = rev []T: Type
h, a: T
t: list T
H: h :: a :: t = rev (a :: t) ++ [h]
IHt: h :: t = rev t ++ [h] -> t = rev ta :: t = rev (a :: t)T: Type
h: T
H: [h] = rev [] ++ [h][] = rev []reflexivity.T: Type
h: T
H: [h] = rev [] ++ [h][] = []T: Type
h, a: T
t: list T
H: h :: a :: t = rev (a :: t) ++ [h]
IHt: h :: t = rev t ++ [h] -> t = rev ta :: t = rev (a :: t)T: Type
h, a: T
t: list T
H: h :: a :: t = rev (a :: t) ++ [h]
IHt: h :: t = rev t ++ [h] -> t = rev ta :: t = rev t ++ [a]T: Type
h, a: T
t: list T
H: h :: a :: t = (rev t ++ [a]) ++ [h]
IHt: h :: t = rev t ++ [h] -> t = rev ta :: t = rev t ++ [a]
Answer
Main answer
Before you start proving your theorem, you should try to thoroughly understand what your theorem says. Your theorem is simply wrong.
Counterexample: 2 :: [1;2] = rev [1;2] ++ [2], but [1;2] is not a palindrome.
Full proof:
Require Import List. Import ListNotations.~ (forall (T : Type) (h : T) (t : list T), h :: t = rev t ++ [h] -> t = rev t)~ (forall (T : Type) (h : T) (t : list T), h :: t = rev t ++ [h] -> t = rev t)H: forall (T : Type) (h : T) (t : list T), h :: t = rev t ++ [h] -> t = rev tFalseinversion H. Qed.H: [1; 2] = rev [1; 2]False
Minor issues
rev(t) should be just rev t. Just an aesthetic point, but probably you should get yourself more familiar to writing in functional programming style.
Usually theorems about lists are proven using induction
This is a pretty naive statement, though technically correct. There are so many ways to do induction on a value, and choosing the induction that works best is a crucial skill. To name a few: