Coq Isabelle中带类型参数的归纳谓词
我开始学习Isabelle,想尝试在Isabelle中定义一个幺半群,但不知道如何定义 在Coq中,我会这样做:Coq Isabelle中带类型参数的归纳谓词,coq,isabelle,type-parameter,Coq,Isabelle,Type Parameter,我开始学习Isabelle,想尝试在Isabelle中定义一个幺半群,但不知道如何定义 在Coq中,我会这样做: inductive monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" for f i where axioms: "⟦f e i = e; f i e = e⟧ ⟹ monoid f i" 归纳幺半群(τ:型)(op:τ->τ->τ)(i:τ):Prop:= |公理:(forall(e:τ),op e i=e)-> (对于所有(e:τ),op i e
inductive monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" for f i where
axioms: "⟦f e i = e; f i e = e⟧ ⟹ monoid f i"
归纳幺半群(τ:型)(op:τ->τ->τ)(i:τ):Prop:=
|公理:(forall(e:τ),op e i=e)->
(对于所有(e:τ),op i e=e)->
幺半群τopi。
我不知道如何在伊莎贝尔身上做同样的事情。从概念上讲,我想到了这样的事情:
inductive monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" for f i where
axioms: "⟦f e i = e; f i e = e⟧ ⟹ monoid f i"
a幺半群('a⇒ 'A.⇒ '(a)⇒ 'A.⇒ “bool”表示f i在哪里
公理:⟦f e i=e;f i e=e⟧ ⇒ 幺半群f i“
但是,这在伊莎贝尔身上是无效的
如何在Isabelle中定义带类型化参数的归纳谓词?我对Coq了解不多,但Isabelle的类型系统非常不同。Isabelle值不接受“类型参数”,Isabelle类型不接受“值参数” 在Isabelle中,您的示例是一个简单的多态定义,可以这样做:
inductive monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" for f i where
axioms: "⟦f e i = e; f i e = e⟧ ⟹ monoid f i"
我必须指出,这意味着如果存在一个这样的e
,那么就有一个幺半群。你可能想写的是
inductive monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" for f i where
axioms: "⟦⋀e. f e i = e; ⋀e. f i e = e⟧ ⟹ monoid f i"
这里,e
在假设中被普遍量化,这意味着法律必须适用于所有e
,才能构成幺半群
作为归纳定义这样做是可能的,并且具有自动生成适当的引入/消除规则的优势(并且能够通过归纳案例
生成更多规则)。但是,还有其他方法
使用定义
但是,您也可以将其写成一个简单的定义:
definition monoid :: "('a ⇒ 'a ⇒ 'a) ⇒ 'a ⇒ bool" where
"monoid f i = ((∀e. f e i = e) ∧ (∀e. f i e = e))"
这给出了monoid
的定义,作为引理monoid\u def
。如果您想要引入/排除规则,您必须自己推导它们
使用区域设置
第三种可能也是最合适的解决方案是locale。区域设置是在上下文中保留某些固定变量和假设,并在此上下文中保留原因的一种方式。下面的示例演示如何将幺半群定义为区域设置,在该区域设置中派生引理,然后将区域设置解释为具体的示例幺半群(即列表),并使用我们在区域设置中为它们证明的引理
locale monoid =
fixes i :: 'a and f :: "'a ⇒ 'a ⇒ 'a"
assumes left_neutral: "f i e = e"
and right_neutral: "f e i = e"
begin
lemma neutral_unique_left:
assumes "⋀e. f i' e = e"
shows "i' = i"
proof-
from right_neutral have "i' = f i' i" by simp
also from assms have "f i' i = i" by simp
finally show "i' = i" .
qed
end
thm monoid.neutral_unique_left
(* Output: monoid i f ⟹ (⋀e. f i' e = e) ⟹ i' = i *)
(* Let's interpret our monoid for the type "'a list", with []
as neutral element and concatenation (_ @ _) as the operation. *)
interpretation list_monoid: monoid "[]" "λxs ys. xs @ ys"
by default simp_all
thm list_monoid.neutral_unique_left
(* Output: (⋀e. i' @ e = e) ⟹ i' = [] *)
使用类型类
第四种可能性类似于locale,它是类型类。Isabelle支持类型类(与Haskell中的类型类类似,尽管限制性更强),您可以创建一个monoid
类型类,然后将其实例化为具体类型,如nat
,int
,'a list
等
更多信息
有关归纳谓词、区域设置和类型类的更多信息,请参阅这些工具的文档: