如何在COQ一个函数中进行编码,该函数汇总了由2个列表代表的整数和代表holdback的布尔值?
我想设置递归函数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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的功能可能具有以下表格:
为了填充孔/注释,并计划证明正确性,您可以将算术属性与可能的情况相关联。
例如,平等
(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:
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 caseadd_r (true::r) (false::s) true = false :: (add_r r s true)