내 이론에는 4 가지 종류의 컬렉션이 있습니다.추상 콜렉션 데이터 유형을 정의하는 방법은 무엇입니까?
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])"
을 나는이 수집 종류의 다형성 작업 (
includes
및
includes_all
)를 정의 할 필요가
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))" .
: 각 콜렉션 유형에 대해 나는 count
및 for_all
작업을 정의
문제는 이러한 작업이 구조적으로 동일하며 t를 복제하고 싶지 않다는 것입니다. 헛기침. 나는 추상적 인 집합 유형을 정의하려고 :
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)"
을하지만 어떻게 추상 하나에서 구체적인 수집 유형을 도출하는 아무 생각이 :
당신은 추상 컬렉션 형식을 axiomatized하면typedef 'a mybag = "{xs :: 'a mycol. ???}" ..
typedef 'a myseq = "{xs :: 'a mycol. ???}" ..
typedef 'a myset = "{xs :: 'a mycol. ???}" ..
typedef 'a myord = "{xs :: 'a mycol. ???}" ..
답변 해 주셔서 감사합니다. 제발 당신을 명확히 해 주시겠습니까? mybag.includes 등의 코드 방정식을 자동으로 생성 할 수 있습니까? 그리고 두 인수 모두에서'includes_all' 다형성을 만들 수 있습니까? 이 로케일은'includes_all :: "a mybag ⇒ 'mybag ⇒ bool"을 정의하지만'includes_all :: "a mybag를 정의하지 않습니다 ⇒'myseq ⇒ bool" – Denis
오, 생성 방법은 있습니다 암호. 글로벌 해석을 사용해야합니다 :'global_interpretation mybag : container mybag_count mybag_for_all mybag_includes = "mybag.includes"를 정의합니다. " – Denis
또한 다른 컬렉션 유형에 대해'includes_all'을 정의하는 방법이 있습니다. 로케일 표현식을 사용해야합니다 :'locale container_pair = container1 : container count1 for_all1 + container2 : container count2 for_all2'. 그래서'includes_all'의 정의는 다음과 같습니다 :'includes_all C C 'for_all2 C'(container1.includes C)' – Denis