Skip to content

Instantly share code, notes, and snippets.

@ikedaisuke
Created March 23, 2011 07:05
Show Gist options
  • Save ikedaisuke/882733 to your computer and use it in GitHub Desktop.
Save ikedaisuke/882733 to your computer and use it in GitHub Desktop.
reverse (reverse xs) ≡ xs in Agda
{-# 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