SF习题答案(2)(LF-Induction)

介绍

Coq是一个定理证明辅助助手,在对一些关键系统进行形式化证明时十分重要的证明工具。本博客是针对自《Software Foundation》的第一卷《LOGICAL FOUNDATIONS》中的习题进行解答,在阅读的过程中请参考书籍进行阅读。

Induction

Exercise 1: 2 stars, standard, recommended (basic_induction)

Prove the following using induction. You might need previously proven results.
Theorem mult_0_r : ∀n:nat,
n * 0 = 0.
Proof.
(* FILL IN HERE ) Admitted.
Theorem plus_n_Sm : ∀n m : nat,
S (n + m) = n + (S m).
Proof.
(
FILL IN HERE ) Admitted.
Theorem plus_comm : ∀n m : nat,
n + m = m + n.
Proof.
(
FILL IN HERE ) Admitted.
Theorem plus_assoc : ∀n m p : nat,
n + (m + p) = (n + m) + p.
Proof.
(
FILL IN HERE *) Admitted.

解析:证明策略” induction n as [| n’]”是数学归纳法的思想,实际的证明就是证明n为0时定理成立,以及假设n’=n-1时成立,证明n的定理成立。在证明定理plus_comm时,需要使用到n+0=n的定理,在示例中并没有相关已证号的定理,因此引入了定理plus_O_r : forall n : nat, n + 0 = n,并进行了证明,在后面的证明中可以直接使用。

Theorem mult_0_r : forall n:nat,
  n * 0 = 0.
Proof.
  intros n. induction n as [| n' IHn'].
  - reflexivity.
  - simpl. rewrite -> IHn'. reflexivity.  Qed.

Theorem plus_n_Sm : forall n m : nat,
  S (n + m) = n + (S m).
Proof.
  intros n m. induction n as [| n'].
  - simpl. reflexivity.
  - simpl. rewrite -> IHn'. reflexivity. Qed.

(*-start- myadd function *)
Theorem plus_O_r : forall n : nat, n + 0 = n.
Proof. 
  intros n. induction n as [| n'].
  - simpl. reflexivity.
  - simpl. rewrite -> IHn'. reflexivity. Qed.
(*-end- myadd function *)

Theorem plus_comm : forall n m : nat,
  n + m = m + n.
Proof.
  intros n m. induction n as [| n'].
  - simpl. rewrite -> plus_O_r. reflexivity.
  - simpl. rewrite -> IHn'. rewrite -> plus_n_Sm. reflexivity. Qed.

Theorem plus_assoc : forall n m p : nat,
  n + (m + p) = (n + m) + p.
Proof.
  intros n m. induction n as [| n'].
  - simpl. reflexivity.
  - simpl. intros p
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值