Created
March 23, 2011 07:05
-
-
Save ikedaisuke/882733 to your computer and use it in GitHub Desktop.
reverse (reverse xs) ≡ xs in Agda
This file contains 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
{-# OPTIONS --universe-polymorphism #-} | |
module ReverseReverseId where | |
open import Data.List | |
open import Data.List.Properties | |
open import Relation.Binary.PropositionalEquality | |
as P using (_≡_; refl; cong) | |
ReverseReverseId : ∀ {a} {A : Set a} (xs : List A) -> | |
reverse (reverse xs) ≡ xs | |
ReverseReverseId [] = refl | |
ReverseReverseId (x ∷ xs) = | |
begin | |
reverse (reverse (x ∷ xs)) | |
≡⟨ cong (λ zs → reverse zs) (unfold-reverse x xs) ⟩ | |
reverse (reverse xs ++ [ x ]) | |
≡⟨ reverse-++-commute (reverse xs) [ x ] ⟩ | |
reverse [ x ] ++ reverse (reverse xs) | |
≡⟨ cong (λ zs → reverse [ x ] ++ zs) (ReverseReverseId xs) ⟩ | |
reverse [ x ] ++ xs ≡⟨ refl ⟩ | |
x ∷ xs | |
∎ | |
where open P.≡-Reasoning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment