简体   繁体   English

Isabelle/HOL 限制密码域

[英]Isabelle/HOL restrict codomain

I am sorry for asking so many Isabelle questions lately.我很抱歉最近问了这么多伊莎贝尔问题。 Right now I have a type problem.现在我有一个类型问题。

I want to use a type_synonym introduced in a AFP-theory.我想使用 AFP 理论中引入的 type_synonym。

type_synonym my_fun = "nat ⇒ real"

I have a locale in my own theory where:我在自己的理论中有一个语言环境:

fixes n :: nat

and f :: "my_fun"

and A :: "nat set"

defines A: "A ≡ {0..n}"

However, in my use case the output of the function f is always a natural number in the set {0..n}.但是,在我的用例中,函数 f 的输出始终是集合 {0..n} 中的自然数。 I want to impose this as a condition (or is there a better way to do it?).我想将此作为条件强加(或者有更好的方法吗?)。 The only way I found was to:我发现的唯一方法是:

assumes "∀v. ∃ i. fv = i ∧ i ∈ A"

since自从

assumes "∀v. fv ∈ A"

does not work.不起作用。

If I let Isabelle show me the involved types it seems alright to me:如果我让 Isabelle 向我展示所涉及的类型,对我来说似乎没问题:

∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set)

But of course now I cannot type something like this:但当然现在我不能输入这样的东西:

have "f ` {0..10} ⊆ A"

But I have to prove this.但我必须证明这一点。 I understand where this problem comes from.我明白这个问题从何而来。 However, I do not know how to proceed in a case like this.但是,我不知道在这种情况下如何进行。 What is the normal way to deal with it?正常的处理方法是什么? I would like to use my_fun as it has the same meaning as in my theory.我想使用 my_fun 因为它与我的理论具有相同的含义。

Thank you (again).再次感谢你)。

If you look closely at ∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set)如果你仔细观察∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set) ∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set) ∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set) , you will be able to see the mechanism that was used for making the implicit type conversion between nat and real : it is the abbreviation real (this invokes of_nat defined for semiring_1 in Nat.thy) that appears in the statement of the assumption in the context of the locale. ∀v::nat. ∃i::nat. (f::nat ⇒ real) v = real i ∧ i ∈ (A::nat set) ,您将能够看到用于在natreal之间进行隐式类型转换的机制:它是缩写real (这将调用of_nat用于定义semiring_1在Nat.thy),其出现在区域设置的情况下的假设的语句。

Of course, you can use the same mechanism explicitly.当然,您可以显式地使用相同的机制。 For example, you can define A::real set as A ≡ image real {0..n} instead of A::nat set as A ≡ {0..n} .例如,您可以将A::real set定义为A ≡ image real {0..n}而不是A::nat setA ≡ {0..n} Then you can use range f ⊆ A instead of assumes "∀v. ∃ i. fv = i ∧ i ∈ A” . However, I doubt that there is a universally accepted correct way to do it: it depends on what exactly you are trying to achieve. Nonetheless, for the sake of the argument, your locale could look like this:然后你可以使用range f ⊆ A而不是assumes "∀v. ∃ i. fv = i ∧ i ∈ A” 。但是,我怀疑是否有一种普遍接受的正确方法来做到这一点:这取决于你到底是什么试图实现。尽管如此,为了论证起见,您的语言环境可能如下所示:

type_synonym my_fun = "nat ⇒ real"

locale myloc_basis =
  fixes n :: nat

abbreviation (in myloc_basis) A where "A ≡ image real {0..n}"

locale myloc = myloc_basis +
  fixes f :: "my_fun"
  assumes range: "range f ⊆ A"

lemma (in myloc) "f ` {0..10} ⊆ A"
  using range by auto

I want to impose this as a condition (or is there a better way to do it?).我想将此作为条件强加(或者有更好的方法吗?)。

The answer depends on what is known about f .答案取决于对f了解。 If only a condition on the range of f is known, as the statement of your question seems to suggest, then, I guess, you can only state is as an assumption.如果只知道f范围内的条件,正如您的问题陈述似乎所暗示的那样,那么,我想,您只能将其陈述为假设。


As a side note, to the best of my knowledge, defines is considered to be obsolete and it is best to avoid using it in the specifications of a locale: stackoverflow.com/questions/56497678 .作为旁注,据我所知, defines被认为是过时的,最好避免在语言环境的规范中使用它: stackoverflow.com/questions/56497678


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM