将类导入Isabelle中的语言环境以及其他相关问题

时间:2018-04-29 11:04:25

标签: isabelle

问题

  • 我想了解是否存在将类导入语言环境的简单方法。
  • 或者,我想了解是否有一种简单的方法可以让我在类中的假设中使用多种类型。

我想重用与库HOL中某些预定义类相关联的定理来开发我自己的语言环境。但是,在我看来,目前没有标准方法可以让我实现这一目标(例如见this question - 第5条)。

不幸的是,我的问题需要使用多种类型的假设来定义结构(即语言环境或类)。因此,我更喜欢使用locales。但是,我还想避免代码重复,并尽可能多地重用库HOL中已存在的结构。

theory my_theory
imports Complex_Main 
begin


(*It is possible to import other classes, establish a subclass relationship and
use theorems from the super classes. However, if I understand correctly, it 
is not trivial to ensure that multiple types can be used in the assumptions
that are associated with the subclass.*)
class my_class = order +
  fixes f :: "'a ⇒ real"
begin
subclass order
proof
qed
end

lemma (in my_class) property_class: "⟦ x ≤ y; y ≤ z ⟧ ⟹ x ≤ z"
  by auto


(*Multiple types can be used with ease. However, I am not sure how (if 
it is possible) to ensure that the lemmas that are associated with the
imported class can be reused in the locale.*)
locale my_locale =
  less_eq: order less_eq 
  for less_eq :: "'a ⇒ 'a ⇒ bool" +
  fixes f :: "'a ⇒ 'b"
begin
sublocale order
proof
qed
end

sublocale my_locale ⊆ order
proof
qed

(*nitpick finds a counterexample, because, for example, less_eq is treated 
as a free variable.*)
lemma (in my_locale) property_locale: "⟦ x ≤ y; y ≤ z ⟧ ⟹ x ≤ z"
  by nitpick

end

建议的解决方案

目前我正在考虑在我自己的语言环境中重新定义最少量的公理,这足以建立我的语言环境与HOL中相应类之间的等价。但是,这种方法会导致一定数量的代码重复:

theory my_plan
imports Complex_Main 
begin

locale partial_order =
  fixes less_eq :: "'a ⇒ 'a ⇒ bool" (infixl "≼" 50)
    and less :: "'a ⇒ 'a ⇒ bool" (infixl "≺" 50)
  assumes refl [intro, simp]: "x ≼ x"
    and anti_sym [intro]: "⟦ x ≼ y; y ≼ x ⟧ ⟹ x = y" 
    and trans [trans]: "⟦ x ≼ y; y ≼ z ⟧ ⟹ x ≼ z"
    and less_eq: "(x ≺ y) = (x ≼ y ∧ x ≠ y)"
begin
end

sublocale partial_order ⊆ order
proof
  fix x y z
  show "x ≼ x" by simp
  show "x ≼ y ⟹ y ≼ z ⟹ x ≼ z" using local.trans by blast
  show "x ≼ y ⟹ y ≼ x ⟹ x = y" by blast
  show "(x ≺ y) = (x ≼ y ∧ ¬ y ≼ x)" using less_eq by auto
qed

sublocale order ⊆ partial_order
proof
  fix x y z
  show "x ≤ x" by simp
  show "x ≤ y ⟹ y ≤ x ⟹ x = y" by simp
  show "x ≤ y ⟹ y ≤ z ⟹ x ≤ z" by simp
  show "(x < y) = (x ≤ y ∧ x ≠ y)" by auto
qed

lemma (in partial_order) le_imp_less_or_eq: "x ≼ y ⟹ x ≺ y ∨ x = y"
  by (simp add: le_imp_less_or_eq)

end

我打算遵循的方法是否适合在Isabelle开发图书馆?不幸的是,我还没有看到在HOL开发的背景下使用这种方法。但是,我仍然不熟悉图书馆的大部分内容。

  • 另外,如果问题定义中所述的任何信息不正确,请告诉我:我是Isabelle的新手。

与问题没有直接关系的一般性评论

最后,作为旁注,我注意到HOL中可能存在一定数量的部分代码重复。特别是,在我看来,HOL/Lattice/HOL/Algebra/Order - HOL/Algebra/LatticeHOL/Library/Boolean_Algebra中的理论与HOL/Orderings - HOL/Lattices中的理论相似。但是,我不确定这些理论之间的等同性是否通过子范围/子类关系(例如参见class_deps)建立到足够的程度。当然,我理解这些理论使用了明显的公理化,而HOL/Algebra/HOL/Library/Boolean_Algebra中的理论都是基于语言环境。此外,HOL/Algebra/中的理论包含了一些尚未在其他理论中形式化的信息。但是,我仍然希望更好地理解为什么所有四种理论在HOL中共存,并且这些理论之间的关系并不总是清楚地表明。

1 个答案:

答案 0 :(得分:0)

在Akihisa Yamada的Isabelle邮件列表中提出了该问题的解决方案,可通过以下超链接获得:link。下面还提供了解决方案的副本(对格式进行了细微更改),以供作者许可参考。

应该注意的是,所提出的解决方案也已用于HOL的开发。

Akihisa Yamada提出的解决方案

让我对您的技术问题发表评论,因为我也解决了与您相同的目标。不过,如果有更好的解决方案,我会很高兴。

lemma (in my_locale) property_locale: "⟦ x ≤ y; y ≤ z ⟧ ⟹ x ≤ z"
  by nitpick

将类解释为语言环境似乎不会导入表示法,因此这里“≤”表示“ord”的全局表示,它不假设任何内容(可以通过 ctrl + hover检查在x等。)。

我的解决方案是定义语法的语言环境并在需要使用语法时解释它(sublocale在某种程度上很慢)。

locale ord_syntax = ord
begin

notation less_eq (infix "⊑" 50)
notation less (infix "⊏" 50)
abbreviation greater_eq_syntax (infix "⊒" 50) where 
"greater_eq_syntax ≡ ord.greater_eq less_eq" 
abbreviation greater_syntax (infix "⊐" 50) where 
"greater_syntax ≡ ord.greater less"

end

context my_locale begin
interpretation ord_syntax.
lemma property_locale: "⟦ x ⊑ y; y ⊑ z ⟧ ⟹ x ⊑ z" using less_eq.order_trans.
end
相关问题