Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Doing something n times with backgtracking

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Doing something n times with backgtracking


Chronological Thread 
  • From: Jason -Zhong Sheng- Hu <fdhzs2010 AT hotmail.com>
  • To: "coq-club AT inria.fr" <coq-club AT inria.fr>, Joey Eremondi <joey.eremondi AT gmail.com>
  • Subject: Re: [Coq-Club] Doing something n times with backgtracking
  • Date: Sun, 19 Aug 2018 02:18:41 +0000
  • Accept-language: en-CA, en-US
  • Authentication-results: mail3-smtp-sop.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-SN1-obe.outbound.protection.outlook.com
  • Ironport-phdr: 9a23:aiWUwRbEbA13V1BA9BBaEl3/LSx+4OfEezUN459isYplN5qZrsu6bnLW6fgltlLVR4KTs6sC17KI9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa8bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjm58axlVAHnhzsGNz4h8WHYlMpwjL5AoBm8oxBz2pPYbJ2JOPZ7eK7WYNEUSndbXstJVyJPHJ6yb5cBAeQCM+ZXrZXyqFQVoBSkGQWgGPnixiNUinPo26AxzuQvERvB3AwlB98AtG7brM7yNKcUTOu51arHzTXEb/NQ1jf29ZXGchA/rvGKUrJ8aNfax0syFwjYiViQp5HqPzOU1+QWrWSX8/dsWf60hm4nrAFxvj2vyd0tionNnI4a1lfE9SBgzYszONa2Rkl7Ydu+H5tRsSGXL5B2Qt84TG50uyY6zaMGtoChfCgEzJQnwBDeZ+abfIiP5xLuUvuaLzRghH99d7+zmwy+/Ey+xuHmVsS4ykhGoyhdntnCqH8A1ADf582CR/Rg+kquxzmC2gXR5+xFIU04i6/WJp88zbEqipYetF7MEyzrl0rriqKda18q9fKy6+v9Z7Xrvp+cOJFwigH5KqkggtCyD+MkPgQQRmSV5Pyy2KD68U3+W7pFkOc6kq7EsJDGPssbobO5AwlI3Yo58xa/FTCm0MgGknYbMFJFeRWHj47zN1HJPfD4EfO/g1OrkDdo3fzJIrrhApDVInjClrfuY6p95lZTxQYv19xS44xYBqsBLf7pREP8tsTUDhojPAy1x+bnBs991oQbWW+XDK+WLaPSsF6T5u4xP+WAeZMZtS39K/gi+/7uiGU2mV4ZfaWzwZQXb3W4Eux8I0qFeXrsnssBEWASswUiS+zqkUSOXiJXZ3avRK0x/So7CYKjDYfbXI+hmr2B3CGhHp1XfG9KEF6MEW27P7mDDr0HbzvXKct8mBQFU6KgQskvz1vm4AT90v9sKvfe0iwer5PqktZvsambtxY/5HRZFcmY1GeBTikgnGQFVnk7xq16pkpxy3+M1KF5h7pTEtkFtN1TVQJvF5fHyOoyTuLyXQTONuyJRVCpB52GHHllQN4x0cRUOx8lM9WlkhXK3i7sCLgQwe/YTKco+77RiiCib/12zGzLgex41wF/E5l/cFa+j6s6zDD9QovAkkGXjaGvLP9O3CnR8W6CySyFu0QKCVcsA5WAZmgWYw7tlfq8/lnLFuT8CbM7NwJAzYiJLa4YMoS032UDf+/qPZHlW0z0m2q0AkrXlJWlSdKwPl47hWDaAkVClB0P93GbMwR4Hj2mv2/VED1pExTofl/o9u597ni8Sx1twg==

Hi Joey,


I believe the original one with multimatch has done what you want. Just `do 2 find_specialize_in H` should suffice. That's because the backtracking point from multimatch is far reaching. However, multimatch tends to backtrack too much and gives performance impact. Maximilian's solution is better from this perspective.


Sincerely Yours,

Jason Hu

From: coq-club-request AT inria.fr <coq-club-request AT inria.fr> on behalf of Maximilian Wuttke <s8mawutt AT stud.uni-saarland.de>
Sent: August 18, 2018 7:05:22 PM
To: coq-club AT inria.fr; Joey Eremondi
Subject: Re: [Coq-Club] Doing something n times with backgtracking
 
Hi Joey,


You can try to do recursion on a Coq number in Ltac:

~~~~
Ltac find_specialize_in H n :=
lazymatch n with
| 0 => idtac
| S ?n' =>
match goal with
| [ v : _ |- _ ] => specialize (H v); find_specialize_in H n'
end
end.

Goal forall (T:Type) (P: T -> Prop) (y:T) (H : forall (x:T), x=y -> P x) (x1 : T) (x2 : T) (Heq : x1 = y), P x1.
Proof.
intros. now find_specialize_in H 2.
Qed.
~~~~

This is equivalent to `find_specialize_in H; find_specialize_in H` (with your version using multimatch).
Note that I replaced the multimatch with match.
This works, because when the recursive tactical call fails, the match backtracks (i.e. chooses another `v`).
If you want something like `find_specialize_in H 1; find_specialize_in H 1` to work, you can again replace the `match` with `multimatch`.

Note that the second argument of the tactic (i.e. the number of repeats), is an actual Coq term.
For example, the `lazymatch` fails if you call `find_specialize_in H true`.


Sincerely
Maximilian

On August 19, 2018 12:34:05 AM GMT+02:00, Joey Eremondi <joey.eremondi AT gmail.com> wrote:

Suppose I have a tactic like this (taken from HaysTac), that searches for an argument to specialize a particular hypothesis with:

    Ltac find_specialize_in H :=
      multimatch goal with
      | [ v : _ |- _ ] => specialize (H v)
    end.

However, I'd like to write a tactic that searches for `n` arguments to specialize a tactic with. The key is that it needs to backtrack. For example, if I have the following hypotheses:

    y : T
    H : forall (x : T), x = y -> P x
    x1 : T
    x2 : T
    Heq : x1 = y

If I write `do 2 (find_specialize_in H)`, it might choose `x2` to instantiate it, then fail trying to find a second argument. So I need my repeat loop to be able to backtrack with which arguments it chooses to specialize earlier arguments.

Is it possible to do this? How can I make a tactic loop that backtracks with its choices of previous iterations?

Thanks,

Joey


--
Sent from my Android device with K-9 Mail.



Archive powered by MHonArc 2.6.18.

Top of Page