Isabelle/Isar中的仿函子结构

Isabelle/Isar中的仿函子结构,isabelle,isar,Isabelle,Isar,数学中有一个小定理: 假设u不是A的元素,v不是B的元素,f是从A到B的内射函数。设A'=A并集{u}和B'=B并集{v},如果x在A中,则通过g(x)=f(x)定义g:A'->B',g(u)=v。那么g也是内射的 如果我编写类似OCaml的代码,我会将A和B表示为类型,将f表示为A->B函数,类似于 module type Q = sig type 'a type 'b val f: 'a -> 'b end definition injective ::

数学中有一个小定理:

假设u不是A的元素,v不是B的元素,f是从A到B的内射函数。设A'=A并集{u}和B'=B并集{v},如果x在A中,则通过g(x)=f(x)定义g:A'->B',g(u)=v。那么g也是内射的

如果我编写类似OCaml的代码,我会将A和B表示为类型,将f表示为A->B函数,类似于

module type Q = 
  sig
   type 'a
   type 'b
   val f: 'a -> 'b
  end
definition injective :: "('a  ⇒ 'b)  ⇒ bool"
  where "injective f  ⟷ ( ∀ P Q.  (f(P) = f(Q)) ⟷ (P = Q))" 

proposition: "injective f ⟹ injective (Q(f))"
然后定义一个函子

module Extend (M : Q) : Q = 
  struct
    type a = OrdinaryA of M.a | ExoticA
    type b = OrdinaryB of M.b | ExoticB
    let f x = match x with
        OrdinaryA t -> OrdinaryB ( M.f t)
      | Exotic A -> ExoticB
  end;;
我的定理是,如果
Q.f
是内射的,那么
(扩展Q.f
)也是内射的,我希望我的语法或多或少是正确的

我想在伊莎贝尔/伊萨尔身上做同样的事情。通常,这意味着写一些

module type Q = 
  sig
   type 'a
   type 'b
   val f: 'a -> 'b
  end
definition injective :: "('a  ⇒ 'b)  ⇒ bool"
  where "injective f  ⟷ ( ∀ P Q.  (f(P) = f(Q)) ⟷ (P = Q))" 

proposition: "injective f ⟹ injective (Q(f))"

Q
是。。。某物我不知道如何在Isabelle中创建一个类似于OCaml中functor
Q
的操作,该操作创建了两个新的数据类型以及它们之间的函数。注入能力的证明似乎相当简单——仅仅是四种情况的分离。但是我想帮助定义我调用的新函数
qf
,给定函数
f

这里有一个解决方案。我试图为函数
Q
做一个“定义”,但做不到;相反,创建一个常量
Q
(与
map
)让我陈述并证明这个定理:

theory Extensions
  imports Main
begin
text ‹We show that if we have f: 'a → 'b that's injective, and we extend 
both the domain and codomain types by a new element, and extend f in the 
obvious way, then the resulting function is still injective.›
  definition injective :: "('a  ⇒ 'b)  ⇒ bool"
    where "injective f  ⟷ ( ∀ P Q.  (f(P) = f(Q)) ⟷ (P = Q))" 

datatype 'a extension = Ordinary 'a | Exotic

fun Q ::  "('a  ⇒ 'b) ⇒ (('a extension)  ⇒ ('b extension))"  where 
   "Q f (Ordinary u) = Ordinary (f u)" |
   "Q f (Exotic) = Exotic"

lemma "⟦injective f⟧ ⟹ injective (Q f)"
  by (smt Q.elims extension.distinct(1) extension.inject injective_def)

end

我想说两句话。1:标准库中存在一个函数,其行为与您答案中的函数
内射
相同(请参见理论
HOL/Fun
中的函数
inj
)。2:通常情况下,使用理论中的类型构造函数
set
,对于与您问题中的定理类似的定理的陈述更为自然。这将允许您在一个任意类型τ的上下文中陈述定理。当然,我不确定你的申请是什么。因此,我可能是错的。我认为在某个地方有一个“内射”,但它很容易编写,对于这个简单的例子,它将所有东西放在一个地方。至于“设置”。。。事实证明,在我工作的大环境中使用它是错误的,而这个“扩展”几乎完全正确。实际情况,仅供参考:通过添加“无穷远处的点”,从仿射平面构造投影平面。