Zulip Chat Archive

Stream: lean4

Topic: Manipulating custom tactic state


Leni Aniva (May 10 2023 at 06:13):

Hi people, I am trying to create a machine interactable theorem proving environment. Ideally I want an interface where I can create a tactic state with a goal and execute tactics on it with backtracking enabled. I read in Lean/Elab/Tactic/Basic.lean that there are these two types and this function

abbrev TacticM := ReaderT Context $ StateRefT State TermElabM
abbrev Tactic  := Syntax → TacticM Unit
...
def run (mvarId : MVarId) (x : TacticM Unit) : TermElabM (List MVarId)

It seems like I can feed a tactic and a metavar into run and the tactic would manipulate the proof state. What I don't understand from this code is where can I provide the context? I have Environment objects and I would like to use them as the context.

Scott Morrison (May 10 2023 at 06:16):

TermElabM is itself a monad, responsible for maintaining that context.

Mario Carneiro (May 10 2023 at 06:16):

most of the context like the environment is hidden in the monad state of TermElabM here

Scott Morrison (May 10 2023 at 06:16):

It's a bit hard to tell what you want to do: it sounds like Lean itself is the solution to the problem you've specified. :-)

Leni Aniva (May 10 2023 at 06:17):

Scott Morrison said:

It's a bit hard to tell what you want to do: it sounds like Lean itself is the solution to the problem you've specified. :-)

I'm building a text based interface to run tactics on custom examples. Both the examples (theorem to be proven) and tactics will be fed in by text

Leni Aniva (May 10 2023 at 06:18):

Mario Carneiro said:

most of the context like the environment is hidden in the monad state of TermElabM here

What is StateRefT?

Mario Carneiro (May 10 2023 at 06:18):

You should think of it as StateT, that is, it has a state value that is modified and passed out

Mario Carneiro (May 10 2023 at 06:19):

in lean State = read-write data

Mario Carneiro (May 10 2023 at 06:19):

and Context / Reader = read-only data

Leni Aniva (May 10 2023 at 06:19):

How is StateRefT different from StateT and State?

Mario Carneiro (May 10 2023 at 06:20):

StateRefT implements the API of StateT but it uses mutable references behind the scenes to do it

Leni Aniva (May 10 2023 at 06:22):

Thanks! That answers all of my questions


Last updated: Dec 20 2023 at 11:08 UTC