简体   繁体   English

如何在 linux 中将交互式 shell 用于 Coq 代码?

[英]How in linux to use interactive shell for Coq code?

I want to write and debug code in Coq similar to how I write code in Python, R, etc. Specifically:我想在 Coq 中编写和调试代码,类似于我在 Python、R 等中编写代码的方式。具体而言:

I have one terminal window where my code.v file is shown, eg:我有一个终端 window ,其中显示了我的code.v文件,例如:

Definition double (x:nat) : nat := 2 * x.
Definition tripple (x:nat) : nat := 3 * x.

Now in another terminal I want to have an interactive shell that could accept commands to load the code from a code.v , check it, etc. For example:现在在另一个终端中,我想要一个交互式 shell 可以接受从code.v加载代码的命令,检查它等等。例如:

Load code.v // What's the command for this?
Print double. // Expect to see output "double : nat -> nat"

Question 1: what kind of command provides me such interactive shell and what command should I execute in the interactive shell to load a file?问题1:什么样的命令为我提供了这样的交互式shell,我应该在交互式shell中执行什么命令来加载文件?

Moreover, if in my code.v file I have an unfinished proof, eg此外,如果在我的code.v文件中我有一个未完成的证明,例如

Lemma ex4: forall (X : Set) (P : X -> Prop),
  ~(forall x, ~ (P x)) -> (exists x, (P x)).
Proof.
  intros X P A.
  apply not_all_ex_not in A.
  destruct A.

Question 2: Is there a command from an interactive shell like check code.v which would print me a state of my proof, like Coqide does when you press ctrl+down问题 2:是否有来自交互式 shell 的命令,例如check code.v ,它会打印我的证明的 state,就像 Coqide 在您按下ctrl+down时所做的那样

1 subgoal
X : Set
P : X -> Prop
x : X
H : ~ ~ P x
______________________________________(1/1)
exists x0 : X, P x0

Note that I prefer to do everything through linux terminals, rather than using an IDE.请注意,我更喜欢通过 linux 终端完成所有操作,而不是使用 IDE。

Normally if you installed coq and coqide by the usual means, you should have a command called coqtop (it is shorthand for coq toplevel).通常,如果您通过通常的方式安装了coqcoqide ,您应该有一个名为coqtop的命令(它是 coq toplevel 的简写)。 It reads all commands from stdin and prints all results (that would normally go in goal or response windows of coqide ) in stdout .它从stdin读取所有命令并在stdout中打印所有结果(通常是目标中的 go 或 coqide 的响应coqide )。

with your example of code.v you can run the following command.使用您的code.v示例,您可以运行以下命令。

coqtop -require-import Classical < code.v

This will display all output generated by all commands in your file and terminate.这将显示文件中所有命令生成的所有 output 并终止。 The last output will be the result of the last command, making it possible to see the last open goal.最后一个 output 将是最后一个命令的结果,从而可以看到最后一个打开的目标。 Note that -require-import Classical is needed because lemma not_all_ex_not is defined in that module.请注意,需要-require-import Classical ,因为在该模块中定义了引理not_all_ex_not

In practice, this is not very convenient, because you have to rerun the whole file every time you add a new command.实际上,这不是很方便,因为每次添加新命令时都必须重新运行整个文件。 You can also keep the system running, with the effect of executing the file code.v already recorded, by typing the following command line.您还可以通过键入以下命令行来保持系统运行,执行已记录的文件code.v

coqtop -require-import Classical -load-vernac-source code.v

This does not display the goals after the last command, but you can require it by typing the command Show.这不会在最后一个命令之后显示目标,但您可以通过键入命令Show. You can then type more commands in the terminal to see their effect on the state of the coqtop programs.然后,您可以在终端中键入更多命令,以查看它们对coqtop程序的 state 的影响。 It is then your responsibility to record the commands you sent to coqtop for later reproduction of the proofs.然后,您有责任记录您发送到coqtop的命令,以便以后复制证明。 The user-interfaces like coqide , proof-general or vscoq are mostly meant to help you in this recording task. coqideproof-generalvscoq等用户界面主要用于帮助您完成此录制任务。

For more information, you should type有关更多信息,您应该键入

coqtop --help

You should also consider using coqtop in combination with rlwrap .您还应该考虑将coqtoprlwrap结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM