Livebook smart cell for Isabelle theories: a CodeMirror editor with Isabelle outer-syntax highlighting and symbol display, checked on demand by a local Isabelle server.
This is an alpha release: expect rough edges and breaking changes.
Mix.install([
{:kino_isabelle, "~> 0.1.0-alpha.2"}
])Isabelle must be installed, with isabelle on PATH or ISABELLE_TOOL
pointing to it, unless the runtime uses a running server. Tested with Isabelle2025-2. A logic session without a built
heap is built on first use, which can take long. Server cleanup relies on
/bin/sh, so Windows is not supported.
Isabelle also needs tar on the PATH of the Livebook runtime; without it,
the server fails with Return code 1 from bash script: ".../gnu-utils-.../etc/settings".
The NixOS services.livebook service, for example, has no tar on its PATH;
add pkgs.gnutar to services.livebook.extraPackages.
livebooks/demo.livemd walks through the cell.
Add the Isabelle theory smart cell and write theory text. By default the
cell generates the header (theory Scratch imports Main begin … end) from
the toolbar fields; with header mode "in text" the cell holds a complete
theory.
- Check runs Isabelle on the current text. Errors and warnings appear as lint diagnostics; the panel below the editor shows all messages of the command under the cursor. Nothing is checked while typing.
-
Evaluating the cell returns a
KinoIsabelle.Result, shown as Summary / Messages / Errors / Raw tabs, and binds it to the variable in Assign to (result,result2, … by default). An unchanged theory is not checked twice. - Symbols such as
\<forall>are displayed as∀. Type\forall,\<forallor an abbreviation like==>and pick the symbol from the completion list.
The first check of a runtime starts the Isabelle server and the logic session. They are shared by all cells of the runtime and stopped with it. All theories of a runtime are written to one directory, so a cell can import the theory of another cell that was checked before.
Without the smart cell:
{:ok, result} = KinoIsabelle.check(~S(lemma "\<forall>x. x = x" by simp), imports: ["Main"])Instead of starting a server of its own, a runtime can connect to one that is already running. Configure it before the first check, for example in the setup cell:
Mix.install(
[{:kino_isabelle, "~> 0.1.0-alpha.2"}],
config: [kino_isabelle: [server: [port: 4711, password: "…"]]]
)isabelle server prints port and password when it starts
(server "isabelle" = 127.0.0.1:4711 (password "…")), isabelle server -l
lists the running servers. :host defaults to "127.0.0.1". The setting is
read at the first check, so Application.put_env(:kino_isabelle, :server, …)
before that works as well.
Logic sessions already running on the server are reused when their ids are given by logic name:
server: [port: 4711, password: "…", sessions: %{"HOL" => "<session_id>"}]Cells whose logic is HOL then check in that session; other logics are
started on the server. A session id is what the server's session_start
command returns, e.g. typed into the console of isabelle server -c:
session_start {"session": "HOL"}.
- Isabelle servers listen on 127.0.0.1 only and read the theory files from the
runtime's temporary directory (
kino_isabelle_<OS pid>inSystem.tmp_dir!()). The server must therefore run on the same machine, or see that directory under the same path. - The server and the logic sessions the runtime started on it keep running when the runtime stops.
mix test # includes Isabelle integration tests when isabelle is found
cd assets && npm install && npm test
npm run build # rebuilds lib/assets/cell/build (committed), including
# THIRD_PARTY_LICENSES.txt for the bundled npm packages
mix kino_isabelle.gen_syntax HOL # regenerates priv/keywords.json and priv/symbols.jsonThe keyword table is generated for one logic (HOL); keywords that other sessions add are not highlighted. After regenerating it, rebuild the assets.
MIT, see LICENSE. The bundled editor code (CodeMirror and its
dependencies, all MIT) comes with its licenses in
lib/assets/cell/build/THIRD_PARTY_LICENSES.txt.