Created
May 22, 2020 12:02
-
-
Save gallais/e921eb54f22ae663ba75a2c28ac45802 to your computer and use it in GitHub Desktop.
Palindrome via an accumulator-based definition.
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 List. | |
Inductive PalAcc {A : Type} (acc : list A) : list A -> Type | |
:= Even : PalAcc acc acc | |
| Odd : forall x, PalAcc acc (x :: acc) | |
| Step : forall x xs, PalAcc (x :: acc) xs -> PalAcc acc (x :: xs) | |
. | |
Definition Pal {A : Type} (xs : list A) : Type := PalAcc nil xs. | |
Theorem PalAccRevAcc {A : Type} (acc xs : list A) : | |
PalAcc acc xs -> rev_append acc xs = rev_append xs acc. | |
Proof. | |
induction 1; trivial. | |
Qed. | |
Theorem PalRev {A : Type} (xs : list A) : | |
Pal xs -> rev xs = xs. | |
Proof. | |
intro prf; rewrite rev_alt, <- (PalAccRevAcc _ _ prf); reflexivity. | |
Qed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment