Skip to main content

lean4_jupyter: A Lean 4 Jupyter kernel via REPL

Project description

lean4_jupyter

A Lean 4 Jupyter kernel via repl.

Status

Alpha.

What's already working

🔥 See it in action: Tutorial notebook.

The kernel can:

  • execute Lean 4 commands
  • execute Lean 4 tatics with magic like % proof immediately after a sorryed theorem
  • backtrack to earlier environment or proof states with magic like % env 1 or % prove 3
  • support magics like %cd or %load (loading a file)
  • support for importing modules from projects and their dependencies, e.g. Mathlib ( demo ).

Output:

  • In jupyter notebook and alike: echos the input annotated in alectryon style, at the corresponding line (not columns yet), with messages, proof states
  • In jupyter console and alike: echos the input annotated in codespan style, at the corresponding line:column, with messages, proof states

What's next

  • Fix repl#40 (PRed as repl#41)
  • Improve the alectryon annotation to support annotations in the middle of a line
  • Make magics like %cd and %load work more robustly
  • Support show tactics after %load
  • Add a CI based on papermill
  • Improve UI in Jupyter Dark themes
  • Minor code refactor to smooth things out

Installation

First, you need a working Lean 4 installation. You can install it via elan.

Verify that lean and lake is in your PATH:

lean --version
lake --help|head -n 1

they should output Lean/Lake versions, respectively.

Then, you need to have a working repl in your PATH.

You can build it from source (please read and adjust them before executing):

# If you need to clean up before reinstalling
# rm -rf ~/.lean4_jupyter/repl
# rm /usr/local/bin/repl

# Prepare a directory for lean4_jupyter where we install repl to
mkdir -p ~/.lean4_jupyter

# Before repl#41 merge, you might need to use this branch instead
git clone -b fix-dup https://github.com/utensil/repl ~/.lean4_jupyter/repl
# git clone https://github.com/leanprover-community/repl ~/.lean4_jupyter/repl

# Build repl
(cd ~/.lean4_jupyter/repl && lake build)

# Install repl to a place in your PATH, so less hassle of fiddling with PATH
ln -s ~/.lean4_jupyter/repl/.lake/build/bin/repl /usr/local/bin/repl

Verify that repl is working:

echo '{"cmd": "#eval Lean.versionString"}'|repl

In case repl hangs, you could kill it with

ps aux|grep repl|grep -v grep|awk '{print $2}'|xargs kill -9

Then, ensure that you have python, pip, jupyter installed, and run:

pip install jupyterlab

Then, install the kernel:

pip install lean4_jupyter
# or in development mode, check out the repo then run
# pip install -e .
python -m lean4_jupyter.install

To use it, run one of:

# Web UI
jupyter notebook
jupyter lab

# Console UI
# hint: use Ctrl-D and confirm with y to exit
jupyter console --kernel lean4
# hint: you need to run `pip install PyQt5 qtconsole` to install it
jupyter qtconsole --kernel lean4

Inspired by

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lean4_jupyter-0.0.1rc6.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

lean4_jupyter-0.0.1rc6-py2.py3-none-any.whl (14.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lean4_jupyter-0.0.1rc6.tar.gz.

File metadata

  • Download URL: lean4_jupyter-0.0.1rc6.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for lean4_jupyter-0.0.1rc6.tar.gz
Algorithm Hash digest
SHA256 fa7a12ae4ab5015d710d49fd76f729c004c60baafee7cf3b54028ee5995bfd48
MD5 99d29f35c371ceda29839431fef8ecb0
BLAKE2b-256 a45990d536802c4fa5c76aa494144324352649c754f097dfd448d5ffef36ecf9

See more details on using hashes here.

File details

Details for the file lean4_jupyter-0.0.1rc6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lean4_jupyter-0.0.1rc6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9fe999a40cf5240d460cbc28dd5fbbe5e8f6faba33dd7a8aa707dfac1e62074b
MD5 c3653fd1399a1cf6c96a3294be3653e6
BLAKE2b-256 24f6d79b0c005b50abe39b10e7a209b9d83b46d695d21118cfcecab7a09db7ee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page