coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Clément Pit-Claudel <cpitclaudel AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport
- Date: Tue, 12 Nov 2019 21:46:31 -0500
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=cpitclaudel AT gmail.com; spf=Pass smtp.mailfrom=cpitclaudel AT gmail.com; spf=None smtp.helo=postmaster AT mail-qv1-f48.google.com
- Ironport-phdr: 9a23:F0CQsxXk+HwXwV1I6w8vSVsy6ZnV8LGtZVwlr6E/grcLSJyIuqrYbBWEt8tkgFKBZ4jH8fUM07OQ7/m7HzVbud3d4TgrS99lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUhrwOhBoKevrB4Xck9q41/yo+53Ufg5EmCexbal9IRmrowjdrNQajIV+Jqo+xRbEpmZDdvhLy29vOV+dhQv36N2q/J5k/SRQuvYh+NBFXK7nYak2TqFWASo/PWwt68LlqRfMTQ2U5nsBSWoWiQZHAxLE7B7hQJj8tDbxu/dn1ymbOc32Sq00WSin4qx2RhLklDsLOjgk+2zRl8d+jr9UoAi5qhJi3YDUboGbOvlwcKzTctwVR3ZOUMlKWixdAY6xdZcDA/YPMOtaqYT2ulsArQG5BQmpHO7i1DtIgWXz3aIk1eQhDRnJ0hYhH9ISqXjZstH1O70PUe+o0qbIySjIYvRK1jfl6YjIbgwuofWWUrJtbMXe100vGhjKjlWVs4PlPjeV2v4RvGic6uptTOSigHMkpQFpujWj2Nsgh43Tio8Wyl3I7zt1zJsxKNGiR0N2YsaoHIVRui2GKod7R94uTmJntSs/xbAKpJ22cDQPxZkmxhPQdf6Kfo2T7R7/SeqcIzJ1iXF5dL+xmxm/9Eetx+3gWsaq1VtHrDRJn9jRun0Lyhfd8NKISuFn8UekwTuP1x7c6uVDIU0skKrUMZ8hwropmpoKr0TPAzb6mEv5gaKVbEkk9e+o6+PoYrXiuJCQLZN7igb7Mqg2m8y/B/o3MhQWUmSF5eix0Kfv8E75TblQkPE6j63UvIrVKMkYvqK5BhVa0ocn6xaxFTem19EYkGEbI1JdeRKHk5TmO1XUL/DlEPiwnVCsnSxkx/DDJLLhA5HNImLfn7fmeLZx81RcxxYrzdBD+5JUDakML+70Wk/ordDXEhs5MxGvzOv8E9V81oYeWXqVDaODMaPSt0WI5uM1LOWWao8VomW1F/9w7Pn3yHQ9hFU1fK+z3JJRZmrrMO5hJhCyZfvpj9EdJl8Lok8VSOX3hFCGGWpYf3euVKY1+z02DKqpCI7CQsamh7nXj3TzJYFfem0TUgPEKnzvbYjRA65ROhLXGddol3k/bZbkS4Il0kvz5grzyr4iN/SNvyNE5dTs09964+CVnhY3p2QtU5atllqVRmQxpVsmAics1fkm80N4w1aHl6N/hq4ATI0B17ZySg4/cKXk4al/AtH2VBjGe47QGlmjS9SiRzo2S4Bozg==
On 2019-11-12 20:24, Dan Christensen wrote:
> This looks very promising! I had tried something similar which didn't
> work. Can you explain why these two lines are needed:
>
> let fn := fresh "f" in
> set f as fn;>
> I had tried something like:
>
> Goal forall m n, (4 * (m + (3 * n)) * 2) = 1.
> intros.
> match type of Nat.add_comm with
> | forall a b, @?f a b = _ =>
> match goal with
> | [ |- context[f ?x ?y] ] =>
> pattern (f x y);
> set x as arg1; set y as arg2
> end
> end.
`set` is a bit more powerful that context[] pattern-matching. Your `f` is
eta-expanded here, so it's not a plain Nat.add, it's (fun a b => a + b).
Here's an example:
Require Import Arith.
Goal forall m n, (4 * (m + (3 * n)) * 2) = 1.
intros.
Fail lazymatch goal with (* This is essentially what your tactic tries to
do *)
| [ |- context[(fun a b => a + b) ?x ?y] ] => idtac
end. (* It fails because the goal doesn't have a literal eta-expanded
(fun a b => a + b) in it *)
change Nat.add with (fun a b => a + b).
lazymatch goal with (* This one works *)
| [ |- context[(fun a b => a + b) ?x ?y] ] => idtac
end.
cbv beta.
set (fun a b => a + b). (* So does [set] *)
> This correctly gets source to be (?x + ?y), but the match of the goal
> against context[source] fails. Maybe I'm just confused and these
> existential variables are different from the variables in match
> patterns?
Yup, the notation is the same, but these are quite different beasts. Your
pattern-matches looks for a subterm of the goal that contains references to
the evars you just created, but your goal doesn't contain that. What you
need to make your example go through is
match goal with
| [ |- context[?x] ] =>
unify x source;
…
| _ => idtac source "unmatched"
end.
… but in general, I'd stay away from evar-based strategies. Consider this
instead:
Require Import Arith.
Ltac source thm :=
let tau := type of thm in
lazymatch tau with
| forall x: ?t, _ =>
constr:(fun x: t =>
ltac:(let thm' := constr:(thm x) in
let thm'' := (eval cbv beta in thm') in
let src := source thm'' in
exact src))
| ?src = _ => constr:(src)
end.
Goal forall m n, (4 * (m + (3 * n)) * 2) = 1.
intros.
let f := source @Nat.add_comm in
let fn := fresh "f" in
set f as fn.
Clément.
- [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/14/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Jason Gross, 11/14/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/15/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/15/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Dan Christensen, 11/15/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Gaëtan Gilbert, 11/15/2019
- Re: [Coq-Club] rewriting in an equality without eq_ind_r / transport, Samuel Gruetter, 11/16/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.