LF-Induction
- 介绍
- Induction
-
- Exercise 1: 2 stars, standard, recommended (basic_induction)
- Exercise 2: 2 stars, standard (double_plus)
- Exercise 3: 2 stars, standard, optional (evenb_S)
- Exercise 4: 3 stars, standard, recommended (mult_comm)
- Exercise 5: 3 stars, standard, optional (more_exercises)
- Exercise 6: 2 stars, standard, optional (eqb_refl)
- Exercise 7: 2 stars, standard, optional (plus_swap')
- Exercise 8: 3 stars, standard, recommended (binary_commute)
- Exercise 9: 5 stars, advanced (binary_inverse)
介绍
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