redid comm, even exists proof

This commit is contained in:
wadler 2018-01-26 19:36:31 -02:00
parent 6ae06a2236
commit 71d92c3776

94
src/extra/Even.agda Normal file
View file

@ -0,0 +1,94 @@
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (; zero; suc; _+_; _*_)
open import Data.Product using (∃; _,_)
+-identity : (m : ) m + zero m
+-identity zero =
begin
zero + zero
≡⟨⟩
zero
+-identity (suc m) =
begin
suc m + zero
≡⟨⟩
suc (m + zero)
≡⟨ cong suc (+-identity m)
suc m
+-suc : (m n : ) m + suc n suc (m + n)
+-suc zero n =
begin
zero + suc n
≡⟨⟩
suc n
≡⟨⟩
suc (zero + n)
+-suc (suc m) n =
begin
suc m + suc n
≡⟨⟩
suc (m + suc n)
≡⟨ cong suc (+-suc m n)
suc (suc (m + n))
≡⟨⟩
suc (suc m + n)
+-comm : (m n : ) m + n n + m
+-comm m zero =
begin
m + zero
≡⟨ +-identity m
m
≡⟨⟩
zero + m
+-comm m (suc n) =
begin
m + suc n
≡⟨ +-suc m n
suc (m + n)
≡⟨ cong suc (+-comm m n)
suc (n + m)
≡⟨⟩
suc n + m
data even : Set where
ev0 : even zero
ev+2 : {n : } even n even (suc (suc n))
lemma : (m : ) 2 * suc m suc (suc (2 * m))
lemma m =
begin
2 * suc m
≡⟨⟩
suc m + (suc m + zero)
≡⟨⟩
suc (m + (suc (m + zero)))
≡⟨ cong suc (+-suc m (m + zero))
suc (suc (m + (m + zero)))
≡⟨⟩
suc (suc (2 * m))
ev-ex : {n : } even n (λ (m : ) 2 * m n)
ev-ex ev0 = (0 , refl)
ev-ex (ev+2 ev) with ev-ex ev
... | (m , refl) = (suc m , lemma m)
ex-ev : {n : } (λ (m : ) 2 * m n) even n
ex-ev (zero , refl) = ev0
ex-ev (suc m , refl) rewrite lemma m = ev+2 (ex-ev (m , refl))
-- I can't see how to avoid using rewrite in the second proof,
-- or how to use rewrite in the first proof!