{"id":50446864,"url":"https://github.com/0art0/lean3-statement-translation-tool","last_synced_at":"2026-05-31T22:02:14.593Z","repository":{"id":63875682,"uuid":"570479748","full_name":"0art0/lean3-statement-translation-tool","owner":"0art0","description":"A tool for automatic formalisation of natural language theorem statements to Lean3 code using OpenAI Codex.","archived":false,"fork":false,"pushed_at":"2023-06-14T10:44:09.000Z","size":75,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-30T19:24:25.343Z","etag":null,"topics":["codex","lean"],"latest_commit_sha":null,"homepage":"","language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0art0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-25T09:42:24.000Z","updated_at":"2023-09-05T02:45:17.000Z","dependencies_parsed_at":"2023-02-05T20:45:50.603Z","dependency_job_id":null,"html_url":"https://github.com/0art0/lean3-statement-translation-tool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0art0/lean3-statement-translation-tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0art0%2Flean3-statement-translation-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0art0%2Flean3-statement-translation-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0art0%2Flean3-statement-translation-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0art0%2Flean3-statement-translation-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0art0","download_url":"https://codeload.github.com/0art0/lean3-statement-translation-tool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0art0%2Flean3-statement-translation-tool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33750475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codex","lean"],"created_at":"2026-05-31T22:02:13.721Z","updated_at":"2026-05-31T22:02:14.588Z","avatar_url":"https://github.com/0art0.png","language":"Lean","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lean3 Statement Translation tool\n\nA tool for automatic formalisation of natural language theorem statements to `Lean3` code using [OpenAI Codex](https://openai.com/blog/openai-codex/).\n\n---\n\nThis is a part of [`LeanAide`](https://github.com/siddhartha-gadgil/LeanAide), which contains an autoformalisation tool using `Lean4`, among other things. A similar (but unrelated) tool also using OpenAI Codex for theorem statement autoformalisation is [`Lean Chat`](https://github.com/zhangir-azerbayev/lean-chat).\n\n## Demonstration\n\n![leanaide_demo](https://user-images.githubusercontent.com/18333981/204189939-dcbf639c-eefe-4e6e-bcdf-2912d641926f.gif)\n\n## Details\n\nThe tool works best on short and self-contained theorem statements, similar to the theorem doc-strings in `mathlib`. The translation is done using *input-dependent prompting*: when the user supplies a statement to be translated, related doc-strings from `mathlib` are automatically picked up and supplied to the Codex model in the form of a \"prompt\".\n\nCodex outputs a few possible translations of the input statement, which are then checked for type-correctness. Lean is a dependently-typed language, so type-checking a translation provides a strong *filter* for correctness. Moreover, as Lean exposes its internals to the user, this part can be done programmatically and efficiently from within Lean. Note that for the filtering to work as intended, the relevant imports must already be present in the file.\n\nBy default, we request `7` completions from Codex and retrieve `15` sentences from `mathlib` for input-dependent prompting. These parameters, and a few more such as temperature, can be adjusted [here](https://github.com/0art0/lean3-statement-translation-tool/blob/abc272a5f40f51f3923fe91b81a04ce7ab9ac5bc/src/interface.lean#L21).\n\nIn [our experiments](https://mathai2022.github.io/papers/17.pdf), we found that Codex with these modifications is able to successfully translate short docstring-like statements at the undergraduate level more than half the time.\n\nIn addition to input-dependent prompting, declarations from the same file (theorems as well as definitions) that have doc-strings are added to the Codex prompt.\n\nThe source of the prompts can influence the style and content of the translation. Translations done with input-dependent prompting with doc-strings from `mathlib` often contain the notation and terminology of `mathlib`. Likewise, when nearby declarations in the file are added to the prompt, translations may make use of definitions that are in the file but not in `mathlib`.\n\n# Quickstart\n\nOur translation is based on Codex, to use which you need an OpenAI key. We also use a server for *sentence similarity*. To get started please configure environment variables using the following bash commands or equivalent in your shell:\n\n```bash\nexport LEANAIDE_IP=\"34.100.184.111:5000\"\nexport OPENAI_API_KEY=\u003cyour-open-ai-key\u003e\n```\n\nClone this repository and open `src/experiments.lean` in VS Code or any other editor for Lean3. \n\nTo translate a statement to Lean code, first type\n\n```lean\ntranslate? \"\u003cthe statement in natural language\u003e\"\n```\n\nin the editor. A number of options for translation should appear in the infoview, highlighted in blue. Clicking on any of the options triggers a call to Codex and temporarily modifies the text in the editor. After a few seconds, a number of suggested translations should appear on the right. Clicking on a translation pastes it into the editor, replacing the text above.\n\nTo add this as a dependency to your own repository, it should suffice to add\n\n```lean\nlean3_statement_translation_tool = {git = \"https://github.com/0art0/lean3-statement-translation-tool\", rev = \u003cthe latest revision of the repository on GitHub\u003e}\n```\n\nas a dependency to the `leanpkg.toml` file of your repository and build (with `leanproject build`). Then any file importing `interface.lean` should be able to run the translation tool as demonstrated above.\n\nThe above instructions should work for a normal use. Details for configuring a local set-up of the server are described in the [`README` of the `LeanAide` repository](https://github.com/siddhartha-gadgil/LeanAide/blob/main/README.md).\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0art0%2Flean3-statement-translation-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0art0%2Flean3-statement-translation-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0art0%2Flean3-statement-translation-tool/lists"}