簡體   English   中英

Coq簡單/展開一次。 (用功能的一次迭代的結果替換目標的一部分。)

[英]Coq simpl / unfold only once. (Replace part of goal with the result of one iteration of a function.)

我是一所大學的講師,參加一門名為“ 類型系統的語言的課程 ,在最后一次講解中,該教授將以下示例用於類型理論的歸納證明:

假設存在歸納定義的自然數(出於某種原因,他堅持稱其為術語),而我們在它們上遞歸定義了一個大於函數。 我們可以證明,對於每一個n,它都擁有(suc n> n)。

我准備了以下Coq代碼以在類中實現此代碼:

Inductive term : Set :=
  | zero
  | suc (t : term)
.

Fixpoint greaterThan (t t' : term) {struct t} : bool :=
  match t, t' with
   | zero, _ => false
   | suc t, zero => true
   | suc t, suc t' => t > t'
  end
where "t > t'" := (greaterThan t t').

Lemma successorIsGreater : forall t : term, suc t > t = true.
Proof.
  induction t.

  (* zero *)
  - simpl.
    reflexivity.

  (* suc t *)
  - 

這將我帶到以下目標:

1 subgoal
t : term
IHt : (suc t > t) = true
______________________________________(1/1)
(suc (suc t) > suc t) = true

我可以通過重寫,展開和/或簡化來解決多種問題,直到它變成反射性,但是我真正想做的是使它變得更整潔的方法是應用一個大於的迭代,這將變成(suc (suc t) > suc t) = true變成(suc t > t) = true ,我可以用exact IHt完成證明。

有沒有辦法解決這個問題?

ps .:我知道我可以simpl in IHt然后使用exact ,但它會擴展為match表達式,比這里需要的更為冗長。

編輯:感謝Théo Winterhalter的回答,我意識到我也可以Théo Winterhalter使用exact的術語,因為這些術語是可轉換的,但是對學生來說並不能很好地說明這一過程。 (附注:誘導的這兩種情況都是可以解決與trivial為好,但我不認為他們會學到太多從任一方法:d)

另一種可能性是使用本地的Arguments來告訴simpl不減少greaterThan匹配的表達式。 Arguments greaterThan: simpl nomatch. greaterThan定義之后的某個地方。 然后當您在環境中使用simpl

1 subgoal
t : term
IHt : (suc t > t) = true
______________________________________(1/1)
(suc (suc t) > suc t) = true

你得到

1 subgoal
t : term
IHt : (suc t > t) = true
______________________________________(1/1)
(suc t > t) = true

如你所願。

我不確定是否有辦法立即進行。 一種常用的方法是通過自反性證明與計算規則相對應的引理:

Lemma greaterThan_suc_suc :
  forall n m,
    suc n > suc m = n > m.
Proof.
  intros. reflexivity.
Defined.

(我使用的是eq_refl ,因此它實際上會展開為eq_refl並在需要時消失。)

還可以進行change以手動進行替換。

change (suc (suc t) > suc t) with (suc t > t).

它將檢查可轉換性,並在目標中將一個表達式替換為另一個表達式。

您可以通過編寫簡化策略來使該過程自動化。

Ltac red_greaterThan :=
  match goal with
  | |- context [ suc ?n > suc ?m ] =>
    change (suc n > suc m) with (n > m)
  | |- context [ suc ?n > zero ] =>
    change (suc n > zero) with true
  | |- context [ zero > ?n ] =>
    change (zero > n) with false
  end.

Lemma successorIsGreater : forall t : term, suc t > t = true.
Proof.
  induction t.

  (* zero *)
  - red_greaterThan. reflexivity.

  (* suc t *)
  - red_greaterThan. assumption.
Qed.

暫無
暫無

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

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