这是数学中的一个小定理:
假设 u 不是 A 的元素,v 不是 B 的元素,f 是从 A 到 B 的单射函数。令 A' = A union {u} 和 B' = B union {v},并定义g: A' -> B' by g(x) = f(x) 如果 x 在 A 中,并且 g(u) = v。那么 g 也是单射的。
如果我正在编写类似 OCaml 的代码,我会将 A 和 B 表示为类型,并将 f 表示为 A->B 函数,例如
module type Q =
sig
type 'a
type 'b
val f: 'a -> 'b
end
然后定义一个函子
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;;
我的定理是 ifQ.f
是单射的,那么 也是(Extend Q).f
,我希望我的语法或多或少是正确的。
我想在 Isabelle/Isar 做同样的事情。通常,这意味着写类似
definition injective :: "('a ⇒ 'b) ⇒ bool"
where "injective f ⟷ ( ∀ P Q. (f(P) = f(Q)) ⟷ (P = Q))"
proposition: "injective f ⟹ injective (Q(f))"
并且Q
是……某事。我不知道如何在 Isabelle 中创建一个类似于Q
OCaml 中的仿函数的单个操作,它创建两个新的数据类型和它们之间的函数。单射性的证明似乎相当简单——只是一个四例拆分。但是我想要帮助定义我调用的新函数Q f
,给定函数f
。