doc: Update all examples to 0.2.23

This commit is contained in:
Leni Aniva 2024-12-11 17:14:44 -08:00
parent 4c559294d3
commit 04e40b6dfa
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
4 changed files with 46 additions and 52 deletions

View File

@ -53,7 +53,7 @@
"project_path = Path(os.getcwd()).parent.resolve() / 'examples/Example'\n", "project_path = Path(os.getcwd()).parent.resolve() / 'examples/Example'\n",
"print(f\"$PWD: {project_path}\")\n", "print(f\"$PWD: {project_path}\")\n",
"server = Server(imports=['Example'], project_path=project_path)\n", "server = Server(imports=['Example'], project_path=project_path)\n",
"units, invocations = server.tactic_invocations(project_path / \"Example.lean\")" "units = server.tactic_invocations(project_path / \"Example.lean\")"
] ]
}, },
{ {
@ -61,7 +61,7 @@
"id": "c3c1be91-27a5-4481-b09d-a32dbb94b058", "id": "c3c1be91-27a5-4481-b09d-a32dbb94b058",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The function returns a tuple `([str], [TacticInvocation])`. The former element is a list of strings containing each compilation unit, comment data included." "The function returns a list of `CompilationUnit` objects, corresponding to each compilation unit in the input Lean file. For performance reasons only the text boundaries are loaded into `CompilationUnit`s."
] ]
}, },
{ {
@ -74,13 +74,13 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"==== #0 ====\n", "#0: [14,85]\n",
"/-- Ensure that Aesop is running -/\n", "/-- Ensure that Aesop is running -/\n",
"example : αα :=\n", "example : αα :=\n",
" by aesop\n", " by aesop\n",
"\n", "\n",
"\n", "\n",
"==== #1 ====\n", "#1: [85,254]\n",
"example : ∀ (p q: Prop), p q → q p := by\n", "example : ∀ (p q: Prop), p q → q p := by\n",
" intro p q h\n", " intro p q h\n",
" -- Here are some comments\n", " -- Here are some comments\n",
@ -94,9 +94,12 @@
} }
], ],
"source": [ "source": [
"for i, u in enumerate(units):\n", "with open(project_path / \"Example.lean\", 'rb') as f:\n",
" print(f\"==== #{i} ====\")\n", " content = f.read()\n",
" print(u)" " for i, unit in enumerate(units):\n",
" print(f\"#{i}: [{unit.i_begin},{unit.i_end}]\")\n",
" unit_text = content[unit.i_begin:unit.i_end].decode('utf-8')\n",
" print(unit_text)"
] ]
}, },
{ {
@ -104,7 +107,7 @@
"id": "52e650fc-4a87-445f-8aa8-707ed9e36c03", "id": "52e650fc-4a87-445f-8aa8-707ed9e36c03",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The latter is a list of `TacticInvocation`, which contains the `.before` (corresponding to the state before the tactic), `.after` (corresponding to the state after the tactic), and `.tactic` (tactic executed) fields. " "Each `CompilationUnit` includes a list of `TacticInvocation`s, which contains the `.before` (corresponding to the state before the tactic), `.after` (corresponding to the state after the tactic), and `.tactic` (tactic executed) fields. "
] ]
}, },
{ {
@ -122,13 +125,33 @@
"⊢ αα\n", "⊢ αα\n",
"[Tactic]\n", "[Tactic]\n",
"aesop (using [])\n", "aesop (using [])\n",
"[Afte]\n", "[After]\n",
"\n", "\n"
]
}
],
"source": [
"for i in units[0].invocations:\n",
" print(f\"[Before]\\n{i.before}\")\n",
" print(f\"[Tactic]\\n{i.tactic} (using {i.used_constants})\")\n",
" print(f\"[After]\\n{i.after}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "51f5398b-5416-4dc1-81cd-6d2514758232",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Before]\n", "[Before]\n",
"⊢ ∀ (p q : Prop), p q → q p\n", "⊢ ∀ (p q : Prop), p q → q p\n",
"[Tactic]\n", "[Tactic]\n",
"intro p q h (using [])\n", "intro p q h (using [])\n",
"[Afte]\n", "[After]\n",
"p q : Prop\n", "p q : Prop\n",
"h : p q\n", "h : p q\n",
"⊢ q p\n", "⊢ q p\n",
@ -138,7 +161,7 @@
"⊢ q p\n", "⊢ q p\n",
"[Tactic]\n", "[Tactic]\n",
"cases h (using ['Eq.refl', 'Or'])\n", "cases h (using ['Eq.refl', 'Or'])\n",
"[Afte]\n", "[After]\n",
"case inl\n", "case inl\n",
"p q : Prop\n", "p q : Prop\n",
"h✝ : p\n", "h✝ : p\n",
@ -151,7 +174,7 @@
"⊢ q p\n", "⊢ q p\n",
"[Tactic]\n", "[Tactic]\n",
"apply Or.inr (using ['Or.inr'])\n", "apply Or.inr (using ['Or.inr'])\n",
"[Afte]\n", "[After]\n",
"case inl.h\n", "case inl.h\n",
"p q : Prop\n", "p q : Prop\n",
"h✝ : p\n", "h✝ : p\n",
@ -163,7 +186,7 @@
"⊢ p\n", "⊢ p\n",
"[Tactic]\n", "[Tactic]\n",
"assumption (using [])\n", "assumption (using [])\n",
"[Afte]\n", "[After]\n",
"\n", "\n",
"[Before]\n", "[Before]\n",
"case inr\n", "case inr\n",
@ -172,7 +195,7 @@
"⊢ q p\n", "⊢ q p\n",
"[Tactic]\n", "[Tactic]\n",
"apply Or.inl (using ['Or.inl'])\n", "apply Or.inl (using ['Or.inl'])\n",
"[Afte]\n", "[After]\n",
"case inr.h\n", "case inr.h\n",
"p q : Prop\n", "p q : Prop\n",
"h✝ : q\n", "h✝ : q\n",
@ -184,25 +207,17 @@
"⊢ q\n", "⊢ q\n",
"[Tactic]\n", "[Tactic]\n",
"assumption (using [])\n", "assumption (using [])\n",
"[Afte]\n", "[After]\n",
"\n" "\n"
] ]
} }
], ],
"source": [ "source": [
"for i in invocations:\n", "for i in units[1].invocations:\n",
" print(f\"[Before]\\n{i.before}\")\n", " print(f\"[Before]\\n{i.before}\")\n",
" print(f\"[Tactic]\\n{i.tactic} (using {i.used_constants})\")\n", " print(f\"[Tactic]\\n{i.tactic} (using {i.used_constants})\")\n",
" print(f\"[Afte]\\n{i.after}\")" " print(f\"[After]\\n{i.after}\")"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51f5398b-5416-4dc1-81cd-6d2514758232",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -221,7 +236,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.12.6" "version": "3.12.7"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -1,23 +0,0 @@
#!/usr/bin/env python3
import subprocess
from pathlib import Path
from pantograph.server import Server
def get_project_and_lean_path():
cwd = Path(__file__).parent.resolve() / 'Example'
p = subprocess.check_output(['lake', 'env', 'printenv', 'LEAN_PATH'], cwd=cwd)
return cwd, p
if __name__ == '__main__':
project_path, lean_path = get_project_and_lean_path()
print(f"$PWD: {project_path}")
print(f"$LEAN_PATH: {lean_path}")
server = Server(imports=['Example'], project_path=project_path, lean_path=lean_path)
units, invocations = server.tactic_invocations(project_path / "Example.lean")
for i, u in enumerate(units):
print(f"==== #{i} ====")
print(u)
print("==== Invocations ====")
for i in invocations:
print(f"{i.before}\n{i.tactic}\n{i.after}\n")

View File

@ -32,5 +32,5 @@ theorem add_comm_proved_formal_sketch : ∀ n m : Nat, n + m = m + n := by
if __name__ == '__main__': if __name__ == '__main__':
server = Server() server = Server()
state0, = server.load_sorry(sketch) unit, = server.load_sorry(sketch)
print(state0) print(unit.goal_state)

View File

@ -25,8 +25,10 @@ class TacticInvocation:
@dataclass(frozen=True) @dataclass(frozen=True)
class CompilationUnit: class CompilationUnit:
# Byte boundaries [begin, end[ of each compilation unit.
i_begin: int i_begin: int
i_end: int i_end: int
messages: list[str] = field(default_factory=list) messages: list[str] = field(default_factory=list)
invocations: Optional[list[TacticInvocation]] = None invocations: Optional[list[TacticInvocation]] = None