mutual recursion

This commit is contained in:
wadler 2018-01-12 15:37:26 -02:00
parent 64dc1651c3
commit 26c63340e8
3 changed files with 49 additions and 3 deletions

View file

@ -161,8 +161,7 @@ akin to associativity, commutativity, and distributivity.
## Conjunction is product
Given two propositions `A` and `B`, the conjunction `A × B` holds
if both `A` holds and `B` holds.
We formalise this idea by
if both `A` holds and `B` holds. We formalise this idea by
declaring a suitable inductive type.
\begin{code}
data _×_ : Set → Set → Set where

View file

@ -22,6 +22,7 @@ about to write your doctoral dissertation!
Here are the inference rules for Natural Deduction annotated with Agda terms.
M : A N : B
---------------- ×-I
(M , N) : A × B

46
src/extra/Mutual2.agda Normal file
View file

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