coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Samuel Gruetter <gruetter AT mit.edu>
- To: "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport
- Date: Tue, 12 Nov 2019 20:41:41 +0000
- Accept-language: en-US
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gruetter AT mit.edu; spf=Pass smtp.mailfrom=gruetter AT mit.edu; spf=None smtp.helo=postmaster AT outgoing-exchange-3.mit.edu
- Ironport-phdr: 9a23:hm9Clh3FtEg4vcRgsmDT+DRfVm0co7zxezQtwd8ZseIWI/ad9pjvdHbS+e9qxAeQG9mCsLQd0bud6vy6EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCezbL9oMRm6swHcusYLjYZtNKo61wfErGZPd+lK321jOEidnwz75se+/Z5j9zpftvc8/MNeUqv0Yro1Q6VAADspL2466svrtQLeTQSU/XsTTn8WkhtTDAfb6hzxQ4r8vTH7tup53ymaINH2QLUpUjms86tnVBnlgzoBOjUk8m/Yl9Zwgbpbrhy/uhJ/34DaboKbNPV8f6PSYdwUSmVaU8ZNTCNMGJ+wY5cTA+cDO+tTsonzp0EJrRu7HQSiGfngyjpVhnDo2a0xzuUvERvb3AM+A9IOrGrbrM/oP6oVXuC11rTIwivfb/NKxzj98pPFchUgofGQR75/b9feyVQ2Gg7Dk16ep4vlPzaP2eQMtWiW9+VgVeOzi24ntgF+uSKjydsrionMgI8e11PK9T1hzYooJtC0Ukp2bcS6HJZTrS2WKoV7Tts/T212uys20LMLtYKhcCQX1Jgr3QPTZ+KGfoSQ/x7uV/ydLDNiiH9qYr6zmgu+/Eemx+bhTMe7ykxKoTBAktTUtnACyRjT6s+fR/t640ehxTmP1wfS6uFCLkA4jLTUKpE9zb4wjJUTt0vDETHvlEj4lqOWc0Qk+vSy5+v5f7rmu4eQN45yig7gLqQjgtGzDOciPgUKRWSX5+ex2Kf+8UD3WLlKi+c5kqjdsJDUP8Qboau5Dhda0oY59hawESum0MgGknkdN19FfROHj5TzN17QPf/4EO+zg06wnzdz2/DGIrrhD43RIXjEibftZKpy60pByAUo1t1f/JJVCrQZIP3pQEPxtdrYDgU4MwOu2ernBs99hcsiXjfFCaiAdajWrFWg5+Q1IuDKapVf8GL2LOFg7Przh1c4n0UcdO+nx81ERmq/G6FdKkCEbH6krc0cHHsWsxB2GOPwlVCeTTNJT3OzQ+Qx6ixtW9HuNpvKWo342O/J5yy8BJADPjkXWGDJKm/hcsC/Y9lJbSuTJsF7lTlVB72gV8ks2Qz87VanmYoiFfLd/2gjjbym1NVx4LeCxxYv6TNzDsKSlmydRGF9mGwFAmRw2aFj50Fx1wXbiPQqs7ljDdVWoshxfEIiL5eNnel7F5b/Vh+TJto=
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.
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?
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, 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.