coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: "Soegtrop, Michael" <michael.soegtrop AT intel.com>
- To: "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: RE: [Coq-Club] Applying Lemma in fold_left
- Date: Sun, 21 Aug 2016 13:11:35 +0000
- Accept-language: de-DE, en-US
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=michael.soegtrop AT intel.com; spf=Pass smtp.mailfrom=michael.soegtrop AT intel.com; spf=None smtp.helo=postmaster AT mga02.intel.com
- Ironport-phdr: 9a23:cyF7GhJ4KChdRGy8R9mcpTZWNBhigK39O0sv0rFitYgUIvXxwZ3uMQTl6Ol3ixeRBMOAuqsC0bud7vCoGTRZp83Q6DZaKN0EfiRGoP1epxYnDs+BBB+zB9/RRAt+Iv5/UkR49WqwK0lfFZW2TVTTpnqv8WxaQU2nZkJLL+j4UrTfk96wn7jrvcaCOkMS1XHgMfsydEzw9lSJ8JFOwMNLEeUY8lPxuHxGeuBblytDBGm4uFLC3Pq254Np6C9KuvgspIZqWKT+eLkkH/QDVGx1ezN92Mq+/xLEVE6E4mYWemQQiBtBRQbfplmuVZDo9yD+q+BV2S+APMSwQ6piChq46KI+AiTvhSgbLTkhtCnyi8dwha9f6lr1oh10w4fZZMeOM/dxYrnaZfsbQ3ZMWoBaUCkXUdD0VJcGE+dUZbUQlIL6vVZb9RY=
for rewriting under fold_left you need to use setoid_rewrite and you need to show that fold_left is a proper function which respects the equalities of its arguments.
I am myself still struggling with the concepts of this, so I took this as an exercise. Maybe one of the experts can review my comments / explanations of the required “Proper term”.
Best regards,
Michael
Require Import List. Require Import Setoid. Require Import Morphisms.
(* For rewriting under f : A->B->C we need an Instance of
Proper ( equality of A ==> equality of B ==> equality of C ) f
The equality is usually (@eq type). The usual equality for a function parameter p D->E->F is pointwise equality
pointwise_relation D (pointwise_relation E (@eq F))
Afaik if (and only if) the equalities for all arguments and result types is (@eq type), the usual rewrite can be used. For fold_left, the problematic parameter is the function f, which requires pointwise equality. *)
(* So for rewriting under fold_left we need: *)
Instance fold_left_proper(A B : Type) : Proper ( pointwise_relation A (pointwise_relation B (@eq A)) ==> @eq (list B) ==> @eq A ==> @eq A ) (fold_left (B:=B)). Proof. unfold Proper, respectful, pointwise_relation. intros f1 f2 Hf l1 l2 Hl. subst. induction l2. - intros n1 n2 Hn. subst. reflexivity. - intros n1 n2 Hn. subst. simpl. apply IHl2. apply Hf. Qed.
Lemma fold_left_zero {a : Type}: forall (l : list a) (n : nat), fold_left (fun (n1 : nat) (_ : a) => n1) l n = n. Admitted.
Parameter x : Set. Definition y := x. Parameter elements : list x.
Goal fold_left (fun (n : nat) (_ : x) => fold_left (fun (n0 : nat) (_ : y) => n0) elements n) elements 0 = 0.
setoid_rewrite fold_left_zero. rewrite fold_left_zero. reflexivity. Qed.
Intel Deutschland GmbH |
- [Coq-Club] Applying Lemma in fold_left, Durjay Chowdhury, 08/15/2016
- Re: [Coq-Club] Applying Lemma in fold_left, Laurent Thery, 08/21/2016
- RE: [Coq-Club] Applying Lemma in fold_left, Soegtrop, Michael, 08/21/2016
- Re: [Coq-Club] Applying Lemma in fold_left, John Wiegley, 08/21/2016
Archive powered by MHonArc 2.6.18.