-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The compiler interaction and source highlighting features of Verso are now extracted to a library that can be used with many different Lean versions. It provides tools for writing Lean projects that use multiple toolchains and including examples from them in the same text. This provides an alternative to inline code blocks for more complicated cases.
- Loading branch information
1 parent
34a9097
commit 8ae46f3
Showing
24 changed files
with
366 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.lake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Examples.Basic | ||
|
||
import SubVerso.Examples | ||
open SubVerso.Examples | ||
|
||
%example basic | ||
def t : Tree Nat := .branch (.branch .leaf 1 .leaf) 2 (.branch (.branch .leaf 3 .leaf) 4 .leaf) | ||
|
||
example := t.flip | ||
|
||
#eval t.flip | ||
|
||
#check Tree.flip | ||
%end | ||
|
||
%example proof | ||
theorem Tree.flip_flip_id (t : Tree α) : t.flip.flip = t := by | ||
induction t with | ||
| leaf => rfl | ||
| branch l v r ih1 ih2 => | ||
simp only [flip] | ||
rw [ih1] | ||
rw [ih2] | ||
%end | ||
|
||
%example oldterm | ||
-- The old syntax: | ||
def foo (n k : Nat) : Nat := | ||
if n < k then | ||
1 + foo (n + 1) k | ||
else 0 | ||
termination_by foo n k => k - n | ||
%end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import SubVerso.Examples | ||
open SubVerso.Examples | ||
|
||
%example Tree | ||
inductive Tree (α : Type u) : Type u where | ||
| leaf | ||
| branch (left : Tree α) (val : α) (right : Tree α) | ||
%end | ||
|
||
%example Tree.flip | ||
def Tree.flip : Tree α → Tree α | ||
| .leaf => .leaf | ||
| .branch l v r => %ex{flopped}{.branch r.flip v l.flip} | ||
%end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{"version": 7, | ||
"packagesDir": ".lake/packages", | ||
"packages": | ||
[{"url": "https://github.com/leanprover/subverso.git", | ||
"type": "git", | ||
"subDir": null, | ||
"rev": "8c578ebd38645c9ac0d64ce6a6958b7975cf8ca6", | ||
"name": "subverso", | ||
"manifestFile": "lake-manifest.json", | ||
"inputRev": "main", | ||
"inherited": false, | ||
"configFile": "lakefile.lean"}], | ||
"name": "examples", | ||
"lakeDir": ".lake"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Lake | ||
open Lake DSL | ||
|
||
require subverso from git "https://github.com/leanprover/subverso.git"@"main" | ||
|
||
package «examples» where | ||
-- add package configuration options here | ||
|
||
@[default_target] | ||
lean_lib «Examples» where | ||
-- add library configuration options here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
leanprover/lean4:v4.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Verso.Genre.Blog | ||
import DemoSite.Categories | ||
open Verso Genre Blog | ||
open DemoSite | ||
|
||
set_option pp.rawOnError true | ||
|
||
#doc (Post) "Examples from Subprojects" => | ||
|
||
%%% | ||
authors := ["Fictional Author", "Another Fictional Author"] | ||
date := {year := 2024, month := 3, day := 5} | ||
categories := [examples, other] | ||
%%% | ||
|
||
This post demonstrates mixing highlighted examples from multiple Lean versions. | ||
|
||
{leanExampleProject examples "examples/website-examples"} | ||
|
||
# Foo | ||
|
||
Here's a tree: | ||
|
||
{leanCommand examples Examples.Basic.Tree} | ||
|
||
They can be flipped around: | ||
|
||
{leanCommand examples Examples.Basic.Tree.flip} | ||
|
||
And subterms can be included: {leanTerm examples}`Examples.Basic.Tree.flip.flopped`. | ||
|
||
We can even prove things about them: | ||
|
||
{leanCommand examples Examples.proof} | ||
|
||
And use old syntax: | ||
|
||
{leanCommand examples Examples.oldterm} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
{"version": 7, | ||
"packagesDir": ".lake/packages", | ||
"packages": [], | ||
"packages": | ||
[{"url": "https://github.com/leanprover/subverso.git", | ||
"type": "git", | ||
"subDir": null, | ||
"rev": "8c578ebd38645c9ac0d64ce6a6958b7975cf8ca6", | ||
"name": "subverso", | ||
"manifestFile": "lake-manifest.json", | ||
"inputRev": "main", | ||
"inherited": false, | ||
"configFile": "lakefile.lean"}], | ||
"name": "verso", | ||
"lakeDir": ".lake"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
leanprover/lean4:nightly-2024-02-26 | ||
leanprover/lean4:v4.7.0-rc1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.