簡體   English   中英

Coq強制和目標匹配

[英]Coq coercions and goal matching

假設我有以下設置:

Inductive exp: Set :=
| CE: nat -> exp.

Inductive adt: exp -> Prop :=
| CA: forall e, adt e.

Coercion nat_to_exp := CE.

Ltac my_tactic := match goal with
| [ |- adt (CE ?N) ] => apply (CA (CE N))
end.

我嘗試使用自定義策略證明一個簡單的定理:

Theorem silly: adt 0.
Proof.
  my_tactic. (* Error: No matching clauses for match. *)
Abort.

之所以失敗,是因為目標不是adt (CE ?N)形式,而是adt (nat_to_exp ?N)形式adt (nat_to_exp ?N)使用Set Printing Coercions adt (nat_to_exp ?N)時會明確顯示)。

試圖證明定理稍有不同:

Theorem silly: adt (CE 0).
Proof.
  my_tactic. (* Success. *)
Qed.

我知道可能的解決方法:

  • 不使用強制。
  • 在戰術中展開強制(使用unfold nat_to_exp )。 這可以稍微緩解問題,但是一旦引入新的強制措施(該策略不知道)后就會失敗。

理想情況下,如果模式在展開所有定義之后匹配,則我希望模式匹配成功(當然,定義不應該保持展開)。

這可能嗎? 如果沒有,有什么原因導致不可能?

您可以直接將構造函數CE聲明為強制,而不是像這樣將其包裝為nat_to_exp

Coercion CE : nat >-> exp.

這樣證明就毫無問題地通過了。 如果您堅持要命名強制(例如,因為它是一個復合表達式而不是單個構造函數),則可以更改策略,以便它明確處理未展開的強制:

Ltac my_tactic := match goal with
| [ |- adt (CE ?N) ] => apply (CA (CE N))
| [ |- adt (nat_to_exp ?N) ] => apply (CA (CE N))
end.

暫無
暫無

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

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