我如何证明 b = c if (andb b c = orb b c) in coq?

How would I prove that b = c if (andb b c = orb b c) in coq?

我是 coq 的新手,我正在尝试证明这一点...

Theorem andb_eq_orb :
  forall (b c : bool),
  (andb b c = orb b c) -> (b = c).

这是我的证明,但是当我到达目标时我卡住了 (false = true -> false = true)。

Proof.
intros b c.
induction c.
destruct b.
reflexivity.
simpl.
reflexivity.

我不确定如何重写该表达式以便我可以使用自反性。但即使我这样做,我也不确定它是否会导致证明。

不过,如果我从假设 b = c 开始,我就能解决这个问题。即...

Theorem andb_eq_orb_rev :
  forall (b c : bool),
  (b = c) -> (andb b c = orb b c).
Proof.
intros.
simpl.
rewrite H.
destruct c.
reflexivity.
reflexivity.
Qed.

但是如果我从具有布尔函数的假设开始,我不知道如何解决。

您需要使用 intro 策略。这会将 false = true 作为假设移动到您的证明上下文中,然后您可以使用它来重写。

这可能不是最有效的方法。

在第 induction c. 步(卡住的地方):

______________________________________(1/2)
b && true = b || true -> b = true
______________________________________(2/2)
b && false = b || false -> b = false

您可以使用 rewrite 和 [bool][1] 中的基本定理来简化术语,例如 b && trueb,以及 b || truetrue.

这可以减少到两个 "trivial" 子目标:

b : bool
______________________________________(1/2)
b = true -> b = true
______________________________________(2/2)
false = b -> b = false

这几乎是使用 assumption 的微不足道的证明,除了它是一个 symmetry 之外。您可以 try 如果 symmetry 将使它们匹配使用:

try (symmetry;assumption); try assumption.

(真正了解 Coq 的人可能会告诉我如何更简洁地 try

放在一起:

Require Import Bool.
Theorem andb_eq_orb : forall b c, andb b c = orb b c -> b = c.
Proof. 
destruct c; 

try (rewrite andb_true_r);
try (rewrite orb_true_r);
try (rewrite andb_false_r);
try (rewrite orb_false_r);
intro H;
try (symmetry;assumption); try assumption.
Qed.

第二种方法是暴力破解并使用"Truth table"方法。这意味着您可以将所有变量分解为其真值,并简化为:destruct b, c; simpl.。这再次给出了四个微不足道的含义,最多一个 symmetrytry:

4 subgoal
______________________________________(1/4)
true = true -> true = true
______________________________________(2/4)
false = true -> true = false
______________________________________(3/4)
false = true -> false = true
______________________________________(4/4)
false = false -> false = false

放在一起:

Theorem andb_eq_orb1 : forall b c, andb b c = orb b c -> b = c.
Proof. 
destruct b, c; simpl; intro; try (symmetry;assumption); try assumption.
Qed.

第一种方法比较麻烦,但它不涉及枚举所有真相 table 行(我认为)。

您不需要归纳法,因为 bool 不是递归数据结构。只需查看 bc 值的不同情况。使用 destruct 来做到这一点。在两种情况下,假设 H 将属于 true = false 类型,您可以使用 inversion H 完成证明。在其他两种情况下,目标将是 true = true 类型,可以用 reflexivity.

来解决
Theorem andb_eq_orb : forall b c, andb b c = orb b c -> b = c.
Proof. destruct b,c;  intro H; inversion H; reflexivity. Qed.