10

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

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

在归纳章节(http://www.cis.upenn.edu/~bcpierce/sf/Induction.html)中,我完全按照说明进行操作。我使用coqc 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 书中没有明确说明的其他东西,但我不知道是什么。

4

1 回答 1

15

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

(* [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.

(附注:当我通过 Software Foundations 工作时,我发现使用提供的.v文件作为我的工作材料非常有帮助。您不必担心省略的代码,您不必重新输入定义,所有问题就在那里。当然,您的里程可能会有所不同。)

于 2013-10-06T20:28:46.380 回答