Coq 找到一个有充分根据的关系来证明函数在某点停止递减的终止
假设我们有:Coq 找到一个有充分根据的关系来证明函数在某点停止递减的终止,coq,termination,totality,Coq,Termination,Totality,假设我们有: Require Import ZArith Program. Program Fixpoint range (from to : Z) {measure f R} : list := if from <? to then from :: range (from + 1) to else []. 使用我的自定义: Definition preceeds_eq (l r : option nat) : Prop := match l, r with
Require Import ZArith Program.
Program Fixpoint range (from to : Z) {measure f R} : list :=
if from <? to
then from :: range (from + 1) to
else [].
使用我的自定义:
Definition preceeds_eq (l r : option nat) : Prop :=
match l, r with
| None, None => False
| None, (Some _) => True
| (Some _), None => False
| (Some x), (Some y) => x < y
end.
Definition-precedes\u-eq(lr:option-nat):道具:=
将l,r与
|无,无=>False
|无,(部分)=>正确
|(Some ux),None=>False
|(一些x),(一些y)=>x
演员们:
Definition Z_to_nat (z : Z) (p : 0 <= z) : nat.
Proof.
dependent destruction z.
- exact (0%nat).
- exact (Pos.to_nat p).
- assert (Z.neg p < 0) by apply Zlt_neg_0.
contradiction.
Defined.
Definition Z_to_nat(Z:Z)(p:0如果您使用Z.abs_nat
或Z.to_nat
函数将间隔的长度映射到nat
,并使用一个函数确定范围是否为空,结果类型信息更丰富(Z_lt_dec
),则解决方案变得非常简单:
Require Import ZArith Program.
Program Fixpoint range (from to : Z) {measure (Z.abs_nat (to - from))} : list Z :=
if Z_lt_dec from to
then from :: range (from + 1) to
else [].
Next Obligation. apply Zabs_nat_lt; auto with zarith. Qed.
使用Z_lt_dec
而不是其布尔计数器部分,可以将的证明从
传播到上下文中,从而使您能够轻松处理证明义务。我有60个范围从到
才意识到我不能有一个自反的有根据的关系…所有这些废话都可以用一行来代替…谢谢你,安东,现在如果你不介意的话,我需要卸载Coq:)。还有,计算决策程序到底是怎么回事(bool程序)某种程度上,它的表现力不如关于可判定性的陈述:(.Z_lt_dec
也是一个判定过程,但除了将结果标记为真或假之外(分别称为left
和right
)它还为结果附上了一个证明。它被很有启发性地称为sumbool
——有一次我试图解释它的用法(在它的后半部分)。
Require Import ZArith Program.
Program Fixpoint range (from to : Z) {measure (Z.abs_nat (to - from))} : list Z :=
if Z_lt_dec from to
then from :: range (from + 1) to
else [].
Next Obligation. apply Zabs_nat_lt; auto with zarith. Qed.