如何做归纳证明

发布于 2025-01-21 23:01:44 字数 436 浏览 4 评论 0原文

我必须证明:

Lemma bsuccOK: forall l, value (bsucc l) = S (value l).

有一个归纳证明,但我不明白该怎么做。

这是BSUCC函数:

Fixpoint bsucc (l: list bool): list bool := match l with
|[]=>[]
|r::true=>(bsucc r)::false
|r::false=>r::true
end.

Lemma bsucc_test1: bsucc [false;true;false;true] = [true;true;false;true].

Proof.
easy.
Admitted.

它为代表二进制数字的布尔值列表提供了继任者。

任何帮助将不胜感激!

I have to show that :

Lemma bsuccOK: forall l, value (bsucc l) = S (value l).

with an induction proof, but I don't understand how to do it.

Here is the bsucc function:

Fixpoint bsucc (l: list bool): list bool := match l with
|[]=>[]
|r::true=>(bsucc r)::false
|r::false=>r::true
end.

Lemma bsucc_test1: bsucc [false;true;false;true] = [true;true;false;true].

Proof.
easy.
Admitted.

It gives the successor of a list of booleans representing a binary number.

Any help would be very appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聽兲甴掵 2025-01-28 23:01:44

您使用哪个二进制表示?
如果首先考虑最不重要的位,则例如4表示为[false; false; true; true]

这是bsuccvalue的定义。注意列表符号中的参数顺序,以及bsucc []的略有更改。希望没关系。

Require Import List Lia.
Import ListNotations. 

(** Least significant bit first  *)

Fixpoint bsucc (l: list bool):  list bool :=
  match l with
  | []  =>[true]
  | true::r => false:: (bsucc r)
  | false::r => true::r
  end.

Fixpoint value (s:list bool):  nat:=
  match s with
  | []   => 0
  | true::r => S (2 * value r)
  | false::r => 2 * value r
  end.

Compute value [false;false;true]. (* 4 *)

然后,通过l诱导,您的目标是可解决的。您也可以使用的策略是CBNsimpercase重写lia(用于线性算术)。

Which binary representation do you use ?
If you consider Least significant bits first, then for instance 4 is represented as [false;false;true].

Here is a definition of bsuccand value. Note the order of arguments in list notations, and a slight change in bsucc []. Hope it's OK.

Require Import List Lia.
Import ListNotations. 

(** Least significant bit first  *)

Fixpoint bsucc (l: list bool):  list bool :=
  match l with
  | []  =>[true]
  | true::r => false:: (bsucc r)
  | false::r => true::r
  end.

Fixpoint value (s:list bool):  nat:=
  match s with
  | []   => 0
  | true::r => S (2 * value r)
  | false::r => 2 * value r
  end.

Compute value [false;false;true]. (* 4 *)

Then, your goal is solvable, by induction on l. Tactics you may also use are cbnor simpl, case, rewrite, and lia(for linear arithmetic).

一场春暖 2025-01-28 23:01:44

感谢您,这里的答案终于找到了:

Lemma bsuccOK: forall l, value (bsucc l) = S (value l).
Proof.
induction l; auto.
destruct a.
-simpl.
rewrite IHl.
lia.
-simpl.
lia.
Qed.

Thanks to you, here the answer I finally found:

Lemma bsuccOK: forall l, value (bsucc l) = S (value l).
Proof.
induction l; auto.
destruct a.
-simpl.
rewrite IHl.
lia.
-simpl.
lia.
Qed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文