这是两个简单的谓词:
definition map_is_empty :: "(string ⇒ nat option) ⇒ bool" where
"map_is_empty env ≡ ∀x. env x = None"
value "map_is_empty Map.empty"
value "map_is_empty [''x''↦1]"
definition map_is_less_5 :: "(string ⇒ nat option) ⇒ bool" where
"map_is_less_5 env ≡ ∀x. ∃y. env x = Some y ∧ y < 5"
value "map_is_less_5 [''x''↦1,''y''↦2]"
value "map_is_less_5 [''x''↦1,''y''↦2,''z''↦7]"
问题是value
会返回错误,例如:
Wellsortedness error
(in code equation map_is_empty ?env ≡ ∀x. Option.is_none (?env x),
with dependency "Pure.dummy_pattern" -> "map_is_empty"):
Type char list not of sort enum
No type arity list :: enum
如何定义这些谓词以便能够使用value
或values
评估它们?
也许~~/src/HOL/Library/Finite_Map
和~~/src/HOL/Library/Mapping
可以提供帮助,但我使用它们会遇到类似的错误。
~~/src/HOL/Library/FinFun
似乎对我的任务很理想,但我得到了同样的错误:
definition ff_is_empty :: "(string ⇒f nat option) ⇒ bool" where
"ff_is_empty env ≡ ∀x. env $ x = None"
value "ff_is_empty (K$ None)"
答案 0 :(得分:2)
我得到了它! ~~/src/HOL/Library/FinFun
很棒。详细信息可在this presentation中找到。另请参阅&#34;正式化FinFuns - 生成代码
作为Isabelle / HOL&#34;的数据的功能作者:Andreas Lochbihler。
对于每个谓词,必须定义一个用∀
替换finfun_All
的引理。这个引理用于代码生成:
definition ff_is_empty :: "(string ⇒f nat option) ⇒ bool" where
"ff_is_empty env ⟷ (∀x. env $ x = None)"
lemma ff_is_empty_code [code]:
"ff_is_empty env ⟷ finfun_All ((λx. x = None) ∘$ env)"
by (auto simp add: ff_is_empty_def finfun_All_All)
value "ff_is_empty (K$ None)"
value "ff_is_empty (K$ None)(''x'' $:= Some 1)"
fun option_less :: "nat option ⇒ nat ⇒ bool" where
"option_less (Some a) b = (a < b)"
| "option_less _ _ = True"
definition ff_is_less_5 :: "(string ⇒f nat option) ⇒ bool" where
"ff_is_less_5 env ⟷ (∀x. option_less (env $ x) 5)"
lemma ff_is_less_5_code [code]:
"ff_is_less_5 env ⟷ finfun_All ((λx. option_less x 5) ∘$ env)"
by (auto simp add: ff_is_less_5_def finfun_All_All)
value "ff_is_less_5 (K$ None)(''x'' $:= Some 1)"
value "ff_is_less_5 (K$ None)(''x'' $:= Some 1)(''y'' $:= Some 2)(''z'' $:= Some 7)"