Coq:在if-then-else下重写

Coq:在if-then-else下重写,coq,coq-tactic,rewriting,Coq,Coq Tactic,Rewriting,我有时需要在不破坏区分的前提下,对if-then-else的一个分支进行简化 From Coq Require Import Setoid. Lemma true_and : forall P, True /\ P <-> P. Proof. firstorder. Qed. Goal (forall (b:bool) P Q, if b then True /\ P else Q). intros. Fail rewrite (true_and P). Abor

我有时需要在不破坏区分的前提下,对if-then-else的一个分支进行简化

From Coq Require Import Setoid.

Lemma true_and :
  forall P, True /\ P <-> P.
Proof.
  firstorder.
Qed.

Goal (forall (b:bool) P Q, if b then True /\ P else Q).
  intros.
  Fail rewrite (true_and P).
Abort.
来自Coq的
需要导入Setoid。
引理true_和:
对于all P,True/\P。
证明。
一等货。
Qed。
目标(对于所有(b:bool)pq,如果b,则为True/\P else Q)。
介绍。
重写失败(为真)。
中止
在本例中,
rewrite
失败(
setoid\u rewrite
),建议注册以下内容

  • “子关系eq(Basics.flip Basics.impl)”
    :对我来说似乎很公平
  • “子关系iff eq”
    :不可能

为什么重写引擎要求这么高?

我认为重写策略失败了,因为你想要的不是重写,而是减少(
True/\p
在技术上不等于
p
)。如果要维护
If-then-else
语句,我将建议以下解决方案(但有点不满意):

tractics.v
文件中,添加以下引理和LTAC:

Lemma if_then_else_rewrite:
  forall (b: bool) (T1 T2 E1 E2 : Prop),
    (T1 -> T2) ->
    (E1 -> E2) ->
    (if b then T1 else E1) ->
    (if b then T2 else E2).
Proof.
  destruct b; auto.
Qed.

Ltac ite_app1 Th :=
  match goal with
  | H:_ |- if ?b then ?T2 else ?E =>
    eapply if_then_else_rewrite with (E1 := E) (E2 := E);
    [eapply Th | eauto |]
   end.


Ltac ite_app2 Th :=
  match goal with
  | H:_ |- if ?b then ?T else ?E2 =>
    eapply if_then_else_rewrite with (T1 := T) (T2 := T);
    [eauto | eapply Th |]
   end.
然后,当您有一个顶级
if-Then-else
目标时,您可以使用
ite\u app1 Th
ite\u app2 Th
在左侧或右侧应用定理
Th
。例如,您的目标是:

Goal (forall (b:bool) P Q, if b then (True /\ P) else Q).
  intros.
  ite_app1 true_and. (* -> if b then P else Q *)

您可能需要根据您的需要对LTAC进行微调(在上下文中应用,而不是在目标中应用,等等),但这是第一个解决方案。也许有人可以带来更多的ltac黑魔法,以更普遍的方式解决这个问题。

谢谢!根据你的建议,我提出了以下策略,仍然利用了重写引擎(在选择子术语时非常有效,除非在if then else下……):
Ltac ite_rewrite Hr:=重写Hr | | |将目标与| | context匹配[if | then | else]=>重写if then | else|u rewrite;[| ite_rewrite Hr;reflectivity | ite_rewrite Hr;reflectivity]|=>idtac end.
(在
if_then_else_rewrite
中使用等价项更改含义后)是的,这样更好!您可能会发现,在某些情况下,该策略会创建无法立即解决的新目标(即,
自反性
还不够),因此您可以进行重写,并且仍然有复杂的重写证明,而无需事先明确说明(正向推理对于定义/引理的更改更为脆弱)。