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

Joh*_*ohn 8 coq

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

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

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

一切正常,直到最后一行,此时我收到以下错误:

Toplevel input, characters 5-15:
> Case "b = true".
>      ^^^^^^^^^^
Error: No interpretation for string "b = true".
Run Code Online (Sandbox Code Playgroud)

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

这个Case关键字(战术?)似乎依赖于SF书不清楚的其他东西,但我无法弄清楚是什么.

Ant*_*sky 13

缺少的是一个字符串数据类型,它挂钩到"..."符号; 该String模块包含这样的表示法和数据类型,但您必须告诉Coq使用该表示法Open Scope string_scope. 还有什么也缺失,但是,是一个实现Case,只有在修复字符串问题后才会显示.所有这些都是Induction.v在"下载"tarball 中的文件中提供的,但它不包含在输出中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.
Run Code Online (Sandbox Code Playgroud)

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