简体   繁体   English

如何使用Agda中N的归纳原理证明N的递归定义方程在命题上成立?

[英]How to prove that the defining equations of the recursor for N hold propositionally using the induction principle for N in Agda?

This is an exercise from the Homotopy Type Theory book. 这是来自同伦类型理论书的练习。 Here's what I have: 这是我所拥有的:

data ℕ : Set where
    zero : ℕ
    succ : ℕ → ℕ

iter : {C : Set} → C → (C → C) → ℕ → C
iter z f  zero    = z
iter z f (succ n) = f (iter z f n)

succℕ : {C : Set} → (ℕ → C → C) → ℕ × C → ℕ × C
succℕ f (n , x) = (succ n , f n x)

iterℕ : {C : Set} → C → (ℕ → C → C) → ℕ → ℕ × C
iterℕ z f = iter (zero , z) (succℕ f)

recℕ : {C : Set} → C → (ℕ → C → C) → ℕ → C
recℕ z f = _×_.proj₂ ∘ iterℕ z f

indℕ : {C : ℕ → Set} → C zero → ((n : ℕ) → C n → C (succ n)) → (n : ℕ) → C n
indℕ z f  zero    = z
indℕ z f (succ n) = f n (indℕ z f n)

recℕzfzero≡z : {C : Set} {z : C} {f : ℕ → C → C} → recℕ z f zero ≡ z
recℕzfzero≡z = refl

recℕzfsuccn≡fnrecℕzfn : {C : Set} {z : C} {f : ℕ → C → C} (n : ℕ) →
                        recℕ z f (succ n) ≡ f n (recℕ z f n)
recℕzfsuccn≡fnrecℕzfn = indℕ refl ?

I don't know how to prove that recℕ zf (succ n) ≡ fn (recℕ zfn) . 我不知道如何证明recℕ zf (succ n) ≡ fn (recℕ zfn) I need to prove: 我需要证明:

(n : ℕ) → recℕ z f (succ n) ≡ f n (recℕ z f n)
        → recℕ z f (succ (succ n)) ≡ f (succ n) (recℕ z f (succ n))

In English, given a natural number n and the induction hypothesis prove the consequent. 用英语,给定自然数n并归纳假设证明了结果。

The infix operator _∘_ is normal function composition. 中缀运算符_∘_是正常的函数组成。 The _≡_ and _×_ data types are defined as: _≡__×_数据类型定义为:

data _≡_ {A : Set} : A → A → Set where
    refl : {x : A} → x ≡ x

record _×_ (A B : Set) : Set where
    constructor _,_
    field
        _×_.proj₁ : A
        _×_.proj₂ : B

I've been thinking of a solution for quite a while but I can't figure out how to solve this problem. 我已经考虑了很长时间了,但是我不知道如何解决这个问题。

Let's get some help from Agda-mode for emacs: 让我们从用于emacs的Agda模式获得一些帮助:

recℕzfsuccn≡fnrecℕzfn : {C : Set} {z : C} {f : ℕ → C → C} (n : ℕ) →
                        recℕ z f (succ n) ≡ f n (recℕ z f n)
recℕzfsuccn≡fnrecℕzfn {f = f} n = {!!}

If we normalize the context in the hole by typing Cu Cu Cc C-, (each time I feel like I'm trying to invoke fatality in Mortal Kombat), we'll see (I cleaned up your definitions a bit) 如果我们通过键入Cu Cu Cc C-,来标准化洞中的上下文(每次我都想尝试在Mortal Kombat中调用死亡),我们将会看到(我稍微整理了一下定义)

Goal: f
      (proj₁
       (iter (0 , .z) (λ nx → succ (proj₁ nx) , f (proj₁ nx) (proj₂ nx))
        n))
      (proj₂
       (iter (0 , .z) (λ nx → succ (proj₁ nx) , f (proj₁ nx) (proj₂ nx))
        n))
      ≡
      f n
      (proj₂
       (iter (0 , .z) (λ nx → succ (proj₁ nx) , f (proj₁ nx) (proj₂ nx))
        n))

The second arguments to f are equal at both sides, so we can write f的第二个参数在两侧相等,因此我们可以写

recℕzfsuccn≡fnrecℕzfn {f = f} n = cong (λ m -> f m (recℕ _ f n)) {!!}

where 哪里

cong : ∀ {a b} {A : Set a} {B : Set b}
       (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl

Now the goal is 现在的目标是

Goal: proj₁ (iter (zero , .z) (succℕ f) n) ≡ n

which is a straightforward lemma 这是一个简单的引理

lem : {C : Set} {z : C} {f : ℕ → C → C} (n : ℕ)
    → proj₁ (iter (zero , z) (succℕ f) n) ≡ n
lem = indℕ refl (λ _ -> cong succ)

So 所以

recℕzfsuccn≡fnrecℕzfn : {C : Set} {z : C} {f : ℕ → C → C} (n : ℕ) →
                        recℕ z f (succ n) ≡ f n (recℕ z f n)
recℕzfsuccn≡fnrecℕzfn {f = f} n = cong (λ m -> f m (recℕ _ f n)) (lem n)

The whole code . 整个代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM