Zulip Chat Archive

Stream: Is there code for X?

Topic: modus ponens in context


Patrick Thomas (Oct 09 2021 at 05:42):

If I have P -> Q and P in the context, is there a tactic that will add Q to the context?

Johan Commelin (Oct 09 2021 at 05:44):

I think apply_fun f at x do it, if f : P -> Q and x : P.

Johan Commelin (Oct 09 2021 at 05:44):

But have := f x or let y := f x also work.

Patrick Thomas (Oct 09 2021 at 05:45):

Thank you.

Patrick Thomas (Oct 09 2021 at 05:55):

apply_fun doesn't seem to work, but let does,

Scott Morrison (Oct 09 2021 at 06:02):

You might need to import tactic.basic for apply_fun.

Patrick Thomas (Oct 09 2021 at 06:04):

I still get, failed to apply f at x.

Scott Morrison (Oct 09 2021 at 07:18):

Can you post a #mwe?

Eric Wieser (Oct 09 2021 at 08:48):

Isn't apply_fun for equalities not implications?

Yaël Dillies (Oct 09 2021 at 08:54):

Yup, as far as I know all it does is using congr_arg.

Scott Morrison (Oct 09 2021 at 08:57):

apply_fun X at Y definitely does more than congr_arg!

Scott Morrison (Oct 09 2021 at 08:57):

But yes, it doesn't do this.

Yaël Dillies (Oct 09 2021 at 08:58):

I should really know better :sweat_smile:

Johan Commelin (Oct 09 2021 at 09:01):

Sorry for the apply_fun suggestion. I should have know that it doesn't work here.

Scott Morrison (Oct 09 2021 at 09:03):

It's so tempting though. We use apply many ways in informal maths.

Scott Morrison (Oct 09 2021 at 09:03):

I think it's reasonable to have apply_fun's semantics be "please do something sensible with this function (at this location)". So we should support it. :-)

Scott Morrison (Oct 09 2021 at 09:04):

@Patrick Thomas, often useful in similar situations is tactic#specialize.

Eric Wieser (Oct 09 2021 at 09:06):

I don't think this is such a case though; apply_fun f means "put f on the right of the colon somewhere". In the case we're talking about, it would mean "use this to construct the term"

Yaël Dillies (Oct 09 2021 at 09:07):

specialize is indeed what you want.

Patrick Thomas (Oct 09 2021 at 14:54):

I think Coq might have an apply in tactic?

Bhavik Mehta (Oct 09 2021 at 15:22):

iirc Coq has apply atfor this, in Lean you can also do replace x := f x to mimic this behaviour, but I generally prefer Johan's original suggestion of have := f x in case I want x : P later

Eric Wieser (Oct 09 2021 at 17:43):

I think apply at would make sense for lean to support

Alex J. Best (Oct 09 2021 at 17:46):

No idea if this code still works but there looks to be an implementation here: https://github.com/jldodds/coq-lean-cheatsheet/blob/master/coq-tactic-substitutes.lean, edit: or is apply in different to apply at?


Last updated: Dec 20 2023 at 11:08 UTC