Created
January 10, 2020 22:40
-
-
Save bruno-cadorette/6ba0859953c53ad76b07adb0a6f14f34 to your computer and use it in GitHub Desktop.
remove last algorithm equivalence proof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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