An open API service indexing awesome lists of open source software.

https://github.com/Paper-Proof/paperproof

Lean theorem proving interface which feels like pen-and-paper proofs.
https://github.com/Paper-Proof/paperproof

lean4 mathematics metaprogramming proof-tree

Last synced: 2 months ago
JSON representation

Lean theorem proving interface which feels like pen-and-paper proofs.

Awesome Lists containing this project

README

        

Paperproof


A new proof interface for Lean 4.


Paperproof vscode


Try Paperproof online







Paperproof will inspect how the hypotheses and goals were changing throughout the Lean 4 proof, and display this history - making it equivalent to how we think of a mathematical proof on paper.

---

In the following tables, you can see what tactics such as `apply`, `rw`, or `cases` look like in Paperproof; and how Paperproof renders real proofs from well-known repos.


Common tactics





Lean
Paperproof


**apply**




```lean
theorem apply (a b: ℝ) : a = b := by
apply le_antisymm
```



image

**have**


```lean
theorem have (a b: ℝ)
(h1: a ≤ b) (h2: b ≤ a) : True := by
have hi := le_antisymm h1 h2
```



image

**intro**



```lean
theorem intro
: ∀ (N: ℕ), ∃ M, N + N = M := by
intro n
```



image

**rw**



```lean
theorem rw (a b: ℕ)
(h1: a = b) : (10 * a = 666) := by
rw [h1]
```



image

**by_contra**



```lean
theorem by_contra (m: ℕ)
: 2 ≤ m := by
by_contra h
```



image

**use**



```lean
theorem use
: ∃ x: ℕ, x = 5 := by
use 42
```



image

**induction**



```lean
theorem induction (n: ℕ)
: Nat.mul 0 n = 0 := by
induction' n with k ih
```



image

**cases**



```lean
theorem casesN (n: ℕ)
: Nat.mul 0 n = 0 := by
cases' n with m
```



image




```lean
theorem casesAnd (A B C: Prop)
(h: A ∧ B) : C := by
cases' h with a b
```



image




```lean
theorem casesOr (A B C: Prop)
(h: A ∨ B) : C := by
cases' h with a b
```



image




```lean
inductive Random where
| hi: ℕ → String → Random
| hello: (2 + 2 = 4) → Random
| wow: Random
theorem casesRandom (C: Prop)
(h: Random) : C := by
cases' h with a b c
```



image



Full-fledged proofs





**Mathematics in Lean (Jeremy Avigad, Patrick Massot)**
([mathematics_in_lean/MIL/C05_Elementary_Number_Theory/solutions/Solutions_S03_Infinitely_Many_Primes.lean:155](https://github.com/leanprover-community/mathematics_in_lean/blob/4bc81ddea0a62c3bbd33cbfc4b4b501d2d0dfb03/MIL/C05_Elementary_Number_Theory/solutions/Solutions_S03_Infinitely_Many_Primes.lean#L155))





Mathematics in Lean - Paperproof


**Mathlib**
([mathlib4/Mathlib/Algebra/Field/Power.lean:30](https://github.com/leanprover-community/mathlib4/blob/9893bbd22fdca4005b93c8dbff16c1d2de21bc1a/Mathlib/Algebra/Field/Power.lean#L30))





Mathlib - Paperproof


**Hitchhiker's Guide to Logical Verification**
**(Anne Baanen, Alexander Bentkamp, Jasmin Blanchette, Johannes Hölzl, Jannis Limperg)**

([logical_verification_2023/blob/main/lean/LoVe/LoVe05_FunctionalProgramming_Demo.lean:316](https://github.com/blanchette/logical_verification_2023/blob/f709e20d2cd515d4ede3e7d2db30103d4f58aaca/lean/LoVe/LoVe05_FunctionalProgramming_Demo.lean#L316))





Hitchhiker's Guide to Logical Verification - Paperproof


## Installation

1. Install the "Paperproof" vscode extension ([link](https://marketplace.visualstudio.com/items?itemName=paperproof.paperproof)).

2. In your `lakefile.toml`, write:

```lean
[[require]]
name = "Paperproof"
git = "https://github.com/Paper-Proof/paperproof.git"
subDir = "lean"
rev = "main"
```

OR, if you use `lakefile.lean`, write:

```lean
-- if you are on a Lean version >= 4.12.0:
require Paperproof from git "https://github.com/Paper-Proof/paperproof.git"@"main"/"lean"
-- if you are on a Lean version <= 4.8.0:
require Paperproof from git "https://github.com/Paper-Proof/paperproof.git"@"21e4ec999c23fc6181d6528cbaecb600a2db6851"/"lean"
```

> Note: if you are on a Lean version in-between these two versions, one of these lines should work.

4. Then, in your terminal, run:

```shell
lake update Paperproof
```

> Note:
> if you're getting "error: unexpected arguments: Paperproof", it means you're on the older version of Lean, and it doesn't support per-package updates. In that case, just run `lake build`.

5. In a Lean file with your theorems, write:

```lean
import Paperproof
```

6. **You're done!**

Now, click on the paperproof icon (after you installed the Paperproof extension, it should appear in all `.lean` files), this will open a Paperproof panel within vscode.

You can click on any theorem now (well, only tactic-based proofs, those starting with `by`, are supported now) - you should see your proof tree rendered.

> [!TIP]
> If you get a build error when you try to build the paperproof package, please copypaste the error message and create the corresponding issue in Paperproof.
> Lean updates its metaprogramming api frequently - we try to go along with it, and it's helpful when incompatibilities are discovered on time.
> The quickfix for any Paperproof build error is to use the Lean version mentioned in [Paperproof's lean-toolchain](https://github.com/Paper-Proof/paperproof/blob/main/lean-toolchain).

## Tutorial

If you worked with formal proofs before, you might find Paperproof most similar to proof trees/Gentzen trees. The resemblance is not spurious, we can easily mimic Semantic Tableaux and Natural Deduction trees with Paperproof. All of these interfaces show "the history of a proof" - the way hypotheses and nodes were changing throughout the proof.

Unlike Gentzen, we can make use of css and javascript - so there are many visual syntax sugars on top of what would be a formal proof tree:

- hypotheses aren't repeated when used multiple times,
- goals and hypotheses are visually differentiated,
- variable scopes are shown as darkening backgrounds,
- available hypotheses are indicated via node transparencies,
- and so on.

Below, you will see a table with the main features of Paperproof.


Paperproof walkthrough






Lean
Paperproof



Hypotheses are displayed as green nodes,
goals are displayed as red nodes,
tactics are displayed as transparent nodes with dashed borders.




image


image



A proof should be read "towards the middle".

So, hypotheses should be read from top to bottom; and goals should be read bottom up.




image



image




To zoom in on a particular dark box, you can click on it.

Hint: these boxes represent variable scopes. Don't overthink this however, we'll always highlight the available hypotheses as you're writing the proof, consider these boxes a visual hint that will eventually become second nature.





Screenshot 2024-08-26 at 13 58 30



Nodes becomes transparent when they are not in scope.

So, an opaque red node represents a currently focused goal, and opaque green nodes represent currently available hypotheses.




image



image


## Updating

To update Paperproof, you only need to rerun `lake update Paperproof`. This will fetch the newest version of the Paperproof Lean library from this github repo, and build it.

Vscode extensions are automatically updated, however you can check for new updates with
**`cmd+shift+p` => "Extensions: Show Extension Updates"**.

Paperproof is a package that's usually only used during development, so you might want to remove it from your `lakefile.lean` when you're pushing to production. In order to do that, just remove the Paperproof require from `lakefile.lean`, and run `lake update Paperproof`. This will clean up `lake-manifest.json` and `lake-packages` for you.

## About Paperproof

**Theoretical:**

- Paperproof ♥️ Semantic Tableaux: [link](https://lakesare.brick.do/paperproof-love-semantic-tableaux-G6rR2BxL5Eyl)
- Paperproof ♥️ Natural Deduction: [link](https://lakesare.brick.do/paperproof-love-natural-deduction-3Mve6W8NgYRJ)
- Paperproof ⚔️ Lean's _#explode_: [link](https://paperproof.brick.do/paperproof-lean-s-explode-Bab05XYMp21q)
- Lean ⚔️ Coq ⚔️ Metamath ⚔️ Isabel proof trees: [link](https://lakesare.brick.do/lean-coq-isabel-and-their-proof-trees-yjnd2O2RgxwV)
- Paperproof's Architecture: [link](https://paperproof.brick.do/paperproof-s-architecture-P632P44ezDa9)

**Practical:**

- How to add my Lean repo to Github Codespaces: [link](https://lakesare.brick.do/how-to-add-my-lean-repo-to-github-codespaces-A13P6g7aYwgg)
- Can Paperproof render proof terms: [link](https://paperproof.brick.do/can-paperproof-render-proof-terms-qm1NZZkazb21)
- How to parse the _InfoTree_: [link](https://antonkov.github.io/posts/How-to-build-a-proof-tree)

**Videos:**

- a super quick 1-minute demo of Paperproof: [youtube link](https://youtu.be/xiIQ0toSpxQ)
- our Lean Together presentation: [youtube link](https://www.youtube.com/watch?v=DWuAGt2RDaM)
- a full Paperproof tutorial: [youtube link](https://youtu.be/q9w1djIcCvc)

## Development

You're welcome to contribute to Paperproof, see the instructions in [CONTRIBUTING.md](https://github.com/Paper-Proof/paperproof/blob/main/CONTRIBUTING.md).