Skip to Content.
Sympa Menu

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

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[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: [Coq-Club] How do you do conditional rewriting?
  • Date: Mon, 21 Sep 2015 10:02:05 -0300
  • Authentication-results: mail2-smtp-roc.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-f176.google.com
  • Ironport-phdr: 9a23:nPk4xhC1eQtqv6xfIVelUyQJP3N1i/DPJgcQr6AfoPdwSP7/psbcNUDSrc9gkEXOFd2CrakU16yP7+jJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6OyZ3rn8mJuLTtICxwzAKnZr1zKBjk5S7wjeIxxbVYF6Aq1xHSqWFJcekFjUlhJFaUggqurpzopM0roGxsvKcq8NcFWqHndexsRrtBST8iLmod5cvxtBCFQxHZtVUGVWBDsgdHBEDu5QvkV5PxtWOutvdy3yKROsjuZb8xUDWmqaxsTUm72288Kzcl/TSP2YRLh6VBrUf5qg==

 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