Isabelle 如何为存在量词生成代码
以下是一个示例理论:Isabelle 如何为存在量词生成代码,isabelle,Isabelle,以下是一个示例理论: datatype ty = A | B | C inductive test where "test A B" | "test B C" inductive test2 where "¬(∃z. test x z) ⟹ test2 x" code_pred [show_modes] test . code_pred [show_modes] test2 . values "{x. test2 A}" 生成的代码尝试在ty上枚举。因此它失败了 我试图定义测试
datatype ty = A | B | C
inductive test where
"test A B"
| "test B C"
inductive test2 where
"¬(∃z. test x z) ⟹ test2 x"
code_pred [show_modes] test .
code_pred [show_modes] test2 .
values "{x. test2 A}"
生成的代码尝试在ty上枚举。因此它失败了
我试图定义测试谓词的可执行版本:
definition "test_ex x ≡ ∃y. test x y"
definition "test_ex_fun x ≡
Predicate.singleton (λ_. False)
(Predicate.map (λ_. True) (test_i_o x))"
lemma test_ex_code [code_abbrev, simp]:
"test_ex_fun = test_ex"
apply (intro ext)
unfolding test_ex_def test_ex_fun_def Predicate.singleton_def
apply (simp split: if_split)
但我不能证明引理。你能推荐一个更好的方法吗?嗯,values抱怨ty不是枚举类型。因此,在这种特殊情况下,最容易执行此实例化
instantiation ty :: enum
begin
definition enum_ty :: "ty list" where
"enum_ty = [A,B,C]"
definition "enum_all_ty f = list_all f [A,B,C]"
definition "enum_ex_ty f = list_ex f [A,B,C]"
instance
proof (intro_classes)
let ?U = "UNIV :: ty set"
show id: "?U = set enum_class.enum"
unfolding enum_ty_def
using ty.exhaust by auto
fix P
show "enum_class.enum_all P = Ball ?U P"
"enum_class.enum_ex P = Bex ?U P"
unfolding id enum_all_ty_def enum_ex_ty_def enum_ty_def by auto
show "distinct (enum_class.enum :: ty list)" unfolding enum_ty_def by auto
qed
之后,您的values命令的计算不会出现问题。嗯,values会抱怨ty不是排序enum。因此,在这种特殊情况下,最容易执行此实例化
instantiation ty :: enum
begin
definition enum_ty :: "ty list" where
"enum_ty = [A,B,C]"
definition "enum_all_ty f = list_all f [A,B,C]"
definition "enum_ex_ty f = list_ex f [A,B,C]"
instance
proof (intro_classes)
let ?U = "UNIV :: ty set"
show id: "?U = set enum_class.enum"
unfolding enum_ty_def
using ty.exhaust by auto
fix P
show "enum_class.enum_all P = Ball ?U P"
"enum_class.enum_ex P = Bex ?U P"
unfolding id enum_all_ty_def enum_ex_ty_def enum_ty_def by auto
show "distinct (enum_class.enum :: ty list)" unfolding enum_ty_def by auto
qed
之后,您的values命令的计算没有问题。我认为引理是不可证明的,我应该找到另一种方法。但可以证明如下:
lemma test_ex_code [code_abbrev, simp]:
"Predicate.singleton (λ_. False)
(Predicate.map (λ_. True) (test_i_o x)) = (∃y. test x y)"
apply (intro ext iffI)
unfolding Predicate.singleton_def
apply (simp_all split: if_split)
apply (metis SUP1_E mem_Collect_eq pred.sel test_i_o_def)
apply (intro conjI impI)
apply (smt SUP1_E the_equality)
apply (metis (full_types) SUP1_E SUP1_I mem_Collect_eq pred.sel test_i_o_def)
done
有趣的是,引理结构和证明结构似乎独立于具体谓词。我想任何谓词都可能有一个通解。我认为引理是不可证明的,我应该找到另一种方法。但可以证明如下:
lemma test_ex_code [code_abbrev, simp]:
"Predicate.singleton (λ_. False)
(Predicate.map (λ_. True) (test_i_o x)) = (∃y. test x y)"
apply (intro ext iffI)
unfolding Predicate.singleton_def
apply (simp_all split: if_split)
apply (metis SUP1_E mem_Collect_eq pred.sel test_i_o_def)
apply (intro conjI impI)
apply (smt SUP1_E the_equality)
apply (metis (full_types) SUP1_E SUP1_I mem_Collect_eq pred.sel test_i_o_def)
done
有趣的是,引理结构和证明结构似乎独立于具体谓词。我想任何谓词都可能有一个通用的解决方案。归纳谓词的参数上的存在量词可以通过引入另一个归纳谓词来执行。例如:
inductive test2_aux where "test x z ==> test2_aux x"
inductive test2 where "~ test2_aux x ==> test2 x"
使用适当的代码pred语句。test2_aux前提下的自由变量z的作用类似于存在变量。由于此转换是规范的,因此code_pred有一个预处理器来执行此操作:
code_pred [inductify] test2 .
做这项工作。归纳谓词参数上的存在量词可以通过引入另一个归纳谓词来执行。例如:
inductive test2_aux where "test x z ==> test2_aux x"
inductive test2 where "~ test2_aux x ==> test2 x"
使用适当的代码pred语句。test2_aux前提下的自由变量z的作用类似于存在变量。由于此转换是规范的,因此code_pred有一个预处理器来执行此操作:
code_pred [inductify] test2 .
完成任务。谢谢您的回答!但我不能将其作为enum的实例,因为它只是一个示例。实际类型不可枚举。我想一个存在可以不用枚举来检查。谢谢你的回答!但我不能将其作为enum的实例,因为它只是一个示例。实际类型不可枚举。我想一个存在可以不用枚举来检查。谢谢!它似乎在没有[icptify]的情况下也能工作。只有在使用原始定义而不使用中间谓词时,才需要使用icptify。事实上,归纳法应该精确地生成中间谓词。谢谢!它似乎在没有[icptify]的情况下也能工作。只有在使用原始定义而不使用中间谓词时,才需要使用icptify。事实上,归纳法应该精确地生成中间谓词。