coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Jason Gross <jasongross9 AT gmail.com>
- To: coq-club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] rewrite as many occurrences as possible
- Date: Mon, 11 Oct 2021 20:33:09 -0700
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-il1-f172.google.com
- Ironport-hdrordr: A9a23:YyRrNKrJ2CTzImaqUKbjTlUaV5pMeYIsimQD101hICG9Ffb4qynOppomPHDP+VUssR0b6LK90cq7Lk80i6QU3WB5B97LN2PbUQCTQL2Kg7GO/wHd
- Ironport-phdr: A9a23:0TLK6RXN4WBLL2aUMSBciAZR/rHV8KwxVTF92vMcY1JmTK2v8tzYMVDF4r011RmVB92duqsP1rWempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffRlEiCC5bL9vIxm7rQfcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh/27XhM5/gqJVrhyiuhJx3ZLbbZqPO/ZiZK7QZ88WSXZDU8tXSidPApm8b4wKD+cZOehXtZL9p1wIrRCjBAesHuTvyiRThnTr2qA60f4uERrB3AwmENIOqnPUrM7uNKoWSu21w6zIwi/Cb/NSwzvy9I/IchU4rPyKQLl/ftbfx1M1GAPZklWft5blPzWN2+kNr2WX8/ZsW+ythmM6qAx8pjahyMkxh4THiY8Y1k7J+DhnzIs7O9G1S0B1bcKmHZZMtCyXOIt4Tt8sTm10tig3zKANt5C8fCgP0psnxhjfZuSIc4iJ/hLjVPuRLixiiH15f7K/gg6+/lSnyu3mUMm7zlJKri5fntbSq38Nyhre4dWERPtl5kqtxyqD2gTJ5uxHIU04j7fXJp8gz7Iqi5Yes1rPEynrk0vslqCWbF8r+u2w5uTnfLrmopicOpdxig7kM6QuntWzAeU8MgQTRmSb9/mw2b/98UHjT7VKifo2kqbdsJ/EP8gUuqm5AwpN3oYi7RawESum3cwGkXUbKF9JYhGKgojzN13TIf31DO2zj0munTt13/zGO6fuApTJLnjNirfherN95lZeyAUp1tBf4JRUCr4bIPL0QU/xr9jVAwQ2Mwyx2ennCdF92pkCVmKIB6+VKLnSvkOQ5uIzP+mMY5cYtyr6K/g8/vLhkXs5mUIGcqSyxpsWaHW4Hux8LEmDYHrshM0BEWYQsQYkQuzqkg7KbTkGbHGrGqk4+ztzXImhFMLIQp2nqL2HxiayWJNMMDNoEFeJRFXhbIKCE9gWbzmJaptjmycDU7e7TJQ6hDmhsQb7z/xsKe+CqX5Qjo7qyNUgv76brho17zEhV6x1PEmCSmh1miUDQDpkhciXRGRyz16C1e5zhPkKTbS7BttMWwY+cJ/Ylql0Uo+oHA3GediNRRCtRdD0WVkM
I haven't tried it myself, but I expect topdown try p to work fine. But it seems like a bug for rewrite_strat try foo to ever fail
On Mon, Oct 11, 2021, 20:11 Samuel Gruetter <gruetter AT mit.edu> wrote:
A related issue is that rewrite also doesn't backtrack if it fails to solve a
sidecondition: https://github.com/coq/coq/issues/7672
That issue (and a few other rewrite issues) made me learn how to write my own
rewrite tactics in Ltac.
In your case, the following home-made rewrite tactic might work:
Require Import ZArith.
Open Scope Z_scope.
Lemma rew_zoom_bw{T: Type}{lhs rhs: T}:
lhs = rhs ->
forall P : T -> Prop, P rhs -> P lhs.
Proof.
intros. subst. assumption.
Qed.
Ltac rewr equ :=
match type of equ with
| ?LHS = _ =>
match goal with
| |- context C[LHS] =>
change ((fun x => ltac:(let b := context C[x] in exact b)) LHS);
apply (rew_zoom_bw equ)
end
end.
Lemma xx (p:3=4) (n: 3=6 -> Z) : 1= match Z.eq_dec 3 6 return Z with
| left p => n p
| right _ => 7
end + 3.
Proof using.
rewr p.
Note that usually, I would use "pattern" in my home-made rewrite tactics, but
"pattern" has the same dependent types issue as Coq's and ssr's rewrite, so I
used "context" instead, so that only one occurrence is cut out at a time.
On Mon, 2021-10-11 at 18:31 -0700, Abhishek Anand wrote:
> Is there a Coq rewrite tactic that will try to rewrite as many occurrences as
> possible instead of just failing when one occurrence cannot be rewritten:
>
> Require Import ZArith.
>
> Open Scope Z_scope.
> Lemma xx (p:3=4) (n: 3=6 -> Z) : 1= match Z.eq_dec 3 6 return Z with
> | left p => n p
> | right _ => 7
> end + 3.
> Proof using.
> Fail rewrite_strat (try topdown p).
> Fail rewrite_strat (try bottomup p).
> Fail rewrite_strat (try innermost p).
> Fail rewrite_strat (try outermost p).
> Fail rewrite p.
> rewrite p at 2.
> Abort.
>
>
>
> -- Abhishek
> http://www.cs.cornell.edu/~aa755/
- [Coq-Club] rewrite as many occurrences as possible, Abhishek Anand, 10/12/2021
- Re: [Coq-Club] rewrite as many occurrences as possible, Samuel Gruetter, 10/12/2021
- Re: [Coq-Club] rewrite as many occurrences as possible, Jason Gross, 10/12/2021
- Re: [Coq-Club] rewrite as many occurrences as possible, Abhishek Anand, 10/12/2021
- Re: [Coq-Club] rewrite as many occurrences as possible, Jason Gross, 10/12/2021
- Re: [Coq-Club] rewrite as many occurrences as possible, Samuel Gruetter, 10/12/2021
Archive powered by MHonArc 2.6.19+.