簡體   English   中英

`le` 的歸納原理

[英]Induction principle for `le`

對於歸納類型nat ,生成的歸納原理在其語句中使用構造函數OS

Inductive nat : Set :=  O : nat | S : nat -> nat

nat_ind
 : forall P : nat -> Prop,
   P 0 ->
   (forall n : nat, P n -> P (S n)) -> forall n : nat, P n

但是對於le ,生成的語句不使用構造函數le_nle_S

Inductive le (n : nat) : nat -> Prop :=
le_n : n <= n | le_S : forall m : nat, n <= m -> n <= S m

le_ind
 : forall (n : nat) (P : nat -> Prop),
   P n ->
   (forall m : nat, n <= m -> P m -> P (S m)) ->
   forall n0 : nat, n <= n0 -> P n0

然而,可以按照與nat相同的形狀來陳述和證明歸納原理:

Lemma le_ind' : forall n (P : forall m, le n m -> Prop),
P n (le_n n) ->
(forall m (p : le n m), P m p -> P (S m) (le_S n m p)) ->
forall m (p : le n m), P m p.
Proof.
fix H 6; intros; destruct p.
apply H0.
apply H1, H.
apply H0.
apply H1.
Qed.

我想生成的更方便。 但是 Coq 如何為其生成的歸納原理選擇形狀? 如果有任何規則,我在參考手冊中找不到它們。 Agda 等其他證明助手呢?

您可以使用命令Scheme (請參閱文檔 )來手動為歸納類型生成歸納原理。

該命令有兩種形式:

  • Scheme scheme := Induction for Sort Prop的歸納產生標准的誘導方案。
  • Scheme scheme := Minimality for Sort Prop生成簡化的歸納方案,更適合歸納謂詞。

如果在Type定義感應Type ,則生成的感應原理是第一種。 如果在Prop定義歸納類型(即歸納謂詞),則生成的歸納原理是第二種。

要獲得在le情況下所需的歸納原理,可以在Type定義它:

Inductive le (n : nat) : nat -> Type :=
| le_n : le n n
| le_S : forall m : nat, le n m -> le n (S m).

Check le_ind.
(* forall (n : nat) (P : forall n0 : nat, le n n0 -> Prop),
   P n (le_n n) ->
   (forall (m : nat) (l : le n m), P m l -> P (S m) (le_S n m l)) ->
   forall (n0 : nat) (l : le n n0), P n0 l
*)

或者您可以手動要求Coq生成預期的歸納原則:

Inductive le (n : nat) : nat -> Prop :=
| le_n : le n n
| le_S : forall m : nat, le n m -> le n (S m).

Check le_ind.
(* forall (n : nat) (P : nat -> Prop),
   P n ->
   (forall m : nat, le n m -> P m -> P (S m)) ->
   forall n0 : nat, le n n0 -> P n0
*)

Scheme le_ind2 := Induction for le Sort Prop.
Check le_ind2.
(* forall (n : nat) (P : forall n0 : nat, le n n0 -> Prop),
   P n (le_n n) ->
   (forall (m : nat) (l : le n m), P m l -> P (S m) (le_S n m l)) ->
   forall (n0 : nat) (l : le n n0), P n0 l
*)

這是因為le_Sle_n被擴展了。

le_ind
 : forall (n : nat) (P : nat -> Prop),
   P n ->                                         1) le_n case
   (forall m : nat, n <= m -> P m -> P (S m)) ->  2) le_S case
   forall n0 : nat, n <= n0 -> P n0

n <= n0可以通過兩種方式構造:

  1. 通過le_n所以你有n <= n 你必須顯示P n 由於您在構造函數中沒有任何含義,因此您沒有任何前提。
  2. 通過le_S 所以你有n <= m -> n <= S m 你想要顯示P (S m) 由於您有n <= m ,因此可以假設n <= m且(歸納假設) P m為真。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM