Hub documentation

形式化证明(Lean 4)

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

形式化证明(Lean 4)

Hub 原生支持在所有仓库中渲染 Lean 4(.lean)文件,并提供语句视图、大纲侧边栏以及 Lean 4 语法高亮功能。

A Lean 4 file on the Hub in Statements view (light mode), showing KaTeX-rendered docstrings, highlighted theorem signatures, folded proof toggles, and the Outline sidebar.

语句视图

在文件和版本或存储桶中打开.lean文件时,默认显示其语句视图,因此您可以在无需滚动浏览冗长证明的情况下,查看文件所定义和证明的内容:

  • KaTeX 文档字符串: /-- ... -/ 文档字符串支持渲染行内($...$)和独立($$...$$)数学公式、代码以及链接。
  • 可折叠的证明与主体:证明(theorem、lemma、example)和定义(def、abbrev、structure、inductive、……)默认折叠在切换控件之后。
  • 未完成的证明:sorry、admit 和 #exit 会以红色高亮显示,以便立即突出显示缺口。

点击任意 证明 或 正文 切换按钮以在行内展开:

Expanded proofs inside Statements view (light mode), showing sorry highlighted in red and a 17-line Lean 4 proof expanded inline.

在公开文件上试一试:

大纲

在桌面端,固定的大纲侧边栏会列出所有声明及其类型和行号。点击任意条目即可直接跳转至该位置(#L<line>),或点击声明的行号以获取可分享的链接。

完整视图

点击右上角切换器中的 Full——或在 URL 末尾添加 ?code=true——即可查看带有 Lean 4 语法高亮、行号和 Outline 侧边栏的完整文件。从 Full 视图复制的行链接会保留 ?code=true(例如,1.lean?code=true#L54)。

A Lean 4 file on the Hub in Full view (light mode), showing Lean 4 syntax highlighting, red sorry highlighting, line numbers, and the Outline sidebar.

Markdown 代码块

Lean 4 语法高亮在 Model Cards、Dataset Cards、Space Cards、Discussions 和 Pull Requests 中同样有效,使用 lean 或 lean4 代码围栏即可:

```lean
/-- Every natural number plus zero is itself. -/
theorem add_zero_example (n : ℕ) : n + 0 = n := by
  exact Nat.add_zero n
```
Update on GitHub