Isabelle终止包含自身映射的数据类型上的函数

Isabelle终止包含自身映射的数据类型上的函数,isabelle,Isabelle,在Isabelle中是否可以定义终止递归函数fwhere f有一个t类型的单一参数,因此t类型的值可能包含到t类型的值的映射,以及 f对此类映射范围内的所有元素执行递归调用 例如在理论上考虑数据类型 TIE < /代码>: 我尝试了一个简单的函数height,用于计算尝试的高度(有有限多个输出边): 在这里,字典顺序不足以证明函数是终止的,但到目前为止,我还无法对trie(终止)制定任何本身不需要类似递归的度量。 在此我必须承认,我不确定我是否正确理解了Isabelle/HOL中的数据类型(

在Isabelle中是否可以定义终止递归函数
f
where

  • f
    有一个
    t
    类型的单一参数,因此
    t
    类型的值可能包含到
    t
    类型的值的映射,以及
  • f
    对此类映射范围内的所有元素执行递归调用

例如在理论上考虑数据类型<代码> TIE < /代码>:

我尝试了一个简单的函数
height
,用于计算尝试的高度(有有限多个输出边):

在这里,
字典顺序
不足以证明函数是终止的,但到目前为止,我还无法对
trie
(终止)制定任何本身不需要类似递归的度量。 在此我必须承认,我不确定我是否正确理解了Isabelle/HOL中的数据类型(即,上述定义的
trie
是否始终具有有限的高度)


是否有可能表明高度终止?

根据Peter Zeller的评论,我能够通过在定义中添加
(domintros)
来证明高度终止,然后使用事实
height.domintros
trie进行归纳,导致以下终止证明:

function (domintros) height :: "'a trie ⇒ nat" where
  "height (Nd _ edges) = (if dom edges = Set.empty ∨ ¬ finite (dom edges)
    then 0
    else 1 + Max (height ` ran edges))"
  by pat_completeness auto
termination apply auto
proof -
  fix x :: "'a trie"
  show "height_dom x"
  proof (induction)
    case (Nd b edges)

    have "(⋀x. x ∈ ran edges ⟹ height_dom x)"
    proof -
      fix x assume "x ∈ ran edges" 
      then have "∃a. edges a = Some x"
        unfolding ran_def by blast
      then have "∃a. Some x = edges a"
        by (metis (no_types))
      then have "Some x ∈ range edges"
        by blast
      then show "height_dom x"
        using Nd by auto
    qed
    then show ?case
      using height.domintros by blast
  qed
qed

您是否尝试过在声明中添加
函数(domintros)
选项,然后使用归纳法进行终止证明?非常感谢,这确实足以证明终止。你想提交你的评论作为答案,还是我可以根据你的评论自己回答这个问题?如果你能自己添加答案,包括工作终止证明,那就太好了。
theory Scratch
  imports "HOL-Data_Structures.Trie_Fun"
begin

function height :: "'a trie ⇒ nat" where
  "height (Nd _ edges) = (if dom edges = Set.empty ∨ ¬ finite (dom edges)
    then 0
    else 1 + Max (height ` ran edges))"
  by pat_completeness auto
termination (* ??? *)

end
function (domintros) height :: "'a trie ⇒ nat" where
  "height (Nd _ edges) = (if dom edges = Set.empty ∨ ¬ finite (dom edges)
    then 0
    else 1 + Max (height ` ran edges))"
  by pat_completeness auto
termination apply auto
proof -
  fix x :: "'a trie"
  show "height_dom x"
  proof (induction)
    case (Nd b edges)

    have "(⋀x. x ∈ ran edges ⟹ height_dom x)"
    proof -
      fix x assume "x ∈ ran edges" 
      then have "∃a. edges a = Some x"
        unfolding ran_def by blast
      then have "∃a. Some x = edges a"
        by (metis (no_types))
      then have "Some x ∈ range edges"
        by blast
      then show "height_dom x"
        using Nd by auto
    qed
    then show ?case
      using height.domintros by blast
  qed
qed