这是 Isabelle 代码生成的后续内容:容器的抽象引理?:
我想为the_question
以下理论生成代码:
theory Scratch imports Main begin
typedef small = "{x::nat. x < 10}" morphisms to_nat small
by (rule exI[where x = 0], simp)
code_datatype small
lemma [code abstype]: "small (to_nat x) = x" by (rule to_nat_inverse)
definition a_pred :: "small ⇒ bool"
where "a_pred = undefined"
definition "smaller j = [small i . i <- [0 ..< to_nat j]]"
definition "the_question j = (∀i ∈ set (smaller j). a_pred j)"
问题是方程smaller
不适合代码生成,因为它提到了抽象函数small
。
现在根据 Andreas 对我最后一个问题的回答和关于数据细化的论文,下一步是为小数集引入一种类型,并smaller
为该类型创建一个定义:
typedef small_list = "{l. ∀x∈ set l. (x::nat) < 10}" by (rule exI[where x = "[]"], auto)
code_datatype Abs_small_list
lemma [code abstype]: "Abs_small_list (Rep_small_list x) = x" by (rule Rep_small_list_inverse)
definition "smaller' j = Abs_small_list [ i . i <- [0 ..< to_nat j]]"
lemma smaller'_code[code abstract]: "Rep_small_list (smaller' j) = [ i . i <- [0 ..< to_nat j]]"
unfolding smaller'_def
by (rule Abs_small_list_inverse, cases j, auto elim: less_trans simp add: small_inverse)
现在smaller'
是可执行的。据我了解,我需要将操作重新定义small list
为操作small_list
:
definition "small_list_all P l = list_all P (map small (Rep_small_list l))"
lemma[code]: "the_question j = small_list_all a_pred (smaller' j)"
unfolding small_list_all_def the_question_def smaller'_code smaller_def Ball_set by simp
我可以为the_question
. 但是 的定义small_list_all
不适合代码生成,因为它提到了抽象态射small
。如何使small_list_all
可执行文件?
(请注意,我无法展开 的代码方程a_pred
,因为问题实际上发生在实际递归的代码方程中a_pred
。另外,我想避免涉及在运行时重新检查不变量的黑客行为。)