将部分定义提升为商类型

时间:2013-03-11 20:25:01

标签: isabelle

我在集合上有一个部分定义的运算符(disj_union),我希望将其提升为商类型(natq)。在道德上,我认为应该可以,因为总是可以在等价类中找到某些代表,其中定义了运算符[*]。但是,我无法完成提升定义保留等效性的证据,因为disj_union仅部分定义。在我下面的理论文件中,我提出了一种定义我的disj_union运算符的方法,但我不喜欢它,因为它具有很多absRep函数,而我认为这很难合作(对吗?)。

使用Isabelle中的商定义这种事物的好方法是什么?

theory My_Theory imports 
  "~~/src/HOL/Library/Quotient_Set" 
begin

(* A ∪-operator that is defined only on disjoint operands. *)
definition "X ∩ Y = {} ⟹ disj_union X Y ≡ X ∪ Y"

(* Two sets are equivalent if they have the same cardinality. *)
definition "card_eq X Y ≡ finite X ∧ finite Y ∧ card X = card Y"

(* Quotient sets of naturals by this equivalence. *)
quotient_type natq = "nat set" / partial: card_eq
proof (intro part_equivpI)
  show "∃x. card_eq x x" by (metis card_eq_def finite.emptyI)
  show "symp card_eq" by (metis card_eq_def symp_def)
  show "transp card_eq" by (metis card_eq_def transp_def)
qed

(* I want to lift my disj_union operator to the natq type. 
   But I cannot complete the proof, because disj_union is
   only partially defined. *)
lift_definition natq_add :: "natq ⇒ natq ⇒ natq"
is "disj_union"
oops

(* Here is another attempt to define natq_add. I think it
   is correct, but it looks hard to prove things about, 
   because it uses abstraction and representation functions
   explicitly. *)
definition natq_add :: "natq ⇒ natq ⇒ natq"
where "natq_add X Y ≡ 
  let (X',Y') = SOME (X',Y'). 
  X' ∈ Rep_natq X ∧ Y' ∈ Rep_natq Y ∧ X' ∩ Y' = {} 
  in abs_natq (disj_union X' Y')"

end

[*]这有点像捕获 - 避免替换只是在绑定变量不冲突的条件下定义的;通过重命名为alpha等价类中的另一个代表,可以始终满足的条件。

2 个答案:

答案 0 :(得分:2)

这样的事情(只是一个想法):

definition disj_union' :: "nat set ⇒ nat set ⇒ nat set"
where "disj_union' X Y ≡ 
  let (X',Y') = SOME (X',Y'). 
  card_eq X' X ∧ card_eq Y' Y ∧ X' ∩ Y' = {} 
  in disj_union X' Y'"

lift_definition natq_add :: "natq ⇒ natq ⇒ natq"
is "disj_union'" oops

答案 1 :(得分:0)

为了记录,这里是Ondřej的建议(好吧,稍微修改一下,其中只有一个操作数被重命名,而不是两者都完成)......

(* A version of disj_union that is always defined. *)
definition disj_union' :: "nat set ⇒ nat set ⇒ nat set"
where "disj_union' X Y ≡ 
  let Y' = SOME Y'. 
  card_eq Y' Y ∧ X ∩ Y' = {} 
  in disj_union X Y'"

(* Can always choose a natural that is not in a given finite subset of ℕ. *)
lemma nats_infinite:
  fixes A :: "nat set"
  assumes "finite A"
  shows "∃x. x ∉ A"
proof (rule ccontr, simp)
  assume "∀x. x ∈ A"
  hence "A = UNIV" by fast
  hence "finite UNIV" using assms by fast
  thus False by fast
qed

(* Can always choose n naturals that are not in a given finite subset of ℕ. *)
lemma nat_renaming:
  fixes x :: "nat set" and n :: nat
  assumes "finite x" 
  shows "∃z'. finite z' ∧ card z' = n ∧ x ∩ z' = {}"
using assms
apply (induct n)
apply (intro exI[of _ "{}"], simp)
apply (clarsimp)
apply (rule_tac x="insert (SOME y. y ∉ x ∪ z') z'" in exI)
apply (intro conjI, simp)
apply (rule someI2_ex, rule nats_infinite, simp, simp)+
done

lift_definition natq_add :: "natq ⇒ natq ⇒ natq"
is "disj_union'"
apply (unfold disj_union'_def card_eq_def)
apply (rule someI2_ex, simp add: nat_renaming)
apply (rule someI2_ex, simp add: nat_renaming)
apply (metis card.union_inter_neutral disj_union_def empty_iff finite_Un)
done