Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Ltac body involving a "with" clause

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Ltac body involving a "with" clause


Chronological Thread 
  • From: Samuel Gruetter <gruetter AT mit.edu>
  • To: "coq-club AT inria.fr" <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Ltac body involving a "with" clause
  • Date: Wed, 9 Dec 2020 17:37:54 +0000
  • Accept-language: en-US
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gruetter AT mit.edu; spf=Pass smtp.mailfrom=gruetter AT mit.edu; spf=None smtp.helo=postmaster AT outgoing-exchange-1.mit.edu
  • Ironport-phdr: 9a23:CgKBexZzlkkqerzpZxm/Fdr/LSx+4OfEezUN459isYplN5qZr8m4bnLW6fgltlLVR4KTs6sC17OJ9fm/CSdduN6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vLhi6txjdu8sVjIdtKqs91wbCr2dVdehR2W5mP0+YkQzm5se38p5j8iBQtOwk+sVdT6j0fLk2QKJBAjg+PG87+MPktR/YTQuS/XQcSXkZkgBJAwfe8h73WIr6vzbguep83CmaOtD2TawxVD+/4apnVAPkhSEaPDM/7WrZiNF/jLhDrRyhuRJx3pLUbo+WOvpwfKzdfM8VSmVaU8lLSyBMGJmxY5cTA+cDO+tTsonzp0EJrRu7HQSiGfngyjpVhnDo2a0xzuUvERvb3AM+A9IOrGrbrM/oP6oVXuC11rTIwivfb/NKxzj98pPFchUgofGQR75/b9feyVQ2Gg7Dk16fppDrMSmP2eQRr2iU8fBgVeS3hmI7twx8ojahy8MyhoXXm48bxEzJ+ytnzIooONG2SFN2bcCrHpZOsyyXOIR4TMwsTmxntys0xbIItJqncCYFx5oqwQPUZf+fc4WQ/x7uV/ydLDNiiH57e7+znQu+/Ei4xuD9V8S4ylhHojZfntXRq3wA1Abf5tWHR/dl40us2iyD2gTJ5uxLO0w4iLfXJpEnz7UtjJQcq17DETXzmEjujK+ZaEEk+u+w5uTgf7XmupCcN4h1igH4PaQig9KwAOskPQgORWeb/+u826P68UHkWrlKi/w2krXDvJ/EOMsbu7a1Aw5T0ok99xayFyqq3dcCkXQDNl5JZhGKg5L0N1zOOPz4CO2wg1WokDdl3fDGObjhD43CLnjZjbfuY6p961JCxwop1t1f4pNUCq0bLP3tR0DxqcTUDgUlPAys3+bnFNJ925sCVmKIG6+VKb/dsVuV5u00OOSMf48UuDPlK/c//fLujHk5mUUcfaazx5cXZmq4TbxaJBDTan31x9wFDG0ivwwkTeWshkfIGWpYYG/3VKYh7Bk6DpinBMHNXNb+rqaG2XKAF5hLa2QOJUqRHGv0ep/MD/gWdS+OPsJ7ujkFSf6sR5J3hkLmjxPz17cydrmcwSYfr5+2jIEotd2Wrgk78HlPN+rY02yJSDslzGQVWzAx3aZw5EFtwVeK16d1xqUeEN1Pof5FT1VibM+O/6lBE9n3Hzn5UJKMQVeiTM+hBGBjS9MthdICfhQkQonwvlX4xyOvRoQtufmTHpVloKfdwz78K9svk3s=

Hi Adam,

I don't think this is an Ltac bug, I'd even call it a feature! For instance, I could match on the name of the argument of temp, and use a variable myA to refer to that name when I apply the lemma, as follows:

Lemma temp{A:Type} : forall (a:A), a = a.
Proof.
  trivial.
Defined.
 
Ltac generic lem :=
  lazymatch type of lem with
  | forall (myA: Type) (mya: myA), _ =>
    lazymatch goal with
    | H: ?b = _ |- _ => apply lem with (mya := b)
    end
  end.
 
Example temp_ex {A:Type} : forall (c:A), c = c -> c = c.
Proof.
  intros.
  generic @temp.

And regarding hints on how to debug: I replaced match by lazymatch (so that the decision which branch to take only depends on the pattern and not on whether the tactic to the right of => succeeds), which makes debugging easier in the case where the pattern matches, but the tactic fails: You get the precise error message, rather than just "No matching clauses for match".

Hope that helps,

Sam


On Mon, 2020-12-07 at 21:28 +0000, Petz, Adam Michael wrote:

Hello all,

 

I encountered some surprising (to me) behavior while writing an Ltac procedure involving a “with” clause.  A minimal example appears below.  The problem occurs when binding a variable from a hypothesis, then using that variable in the LHS of a with binding in the Ltac body.  My expectation is that the LHS (x in the assignment x:=y) is unaffected by substitution, and must simply match the name of a bound variable in the type of the Lemma to which it is being applied.

 

I suspected a scoping issue, so I found a workaround in temp_ltac’ below by changing the name of the bound variable to one that does not appear in the type of the Lemma.  However, I fear this could become tedious in larger developments.

 

Finally, a few questions:  Is this a bug in Ltac?  If not, are there tricks/best practices to avoid it?  Any hints on how to debug Ltac errors like this would also be much appreciated!

 

Best,

Adam

 

 

Lemma temp{A:Type} : forall (a:A), a = a.

Proof.

  trivial.

Defined.

 

Ltac temp_ltac :=

  match goal with

  | [H: ?a = _ |- _] => apply temp with (a:=a); eauto

  end.

 

Example temp_ex {A:Type} : forall (c:A), c = c -> c = c.

Proof.

  intros.

  Fail temp_ltac.

  (* Does this evaluate to: apply temp with (c:=c) ? *)

  (* Intent is as follows: *)

  apply temp with (a:=c).

Qed.

 

Ltac temp_ltac' :=

  match goal with

  | [H: ?b = _ |- _] => apply temp with (a:=b); eauto

  end.

 

Example temp_ex' {A:Type} : forall (c:A),  c = c -> c = c.

Proof.

  intros.

  temp_ltac'.

Qed.

 




Archive powered by MHonArc 2.6.19+.

Top of Page