coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Dan Christensen <jdc AT uwo.ca>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport
- Date: Tue, 12 Nov 2019 16:34:43 -0500
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=Neutral smtp.pra=jdc AT uwo.ca; spf=None smtp.mailfrom=gsmlcc-coq-club AT m.gmane.org; spf=None smtp.helo=postmaster AT blaine.gmane.org
- Cancel-lock: sha1:I+DL/GrNYd22fk+5TjiLjFUNFAo=
- Ironport-phdr: 9a23:65CNrx8tOqwYlf9uRHKM819IXTAuvvDOBiVQ1KB40OkcTK2v8tzYMVDF4r011RmVBN6dsqgVwLOL6ejJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVijexe65+IAuyoAneq8UbgZVuIbstxxXUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vyiu47ttRRT1jioMKjw3/3zNisFokqxVoA+vqRJ8zY7ab46aKPRxc7jBfd8GX2dNQtpdWjZdDo66coABD/ABPeFdr4TlqVUBtx2+DhSyCePv0D9Ih2T23bEk3OQnCgHJwgogFM8JvXTWsdr6KLwfUf27zanP1znMc+lZ1C775YPVfB4hpvSMUqhxccrX0UQvGALFjkmQqYz4JDyZzPgCs2+e7+dmSOmhiHYnphlsrjWrxsogkJTFi4IRx1ze6Cl0woc4KcemREJlYNOpFoZbuTuAOItsWMwiRnlluCYkxb0Cvp62ZDMFyJA9yB7ebfyIbZKE4h3mVOmLJzd3mmhpeLWlhxa96USgy+v8Wdeo0FtSsyZIltnBumoQ2xHT7sWLUOZx80Wg1DqVyQzf9OBJLVgxlaXBKp4hxrAwloAUsUTGBiL2l172jKqSdko45uek8vjoYrL/ppOFK4B0jhz+Pb81l8y6G+g4PQ0OUHKd+euizrHj+lf5QLpSgv0sjqbZqIzaJdgcpqOhHwBV1Z8j5w+jADeizdQXhmIKLElFeRKCl4jmIUvCIPH+DfelglSjii1nx/7cPu6pPpKYJX/a1bzlYLxV6khGyQN1w8oMyYhTD+QtKfS7cU/rtcfEAxkiPgr8l+TrA/1gyYRYUmvZUfzRC7/brVLdvrFnGOKLfoJA4G+hechg3ObniDoCoXFYZbOgjckKd3f+Ff00eRzIM0qpuc8IFCIxhiR7SeXrjFOYVjsKPCS3Ga057zc2ToW8AtWbH93/sPm6xC6+W6ZuSCVGB1SLSCe6fYGNWvEBLi2XK8ls1DseWur5Rg==
- Mail-copies-to: never
> Not sure if relevant, but I recently wrote my own rewrite tactic:
> https://github.com/mit-plv/coqutil/blob/master/src/coqutil/Tactics/rewr.v
> It's more cumbersome to use (you have to spell out the left-hand side), but
> I
> find it easier to control it and to understand what's going on.
Thanks for the response. I took a look at your rewrite tactic. It's
clever, and it could probably handle the things I'm considering, but
for each lemma, I'd have to write a version of getEq that figures out
the arguments to use for the lemma. Coq's built-in rewrite is able
to figure that out with no work on my part, and that's what I'd like
to figure out.
Does anyone know if it's possible to access the power of rewriting,
without doing a rewrite? That is, to find a sub-term of a given term
that unifies with the lhs of a lemma (with arguments) and so that the
sub-term can be abstracted away from the term?
If it's not currently possible, could a tactic be added to Coq that
gives access to what rewrite does?
Or can I call rewrite, examine the proof term it generates, undo the
rewrite, and use that info myself (all in Ltac)?
> And one more thing: Did you consider using multimatch instead of
> match? I had to do so at one point and maybe that's just what you're
> missing?
I also tried multimatch, and it didn't help, since my errors seem fatal,
not causing backtracking.
My original message follows, for reference.
Dan
On Mon, 2019-11-11 at 19:02 -0500, Dan Christensen wrote:
> The tactic
>
> rewrite lem
>
> does two clever things. It figures out arguments to pass to the
> function lem so that it produces an equality whose left-hand-side
> matches a sub-term of the goal, and it abstracts away that sub-term
> to make the goal into a type family.
>
> However, in the case where the goal is an equality, it produces proof
> terms that are more complicated than necessary. (I'm working within
> the HoTT library, where I need to manipulate the proof terms later in
> the development.)
>
> Below I give a simplified example of two proofs of the same theorem,
> one using rewrite (which generates a proof term using eq_ind_r) and
> one using f_equal and eq_trans. (In HoTT lingo, those would be
> internal_paths_rew_r, and ap and concat, respectively.)
>
> I would like a tactic that is as easy to use as rewrite but which
> produces proofs like the second method below.
>
> I came up with a crude tactic rewrite_in_lhs that often works, also
> shown below. In this example, it works perfectly. However, in more
> complicated examples, the line
>
> let f := constr:(fun w : T => ltac:(let t := context F [w] in exact t))
> in
>
> generates an Ltac error when the lambda expression is not well-typed,
> and Coq doesn't backtrack and try a different match. (The same problem
> happens if I try using "eval pattern src in lhs".)
>
> So my question is whether there is a more robust way to match a lemma
> to a sub-term and then abstract the context of the sub-term to a
> function, which I can then manipulate further.
>
> If an Ltac error can be caught and converted into a tactic failure,
> that would work. But even if that is possible, my method is much
> slower than rewrite, so I hope that there is a more direct solution.
>
> Thanks for any help!
>
> Dan
>
>
> Parameter A C : Type.
> Parameter g : A -> C.
> Parameter c : C.
>
> Axiom lem : forall a : A, g a = c.
>
> Theorem example {B : Type} (f : C -> B) (a : A) (b : B) (q : f c = b)
> : f (g a) = b.
> Proof.
> rewrite lem. (* [lem a] gives [g a = c] *)
> exact q.
> Qed.
>
> Print example.
> (* fun (B : Type) (f : C -> B) (a : A) (b : B) (q : f c = b) =>
> eq_ind_r (fun c : C => f c = b) q (lem a) *)
>
> Theorem example' {B : Type} (f : C -> B) (a : A) (b : B) (q : f c = b)
> : f (g a) = b.
> Proof.
> exact (eq_trans (f_equal f (lem a)) q).
> Qed.
>
> Print example'.
> (* fun (B : Type) (f : C -> B) (a : A) (b : B) (q : f c = b) =>
> eq_trans (f_equal f (lem a)) q *)
>
> (* Try *every* subterm [t] of lhs to see if [lem] can give a path [p]
> starting at [t].
> If so, do [refine (eq_trans (f_equal f p) _)] for suitable [f]. *)
> Tactic Notation "rewrite_in_lhs" uconstr(lem) :=
> lazymatch goal with
> | |- ?lhs = ?rhs
> => match lhs with
> | context F [?src]
> => let T := type of src in
> let f := constr:(fun w : T => ltac:(let t := context F [w] in
> exact t)) in
> refine (eq_trans (f_equal f _) _); [eapply lem | idtac]
> end
> end.
>
> Lemma example'' {B : Type} (f : C -> B) (a : A) (b : B) (q : f c = b)
> : f (g a) = b.
> Proof.
> rewrite_in_lhs lem.
> exact q.
> Qed.
>
> Print example''.
> (* fun (B : Type) (f : C -> B) (a : A) (b : B) (q : f c = b) =>
> eq_trans (f_equal (fun w : C => f w) (lem a)) q *)
- [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Samuel Gruetter, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Talia Ringer, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Talia Ringer, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Talia Ringer, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Clément Pit-Claudel, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Clément Pit-Claudel, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Clément Pit-Claudel, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/13/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Talia Ringer, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/12/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Samuel Gruetter, 11/12/2019
Archive powered by MHonArc 2.6.18.