Hi all, maybe it's a silly question but is there a way to use hints defined with Hint Extern
to progress even if it does not conclude the goal?
I use them to do some typeclass inference and in case it does find an instance eauto with typeclass_instances
seems to behave mostly has exact _
. But in some cases, it will not find an instance, but I would still like to apply the hints and get the sub-goal it failed to solve as a sub-goal.
Is there already a tactic that does this? eauto with typeclass_instances
or even eauto with mydb
don't seem to apply the hint if it doesn't solve the goal.
Thanks.
You can use || shelve
I guess to get the subgoal
(using typeclasses eauto
)
This PR https://github.com/coq/coq/pull/13952 should also help in the future
You mean this?
unshelve (typeclasses eauto || shelve).
For me it still doesn't do anything.
Matthieu Sozeau said:
This PR https://github.com/coq/coq/pull/13952 should also help in the future
Sounds interesting, but this only for error reporting (which is great).
I would like to actually get the subgoal and then solve it interactively.
I guess my question is: when does eauto
apply hints even if they do not conclude the goal?
There is a new best_effort
option that could give you subgoals
Can you show your Hint Extern
?
You shouldn't unshelve
My Hint is
#[export] Hint Extern 2 (ValidPackage ?L ?I ?E (mkfmap ((?i, mkdef ?A ?B ?f) :: ?p)))
=>
eapply valid_package_cons ; [
eapply valid_package_from_class
| intro ; eapply valid_code_from_class
| unfold "\notin" ; rewrite imfset_fset ; rewrite in_fset ; eauto
]
: typeclass_instances packages.
Sorry for no context.
Matthieu Sozeau said:
You shouldn't unshelve
typeclasses eauto || shelve.
Unshelve.
is also the identity.
The idea is that if you want a goal to remain after resolution, you just need to shelve it, so you shelve in the Hint Extern or you add a Hint with low precedence which shelves the subgoal if not other hint could apply. Then resolution proceeds on the rest of the goals and keeps the shelved subgoals until the end
Matthieu Sozeau said:
There is a new
best_effort
option that could give you subgoals
https://coq.inria.fr/refman/search.html?q=best_effort&check_keywords=yes&area=default gives no result. How should I use it?
That's introduced by the PR above, so not there yet
Matthieu Sozeau said:
The idea is that if you want a goal to remain after resolution, you just need to shelve it, so you shelve in the Hint Extern or you add a Hint with low precedence which shelves the subgoal if not other hint could apply. Then resolution proceeds on the rest of the goals and keeps the shelved subgoals until the end
I see, thanks.
It is not advised to use eauto
in a hint extern. You should rather give back control to the proof-search. But you might want to do typeclasses eauto || shelve
in this case.
Another PR allows to have more control in Hint Extern: https://github.com/coq/coq/pull/6285, but again, it's not there yet
Matthieu Sozeau said:
It is not advised to use
eauto
in a hint extern. You should rather give back control to the proof-search. But you might want to dotypeclasses eauto || shelve
in this case.
I was using eauto
there because the goal there is not a class.
Thanks for your help!
I was using eauto there because the goal there is not a class.
This isn't relevant. You should probably always rely on typeclasses eauto
even when solving non-class goals. Just use different hint databases with the with
clause.
And BTW, see also https://hal.archives-ouvertes.fr/hal-01671994 (it's becoming quite old as a reference, I know that @Clément Pit-Claudel and others have been using these techniques recently but I don't think anyone else has written about them yet).
Théo Zimmermann said:
I was using eauto there because the goal there is not a class.
This isn't relevant. You should probably always rely on
typeclasses eauto
even when solving non-class goals. Just use different hint databases with thewith
clause.
Oh thanks, that's the thing I was missing!
I'm using this technique here: https://github.com/mit-plv/rupicola/blob/d1daf657df0518f3590acb9b16faa331fb4cfeaa/src/Rupicola/Lib/Compiler.v#L1273
Last updated: Sep 23 2023 at 13:01 UTC