Add documentation; Remove mathlib dependency
This commit is contained in:
parent
572548c1bd
commit
a00a2b4a42
|
@ -110,7 +110,10 @@ def execute (command: Command): Subroutine Lean.Json := do
|
|||
| .ok expr => do
|
||||
try
|
||||
let format ← Lean.Meta.ppExpr (← Lean.Meta.inferType expr)
|
||||
return Lean.toJson <| ({ type := toString format }: ExprTypeResult)
|
||||
return Lean.toJson <| ({
|
||||
type := toString format,
|
||||
roundTrip := toString <| (← Lean.Meta.ppExpr expr)
|
||||
}: ExprTypeResult)
|
||||
catch exception =>
|
||||
return errorI "typing" (← exception.toMessageData.toString)
|
||||
proof_start (args: ProofStart): Subroutine Lean.Json := do
|
||||
|
|
|
@ -52,6 +52,7 @@ structure ExprType where
|
|||
deriving Lean.FromJson
|
||||
structure ExprTypeResult where
|
||||
type: String
|
||||
roundTrip: String
|
||||
deriving Lean.ToJson
|
||||
|
||||
structure ProofStart where
|
||||
|
|
|
@ -20,7 +20,7 @@ def syntax_from_str (env: Environment) (s: String): Except String Syntax :=
|
|||
(fileName := "<stdin>")
|
||||
|
||||
|
||||
def syntax_to_expr (syn: Syntax): Elab.TermElabM (Except String Expr) := do
|
||||
def syntax_to_expr_type (syn: Syntax): Elab.TermElabM (Except String Expr) := do
|
||||
try
|
||||
let expr ← Elab.Term.elabType syn
|
||||
-- Immediately synthesise all metavariables if we need to leave the elaboration context.
|
||||
|
@ -29,6 +29,15 @@ def syntax_to_expr (syn: Syntax): Elab.TermElabM (Except String Expr) := do
|
|||
let expr ← instantiateMVars expr
|
||||
return .ok expr
|
||||
catch ex => return .error (← ex.toMessageData.toString)
|
||||
def syntax_to_expr (syn: Syntax): Elab.TermElabM (Except String Expr) := do
|
||||
try
|
||||
let expr ← Elab.Term.elabTerm (stx := syn) (expectedType? := .none)
|
||||
-- Immediately synthesise all metavariables if we need to leave the elaboration context.
|
||||
-- See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Unknown.20universe.20metavariable/near/360130070
|
||||
--Elab.Term.synthesizeSyntheticMVarsNoPostponing
|
||||
let expr ← instantiateMVars expr
|
||||
return .ok expr
|
||||
catch ex => return .error (← ex.toMessageData.toString)
|
||||
|
||||
structure BoundExpression where
|
||||
binders: Array (String × String)
|
||||
|
|
28
README.md
28
README.md
|
@ -2,20 +2,23 @@
|
|||
|
||||
An interaction system for Lean 4.
|
||||
|
||||
![Pantograph](doc/icon.svg)
|
||||
|
||||
## Installation
|
||||
|
||||
Install `elan` and `lean4`. Then, execute
|
||||
``` sh
|
||||
lake build
|
||||
```
|
||||
In order to use `mathlib`, its binary must also be built
|
||||
Then, setup the `LEAN_PATH` environment variable so it contains the library path of lean libraries. The libraries must be built in advance. For example, if `mathlib4` is stored at `../lib/mathlib4`,
|
||||
``` sh
|
||||
lake build Qq
|
||||
lake build aesop
|
||||
lake build std
|
||||
lake build mathlib
|
||||
LIB="../lib"
|
||||
LIB_MATHLIB="$LIB/mathlib4/lake-packages"
|
||||
export LEAN_PATH="$LIB/mathlib4/build/lib:$LIB_MATHLIB/aesop/build/lib:$LIB_MATHLIB/Qq/build/lib:$LIB_MATHLIB/std/build/lib"
|
||||
|
||||
LEAN_PATH=$LEAN_PATH build/bin/pantograph $@
|
||||
```
|
||||
In a future version, the dependencies of mathlib will be removed and the user will be responsible for adding such library paths to `LEAN_PATH`.
|
||||
Note that `lean-toolchain` must be present in the `$PWD` in order to run Pantograph! This is because Pantograph taps into Lean's internals.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -42,7 +45,7 @@ $ build/bin/Pantograph Init
|
|||
catalog
|
||||
inspect {"name": "Nat.le_add_left"}
|
||||
```
|
||||
Example with `mathlib` (~90k symbols)
|
||||
Example with `mathlib4` (~90k symbols, may stack overflow, see troubleshooting)
|
||||
```
|
||||
$ lake env build/bin/Pantograph Mathlib.Analysis.Seminorm
|
||||
catalog
|
||||
|
@ -59,6 +62,17 @@ proof.printTree {"treeId": 0}
|
|||
```
|
||||
where the application of `assumption` should lead to a failure.
|
||||
|
||||
## Commands
|
||||
|
||||
See `Pantograph/Commands.lean` for a description of the parameters and return values in Json.
|
||||
- `catalog`: Display a list of all safe Lean symbols in the current context
|
||||
- `inspect {"name": <name>}`: Show the type and package of a given symbol
|
||||
- `clear`: Delete all cached expressions and proof trees
|
||||
- `expr.type {"expr": <expr>}`: Determine the type of an expression and round-trip it
|
||||
- `proof.start {["name": <name>], ["expr": <expr>], ["copyFrom": <symbol>]}`: Start a new proof state from a given expression or symbol
|
||||
- `proof.tactic {"treeId": <id>, "stateId": <id>, "goalId": <id>, "tactic": string}`: Execute a tactic on a given proof state
|
||||
- `proof.printTree {"treeId": <id>}`: Print the topological structure of a proof tree
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If lean encounters stack overflow problems when printing catalog, execute this before running lean:
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="256"
|
||||
height="256"
|
||||
viewBox="0 0 55.900957 55.900957"
|
||||
version="1.1"
|
||||
id="svg21534"
|
||||
xml:space="preserve"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="icon.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview21536"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#111111"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="1"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="px"
|
||||
showgrid="true"
|
||||
inkscape:zoom="5.1754899"
|
||||
inkscape:cx="158.82554"
|
||||
inkscape:cy="91.682142"
|
||||
inkscape:window-width="3777"
|
||||
inkscape:window-height="2093"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1"><inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid23833"
|
||||
spacingx="3.4938098"
|
||||
spacingy="3.4938098"
|
||||
empspacing="4" /></sodipodi:namedview><defs
|
||||
id="defs21531" /><g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"><rect
|
||||
style="fill:#3e3e3e;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.78013;stroke-miterlimit:3.4;stroke-dasharray:none"
|
||||
id="rect26805"
|
||||
width="11.502316"
|
||||
height="2.2512667"
|
||||
x="33.344425"
|
||||
y="7.6690259"
|
||||
ry="0.28140834"
|
||||
rx="0.47926313" /><path
|
||||
style="fill:#3e3e3e;stroke:none;stroke-width:0.218363px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="m 35.764667,9.9513013 c 0,0 -26.8581417,13.7987337 -28.0863506,14.9501437 -1.250042,1.171878 3.2347846,3.945325 3.2347846,3.945325 l 21.34979,14.934062 6.624567,0.453105 -27.599216,-17.304358 c 0,0 -0.603209,-0.08927 -0.600411,-0.762283 0.0028,-0.673015 27.32022,-16.4227356 27.32022,-16.4227356 z"
|
||||
id="path27381"
|
||||
sodipodi:nodetypes="csccccscc" /><path
|
||||
style="fill:#3e3e3e;stroke:none;stroke-width:0.218363px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="M 10.97848,26.985751 40.537772,9.7943227 41.921795,9.7005084 11.210626,27.421377 Z"
|
||||
id="path27479" /><path
|
||||
style="fill:#3e3e3e;stroke:none;stroke-width:0.218363px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="m 7.0509847,25.522367 c -0.8266141,1.386819 -2.4011783,4.48805 -2.4706357,4.90223 -0.069458,0.414182 0.4434324,0.513474 0.8491061,0.757041 C 5.835129,31.425204 19.33424,43.917182 19.33424,43.917182 l 0.324562,-0.539228 c 0,0 -14.2055729,-12.369493 -14.0644435,-12.868167 0.1411292,-0.498672 3.544896,-3.777392 3.544896,-3.777392 L 7.4596884,25.117508 Z"
|
||||
id="path27481" /><rect
|
||||
style="fill:#3e3e3e;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.11692;stroke-miterlimit:3.4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect27483"
|
||||
width="36.38942"
|
||||
height="3.6217353"
|
||||
x="13.953447"
|
||||
y="43.009739"
|
||||
rx="0.43672624"
|
||||
ry="0.43672624" /><path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.218363px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M -2.1119274,7.666599 H 64.179192"
|
||||
id="path27487" /></g></svg>
|
After Width: | Height: | Size: 3.5 KiB |
|
@ -3,11 +3,7 @@ open Lake DSL
|
|||
|
||||
package pantograph
|
||||
|
||||
require mathlib from git
|
||||
"https://github.com/leanprover-community/mathlib4.git" @ "8e5a00a8afc8913c0584cb85f37951995275fd87"
|
||||
|
||||
lean_lib Pantograph {
|
||||
-- add library configuration options here
|
||||
}
|
||||
|
||||
@[default_target]
|
||||
|
@ -20,11 +16,9 @@ lean_exe pantograph {
|
|||
require LSpec from git
|
||||
"https://github.com/lurk-lab/LSpec.git" @ "88f7d23e56a061d32c7173cea5befa4b2c248b41"
|
||||
lean_lib Test {
|
||||
-- add library configuration options here
|
||||
}
|
||||
lean_exe test {
|
||||
root := `Test.Main
|
||||
-- Somehow solves the native symbol not found problem
|
||||
supportInterpreter := true
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue