簡體   English   中英

`apply.` 策略在 Coq 中的作用是什么——即沒有指定規則或假設來統一目標的結論?

[英]What does `apply.` tactic on it's own do in Coq -- i.e. without specifying a rule or hypothesis to unify the goal's conclusion with?

我想我理解 apply 策略的主要思想,但我無法弄清楚它在這種情況下的作用:

Lemma HilbertS : 
  forall A B C : Prop, 
    (A -> B -> C) -> (A -> B) -> A -> C.
  (* A ->(B -> C)*)
Proof.
  move=> A B C. (* since props A B C are the 1st things in the assumption stack, this pops them and puts them in the local context, note using the same name as the proposition name.*)
  move=> hAiBiC hAiB hA. (* pops the first 3 premises from the hypothesis stack with those names into the local context *)
  move: hAiBiC. (* put hAiBiC tactic back *)
apply.
by [].
by apply: hAiB.
Qed.

我知道apply策略收到一個假設並將假設的結論與子目標的結論相匹配(我假設當前關注的子目標)並且如果它們統一然后使用統一的替換來更新假設的前提作為新的子目標。 詳見附錄。

但是,在我給出的HilbertS證明中,我無法弄清楚apply. 實際上是在做, coq 中的常規策略和 coq的 ssreflex 中的文檔沒有幫助。

注意證明 state 是:

A, B, C: Prop
hAiB: A -> B
hA: A
====
1/1
(A -> B -> C) -> C

什么是apply. 如果假設甚至不是 select,在這里做什么? 我假設它與某些東西統一,但C不在本地上下文中的任何假設中,所以它真的讓我感到困惑,它甚至與什么統一。 基本上什么是apply. 在這里做——尤其是在沒有給定策略應用的假設/術語參數的情況下(在 SSReflect 中)?


附錄解釋我對apply的理解

(* 
https://pjreddie.com/coq-tactics/#apply 

Usually an apply in Isabelle matches the rule's conclusion with the subgoal's 
conclusion, unifies them and if them match then replaces the rules hypothesis
as the things to be proven given the substitution
e.g.
rule1 A1 => A2 => A
subgoal: B1 => B2 => C
apply rule rule. (* replace C with A1 A1 to be proven with the right subtitution*)

sig = Unify(A, C)

new subgoals:
sig(B1) => sig(B2) => sig(A1)
sig(B1) => sig(B2) => sig(A2)

note: notation: proof_state = <local_context, goals>
*)
Lemma modus_ponens:
  forall p q : Prop, 
    (p -> q) -> p -> q.
Proof.
  intros. (*  <H: p -> q, H0: p, q> *)
  apply H. (* matches H cocnlusion q with goal q, replaces p to be proven now *)
  assumption. (* goal p is in the assumption in the local context, so discharge it *)
Qed.

From Coq Require Import ssreflect ssrfun ssrbool.
Lemma modus_ponens':
  forall p q : Prop, 
    (p -> q) -> p -> q.
Proof.
  move=> p q p_implies_q p_fact. (* <..., p_fact: p, p_implies)q: p->q, goal=q>*)
  apply: p_implies_q.
  assumption.
Qed.

您鏈接的 SSReflect 文檔說明了它的作用:

在其有缺陷的形式中,此策略是以下內容的同義詞:

 intro top; first [refine top | refine (top _) | refine (top _ _) | …]; clear top.

其中top是一個新名稱, refine策略的序列試圖捕獲要插入的適當數量的通配符。 請注意,使用 refine 策略意味着該策略試圖將目標與常量擴展和子項求值相匹配。

apply. 采用A -> R形式的目標,並按順序嘗試統一(大致) A = RA = H1 -> RA = H1 -> H2 -> R等,直到它獲得統一一些H1 , ..., Hn (所以目標看起來像(H1 ->... -> Hn -> R) -> R )。 然后通過使用H1 ->... -> Hn -> R假設將子目標組合成R結論,將其變成子目標H1 , ..., Hn (實際行為比這更普遍,因為它也應該能夠處理依賴產品。)或者,簡而言之,

apply.

基本上是

intros H. apply H; clear H.

暫無
暫無

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

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