Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] autorewrite neglects sub-patterns?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] autorewrite neglects sub-patterns?


Chronological Thread 
  • From: Matthieu Sozeau <mattam AT mattam.org>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] autorewrite neglects sub-patterns?
  • Date: Thu, 7 Jun 2018 20:27:44 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mattam AT mattam.org; spf=Pass smtp.mailfrom=matthieu.sozeau AT gmail.com; spf=None smtp.helo=postmaster AT mail-wr0-f175.google.com
  • Ironport-phdr: 9a23:kJ+9HxDVv95L1icBuHF0UyQJP3N1i/DPJgcQr6AfoPdwSPv/pMbcNUDSrc9gkEXOFd2Cra4c1qyO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglUhDexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykCoIODA5/2PXhMJ+j6xVvQyvqABkzoHOfI2YLuBzcr/Bcd4YQ2dKQ8ZfVzZGAoO5d4YBCPAOPfpEr4n9plsBswa+DhSxCuPoyz5HmGX53bAn2OkmFAHJxhAgH84Uv3TRt9j1Mb0dUfypzKbSyDXPdfRW2S3y6IXRdB0qvP+CXbV1ccXLyEkvERvIjlSWqYz/PjOazP4Bs2aB7+dmSOmhiHYnphlvrjSzwsogkIrEi4IPxlzZ6yl0w5w5KcC6RUN7Z9OvDYFeuDuAN4RsR8MvW2Fotzg+yr0BoZO7eTIFyJUjxxLGZf2HaZSE7gvtVOqMIzp1hGhpeL24hxa1/kigzvPzWtOo31ZNqypJitjMtnYT2BzP8sWLVOdx80O71TuM1w3f8PxILV43mKbBNpIswL49moIWsUvZHy/2nEv2jLWRdkUh4uWo7v7oYqn6pp+cNo97lBz+Pr41msy4AOU3LBIBX3WA9OSz0b3s50z5QLFQgvIqlanZtYjWJd4Hqa6hHw9VzoEj5g6jADehydQUhGUILFZYeB2clIXpIFHPIPXgDfilmViskTFrx+rHPrL7GJnNIGLDw//deuN27FcZww4ux/he4YhVA/cPOqHdQEj04fnREgM5MgGpi93gGth0y8tKXGuTHqacGKbbrUOB46QoOebaN9xdgyr0N/Vwv62mtnQ+g1JIJfD4j6tSU2ixG7FdG2vcZHPthtkbFmJT51gxSeXrjBuJVjsBPi/uDZJ53SkyDcedNamGXpqk2ebT2S6nApRTIGdcBQLUSCq6R8C/Q/4JLRmqDIphnzgDD+bzToYg0VSxrle/xeM4c6zb/SoXsZ+l399wtbXe

Dear Kevin,

  [autorewrite] is indeed a bit crude, namely it only does [repeat rewrite].
You might prefer more control using the [rewrite_strat] tactic which allows
you to control the traversal strategy and will try to apply the rewrite rule to 
subterms as you instruct it. In your example:

  now rewrite_strat (topdown (hints mydb)).
or 
  now rewrite_strat (bottomup (hints mydb)).

complete your proof. Both strategies are fixpoints: 
- for topdown, if the argument tactic succeeds (here (hints mydb) which
  succeeds when it can use one of the rewrite hints), it calls itself recursively 
  and if it fails it recursively calls itself on subterms or stops making no 
  progress if there are no subterms
- for bottomup, it goes to the leaves of the term first.

https://coq.inria.fr/refman/addendum/generalized-rewriting.html#strategies-for-rewriting

Best,
-- Matthieu

On Thu, Jun 7, 2018 at 8:02 PM Kevin Hamlen <hamlen AT utdallas.edu> wrote:
Dear Coq users,

I'm finding that "autorewrite" fails to consider rewriting opportunities
within patterns that match a hint but fail it.  Is this behavior
intentional?  Here's an example:

Require Import NArith.
Open Scope N.

Hint Rewrite N.mod_small using assumption : mydb.

Goal forall x y z, x < y -> (x mod y) mod z = x mod z.
   intros.
   Fail progress (autorewrite with mydb).
   (* This unfortunately fails to progress even though it could
successfully rewrite "x mod y" to "x".  It fails because it first tries
rewriting "(x mod y) mod z" to "x mod y" and is unsuccessful, and then
never looks for rewrite opportunities within the matched pattern. *)

   (* If I manually strip the "_ mod z" part, it finds the pattern and
rewrites it: *)
   apply (f_equal (fun n => n mod z)).
   progress (autorewrite with mydb).
   reflexivity.
Qed.

Is there any work-around?  This behavior unfortunately makes autorewrite
useless for most of my patterns, forcing me to resort to much slower Ltacs.

Cheers,
Kevin





Archive powered by MHonArc 2.6.18.

Top of Page