coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Matthieu Sozeau <mattam AT mattam.org>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting.
- Date: Thu, 4 Oct 2018 19:19:02 +0200
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mattam AT mattam.org; spf=Pass smtp.mailfrom=matthieu.sozeau AT gmail.com; spf=None smtp.helo=postmaster AT mail-wr1-f52.google.com
- Ironport-phdr: 9a23:1dzV1BEBmKrEPh1N89NnX51GYnF86YWxBRYc798ds5kLTJ78p8+wAkXT6L1XgUPTWs2DsrQY07WQ6/iocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmDiwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjDQhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VDK/5KlpVRDokj8KODE38G7VisJ+gqFVrg+/qRNj2IPbep2ZOeBkc6/BYd8XR2xMVdtRWSxbBYO8apMCAe0bMuZEs4n9p1oOogWjBQKxGe3vzT5JiWHs0q0nzu8sFgTG0xY8H9ISqnvUqc74NKIIXuCp0KnH1zDDY+lR2Tfn54jFaxYsquyPU7Joacfd11UjGgffgliTqYHpJS2Z2voQv2SB7+dsS+SigHM9pQ5ruDig3MIsh5HJho0LzlDE8j10wIMvKt25TE53eNClEIFNuy2DOYt7Qt0uT3tnuCY9zb0Gtpq7czYQxJs7wB7fbuSLc4mO4h39SOacOSl0iG5hdb6lhBu/8VKsxvPiWsWpylpHrjRJnsHJtn8X1hzT7saHSuF6/kekwTuP0hrc6v1YIUA0lKrUNYMhzqQrlpoUsEXMADX5mFjtga+Zc0Ur4Omo6+D9brr6oZ+cMpd4ihviPaQ2hsy/HeM4PxASUGic4OSwzaHs/UnkQLpRlfA2ianYsJXCJcsBvKK5AglV0pwi6xmlFTum3s4YzjE7KwdOfwvChIz0MXnPJur5BLGxmQeCijBuktXPIqHhA5jQZkPEgrroYP4p7kdA1AM25dVW+45dD/cGOv2lCRy5j8DREhJsa1/8+O3gEtgojtpPC1LKObeQNebpiXHN4+suJ+eWY4pM4WTyLvEk47jlinprwAZBL5ns5oMebTWDJtojO1+QOCC+h94dDW4P+A0kQ76y0QDQYXtof3+3GpkEyHQ7BYahV9qRQ4mshPmexn7+EMAMIG9BDV+IHDHjcIDWA/o=
Hi Yves,
there is an issue indeed that [by rec] expects the relation to be independent from
the parameters (otherwise, the functional it would produce would not allow
to change T at recursive calls, i.e it would change the type of redo_rev_tree in the body
of the function). It should give you an error rather than this puzzling not-found, I agree.
One solution is to use a section as you did to make it explicit that T is a fixed parameter.
Equations also allows to do recursion on an arbitrary combination of the arguments, so
you can also do the following:
Definition ltt (t1 : {T & btree T}) (t2 : {T & btree T}) :=
size (projT2 t1) < size (projT2 t2).
Equations redo_rev_tree {T} (t : btree T) : btree T :=
redo_rev_tree t by rec (existT (fun T => btree T) T t) ltt :=
redo_rev_tree Leaf := Leaf ;
redo_rev_tree (Node a t1 t2) := Node a (redo_rev_tree t2)
(redo_rev_tree t1).
Next Obligation.
apply size2.
Qed.
Next Obligation.
apply size1.
Qed.
Best,
-- Matthieu
On Thu, Oct 4, 2018 at 5:06 PM Yves Bertot <yves.bertot AT inria.fr> wrote:
I am trying to write a tutorial example using binary trees and show how
to use the ..._elim theorem generated by the Equations package. I would
like some help.
Here is a self contained example.
Require Import Arith.
From Equations Require Import Equations.
Inductive btree (T : Type) : Type :=
Leaf | Node (val : T) (t1 t2 : btree T).
Arguments Leaf {T}.
Arguments Node {T}.
Fixpoint count {T : Type} (p : T -> bool) (t : btree T) : nat :=
match t with
| Leaf => 0
| Node x t1 t2 =>
(if p x then 1 else 0) + (count p t1 + count p t2)
end.
Definition size {T : Type} (t : btree T) := count (fun x => true) t.
Lemma size1 {T} (a : T) t1 t2 : size t1 < size (Node a t1 t2).
Proof.
unfold size; simpl.
unfold lt; apply Peano.le_n_S, Nat.le_add_r.
Qed.
Lemma size2 {T} (a : T) t1 t2 : size t2 < size (Node a t1 t2).
Proof.
unfold size; simpl.
unfold lt; apply Peano.le_n_S; rewrite Nat.add_comm; apply Nat.le_add_r.
Qed.
Section redo_rev.
Variable (T : Type).
Definition ltt (t1 t2 : btree T) := size t1 < size t2.
Equations redo_rev_tree (t : btree T) : btree T :=
redo_rev_tree t by rec t ltt :=
redo_rev_tree Leaf := Leaf ;
redo_rev_tree (Node a t1 t2) := Node a (redo_rev_tree t2)
(redo_rev_tree t1).
Next Obligation.
apply size2.
Qed.
Next Obligation.
apply size1.
Qed.
End redo_rev.
Equations redo_rev_tree' {T} (t : btree T) : btree T :=
redo_rev_tree' t by rec t (@ltt T) :=
redo_rev_tree' Leaf := Leaf ;
redo_rev_tree' (Node a t1 t2) := Node a (redo_rev_tree t2)
(redo_rev_tree t1).
I would like to avoid to define my function redo_rev_tree in a section,
so this is the reason why try to define the function redo_rev_tree'.
It complains That T is unknown, but when I replace T with and
underscore, it complains that it can't guess the value for this place
holder, which should be determined in a context where T appears...
Error: The reference T was not found in the current environment.
- [Coq-Club] Problem using Coq-equations in a polymorphic setting., Yves Bertot, 10/04/2018
- Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting., Matthieu Sozeau, 10/04/2018
- Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting., Yves Bertot, 10/05/2018
- Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting., Matthieu Sozeau, 10/05/2018
- Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting., Yves Bertot, 10/05/2018
- Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting., Matthieu Sozeau, 10/04/2018
Archive powered by MHonArc 2.6.18.