Search code examples
coq

Finding rewrite rules


I have a hard time finding the available rewrite rules for my situation. As I don't want to bother you with each rewrite question, I was wondering do you have some tips for finding suitable rewrite rules?

Do you have any tips on how to solve and or search for rewriting the following example:

1 subgoal
H: P
H0: Q
__________
R

And say I have Lemma Join: P /\ Q = R In order to do this rewrite, I suppose I need to get H and H0 first rewritten into P /\ Q. So how would you solve or find the rewrite rules for such a case?

Another example

H: a <= b
____________
b < a

I am confident there should exists some commutativity rewrite rule for this, but how can I best find this rule?

Many thanks in advance!


Solution

  • First a tip so you don't run into this problem later: Don't confuse equality of types for logical equivalence. What you usually mean in your first example above is that P/\Q <-> R, not that the type P/\Q is definitionally the same type as R.

    With regards to your question about finding lemmas in the library; yes, it is very important to be able to find things there. Coq's Search command lets you find all (Required) lemmas that contain a certain pattern somewhere in it, or some particular string. The latter is useful because the library tends to have a somewhat predicable naming scheme, for instance the names for lemmas about decidability often contains then string "dec", commutativity lemmas often are called something with "comm" etc.

    Try for example to search for decidability lemmas about integers, i.e. lemmas that have the term Z somewhere inside them, and the name contains the string "dec".

    Require Import ZArith.
    Search "dec" Z.
    

    Back to your question; in your case you want to find a lemma that ends with "something and something", so you can use the pattern ( _ /\ _ )

    Search ( _ /\ _ ).
    

    However, you get awfully many hits, because many lemmas ends with "something and something".

    In your particular case, you perhaps want to narrow the search to

    Search (?a -> ?b -> ?a /\ ?b).
    

    but be careful when you are using pattern variables, because perhaps the lemma you was looking for had the arguments in the other order.

    In this particular case you found the lemma

    conj: forall [A B : Prop], A -> B -> A /\ B
    

    which is not really a lemma but the actual constructor for the inductive type. It is just a function. And remember, every theorem/lemma etc. in type theory is "just a function". Even rewriting is just function application.

    Anyway, take seriously the task of learning to find lemmas, and to read the output from Search. It will help you a lot.

    Btw, the pattern matching syntax is like the term syntax but with holes or variables, which you will also use when you are writing Ltac tactics, so it is useful to know for many reasons.