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: Adam Chlipala <adamc AT csail.mit.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] How do you do conditional rewriting?
  • Date: Mon, 21 Sep 2015 09:17:14 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=adamc AT csail.mit.edu; spf=Pass smtp.mailfrom=adamc AT csail.mit.edu; spf=None smtp.helo=postmaster AT outgoing.csail.mit.edu
  • Ironport-phdr: 9a23:sT6kdB+cW+EZLv9uRHKM819IXTAuvvDOBiVQ1KB90OocTK2v8tzYMVDF4r011RmSDdmdsq4MotGVmp6jcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47AblHf6ke/8SQVUk2mc1EleqKsRsb7tIee6aObw9XreQJGhT6wM/tZDS6dikHvjPQQmpZoMa0ryxHE8TNicuVSwn50dxrIx06vrpT4wJk2+CNJ/vkl6sRoUKPgfq1+Q6YLIi4hNjUc6MTu/TLDSQqX738VGjEfnhNNCCDO9xj7WtH0sze8u+ZgjnrJdfbqRKw5DGzxp5xgTwXl3X8K

Still, one attractive way to proceed is to prove a lemma with extra side conditions that are not logically necessary, if your heuristic can be phrased that way.

On 09/21/2015 09:11 AM, Hugo Carvalho wrote:
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