[英]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).
這是我的證明,但是當我到達目標時我被卡住了(假=真 - >假=真)。
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.
但是,如果我從具有布爾函數的假設開始,我無法弄清楚如何解決。
您不需要歸納,因為bool
不是遞歸數據結構。 只需通過b
和c
值的不同情況。 使用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.
你會想要使用intro
策略。 這會將false = true
移動到您的證明上下文中,作為您可以用來重寫的假設。
這可能不是最有效的方法。
在步進induction c.
(它被卡住了):
______________________________________(1/2)
b && true = b || true -> b = true
______________________________________(2/2)
b && false = b || false -> b = false
您可以在[bool] [1]中使用rewrite
和基本定理來簡化諸如b && true
到b
和b || true
術語。 b || true
要true
。
這可以將它減少到兩個“微不足道”的子目標:
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.
第二種方法是強制它並使用“真值表”方法。 這意味着您可以將所有變量分解為其真值,並簡化: destruct b, c; simpl.
destruct b, c; simpl.
。 這再次給出了四個微不足道的含義,最多可以try
一個symmetry
:
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.
第一種方法更麻煩,但它不涉及枚舉所有真值表行(我認為)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.