Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting.

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting.


Chronological Thread 
  • 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: Fri, 5 Oct 2018 13:47:32 +0200
  • Authentication-results: mail3-smtp-sop.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-f65.google.com
  • Ironport-phdr: 9a23:0StbshZK5BxAccDluevaLp7/LSx+4OfEezUN459isYplN5qZoMy5bnLW6fgltlLVR4KTs6sC17KJ9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa/bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjE2/mHYiMx+gqxYrhy8uRJw35XZb5uJOPdkZK7RYc8WSGhHU81MVyJBGIS8b44XAuQGJ+lYs5X9p1sPrRSgGAmnGf7hyjhJh3Dox6I6zvkqHAbD3AM6A9IOrG7brNDuOacXS++10LXIwi/Gb/9M3jf98ofIfwknrPqRXrxwadLcxVczGw7BlFmdqozoMymL2ugTrmSX9ettWOKphmU6sQ9+uCKvyd0pioTRhoIa1FTE9SJhzYYwP9K4SUp7bceqEZtKqi2WLoV2T8IiTm1ytyY6zboGuZG/fCcU0pgo2xnfa/mff4iJ5BLsSvqRLC9miH55fL+znRW//Ei6xuHiSMW4zUxGoytFn9XUs3ACzR3T6syJSvtn+Ueh3C6C1wXJ5eFYPUA0lavbJIA8wrIqjZoTtkXCETHsl0Xrl6KWeUAk9fKp6+TjeLnpupicN4pshgHkLqsugtC/Afg/MgUWQ2eb/v282KT/8k39XbVFleY7krLZsZDfPcQUvLS1Aw5T0oY56hawFS2q0NoCnSpPEFUQcxWeyoPtJlvmIfbiDP75jU7/vi1swqXjN6H9ApTAMzD4l6XsdKs1v0tV1BY6yPha7o5IA7RHJ+j8DByi/OfEBwM0ZlTni93sD89wg9tHCDC/R5SBOaaXimemo+cmIu2CfogQ4W+vJP0s5vqohng8ywZEIfuZmKAPYXX9JcxIZl2DaCO20NIIDXsDu0w5VuO40ATfAw4WXG67WucH3h9+CI+iCt2eFIWkgbjEwz3iW5MIOyZJDVeDFXqufIKBCa8B

Hi Yves,

Indeed, it should be typed in a context with just the section variables. Then you would see the problem more clearly. Can you open an issue on Equations’ github about it?

Best,
— Matthieu
Le ven. 5 oct. 2018 à 06:40, Yves Bertot <yves.bertot AT inria.fr> a écrit :
I am now trying to think about what could be a good error message.

The problem is then that if you replace the (@ltt T) with (@ltt _), the error message is different:

Error: Cannot infer this placeholder of type
"Type" in environment:
T : Type
t : btree T

This seems to imply that T should be available in the context where the relation is provided and is
misleading to the user.  Is there a good reason for this error message to mention a context where
T is apparent?

Yves

From: "Matthieu Sozeau" <mattam AT mattam.org>
To: "coq-club" <coq-club AT inria.fr>
Sent: Thursday, October 4, 2018 7:19:02 PM
Subject: Re: [Coq-Club] Problem using Coq-equations in a polymorphic setting.
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.





Archive powered by MHonArc 2.6.18.

Top of Page