Equiv程序的等价关系
Set Warnings "-notation-overridden,-parsing".
From PLF Require Import Maps.
From Coq Require Import Bool.Bool.
From Coq Require Import Arith.Arith.
From Coq Require Import Init.Nat.
From Coq Require Import Arith.PeanoNat. Import Nat.
From Coq Require Import Arith.EqNat.
From Coq Require Import omega.Omega.
From Coq Require Import Lists.List.
From Coq Require Import Logic.FunctionalExtensionality.
Import ListNotations.
From PLF Require Import Imp.
一些关于习题的建议:
- 这里要进行的大多数 Coq 证明都与我们之前提供的类似。在做作业之前,
请先花点时间,非形式化地在纸上以及在 Coq 中思考我们的证明,
确保你完全理解了其中的每个细节。这会节省你大量的时间。
- 我们现在进行的 Coq 证明已经足够复杂,几乎不可能再单靠“感觉”
或乱撞的方式来完成证明了。你需要以“为何某个属性为真”以及“如何进行证明”
的想法开始。完成此任务的最佳方式是在开始形式化证明前,至少先在纸上写出
非形式化证明的梗概,即以直观的方式说服自己相信该定理成立,
然后再进行形式化证明。或者,你也可以拉一个好友,尝试说服他此定理成立,
然后形式化你的解释。
- 请使用自动化工具来减少工作量!如果你全部显式地写出证明中的所有情况, 那么本章中的证明会非常长。
行为的等价关系
定义
Definition aequiv (a1 a2 : aexp) : Prop :=
∀ (st : state),
aeval st a1 = aeval st a2.
Definition bequiv (b1 b2 : bexp) : Prop :=
∀ (st : state),
beval st b1 = beval st b2.
下面是一些算术和布尔表达式等价的简单例子。
Theorem aequiv_example: aequiv (X - X) 0.
Proof.
intros st. simpl. omega.
Qed.
intros st. simpl. omega.
Qed.
Theorem bequiv_example: bequiv (X - X = 0) true.
对指令而言,情况则有些微妙。我们无法简单地说“如果在相同的初始状态下,
两个指令求值的停机状态相同,那么这两个指令等价”,
因为有些指令在某些初始状态下运行时根本不会在任何状态下停机!
我们实际上需要的是:“若两个指令在任何给定的初始状态下,要么发散,
要么在相同的状态下停机,则二者行为等价。”简单来说,就是:
“若其中一个指令在某状态下停机,那么另一个也在该状态下停机,反之亦然。”
Definition cequiv (c1 c2 : com) : Prop :=
∀ (st st' : state),
(st =[ c1 ]=> st') ↔ (st =[ c2 ]=> st').
Theorem skip_left : ∀ c,
cequiv
(SKIP;; c)
c.
Proof.
(* 课上已完成 *)
intros c st st'.
split; intros H.
- (* -> *)
inversion H; subst.
inversion H2. subst.
assumption.
- (* <- *)
apply E_Seq with st.
apply E_Skip.
assumption.
Qed.
Theorem TEST_true_simple : ∀ c1 c2,
cequiv
(TEST true THEN c1 ELSE c2 FI)
c1.
Proof.
intros c1 c2.
split; intros H.
- (* -> *)
inversion H; subst. assumption. inversion H5.
- (* <- *)
apply E_IfTrue. reflexivity. assumption. Qed.
intros c1 c2.
split; intros H.
- (* -> *)
inversion H; subst. assumption. inversion H5.
- (* <- *)
apply E_IfTrue. reflexivity. assumption. Qed.
当然,人类程序员是不会写把断言(guard)直接写成 true 的条件分支的。
不过当断言'等价于真'的情况时就会写出来: '定理':若 b 等价于 BTrue,则 TEST b THEN c1 ELSE c2 FI 等价于 c1。
'证明':
下面是这个证明的形式化版本:
- (→) 我们必须证明,对于所有的 st 和 st',若 st =[
TEST b THEN c1 ELSE c2 FI ]=> st' 则 st =[ c1 ]=> st'。
- 假设 st =[ TEST b THEN c1 ELSE c2 FI ]=> st' 证明自 E_IfTrue
这条证明规则。若使用证明规则 E_IfTrue 其必备的前提条件 st =[ c1 ]=> st'
必为真,而这正好是我们的证明所需要的条件。
- 另一方面, 假设 st =[ TEST b THEN c1 ELSE c2 FI ]=> st' 证明自
E_IfFalse。我们能得知 beval st b = false 和 st =[ c2 ]=> st'。
- 假设 st =[ TEST b THEN c1 ELSE c2 FI ]=> st' 证明自 E_IfTrue
这条证明规则。若使用证明规则 E_IfTrue 其必备的前提条件 st =[ c1 ]=> st'
必为真,而这正好是我们的证明所需要的条件。
- (<-) 我们必须证明,对于所有 st 和 st',若st =[ c1 ]=> st'
则 IFB b THEN c1 ELSE c2 FI / st \\ st'。
Theorem TEST_true: ∀ b c1 c2,
bequiv b BTrue →
cequiv
(TEST b THEN c1 ELSE c2 FI)
c1.
Proof.
intros b c1 c2 Hb.
split; intros H.
- (* -> *)
inversion H; subst.
+ (* b 求值为 true *)
assumption.
+ (* b 求值为 false(矛盾) *)
unfold bequiv in Hb. simpl in Hb.
rewrite Hb in H5.
inversion H5.
- (* <- *)
apply E_IfTrue; try assumption.
unfold bequiv in Hb. simpl in Hb.
rewrite Hb. reflexivity. Qed.
intros b c1 c2 Hb.
split; intros H.
- (* -> *)
inversion H; subst.
+ (* b 求值为 true *)
assumption.
+ (* b 求值为 false(矛盾) *)
unfold bequiv in Hb. simpl in Hb.
rewrite Hb in H5.
inversion H5.
- (* <- *)
apply E_IfTrue; try assumption.
unfold bequiv in Hb. simpl in Hb.
rewrite Hb. reflexivity. Qed.
Theorem TEST_false : ∀ b c1 c2,
bequiv b BFalse →
cequiv
(TEST b THEN c1 ELSE c2 FI)
c2.
Proof.
(* 请在此处解答 *) Admitted.
☐
bequiv b BFalse →
cequiv
(TEST b THEN c1 ELSE c2 FI)
c2.
Proof.
(* 请在此处解答 *) Admitted.
☐
Theorem swap_if_branches : ∀ b e1 e2,
cequiv
(TEST b THEN e1 ELSE e2 FI)
(TEST BNot b THEN e2 ELSE e1 FI).
Proof.
(* 请在此处解答 *) Admitted.
☐
Theorem WHILE_false : ∀ b c,
bequiv b BFalse →
cequiv
(WHILE b DO c END)
SKIP.
Proof.
intros b c Hb. split; intros H.
- (* -> *)
inversion H; subst.
+ (* E_WhileFalse *)
apply E_Skip.
+ (* E_WhileTrue *)
rewrite Hb in H2. inversion H2.
- (* <- *)
inversion H; subst.
apply E_WhileFalse.
rewrite Hb.
reflexivity. Qed.
intros b c Hb. split; intros H.
- (* -> *)
inversion H; subst.
+ (* E_WhileFalse *)
apply E_Skip.
+ (* E_WhileTrue *)
rewrite Hb in H2. inversion H2.
- (* <- *)
inversion H; subst.
apply E_WhileFalse.
rewrite Hb.
reflexivity. Qed.
练习:2 星, advanced, optional (WHILE_false_informal)
写出 WHILE_false 的非形式化证明。☐
- 假设 st =[ WHILE b DO c END ]=> st' 使用规则 E_WhileFalse 证明。
那么根据假设得出 beval st b = false。但它与 b 等价于 BTrue 矛盾。
- 假设 st =[ WHILE b DO c END ]=> st' 使用规则 E_WhileTrue证明。 我们必有:
Lemma WHILE_true_nonterm : ∀ b c st st',
bequiv b BTrue →
~( st =[ WHILE b DO c END ]=> st' ).
Proof.
(* 课上已完成 *)
intros b c st st' Hb.
intros H.
remember (WHILE b DO c END)%imp as cw eqn:Heqcw.
induction H;
(* 大多数证明规则无法应用,我们可通过反演(inversion)来去除它们: *)
inversion Heqcw; subst; clear Heqcw.
(* 我们只关心这两个关于 WHILE 循环的证明规则: *)
- (* E_WhileFalse *) (* 矛盾 -- b 总为真! *)
unfold bequiv in Hb.
(* rewrite 能实例化 st 中的量词 *)
rewrite Hb in H. inversion H.
- (* E_WhileTrue *) (* 直接使用 IH *)
apply IHceval2. reflexivity. Qed.
练习:2 星, standard, optional (WHILE_true_nonterm_informal)
试解释 WHILE_true_nonterm 的含义。☐
练习:2 星, standard, recommended (WHILE_true)
请证明以下定理。'提示':你可能需要使用 WHILE_true_nonterm 。Theorem WHILE_true : ∀ b c,
bequiv b true →
cequiv
(WHILE b DO c END)
(WHILE true DO SKIP END).
Proof.
(* 请在此处解答 *) Admitted.
☐
Theorem loop_unrolling : ∀ b c,
cequiv
(WHILE b DO c END)
(TEST b THEN (c ;; WHILE b DO c END) ELSE SKIP FI).
Proof.
(* 课上已完成 *)
intros b c st st'.
split; intros Hce.
- (* -> *)
inversion Hce; subst.
+ (* 不执行循环 *)
apply E_IfFalse. assumption. apply E_Skip.
+ (* 执行循环 *)
apply E_IfTrue. assumption.
apply E_Seq with (st' := st'0). assumption. assumption.
- (* <- *)
inversion Hce; subst.
+ (* 执行循环 *)
inversion H5; subst.
apply E_WhileTrue with (st' := st'0).
assumption. assumption. assumption.
+ (* 不执行循环 *)
inversion H5; subst. apply E_WhileFalse. assumption. Qed.
split; intros Hce.
- (* -> *)
inversion Hce; subst.
+ (* 不执行循环 *)
apply E_IfFalse. assumption. apply E_Skip.
+ (* 执行循环 *)
apply E_IfTrue. assumption.
apply E_Seq with (st' := st'0). assumption. assumption.
- (* <- *)
inversion Hce; subst.
+ (* 执行循环 *)
inversion H5; subst.
apply E_WhileTrue with (st' := st'0).
assumption. assumption. assumption.
+ (* 不执行循环 *)
inversion H5; subst. apply E_WhileFalse. assumption. Qed.
Theorem seq_assoc : ∀ c1 c2 c3,
cequiv ((c1;;c2);;c3) (c1;;(c2;;c3)).
Proof.
(* 请在此处解答 *) Admitted.
☐
cequiv ((c1;;c2);;c3) (c1;;(c2;;c3)).
Proof.
(* 请在此处解答 *) Admitted.
☐
Theorem identity_assignment : ∀ x,
cequiv
(x ::= x)
SKIP.
Proof.
intros.
split; intro H; inversion H; subst.
- (* -> *)
rewrite t_update_same.
apply E_Skip.
- (* <- *)
assert (Hx : st' =[ x ::= x ]=> (x !-> st' x ; st')).
{ apply E_Ass. reflexivity. }
rewrite t_update_same in Hx.
apply Hx.
Qed.
Theorem assign_aequiv : ∀ (x : string) e,
aequiv x e →
cequiv SKIP (x ::= e).
Proof.
(* 请在此处解答 *) Admitted.
☐
aequiv x e →
cequiv SKIP (x ::= e).
Proof.
(* 请在此处解答 *) Admitted.
☐
练习:2 星, standard (equiv_classes)
[ [prog_a;prog_b;prog_c;prog_d;prog_e;prog_f;prog_g;prog_h] ;
[prog_i] ]
Definition prog_a : com :=
(WHILE ~(X ≤ 0) DO
X ::= X + 1
END)%imp.
Definition prog_b : com :=
(TEST X = 0 THEN
X ::= X + 1;;
Y ::= 1
ELSE
Y ::= 0
FI;;
X ::= X - Y;;
Y ::= 0)%imp.
Definition prog_c : com :=
SKIP%imp.
Definition prog_d : com :=
(WHILE ~(X = 0) DO
X ::= (X × Y) + 1
END)%imp.
Definition prog_e : com :=
(Y ::= 0)%imp.
Definition prog_f : com :=
(Y ::= X + 1;;
WHILE ~(X = Y) DO
Y ::= X + 1
END)%imp.
Definition prog_g : com :=
(WHILE true DO
SKIP
END)%imp.
Definition prog_h : com :=
(WHILE ~(X = X) DO
X ::= X + 1
END)%imp.
Definition prog_i : com :=
(WHILE ~(X = Y) DO
X ::= Y + 1
END)%imp.
Definition equiv_classes : list (list com)
(* 将本行替换成 ":= _你的_定义_ ." *). Admitted.
(* 请勿修改下面这一行: *)
Definition manual_grade_for_equiv_classes : option (nat×string) := None.
☐
行为等价是一种等价关系
Lemma refl_aequiv : ∀ (a : aexp), aequiv a a.
Proof.
intros a st. reflexivity. Qed.
intros a st. reflexivity. Qed.
Lemma sym_aequiv : ∀ (a1 a2 : aexp),
aequiv a1 a2 → aequiv a2 a1.
Proof.
intros a1 a2 H. intros st. symmetry. apply H. Qed.
intros a1 a2 H. intros st. symmetry. apply H. Qed.
Lemma trans_aequiv : ∀ (a1 a2 a3 : aexp),
aequiv a1 a2 → aequiv a2 a3 → aequiv a1 a3.
Proof.
unfold aequiv. intros a1 a2 a3 H12 H23 st.
rewrite (H12 st). rewrite (H23 st). reflexivity. Qed.
unfold aequiv. intros a1 a2 a3 H12 H23 st.
rewrite (H12 st). rewrite (H23 st). reflexivity. Qed.
Lemma refl_bequiv : ∀ (b : bexp), bequiv b b.
Lemma sym_bequiv : ∀ (b1 b2 : bexp),
bequiv b1 b2 → bequiv b2 b1.
Lemma trans_bequiv : ∀ (b1 b2 b3 : bexp),
bequiv b1 b2 → bequiv b2 b3 → bequiv b1 b3.
Proof.
unfold bequiv. intros b1 b2 b3 H12 H23 st.
rewrite (H12 st). rewrite (H23 st). reflexivity. Qed.
unfold bequiv. intros b1 b2 b3 H12 H23 st.
rewrite (H12 st). rewrite (H23 st). reflexivity. Qed.
Lemma refl_cequiv : ∀ (c : com), cequiv c c.
Lemma sym_cequiv : ∀ (c1 c2 : com),
cequiv c1 c2 → cequiv c2 c1.
Proof.
unfold cequiv. intros c1 c2 H st st'.
assert (st =[ c1 ]=> st' ↔ st =[ c2 ]=> st') as H'.
{ (* Proof of assertion *) apply H. }
apply iff_sym. assumption.
Qed.
unfold cequiv. intros c1 c2 H st st'.
assert (st =[ c1 ]=> st' ↔ st =[ c2 ]=> st') as H'.
{ (* Proof of assertion *) apply H. }
apply iff_sym. assumption.
Qed.
Lemma iff_trans : ∀ (P1 P2 P3 : Prop),
(P1 ↔ P2) → (P2 ↔ P3) → (P1 ↔ P3).
Proof.
intros P1 P2 P3 H12 H23.
inversion H12. inversion H23.
split; intros A.
apply H1. apply H. apply A.
apply H0. apply H2. apply A. Qed.
intros P1 P2 P3 H12 H23.
inversion H12. inversion H23.
split; intros A.
apply H1. apply H. apply A.
apply H0. apply H2. apply A. Qed.
Lemma trans_cequiv : ∀ (c1 c2 c3 : com),
cequiv c1 c2 → cequiv c2 c3 → cequiv c1 c3.
行为等价是一种一致性
aequiv a1 a1' | |
cequiv (x ::= a1) (x ::= a1') |
cequiv c1 c1' | |
cequiv c2 c2' | |
cequiv (c1;;c2) (c1';;c2') |
Theorem CAss_congruence : ∀ x a1 a1',
aequiv a1 a1' →
cequiv (CAss x a1) (CAss x a1').
Proof.
intros x a1 a2 Heqv st st'.
split; intros Hceval.
- (* -> *)
inversion Hceval. subst. apply E_Ass.
rewrite Heqv. reflexivity.
- (* <- *)
inversion Hceval. subst. apply E_Ass.
rewrite Heqv. reflexivity. Qed.
intros x a1 a2 Heqv st st'.
split; intros Hceval.
- (* -> *)
inversion Hceval. subst. apply E_Ass.
rewrite Heqv. reflexivity.
- (* <- *)
inversion Hceval. subst. apply E_Ass.
rewrite Heqv. reflexivity. Qed.
循环的一致性更有趣, 因为它需要使用归纳法。
'定理': 对于 WHILE,等价关系是一种一致性 -- 即,若 b1 等价于 b1' 且 c1
等价于 c1',那么 WHILE b1 DO c1 END 等价于 WHILE b1' DO c1' END。
'证明': 假设 b1 等价于 b1' 且 c1 等价于 c1'。我们必须证明,
对于每个 st 和 st',st =[ WHILE b1 DO c1 END ]=> st' 当且仅当
st =[ WHILE b1' DO c1' END ]=> st'。我们把两个方向分开考虑。
- (→) 我们通过对 st =[ WHILE b1 DO c1 END ]=> st' 使用归纳法证明
st =[ WHILE b1 DO c1 END ]=> st' 蕴含 st =[ WHILE b1' DO c1' END ]=> st'。
只有推导的最后所使用的规则为 E_WhileFalse 或 E_WhileTrue
时才需要进行特别讨论。
- E_WhileFalse:此时我们拥有假设的必备条件 beval st b1 = false
和 st = st'。但是,由于 b1 和 b1' 等价,我们有
beval st b1' = false,然后应用 E-WhileFalse 得出我们需要的
st =[ WHILE b1' DO c1' END ]=> st'。
- E_WhileTrue:此时我们拥有假设的必备条件 beval st b1 = true,以及
对于某些状态 st'0 的 st =[ c1 ]=> st'0 和 st'0 =[ WHILE b1 DO c1
END ]=> st',还有归纳假设 st'0 =[ WHILE b1' DO c1' END ]=> st'。
- E_WhileFalse:此时我们拥有假设的必备条件 beval st b1 = false
和 st = st'。但是,由于 b1 和 b1' 等价,我们有
beval st b1' = false,然后应用 E-WhileFalse 得出我们需要的
st =[ WHILE b1' DO c1' END ]=> st'。
- (<-) 反之亦然。 ☐
Theorem CWhile_congruence : ∀ b1 b1' c1 c1',
bequiv b1 b1' → cequiv c1 c1' →
cequiv (WHILE b1 DO c1 END) (WHILE b1' DO c1' END).
Proof.
(* 课上已完成 *)
unfold bequiv,cequiv.
intros b1 b1' c1 c1' Hb1e Hc1e st st'.
split; intros Hce.
- (* -> *)
remember (WHILE b1 DO c1 END)%imp as cwhile
eqn:Heqcwhile.
induction Hce; inversion Heqcwhile; subst.
+ (* E_WhileFalse *)
apply E_WhileFalse. rewrite <- Hb1e. apply H.
+ (* E_WhileTrue *)
apply E_WhileTrue with (st' := st').
× (* 执行展示循环 *) rewrite <- Hb1e. apply H.
× (* 执行主体 *)
apply (Hc1e st st'). apply Hce1.
× (* 执行之后的循环 *)
apply IHHce2. reflexivity.
- (* <- *)
remember (WHILE b1' DO c1' END)%imp as c'while
eqn:Heqc'while.
induction Hce; inversion Heqc'while; subst.
+ (* E_WhileFalse *)
apply E_WhileFalse. rewrite → Hb1e. apply H.
+ (* E_WhileTrue *)
apply E_WhileTrue with (st' := st').
× (* 执行展示循环 *) rewrite → Hb1e. apply H.
× (* 执行主体 *)
apply (Hc1e st st'). apply Hce1.
× (* 执行之后的循环 *)
apply IHHce2. reflexivity. Qed.
Theorem CSeq_congruence : ∀ c1 c1' c2 c2',
cequiv c1 c1' → cequiv c2 c2' →
cequiv (c1;;c2) (c1';;c2').
cequiv c1 c1' → cequiv c2 c2' →
cequiv (c1;;c2) (c1';;c2').
Proof.
(* 请在此处解答 *) Admitted.
☐
(* 请在此处解答 *) Admitted.
☐
Theorem CIf_congruence : ∀ b b' c1 c1' c2 c2',
bequiv b b' → cequiv c1 c1' → cequiv c2 c2' →
cequiv (TEST b THEN c1 ELSE c2 FI)
(TEST b' THEN c1' ELSE c2' FI).
Proof.
(* 请在此处解答 *) Admitted.
☐
bequiv b b' → cequiv c1 c1' → cequiv c2 c2' →
cequiv (TEST b THEN c1 ELSE c2 FI)
(TEST b' THEN c1' ELSE c2' FI).
Proof.
(* 请在此处解答 *) Admitted.
☐
Example congruence_example:
cequiv
(* 程序 1: *)
(X ::= 0;;
TEST X = 0
THEN
Y ::= 0
ELSE
Y ::= 42
FI)
(* 程序 1: *)
(X ::= 0;;
TEST X = 0
THEN
Y ::= X - X (* <--- 这里不同 *)
ELSE
Y ::= 42
FI).
Proof.
apply CSeq_congruence.
- apply refl_cequiv.
- apply CIf_congruence.
+ apply refl_bequiv.
+ apply CAss_congruence. unfold aequiv. simpl.
× symmetry. apply minus_diag.
+ apply refl_cequiv.
Qed.
练习:3 星, advanced, optional (not_congr)
我们已经证明了 cequiv 关系对指令同时满足等价关系和一致性。 你能想出一个对于指令满足等价关系但'不满足'一致性的关系吗?(* 请在此处解答 *)
☐
程序变换
Definition atrans_sound (atrans : aexp → aexp) : Prop :=
∀ (a : aexp),
aequiv a (atrans a).
Definition btrans_sound (btrans : bexp → bexp) : Prop :=
∀ (b : bexp),
bequiv b (btrans b).
Definition ctrans_sound (ctrans : com → com) : Prop :=
∀ (c : com),
cequiv c (ctrans c).
Fixpoint fold_constants_aexp (a : aexp) : aexp :=
match a with
| ANum n ⇒ ANum n
| AId x ⇒ AId x
| APlus a1 a2 ⇒
match (fold_constants_aexp a1,
fold_constants_aexp a2)
with
| (ANum n1, ANum n2) ⇒ ANum (n1 + n2)
| (a1', a2') ⇒ APlus a1' a2'
end
| AMinus a1 a2 ⇒
match (fold_constants_aexp a1,
fold_constants_aexp a2)
with
| (ANum n1, ANum n2) ⇒ ANum (n1 - n2)
| (a1', a2') ⇒ AMinus a1' a2'
end
| AMult a1 a2 ⇒
match (fold_constants_aexp a1,
fold_constants_aexp a2)
with
| (ANum n1, ANum n2) ⇒ ANum (n1 × n2)
| (a1', a2') ⇒ AMult a1' a2'
end
end.
Example fold_aexp_ex1 :
fold_constants_aexp ((1 + 2) × X)
= (3 × X)%imp.
Proof. reflexivity. Qed.
注意此版本的常量折叠不包括优化平凡的加法等 -- 为简单起见,
我们把注意力集中到单个优化上来。将其它简化表达式的方法加进来也不难,
只是定义和证明会更长。
Example fold_aexp_ex2 :
fold_constants_aexp (X - ((0 × 6) + Y))%imp = (X - (0 + Y))%imp.
Proof. reflexivity. Qed.
我们不仅可以将 fold_constants_aexp 优化成 bexp(如在 BEq 和 BLe
的情况下),还可以查找常量'布尔'表达式并原地求值。
Fixpoint fold_constants_bexp (b : bexp) : bexp :=
match b with
| BTrue ⇒ BTrue
| BFalse ⇒ BFalse
| BEq a1 a2 ⇒
match (fold_constants_aexp a1,
fold_constants_aexp a2) with
| (ANum n1, ANum n2) ⇒
if n1 =? n2 then BTrue else BFalse
| (a1', a2') ⇒
BEq a1' a2'
end
| BLe a1 a2 ⇒
match (fold_constants_aexp a1,
fold_constants_aexp a2) with
| (ANum n1, ANum n2) ⇒
if n1 <=? n2 then BTrue else BFalse
| (a1', a2') ⇒
BLe a1' a2'
end
| BNot b1 ⇒
match (fold_constants_bexp b1) with
| BTrue ⇒ BFalse
| BFalse ⇒ BTrue
| b1' ⇒ BNot b1'
end
| BAnd b1 b2 ⇒
match (fold_constants_bexp b1,
fold_constants_bexp b2) with
| (BTrue, BTrue) ⇒ BTrue
| (BTrue, BFalse) ⇒ BFalse
| (BFalse, BTrue) ⇒ BFalse
| (BFalse, BFalse) ⇒ BFalse
| (b1', b2') ⇒ BAnd b1' b2'
end
end.
Example fold_bexp_ex1 :
fold_constants_bexp (true && ~(false && true))%imp
= true.
Proof. reflexivity. Qed.
Example fold_bexp_ex2 :
fold_constants_bexp ((X = Y) && (0 = (2 - (1 + 1))))%imp
= ((X = Y) && true)%imp.
Proof. reflexivity. Qed.
为了折叠指令中的常量,我们需要对所有内嵌的表达式应用适当的折叠函数。
Open Scope imp.
Fixpoint fold_constants_com (c : com) : com :=
match c with
| SKIP ⇒
SKIP
| x ::= a ⇒
x ::= (fold_constants_aexp a)
| c1 ;; c2 ⇒
(fold_constants_com c1) ;; (fold_constants_com c2)
| TEST b THEN c1 ELSE c2 FI ⇒
match fold_constants_bexp b with
| BTrue ⇒ fold_constants_com c1
| BFalse ⇒ fold_constants_com c2
| b' ⇒ TEST b' THEN fold_constants_com c1
ELSE fold_constants_com c2 FI
end
| WHILE b DO c END ⇒
match fold_constants_bexp b with
| BTrue ⇒ WHILE BTrue DO SKIP END
| BFalse ⇒ SKIP
| b' ⇒ WHILE b' DO (fold_constants_com c) END
end
end.
Close Scope imp.
Example fold_com_ex1 :
fold_constants_com
(* 原程序: *)
(X ::= 4 + 5;;
Y ::= X - 3;;
TEST (X - Y) = (2 + 4) THEN SKIP
ELSE Y ::= 0 FI;;
TEST 0 ≤ (4 - (2 + 1)) THEN Y ::= 0
ELSE SKIP FI;;
WHILE Y = 0 DO
X ::= X + 1
END)%imp
= (* 常量折叠后: *)
(X ::= 9;;
Y ::= X - 3;;
TEST (X - Y) = 6 THEN SKIP
ELSE Y ::= 0 FI;;
Y ::= 0;;
WHILE Y = 0 DO
X ::= X + 1
END)%imp.
Proof. reflexivity. Qed.
Theorem fold_constants_aexp_sound :
atrans_sound fold_constants_aexp.
Proof.
unfold atrans_sound. intros a. unfold aequiv. intros st.
induction a; simpl;
(* ANum 和 AId 很显然 *)
try reflexivity;
(* 从 IH 和下面的观察出发很容易完成对 APlus、AMinus 和 AMult 情况的证明:
aeval st (APlus a1 a2)
= ANum ((aeval st a1) + (aeval st a2))
= aeval st (ANum ((aeval st a1) + (aeval st a2)))
(AMinus/minus 和 AMult/mult 同理) *)
try (destruct (fold_constants_aexp a1);
destruct (fold_constants_aexp a2);
rewrite IHa1; rewrite IHa2; reflexivity). Qed.
unfold atrans_sound. intros a. unfold aequiv. intros st.
induction a; simpl;
(* ANum 和 AId 很显然 *)
try reflexivity;
(* 从 IH 和下面的观察出发很容易完成对 APlus、AMinus 和 AMult 情况的证明:
aeval st (APlus a1 a2)
= ANum ((aeval st a1) + (aeval st a2))
= aeval st (ANum ((aeval st a1) + (aeval st a2)))
(AMinus/minus 和 AMult/mult 同理) *)
try (destruct (fold_constants_aexp a1);
destruct (fold_constants_aexp a2);
rewrite IHa1; rewrite IHa2; reflexivity). Qed.
练习:3 星, standard, optional (fold_bexp_Eq_informal)
下面是布尔表达式常量折叠中 BEq 情况的可靠性的证明。 请认真读完它再和之后的形式化证明作比较,然后补充完 BLe 情况的形式化证明 (尽量不看之前 BEq 情况的证明)。beval st (BEq a1 a2)
= beval st (fold_constants_bexp (BEq a1 a2)).
- 首先,假设对于某些 n1 和 n2 而言有 fold_constants_aexp a1 = ANum n1
和 fold_constants_aexp a2 = ANum n2。
fold_constants_bexp (BEq a1 a2)
= if n1 =? n2 then BTrue else BFalse
beval st (BEq a1 a2)
= (aeval st a1) =? (aeval st a2).
aeval st a1
= aeval st (fold_constants_aexp a1)
= aeval st (ANum n1)
= n1
aeval st a2
= aeval st (fold_constants_aexp a2)
= aeval st (ANum n2)
= n2,
beval st (BEq a1 a2)
= (aeval a1) =? (aeval a2)
= n1 =? n2.
beval st (if n1 =? n2 then BTrue else BFalse)
= if n1 =? n2 then beval st BTrue else beval st BFalse
= if n1 =? n2 then true else false
= n1 =? n2.
beval st (BEq a1 a2)
= n1 =? n2.
= beval st (if n1 =? n2 then BTrue else BFalse), - 另一方面,假设 fold_constants_aexp a1 和 fold_constants_aexp a2
之一并非常量。此时,我们必须证明
beval st (BEq a1 a2)
= beval st (BEq (fold_constants_aexp a1)
(fold_constants_aexp a2)),
(aeval st a1) =? (aeval st a2)
= (aeval st (fold_constants_aexp a1)) =?
(aeval st (fold_constants_aexp a2)).
aeval st a1 = aeval st (fold_constants_aexp a1)
aeval st a2 = aeval st (fold_constants_aexp a2),
Theorem fold_constants_bexp_sound:
btrans_sound fold_constants_bexp.
Proof.
unfold btrans_sound. intros b. unfold bequiv. intros st.
induction b;
(* BTrue 和 BFalse 是显然的 *)
try reflexivity.
- (* BEq *)
simpl.
(当存在许多构造子时,使用归纳法会让给变量取名编程一件琐事,
然而 Coq 并不总是能够选择足够好的变量名。我们可以使用 rename 重命名:
策略 rename a into a1 会将当前目标和上下文中的 a 重命名为 a1。)
remember (fold_constants_aexp a1) as a1' eqn:Heqa1'.
remember (fold_constants_aexp a2) as a2' eqn:Heqa2'.
replace (aeval st a1) with (aeval st a1') by
(subst a1'; rewrite <- fold_constants_aexp_sound; reflexivity).
replace (aeval st a2) with (aeval st a2') by
(subst a2'; rewrite <- fold_constants_aexp_sound; reflexivity).
destruct a1'; destruct a2'; try reflexivity.
(* 唯一有趣的是 a1 和 a2 在折叠后同时变为常量 *)
simpl. destruct (n =? n0); reflexivity.
- (* BLe *)
(* 请在此处解答 *) admit.
- (* BNot *)
simpl. remember (fold_constants_bexp b) as b' eqn:Heqb'.
rewrite IHb.
destruct b'; reflexivity.
- (* BAnd *)
simpl.
remember (fold_constants_bexp b1) as b1' eqn:Heqb1'.
remember (fold_constants_bexp b2) as b2' eqn:Heqb2'.
rewrite IHb1. rewrite IHb2.
destruct b1'; destruct b2'; reflexivity.
(* 请在此处解答 *) Admitted.
☐
remember (fold_constants_aexp a2) as a2' eqn:Heqa2'.
replace (aeval st a1) with (aeval st a1') by
(subst a1'; rewrite <- fold_constants_aexp_sound; reflexivity).
replace (aeval st a2) with (aeval st a2') by
(subst a2'; rewrite <- fold_constants_aexp_sound; reflexivity).
destruct a1'; destruct a2'; try reflexivity.
(* 唯一有趣的是 a1 和 a2 在折叠后同时变为常量 *)
simpl. destruct (n =? n0); reflexivity.
- (* BLe *)
(* 请在此处解答 *) admit.
- (* BNot *)
simpl. remember (fold_constants_bexp b) as b' eqn:Heqb'.
rewrite IHb.
destruct b'; reflexivity.
- (* BAnd *)
simpl.
remember (fold_constants_bexp b1) as b1' eqn:Heqb1'.
remember (fold_constants_bexp b2) as b2' eqn:Heqb2'.
rewrite IHb1. rewrite IHb2.
destruct b1'; destruct b2'; reflexivity.
(* 请在此处解答 *) Admitted.
☐
Theorem fold_constants_com_sound :
ctrans_sound fold_constants_com.
Proof.
unfold ctrans_sound. intros c.
induction c; simpl.
- (* SKIP *) apply refl_cequiv.
- (* ::= *) apply CAss_congruence.
apply fold_constants_aexp_sound.
- (* ;; *) apply CSeq_congruence; assumption.
- (* TEST *)
assert (bequiv b (fold_constants_bexp b)). {
apply fold_constants_bexp_sound. }
destruct (fold_constants_bexp b) eqn:Heqb;
try (apply CIf_congruence; assumption).
(* (如果 if 没有被优化掉,那么我们很容易使用 IH 和
fold_constants_bexp_sound 来得出证明。) *)
+ (* b 总为真 *)
apply trans_cequiv with c1; try assumption.
apply TEST_true; assumption.
+ (* b 总为假 *)
apply trans_cequiv with c2; try assumption.
apply TEST_false; assumption.
- (* WHILE *)
(* 请在此处解答 *) Admitted.
☐
再论 (0 + n) 优化的可靠性
练习:4 星, advanced, optional (optimize_0plus)
回顾'逻辑基础' Imp 一章中 optimize_0plus 的定义:Fixpoint optimize_0plus (e:aexp) : aexp :=
match e with
| ANum n ⇒
ANum n
| APlus (ANum 0) e2 ⇒
optimize_0plus e2
| APlus e1 e2 ⇒
APlus (optimize_0plus e1) (optimize_0plus e2)
| AMinus e1 e2 ⇒
AMinus (optimize_0plus e1) (optimize_0plus e2)
| AMult e1 e2 ⇒
AMult (optimize_0plus e1) (optimize_0plus e2)
end.
optimize_0plus_aexp
optimize_0plus_bexp
optimize_0plus_com
- 请为此优化器写一个有意义的测试用例。
- 证明此优化程序有可靠性。(这部分应该会'很简单' 。)
(* 请在此处解答 *)
☐
证明程序不等价
c1 = (X ::= 42 + 53;;
Y ::= Y + X)
c2 = (X ::= 42 + 53;;
Y ::= Y + (42 + 53))
Fixpoint subst_aexp (x : string) (u : aexp) (a : aexp) : aexp :=
match a with
| ANum n ⇒
ANum n
| AId x' ⇒
if eqb_string x x' then u else AId x'
| APlus a1 a2 ⇒
APlus (subst_aexp x u a1) (subst_aexp x u a2)
| AMinus a1 a2 ⇒
AMinus (subst_aexp x u a1) (subst_aexp x u a2)
| AMult a1 a2 ⇒
AMult (subst_aexp x u a1) (subst_aexp x u a2)
end.
Example subst_aexp_ex :
subst_aexp X (42 + 53) (Y + X)%imp
= (Y + (42 + 53))%imp.
Proof. reflexivity. Qed.
而这里是一个我们感兴趣的性质:它断言类似上述形式的 c1 和 c2
总是等价的。
Definition subst_equiv_property := ∀ x1 x2 a1 a2,
cequiv (x1 ::= a1;; x2 ::= a2)
(x1 ::= a1;; x2 ::= subst_aexp x1 a1 a2).
遗憾的是, 这个性质'并不'总是成立 -- 即,它并不是对所有的
x1、x2、a1 和 a2 都成立。
cequiv (x1 ::= a1;; x2 ::= a2)
(x1 ::= a1;; x2 ::= subst_aexp x1 a1 a2).
我们使用反证法来证明这一点。假设对于所有的 x1、x2、a1
和 a2,我们有
cequiv (x1 ::= a1;; x2 ::= a2)
(x1 ::= a1;; x2 ::= subst_aexp x1 a1 a2).
考虑以下程序:
X ::= X + 1;; Y ::= X
注意
empty_st =[ X ::= X + 1;; Y ::= X ]=> st1,
其中 st1 = (Y !-> 1 ; X !-> 1).
根据假设,我们知道
cequiv (X ::= X + 1;;
Y ::= X)
(X ::= X + 1;;
Y ::= X + 1)
同时,根据 cequiv 的定义,我们有
empty_st =[ X ::= X + 1;; Y ::= X + 1 ]=> st1.
但是我们也能推导出
empty_st =[ X ::= X + 1;; Y ::= X + 1 ]=> st2,
其中 st2 = (Y !-> 2 ; X !-> 1)。但由于 ceval 是确定性的,而
st1 ≠ st2 ,这就造成了矛盾! ☐
cequiv (x1 ::= a1;; x2 ::= a2)
(x1 ::= a1;; x2 ::= subst_aexp x1 a1 a2).
cequiv (x1 ::= a1;; x2 ::= a2)
(x1 ::= a1;; x2 ::= subst_aexp x1 a1 a2).
X ::= X + 1;; Y ::= X
empty_st =[ X ::= X + 1;; Y ::= X ]=> st1,
cequiv (X ::= X + 1;;
Y ::= X)
(X ::= X + 1;;
Y ::= X + 1)
empty_st =[ X ::= X + 1;; Y ::= X + 1 ]=> st1.
empty_st =[ X ::= X + 1;; Y ::= X + 1 ]=> st2,
Theorem subst_inequiv :
¬ subst_equiv_property.
Proof.
unfold subst_equiv_property.
intros Contra.
(* 这里有个反例:假设 subst_equiv_property
成立能够让我们证明以下两个程序等价... *)
remember (X ::= X + 1;;
Y ::= X)%imp
as c1.
remember (X ::= X + 1;;
Y ::= X + 1)%imp
as c2.
assert (cequiv c1 c2) by (subst; apply Contra).
(* ...我们来证明 c2 能够在两个不同的状态下停机:
st1 = (Y !-> 1 ; X !-> 1)
st2 = (Y !-> 2 ; X !-> 1). *)
remember (Y !-> 1 ; X !-> 1) as st1.
remember (Y !-> 2 ; X !-> 1) as st2.
assert (H1 : empty_st =[ c1 ]=> st1);
assert (H2 : empty_st =[ c2 ]=> st2);
try (subst;
apply E_Seq with (st' := (X !-> 1));
apply E_Ass; reflexivity).
apply H in H1.
(* 最后,因为程序求值的确定性而产生矛盾。 *)
assert (Hcontra : st1 = st2)
by (apply (ceval_deterministic c2 empty_st); assumption).
assert (Hcontra' : st1 Y = st2 Y)
by (rewrite Hcontra; reflexivity).
subst. inversion Hcontra'. Qed.
unfold subst_equiv_property.
intros Contra.
(* 这里有个反例:假设 subst_equiv_property
成立能够让我们证明以下两个程序等价... *)
remember (X ::= X + 1;;
Y ::= X)%imp
as c1.
remember (X ::= X + 1;;
Y ::= X + 1)%imp
as c2.
assert (cequiv c1 c2) by (subst; apply Contra).
(* ...我们来证明 c2 能够在两个不同的状态下停机:
st1 = (Y !-> 1 ; X !-> 1)
st2 = (Y !-> 2 ; X !-> 1). *)
remember (Y !-> 1 ; X !-> 1) as st1.
remember (Y !-> 2 ; X !-> 1) as st2.
assert (H1 : empty_st =[ c1 ]=> st1);
assert (H2 : empty_st =[ c2 ]=> st2);
try (subst;
apply E_Seq with (st' := (X !-> 1));
apply E_Ass; reflexivity).
apply H in H1.
(* 最后,因为程序求值的确定性而产生矛盾。 *)
assert (Hcontra : st1 = st2)
by (apply (ceval_deterministic c2 empty_st); assumption).
assert (Hcontra' : st1 Y = st2 Y)
by (rewrite Hcontra; reflexivity).
subst. inversion Hcontra'. Qed.
练习:4 星, standard, optional (better_subst_equiv)
之前我们思考的等价关系也不全是妄言 -- 只要再增加一个条件, 即变量 X 不在第一个赋值语句的右边出现,它就是正确的了。Inductive var_not_used_in_aexp (x : string) : aexp → Prop :=
| VNUNum : ∀ n, var_not_used_in_aexp x (ANum n)
| VNUId : ∀ y, x ≠ y → var_not_used_in_aexp x (AId y)
| VNUPlus : ∀ a1 a2,
var_not_used_in_aexp x a1 →
var_not_used_in_aexp x a2 →
var_not_used_in_aexp x (APlus a1 a2)
| VNUMinus : ∀ a1 a2,
var_not_used_in_aexp x a1 →
var_not_used_in_aexp x a2 →
var_not_used_in_aexp x (AMinus a1 a2)
| VNUMult : ∀ a1 a2,
var_not_used_in_aexp x a1 →
var_not_used_in_aexp x a2 →
var_not_used_in_aexp x (AMult a1 a2).
Lemma aeval_weakening : ∀ x st a ni,
var_not_used_in_aexp x a →
aeval (x !-> ni ; st) a = aeval st a.
Proof.
(* 请在此处解答 *) Admitted.
使用 var_not_used_in_aexp,形式化并证明正确版本的 subst_equiv_property。
(* 请在此处解答 *)
☐
扩展练习:非确定性 Imp
x = 0;;
f(++x, x)
HAVOC Y;;
Z ::= Y × 2
为了形式化 Himp,我们首先在指令定义中增加一条从句。
Inductive com : Type :=
| CSkip : com
| CAss : string → aexp → com
| CSeq : com → com → com
| CIf : bexp → com → com → com
| CWhile : bexp → com → com
| CHavoc : string → com. (* <--- 新增 *)
Notation "'SKIP'" :=
CSkip : imp_scope.
Notation "X '::=' a" :=
(CAss X a) (at level 60) : imp_scope.
Notation "c1 ;; c2" :=
(CSeq c1 c2) (at level 80, right associativity) : imp_scope.
Notation "'WHILE' b 'DO' c 'END'" :=
(CWhile b c) (at level 80, right associativity) : imp_scope.
Notation "'TEST' e1 'THEN' e2 'ELSE' e3 'FI'" :=
(CIf e1 e2 e3) (at level 80, right associativity) : imp_scope.
Notation "'HAVOC' l" :=
(CHavoc l) (at level 60) : imp_scope.
练习:2 星, standard (himp_ceval)
现在,我们必须扩展操作语义。前面我们已经提过了 ceval 关系的模版, 指定了大步语义。为了形式化 HAVOC 指令的行为,我们还需要在 ceval 的定义中添加哪些规则?Reserved Notation "st '=[' c ']=>' st'" (at level 40).
Open Scope imp_scope.
Inductive ceval : com → state → state → Prop :=
| E_Skip : ∀ st,
st =[ SKIP ]=> st
| E_Ass : ∀ st a1 n x,
aeval st a1 = n →
st =[ x ::= a1 ]=> (x !-> n ; st)
| E_Seq : ∀ c1 c2 st st' st'',
st =[ c1 ]=> st' →
st' =[ c2 ]=> st'' →
st =[ c1 ;; c2 ]=> st''
| E_IfTrue : ∀ st st' b c1 c2,
beval st b = true →
st =[ c1 ]=> st' →
st =[ TEST b THEN c1 ELSE c2 FI ]=> st'
| E_IfFalse : ∀ st st' b c1 c2,
beval st b = false →
st =[ c2 ]=> st' →
st =[ TEST b THEN c1 ELSE c2 FI ]=> st'
| E_WhileFalse : ∀ b st c,
beval st b = false →
st =[ WHILE b DO c END ]=> st
| E_WhileTrue : ∀ st st' st'' b c,
beval st b = true →
st =[ c ]=> st' →
st' =[ WHILE b DO c END ]=> st'' →
st =[ WHILE b DO c END ]=> st''
(* 请在此处解答 *)
where "st =[ c ]=> st'" := (ceval c st st').
Close Scope imp_scope.
作为合理性检查,以下断言对于你的定义来说应该是可证的:
Example havoc_example1 : empty_st =[ (HAVOC X)%imp ]=> (X !-> 0).
Proof.
(* 请在此处解答 *) Admitted.
Example havoc_example2 :
empty_st =[ (SKIP;; HAVOC Z)%imp ]=> (Z !-> 42).
Proof.
(* 请在此处解答 *) Admitted.
(* 请勿修改下面这一行: *)
Definition manual_grade_for_Check_rule_for_HAVOC : option (nat×string) := None.
☐
请证明你的想法。
请证明你的想法。(提示:你可能会用到 assert 的略。)
Theorem ptwice_cequiv_pcopy :
cequiv ptwice pcopy ∨ ¬cequiv ptwice pcopy.
Proof. (* 请在此处解答 *) Admitted.
☐
练习:4 星, advanced (p1_p2_term)
考虑一下指令:Definition p1 : com :=
(WHILE ¬ (X = 0) DO
HAVOC Y;;
X ::= X + 1
END)%imp.
Definition p2 : com :=
(WHILE ¬ (X = 0) DO
SKIP
END)%imp.
直觉上来说,p1 和 p2 的停机行为相同:要么无限循环,要么以相同的状态开始,
就在相同的状态下停机。我们可以用以下引理分别刻画 p1 和 p2 的停机行为:
Lemma p1_may_diverge : ∀ st st', st X ≠ 0 →
¬ st =[ p1 ]=> st'.
Proof. (* 请在此处解答 *) Admitted.
Lemma p2_may_diverge : ∀ st st', st X ≠ 0 →
¬ st =[ p2 ]=> st'.
Proof.
(* 请在此处解答 *) Admitted.
☐
Definition p3 : com :=
(Z ::= 1;;
WHILE ~(X = 0) DO
HAVOC X;;
HAVOC Z
END)%imp.
Definition p4 : com :=
(X ::= 0;;
Z ::= 1)%imp.
Theorem p3_p4_inequiv : ¬ cequiv p3 p4.
Proof. (* 请在此处解答 *) Admitted.
☐
练习:5 星, advanced, optional (p5_p6_equiv)
证明以下指令等价。(提示:正如我们之前提到的,我们为 Himp 定义的 cequiv 只考虑了可能的停机配置的集合:对于两个拥有相同起始状态 st 的程序而言,当且仅当二者可能的停机状态的集合相同时,二者才等价。 若 p5 停机,那么最终状态应当是什么?反过来说,p5 总是会停机吗?)Definition p5 : com :=
(WHILE ~(X = 1) DO
HAVOC X
END)%imp.
Definition p6 : com :=
(X ::= 1)%imp.
Theorem p5_p6_equiv : cequiv p5 p6.
Proof. (* 请在此处解答 *) Admitted.
☐
附加练习
练习:4 星, standard, optional (for_while_equiv)
此练习是 Imp 一章中可选练习 add_for_loop 的扩展, 就是那个让你扩展出类似 C 风格的 for 循环指令的练习。请证明指令:for (c1 ; b ; c2) {
c3
}
c1 ;
WHILE b DO
c3 ;
c2
END
(* 请在此处解答 *)
☐
☐
Theorem swap_noninterfering_assignments: ∀ l1 l2 a1 a2,
l1 ≠ l2 →
var_not_used_in_aexp l1 a2 →
var_not_used_in_aexp l2 a1 →
cequiv
(l1 ::= a1;; l2 ::= a2)
(l2 ::= a2;; l1 ::= a1).
Proof.
(* 请在此处解答 *) Admitted.
☐
练习:4 星, advanced, optional (capprox)
在这个练习中我们定义了一个非对称的程序等价变形, 叫做 '程序近似(program approximation)'。 当每个能让 c1 停机的初始状态也能让 c2 在相同的状态下停机时,我们就说程序 c1 '近似与' 程序 c2 。下面是程序近似的形式化定义:
例如,程序
c1 = WHILE ~(X = 1) DO
X ::= X - 1
END
近似于 c2 = X ::= 1,但是 c2 不近似于 c1,因为 c1
不会在 X = 0 时停机,而 c2 会。如果两个程序互相近似,那么它们等价。
请找出两个程序 c3 和 c4,它们互不近似。
c1 = WHILE ~(X = 1) DO
X ::= X - 1
END
Definition c3 : com
(* 将本行替换成 ":= _你的_定义_ ." *). Admitted.
Definition c4 : com
(* 将本行替换成 ":= _你的_定义_ ." *). Admitted.
Theorem c3_c4_different : ¬ capprox c3 c4 ∧ ¬ capprox c4 c3.
Proof. (* 请在此处解答 *) Admitted.
找出一个程序 cmin 近似于所有别的程序。
Definition cmin : com
(* 将本行替换成 ":= _你的_定义_ ." *). Admitted.
Theorem cmin_minimal : ∀ c, capprox cmin c.
Proof. (* 请在此处解答 *) Admitted.
最后,再找出程序近似的一个非平凡的属性(当从左到右时)。
Definition zprop (c : com) : Prop
(* 将本行替换成 ":= _你的_定义_ ." *). Admitted.
Theorem zprop_preserving : ∀ c c',
zprop c → capprox c c' → zprop c'.
Proof. (* 请在此处解答 *) Admitted.
☐
(* 2022-03-14 05:28:20 (UTC+00) *)