Coq 战术自动化:简单的决策过程

Coq 战术自动化:简单的决策过程,coq,coq-tactic,Coq,Coq Tactic,我正在尝试自动决定ASCII字符是否为空白。这是我目前拥有的 Require Import Ascii String. Scheme Equality for ascii. Definition IsWhitespace (c : ascii) := (c = "009"%char) \/ (c = "032"%char). Definition isWhitespace (c : ascii) : {IsWhitespace c} + {not (IsWhitespace c)}. Pr

我正在尝试自动决定ASCII字符是否为空白。这是我目前拥有的

Require Import Ascii String.

Scheme Equality for ascii.

Definition IsWhitespace (c : ascii) := (c = "009"%char) \/ (c = "032"%char).

Definition isWhitespace (c : ascii) : {IsWhitespace c} + {not (IsWhitespace c)}.
Proof.
  unfold IsWhitespace.
  pose proof (ascii_eq_dec c "009"%char) as [H1|H1];
  pose proof (ascii_eq_dec c "032"%char) as [H2|H2];
  auto.
  right. intros [H3|H3]; auto.
Admitted.

什么样的方法可以使证明更简洁?

证明几乎是最简洁的!你最多能做的就是调用一种更强大的策略,比如
直觉

Definition isWhitespace (c : ascii) : {IsWhitespace c} + {not (IsWhitespace c)}.
Proof.
now unfold IsWhitespace;
    case (ascii_eq_dec c "009"%char);
    case (ascii_eq_dec c " "%char); intuition.

通常,使证明更加自动化需要编写比开始时多一点的代码,以便处理更多的案例。采用这种方法,我改编了以下样本:

有了这个样板,你的证据就变成了

Definition IsWhitespace (c : ascii) := (c = "009"%char) \/ (c = "032"%char).
Definition isWhitespace (c : ascii) : Decidable (IsWhitespace c) := _.
这是最短的证明。(请注意,
:=
.Proof.exact.Defined.
相同,后者本身与
.Proof.typeclasses.Defined.
相同)

请注意,这与ejgallego的证明非常相似,因为
tauto
直觉失败
相同


还要注意的是,它比简单地在*中使用
hnf要长得多,但也更强大;tauto
,处理几十种不同类型的可判定命题。

按照Jason回答的精神,我们当然可以使用一些处理可判定等式的库来得出您的结果:

这将
ascii
声明为具有可判定等式的类型:

From Coq Require Import Ascii String ssreflect ssrfun ssrbool.
From mathcomp Require Import eqtype ssrnat.

Lemma ascii_NK : cancel N_of_ascii ascii_of_N.
Proof. exact: ascii_N_embedding. Qed.

Definition ascii_eqMixin := CanEqMixin ascii_NK.
Canonical ascii_eqType := EqType _ ascii_eqMixin.
在这种风格中,通常您声明您的属性是可判定命题,因此无需证明:

Definition IsWhitespaceb (c : ascii) := [|| c == "009"%char | c == " "%char].
但是,如果需要,您当然可以恢复非计算性的:

Definition IsWhitespace (c : ascii) := (c = "009"%char) \/ (c = "032"%char).

Lemma whitespaceP c : reflect (IsWhitespace c) (IsWhitespaceb c).
Proof. exact: pred2P. Qed.

当然可以使用更多的自动化。

这太有趣了!请您解释一下
参数
方面好吗?为什么要使用
符号
而不是
定义
。。。这种方法看起来很像标准库的
Coq.Structures.Equalities
部分,有什么特别的理由不使用它吗?
参数
位允许您编写
dec(x=y)
来表示“通过类型类解析找到
x=y
的可判定性实例并在此处使用”。没有它,
dec(x=y)
是一个类型错误,因为
dec
意味着“通过类型类解析,找到任何命题的可判定性的第一个实例,并在这里使用它”;大小写(ascii_eq_dec“009”%char),(ascii_eq_dec”%char);陶托。
我们使用
compute
来展开这里的一切。
Definition IsWhitespace (c : ascii) := (c = "009"%char) \/ (c = "032"%char).

Lemma whitespaceP c : reflect (IsWhitespace c) (IsWhitespaceb c).
Proof. exact: pred2P. Qed.