Skip to content

Instantly share code, notes, and snippets.

@gabriel-fallen
Last active June 28, 2017 09:46
Show Gist options
  • Save gabriel-fallen/87e79c4dbcac608328c63f66795af70c to your computer and use it in GitHub Desktop.
Save gabriel-fallen/87e79c4dbcac608328c63f66795af70c to your computer and use it in GitHub Desktop.
A proof in Idris that `reverse . reverse = id`
module SampleTheorems
%default total
reverse' : List a -> List a
reverse' [] = []
reverse' (x :: xs) = reverse' xs ++ [x]
append_nil : xs ++ [] = xs
append_nil {xs = []} = Refl
append_nil {xs = (y :: ys)} = rewrite append_nil {xs=ys} in Refl
rev_distrib : (xs, ys : List a) -> reverse' (xs ++ ys) = reverse' ys ++ reverse' xs
rev_distrib [] ys = rewrite append_nil {xs=(reverse' ys)} in Refl
rev_distrib (z :: zs) ys = rewrite rev_distrib zs ys in
rewrite appendAssociative (reverse' ys) (reverse' zs) [z] in Refl
rev_rev_id : (lst : List a) -> reverse' (reverse' lst) = lst
rev_rev_id [] = Refl
rev_rev_id (x :: xs) = rewrite rev_distrib (reverse' xs) [x] in
rewrite rev_rev_id xs in Refl
@gabriel-fallen
Copy link
Author

Revision 3 is working with Idris 0.11 (current master at least).

@clayrat
Copy link

clayrat commented Jun 28, 2017

Works with 1.0 too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment