Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] rewrite as many occurrences as possible

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] rewrite as many occurrences as possible


Chronological Thread 
  • From: Abhishek Anand <abhishek.anand.iitg 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 21:26:26 -0700
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=abhishek.anand.iitg AT gmail.com; spf=Pass smtp.mailfrom=abhishek.anand.iitg AT gmail.com; spf=None smtp.helo=postmaster AT mail-ed1-f44.google.com
  • Ironport-hdrordr: A9a23:8PV9OKN+GDFyyMBcTvijsMiBIKoaSvp037BL7TEJdfUxSKalfq+V7ZEmPHPP+VQssTQb6LO90cq7IE80l6QFhbX5VI3KNGLbUSmTTL2KhrGSpAEIdReOkNK1Fp0NT0G9MrDN5JRB4voSKTPXL+od
  • Ironport-phdr: A9a23:t4TEdh3cejcQY/xRsmDOHgQyDhhOgF0UFjAc5pdvsb9SaKPrp82kYBaHo6Q0xwKWFazgqNt8w9LMtK7hXWFSqb2gi1slNKJ2ahkelM8NlBYhCsPWQWfyLfrtcjBoVJ8aDAwt8H60K1VaF9jjbFPOvHKy8SQSGhLiPgZpO+j5AIHfg9qr2+yo/5DffgpEiTq/bLhvMBi4sALdu9UMj4B/MKgx0BzJonVJe+RS22xlIE+Ykgj/6Mmt4pNt6jxctP09+cFOV6X6ZLk4QqdDDDs6KWA15dbkugfFQACS+3YTSGQWkh5PAwjY8BH3W4r6vyXmuuZh3iSRIMv7Rq02Vzu/9admUBDniCkFODA5/m/ZidF+grxHrx+6vRNz35TZbZuJOPZifK7Qe84RS2pbXsZWUixMGp+xYJAPD+oAJuZYr5fyp1gTphaiAwmjHuXvxSJVjXLxx6I1yOQhEQDd3AwgAd0Os27Yo8/zNKgIV+C60bPEzTTCb/NK1jfw84fIchU7rvGNWbJ8a9beyU4qFw7ciFibtIPqMS+P2OsXr2ib8/RvVfipi2M/tw1/rTihyMcyhoTNmI8YxFDK+yp3zos1JdC1Skp2b9GmHZZQuSyXM5Z7T90+T2xnuSs21rkLtJy6cSUJ1Zgr2RjSYOGJfYiP5xLsTueRITFgiX15f7K/nRCy/lakyu34TMW7zktFrjddntnDt3ANyxzT6tWcRfdn4kih3jOP2gbO4e9HOUA5jbTXJ4Ilz7IqlZcesV7PEjHqlEj1lqObeUop9+614Or9eLrmvIWTN4pshwH+LKsunsu/DPw9MgcUXmib/f2w26P+8kHkWblKgPI7n6bDvJDVIsQboaG5AwtL3Yo59xm/CDKm3MwZnXkBMl1FZAqKg5b1N1zKOvz1Dveyj06ynDt3xP3KJLLsD5rVInjGirjhfLJ960BGyAo0yNBS/4hbBaoBIPLyQU/xtMLXDhwjPwOuxeboEtN92Z4EVWKOA6+ZLKzSvESH5uIqOeaMZYsVtCzhJPgi4v7ilWU5lkMFfam1wZsXb2i1EehhI0WAeHbjntMBEXoRsQclV+zriFiCUSZJaHqoXqI84Cs7CIO8AovZSICtmu/J4CDuFZpPI2tCF1rERXzvbsCPX+oGQCOUOM5o1DIeA+uPUYgkgDiktA7hy7dkZsPS8ysU/cbq3th0/O3ellc78zVyA4Kc0n2CZ25xl2IMATQx2fYs8gRG1l6f3P0g0LRjHttJ6qYROu/VHZHZxu1+Tdv1X1CYFj9sYFmjS9SiRzo2S4BpqzfvS0N0GtHngxyamiT2X/kakLuEAJFy+aXZjSCZGg==

Thanks Jason. I just tried `topdown try p` and it ran into stack overflow:

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.
  rewrite_strat (topdown try p). (* stack overflow *)
Abort.



On Mon, Oct 11, 2021 at 8:33 PM Jason Gross <jasongross9 AT gmail.com> wrote:
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/




Archive powered by MHonArc 2.6.19+.

Top of Page