Zulip Chat Archive
Stream: general
Topic: get target or hyp type
Johan Commelin (Apr 20 2020 at 09:52):
Is there something like this already? Or am I approaching things wrong?
meta def target_or_hyp_type : option expr → tactic expr | none := target | (some h) := infer_type h
Mario Carneiro (Apr 20 2020 at 09:57):
that seems fine to me, but it also looks specific to your use case
Mario Carneiro (Apr 20 2020 at 09:58):
if you want something more general, I would suggest something taking a loc
as input
Johan Commelin (Apr 20 2020 at 10:00):
Does something like that already exist?
Johan Commelin (Apr 20 2020 at 10:01):
Similarly something like this...??
meta def replace' : option expr → expr → expr → tactic unit | none := tactic.replace_target | (some h) := λ e p, tactic.replace_hyp h e p >> skip
Johan Commelin (Apr 20 2020 at 10:01):
Or should that also be done with loc
?
Mario Carneiro (Apr 20 2020 at 10:02):
I think you are asking the wrong question. What is this for? Usually the goal and the hypotheses have to be treated differently, since in one you can reason forward and the other you reason backward
Johan Commelin (Apr 20 2020 at 10:03):
Except for rw
, I think
Mario Carneiro (Apr 20 2020 at 10:04):
There is a function, loc.apply
, where you give it a tactic to operate on hypotheses and another to operate on the goal, and it will do what it needs to on any loc
, using any combination of h
, |-
and *
Johan Commelin (Apr 20 2020 at 10:04):
Yep, I'm already using that one
Mario Carneiro (Apr 20 2020 at 10:05):
as such, there is no option expr
involved
Mario Carneiro (Apr 20 2020 at 10:05):
just two separate functions
Johan Commelin (Apr 20 2020 at 10:07):
But that leads to lots of duplication, I think
Johan Commelin (Apr 20 2020 at 10:07):
See the nth-rewrite
branch
Mario Carneiro (Apr 20 2020 at 10:07):
it's not really duplication, it only looks like it
Mario Carneiro (Apr 20 2020 at 10:08):
the actual tactics you have to use and the order stuff flows around is different
Mario Carneiro (Apr 20 2020 at 10:09):
once you get to something rewrite-like, it does turn into just one tactic, with the form expr -> tactic (expr x expr)
Mario Carneiro (Apr 20 2020 at 10:12):
looking at your branch, I think you should indeed factor everything through a conversion and applying a conversion
Johan Commelin (Apr 20 2020 at 10:12):
What is a conversion?
Mario Carneiro (Apr 20 2020 at 10:13):
expr -> tactic (expr x expr)
, given input e
produces e'
and a proof of p : e = e'
Mario Carneiro (Apr 20 2020 at 10:13):
you can cleanly express descending into subterms with this type
Mario Carneiro (Apr 20 2020 at 10:14):
and given such a conversion you can apply it to the target as one tactic, or apply it to a hypothesis
Johan Commelin (Apr 20 2020 at 10:17):
Are such conversions already used in mathlib? Are there supporting functions?
Johan Commelin (Apr 20 2020 at 10:17):
Or should I roll my own?
Mario Carneiro (Apr 20 2020 at 10:17):
there are a couple, I use it a lot in ring
Mario Carneiro (Apr 20 2020 at 10:18):
but mostly it's just a pattern that doesn't require much support
Johan Commelin (Apr 20 2020 at 10:18):
Ok, but it hasn't been factored out in some sort of reusable package?
Johan Commelin (Apr 20 2020 at 10:18):
Ok... fine
Mario Carneiro (Apr 20 2020 at 10:20):
see for instance simp_target
and simp_hyp
that rely on tactic.simplify
which is basically a conversion like I described (although it takes some extra arguments)
Mario Carneiro (Apr 20 2020 at 10:21):
they just get the result from the conversion and pass to replace_target
and replace_hyp
respectively
Mario Carneiro (Apr 20 2020 at 10:22):
so I think these functions are the reusable package
Mario Carneiro (Apr 20 2020 at 10:23):
In the tactic.norm_num
file there are some orphaned conversion operations refl_conv
and trans_conv
that could go in tactic.core
Johan Commelin (Apr 20 2020 at 14:28):
@Mario Carneiro I have no idea whether I did things right, but I think I've deduplicated the code quite far. See #2471
Last updated: Dec 20 2023 at 11:08 UTC