coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Jason -Zhong Sheng- Hu <fdhzs2010 AT hotmail.com>
- To: Kevin Hamlen <hamlen AT utdallas.edu>, "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Conditionally apply a multi-goal tactic?
- Date: Wed, 23 May 2018 23:21:22 +0000
- Accept-language: en-CA, en-US
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=fdhzs2010 AT hotmail.com; spf=Pass smtp.mailfrom=fdhzs2010 AT hotmail.com; spf=Pass smtp.helo=postmaster AT NAM02-CY1-obe.outbound.protection.outlook.com
- Ironport-phdr: 9a23:mDRj0xzXZwhoY6jXCy+O+j09IxM/srCxBDY+r6Qd2usVIJqq85mqBkHD//Il1AaPAd2Araocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HdbglSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDtU7s6RSqt4LtqSB/wiScIKTg58H3MisdtiK5XuQ+tqwBjz4LRZoyeKfhwcb7Hfd4CRWRPQNtfVzBPDI2/YYsADfYOMulDoobnu1cCsQGzCRWwCO/xzDJDm3/43bc90+QkCQzI2BYvH8kJsHTSsd75LaQdUeCyzKnOwjXIcu5Y2Tfj54jOfRAtuOyHU7BtccHMzkQvGR7KjlWRqIz+IT+ZyvkBv3SA4upgUuKvl2snpBtwojir3Msjlo7JhocMx13C6C53w541KMW3RUJne9KpFIVcuzuVOodsX88vTHlkuCgkxbAFpZK2eS0HxZo6yBPbZfGKdpKH7QntWeqMJDp3mHxldbCxhxu37Uev1uPxVsey3V1XtCRKiMPMuWoI1xHL6siIVP99/kC51DiXyw3d7f1ILV4tmafFKZEt36c8lp0IvkvdBCP2n1j2jLONeUUj5+io7fnobq/+pp+GMI90lh/xPbgymsy+BuQ4NBICX2+G+eSg0L3j+kr5QLZQgvIqlanZtYjWJcUdpqGnHw9Yyoku5wqlAzqiztgUh3YKIEhYdB+Il4TpPkvBIPH8DfexmVSslzJryujIPrL8ApXML2PDnKn9cbpg90JR0wozzddD55JREL4BIfbzVlXtu9zfCx81Kxa0zPr/CNVhyoMeXnqCDbOeMKPLqFOH+uYvI/SXa4IOozb8K/0l5+b0gnMjmF8de7Op3ZoNZ3yiEPRmORbRXX25odofEGFCngM7SOHswAmCWDtXanCaQr4w7zU/AZngAIveEMTlyreGxWKwGoBcTmFAEFGFV3nyPc3QUPAVLSmWP8VJkzoeVLHnRZV3hj+0swqv6bN8Keycvx8YspTsnON16uvc0FkS6HQgAcidwXrXFzgstmMPWzo/3aQ5qkt4nATQmZNkiuBVQIQAr8hCVR03YNuFl7QjWoLCHznZd9LMc26IB9CvADU/VNU0moRcY0FhHtyjilbI2C/4WuZJxYzOP4Q99+fn51a0P9x0ki2U1K49ilAnRo1EMmj03vcipTiWPJbAlgCir4jvdakY23KSpkGq6DLU+WppCUt3W6iDWm0DbEzLq9i//lnFU7KlFbUgNE1G1NKGLaxJLNbuiAcfSQ==
Hi Kevin,
so you invoke a tactic to reorder the goals to a proper order to work on manually? I'd imagine you must inspect your goals a lot. If that's the case, why not discharge some goals, if not all, if you already have some logical understanding of them?
Coming back to your original question, I am not sure what you are targeting is feasible in raw Ltac (experts please confirm). What Ltac essentially does is really simple: it evaluates a Ltac _expression_ to corresponding
value, and in the case of being used as a tactic, it passes on the resulting tactic value to external machinery to exercise accordingly. What semicolon says is to ask the said machinery to apply following tactic value _independently_ to each goal. The reason
why your attempt fails, is due to branching, which is introduced by || here. It's very important to realize that the Ltac searching machinery regard your goals independently, so whenever branching occurs, there are chances that the search path might diverge
thereafter. Also note that backtrackings happen after branches also occur independently, unless one branch exhausts its backtracking point and the failure propagates beyond the branch.
To answer why the `do n` one also fails, it's because failure in Ltac will propagate up, until it hits a backtracking point and trigger a backtracking, or it hits the top level. That is also not a good way to use a tactic
that is expected to fail.
I personally used numgoals in some occasions to detect a sequence of tactics "at least does not hurt", by guarding inversion/destruct does not generate more goals than some point. But in general, Ltac is actually quite
limited and there aren't much things you can do if you want to achieve some specific target of such kind.
Jason Hu
Ltac reps tac :=
let x := numgoals in
guard x > 0;
pngoals;
tac;
reps tac.
Goal True /\ False.
split.
Fail all:reps fail.
Sent: May 23, 2018 6:16:34 PM
To: Jason -Zhong Sheng- Hu; coq-club AT inria.fr
Subject: Re: [Coq-Club] Conditionally apply a multi-goal tactic?
In my case, my tactic uses "cycle" and "swap" after repeated "destruct" to reorganize the goal order. When the number of goals is large, and there is a more natural order than the one yielded by "destruct", this can be very useful. Otherwise one must manually find and focus each logically "next" goal out of a sea of perhaps hundreds of goals, which can be very tedious.
However, my question also applies to any tactic that consults "numgoals" (e.g., to constrain goal explosions), even if the tactic doesn't do any goal-reordering. It's not clear to me why tactics like "||" must restrict focus to a single goal even when the tactics on which they operate are applicable to multiple goals.
Best,
Kevin
Hi Kevin,
This way of constructing auto tactics makes me curious. How do you use `cycle` in your tactic? Would the use of that be substantially useful?
Thanks,Jason Hu
-------- Original message --------From: Kevin Hamlen <hamlen AT utdallas.edu>Date: 5/23/18 17:27 (GMT-05:00)Subject: [Coq-Club] Conditionally apply a multi-goal tactic?
Dear Coq Users,
I have a tactic T that operates on multiple goals as a group (e.g., it
uses the "cycle" tactic). I would like to repeatedly apply this tactic
until it fails or there are no more focused goals. How can I do so?
I first tried the obvious: "all: repeat T."
But that doesn't work because "repeat" cancels the "all" specifier,
narrowing the proof scope to one goal at a time, and preventing T from
operating on multiple goals. One can verify this by executing the
following:
Ltac showgoalcount := let g:=numgoals in idtac g.
Goal True /\ True.
split. all: repeat showgoalcount. (* prints two 1's instead of a 2 *)
Abort.
I then tried a recursive ltac:
Ltac myrepeat T :=
let n := numgoals in (guard n=0 || (showgoalcount; T; myrepeat T)).
But that doesn't work either, because "||" also cancels the "all"
specifier, which one can verify by executing this:
Goal True /\ True.
split. all: myrepeat reflexivity. (* prints two 1's instead of a 2
then a 1 *)
Qed.
Similar experiments reveal that "try", "tryif", and "first" all fail for
the same reason.
The only partial solution I can find is the following (rather
ridiculous) use of "do":
Ltac crazyrepeat T :=
let n:=numgoals in do n (showgoalcount; T; crazyrepeat T).
This actually works when T never fails, because "do n ..." has the
desired effect of succeeding without doing anything when n=0, yet it
keeps all goals in focus when n>0. But failures of T cause the whole
tactic to fail instead of making progress; and this solution scales out
of control when the number of goals is large, since it queues n
recursive calls on every iteration, resulting in an exponential number
of iterations.
Is there any solution?
Best regards,
Kevin
- [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/23/2018
- RE: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/23/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/24/2018
- Re: [Coq-Club] Conditionally apply a multi-goal tactic?, Kevin Hamlen, 05/24/2018
- RE: [Coq-Club] Conditionally apply a multi-goal tactic?, Jason -Zhong Sheng- Hu, 05/23/2018
Archive powered by MHonArc 2.6.18.