[英]Allow potentially infinite loops in Coq
I'm asking your help because I would like to know if it would be possible to allow the definition of potentially infinite fixpoints in Coq, just to check if the current definition eventually produces an output.我请求您的帮助是因为我想知道是否可以允许在 Coq 中定义潜在的无限定点,只是为了检查当前定义是否最终会产生 output。
I've tried the new Unset Guard Checking
command, be what I'd like to disable precisely is the decreasing argument checking (because I actually have the error cannot guess decreasing argument of fix
.我已经尝试过新的Unset Guard Checking
命令,我想精确禁用的是递减参数检查(因为我实际上有错误cannot guess decreasing argument of fix
。
I understand that it is a bit of a shame to disable this feature in Coq, but it is just to get a small utility function to check whether the current definition is correct, to make sure that providing then a decreasing argument will work in further development.我知道在 Coq 中禁用此功能有点可惜,但这只是为了获得一个小实用程序 function 来检查当前定义是否正确,以确保提供递减参数将在进一步开发中起作用.
Unset Guard Checking
does disable the decreasing argument checking. Unset Guard Checking
确实会禁用递减参数检查。 You may have to explicitly specify the argument which you want the system to assume decreasing using {struct foo}
like this example.您可能必须像此示例一样使用{struct foo}
显式指定您希望系统假设减少的参数。
Unset Guard Checking.
Fixpoint y {A} (f : A -> A) {struct f} : A := f (y f).
However, if you don't have a strong reason, the better way to define a possibly infinite function is to add an argument to force termination.但是,如果您没有充分的理由,定义可能无限的 function 的更好方法是添加一个参数来强制终止。
Fixpoint y_opt {A} (lim : nat) (f : A -> A) : option A :=
match lim with
| O => None
| S lim' =>
match y_opt lim' f with
| None => None
| Some x => Some (f x)
end
end.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.