lean-ja / lean-ja/lean-by-example
公理がどこで導入されたかまで出力する `#print axioms` コマンドの亜種
Open
Nobody has claimed this yet.
コード例
メモ
対話的コマンド
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
Zulip: > Hunting down axioms
import Lean
open Lean
structure State where
visited : NameSet := {}
axioms : Array (Name × Name) := #[]
abbrev M := ReaderT Environment $ StateM State
partial def collect (origin : Name) (c : Name) : M Unit := do
let collectExpr (origin : Name) (e : Expr) : M Unit := e.getUsedConstants.forM (collect origin)
let s ← get
unless s.visited.contains c do
modify fun s => { s with visited := s.visited.insert c }
let env ← read
match env.find? c with
| some (ConstantInfo.axiomInfo _) => modify fun s => { s with axioms := s.axioms.push (origin, c) }
| some (ConstantInfo.defnInfo v) => collectExpr c v.type *> collectExpr c v.value
| some (ConstantInfo.thmInfo v) => collectExpr c v.type *> collectExpr c v.value
| some (ConstantInfo.opaqueInfo v) => collectExpr c v.type *> collectExpr c v.value
| some (ConstantInfo.quotInfo _) => pure ()
| some (ConstantInfo.ctorInfo v) => collectExpr c v.type
| some (ConstantInfo.recInfo v) => collectExpr c v.type
| some (ConstantInfo.inductInfo v) => collectExpr c v.type *> v.ctors.forM (collect c)
| none => pure ()
def foo [Monad m] [MonadEnv m] (constName : Name) : m (Array (Name × Name)) := do
let env ← getEnv
let (_, s) := ((collect constName constName).run env).run {}
return s.axioms
def hack : Nat := sorry
def bar : Nat := hack
def foobar : Nat := bar + bar
#eval show MetaM _ from do foo ``foobar
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Zulip discussion and the Lean prototype in this issue, especially collect, foo, and the sample hack/bar/foobar declarations. Determine the appropriate command entry point and confirm that the finished variant reports each axiom together with the declaration through which it was introduced.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100