Isabelle 如何证明函数在其域上是全的?
我有以下理论:Isabelle 如何证明函数在其域上是全的?,isabelle,Isabelle,我有以下理论: theory Color imports Main begin datatype color = RED | GREEN function invert :: "color => color" where "invert RED = GREEN" | "invert GREEN = RED " apply (pat_completeness) apply auto done termination by lexicographic_or
theory Color
imports Main
begin
datatype color = RED | GREEN
function invert :: "color => color"
where
"invert RED = GREEN"
| "invert GREEN = RED "
apply (pat_completeness)
apply auto
done
termination by lexicographic_order
lemma invert_univ: "invert_dom = (λx. True)"
我想证明
invert
在它的整个域上是total的,因此invert\u dom
定义了数据类型color
上的通用集。我们如何进行这一证明?或者,我应该用其他方法来表述吗?首先,您确实不需要在这里使用函数。这个函数的终止证明很简单,可以自动找到,所以您只需编写
fun invert :: "color ⇒ color"
where
"invert RED = GREEN"
| "invert GREEN = RED"
或者,由于它在数据类型color
上是原始递归的:
primrec invert :: "color ⇒ color"
where
"invert RED = GREEN"
| "invert GREEN = RED"
甚至只是
definition invert :: "color ⇒ color" where
"invert c = (case c of RED ⇒ GREEN | GREEN ⇒ RED)"
在最后一种情况下,您必须使用引理invert_def
手动展开invert
的定义
现在谈谈你的实际问题:从技术上讲,在HOL中,每个函数都是总的。这是必然的,因为表达式完全没有价值的逻辑往往变得非常混乱。您可以通过在某些输入上返回undefined
来“模拟”非总和性,这是一些您一无所知的任意值undefined::int
是某个整数值–可以是0,也可以是42或任何其他整数。对于使用函数包定义的函数,仅当您未指定案例(例如,不给出一个案例的方程式)或函数未在某些输入上终止时(那么事情就会变得混乱;如果您想对函数进行任何推理,那么您必须证明它在您首先给出的输入上终止)
如果您已经给出了终止证明—在本例中,您已经给出了终止证明,因为函数通常会终止—那么invert_dom
谓词基本上是无用的。你不需要它
否则,您可以使用invert.domintros
规则证明invert\u dom
对给定的输入有效。由于在实践中很少需要它们,因此您必须使用函数(domintros)
而不是函数来手动打开它们的生成。然后你可以证明你提出的引理如下:
lemma "invert_dom = (λ_. True)"
proof
fix x show "invert_dom x = True"
by (cases x) (auto intro: invert.domintros)
qed
但是,*\u dom
谓词在实践中很少使用。谢谢。我认为我需要dom,因为我找到了AddShell.bit.psimps(1):bit dom(BITV?b?bv)⟹ bit(BITV?b?bv)=?b,我想证明这个蕴涵的RHS,其中RHS实际上是bit函数定义的一个子句。我将把这作为一个单独的问题发布。如果您有一个终止函数,则有\uuu.simps
规则。使用它们而不是。.psimps
。使用primrec和definition,我有bit_def-我没有它的函数-然后应用(simp add:bit_def)完成了这个技巧。函数
也会生成一个\u def
引理,但它是一个丑陋且无法使用的引理。如果你证明了终止,你肯定应该有.simps
引理,这些就是你想要用来展开定义的引理。