简体   繁体   English

使用 Omega 证明 Coq 中的引理

[英]Using Omega to prove a lemma in Coq

I am trying to make a proof in Coq using Omega.我正在尝试使用 Omega 在 Coq 中进行证明。 I spent a lot of time on it, but nothing came to me.我在这上面花了很多时间,但什么都没发生。 I have to say I am new in Coq, so I am not at ease with this kind of language, and I do not have much experience.不得不说我是Coq新手,对这种语言不太放心,也没有太多经验。 But I am working on it.但我正在努力。

Here's the code I have to prove:这是我必须证明的代码:

Require Import Arith Omega.

Fixpoint div2 (n : nat) :=
 match n with
   S (S p) => S (div2 p)
 | _ => 0
 end.

Fixpoint mod2 (n : nat) :=
 match n with
   S (S p) => mod2 p
 | x => x
 end.

To make this proof, I thought it would help to prove by induction this lemma first:为了证明这一点,我认为首先通过归纳证明这个引理会有所帮助:

Lemma div2_eq : forall n, 2 * div2 n + mod2 n = n.

Then this one, using omega and div2_eq :然后是这个,使用 omega 和 div2_eq :

Lemma div2_le : forall n, div2 n <= n.

But I did not manage to go further.但我没能走得更远。

Does anyone know what to do?有谁知道该怎么做?

You can easily derive induction principles from the functions div2 and mod2 like so:你可以很容易地从函数div2mod2推导出归纳原理,如下所示:

Functional Scheme div2_ind := Induction for div2 Sort Prop.
Functional Scheme mod2_ind := Induction for mod2 Sort Prop.

div2_ind and mod2_ind have more or less types: div2_indmod2_ind有或多或少的类型:

forall P1,
  P1 0 0 ->
  P1 1 0 ->
  (forall n1, P1 n1 (div2 n1) -> P1 (S (S n1)) (S (div2 n1))) ->
  forall n1, P1 n1 (div2 n1)

forall P1,
  P1 0 0 ->
  P1 1 1 ->
  (forall n1, P1 n1 (mod2 n1) -> P1 (S (S n1)) (mod2 n1)) ->
  forall n1, P1 n1 (mod2 n1)

To apply these theorems you can conveniently write functional induction (div2 n) or functional induction (mod2 n) where you might usually write induction n .要应用这些定理,您可以方便地编写functional induction (div2 n)functional induction (mod2 n) ,您通常会在其中编写induction n

But a stronger induction principle is associated with these functions:但是一个更强的归纳原理与这些函数相关联:

Lemma nat_ind_alt : forall P1 : nat -> Prop,
  P1 0 ->
  P1 1 ->
  (forall n1, P1 n1 -> P1 (S (S n1))) ->
  forall n1, P1 n1.
Proof.
intros P1 H1 H2 H3. induction n1 as [[| [| n1]] H4] using lt_wf_ind.
  info_auto.
  info_auto.
  info_auto.
Qed.

In fact, the domain of any function is a clue to a useful induction principle.事实上,任何函数的定义域都是有用归纳原理的线索。 For example, the induction principle associated to the domain of the functions plus : nat -> nat -> nat and mult : nat -> nat -> nat is just structural induction.例如,与函数域相关的归纳原理plus : nat -> nat -> natmult : nat -> nat -> nat只是结构归纳。 Which makes me wonder why Functional Scheme doesn't just generate these more general principles instead.这让我想知道为什么Functional Scheme不只是生成这些更一般的原则。

In any case, the proofs of your theorems then become:无论如何,你的定理的证明变成了:

Lemma div2_eq : forall n, 2 * div2 n + mod2 n = n.
Proof.
induction n as [| | n1 H1] using nat_ind_alt.
  simpl in *. omega.
  simpl in *. omega.
  simpl in *. omega.
Qed.

Lemma div2_le : forall n, div2 n <= n.
Proof.
induction n as [| | n1 H1] using nat_ind_alt.
  simpl. omega.
  simpl. omega.
  simpl. omega.
Qed.

You should familiarize yourself with functional induction, but more importantly, you should really familiarize yourself with well-founded induction.您应该熟悉功能归纳,但更重要的是,您应该真正熟悉有根据的归纳。

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

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