如何在COQ一个函数中进行编码,该函数汇总了由2个列表代表的整数和代表holdback的布尔值?

发布于 2025-01-22 13:54:56 字数 822 浏览 2 评论 0原文

我想设置递归函数badd_r:list bool - >列表bool->布尔 - >列表布尔,总和由2个列表代表的整数和布尔值代表保留。 我需要使用这两个函数B1ADD_R(两个列表的总和),BSUCC(二进制数字的后继商,由布尔列表表示)。 这是两个功能:

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

Definition b1add_r b1 b2 r :=
  match b1,b2 with
    true, true => (r,true)
  | true,false => (negb r, r)
  | false, true => (negb r,r)
  | false,false => (r, false)
end.

我不知道如何在COQ中编码此功能以及如何证明它...

Lemma badd_rOK: forall l1 l2 r,
  value (badd_r l1 l2 r) = value l1 + value l2 + (if r then 1 else 0).

Fixpoint value (l: list bool) :=
  match l with
  | [] => 0
  | true :: r => 1 + 2 * value r
  | false :: r => 2 * value r
end.

任何帮助都将不胜感激!

I want to set the recursive function badd_r: list bool -> list bool -> bool -> list bool that sum the integers represented by the 2 lists and boolean representing a holdback.
I need to use these two functions b1add_r(sum of two lists), bsucc(successor of a binary number represented by a list of booleans).
Here are the two functions:

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

Definition b1add_r b1 b2 r :=
  match b1,b2 with
    true, true => (r,true)
  | true,false => (negb r, r)
  | false, true => (negb r,r)
  | false,false => (r, false)
end.

I have no idea how to code this function in coq and how to prove it...

Lemma badd_rOK: forall l1 l2 r,
  value (badd_r l1 l2 r) = value l1 + value l2 + (if r then 1 else 0).

Fixpoint value (l: list bool) :=
  match l with
  | [] => 0
  | true :: r => 1 + 2 * value r
  | false :: r => 2 * value r
end.

Any help would be appreciated!

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

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

发布评论

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

评论(1

哥,最终变帅啦 2025-01-29 13:54:56

您的功能可能具有以下表格:

Fixpoint badd_r (l1 l2:list bool) (r : bool) : list bool :=
  match l1, l2 with
    nil, nil => (* base case 1 *)
  | a::r1, nil => (* base case 2 *)
  | nil, b::r2 => (* base case 3 *)
  | a::r1, b:: r2 => let (c, r') := b1add_r a b r
                     in (* recursive case *)
  end.

为了填充孔/注释,并计划证明正确性,您可以将算术属性与可能的情况相关联。
例如,平等(1+2*x)+(0+2*y)+1 = 0+2(x+y+1)对应于情况add_r(true) :: r)(false :: s)true = false ::(add_r rs true)

Your function may have the following form:

Fixpoint badd_r (l1 l2:list bool) (r : bool) : list bool :=
  match l1, l2 with
    nil, nil => (* base case 1 *)
  | a::r1, nil => (* base case 2 *)
  | nil, b::r2 => (* base case 3 *)
  | a::r1, b:: r2 => let (c, r') := b1add_r a b r
                     in (* recursive case *)
  end.

In order to fill the holes/comments, and plan to prove correctness, you may relate arithmetic properties with the possible cases.
For instance, the equality (1+2*x)+(0+2*y)+1= 0+2(x+y+1) corresponds to the case add_r (true::r) (false::s) true = false :: (add_r r s true)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文