mutual recursion
This commit is contained in:
parent
64dc1651c3
commit
26c63340e8
3 changed files with 49 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -21,7 +21,8 @@ about to write your doctoral dissertation!
|
|||
## Natural Deduction
|
||||
|
||||
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
46
src/extra/Mutual2.agda
Normal 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 , {!!}
|
||||
|
Loading…
Reference in a new issue