通过《Software Foundation》学习Coq语言的基本用法——2.Induction 3.Lists

摘录自《Software Foundation》,旨在交流与学习Coq的基本用法; 强烈建议大家下载源码自己运行一遍

Induction

通过Simplification证明的局限性

前面已经通过simplification证明了0 + n = n,现在尝试证明n = n + 0

Theorem plus_n_O_firsttry : forall n:nat,
  n = n + 0.
Proof.
  intros n.
  simpl. (* Does nothing! *)
Abort.

可以看到,reflexivity在这里无能为力,因为nn + 0都是未知数,所以plus函数的match无法匹配。如果用destruct呢?

Theorem plus_n_O_secondtry : forall n:nat,
  n = n + 0.
Proof.
  intros n. destruct n as [| n'].
  - (* n = 0 *)
    reflexivity. (* so far so good... *)
  - (* n = S n' *)
    simpl.       (* ...but here we are stuck again *)
Abort.

运行以上代码会发现,destructn分为O(也就是0)与S n'(也就是非0)两种情况。n为0时可以证明,但n = S n'时仍然证明不了——即使将n'destruct

回忆数学归纳法的使用。Coq中也提供了类似的证明方法。

用induction进行归纳证明

注意这里的induction不是定义类型的inducive

Coq中提供了一个叫induction的tactic,它把上述定理的证明分成两个子目标:

  1. 证明P(O)成立
  2. 证明P(n')成立可以推导出P(S n')

下面是证明过程

Theorem plus_n_O : forall n:nat, n = n + 0.
Proof.
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值