使用Coq中的匹配表达式分解构造函数的相等性

时间:2018-05-01 14:04:11

标签: coq coq-tactic

我有一个类似于Decomposing equality of constructors coq的问题,但是,我的等式包含一个match表达式。考虑一下这个例子(这是荒谬的,但仅用于澄清):

Fixpoint positive (n : nat) :=
  match n with
  | O => Some O
  | S n => match positive n with
    | Some n => Some (S n)
    | None => None (* Note that this never happens *)
    end
  end.

Lemma positiveness : forall n : nat, Some (S n) = positive (S n).
Proof.
intro.
simpl.

此时,在环境中使用n : nat,目标是:

Some (S n) =
match positive n with
| Some n0 => Some (S n0)
| None => None
end

我想将其转换为环境n, n0 : nat中的两个子目标:

positive n = Some n0  (* Verifying the match *)
S n = S n0            (* Verifying the result *)

我希望如果证明相等的match有多个可能有效的案例,那么新目标就是所有可能性的分离,例如对

Some (S n) =
match positive n with
| Some (S n0) => Some (S (S n0))
| Some O => Some (S O)
| None => None
end

我希望

   (positive n = Some (S n0) /\ S n = S (S n0))  (* First alternative *)
\/ (positive n = Some O      /\ S n = S O)       (* Second alternative *)

是否有Coq战术可以做到这一点或类似事情?

2 个答案:

答案 0 :(得分:2)

  

是否有Coq战术可以做到这一点或类似事情?

如果您运行destruct (positive n) eqn:H,您将获得两个子目标。在第一个子目标中,你得到:

  n, n0 : nat
  H : positive n = Some n0
  ============================
  Some (S n) = Some (S n0)

在第二个子目标中你得到了

  n : nat
  H : positive n = None
  ============================
  Some (S n) = None

这不是你要求的,但在第二个子目标中,你可以写assert (exists n0, positive n = Some n0);这将为您提供所寻求的目标,并且您可以通过destruct exists并使用congruencediscriminate来展示剩余的目标,以显示positive n不能同时为NoneSome

答案 1 :(得分:0)

我无法理解你的动机。在您的示例中,使用更一般的引理更容易证明您的结果:

Fixpoint positive (n : nat) :=
  match n with
  | O => Some O
  | S n => match positive n with
    | Some n => Some (S n)
    | None => None (* Note that this never happens *)
    end
  end.

Lemma positiveness n : positive n = Some n.
Proof.
  now induction n as [|n IH]; simpl; trivial; rewrite IH.
Qed.

Lemma positiveness' n : Some (S n) = positive (S n).
Proof. now rewrite positiveness. Qed.

您想要执行的案例分析是否更适合其他应用程序?