How to call proof assistant Coq from external software? Does Coq have some API? Is Coq command line interface rich enough to pass arguments in file and receive response in file? I am interested in Java or C++ bridges.
This is legitimate question. Coq is not the usual business software from which one can expect the developer friendly API. I had similary question about Isabelle/HOL and it was legitimate question with non-trivial answer.
As of today, there are three ways to interact with Coq, ordered from more effort to less power:
The OCaml API: This is what Coq plugins do, however, some parts of the OCaml API are notoriously difficult to master and a high expertise is usually needed. The API also changes from one release to another making maintenance hard. There is not official documentation for the OCaml API other than looking at the source code, but quite a few tutorials with different degrees of maintenance are floating around.
The XML protocol: This is what IDEs use. It allows the client to perform basic Coq document operations such as checking a part of it, limited search, retrieving goals, etc... official documentation
The command line: As the other answer details, this basically allows to check whether a file can be fully compiled by Coq.
Alternatively, there is an experimental protocol called "SerAPI" [disclaimer I am the author] that lies between 1 and 2. SerAPI is an extension of the XML protocol (but using SEXPs) that tries to provide some advantages of 1 along with richer query operations, without the disadvantages of linking with OCaml.
SerAPI is at a very experimental stage these days, however it may prove useful for some users. webpage
Some additional links:
The command line seems to be the way to go.
Coq includes several command-line tools, including the
coqc
compiler. This program takes a Coq theory file as input and tries to compile it. If something is wrong with the theory, the command fails with a non-zero exit code and writes some feedback onto its output streams. If everything is OK, the command is (typically) silent, exits with a zero exit code, and writes a.vo
file containing the compiled theory.For example:
Here are the docs for Coq's command line tools, which can take various flags: https://coq.inria.fr/refman/practical-tools/coq-commands.html
I am aware of two tools that use Coq as a subordinate proof engine: Frama-C and Why3. Looking at the sources at https://github.com/Frama-C/Frama-C-snapshot/blob/master/src/plugins/wp/ProverCoq.ml (methods
compile
andcheck
) and at https://github.com/AdaCore/why3/tree/master/drivers, these tools also seem to dump Coq theories to a file and then call Coq's command-line tools. As far as I can tell, there is no more direct API for Coq.