rems-project / lem

Lem semantic definition language
Other
130 stars 15 forks source link

Lem

Lem is a tool for lightweight executable mathematics, for writing, managing, and publishing large-scale portable semantic definitions, with export to LaTeX, executable code (currently OCaml) and interactive theorem provers (currently Coq, HOL4, and Isabelle/HOL, though the generated Coq is not necessarily idiomatic). It is also intended as an intermediate language for generating definitions from domain-specific tools, and for porting definitions between interactive theorem proving systems.

The language, originally based on a pure fragment of OCaml, combines features familiar from functional programming languages with logical constructs. From functional programming languages we take pure higher-order functions, general recursion, recursive algebraic datatypes, records, lists, pattern matching, parametric polymorphism, a simple type class mechanism for overloading, and a simple module system. To these we add logical constructs familiar in provers: universal and existential quantification, sets (including set comprehensions), relations, finite maps, inductive relation definitions, and lemma statements. Then there are facilities to let the user tune how Lem definitions are mapped into the various targets (by declaring target representations and controlling notation, renaming, inlining, and type classes), to generate witness types and executable functions from inductive relations, and for assertions.

Lem has been used in several applications, some of which can be found in the examples directory. As of 2020, Lem remains in continuous use but is not under active development.

Papers

Documentation

Documentation can be found in doc/built-doc, including:

To install and build

Lem is available as an opam package and a github repo.

With OPAM (released version)

First, ensure you have opam (the OCaml package manager) installed, version 2.0 or greater (opam 1 versions of Lem are no longer supported). You can use your system's package manager e.g. sudo apt-get install opam (e.g. on Ubuntu 20.04) or follow the instructions from the opam website. On older Ubuntu versions you will not be able to use their package manager's opam 1 version, and will need to install opam 2 following the instructions on the opam website.

Then opam install lem will install the latest Lem version.

With OPAM (github checkout)

In the checkout directory, run opam pin add lem ..

To rebuild and reinstall after local changes, run opam upgrade --working-dir lem (or opam upgrade -w lem).

Without OPAM

The command make (make world) builds the lem binary, and places a symbolic link to it in the top-level directory. Now set the LEMLIB environment variable to PATH_TO_LEM/library, or alternately pass the -lib PATH_TO_LEM/library flag to lem when you run it.

Backend libraries

Running make only generates Lem. It not generate the libraries needed to use Lem's output for certain backends. To generate the libraries for a specific backend, please run

These targets depend on the corresponding tool being installed. If you just want to generate the input that Lem gives to these tools, please run make libs.

Dependencies

Lem depends on OCaml. Lem has been tested against OCaml 4.07.0, 4.12.0 and 5.0.0~beta1. Other versions might or might not work. Lem requires the OCaml ZArith library for arbitrary precision arithmetic. Lem has been tested against ZArith version 1.4 and 1.9.1. Other versions might or might not work.

The generated Isabelle theories require the Word_Lib entry of the Archive of Formal Proofs to be installed and set up (e.g. by adding the path to Word_Lib to $ISABELLE_HOME_USER/ROOTS). An Isabelle 2022 version of the AFP can be downloaded here.

Supported versions of target software

Lem has been tested against the following versions of the backend software:

Examples

The examples directory in the repository contains or points to several of the early major examples of Lem usage:

Lem and Ott

Lem shares many of the goals of our Ott tool: both emphasize source readability, and multi-prover compatibility. However, Lem is a general-purpose specification language, whereas Ott is a domain-specific language for writing specifications of programming languages (i.e., inductive relations over syntax). Thus, Ott supports rich user-defined syntaxes, whereas Lem supports functional programming idioms. The two can be used together in some cases: Ott can now generate Lem specifications.

History

People

Lem has been developed principally by Dominic Mulligan, Kathryn E. Gray, Scott Owens, Peter Sewell, and Thomas Tuerk; with additional contributions from Basile Clement, Brian Campbell, Christopher Pulte, David Sheets, Fabian Immler Frederic Loulergue, Francesco Zappa Nardelli. Gabriel Kerneis, James Lingard, Jean Pichon-Pharabod, Justus Matthiesen, Kayvan Memarian, Kyndylan Nienhuis, Lars Hupel, Mark Batty, Michael Greenberg Michael Norrish, Ohad Kammar, Peter Boehm, Robert Norton Sami Mäkelä, Shaked Flur Stephen Kell, Thibaut Pérami, Thomas Bauereiss, Thomas Williams, Victor Gomes, and emersion.

License

Lem is made available under the BSD 3-clause license, with the exception of a few files derived from OCaml, which are under the GNU Library GPL.