ml4pg

Last updated: 2019-01-16 17:05:11 +0000

Upstream URL: git clone http://chriswarbo.net/git/ml4pg.git

Repo

View repository

View issue tracker

Contents of README follows


ML4PG usage instructions

ML4PG performs machine learning on Coq proof scripts, finding similarities in theorems/lemmas/etc. and clustering them. For more information, see ml4pg_manual.pdf

Quick Start

ML4PG is maintained at http://chriswarbo.net/essays/repos/ml4pg.html where you can check out the latest version using git.

Once you’ve downloaded ML4PG, the easiest way to use it is via the Nix package manager. If your operating system doesn’t provide Nix, you can get it manually from http://nixos.org/nix

Once you have Nix installed, open a terminal in the top-level ML4PG directory and run:

<pre><code>nix-shell --pure</code></pre>

This will tell Nix to download and install all of ML4PG’s dependencies, then open a shell with only these dependencies available (omit “–pure” if you want access to your regular commands too).

NOTE: These dependencies will <em>not</em> conflict with any existing software. They will be installed into standalone directories and made available to the shell via environment variables. The packages will also be cached, to prevent downloading them every time. For more information, see the Nix Web site.

Slow Start

For those who don’t want to use Nix, or want to know a little about what it’s doing. These details are just an English prose version of <code>default.nix</code>.

Dependencies

<ul> <li>Emacs</li> <li>ProofGeneral</li> <li>Coq</li> <li>Java runtime</li> <li>Graphviz</li> </ul>

ML4PG runs inside Emacs, on top of ProofGeneral. Although ProofGeneral works with several languages/proof systems, ML4PG will only work with Coq.

The machine learning is performed by Weka, which is included, but Weka requires a Java runtime to work.

Graphviz is used to generate the output.

Environment

ML4PG can be controlled using several environment variables. If these aren’t provided, you will either be prompted to choose a value, or a default will be used:

<ul> <li><code>ML4PG_HOME</code> is required, and should be the top-level directory of ML4PG, ending in a “/”. This is used to load Emacs Lisp files and cache intermediate results. This will be set automatically by <code>nix-shell</code>.</li> <li><code>ML4PG_TYPE</code> should be either <code>coq</code> or <code>ssreflect</code>, and determines which implementation of ML4PG should be used. There is effort to bring these together into a common “generic” version, but that’s not complete yet. Default is <code>coq</code>.</li> <li><code>HYPOTHESES_FILE</code>, if provided, should be a file name. During feature extraction, the hypotheses available at each proof step will be written to this file. Useful for distinguishing between tactic arguments and fresh variables.</li> <li><code>TEST_VERBOSE</code>, if provided and set to <code>t</code>, will output extra debug information. Mainly useful when running tests.</li> <li><code>TEST_SUITE</code> determines which test suite to run, either <code>coq</code> or <code>ssreflect</code>. Defaults to <code>ML4PG_TYPE</code>.</li> <li><code>ML4PG_TEST_PATTERN</code>, if provided, should be a regular expression matching the names of tests to run. All tests start with <code>ml4pg-</code>, so that’s the default value.</li> </ul>

Running ML4PG

Once you have a shell with the dependencies available and ML4PG_HOME set (whether by Nix or otherwise) you can start ML4PG. There are several ways to do this:

Testing

ML4PG comes with an automated test suite, which you can use to verify that it’s installed and working. The following command will run all tests:

<pre><code>./tests/runner.sh</code></pre>

Interactive usage

It is recommended to run ML4PG in its own Emacs instance, since it might interfere with existing buffers, or may cause Emacs to exit/crash.

You can launch Emacs with ML4PG available like this:

<pre><code>emacs -l ml4pg.el</code></pre>

If you want to run ML4PG in an existing Emacs instance, you can use the following snippet:

<pre><code>(load-file "ml4pg.el")</code></pre>

Either way, you can then open a Coq file and ML4PG will provide a <code>Statistics</code> menu of commands you can run.

You can also specify your Coq file via the commandline:

<pre><code>emacs -l ml4pg.el --file my_script.v</code></pre>

Non-interactive usage

ML4PG can be run non-interactively from the commandline or from a shell script. To do this, use Emacs in “batch mode”:

<pre><code>emacs --batch -l ml4pg.el</code></pre>

That command will exit immediately after loading ML4PG; to do run something more interesing you can provide some extra Emacs Lisp code in several ways. You can provide an in-line snippet of ELisp on the command line:

<pre><code>emacs --batch -l ml4pg.el --eval '(my-function)'</code></pre>

You can provide an Emacs Lisp file as a script (<code>--script</code> implies <code>--batch</code>):

<pre><code>emacs -l ml4pg.el --script my-script.el</code></pre>

If your ELisp script loads ML4PG, via <code>(load-file "ml4pg.el")</code>, then you only need to provide your script:

<pre><code>emacs --script my-script.el</code></pre>

You can also give your script a “shebang” for executing Emacs automatically from the shell, eg.

<pre><code>$ cat my-script.el #!emacs --script (load-file "ml4pg.el") (your elisp goes here) $ ./my-script.el</code></pre>

Extracting Hypotheses

When ML4PG’s <code>(extract-feature-theorems)</code> function is called (bound to the menu entry “Extract info up to point”), it will run through the Coq script and store the names which are in-scope at each step.

If you want these to be saved to a file, you can provide a <code>HYPOTHESES_FILE</code> environment variable, or set the LISP variable <code>hypotheses-file</code>.

These hypotheses are stored internally by the <code>proof-hypotheses</code> LISP variable.

For example, to extract the hypotheses from <code>foo.v</code>:

<pre><code>$ ML4PG_MODE=coq HYPOTHESES_FILE=/tmp/foo.hyps emacs \ --load ml4pg.el \ --file foo.v \ --eval '(progn (goto-char (point-max)) (extract-feature-theorems))'</code></pre>