简体   繁体   English

在 Coq 中允许潜在的无限循环

[英]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.

相关问题 如何递归遍历潜在的无限树 - How to recursively traverse a potentially infinite tree 防止无限循环 - preventing infinite loops prolog 哪个是最佳的,无限递归或无限循环? - Which is more optimal, infinite recursion or infinite loops? 在Python中对无限循环使用无限递归是一种罪恶吗? - Is it a sin to use infinite recursion for infinite loops in Python? 检测Lua表爬网中的无限循环 - Detect infinite loops in lua table crawling 如何使用堆栈处理递归函数中的无限循环? - How can I handle infinite for loops in a recursive function with Stacks? 无限循环和没有停止条件的递归函数何时最终停止? - When will infinite loops, and recursive functions with no stop conditions, eventually stop? 反应将父级传递给孩子的道具导致无限循环 - React parent passing props to a child causes infinite loops 有没有办法让 for 循环和数组元素的数量在算法中可变? - java - Is there a way to allow for the number of for loops and array elements to be variable in algorithm? - java 有谁知道在使用递归调用时无限循环和 StackOverflow 错误发生了什么? - Does anyone know what's happening with infinite loops and StackOverflow error while using recursive call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM