Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

I have one terminal window where my code.v file is shown, e.g.:

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:

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?

Moreover, if in my code.v file I have an unfinished proof, e.g.

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

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.

like image 951
mercury0114 Avatar asked Nov 15 '25 23:11

mercury0114


1 Answers

Normally if you installed coq and coqide by the usual means, you should have a command called coqtop (it is shorthand for 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.

with your example of code.v you can run the following command.

coqtop -require-import Classical < code.v

This will display all output generated by all commands in your file and terminate. The last output will be the result of the last command, making it possible to see the last open goal. Note that -require-import Classical is needed because lemma not_all_ex_not is defined in that module.

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.

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. You can then type more commands in the terminal to see their effect on the state of the coqtop programs. It is then your responsibility to record the commands you sent to coqtop for later reproduction of the proofs. The user-interfaces like coqide, proof-general or vscoq are mostly meant to help you in this recording task.

For more information, you should type

coqtop --help

You should also consider using coqtop in combination with rlwrap.

like image 144
Yves Avatar answered Nov 17 '25 21:11

Yves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!