Bidirectional Lean4-Python transpiler
Project description
LP² (lp2) — Lean ↔ Python, squared
LP² = LP² = LP × LP = Lean ↔ Python, squared for bidirectional. Translates in both directions: Python→Lean and Lean→Python.
Translate Python functions with type hints into Lean 4 definitions, and Lean 4 definitions into Python functions.
Install
pip install lp2
Usage
CLI
# Python → Lean4
lp2 py2lean my_file.py
lp2 py2lean --stdin < my_file.py
# Lean4 → Python
lp2 lean2py my_file.lean
lp2 lean2py --stdin < my_file.lean
Python API
from lp2 import py_to_lean, lean_to_py, convert_str, convert_file
lean_code = py_to_lean("def add(x: int, y: int) -> int:\n return x + y\n")
py_code = lean_to_py("def add (x y : Int) : Int := x + y\n")
# Convenience
result = convert_str(source, "py2lean")
result = convert_file("input.py", "py2lean")
Examples
Python → Lean4:
def fib(n: int) -> int:
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
def fib (n : Int) : Int :=
if n ≤ 1 then n else fib (n - 1) + fib (n - 2)
Lean4 → Python:
def isZero (n : Int) : Bool := match n with
| 0 => true
| _ => false
def isZero(n: int) -> bool:
match n:
case 0:
return True
case _:
return False
Development
pip install -e ".[test]"
pytest
ruff format src/ tests/
prospector --with-tool ruff --with-tool mypy src/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lp2-0.1.0.tar.gz.
File metadata
- Download URL: lp2-0.1.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2dbda90a1fd0e51d5aebf80eef9e02a70f8ac7d4ed380956611105e2fce8253
|
|
| MD5 |
74a4099ef2ea5309432faa312b853cdf
|
|
| BLAKE2b-256 |
007c37e3d50a32bed1051d36dd3d7d434e0bfcfabc8564fcae0764fec25b3069
|
Provenance
The following attestation bundles were made for lp2-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on daedalus/lp2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp2-0.1.0.tar.gz -
Subject digest:
f2dbda90a1fd0e51d5aebf80eef9e02a70f8ac7d4ed380956611105e2fce8253 - Sigstore transparency entry: 1624240235
- Sigstore integration time:
-
Permalink:
daedalus/lp2@d9bd7b3a684a3f8e20d0689af48f4a5bac359540 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@d9bd7b3a684a3f8e20d0689af48f4a5bac359540 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lp2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lp2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4fb14b5861f6a94300d6d4e3cb15bd75e6e92ea66fccd9133fc03ef52267e8d
|
|
| MD5 |
8a7020aec666afe4ec253b0d8ae47acc
|
|
| BLAKE2b-256 |
f65d62426aadc1b1c911bb7a0730021a0b43d55073379d0a07c86ec03467016c
|
Provenance
The following attestation bundles were made for lp2-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on daedalus/lp2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp2-0.1.0-py3-none-any.whl -
Subject digest:
b4fb14b5861f6a94300d6d4e3cb15bd75e6e92ea66fccd9133fc03ef52267e8d - Sigstore transparency entry: 1624240263
- Sigstore integration time:
-
Permalink:
daedalus/lp2@d9bd7b3a684a3f8e20d0689af48f4a5bac359540 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@d9bd7b3a684a3f8e20d0689af48f4a5bac359540 -
Trigger Event:
release
-
Statement type: