Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] How do you do conditional rewriting?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] How do you do conditional rewriting?


Chronological Thread 
  • From: Hugo Carvalho <hugoccomp AT gmail.com>
  • To: coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] How do you do conditional rewriting?
  • Date: Mon, 21 Sep 2015 10:11:11 -0300
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=hugoccomp AT gmail.com; spf=Pass smtp.mailfrom=hugoccomp AT gmail.com; spf=None smtp.helo=postmaster AT mail-ig0-f169.google.com
  • Ironport-phdr: 9a23:8T8tHBAMxqJmkxB2DJ00UyQJP3N1i/DPJgcQr6AfoPdwSP7/psbcNUDSrc9gkEXOFd2CrakU16yP7+jJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6OyZ3rn8mJuLTtICxwzAKnZr1zKBjk5S7wjeIxxbVYF6Aq1xHSqWFJcekFjUlhJFaUggqurpzopM0roGxsvKcq8NcFWqHndexsRrtBST8iLmod5cvxtBCFQxHZtVUGVWBDsgdHBEDu5QvkV5PxtWOutvdy3yKROsjuZb8xUDWmqaxsTUm72288Kzcl/TSP2YRLh6VBrUf5qg==

I have not. From the single line on the documentation, i had deduced this "rewrite LEMMA by LTAC" was to be applied to a LEMMA with side-conditions baked into it, that is, something like "forall v1 v2 v3, ... -> side_condition -> lhs = rhs". In my case, the lemma's conditions for applying are not a part of the theorem.

2015-09-21 10:04 GMT-03:00 Adam Chlipala <adamc AT csail.mit.edu>:
Have you tried [rewrite LEMMA by LTAC]?  Admittedly it doesn't work quite the way I'd like, missing some rewrite opportunities, but it also only succeeds if the lemma side conditions are proved by [LTAC].


On 09/21/2015 09:02 AM, Hugo Carvalho wrote:
 Club,

I'm interested in rewriting conditionally. That is, to use the rewrite tactic only if some condition applies. For example, say we have some way of testing two numbers and will only apply the commutativity of addition if the test goes through. Right now, my tactic looks like this:

Ltac condrewrite :=
 match goal with
   | [ |- context[(plus ?a ?b)] ] =>
   let extravars := (*Some extra computation, such as reflecting a and b into ASTs*) in
   let cmp := (eval compute in (*Test goes here, depends on extravars*) ) in
    match cmp with
    | Gt => rewrite -> (plus_comm a b)
    | _ => fail
    end
 end.

As you might imagine, this is fairly unwieldy. Notice the "context[(plus ?a ?b)]"; i'm replicating, within a ltac match, something i know the rewrite tactic is perfectly capable of doing by itself.

Is there any way of doing this in a cleaner way?





Archive powered by MHonArc 2.6.18.

Top of Page