FStar function strange behavior

怎甘沉沦 提交于 2020-07-10 06:59:11

问题


It seems incorrect that the following simple function is accepted as a terminating one:

val fnc : (nw: nat) -> (ni: nat) -> (ni_max: nat) -> bool
let rec fnc nw ni ni_max =
  match ni with 
  | ni_max -> false
  | _      -> fnc nw (nw + ni) ni_max

Surprisingly, the function does terminate upon evaluating it, for instance, by fnc 0 0 1 and returns false. What am I missing out?


回答1:


The ni_max in the first branch of the pattern is a fresh binder and has no relation to the parameter ni_max of the function. Your code is equivalent to:

let rec fnc nw ni ni_max =
  match ni with 
  | _ -> false
  | _      -> fnc nw (nw + ni) ni_max

which is a function that always returns false.

You probably intended to write

let rec fnc nw ni ni_max =
  if ni = ni_max then false
  else fnc nw (nw + ni) ni_max

and now the termination checker should complain.



来源:https://stackoverflow.com/questions/62473795/fstar-function-strange-behavior

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!