Skip to content

Instantly share code, notes, and snippets.

@bruno-cadorette
Created January 10, 2020 22:40
Show Gist options
  • Select an option

  • Save bruno-cadorette/6ba0859953c53ad76b07adb0a6f14f34 to your computer and use it in GitHub Desktop.

Select an option

Save bruno-cadorette/6ba0859953c53ad76b07adb0a6f14f34 to your computer and use it in GitHub Desktop.
remove last algorithm equivalence proof
Require Import Coq.Lists.List.
Import Coq.Lists.List.ListNotations
Fixpoint my_remove_last {A : Type} (l : list A) : list A:=
match l with
| [] => []
| x :: [] => []
| x :: xs => x :: (my_remove_last xs)
end.
Definition bad_remove_last {A : Type} (l : list A) : list A :=
match rev l with
| [] => []
| _ :: xs => rev xs
end.
Theorem equivalent_remove_last : forall (A : Type) (l : list A),
my_remove_last l = bad_remove_last l.
Proof.
intros. induction l.
- unfold bad_remove_last. reflexivity.
- simpl. rewrite -> IHl. destruct l.
+ reflexivity.
+ unfold bad_remove_last. simpl. destruct (rev l).
* reflexivity.
* simpl.
rewrite -> rev_app_distr.
rewrite -> rev_app_distr.
rewrite -> rev_app_distr. reflexivity.
Qed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment