New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tactic): add various tactics about local definitions #1953
Conversation
fb26435
to
e7df2cb
Compare
@cipher1024: What does the following tactic do? mathlib/src/tactic/monotonicity/interactive.lean Lines 406 to 408 in 253f75c
The docstring is a sentence fragment. Can I rename it to monotonicity.generalize' ?
Also, many of the declarations in that file are not interactive tactics at all... |
|
||
/-- `local_def_value e` returns the value of the expression `e`, assuming that `e` has been defined | ||
locally using a `let` expression. Otherwise it fails. -/ | ||
meta def local_def_value (e : expr) : tactic expr := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this and the following be better implemented in C++? IIRC local definitions are stored in the type context, right? @EdAyers exposed some of the type context to the tactic monad in 3.5c. Rather than this kind of hackish way to get the local def value, maybe there should be a function to query the type context directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would almost certainly be better to implement this in C++.
I don't know how to do that, though.
Shall merge this PR and change it until we've exposed it from the C++ side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already implemented:
tactic.unsafe.type_context.run $ do
lctx <- get_local_context,
some ldecl <- pure (lctx.get_local_decl e.local_uniq_name),
some let_val <- pure ldecl.value,
pure let_val
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Do you know if it possible to run tactic.pp
inside the type_context
monad (for error message handling)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find anything, and I don't think there is a way to run tactics from the type context monad.
|
||
/-- `local_def_value e` returns the value of the expression `e`, assuming that `e` has been defined | ||
locally using a `let` expression. Otherwise it fails. -/ | ||
meta def local_def_value (e : expr) : tactic expr := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already implemented:
tactic.unsafe.type_context.run $ do
lctx <- get_local_context,
some ldecl <- pure (lctx.get_local_decl e.local_uniq_name),
some let_val <- pure ldecl.value,
pure let_val
I don't think we need to change |
5236932
to
46d6854
Compare
I updated |
|
||
/-- `local_def_value e` returns the value of the expression `e`, assuming that `e` has been defined | ||
locally using a `let` expression. Otherwise it fails. -/ | ||
meta def local_def_value (e : expr) : tactic expr := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find anything, and I don't think there is a way to run tactics from the type context monad.
`generalize'` is similar to `generalize`. The difference is that `generalize' : e = x` also succeeds when `e` | ||
does not occur in the goal. It is similar to `set`, but the resulting hypothesis `x` is not a local definition. | ||
-/ | ||
meta def generalize' (h : parse ident?) (_ : parse $ tk ":") (p : parse generalize_arg_p) : tactic unit := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably go into Lean 3.6.
…-community#1953) * feat(tactic): add various tactics about local definitions * remove {α β} * rename generalize' in monotonicity. * updates after reviews Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…-community#1953) * feat(tactic): add various tactics about local definitions * remove {α β} * rename generalize' in monotonicity. * updates after reviews Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
TO CONTRIBUTORS:
Make sure you have:
If this PR is related to a discussion on Zulip, please include a link in the discussion.
For reviewers: code review check list