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

时间:2013-10-06 19:26:08

标签: coq

我正在尝试通过在线软件基础书籍http://www.cis.upenn.edu/~bcpierce/sf/

来学习Coq

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

在归纳章节(http://www.cis.upenn.edu/~bcpierce/sf/Induction.html)中,我完全按照说明进行操作。我使用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".

我对Coq太新了,开始解压为什么这不起作用。我在网上发现了一些建议我首先需要做Require String.,然而,这也不起作用。有没有人通过这本书或遇到过这个问题?如何让代码正常工作?

这个Case关键字(策略?)似乎依赖于SF书未明确的其他内容,但我无法弄清楚是什么。

1 个答案:

答案 0 :(得分:12)

缺少的是一个字符串数据类型,它挂钩到"..."表示法; String模块包含这样的表示法和数据类型,但您必须告诉Coq通过Open Scope string_scope.使用该表示法但是,还缺少Case的实现,它只会显示修复字符串问题后。所有这些都是在“下载”tarball中的Induction.v文件中提供的,但它不包含在输出Induction.html中,可能是由于.v文件中的拼写错误。相关代码,它将是“命名案例”部分的第二段(紧接在“......但更好的方法是使用Case策略”之前,并且就在“这是一个如何{{1的例子”之前使用...“)是:

Case

(旁注:当我使用Software Foundations时,我发现使用提供的(* [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. 文件作为我的工作材料非常有帮助。您不必担心省略代码,您不需要必须重新输入定义,所有问题都在那里。当然,你的里程可能会有所不同。)

相关问题