Coq 证明f(f bool)=bool

Coq 证明f(f bool)=bool,coq,Coq,在coq中,我如何证明接受booltrue | false并返回booltrue | false(如下所示)的函数f,当对单个booltrue | false应用两次时,总是会返回相同的值true | false: (f:bool -> bool) 例如,函数f只能做4件事,让我们调用函数b的输入: 始终返回true 始终返回false 返回b(即如果b为真则返回真,反之亦然) 返回非b(即,如果b为真,则返回false,反之亦然) 因此,如果函数始终返回true: f (f boo

在coq中,我如何证明接受bool
true | false
并返回bool
true | false
(如下所示)的函数
f
,当对单个bool
true | false
应用两次时,总是会返回相同的值
true | false

(f:bool -> bool)
例如,函数
f
只能做4件事,让我们调用函数
b
的输入:

  • 始终返回
    true
  • 始终返回
    false
  • 返回
    b
    (即如果b为真则返回真,反之亦然)
  • 返回
    非b
    (即,如果b为真,则返回false,反之亦然)
因此,如果函数始终返回true:

f (f bool) = f true = true
如果函数总是返回false,我们将得到:

f (f bool) = f false = false
对于其他情况,函数返回
而不是b

f (f true) = f false = true
f (f false) = f true = false
在两种可能的输入情况下,我们总是以原始输入结束。如果我们假设函数返回
b
,情况也是如此

那么,你将如何在coq中证明这一点

Goal forall (f:bool -> bool) (b:bool), f (f b) = f b.
所有目标(f:bool->bool)(b:bool),f(f(fb))=fb。
证明。
介绍。
记住(f true)为ft。
记住(f false)为ff。
破坏ff;破坏ft;破坏b;
试着重写一个稍微短一点的证明:

Require Import Sumbool.

Goal forall (f : bool -> bool) (b:bool), f (f (f b)) = f b.
Proof.
  destruct b;                             (* case analysis on [b] *)
    destruct (sumbool_of_bool (f true));  (* case analysis on [f true] *)
    destruct (sumbool_of_bool (f false)); (* case analysis on [f false] *)
    congruence.                           (* equational reasoning *)
Qed.
在:


谢谢你的精彩作业!多么可爱的定理

这是对Coq使用C-zar声明性证明样式的证明。这比命令式的要长得多(尽管可能是因为我的技能太低)

定理bool_情形:对于所有a,a=true\/a=false。 证明。 让我们来看看。 每箱a。 假设它是假的。 因此,论文。 假设这是真的。 因此,论文。 结束案例。 最终证明。Qed。 所有(b:bool)的目标,f(f(fb))=fb。 证明。 b:布尔。 每箱b。 假设它是假的。 按bool_案例(f false=false\/f false=true)的每个案例。 假设(f false=false)。 因此(f(f(f假))=f假)。 假设H:(f false=true)。 按bool_案例的(f真=假\/f真=真)案例。 假设(f真=假)。 因此H的(f(f(f假))=f假)。 假设(f真=真)。 因此H的(f(f(f假))=f假)。 结束案例。 结束案例。 假设这是真的。 按bool_案例的(f真=假\/f真=真)案例。 假设H:(f真=假)。 按bool_案例(f false=false\/f false=true)的每个案例。 假设(f false=false)。 因此H的(f(f(f真))=f真)。 假设(f假=真)。 因此H的(f(f(f真))=f真)。 结束案例。 假设(f真=真)。 因此(f(f(f真))=f真)。 结束案例。 结束案例。 最终证明。Qed。
我已经意识到f(fb:bool)=b不能被证明,好像f总是返回真f(ffalse)==ftrue==true!=错误。但是,f(f(fb))=f(b)。也许这更接近你想要的问题?我不知道如何在Coq中证明这一点!顺便说一下,你要证明的属性有一个名字:幂等性。那是用什么语言写的?数学?更简洁的证明:
bymove=>f[];病例et:(f为真);案例ef:(f假);重写?et?ef.
一个基于相同思想的略短的证明:
简介f[];案例_eq(f真);案例(f假),;一致性。
Require Import Sumbool.

Goal forall (f : bool -> bool) (b:bool), f (f (f b)) = f b.
Proof.
  destruct b;                             (* case analysis on [b] *)
    destruct (sumbool_of_bool (f true));  (* case analysis on [f true] *)
    destruct (sumbool_of_bool (f false)); (* case analysis on [f false] *)
    congruence.                           (* equational reasoning *)
Qed.
Require Import ssreflect.

Goal forall (f:bool -> bool) (b:bool), f (f (f b)) = f b.
Proof.
move=> f.
by case et:(f true); case ef:(f false); case; rewrite ?et ?ef // !et ?ef.
Qed.
Theorem bool_cases : forall a, a = true \/ a = false. proof. let a:bool. per cases on a. suppose it is false. thus thesis. suppose it is true. thus thesis. end cases. end proof. Qed. Goal forall (b:bool), f (f (f b)) = f b. proof. let b:bool. per cases on b. suppose it is false. per cases of (f false = false \/ f false = true) by bool_cases. suppose (f false = false). hence (f (f (f false)) = f false). suppose H:(f false = true). per cases of (f true = false \/ f true = true) by bool_cases. suppose (f true = false). hence (f (f (f false)) = f false) by H. suppose (f true = true). hence (f (f (f false)) = f false) by H. end cases. end cases. suppose it is true. per cases of (f true = false \/ f true = true) by bool_cases. suppose H:(f true = false). per cases of (f false = false \/ f false = true) by bool_cases. suppose (f false = false). hence (f (f (f true)) = f true) by H. suppose (f false = true). hence (f (f (f true)) = f true) by H. end cases. suppose (f true = true). hence (f (f (f true)) = f true). end cases. end cases. end proof. Qed.