Coq:在 if-then-else 下重写

标签 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).
Abort.
在这个例子中 rewrite失败(setoid_rewrite也是),建议注册以下
  • "subrelation eq (Basics.flip Basics.impl)" : 对我来说似乎很公平
  • "subrelation iff eq" : 没门!

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

    最佳答案

    我认为重写策略失败了,因为您想要的不是重写,而是减少( True /\ P 在技术上不等于 P )。如果您想维护if then else声明,我会建议以下解决方案(但有点不满意):
    Tactics.v文件,添加以下引理和 ltacs :

    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 ,你可以应用一个定理 Th使用 ite_app1 Th 到左侧或右侧或 ite_app2 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黑暗魔法以更通用的方式解决这个问题。

    关于Coq:在 if-then-else 下重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67180401/

    相关文章:

    recursion - Coq:在匹配语句中保存信息

    coq - 使用依赖类型进行析构

    functional-programming - Coq:使用 "rewrite"或 "apply"将 (negb (neqb true) 简化为 true ?

    .htaccess - URL 重写在 Wamp 服务器上不起作用

    haskell - 重写作为 GHC : Is it really needed? 中的实用优化技术

    relation - 如何在 Coq 中使用 Rmult 在一个术语中重写 Rle?

    coq - 使用假设删除匹配语句中的案例

    coq - 一般证明是什么以及为什么我不能删除它

    coq - 如何在 Coq 中切换当前目标?

    equality - 在 Coq 中将不同的相等类型定义为归纳类型