created EvenOdd

This commit is contained in:
wadler 2018-01-05 19:29:29 -02:00
parent e43a20aa2e
commit 75f59e722d
2 changed files with 39 additions and 1 deletions

38
src/EvenOdd.agda Normal file
View file

@ -0,0 +1,38 @@
open import Data.Nat using (; zero; suc; _+_; _*_)
open import Data.Product using (∃; _,_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
+-identity : (n : ) n + zero n
+-identity zero = refl
+-identity (suc n) rewrite +-identity n = refl
+-suc : (m n : ) n + suc m suc (n + m)
+-suc m zero = refl
+-suc m (suc n) rewrite +-suc m n = refl
+-comm : (m n : ) m + n n + m
+-comm zero n rewrite +-identity n = refl
+-comm (suc m) n rewrite +-suc m n | +-comm m n = refl
mutual
data even : Set where
zero : even zero
suc : {n : } odd n even (suc n)
data odd : Set where
suc : {n : } even n odd (suc n)
+-lemma : (m : ) suc (suc (m + (m + 0))) suc m + (suc m + 0)
+-lemma m rewrite +-identity m | +-suc m m = refl
+-lemma : (m : ) suc (suc (m + (m + 0))) suc m + (suc m + 0)
+-lemma m rewrite +-suc m (m + 0) = {!!}
mutual
is-even : (n : ) even n (λ (m : ) n 2 * m)
is-even zero zero = zero , refl
is-even (suc n) (suc oddn) with is-odd n oddn
... | m , n≡1+2*m rewrite n≡1+2*m | +-lemma m = suc m , refl
is-odd : (n : ) odd n (λ (m : ) n 1 + 2 * m)
is-odd (suc n) (suc evenn) with is-even n evenn
... | m , n≡2*m rewrite n≡2*m = m , refl

View file

@ -11,7 +11,7 @@ the next step is to define relations, such as *less than or equal*.
\begin{code}
open import Naturals using (; zero; suc; _+_; _*_; _∸_)
open import Properties using (+-comm; +-identity; +-suc)
open import Properties using (+-comm)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
\end{code}