尝试使用用例时出现coq错误。软件基础书籍中的示例

尝试使用用例时出现coq错误。软件基础书籍中的示例,coq,Coq,我试图通过在线软件基础书籍学习Coq: 我正在使用交互式命令行Coq解释器coqtop 在归纳章节()中,我完全按照说明进行操作。我使用coqc Basics.v编译Basics.v。然后启动coqtop,并准确键入: Require Export Basics. Theorem andb_true_elim1 : forall b c : bool, andb b c = true -> b = true. Proof. intros b c H. destruct b.

我试图通过在线软件基础书籍学习Coq:

我正在使用交互式命令行Coq解释器
coqtop

在归纳章节()中,我完全按照说明进行操作。我使用
coqc Basics.v
编译Basics.v。然后启动
coqtop
,并准确键入:

Require Export Basics. 
Theorem andb_true_elim1 : forall b c : bool,
  andb b c = true -> b = true.
Proof.
  intros b c H.
  destruct b.
  Case "b = true".
在最后一行之前,一切都正常,在这一点上,我得到以下错误:

Toplevel input, characters 5-15:
> Case "b = true".
>      ^^^^^^^^^^
Error: No interpretation for string "b = true".
我是个新手,没法解释为什么这不管用。我在网上发现了一些建议,建议我需要执行
Require String。
首先,这也不起作用。有人读过这本书或遇到过这个问题吗?如何使代码正常工作


这个Case关键字(策略?)似乎依赖于SF书中没有明确说明的其他内容,但我不知道需要什么。

缺少的是一个字符串数据类型,它与
“…”符号挂钩;
String
模块包含这样的符号和数据类型,但是您必须通过
Open Scope String\u Scope告诉Coq使用该符号。
但是,还缺少
Case
的实现,它只有在您解决字符串问题后才会出现。所有这些都是在“下载”tarball中的
inclusion.v
文件中提供给您的,但它没有包含在输出
inclusion.html
中,可能是由于
.v
文件中的键入错误。相关代码,即“命名案例”部分的第二段(紧跟在“……但更好的方法是使用
案例
策略”之后,紧跟在“以下是如何使用
案例
的示例…”之前),是:


(旁注:当我研究软件基础时,我发现使用提供的
.v
文件作为我的工作资料非常有帮助。你不必担心省略的代码,你不必重新键入定义,所有问题都在那里。当然,你的里程数可能会有所不同。)

很酷,谢谢,这非常有效。将我指向inclution.v文件也非常有帮助,我没有想到在v中会有代码,而不是html中。所以我猜这意味着,案例不是语言中固有的东西,而是科幻小说作者为注释证据而添加的东西?这是一种常见的做法还是SF的做事方式所特有的?另外,我不知道为什么“Case”的东西比简单的注释(如(*Case b=true*)要好。@quadelirus
Case
的东西会抛出一个错误,从而在发生变化时简化调试。示例:如果您对
nat
s进行归纳,并且您的基础(
O
)案例的策略在更改后不再解决该部分,它将在
case“n=sn'”
上抛出一个错误,而不是继续将
s
-案例的内容应用到(仍然未完成)
O
-case.@quadelirus这些
case
-marker可以在软件基础以外的开发中找到,但也有其他样式。就我个人而言,我更喜欢“Chlipala风格”的证明(即,自动化到证明足够短,您根本不需要任何
案例
标记。)--请参阅另一本Coq书籍。+1感谢您发布这篇文章。我正在研究这些例子,但也错过了这个。这正是我所需要的。案件策略怎么了?它被移除了吗?您与软件基础的链接已断开,2019年1月的版本在此没有在归纳中使用或定义案例策略。v:
(* [Case] is not built into Coq: we need to define it ourselves.
    There is no need to understand how it works -- you can just skip
    over the definition to the example that follows.  It uses some
    facilities of Coq that we have not discussed -- the string
    library (just for the concrete syntax of quoted strings) and the
    [Ltac] command, which allows us to declare custom tactics.  Kudos
    to Aaron Bohannon for this nice hack! *)

Require String. Open Scope string_scope.

Ltac move_to_top x :=
  match reverse goal with
  | H : _ |- _ => try move x after H
  end.

Tactic Notation "assert_eq" ident(x) constr(v) :=
  let H := fresh in
  assert (x = v) as H by reflexivity;
  clear H.

Tactic Notation "Case_aux" ident(x) constr(name) :=
  first [
    set (x := name); move_to_top x
  | assert_eq x name; move_to_top x
  | fail 1 "because we are working on a different case" ].

Tactic Notation "Case" constr(name) := Case_aux Case name.
Tactic Notation "SCase" constr(name) := Case_aux SCase name.
Tactic Notation "SSCase" constr(name) := Case_aux SSCase name.
Tactic Notation "SSSCase" constr(name) := Case_aux SSSCase name.
Tactic Notation "SSSSCase" constr(name) := Case_aux SSSSCase name.
Tactic Notation "SSSSSCase" constr(name) := Case_aux SSSSSCase name.
Tactic Notation "SSSSSSCase" constr(name) := Case_aux SSSSSSCase name.
Tactic Notation "SSSSSSSCase" constr(name) := Case_aux SSSSSSSCase name.