Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Isabelle 如何定义抽象集合数据类型?_Isabelle - Fatal编程技术网

Isabelle 如何定义抽象集合数据类型?

Isabelle 如何定义抽象集合数据类型?,isabelle,Isabelle,在我的理论中,有4种藏品。对于我为所有操作定义的每个集合类型count和: theory MyCollections imports Main "~~/src/HOL/Library/Dlist" "~~/src/HOL/Library/Multiset" begin typedef 'a mybag = "UNIV :: 'a multiset set" .. (* not unique, not ordered *) typedef 'a myseq = "UNIV :

在我的理论中,有4种藏品。对于我为所有操作定义的每个集合类型
count

theory MyCollections
  imports Main
    "~~/src/HOL/Library/Dlist"
    "~~/src/HOL/Library/Multiset"
begin

typedef 'a mybag = "UNIV :: 'a multiset set" .. (* not unique, not ordered *)
typedef 'a myseq = "UNIV :: 'a list set" ..     (* not unique, ordered *)
typedef 'a myset = "UNIV :: 'a set set" ..      (* unique, not ordered *)
typedef 'a myord = "UNIV :: 'a dlist set" ..    (* unique, ordered *)

setup_lifting type_definition_mybag
setup_lifting type_definition_myseq
setup_lifting type_definition_myset
setup_lifting type_definition_myord

lift_definition mybag_count :: "'a mybag ⇒ 'a ⇒ nat" is "Multiset.count" .
lift_definition myseq_count :: "'a myseq ⇒ 'a ⇒ nat" is "count_list" .
lift_definition myset_count :: "'a myset ⇒ 'a ⇒ nat" is "(λxs x. if x ∈ xs then 1 else 0)" .
lift_definition myord_count :: "'a myord ⇒ 'a ⇒ nat" is "(λxs x. if Dlist.member xs x then 1 else 0)" .

lift_definition mybag_for_all :: "'a mybag ⇒ ('a ⇒ bool) ⇒ bool" is "Multiset.Ball" .
lift_definition myseq_for_all :: "'a myseq ⇒ ('a ⇒ bool) ⇒ bool" is "(λxs f. list_all f xs)" .
lift_definition myset_for_all :: "'a myset ⇒ ('a ⇒ bool) ⇒ bool" is "Ball" .
lift_definition myord_for_all :: "'a myord ⇒ ('a ⇒ bool) ⇒ bool" is "(λxs f. list_all f (list_of_dlist xs))" .
我需要为这些集合类型定义多态操作(
包括
包括所有
):

lift_definition mybag_includes :: "'a mybag ⇒ 'a ⇒ bool" is
  "(λxs x. mybag_count xs x > 0)" .

lift_definition myseq_includes :: "'a myseq ⇒ 'a ⇒ bool" is
  "(λxs x. myseq_count xs x > 0)" .

lift_definition myset_includes :: "'a myset ⇒ 'a ⇒ bool" is
  "(λxs x. myset_count xs x > 0)" .

lift_definition myord_includes :: "'a myord ⇒ 'a ⇒ bool" is
  "(λxs x. myord_count xs x > 0)" .


lift_definition mybag_mybag_includes_all :: "'a mybag ⇒ 'a mybag ⇒ bool" is
  "(λxs ys. mybag_for_all ys (mybag_includes xs))" .

lift_definition mybag_myseq_includes_all :: "'a mybag ⇒ 'a myseq ⇒ bool" is
  "(λxs ys. myseq_for_all ys (mybag_includes xs))" .

(* ... and 14 more similar operations for other type combinations *)
一些测试用例:

value "mybag_myseq_includes_all (Abs_mybag {#1::nat,2,4,5,3,4#}) (Abs_myseq [1::nat,2])"
value "mybag_myseq_includes_all (Abs_mybag {#1::nat,2,4,5,3,4#}) (Abs_myseq [1::nat,7])"
问题是这些操作在结构上是相同的,我不想重复它们。我尝试定义一个抽象集合类型:

typedecl 'a mycol
consts
  mycol_count :: "'a mycol ⇒ 'a ⇒ nat"
  mycol_for_all :: "'a mycol ⇒ ('a ⇒ bool) ⇒ bool"

definition mycol_includes :: "'a mycol ⇒ 'a ⇒ bool" where
  "mycol_includes xs x ≡ mycol_count xs x > 0"

definition mycol_includes_all :: "'a mycol ⇒ 'a mycol ⇒ bool" where
  "mycol_includes_all xs ys ≡ mycol_for_all xs (mycol_includes ys)"
但我不知道如何从抽象集合类型派生出具体集合类型:

typedef 'a mybag = "{xs :: 'a mycol. ???}" ..
typedef 'a myseq = "{xs :: 'a mycol. ???}" ..
typedef 'a myset = "{xs :: 'a mycol. ???}" ..
typedef 'a myord = "{xs :: 'a mycol. ???}" ..

一旦对抽象集合类型进行了公理化,就不能再在逻辑中对其进行细化。因此,提议的方法不起作用。但是如果您将容器类型保留为抽象(作为类型变量),那么这是可能的。我建议使用区域设置进行此操作:

locale container =
  fixes count :: "'container => 'a => nat"
  and for_all :: "'container => ('a => bool) => bool"
begin

definition "includes" where "includes C x <--> count C x > 0"
definition includes_all where "includes_all C C' <--> for_all C (includes C')"

end

生成缩写mybag.includes和mybag.includes\u all。此外,在区域设置
容器中证明的所有定理也专门用于
mybag
,前缀为
mybag

,感谢您的回答!请你澄清一下好吗。是否可以自动为mybag.includes等生成代码方程式。?在这两个参数中是否可以使
includes\u all
多态?此区域设置定义了
包含所有内容:“'a mybag⇒ '我的包⇒ bool“
但未定义
包含所有内容::”'a mybag⇒ '神秘人⇒ bool“
哦,我知道了如何生成代码。我必须使用全局解释:
global\u解释mybag:container mybag\u count mybag\u for\u all defined mybag\u includes=“mybag.includes”。
而且我还知道如何为不同的收集类型定义
includes\u all
。我必须使用区域设置表达式:
locale container\u pair=container1:container count1表示所有1+container2:container count2表示所有2
。因此,
包含所有
的定义如下:
包含所有C'⟷ 对于所有的C'(container1.includes C)
@Denis:没错。如果要在一个操作中组合两个不同的错误实现,则需要两个区域设置
容器的副本。因此,如果有不同的容器,则需要
n^2
解释<代码>全局_解释
定义
也是代码生成的正确选择。
interpretation mybag: container mybag_count mybag_forall .