简体   繁体   English

伊莎贝尔结构证明

[英]Isabelle structure proof

There is a set of some structures.有一组一些结构。 I'm trying to prove that the cardinality of the set equals some number.我试图证明集合的基数等于某个数字。 Full theory is too long to post here.完整的理论太长,无法在此处发布。 So here is a simplified one just to show the idea.所以这里是一个简化的只是为了展示这个想法。

Let the objects (which I need to count) are sets containing natural numbers from 1 to n.让对象(我需要计算)是包含从 1 到 n 的自然数的集合。 The idea of the proof is as follows.证明思路如下。 I define a function which transforms sets to lists of 0 and 1. Here is the function and its inverse:我定义了一个将集合转换为 0 和 1 列表的函数。这是函数及其逆函数:

fun set_to_bitmap :: "nat set ⇒ nat ⇒ nat ⇒ nat list" where
  "set_to_bitmap xs x 0 = []"
| "set_to_bitmap xs x (Suc n) =
    (if x ∈ xs then Suc 0 else 0) # set_to_bitmap xs (Suc x) n"

fun bitmap_to_set :: "nat list ⇒ nat ⇒ nat set" where
  "bitmap_to_set [] n = {}"
| "bitmap_to_set (x#xs) n =
    (if x = Suc 0 then {n} else {}) ∪ bitmap_to_set xs (Suc n)"

value "set_to_bitmap {1,3,7,8} 1 8"
value "bitmap_to_set (set_to_bitmap {1,3,7,8} 1 8) 1"

Then I plan to prove that 1) a number of 0/1 lists with length n equals 2^^n , 2) the functions are bijections, 3) so the cardinality of the original set is 2^^n too.然后我打算证明 1) 一些长度为 n 的 0/1 列表等于2^^n ,2) 函数是双射,3) 所以原始集合的基数也是2^^n

Here are some auxiliary definitions and lemmas, which seems useful:这里有一些辅助定义和引理,看起来很有用:

definition "valid_set xs n ≡ (∀a. a ∈ xs ⟶ 0 < a ∧ a ≤ n)"
definition "valid_bitmap ps n ≡ length ps = n ∧ set ps ⊆ {0, Suc 0}"

lemma length_set_to_bitmap:
  "valid_set xs n ⟹
   x = Suc 0 ⟹
   length (set_to_bitmap xs x n) = n"
  apply (induct xs x n rule: set_to_bitmap.induct)
  apply simp
  sorry

lemma bitmap_members:
  "valid_set xs n ⟹
   x = Suc 0 ⟹
   set_to_bitmap xs x n = ps ⟹
   set ps ⊆ {0, Suc 0}"
  apply (induct xs x n arbitrary: ps rule: set_to_bitmap.induct)
  apply simp
  sorry

lemma valid_set_to_valid_bitmap:
  "valid_set xs n ⟹
   x = Suc 0 ⟹
   set_to_bitmap xs x n = ps ⟹
   valid_bitmap ps n"
  unfolding valid_bitmap_def
  using bitmap_members length_set_to_bitmap by auto

lemma valid_bitmap_to_valid_set:
  "valid_bitmap ps n ⟹
   x = Suc 0 ⟹
   bitmap_to_set ps x = xs ⟹
   valid_set xs n"
  sorry

lemma set_to_bitmap_inj:
  "valid_set xs n ⟹
   valid_set xy n ⟹
   x = Suc 0 ⟹
   set_to_bitmap xs x n = ps ⟹
   set_to_bitmap ys x n = qs ⟹
   ps = qs ⟹
   xs = ys"
  sorry

lemma set_to_bitmap_surj:
  "valid_bitmap ps n ⟹
   x = Suc 0 ⟹
   ∃xs. set_to_bitmap xs x n = ps"
  sorry

lemma bitmap_to_set_to_bitmap_id:
  "valid_set xs n ⟹
   x = Suc 0 ⟹
   bitmap_to_set (set_to_bitmap xs x n) x = xs"
  sorry

lemma set_to_bitmap_to_set_id:
  "valid_bitmap ps n ⟹
   x = Suc 0 ⟹
   set_to_bitmap (bitmap_to_set ps x) x n = ps"
  sorry

Here is a final lemma:这是最后的引理:

lemma valid_set_size:
  "card {xs. valid_set xs n} = 2 ^^ n"

Does this approach seem valid?这种方法看起来有效吗? Are there any examples of such a proof?有没有这样的证明的例子? Could you suggest an idea on how to prove the lemmas?你能提出一个关于如何证明引理的想法吗? I'm stuck because the induction with set_to_bitmap.induct seems to be not applicable here.我被卡住了,因为set_to_bitmap.induct的归纳在set_to_bitmap.induct似乎不适用。

In principle, that kind of approach does work: if you have a function f from a set A to a set B and an inverse function to it, you can prove bij_betw f AB (read: f is a bijection from A to B ), and that then implies card A = card B .原则上,这种方法确实有效:如果你有一个从集合A到集合B的函数f和一个反函数,你可以证明bij_betw f AB (读作: f是从AB的双射),然后这意味着card A = card B

However, there are a few comments that I have:但是,我有一些评论:

  1. You should use bool lists instead of nat lists if you can only have 0 or 1 in them anyway.如果无论如何你只能有 0 或 1,你应该使用bool列表而不是nat列表。

  2. It is usually better to use existing library functions than to define new ones yourself.使用现有的库函数通常比自己定义新函数更好。 Your two functions could be defined using library functions like this:你的两个函数可以使用这样的库函数来定义:

     set_to_bitmap :: nat ⇒ nat ⇒ nat set ⇒ bool list set_to_bitmap xn A = map (λi. i ∈ A) [x..<x+n] bitmap_to_set :: nat ⇒ bool list ⇒ nat set bitmap_to_set n xs = (λi. i + n) ` {i. i < length xs ∧ xs ! i}```
  3. Side note: I would use upper-case letters for sets, not something like xs (which is usually used for lists).旁注:我会使用大写字母来表示集合,而不是像xs这样的东西(通常用于列表)。

  4. Perhaps this is because you simplified your problem, but in its present form, valid_set A n is simply the same as A ⊆ {1..n} and the {A. valid_set A n}也许这是因为您简化了问题,但在目前的形式中, valid_set A nA ⊆ {1..n}A ⊆ {1..n}完全相同{A. valid_set A n} {A. valid_set A n} is simply Pow {1..n} . {A. valid_set A n}就是Pow {1..n} The cardinality of that is easy to show with results from the library:库的结果很容易显示其基数:

     lemma "card (Pow {1..(n::nat)}) = 2 ^ n" by (simp add: card_Pow)`

As for your original questions: Your first few lemmas are provable, but for the induction to go through, you have to get rid of some of the unneeded assumptions first.至于你最初的问题:你的前几个引理是可证明的,但要通过归纳,你必须首先摆脱一些不需要的假设。 The x = Suc 0 is the worst one – there is no way you can use induction if you have that as an assumption, because as soon as you do one induction step, you increase x by 1 and so you won't be able to apply your induction hypothesis. x = Suc 0是最糟糕的——如果你把它作为假设,你就无法使用归纳法,因为一旦你做一个归纳步骤,你就将x增加 1,所以你将无法应用你的归纳假设。 The following versions of your first three lemmas go through easily:前三个引理的以下版本很容易通过:

lemma length_set_to_bitmap:
  "length (set_to_bitmap xs x n) = n"
  by (induct xs x n rule: set_to_bitmap.induct) auto

lemma bitmap_members:
  "set (set_to_bitmap xs x n) ⊆ {0, Suc 0}"
  by (induct xs x n rule: set_to_bitmap.induct) auto

lemma valid_set_to_valid_bitmap: "valid_bitmap (set_to_bitmap xs x n) n"
  unfolding valid_bitmap_def
  using bitmap_members length_set_to_bitmap by auto

I also recommend not adding "abbreviations" like ps = set_to_bitmap xs xn as an assumption.我还建议不要添加像ps = set_to_bitmap xs xn这样的“缩写”作为假设。 It doesn't break anything, but it tends to complicate things needlessly.它不会破坏任何东西,但它往往会不必要地使事情复杂化。

The next lemma is a bit trickier.下一个引理有点棘手。 Due to your recursive definitions, you have to generalise the lemma first ( valid_bitmap requires the set to be in the range from 1 to n , but once you make one induction step it has to be from 2 to n ).由于您的递归定义,您必须首先概括引理( valid_bitmap要求集合在1n的范围内,但是一旦您进行一个归纳步骤,它必须是从2n )。 The following works:以下工作:

lemma valid_bitmap_to_valid_set_aux:
  "bitmap_to_set ps x ⊆ {x..<x + length ps}"
  by (induction ps x rule: bitmap_to_set.induct)
     (auto simp: valid_bitmap_def valid_set_def)

lemma valid_bitmap_to_valid_set:
  "valid_bitmap ps n ⟹ valid_set (bitmap_to_set ps 1) n"
  using valid_bitmap_to_valid_set_aux unfolding valid_bitmap_def valid_set_def
  by force

Injectivity and surjectivity (which is your ultimate goal) should follow from the fact that the two are inverse functions.射性和满射性(这是您的最终目标)应该从这两个是反函数的事实得出。 Proving that will probably be doable with induction, but will require a few generalisations and auxiliary lemmas.通过归纳证明这可能是可行的,但需要一些概括和辅助引理。 It should be easier if you stick to the non-recursive definition using library functions that I sketched above.如果您坚持使用我在上面勾画的库函数的非递归定义,那应该会更容易。

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

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