LF-Basic
- 介绍
- Bsaic
-
- Exercise 1: 1 star, standard (nandb)
- Exercise 2: 1 star, standard (andb3)
- Exercise 3: 1 star, standard (factorial)
- Exercise 4: 1 star, standard (ltb)
- Exercise 5: 1 star, standard (plus_id_exercise)
- Exercise 6: 2 stars, standard (mult_S_1)
- Exercise 7: 2 stars, standard (andb_true_elim2)
- Exercise 8: 1 star, standard (zero_nbeq_plus_1)
- Exercise 9: 1 star, standard (indentity_fn_applied_twice)
- Exercise 10: 1 star, standard (negation_fn_applied_twice)
- Exercise 11: 3 stars, standard, optional (andb_eq_orb)
- Exercise 12: 3 stars, standard (binary)
介绍
Coq是一个定理证明辅助助手,在对一些关键系统进行形式化证明时十分重要的证明工具。本博客时针对自《Software Foundation》的第一卷《LOGICAL FOUNDATIONS》中的习题进行解答,在阅读的过程中请参考书籍进行阅读。
Bsaic
Exercise 1: 1 star, standard (nandb)
Remove “Admitted.” and complete the definition of the following function; then make sure that the Example assertions below can each be verified by Coq. (I.e., fill in each proof, following the model of the orb tests above.) The function should return true if either or both of its inputs are false.
Definition nandb (b1:bool) (b2:bool) : bool
(* REPLACE THIS LINE WITH “:= your_definition .” ). Admitted.
Example test_nandb1: (nandb true false) = true.
( FILL IN HERE ) Admitted.
Example test_nandb2: (nandb false false) = true.
( FILL IN HERE ) Admitted.
Example test_nandb3: (nandb false true) = true.
( FILL IN HERE ) Admitted.
Example test_nandb4: (nandb true true) = false.
( FILL IN HERE *) Admitted.
解析:参考讲解中andb和orb的定义,根据几个测试的参数及输出得出定义,并更改测试中的证明语句,自动验证定义的正确。
Definition nandb (b1:bool) (b2:bool) : bool :=
match b1 with
| true => match b2 with
| true => false
| false => true
end
| false => match b2 with
| true => true
| false => true
end
end.
Example test_nandb1: (nandb true false) = true.
Proof. simpl. reflexivity. Qed.
Example test_nandb2: (nandb false false) = true.
Proof. simpl. reflexivity. Qed.
Example test_nandb3: (nandb false true) = true.
Proof. simpl. reflexivity. Qed.
Example test_nandb4: (nandb true true) = false.
Proof. simpl. reflexivity. Qed.
Exercise 2: 1 star, standard (andb3)
Do the same for the andb3 function below. This function should return true when all of its inputs are true, and false otherwise.
Definition andb3 (b1:bool) (b2:bool) (b3:bool) : bool
(* REPLACE THIS LINE WITH “:= your_definition .” ). Admitted.
Example test_andb31: (andb3 true true true) = true.
( FILL IN HERE ) Admitted.
Example test_andb32: (andb3 false true true) = false.
( FILL IN HERE ) Admitted.
Example test_andb33: (andb3 true false true) = false.
( FILL IN HERE ) Admitted.
Example test_andb34: (andb3 true true false) = false.
( FILL IN HERE *) Admitted.
解析:和上一题思考过程相似。
Definition andb3 (b1:bool) (b2:bool) (b3:bool) : bool :=
match b1 with
| false => false
| true => match b2 with
| false => false
| true => b3
end
end.
Example test_andb31: (andb3 true true true) = true.
Proof. simpl. reflexivity. Qed.
Example test_andb32: (andb3 false true true) = false.
Proof. simpl. reflexivity. Qed.
Example test_andb33: (andb3 true false true)